source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/XMLDocumentAction.java@ 25490

Last change on this file since 25490 was 25490, checked in by kjdon, 12 years ago

add the extra info into the page to keep in line with other actions

  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1package org.greenstone.gsdl3.action;
2
3import org.greenstone.gsdl3.core.ModuleInterface;
4import org.greenstone.gsdl3.util.*;
5import org.greenstone.gsdl3.service.TEIRetrieve;
6// XML classes
7import org.w3c.dom.Node;
8import org.w3c.dom.NodeList;
9import org.w3c.dom.Text;
10import org.w3c.dom.Document;
11import org.w3c.dom.Element;
12
13import java.util.HashMap;
14import java.util.HashSet;
15import java.util.Vector;
16import java.util.Map;
17import java.util.Iterator;
18import java.io.File;
19
20/** action class for retrieving parts of XML documents */
21public class XMLDocumentAction extends Action
22{
23
24 /**
25 * process - processes a request.
26 */
27 public Node process(Node message_node)
28 {
29
30 Element message = this.converter.nodeToElement(message_node);
31
32 // get the request - assume there is only one
33 Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
34
35 // create the return message
36 Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
37 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
38 result.appendChild(page_response);
39
40 UserContext userContext = new UserContext(request);
41 addSiteMetadata(page_response, userContext);
42 addInterfaceOptions(page_response);
43
44 // extract the params from the cgi-request, and check that we have a coll specified
45 Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
46 HashMap params = GSXML.extractParams(cgi_param_list, false);
47
48 String collection = (String) params.get(GSParams.COLLECTION);
49 if (collection == null || collection.equals(""))
50 {
51 return result;
52 }
53 String doc_name = (String) params.get(GSParams.DOCUMENT);
54 if (doc_name == null || doc_name.equals(""))
55 {
56 return result;
57 }
58
59 // subaction used to decide if we are returning content or structure
60 String document_mode = request.getAttribute(GSXML.SUBACTION_ATT);
61 String to = null;
62 if (document_mode.equals("text"))
63 {
64 to = GSPath.appendLink(collection, "DocumentContentRetrieve");
65 }
66 else if (document_mode.equals("toc"))
67 {
68 to = GSPath.appendLink(collection, "DocumentStructureRetrieve");
69 }
70 else
71 { // the default is text
72 to = GSPath.appendLink(collection, "DocumentContentRetrieve");
73 }
74
75 // make the request to the collection
76 Element mr_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
77
78 Element ret_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
79 mr_message.appendChild(ret_request);
80
81 Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
82 ret_request.appendChild(doc_list);
83 Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
84 doc.setAttribute(GSXML.NODE_ID_ATT, doc_name);
85 doc_list.appendChild(doc);
86
87 // also add in a request for the Title metadata
88 to = GSPath.appendLink(collection, "DocumentMetadataRetrieve");
89 Element meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
90 // copy the doc list
91 meta_request.appendChild(doc_list.cloneNode(true));
92 // add in a metadata param
93 Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
94 meta_request.appendChild(param_list);
95 Element param = GSXML.createParameter(this.doc, "metadata", "root_Title");
96 param_list.appendChild(param);
97
98 // add the request to the message
99 mr_message.appendChild(meta_request);
100
101 Element ret_response = (Element) this.mr.process(mr_message);
102 String[] links = { GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM };
103 String path = GSPath.createPath(links);
104 Element doc_node = (Element) this.doc.importNode(GSXML.getNodeByPath(ret_response, path), true);
105 page_response.appendChild(doc_node);
106
107 // get the metadata list
108 Element meta_response = (Element) ret_response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(1);
109 String[] mlinks = { GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER };
110 path = GSPath.createPath(mlinks);
111
112 Element meta_list = (Element) GSXML.getNodeByPath(meta_response, path);
113 if (meta_list != null)
114 {
115 doc_node.appendChild(this.doc.importNode(meta_list, true));
116 }
117 return result;
118 }
119
120}
Note: See TracBrowser for help on using the repository browser.