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

Last change on this file was 38955, checked in by kjdon, 2 days ago

instead of synchronising on the display item list, take a copy and then use it.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 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 DisplayItemUtil.storeDisplayItems(this.display_item_list, 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 Element di_list = response_doc.createElement(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER);
90 description.appendChild(di_list);
91 //synchronized(this.display_item_list) {
92 Element main_di_list_copy = (Element)response_doc.importNode(this.display_item_list, true);
93 DisplayItemUtil.addLanguageSpecificDisplayItems(di_list, /*this.display_item_list*/ main_di_list_copy, lang, DEFAULT_LANG, this.class_loader);
94 //}
95 description.appendChild(response_doc.importNode(this.service_list, true));
96 description.appendChild(response_doc.importNode(this.metadata_list, true));
97 description.appendChild(response_doc.importNode(this.library_param_list, true));
98 description.appendChild(response_doc.importNode(this.document_list, true));
99 return response;
100 }
101
102 // go through the param list and see what components are wanted
103 NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
104 for (int i=0; i<params.getLength(); i++) {
105
106 Element param = (Element)params.item(i);
107 // Identify the structure information desired
108 if (param.getAttribute(GSXML.NAME_ATT) == GSXML.SUBSET_PARAM ) {
109 String info = param.getAttribute(GSXML.VALUE_ATT);
110 if (info.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
111 description.appendChild(response_doc.importNode(this.service_list, true));
112 } else if (info.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
113 description.appendChild(response_doc.importNode(metadata_list, true));
114 } else if (info.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER)) {
115 Element di_list = response_doc.createElement(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER);
116 description.appendChild(di_list);
117 Element main_di_list_copy = (Element)response_doc.importNode(this.display_item_list, true);
118 DisplayItemUtil.addLanguageSpecificDisplayItems(di_list, /*this.display_item_list*/ main_di_list_copy, lang, DEFAULT_LANG, this.class_loader);
119
120
121 } else if (info.equals(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER)) {
122 description.appendChild(response_doc.importNode(this.document_list, true));
123 } else if (info.equals(GSXML.LIBRARY_PARAM_ELEM+GSXML.LIST_MODIFIER)) {
124
125 description.appendChild(response_doc.importNode(this.library_param_list, true));
126 }
127
128 }
129 }
130 return response;
131 }
132 return super.processMessage(response_doc, request);
133
134 }
135
136}
Note: See TracBrowser for help on using the repository browser.