source: trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/XMLCollection.java@ 13270

Last change on this file since 13270 was 13270, checked in by shaoqun, 17 years ago

replace Category class which is deprecated with Logger class

  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 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 // metadata
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 meta_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
39 GSXML.addMetadata(this.doc, meta_list, "httpPath", this.site_http_address+"/collect/"+this.cluster_name);
40 addMetadata(meta_list);
41
42 // display stuff
43 Element display_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
44 if (display_list != null) {
45 addDisplayItems(display_list);
46 }
47
48 Element config_doc_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);
49 if (config_doc_list != null) {
50 document_list = (Element)this.doc.importNode(config_doc_list, true);
51 } else {
52 document_list = this.doc.createElement(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);
53 }
54 return true;
55
56 }
57
58 /** handles requests made to the ServiceCluster itself
59 *
60 * @param req - the request Element- <request>
61 * @return the result Element - should be <response>
62 */
63 protected Element processMessage(Element request) {
64
65 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
66 response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
67 String type = request.getAttribute(GSXML.TYPE_ATT);
68 String lang = request.getAttribute(GSXML.LANG_ATT);
69 response.setAttribute(GSXML.TYPE_ATT, type);
70
71 if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE)) {
72 // create the collection element
73 Element description = (Element)this.description.cloneNode(false);
74 response.appendChild(description);
75 // check the param list
76 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
77 if (param_list == null) {
78 addAllDisplayInfo(description, lang);
79 description.appendChild(this.service_list);
80 description.appendChild(this.metadata_list);
81 description.appendChild(this.document_list);
82 return response;
83 }
84
85 // go through the param list and see what components are wanted
86 NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
87 for (int i=0; i<params.getLength(); i++) {
88
89 Element param = (Element)params.item(i);
90 // Identify the structure information desired
91 if (param.getAttribute(GSXML.NAME_ATT) == GSXML.SUBSET_PARAM ) {
92 String info = param.getAttribute(GSXML.VALUE_ATT);
93 if (info.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
94 description.appendChild(this.service_list);
95 } else if (info.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
96 description.appendChild(metadata_list);
97 } else if (info.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER)) {
98 addAllDisplayInfo(description, lang);
99
100 } else if (info.equals(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER)) {
101 description.appendChild(this.document_list);
102 }
103
104 }
105 }
106 return response;
107 }
108
109 if (type.equals(GSXML.REQUEST_TYPE_SYSTEM)) {
110 response = processSystemRequest(request);
111 } else { // unknown type
112 logger.error("cant handle request of type "+ type);
113
114 }
115 return response;
116 }
117
118}
Note: See TracBrowser for help on using the repository browser.