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
Line 
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 */
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
35import org.apache.log4j.*;
36
37/**
38 * Represents a collection in Greenstone. A collection is an extension of
39 * a ServiceCluster - it has local data that the services use.
40 *
41 * @author <a href="mailto:[email protected]">Katherine Don</a>
42 * @version $Revision: 13994 $
43 * @see ModuleInterface
44 */
45public class Collection
46 extends ServiceCluster {
47
48 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.collection.Collection.class.getName());
49
50 /** is this collection being tidied */
51 protected boolean useBook = false;
52 /** is this collection public or private */
53 protected boolean is_public = true;
54 protected XMLTransformer transformer = null;
55 /** same as setClusterName */
56 public void setCollectionName(String name) {
57 setClusterName(name);
58 }
59
60 public Collection() {
61 super();
62 this.description = this.doc.createElement(GSXML.COLLECTION_ELEM);
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
78 if (this.site_home == null || this.cluster_name== null) {
79 logger.error("Collection: site_home and collection_name must be set before configure called!");
80 return false;
81 }
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 }
89 // process the metadata and display items
90 findAndLoadInfo(coll_config_xml, build_config_xml);
91
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 }
99
100 public boolean useBook() {
101 return useBook;
102 }
103
104 public boolean isPublic() {
105 return is_public;
106 }
107 /**
108 * load in the collection config file into a DOM Element
109 */
110 protected Element loadCollConfigFile() {
111
112 File coll_config_file = new File(GSFile.collectionConfigFile(this.site_home, this.cluster_name));
113
114 if (!coll_config_file.exists()) {
115 logger.error("Collection: couldn't configure collection: "+this.cluster_name+", "+coll_config_file+" does not exist");
116 return null;
117 }
118 // get the xml for both files
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 }
124 return coll_config_elem;
125
126 }
127
128 /**
129 * load in the collection build config file into a DOM Element
130 */
131 protected Element loadBuildConfigFile() {
132
133 File build_config_file = new File(GSFile.collectionBuildConfigFile(this.site_home, this.cluster_name));
134 if (!build_config_file.exists()) {
135 logger.error("Collection: couldn't configure collection: "+this.cluster_name+", "+build_config_file+" does not exist");
136 return null;
137 }
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 }
143 return build_config_elem;
144 }
145
146 /**
147 * find the metadata and display elems from the two config files and add it to the appropriate lists
148 */
149 protected boolean findAndLoadInfo(Element coll_config_xml,
150 Element build_config_xml){
151
152 // metadata
153 Element meta_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
154 addMetadata(meta_list);
155 meta_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
156 addMetadata(meta_list);
157
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);
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) {
165 resolveMacros(display_list);
166 addDisplayItems(display_list);
167 }
168
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
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 }
202 return true;
203
204 }
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 }
222 /**
223 * do a configure on only part of the collection
224 */
225 protected boolean configureSubset(String subset) {
226
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
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)) {
242 return findAndLoadInfo(coll_config_elem, build_config_elem);
243
244 }
245
246 logger.error("Collection: cant process system request, configure "+subset);
247 return false;
248 }
249
250}
251
252
253
254
Note: See TracBrowser for help on using the repository browser.