[5266] | 1 | package org.greenstone.gsdl3.collection;
|
---|
| 2 |
|
---|
| 3 | import org.greenstone.gsdl3.util.*;
|
---|
| 4 | import org.greenstone.gsdl3.core.*;
|
---|
| 5 | import org.greenstone.gsdl3.service.*;
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | // java XML classes we're using
|
---|
| 9 | import org.w3c.dom.Document;
|
---|
| 10 | import org.w3c.dom.Node;
|
---|
| 11 | import org.w3c.dom.Element;
|
---|
| 12 | import org.w3c.dom.NodeList;
|
---|
| 13 |
|
---|
| 14 | import java.io.File;
|
---|
| 15 | import java.util.HashMap;
|
---|
| 16 |
|
---|
[13123] | 17 | import org.apache.log4j.*;
|
---|
| 18 |
|
---|
[5266] | 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 */
|
---|
| 20 | public class XMLCollection
|
---|
| 21 | extends Collection {
|
---|
| 22 |
|
---|
[13270] | 23 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.collection.XMLCollection.class.getName());
|
---|
[13123] | 24 |
|
---|
[5266] | 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 |
|
---|
[28966] | 32 | // add metadata to stored metadata list from collConfig and buildConfig
|
---|
[5266] | 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 |
|
---|
[28966] | 38 | addMetadata("httpPath", this.site_http_address+"/collect/"+this.cluster_name);
|
---|
[5266] | 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) {
|
---|
[25465] | 43 | resolveMacros(display_list);
|
---|
[5266] | 44 | addDisplayItems(display_list);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[25465] | 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 | }
|
---|
[5266] | 59 | Element config_doc_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);
|
---|
| 60 | if (config_doc_list != null) {
|
---|
[28966] | 61 | document_list = (Element)desc_doc.importNode(config_doc_list, true);
|
---|
[5266] | 62 | } else {
|
---|
[28966] | 63 | document_list = desc_doc.createElement(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);
|
---|
[5266] | 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 | */
|
---|
[28966] | 74 | protected Element processMessage(Document response_doc, Element request) {
|
---|
[5266] | 75 |
|
---|
[28966] | 76 | Element response = response_doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
[5266] | 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
|
---|
[28966] | 84 | Element description = (Element)response_doc.importNode(this.description, false);
|
---|
[5266] | 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);
|
---|
[28966] | 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));
|
---|
[5266] | 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)) {
|
---|
[28966] | 106 | description.appendChild(response_doc.importNode(this.service_list, true));
|
---|
[5266] | 107 | } else if (info.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
|
---|
[28966] | 108 | description.appendChild(response_doc.importNode(metadata_list, true));
|
---|
[5266] | 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)) {
|
---|
[28966] | 113 | description.appendChild(response_doc.importNode(this.document_list, true));
|
---|
| 114 | } else if (info.equals(GSXML.LIBRARY_PARAM_ELEM+GSXML.LIST_MODIFIER)) {
|
---|
[26446] | 115 |
|
---|
[28966] | 116 | description.appendChild(response_doc.importNode(this.library_param_list, true));
|
---|
[5266] | 117 | }
|
---|
[26446] | 118 |
|
---|
[5266] | 119 | }
|
---|
| 120 | }
|
---|
| 121 | return response;
|
---|
| 122 | }
|
---|
[28966] | 123 | return super.processMessage(response_doc, request);
|
---|
[5266] | 124 |
|
---|
| 125 | }
|
---|
[25465] | 126 |
|
---|
[5266] | 127 | }
|
---|