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

Last change on this file since 6233 was 5965, checked in by kjdon, 21 years ago

changed root:Title to root_Title

  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 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
50 // subaction used to decide if we are returning content or structure
51 String document_mode = request.getAttribute(GSXML.SUBACTION_ATT);
52 String to = null;
53 if (document_mode.equals("text")) {
54 to = GSPath.appendLink(collection, "DocumentContentRetrieve");
55 } else if (document_mode.equals("toc")) {
56 to = GSPath.appendLink(collection, "DocumentStructureRetrieve");
57 } else { // the default is text
58 to = GSPath.appendLink(collection, "DocumentContentRetrieve");
59 }
60
61 // make the request to the collection
62 Element mr_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
63
64 Element ret_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang);
65 mr_message.appendChild(ret_request);
66
67 Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
68 ret_request.appendChild(doc_list);
69 Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
70 doc.setAttribute(GSXML.NODE_ID_ATT, doc_name);
71 doc_list.appendChild(doc);
72
73 // also add in a request for the Title metadata
74 to = GSPath.appendLink(collection, "DocumentMetadataRetrieve");
75 Element meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang);
76 // copy the doc list
77 meta_request.appendChild(doc_list.cloneNode(true));
78 // add in a metadata param
79 Element param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
80 meta_request.appendChild(param_list);
81 Element param = GSXML.createParameter(this.doc, "metadata", "root_Title");
82 param_list.appendChild(param);
83
84 // add the request to the message
85 mr_message.appendChild(meta_request);
86
87 Element ret_response = this.mr.process(mr_message);
88 String [] links = {GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM};
89 String path = GSPath.createPath(links);
90 Element doc_node = (Element)this.doc.importNode(GSXML.getNodeByPath(ret_response, path), true);
91 page_response.appendChild(doc_node);
92
93 // get the metadata list
94 Element meta_response = (Element)ret_response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(1);
95 String [] mlinks = {GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER};
96 path = GSPath.createPath(mlinks);
97
98 Element meta_list = (Element)GSXML.getNodeByPath(meta_response, path);
99 if (meta_list != null) {
100 doc_node.appendChild(this.doc.importNode(meta_list, true));
101 }
102 return result;
103 }
104
105}
Note: See TracBrowser for help on using the repository browser.