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

Last change on this file since 9874 was 9874, checked in by kjdon, 19 years ago

merged from branch ant-install-branch: merge 1

  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 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
35/**
36 * Represents a collection in Greenstone. A collection is an extension of
37 * a ServiceCluster - it has local data that the services use.
38 *
39 * @author <a href="mailto:[email protected]">Katherine Don</a>
40 * @version $Revision: 9874 $
41 * @see ModuleInterface
42 */
43public class Collection
44 extends ServiceCluster {
45
46 protected XMLTransformer transformer = null;
47 /** same as setClusterName */
48 public void setCollectionName(String name) {
49 setClusterName(name);
50 }
51
52 public Collection() {
53 super();
54 this.description = this.doc.createElement(GSXML.COLLECTION_ELEM);
55
56 }
57
58 /**
59 * Configures the collection.
60 *
61 * gsdlHome and collectionName must be set before configure is called.
62 *
63 * the file buildcfg.xml is located in gsdlHome/collect/collectionName
64 * collection metadata is obtained, and services loaded.
65 *
66 * @return true/false on success/fail
67 */
68 public boolean configure() {
69
70 if (this.site_home == null || this.cluster_name== null) {
71 System.err.println("Collection: site_home and collection_name must be set before configure called!");
72 return false;
73 }
74
75 Element coll_config_xml = loadCollConfigFile();
76 Element build_config_xml = loadBuildConfigFile();
77
78 if (coll_config_xml==null||build_config_xml==null) {
79 return false;
80 }
81 // process the metadata and display items
82 findAndLoadInfo(coll_config_xml, build_config_xml);
83
84 // now do the services
85 Element service_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
86 configureServiceRack(service_list, coll_config_xml);
87
88 return true;
89
90 }
91 /**
92 * load in the collection config file into a DOM Element
93 */
94 protected Element loadCollConfigFile() {
95
96 File coll_config_file = new File(GSFile.collectionConfigFile(this.site_home, this.cluster_name));
97
98 if (!coll_config_file.exists()) {
99 System.err.println("Collection: couldn't configure collection: "+this.cluster_name+", "+coll_config_file+" does not exist");
100 return null;
101 }
102 // get the xml for both files
103 Document coll_config_doc = this.converter.getDOM(coll_config_file, CONFIG_ENCODING);
104 Element coll_config_elem = null;
105 if (coll_config_doc != null) {
106 coll_config_elem = coll_config_doc.getDocumentElement();
107 }
108 return coll_config_elem;
109
110 }
111
112 /**
113 * load in the collection build config file into a DOM Element
114 */
115 protected Element loadBuildConfigFile() {
116
117 File build_config_file = new File(GSFile.collectionBuildConfigFile(this.site_home, this.cluster_name));
118 if (!build_config_file.exists()) {
119 System.err.println("Collection: couldn't configure collection: "+this.cluster_name+", "+build_config_file+" does not exist");
120 return null;
121 }
122 Document build_config_doc = this.converter.getDOM(build_config_file, CONFIG_ENCODING);
123 Element build_config_elem = null;
124 if (build_config_doc != null) {
125 build_config_elem = build_config_doc.getDocumentElement();
126 }
127 return build_config_elem;
128 }
129
130 /**
131 * find the metadata and display elems from the two config files and add it to the appropriate lists
132 */
133 protected boolean findAndLoadInfo(Element coll_config_xml,
134 Element build_config_xml){
135
136 // metadata
137 Element meta_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
138 addMetadata(meta_list);
139 meta_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
140 addMetadata(meta_list);
141
142 meta_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
143 GSXML.addMetadata(this.doc, meta_list, "httpPath", this.site_http_address+"/collect/"+this.cluster_name);
144 addMetadata(meta_list);
145
146 // display stuff
147 Element display_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
148 if (display_list != null) {
149 addDisplayItems(display_list);
150 }
151 return true;
152
153 }
154 /**
155 * do a configure on only part of the collection
156 */
157 protected boolean configureSubset(String subset) {
158
159 // need the coll config files
160 Element coll_config_elem = loadCollConfigFile();
161 Element build_config_elem = loadBuildConfigFile();
162 if (coll_config_elem == null||build_config_elem == null) {
163 // wont be able to do any of teh requests
164 return false;
165 }
166
167 if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
168 Element service_rack_list = (Element)GSXML.getChildByTagName(build_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
169
170 return configureServiceRack(service_rack_list, coll_config_elem);
171 }
172
173 if (subset.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER) || subset.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER)) {
174 return findAndLoadInfo(coll_config_elem, build_config_elem);
175
176 }
177
178 System.err.println("Collection: cant process system request, configure "+subset);
179 return false;
180 }
181
182}
183
184
185
186
Note: See TracBrowser for help on using the repository browser.