source: trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/Collection.java@ 13994

Last change on this file since 13994 was 13994, checked in by lh92, 17 years ago

Added code to read the pluginList from the collectConfig.xml. If tidy_html option is set then the tidy_option metadata is true

  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
RevLine 
[3235]1/*
2 * Collection.java
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
[3222]19package org.greenstone.gsdl3.collection;
20
21import org.greenstone.gsdl3.util.*;
22import org.greenstone.gsdl3.core.*;
23import org.greenstone.gsdl3.service.*;
24
25
26// java XML classes we're using
27import org.w3c.dom.Document;
28import org.w3c.dom.Node;
29import org.w3c.dom.Element;
30import org.w3c.dom.NodeList;
31
32import java.io.File;
33import java.util.HashMap;
34
[13123]35import org.apache.log4j.*;
36
[3222]37/**
[3468]38 * Represents a collection in Greenstone. A collection is an extension of
39 * a ServiceCluster - it has local data that the services use.
[3222]40 *
[3235]41 * @author <a href="mailto:[email protected]">Katherine Don</a>
42 * @version $Revision: 13994 $
[3222]43 * @see ModuleInterface
44 */
45public class Collection
[3468]46 extends ServiceCluster {
[3222]47
[13270]48 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.collection.Collection.class.getName());
[13123]49
[13994]50 /** is this collection being tidied */
51 protected boolean useBook = false;
[13860]52 /** is this collection public or private */
53 protected boolean is_public = true;
[4097]54 protected XMLTransformer transformer = null;
[3468]55 /** same as setClusterName */
[3222]56 public void setCollectionName(String name) {
[3468]57 setClusterName(name);
[3222]58 }
59
60 public Collection() {
[4942]61 super();
[4097]62 this.description = this.doc.createElement(GSXML.COLLECTION_ELEM);
[3222]63
64 }
65
66 /**
67 * Configures the collection.
68 *
69 * gsdlHome and collectionName must be set before configure is called.
70 *
71 * the file buildcfg.xml is located in gsdlHome/collect/collectionName
72 * collection metadata is obtained, and services loaded.
73 *
74 * @return true/false on success/fail
75 */
76 public boolean configure() {
77
[4097]78 if (this.site_home == null || this.cluster_name== null) {
[13123]79 logger.error("Collection: site_home and collection_name must be set before configure called!");
[3222]80 return false;
81 }
[4097]82
83 Element coll_config_xml = loadCollConfigFile();
84 Element build_config_xml = loadBuildConfigFile();
85
86 if (coll_config_xml==null||build_config_xml==null) {
87 return false;
88 }
[4942]89 // process the metadata and display items
90 findAndLoadInfo(coll_config_xml, build_config_xml);
91
[4097]92 // now do the services
93 Element service_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
94 configureServiceRack(service_list, coll_config_xml);
95
96 return true;
97
98 }
[13860]99
[13994]100 public boolean useBook() {
101 return useBook;
102 }
103
[13860]104 public boolean isPublic() {
105 return is_public;
106 }
[4097]107 /**
[4105]108 * load in the collection config file into a DOM Element
109 */
[4097]110 protected Element loadCollConfigFile() {
111
112 File coll_config_file = new File(GSFile.collectionConfigFile(this.site_home, this.cluster_name));
113
[3847]114 if (!coll_config_file.exists()) {
[13123]115 logger.error("Collection: couldn't configure collection: "+this.cluster_name+", "+coll_config_file+" does not exist");
[4097]116 return null;
[3222]117 }
[4097]118 // get the xml for both files
[9874]119 Document coll_config_doc = this.converter.getDOM(coll_config_file, CONFIG_ENCODING);
120 Element coll_config_elem = null;
121 if (coll_config_doc != null) {
122 coll_config_elem = coll_config_doc.getDocumentElement();
123 }
[4097]124 return coll_config_elem;
125
126 }
127
[4105]128 /**
129 * load in the collection build config file into a DOM Element
130 */
[4097]131 protected Element loadBuildConfigFile() {
[3847]132
[4097]133 File build_config_file = new File(GSFile.collectionBuildConfigFile(this.site_home, this.cluster_name));
[3847]134 if (!build_config_file.exists()) {
[13123]135 logger.error("Collection: couldn't configure collection: "+this.cluster_name+", "+build_config_file+" does not exist");
[4097]136 return null;
[3847]137 }
[9874]138 Document build_config_doc = this.converter.getDOM(build_config_file, CONFIG_ENCODING);
139 Element build_config_elem = null;
140 if (build_config_doc != null) {
141 build_config_elem = build_config_doc.getDocumentElement();
142 }
[4097]143 return build_config_elem;
144 }
145
[4105]146 /**
[4942]147 * find the metadata and display elems from the two config files and add it to the appropriate lists
[4105]148 */
[4942]149 protected boolean findAndLoadInfo(Element coll_config_xml,
150 Element build_config_xml){
[4097]151
[4942]152 // metadata
[3847]153 Element meta_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
[4097]154 addMetadata(meta_list);
[3847]155 meta_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
[4097]156 addMetadata(meta_list);
[3986]157
[4097]158 meta_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
159 GSXML.addMetadata(this.doc, meta_list, "httpPath", this.site_http_address+"/collect/"+this.cluster_name);
160 addMetadata(meta_list);
[4942]161
162 // display stuff
163 Element display_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
164 if (display_list != null) {
[13830]165 resolveMacros(display_list);
[4942]166 addDisplayItems(display_list);
167 }
[13860]168
[13994]169 //check whether the html are tidy or not
170 Element import_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.IMPORT_ELEM);
171 if (import_list != null) {
172 Element plugin_list = (Element)GSXML.getChildByTagName(import_list, GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
173 addPlugins(plugin_list);
174 if (plugin_list != null){
175 Element plugin_elem = (Element)GSXML.getNamedElement(plugin_list, GSXML.PLUGIN_ELEM, GSXML.NAME_ATT, "HTMLPlug");
176 if (plugin_elem != null) {
177 //get the option
178 Element option_elem = (Element)GSXML.getNamedElement(plugin_elem, GSXML.PARAM_OPTION_ELEM, GSXML.NAME_ATT, "-tidy_html");
179 if (option_elem != null) {
180 useBook = true;
181 }
182 }
183 }
184 }
185 meta_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
186 if (useBook == true)
187 GSXML.addMetadata(this.doc, meta_list, "tidyoption", "tidy");
188 else
189 GSXML.addMetadata(this.doc, meta_list, "tidyoption", "untidy");
190 addMetadata(meta_list);
191
[13860]192 // check whether we are public or not
193 if (meta_list != null) {
194 Element meta_elem = (Element) GSXML.getNamedElement(metadata_list, GSXML.METADATA_ELEM, GSXML.NAME_ATT, "public");
195 if (meta_elem != null) {
196 String value = GSXML.getValue(meta_elem).toLowerCase().trim();
197 if (value.equals("false")) {
198 is_public = false;
199 }
200 }
201 }
[3847]202 return true;
[4097]203
[3847]204 }
[13830]205
206 protected boolean resolveMacros(Element display_list) {
207 if (display_list==null) return false;
208 NodeList displaynodes = display_list.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
209 if (displaynodes.getLength()>0) {
210 String http_site = this.site_http_address;
211 String http_collection = this.site_http_address +"/collect/"+this.cluster_name;
212 for(int k=0; k<displaynodes.getLength(); k++) {
213 Element d = (Element) displaynodes.item(k);
214 String text = GSXML.getNodeText(d);
215 text = text.replaceAll("_httpsite_", http_site);
216 text = text.replaceAll("_httpcollection_", http_collection);
217 GSXML.setNodeText(d, text);
218 }
219 }
220 return true;
221 }
[4105]222 /**
223 * do a configure on only part of the collection
224 */
225 protected boolean configureSubset(String subset) {
[3222]226
[4105]227 // need the coll config files
228 Element coll_config_elem = loadCollConfigFile();
229 Element build_config_elem = loadBuildConfigFile();
230 if (coll_config_elem == null||build_config_elem == null) {
231 // wont be able to do any of teh requests
232 return false;
233 }
234
235 if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
236 Element service_rack_list = (Element)GSXML.getChildByTagName(build_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
237
238 return configureServiceRack(service_rack_list, coll_config_elem);
239 }
240
[13994]241 if (subset.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER) || subset.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER) || subset.equals(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER)) {
[4942]242 return findAndLoadInfo(coll_config_elem, build_config_elem);
[4105]243
244 }
245
[13123]246 logger.error("Collection: cant process system request, configure "+subset);
[4105]247 return false;
248 }
249
[3468]250}
[3222]251
252
253
254
Note: See TracBrowser for help on using the repository browser.