Changeset 5294
- Timestamp:
- 2003-08-27T15:03:07+12:00 (21 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/Codec.java
r5244 r5294 41 41 static final public String DOM_TO_TEXT = "DOM_TO_TEXT"; 42 42 static final public String GREENSTONE_TO_DOM = "GREENSTONE_TO_DOM"; 43 static final public String GREENSTONE_TO_TEXT = "GREENSTONE_TO_TEXT"; 43 44 static final public String TEXT_TO_DOM = "TEXT_TO_DOM"; 45 static final public String TEXT_TO_GREENSTONE = "TEXT_TO_GREENSTONE"; 44 46 static final public String TEXT_TO_SHELL_UNIX = "TEXT_TO_SHELL_UNIX"; 45 47 static final public String TEXT_TO_SHELL_WINDOWS = "TEXT_TO_SHELL_WINDOWS"; … … 86 88 greenstone_to_dom = null; 87 89 90 // Transform Greenstone encoded text to plain text 91 String[] greenstone_to_text = { 92 "\\\\\"", "\"", 93 "\\\\\'", "\'", 94 "\\\\n", "\n", 95 """, "\"", 96 "'", "\'", 97 "\\\\\\[", "\\[", 98 "\\\\\\]", "\\]", 99 "\\\\\\\\", "\\\\" 100 }; 101 TRANSFORMS.put(GREENSTONE_TO_TEXT, greenstone_to_text); 102 greenstone_to_text = null; 103 88 104 // Transform plain html text into something that can be placed in a DOM 89 105 String[] text_to_dom = { … … 92 108 ">", ">", 93 109 "\"", """, 94 "\'", "'"}; 110 "\'", "'" 111 }; 95 112 TRANSFORMS.put(TEXT_TO_DOM, text_to_dom); 96 113 text_to_dom = null; 97 114 98 // Transform plain html text into something that can be placed in a shell command 115 // Transform plain html text into greenstone encoding 116 String[] text_to_greenstone = { 117 "\\\\", "\\\\\\\\", 118 "\\[", "\\\\[", 119 "\\]", "\\\\]", 120 "\"", """, 121 "\'", "'", 122 "\n", "\\\\n" 123 }; 124 TRANSFORMS.put(TEXT_TO_GREENSTONE, text_to_greenstone); 125 text_to_greenstone = null; 126 127 // Transform plain html text into something that can be placed in a shell command 99 128 String[] text_to_shell_unix = { 100 129 "\"", "\\\\\"", … … 225 254 System.err.println("Processed: '" + processed + "'"); 226 255 256 transform = "GREENSTONE_TO_TEXT"; 257 System.err.println("Test " + transform); 258 raw = "These \\[ \\] should be escaped, and so should \\\\ that. These " ' \\n are encoded."; 259 System.err.println("Raw: '" + raw + "'"); 260 processed = transform(raw, transform); 261 System.err.println("Processed: '" + processed + "'"); 262 227 263 transform = "TEXT_TO_DOM"; 228 264 System.err.println("Test " + transform); 229 265 raw = "A <\nand a <a href=\"here.html\"><font size='2'>URL</font></a>"; 266 System.err.println("Raw: '" + raw + "'"); 267 processed = transform(raw, transform); 268 System.err.println("Processed: '" + processed + "'"); 269 270 transform = "TEXT_TO_GREENSTONE"; 271 System.err.println("Test " + transform); 272 raw = "These [ ] should be escaped, and so should \\ that. These \" \' \n are encoded."; 230 273 System.err.println("Raw: '" + raw + "'"); 231 274 processed = transform(raw, transform); -
trunk/gli/src/org/greenstone/gatherer/valuetree/GValueModel.java
r5153 r5294 7 7 * University of Waikato, New Zealand. 8 8 * 9 * <BR><BR>10 *11 9 * Author: John Thompson, Greenstone Digital Library, University of Waikato 12 10 * 13 * <BR><BR>14 *15 11 * Copyright (C) 1999 New Zealand Digital Library Project 16 *17 * <BR><BR>18 12 * 19 13 * This program is free software; you can redistribute it and/or modify … … 22 16 * (at your option) any later version. 23 17 * 24 * <BR><BR>25 *26 18 * This program is distributed in the hope that it will be useful, 27 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 21 * GNU General Public License for more details. 30 *31 * <BR><BR>32 22 * 33 23 * You should have received a copy of the GNU General Public License … … 42 32 import org.greenstone.gatherer.msm.MetadataSetManager; 43 33 import org.greenstone.gatherer.msm.MSMUtils; 34 import org.greenstone.gatherer.util.Codec; 35 import org.greenstone.gatherer.util.PatternTokenizer; 44 36 import org.greenstone.gatherer.util.StaticStrings; 45 37 import org.greenstone.gatherer.util.SynchronizedTreeModelTools; … … 53 45 extends DefaultTreeModel { 54 46 47 static final public String PATH_SEP = "\\\\"; 48 static final public String PATH_SEP_PATTERN = "\\\\\\\\"; 49 55 50 private ElementWrapper element; 56 51 … … 84 79 public GValueNode addValue(String value) { 85 80 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); 81 // Tokenize the string using the escaped character 82 PatternTokenizer tokenizer = new PatternTokenizer(value, PATH_SEP); 90 83 GValueNode subject = (GValueNode) root; 91 84 while(tokenizer.hasMoreTokens() && subject != null) { … … 101 94 } 102 95 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();122 }123 124 96 public GValueNode addValue(String value, GValueNode subject, String alias) { 125 97 // To add a value we must first ensure it isn't already present in -this- nodes children. The bummer is that the nice getElements functions search the whole tree so... 126 GValueNode value_node = subject.getValue( Utility.stripNL(value));98 GValueNode value_node = subject.getValue(value); 127 99 if(value_node == null) { 128 100 // Now add the new value. … … 275 247 } 276 248 277 /**278 public void updateValue(String new_value, String old_value) {279 ///ystem.err.println("Updating '" + old_value + "' to '" + new_value + "'");280 StringTokenizer tokenizer = new StringTokenizer(new_value, "\\");281 GValueNode subject = (GValueNode) root;282 while(tokenizer.hasMoreTokens()) {283 String token = tokenizer.nextToken();284 subject = updateValue(token, old_value, subject);285 }286 }287 */288 289 249 /** Called to update a certain value of metadata within a specific 290 250 * subject within a sbject hierarchy. … … 326 286 } 327 287 value = value.substring(next.toString().length()); 328 if(value.startsWith( StaticStrings.ESCAPE_STR + StaticStrings.ESCAPE_STR)) {288 if(value.startsWith(PATH_SEP)) { 329 289 value = value.substring(2); 330 290 index = getHIndex(next, value, index); -
trunk/gli/src/org/greenstone/gatherer/valuetree/GValueNode.java
r5153 r5294 55 55 import org.greenstone.gatherer.msm.ElementWrapper; 56 56 import org.greenstone.gatherer.msm.MSMUtils; 57 import org.greenstone.gatherer.util.Codec; 57 58 import org.greenstone.gatherer.util.StaticStrings; 58 59 import org.greenstone.gatherer.util.Utility; … … 176 177 * @return A <strong>String</strong> representing the path, ie "Titles\Modern\The Green Mile" 177 178 */ 178 public String getFullPath( ) {179 public String getFullPath(boolean as_text) { 179 180 if(default_value != null) { 180 181 return default_value; … … 184 185 while(node != null && !node.getElement().getNodeName().equalsIgnoreCase("AssignedValues")) { 185 186 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); 187 path.insert(0, node.toString()); 190 188 node = (GValueNode) node.getParent(); 191 189 } 192 return path.toString(); 190 if(as_text) { 191 return Codec.transform(path.toString(), Codec.GREENSTONE_TO_TEXT); 192 } 193 else { 194 return path.toString(); 195 } 193 196 } 194 197 … … 226 229 map(); 227 230 } 228 GValueNode result = null; 229 for(int i = 0; result == null && i < children.size(); i++) { 230 Object child = children.get(i); 231 if(child.toString().equalsIgnoreCase(value)) { 232 result = (GValueNode) child; 233 } 234 } 235 return result; 231 for(int i = 0; i < children.size(); i++) { 232 GValueNode child = (GValueNode) children.get(i); 233 if(child.toString(false).equalsIgnoreCase(value)) { 234 return child; 235 } 236 } 237 return null; 236 238 } 237 239 … … 320 322 */ 321 323 public String toString() { 324 return toString(true); 325 } 326 327 public String toString(boolean as_text) { 322 328 if(default_value != null) { 323 329 return default_value; … … 327 333 String result = null; 328 334 if(name.equals("Subject")) { 329 result = MSMUtils.getValue(element); 335 if(as_text) { 336 result = Codec.transform(MSMUtils.getValue(element), Codec.GREENSTONE_TO_TEXT); 337 } 338 else { 339 result = MSMUtils.getValue(element); 340 } 330 341 } 331 342 else if(name.equals("AssignedValues")) { 332 343 result = getMetadataElementName(); 333 344 } 334 return Utility.stripNL(result);345 return result; 335 346 } 336 347
Note:
See TracChangeset
for help on using the changeset viewer.