source: trunk/gli/src/org/greenstone/gatherer/collection/BasicCollectionConfiguration.java@ 6056

Last change on this file since 6056 was 6051, checked in by jmt12, 21 years ago

Here is the result of sixteen hours work over the weekend. I'm too tired to comment them all separately, but here are some of the highlights:
Rewrote how the 'base on collection' method actually retrieves and updates the collection configuration - ensuring the CDM.CollectionConfiguration class is used instead of the retarded Collection.CollectionConfiguration (which coincidently has had a name change to BasicCollectionConfiguration). Went through code search for places where the two versions had been confused. Rewrote large swathes of GDMDocument so as to differentiate between normal and extracted metadata - an attempt to prevent the snowballing extracted metadata problem. Fixed problem where GLI was correctly recieving the last few lines of an external process. The collection shortname is no longer visible, nor is the confusing double name for metadata elements. Also coloured folders in the trees are kaput. The users email is now saved as part of the GLI configuration and is used as appropriate to fill out collection fields. There are new options on the right click menus over trees to allow the expansion and collapsing of folders. 'Show Files' now shows all types (or at least 6 types) of image properly (arg, the plagues of copy and paste). 'Based On' collections are public, plugin list automatically moves to next entry if plugin removed (I guess we should do the same in every other screen?) and metadata arguments in plugins/classifiers are no longer editable. There are about a dozen other small things, but I can't remember them. Hope I remembered to set all of the files to UNIX line-endings.

  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.collection;
38
39import java.io.*;
40import org.greenstone.gatherer.Gatherer;
41import org.greenstone.gatherer.cdm.CommandTokenizer;
42import org.greenstone.gatherer.msm.MSMUtils;
43import org.greenstone.gatherer.util.Codec;
44import org.greenstone.gatherer.util.StaticStrings;
45import org.greenstone.gatherer.util.Utility;
46import org.w3c.dom.*;
47
48/** This class provides access to a collection configuration file. This version accepts either a valid xml document or a historical collect.cfg file. */
49public class BasicCollectionConfiguration
50 implements Comparable {
51
52 private Element creator_element;
53 private Element description_element;
54 private Element maintainer_element;
55 private Element name_element;
56 private File file;
57 private String creator;
58 private String description;
59 private String maintainer;
60 private String name;
61
62 public BasicCollectionConfiguration(File file) {
63 this.file = file;
64 try {
65 String filename = file.getName().toLowerCase();
66 if(filename.endsWith(".xml")) {
67 // This is where G3 compliant code will one day live
68 }
69 else if(filename.endsWith(".cfg")) {
70 FileReader fr = new FileReader(file);
71 BufferedReader br = new BufferedReader(fr);
72 String command = null;
73 while((command = br.readLine()) != null) {
74 if(command.length() > 0) {
75 // We have to test the end of command for the special character '\'. If found, remove it and append the next line, then repeat.
76 while(command.trim().endsWith("\\")) {
77 command = command.substring(0, command.lastIndexOf("\\"));
78 String next_line = br.readLine();
79 if(next_line != null) {
80 command = command + next_line;
81 }
82 next_line = null;
83 }
84 CommandTokenizer tokenizer = new CommandTokenizer(command, br);
85 String command_type_str = tokenizer.nextToken().toLowerCase();
86 if(command_type_str == null) {
87 // Bad command. Do nothing
88 }
89 else if(command_type_str.equals(StaticStrings.COLLECTIONMETADATA_CREATOR_STR)) {
90 creator = tokenizer.nextToken();
91 }
92 else if(command_type_str.equals(StaticStrings.COLLECTIONMETADATA_MAINTAINER_STR)) {
93 maintainer = tokenizer.nextToken();
94 }
95 else if(command_type_str.equalsIgnoreCase(StaticStrings.COLLECTIONMETADATA_STR)) {
96 String meta_type_str = tokenizer.nextToken();
97 String value_str = tokenizer.nextToken();
98 // check for language
99 String language_str = StaticStrings.ENGLISH_LANGUAGE_STR; // assume the no-lang ones are english, but we shouldn't really do this.
100 if(meta_type_str != null && value_str != null) {
101 meta_type_str = meta_type_str.toLowerCase();
102 if(value_str.startsWith(StaticStrings.LBRACKET_CHARACTER) && value_str.endsWith(StaticStrings.RBRACKET_CHARACTER)) {
103 language_str = value_str.substring(value_str.indexOf(StaticStrings.EQUALS_CHARACTER) + 1, value_str.length() - 1);
104 language_str = language_str.toLowerCase();
105 value_str = tokenizer.nextToken();
106 }
107 // now we can work out which coll meta we are dealing with
108 if (meta_type_str.equals(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR)) {
109 // If this is the first collection title found, then use it, otherwise search for one that more closely matches our choosen interface language
110 if (name == null || language_str.equals(Gatherer.dictionary.getLanguage())) {
111 name = Codec.transform(value_str, Codec.GREENSTONE_TO_TEXT);
112 }
113 }
114 else if (meta_type_str.equals(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR)) {
115 // Again we are either looking for the first description, then after that a language specific one
116 if (description == null || language_str.equals(Gatherer.dictionary.getLanguage())) {
117 description = Codec.transform(value_str, Codec.GREENSTONE_TO_TEXT);
118 }
119 }
120 }
121 language_str = null;
122 value_str = null;
123 meta_type_str = null;
124 } // end of coll meta bit
125 command_type_str = null;
126 tokenizer = null;
127 } // if command.length > 0
128 } // while
129 command = null;
130 br.close();
131 fr.close();
132 br = null;
133 fr = null;
134 } // cfg file
135 ///ystem.err.println("Parsed collect.cfg");
136 ///ystem.err.println("name = " + name);
137 ///ystem.err.println("creator = " + creator);
138 ///ystem.err.println("maintainer = " + maintainer);
139 ///ystem.err.println("description = " + description);
140 }
141 catch(Exception error) {
142 Gatherer.println("Error in CollectionConfiguration.<init>(): " + error);
143 Gatherer.printStackTrace(error);
144 }
145 }
146
147 /** Compare this configuration to another for ordering, which essentially compares two strings for ordering.
148 * @param other the other Object which is presumably another basic collection configuration
149 * @return an integer which is either <0, 0 or >0 if this configuration is naturally less than, equal to or greater than the target object
150 */
151 public int compareTo(Object other) {
152 if(other == null) {
153 return -1;
154 }
155 return toString().compareTo(other.toString());
156 }
157
158 public boolean equals(Object other) {
159 return (compareTo(other) == 0);
160 }
161
162 /** Retrieve the creators email for this collection.
163 * @return a String
164 */
165 public String getCreator() {
166 String result = StaticStrings.EMPTY_STR;
167 if(creator_element != null) {
168 result = MSMUtils.getValue(creator_element);
169 }
170 else if(creator != null) {
171 result = creator;
172 }
173 return result;
174 }
175
176 public String getDescription() {
177 String result = StaticStrings.EMPTY_STR;
178 if(description_element != null) {
179 result = MSMUtils.getValue(description_element);
180 }
181 else if(description != null) {
182 result = description;
183 }
184 return result;
185 }
186
187 public File getFile() {
188 return file;
189 }
190
191 public String getMaintainer() {
192 String result = StaticStrings.EMPTY_STR;
193 if(maintainer_element != null) {
194 result = MSMUtils.getValue(maintainer_element);
195 }
196 else if(maintainer != null) {
197 result = maintainer;
198 }
199 return result;
200 }
201
202 public String getName() {
203 String result = StaticStrings.EMPTY_STR;
204 if(name_element != null) {
205 result = MSMUtils.getValue(name_element);
206 }
207 else if(name != null) {
208 result = name;
209 }
210 return result;
211 }
212
213 /** Retrieve the short name for this collection which, given this current file is in <col_name>/etc/collect.cfg, is the name of this file's parent file's parent.
214 * @return the short name of this collection as a String
215 */
216 /*
217 public String getShortName() {
218 return file.getParentFile().getParentFile().getName();
219 }
220 */
221
222 /** Display the title for this collection. */
223 public String toString() {
224 return getName();
225 }
226}
Note: See TracBrowser for help on using the repository browser.