1 | package org.greenstone.gsdl3.action;
|
---|
2 |
|
---|
3 | import org.greenstone.gsdl3.util.*;
|
---|
4 |
|
---|
5 | // XML classes
|
---|
6 | import org.w3c.dom.Document;
|
---|
7 | import org.w3c.dom.Node;
|
---|
8 | import org.w3c.dom.Element;
|
---|
9 |
|
---|
10 | // other java stuff
|
---|
11 | import java.util.*;
|
---|
12 | import java.io.Serializable;
|
---|
13 | import java.io.PrintWriter;
|
---|
14 | import java.io.Serializable;
|
---|
15 | import java.io.StringWriter;
|
---|
16 |
|
---|
17 | import org.apache.log4j.*;
|
---|
18 |
|
---|
19 | public class RSSAction extends Action
|
---|
20 | {
|
---|
21 |
|
---|
22 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.RSSAction.class.getName());
|
---|
23 |
|
---|
24 | /** process a request */
|
---|
25 | public Node process(Node message_node)
|
---|
26 | {
|
---|
27 |
|
---|
28 | Element message = GSXML.nodeToElement(message_node);
|
---|
29 | Document doc = message.getOwnerDocument();
|
---|
30 |
|
---|
31 | // assume only one request
|
---|
32 | Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
|
---|
33 |
|
---|
34 | UserContext userContext = new UserContext(request);
|
---|
35 | // get the param list
|
---|
36 | Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
37 | HashMap<String, Serializable> params = GSXML.extractParams(cgi_param_list, false);
|
---|
38 |
|
---|
39 | String service_name = "RSSFeed"; // RSSFeed service of RSSRetrieve.java
|
---|
40 | String collection = (String) params.get(GSParams.COLLECTION);
|
---|
41 | String to = GSPath.prependLink(service_name, collection); // collection/RSSFeed
|
---|
42 | // Get baseUrl for links in RSS Feed
|
---|
43 | String baseUrl = request.getAttribute("baseURL");
|
---|
44 |
|
---|
45 |
|
---|
46 | // the first part of the response is the service description
|
---|
47 | // for now get this again from the service.
|
---|
48 | // this should be cached somehow later on.
|
---|
49 |
|
---|
50 | Element mr_request_message = doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
51 | Element rss_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
|
---|
52 | //Pass baseURL to processRSSFeed
|
---|
53 | rss_request.setAttribute("baseURL", baseUrl);
|
---|
54 | mr_request_message.appendChild(rss_request);
|
---|
55 |
|
---|
56 | Element rss_response = (Element) this.mr.process(mr_request_message);
|
---|
57 | rss_response = (Element) GSXML.getChildByTagName(rss_response, GSXML.RESPONSE_ELEM); // just the response tag
|
---|
58 | if (rss_response == null) {
|
---|
59 | //RSS service not available
|
---|
60 | rss_response = doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
61 |
|
---|
62 | GSXML.addError(rss_response, "RSS service not available for this collection");
|
---|
63 | }
|
---|
64 | // NEED ERROR PROCESSING ?
|
---|
65 |
|
---|
66 | // siteMeta and interfaceOptions are unnecessary, as rss.xsl is going to remove it anyway
|
---|
67 | // but may be handy when doing o=xml to view the original xml as it came through from the GS server
|
---|
68 | addSiteMetadata(rss_response, userContext);
|
---|
69 | addInterfaceOptions(rss_response);
|
---|
70 |
|
---|
71 | Element result = doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
72 | result.appendChild(doc.importNode(rss_response, true));
|
---|
73 | return result;
|
---|
74 |
|
---|
75 | }
|
---|
76 |
|
---|
77 | }
|
---|