Changeset 6147
- Timestamp:
- 2003-12-08T14:20:49+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/collection/BasicCollectionConfiguration.java
r6051 r6147 48 48 /** This class provides access to a collection configuration file. This version accepts either a valid xml document or a historical collect.cfg file. */ 49 49 public class BasicCollectionConfiguration 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 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 177 String result = StaticStrings.EMPTY_STR; 178 178 if(description_element != null) { 179 179 result = MSMUtils.getValue(description_element); 180 180 } 181 181 else if(description != null) { 182 183 } 184 return result; 185 186 187 188 189 190 191 182 result = description; 183 } 184 return result; 185 } 186 187 public File getFile() { 188 return file; 189 } 190 191 public String getMaintainer() { 192 192 String result = StaticStrings.EMPTY_STR; 193 193 if(maintainer_element != null) { 194 194 result = MSMUtils.getValue(maintainer_element); 195 195 } 196 196 else if(maintainer != null) { 197 198 } 199 return result; 200 201 202 197 result = maintainer; 198 } 199 return result; 200 } 201 202 public String getName() { 203 203 String result = StaticStrings.EMPTY_STR; 204 204 if(name_element != null) { 205 205 result = MSMUtils.getValue(name_element); 206 206 } 207 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() { 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 public String getShortName() { 218 217 return file.getParentFile().getParentFile().getName(); 219 } 220 */ 221 222 /** Display the title for this collection. */ 223 public String toString() { 224 return getName(); 225 } 218 } 219 220 /** Display the title for this collection. */ 221 public String toString() { 222 return getName() + StaticStrings.SPACE_CHARACTER + StaticStrings.OPEN_PARENTHESIS_CHARACTER + getShortName() + StaticStrings.CLOSE_PARENTHESIS_CHARACTER; 223 } 226 224 }
Note:
See TracChangeset
for help on using the changeset viewer.