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

Last change on this file since 5148 was 4942, checked in by kjdon, 21 years ago

some coll metadata is now displayItems instead, so the configuration and processing has to take that into account

  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 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: 4942 $
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("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(coll_config_file+" does not exist");
100 System.err.println("couldn't configure collection: "+this.cluster_name);
101 return null;
102 }
103 // get the xml for both files
104 Element coll_config_elem = this.converter.getDOM(coll_config_file, CONFIG_ENCODING).getDocumentElement();
105 return coll_config_elem;
106
107 }
108
109 /**
110 * load in the collection build config file into a DOM Element
111 */
112 protected Element loadBuildConfigFile() {
113
114 File build_config_file = new File(GSFile.collectionBuildConfigFile(this.site_home, this.cluster_name));
115 if (!build_config_file.exists()) {
116 System.err.println(build_config_file+" does not exist");
117 System.err.println("couldn't configure collection: "+this.cluster_name);
118 return null;
119 }
120 Element build_config_elem = this.converter.getDOM(build_config_file, CONFIG_ENCODING).getDocumentElement();
121
122 return build_config_elem;
123 }
124
125 /**
126 * find the metadata and display elems from the two config files and add it to the appropriate lists
127 */
128 protected boolean findAndLoadInfo(Element coll_config_xml,
129 Element build_config_xml){
130
131 // metadata
132 Element meta_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
133 addMetadata(meta_list);
134 meta_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
135 addMetadata(meta_list);
136
137 meta_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
138 GSXML.addMetadata(this.doc, meta_list, "httpPath", this.site_http_address+"/collect/"+this.cluster_name);
139 addMetadata(meta_list);
140
141 // display stuff
142 Element display_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
143 if (display_list != null) {
144 addDisplayItems(display_list);
145 }
146 return true;
147
148 }
149 /**
150 * do a configure on only part of the collection
151 */
152 protected boolean configureSubset(String subset) {
153
154 // need the coll config files
155 Element coll_config_elem = loadCollConfigFile();
156 Element build_config_elem = loadBuildConfigFile();
157 if (coll_config_elem == null||build_config_elem == null) {
158 // wont be able to do any of teh requests
159 return false;
160 }
161
162 if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
163 Element service_rack_list = (Element)GSXML.getChildByTagName(build_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
164
165 return configureServiceRack(service_rack_list, coll_config_elem);
166 }
167
168 if (subset.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER) || subset.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER)) {
169 return findAndLoadInfo(coll_config_elem, build_config_elem);
170
171 }
172
173 System.err.println("ServiceCluster: cant process system request, configure "+subset);
174 return false;
175 }
176
177}
178
179
180
181
Note: See TracBrowser for help on using the repository browser.