Changeset 5153
- Timestamp:
- 2003-08-18T13:55:21+12:00 (21 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/msm/parsers/GreenstoneMetadataParser.java
r5070 r5153 47 47 import org.greenstone.gatherer.msm.MSMUtils; 48 48 import org.greenstone.gatherer.util.DecodeHTMLReader; 49 import org.greenstone.gatherer.util.StaticStrings; 49 50 import org.greenstone.gatherer.util.Utility; 50 51 import org.greenstone.gatherer.valuetree.GValueModel; … … 281 282 if(metadatum != null) { 282 283 // 6c. Try to add metadata. If there is no matching metadata element: 283 ElementWrapper element = Gatherer.c_man.getCollection().msm.getElement(metadatum.element );284 ElementWrapper element = Gatherer.c_man.getCollection().msm.getElement(metadatum.element, true); 284 285 // Arg. The element returned may come from the Greenstone dls, which of course should never be involved during importing. To solve check the namespace isn't "" and if it is nullify the element. Nullify. NULLIFY, Bwuhahahaha... 285 286 if(element != null && element.getNamespace().equals("")) { … … 905 906 /** Retrieve the value associated with a certain index. This is harder than it first sounds as you must take into account the parent indexes of this one. 906 907 * @param index The index whose value you wish to calculate, as a <strong>String</strong>. 907 * @return The fully quantified path to the value that matches index, also as a <strong>String</strong>. Delimitiation between subject layers is denoted by the character '/'908 * @return The fully quantified path to the value that matches index, also as a <strong>String</strong>. Delimitiation between subject layers is denoted by the string "\\" 908 909 */ 909 910 public String getValue(String index) { … … 924 925 ///ystem.err.println("\tHierarchy information required -->"); 925 926 value.append(getValue(index.substring(0, dot_index))); 926 value.append( "\\");927 value.append(StaticStrings.ESCAPE_STR + StaticStrings.ESCAPE_STR); 927 928 ///ystem.err.println("\t<-- Hierarchy information complete"); 928 929 } -
trunk/gli/src/org/greenstone/gatherer/util/StaticStrings.java
r5084 r5153 33 33 public class StaticStrings { 34 34 static final public char NEW_LINE_CHARACTER = '\n'; 35 static final public char STAR_CHAR = '*'; 35 36 static final public String ALLFIELDS_STR = "allfields"; 36 37 static final public String ARCPLUG_STR = "ArcPlug"; … … 38 39 static final public String AT_CHARACTER = "@"; 39 40 static final public String CCS_STR = "ccs"; 41 static final public String CLASSES_FOLDER = "classes"; 40 42 static final public String CLASSIFY_ELEMENT = "Classify"; 41 43 static final public String CLASSIFY_STR = "classify"; … … 66 68 static final public String CUSTOM_ATTRIBUTE = "custom"; 67 69 static final public String DEBUG_ARGUMENT = "-debug"; 70 static final public String DICTIONARY_FILENAME = "dictionary"; 68 71 static final public String EMPTY_STR = ""; 69 72 static final public String ENGLISH_LANGUAGE_STR = "en"; 70 73 static final public String ENUM_STR = "enum"; 74 static final public String ESCAPE_PATTERN = "\\\\"; 75 static final public String ESCAPE_STR = "\\"; 71 76 static final public String EXCLAIMATION_CHARACTER = "!"; 72 77 static final public String EXCLUDE_STR = "exclude"; … … 77 82 static final public String FORMAT_STR = "format"; 78 83 static final public String GSDL_ARGUMENT = "-gsdl"; 84 static final public String HIERARCHY_ATTRIBUTE = "hierarchy"; 79 85 static final public String HIERARCHY_STR = "hierarchy"; 80 86 static final public String HTTP_PROTOCOL_STR = "http://"; 81 87 static final public String HELP_ARGUMENT = "-help"; 88 static final public String IMPORT_FOLDER = "import"; 82 89 static final public String INCLUDE_STR = "include"; 83 90 static final public String INDEX_ELEMENT = "Index"; … … 96 103 static final public String LANGUAGES_STR = "languages"; 97 104 static final public String LBRACKET_CHARACTER = "["; 105 static final public String LBRACKET_PATTERN = "\\["; 98 106 static final public String LEVEL_ATTRIBUTE = "level"; 99 107 static final public String LEVELS_ELEMENT = "Levels"; … … 103 111 static final public String LOAD_ARGUMENT = "-load"; 104 112 static final public String METADATA_ARGUMENT = "-metadata"; 113 static final public String METADATA_SET_EXTENSION = ".mds"; 105 114 static final public String METADATA_STR = "metadata"; 106 115 static final public String METADATA_TYPE_STR = "metadatum"; // Because -someone- complained we have metadata (plural) and metadatum (singular) confused... … … 109 118 static final public String MGPP_ATTRIBUTE = "mgpp_enabled"; 110 119 static final public String MINUS_CHARACTER = "-"; 120 static final public String MODEL_COLLECTION_NAME = "modelcol"; 111 121 static final public String NAME_ATTRIBUTE = "name"; 112 122 static final public String NEWLINE_CHARACTER = "\\"; … … 118 128 static final public String PLUGIN_ELEMENT = "Plugin"; 119 129 static final public String PLUGIN_STR = "plugin"; 130 static final public String PROPERTIES_FILE_EXTENSION = ".properties"; 120 131 static final public String PSEUDO_COLLECTCONFIGURATION_XML = "xml/CollectionConfig.xml"; 121 132 static final public String QUOTE_CHARACTER = "\""; 122 133 static final public String RBRACKET_CHARACTER = "]"; 134 static final public String RBRACKET_PATTERN = "\\]"; 123 135 static final public String RECPLUG_STR = "RecPlug"; 124 136 static final public String SEARCHTYPE_ELEMENT = "SearchType"; … … 127 139 static final public String SEPARATOR_CHARACTER = "/"; 128 140 static final public String SKIN_ARGUMENT = "-skinlf"; 141 static final public String SINGLE_ESCAPE_ONLY_PATTERN = "[^\\\\]+\\\\[^\\\\]+"; 129 142 static final public String SPACE_CHARACTER = " "; 130 143 static final public String SPECIAL_ATTRIBUTE = "special"; … … 143 156 static final public String TRUE_STR = "true"; 144 157 static final public String TYPE_ATTRIBUTE = "type"; 158 static final public String UNDERSCORE_CHARACTER = "_"; 145 159 static final public String UNKNOWN_ELEMENT = "Unknown"; 160 static final public String USE_METADATA_FILES_ARGUMENT = "use_metadata_files"; 146 161 static final public String URL_SEPARATOR_CHARACTER = "/"; 147 162 static final public String VALUE_ATTRIBUTE = "value"; 163 static final public String VALUE_TREE_ATTRIBUTE = "remember_values"; 148 164 } -
trunk/gli/src/org/greenstone/gatherer/util/Utility.java
r4933 r5153 53 53 */ 54 54 public class Utility { 55 static final public Dimension BUTTON_SIZE = new Dimension(160, 35); 56 static final public Dimension LABEL_SIZE = new Dimension(125, 35); 55 57 /** The default size of a gatherer progress bar, in either the download view or the build view. */ 56 58 static final public Dimension PROGRESS_BAR_SIZE = new Dimension(580,65); … … 102 104 static final public String GREENSTONEDIRECTORYMETADATA_TEMPLATE = "xml/metadata.xml"; 103 105 /** Definition of an important directory name, in this case the private web cache directory for the collection. */ 104 static final public String GCACHE_DIR = " gcache" + File.separator;106 static final public String GCACHE_DIR = "cache" + File.separator; 105 107 static final public String GLI_ARCHIVE = "GLI.jar"; 106 108 /** Definition of an important directory name, in this case the location of help documentation. */ 107 109 static final public String HELP_DIR = BASE_DIR + "help" + File.separator; 108 110 /** Definition of an important directory name, in this case the import directory for the collection. */ 109 static final public String IMPORT_DIR = " gimport" + File.separator;111 static final public String IMPORT_DIR = "import" + File.separator; 110 112 /** Definition of an important directory name, in this case the index directory for the collection. */ 111 113 static final public String INDEX_DIR = "index" + File.separator; … … 117 119 /** Definition of an important directory name, in this case the location of the default metadata sets. */ 118 120 static final public String METADATA_DIR = BASE_DIR + "metadata" + File.separator; 119 static final public String METADATA_EXTRACTED = "extracted.mds";120 121 /** The location the gatherer expects to find metadata set information. */ 121 122 static final public String METADATA_SET_TEMPLATE = "xml/template.mds"; … … 123 124 static final public String METADATA_XML = "metadata.xml"; 124 125 static final public String NAME_ELEMENT = "Name"; 125 /** Definition of an important directory name, in this case the import directory for the collection. */126 static final public String OLD_IMPORT_DIR = "import" + File.separator;127 126 /** The default name of the perl executable under unix. */ 128 127 static final public String PERL_EXECUTABLE_UNIX = "perl"; … … 196 195 return new TreePath(temp); 197 196 } 198 /** Decodes a string of text so its safe to use in a Greenstone configuration file. Esentially replaces "\n" with a newline.199 * @param raw The <strong>String</strong> before decoding, read from the configuration file..200 * @return A <strong>String</strong> ready to be placed in a component.201 */202 static public String decodeGreenstone(String raw) {203 raw = raw.replaceAll("'", "\'");204 raw = raw.replaceAll(">", ">");205 raw = raw.replaceAll("<", "<");206 raw = raw.replaceAll(""", "\"");207 raw = raw.replaceAll("'", "\'");208 raw = raw.replaceAll("\\\\n", "\n");209 return raw;210 }211 197 /** Takes a rfc2616 'safe' String and translates it back into its 'unsafe' form. Basically the native c wget decode_string() function, but without pointer stuff. If searches through the String looking for the pattern %xy where x and y are hexidecimal digits and where xy maps to a character.<BR> If x or y are not hexidecimal or % is followed by a \0 then the pattern is left as is. 212 198 * @param encoded The url-safe <strong>String</strong> to be decoded. … … 263 249 * @return A <strong>String</strong> which is safe to write to the configuration file. 264 250 */ 251 static final private char AMPERSTAMP_CHAR = '&'; 252 static final private char ESCAPE_CHAR = '\\'; 253 static final private char GREATER_THAN_CHAR = '>'; 254 static final private char LESS_THAN_CHAR = '<'; 255 static final private char NEWLINE_CHAR = '\n'; 256 static final private char QUOTE_CHAR = '\''; 257 static final private char SPEECH_CHAR = '\"'; 258 static final private String ENCODED_AMPERSTAMP_STR = "&"; 259 static final private String ENCODED_GREATER_THAN_STR = ">"; 260 static final private String ENCODED_LESS_THAN_STR = "<"; 261 static final private String ENCODED_SPEECH_STR = """; 262 static final private String ESCAPED_NEWLINE_STR = "\\n"; 263 264 /** Decodes a string of text so its safe to use in a Greenstone configuration file. Esentially replaces "\n" with a newline. 265 * @param raw The <strong>String</strong> before decoding, read from the configuration file.. 266 * @return A <strong>String</strong> ready to be placed in a component. 267 */ 268 static public String decodeGreenstone(String raw) { 269 raw = raw.replaceAll("'", "\'"); 270 raw = raw.replaceAll(">", ">"); 271 raw = raw.replaceAll("<", "<"); 272 raw = raw.replaceAll(""", "\""); 273 raw = raw.replaceAll("'", "\'"); 274 raw = raw.replaceAll("\\\\n", "\n"); 275 return raw; 276 } 277 265 278 static public String encodeGreenstone(String raw) { 266 raw = raw.replaceAll("<", "<"); 267 raw = raw.replaceAll(">", ">"); 268 return raw.replaceAll("\n", "\\\\n"); 279 // Once again regex fails to provide the power necessary for me to change strings. What I need to do is replace "<" and ">" with "<" and ">", and replace "\<" and "\>" with "<" and ">". 280 StringBuffer processed = new StringBuffer(); 281 int index = 0; 282 while(index < raw.length()) { 283 char c = raw.charAt(index); 284 switch(c) { 285 // Replace a normal new line character with "\n" 286 case NEWLINE_CHAR: 287 processed.append(ESCAPED_NEWLINE_STR); 288 break; 289 // Replace "\<" with "<", or with "\<" if this is for XML. Similar requirements for "\>". 290 case ESCAPE_CHAR: 291 if(index + 1 < raw.length()) { 292 char d = raw.charAt(index + 1); 293 if(d == LESS_THAN_CHAR) { 294 processed.append(LESS_THAN_CHAR); 295 index++; 296 break; 297 } 298 else if(d == GREATER_THAN_CHAR) { 299 processed.append(GREATER_THAN_CHAR); 300 index++; 301 break; 302 } 303 } 304 // I have no idea how this would happen, but I better watch for it anyway 305 processed.append(c); 306 break; 307 // Replace "<" with "<" 308 case LESS_THAN_CHAR: 309 processed.append(ENCODED_LESS_THAN_STR); 310 break; 311 // Replace ">" with ">" 312 case GREATER_THAN_CHAR: 313 processed.append(ENCODED_GREATER_THAN_STR); 314 break; 315 default: 316 processed.append(c); 317 } 318 index++; 319 } 320 return processed.toString(); 321 } 322 /** When retrieve text for, or from the collect.cfg file it may contain characters that can't go into a DOM such as "<" and ">". We also might already have encoded versions "<" and ">". Thus we must encode the former, and double encode the latter. */ 323 static public String encodeXML(String raw) { 324 StringBuffer processed = new StringBuffer(); 325 int index = 0; 326 while(index < raw.length()) { 327 char c = raw.charAt(index); 328 switch(c) { 329 case GREATER_THAN_CHAR: 330 processed.append(ENCODED_GREATER_THAN_STR); 331 break; 332 case LESS_THAN_CHAR: 333 processed.append(ENCODED_LESS_THAN_STR); 334 break; 335 case AMPERSTAMP_CHAR: 336 processed.append(ENCODED_AMPERSTAMP_STR); 337 break; 338 default: 339 processed.append(c); 340 } 341 index++; 342 } 343 return processed.toString(); 269 344 } 270 345 -
trunk/gli/src/org/greenstone/gatherer/valuetree/GValueModel.java
r4686 r5153 42 42 import org.greenstone.gatherer.msm.MetadataSetManager; 43 43 import org.greenstone.gatherer.msm.MSMUtils; 44 import org.greenstone.gatherer.util.StaticStrings; 44 45 import org.greenstone.gatherer.util.SynchronizedTreeModelTools; 45 46 import org.greenstone.gatherer.util.Utility; … … 80 81 } 81 82 82 /** Value may include path ie news /newssw */83 /** Value may include path ie news\newssw */ 83 84 public GValueNode addValue(String value) { 84 StringTokenizer tokenizer = new StringTokenizer(value, "\\"); 85 GValueNode subject = (GValueNode) root; 86 while(tokenizer.hasMoreTokens() && subject != null) { 87 String token = tokenizer.nextToken(); 88 subject = addValue(token, subject, null); 89 ///ystem.err.println("Found or created a node " + token); 90 } 91 return subject; 85 try { 86 // Remove any single escape characters 87 value = stripEscapes(value); 88 // Now we can tokenize the string using the double escaped characters 89 StringTokenizer tokenizer = new StringTokenizer(value, StaticStrings.ESCAPE_STR); 90 GValueNode subject = (GValueNode) root; 91 while(tokenizer.hasMoreTokens() && subject != null) { 92 String token = tokenizer.nextToken(); 93 subject = addValue(token, subject, null); 94 } 95 return subject; 96 } 97 catch (Exception error) { 98 error.printStackTrace(); 99 } 100 return null; 101 } 102 103 /** Replace all current double escapes with single escapes, and remove all currently single escapes. */ 104 static final private char ESCAPE_CHARACTER = '\\'; 105 private String stripEscapes(String raw) { 106 StringBuffer processed_buffer = new StringBuffer(); 107 int raw_length = raw.length(); 108 for(int i = 0; i < raw_length; i++) { 109 char c = raw.charAt(i); 110 switch(c) { 111 case ESCAPE_CHARACTER: 112 if(i < raw_length - 1 && raw.charAt(i+1) == ESCAPE_CHARACTER) { 113 i = i + 1; 114 processed_buffer.append(c); 115 } 116 break; 117 default: 118 processed_buffer.append(c); 119 } 120 } 121 return processed_buffer.toString(); 92 122 } 93 123 … … 245 275 } 246 276 277 /** 247 278 public void updateValue(String new_value, String old_value) { 248 279 ///ystem.err.println("Updating '" + old_value + "' to '" + new_value + "'"); … … 254 285 } 255 286 } 287 */ 256 288 257 289 /** Called to update a certain value of metadata within a specific … … 294 326 } 295 327 value = value.substring(next.toString().length()); 296 if(value.startsWith( "\\")) {297 value = value.substring( 1);328 if(value.startsWith(StaticStrings.ESCAPE_STR + StaticStrings.ESCAPE_STR)) { 329 value = value.substring(2); 298 330 index = getHIndex(next, value, index); 299 331 } -
trunk/gli/src/org/greenstone/gatherer/valuetree/GValueNode.java
r4407 r5153 35 35 *######################################################################## 36 36 */ 37 38 39 40 41 42 43 37 package org.greenstone.gatherer.valuetree; 44 38 /** … … 61 55 import org.greenstone.gatherer.msm.ElementWrapper; 62 56 import org.greenstone.gatherer.msm.MSMUtils; 57 import org.greenstone.gatherer.util.StaticStrings; 63 58 import org.greenstone.gatherer.util.Utility; 64 59 import org.w3c.dom.Document; … … 188 183 GValueNode node = (GValueNode) getParent(); 189 184 while(node != null && !node.getElement().getNodeName().equalsIgnoreCase("AssignedValues")) { 190 path.insert(0, "\\"); 191 path.insert(0, node.toString()); 185 path.insert(0, StaticStrings.ESCAPE_STR + StaticStrings.ESCAPE_STR); 186 String temp = node.toString(); 187 temp = temp.replaceAll(StaticStrings.LBRACKET_PATTERN, StaticStrings.ESCAPE_PATTERN + StaticStrings.LBRACKET_PATTERN); 188 temp = temp.replaceAll(StaticStrings.RBRACKET_PATTERN, StaticStrings.ESCAPE_PATTERN + StaticStrings.RBRACKET_PATTERN); 189 path.insert(0, temp); 192 190 node = (GValueNode) node.getParent(); 193 191 }
Note:
See TracChangeset
for help on using the changeset viewer.