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

Last change on this file since 24993 was 24993, checked in by sjm84, 12 years ago

Adding UserContext to replace the use of lang and uid

  • 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 // extract the params from the cgi-request, and check that we have a coll specified
41 Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
42 HashMap params = GSXML.extractParams(cgi_param_list, false);
43
44 String collection = (String) params.get(GSParams.COLLECTION);
45 if (collection == null || collection.equals(""))
46 {
47 return result;
48 }
49 String doc_name = (String) params.get(GSParams.DOCUMENT);
50 if (doc_name == null || doc_name.equals(""))
51 {
52 return result;
53 }
54 UserContext userContext = new UserContext(request);
55
56 // subaction used to decide if we are returning content or structure
57 String document_mode = request.getAttribute(GSXML.SUBACTION_ATT);
58 String to = null;
59 if (document_mode.equals("text"))
60 {
61 to = GSPath.appendLink(collection, "DocumentContentRetrieve");
62 }
63 else if (document_mode.equals("toc"))
64 {
65 to = GSPath.appendLink(collection, "DocumentStructureRetrieve");
66 }
67 else
68 { // the default is text
69 to = GSPath.appendLink(collection, "DocumentContentRetrieve");
70 }
71
72 // make the request to the collection
73 Element mr_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
74
75 Element ret_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
76 mr_message.appendChild(ret_request);
77
78 Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
79 ret_request.appendChild(doc_list);
80 Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
81 doc.setAttribute(GSXML.NODE_ID_ATT, doc_name);
82 doc_list.appendChild(doc);
83
84 // also add in a request for the Title metadata
85 to = GSPath.appendLink(collection, "DocumentMetadataRetrieve");
86 Element meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
87 // copy the doc list
88 meta_request.appendChild(doc_list.cloneNode(true));
89 // add in a metadata param
90 Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
91 meta_request.appendChild(param_list);
92 Element param = GSXML.createParameter(this.doc, "metadata", "root_Title");
93 param_list.appendChild(param);
94
95 // add the request to the message
96 mr_message.appendChild(meta_request);
97
98 Element ret_response = (Element) this.mr.process(mr_message);
99 String[] links = { GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM };
100 String path = GSPath.createPath(links);
101 Element doc_node = (Element) this.doc.importNode(GSXML.getNodeByPath(ret_response, path), true);
102 page_response.appendChild(doc_node);
103
104 // get the metadata list
105 Element meta_response = (Element) ret_response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(1);
106 String[] mlinks = { GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER };
107 path = GSPath.createPath(mlinks);
108
109 Element meta_list = (Element) GSXML.getNodeByPath(meta_response, path);
110 if (meta_list != null)
111 {
112 doc_node.appendChild(this.doc.importNode(meta_list, true));
113 }
114 return result;
115 }
116
117}
Note: See TracBrowser for help on using the repository browser.