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

Last change on this file since 30837 was 30837, checked in by kjdon, 8 years ago

use the new DisplayItemUtil class instead of loca methods

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