source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/XMLCollection.java@ 28966

Last change on this file since 28966 was 28966, checked in by kjdon, 10 years ago

Lots of changes. Mainly to do with removing this.doc from everywhere. Document is not thread safe. Now we tend to create a new Document everytime we are starting a new page/message etc. in service this.desc_doc is available as teh document to create service info stuff. But it should only be used for this and not for other messages. newDOM is now static for XMLConverter. method param changes for some GSXML methods.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1package org.greenstone.gsdl3.collection;
2
3import org.greenstone.gsdl3.util.*;
4import org.greenstone.gsdl3.core.*;
5import org.greenstone.gsdl3.service.*;
6
7
8// java XML classes we're using
9import org.w3c.dom.Document;
10import org.w3c.dom.Node;
11import org.w3c.dom.Element;
12import org.w3c.dom.NodeList;
13
14import java.io.File;
15import java.util.HashMap;
16
17import org.apache.log4j.*;
18
19/* for a collection that hasn't been built with greenstone build stuff. expects a documentList in the collectionConfig file, and it stores this. this is where doc level metadata comes from */
20public class XMLCollection
21 extends Collection {
22
23 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.collection.XMLCollection.class.getName());
24
25 protected Element document_list = null;
26 /** overwrite this to keep the document list
27 * find the metadata and display elems from the two config files and add it to the appropriate lists
28 */
29 protected boolean findAndLoadInfo(Element coll_config_xml,
30 Element build_config_xml){
31
32 // add metadata to stored metadata list from collConfig and buildConfig
33 Element meta_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
34 addMetadata(meta_list);
35 meta_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
36 addMetadata(meta_list);
37
38 addMetadata("httpPath", this.site_http_address+"/collect/"+this.cluster_name);
39
40 // display stuff
41 Element display_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
42 if (display_list != null) {
43 resolveMacros(display_list);
44 addDisplayItems(display_list);
45 }
46
47 // are we a private collection??
48 if (this.metadata_list != null) {
49
50 Element meta_elem = (Element) GSXML.getNamedElement(this.metadata_list, GSXML.METADATA_ELEM, GSXML.NAME_ATT, "public");
51 if (meta_elem != null) {
52
53 String value = GSXML.getValue(meta_elem).toLowerCase().trim();
54 if (value.equals("false")) {
55 is_public = false;
56 }
57 }
58 }
59 Element config_doc_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);
60 if (config_doc_list != null) {
61 document_list = (Element)desc_doc.importNode(config_doc_list, true);
62 } else {
63 document_list = desc_doc.createElement(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);
64 }
65 return true;
66
67 }
68
69 /** handles requests made to the ServiceCluster itself
70 *
71 * @param req - the request Element- <request>
72 * @return the result Element - should be <response>
73 */
74 protected Element processMessage(Document response_doc, Element request) {
75
76 Element response = response_doc.createElement(GSXML.RESPONSE_ELEM);
77 response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
78 String type = request.getAttribute(GSXML.TYPE_ATT);
79 String lang = request.getAttribute(GSXML.LANG_ATT);
80 response.setAttribute(GSXML.TYPE_ATT, type);
81
82 if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE)) {
83 // create the collection element
84 Element description = (Element)response_doc.importNode(this.description, false);
85 response.appendChild(description);
86 // check the param list
87 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
88 if (param_list == null) {
89 addAllDisplayInfo(description, lang);
90 description.appendChild(response_doc.importNode(this.service_list, true));
91 description.appendChild(response_doc.importNode(this.metadata_list, true));
92 description.appendChild(response_doc.importNode(this.library_param_list, true));
93 description.appendChild(response_doc.importNode(this.document_list, true));
94 return response;
95 }
96
97 // go through the param list and see what components are wanted
98 NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
99 for (int i=0; i<params.getLength(); i++) {
100
101 Element param = (Element)params.item(i);
102 // Identify the structure information desired
103 if (param.getAttribute(GSXML.NAME_ATT) == GSXML.SUBSET_PARAM ) {
104 String info = param.getAttribute(GSXML.VALUE_ATT);
105 if (info.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
106 description.appendChild(response_doc.importNode(this.service_list, true));
107 } else if (info.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
108 description.appendChild(response_doc.importNode(metadata_list, true));
109 } else if (info.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER)) {
110 addAllDisplayInfo(description, lang);
111
112 } else if (info.equals(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER)) {
113 description.appendChild(response_doc.importNode(this.document_list, true));
114 } else if (info.equals(GSXML.LIBRARY_PARAM_ELEM+GSXML.LIST_MODIFIER)) {
115
116 description.appendChild(response_doc.importNode(this.library_param_list, true));
117 }
118
119 }
120 }
121 return response;
122 }
123 return super.processMessage(response_doc, request);
124
125 }
126
127}
Note: See TracBrowser for help on using the repository browser.