source: trunk/gsdl3/src/java/org/greenstone/gsdl3/action/XMLDocumentAction.java@ 6300

Last change on this file since 6300 was 6300, checked in by kjdon, 20 years ago

GSXML.createBasicRequest now expects a user id

  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 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 /** process - processes a request.
25 */
26 public Element process (Element message) {
27
28 // get the request - assume there is only one
29 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
30
31 // create the return message
32 Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
33 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
34 result.appendChild(page_response);
35
36 // extract the params from the cgi-request, and check that we have a coll specified
37 Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
38 HashMap params = GSXML.extractParams(cgi_param_list, false);
39
40 String collection = (String)params.get(GSParams.COLLECTION);
41 if (collection == null || collection.equals("")) {
42 return result;
43 }
44 String doc_name = (String) params.get(GSParams.DOCUMENT);
45 if (doc_name == null || doc_name.equals("")) {
46 return result;
47 }
48 String lang = request.getAttribute(GSXML.LANG_ATT);
49 String uid = request.getAttribute(GSXML.USER_ID_ATT);
50
51 // subaction used to decide if we are returning content or structure
52 String document_mode = request.getAttribute(GSXML.SUBACTION_ATT);
53 String to = null;
54 if (document_mode.equals("text")) {
55 to = GSPath.appendLink(collection, "DocumentContentRetrieve");
56 } else if (document_mode.equals("toc")) {
57 to = GSPath.appendLink(collection, "DocumentStructureRetrieve");
58 } else { // the default is text
59 to = GSPath.appendLink(collection, "DocumentContentRetrieve");
60 }
61
62 // make the request to the collection
63 Element mr_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
64
65 Element ret_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
66 mr_message.appendChild(ret_request);
67
68 Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
69 ret_request.appendChild(doc_list);
70 Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
71 doc.setAttribute(GSXML.NODE_ID_ATT, doc_name);
72 doc_list.appendChild(doc);
73
74 // also add in a request for the Title metadata
75 to = GSPath.appendLink(collection, "DocumentMetadataRetrieve");
76 Element meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
77 // copy the doc list
78 meta_request.appendChild(doc_list.cloneNode(true));
79 // add in a metadata param
80 Element param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
81 meta_request.appendChild(param_list);
82 Element param = GSXML.createParameter(this.doc, "metadata", "root_Title");
83 param_list.appendChild(param);
84
85 // add the request to the message
86 mr_message.appendChild(meta_request);
87
88 Element ret_response = this.mr.process(mr_message);
89 String [] links = {GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM};
90 String path = GSPath.createPath(links);
91 Element doc_node = (Element)this.doc.importNode(GSXML.getNodeByPath(ret_response, path), true);
92 page_response.appendChild(doc_node);
93
94 // get the metadata list
95 Element meta_response = (Element)ret_response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(1);
96 String [] mlinks = {GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER};
97 path = GSPath.createPath(mlinks);
98
99 Element meta_list = (Element)GSXML.getNodeByPath(meta_response, path);
100 if (meta_list != null) {
101 doc_node.appendChild(this.doc.importNode(meta_list, true));
102 }
103 return result;
104 }
105
106}
Note: See TracBrowser for help on using the repository browser.