Changeset 5153 for trunk/gli/src/org/greenstone/gatherer/util/Utility.java
- Timestamp:
- 2003-08-18T13:55:21+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.