Changeset 5816
- Timestamp:
- 2003-11-10T14:25:51+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/collection/CollectionConfiguration.java
r5815 r5816 48 48 next_line = null; 49 49 } 50 CommandTokenizer tokenizer = new CommandTokenizer(command);50 CommandTokenizer tokenizer = new CommandTokenizer(command); 51 51 if(tokenizer.countTokens() >= 2) { 52 52 String temp = tokenizer.nextToken(); … … 68 68 } 69 69 else if(temp.equalsIgnoreCase("collectionmeta")) { 70 String meta_type = tokenizer.nextToken(); 70 71 temp = tokenizer.nextToken(); 71 if(temp.equalsIgnoreCase("collectionname")) { 72 // check for language 73 String language = ""; 74 if(temp.startsWith("[") && temp.endsWith("]")) { 75 language = temp.substring(temp.indexOf("=") + 1, temp.length() - 1); 72 76 temp = tokenizer.nextToken(); 73 if(temp.startsWith("[") && temp.endsWith("]")) { 74 String language = temp.substring(temp.indexOf("=") + 1, temp.length() - 1); 75 if(name == null || language.equalsIgnoreCase(Gatherer.dictionary.getLanguage())) { 76 name = Utility.decodeGreenstone(tokenizer.nextToken()); 77 } 78 79 // now we need to read in the whole of the entry - may span multiple lines, may be surrounded by single or double quotes 80 String start_string = temp.substring(0,1); 81 if ((start_string.equals("\"") || start_string.equals("\'")) && (!temp.endsWith(start_string) || temp.length()==1)) { 82 Gatherer.println("we have found a starting quote but not an ending quote, so now read lines until we get to an end quote"); 83 StringBuffer value_raw = new StringBuffer(temp.substring(1)); 84 int pos = value_raw.indexOf(start_string); 85 int old_pos = 0; 86 while (pos != -1 && value_raw.charAt(pos-1)=='\\') { 87 old_pos = pos+1; 88 pos = value_raw.indexOf(start_string, old_pos); 89 } 90 while(pos == -1) { 91 String next_line = br.readLine(); 92 if(next_line != null) { 93 value_raw.append(next_line); 94 value_raw.append(StaticStrings.NEW_LINE_CHAR); 77 95 } 78 } 79 else if(name == null) { 80 name = Utility.decodeGreenstone(temp); 81 } 82 if(name != null && name.startsWith("\"") && name.endsWith("\"")) { 83 name = name.substring(1, name.length() - 1); 84 } 85 } 86 else if(temp.equalsIgnoreCase("collectionextra")) { 87 // Normal case 88 temp = tokenizer.nextToken(); 89 ///ystem.err.println("Read: " + temp); 90 if(temp.startsWith("[") && temp.endsWith("]")) { 91 String language = temp.substring(temp.indexOf("=") + 1, temp.length() - 1); 92 ///ystem.err.println("Try to match " + language + " to " + Gatherer.dictionary.getLanguage()); 93 if(description == null || language.equalsIgnoreCase(Gatherer.dictionary.getLanguage())) { 94 description = Utility.decodeGreenstone(tokenizer.nextToken()); 95 ///ystem.err.println("Found language match, or first match: " + description); 96 } 97 } 98 else if(description == null){ 99 // Some of the collections floating around have collection extras which contain normal newlines, and so their initial description starts with " (the Command Tokenizer hasn't found a closing speech mark). This will cause an error message to be displayed for the collection. If we have read a collectionextra tag, but we have run out of tokens then we do a sneaky and start reading lines until we encounter a closing " 100 if(temp.startsWith(StaticStrings.SPEECH_CHARACTER) && (!temp.endsWith(StaticStrings.SPEECH_CHARACTER) || temp.length() ==1 )) { 101 ///ystem.err.println("Encountered a strange Collection Description. Doing my best to parse a sensible text block!"); 102 StringBuffer description_raw = new StringBuffer(""); 103 while(description_raw.indexOf(StaticStrings.SPEECH_CHARACTER) == -1) { 104 String next_line = br.readLine(); 105 if(next_line != null) { 106 description_raw.append(next_line); 107 description_raw.append(StaticStrings.NEW_LINE_CHAR); 108 } 109 next_line = null; 110 } 111 description = description_raw.substring(0, description_raw.lastIndexOf(StaticStrings.SPEECH_CHARACTER)); 112 description_raw = null; 113 } 114 else { 115 description = Codec.transform(temp, Codec.GREENSTONE_TO_TEXT); 116 } 117 } 118 if(description != null && description.startsWith(StaticStrings.SPEECH_CHARACTER) && description.endsWith(StaticStrings.SPEECH_CHARACTER)) { 119 description = description.substring(1, description.length() - 1); 120 } 121 } 122 } 96 next_line = null; 97 pos = value_raw.indexOf(start_string, old_pos); 98 while (pos != -1 && value_raw.charAt(pos-1)=='\\') { 99 old_pos = pos+1; 100 pos = value_raw.indexOf(start_string, old_pos); 101 } 102 } 103 104 temp = value_raw.substring(0, value_raw.lastIndexOf(start_string)); 105 value_raw = null; 106 107 } 108 109 // now we can work out which coll meta we are dealing with 110 if (meta_type.equalsIgnoreCase("collectionname")) { 111 if (name==null || language.equalsIgnoreCase(Gatherer.dictionary.getLanguage())) { 112 name= Utility.decodeGreenstone(temp); 113 } 114 115 } else if (meta_type.equalsIgnoreCase("collectionextra")) { 116 if (description == null|| language.equalsIgnoreCase(Gatherer.dictionary.getLanguage())) { 117 description = Utility.decodeGreenstone(temp); 118 // or should we use codec?? 119 // description = Codec.transform(temp, Codec.GREENSTONE_TO_TEXT); 120 } 121 } 122 language = null; 123 meta_type = null; 124 } // end of coll meta bit 123 125 temp = null; 124 } 126 } // if num tokens >= 2 125 127 tokenizer = null; 126 } 127 } 128 } // if command.length > 0 129 } // while 128 130 // just check a couple of things 129 131 if (search_types != null && build_type==null) { … … 135 137 fr.close(); 136 138 fr = null; 137 } 138 139 140 141 142 139 } // cfg file 140 ///ystem.err.println("Parsed collect.cfg"); 141 ///ystem.err.println("name = " + name); 142 ///ystem.err.println("creator = " + creator); 143 ///ystem.err.println("maintainer = " + maintainer); 144 ///ystem.err.println("description = " + description); 143 145 } 144 146 catch(Exception error) {
Note:
See TracChangeset
for help on using the changeset viewer.