Changeset 5805
- Timestamp:
- 2003-11-07T13:20:43+13:00 (20 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/Codec.java
r5707 r5805 37 37 */ 38 38 public class Codec { 39 39 40 40 static final public String DOM_TO_GREENSTONE = "DOM_TO_GREENSTONE"; 41 41 static final public String DOM_TO_TEXT = "DOM_TO_TEXT"; … … 49 49 50 50 static final private int MAX_CACHE_SIZE = 100; 51 51 52 52 static private HashMap TRANSFORMS; 53 53 static private HashMap3D CACHE; 54 54 55 55 56 56 /** Static function called to construct TRANSFORMS mappings */ 57 57 static { 58 58 TRANSFORMS = new HashMap(); 59 59 60 60 // Translate DOM encoded text into Greenstone encoding 61 61 String[] dom_to_greenstone = { … … 69 69 TRANSFORMS.put(DOM_TO_GREENSTONE, dom_to_greenstone); 70 70 dom_to_greenstone = null; 71 71 72 72 // Transform DOM encoded text into plain text 73 73 String[] dom_to_text = { … … 78 78 "<", "<", 79 79 """, "\"", 80 "&", "&" 80 "&", "&", 81 "\\|", "\\\\" 81 82 }; 82 83 TRANSFORMS.put(DOM_TO_TEXT, dom_to_text); … … 104 105 "[", "\\[", 105 106 "]", "\\]", 106 "\\ \\\\\\", "\\\\"107 "\\|", "\\\\" 107 108 }; 108 109 TRANSFORMS.put(GREENSTONE_TO_TEXT, greenstone_to_text); … … 116 117 TRANSFORMS.put(REMOVE_SQUARE_BRACKET, remove_square_bracket); 117 118 remove_square_bracket = null; 118 119 119 120 // Transform plain html text into something that can be placed in a DOM 120 121 String[] text_to_dom = { … … 123 124 ">", ">", 124 125 "\"", """, 125 "\'", "'" 126 "\'", "'", 127 "\\\\", "\\|", 126 128 }; 127 129 TRANSFORMS.put(TEXT_TO_DOM, text_to_dom); … … 130 132 // Transform plain html text into greenstone encoding 131 133 String[] text_to_greenstone = { 132 "\\\\", "\\ \\\\\\",134 "\\\\", "\\|", 133 135 "\\[", "[", 134 136 "\\]", "]", … … 192 194 static final private char UPPER_U_CHAR = 'U'; 193 195 static final private char SEMICOLON_CHAR = ';'; 194 196 195 197 static public String transformUnicode(String raw) { 196 198 StringBuffer processed = new StringBuffer(); -
trunk/gli/src/org/greenstone/gatherer/util/MetadataXML.java
r5581 r5805 32 32 import org.greenstone.gatherer.msm.ElementWrapper; 33 33 import org.greenstone.gatherer.msm.MetadataSetManager; 34 import org.greenstone.gatherer.util.StaticStrings; 34 35 import org.greenstone.gatherer.util.Utility; 35 36 import org.greenstone.gatherer.valuetree.GValueModel; … … 55 56 GValueNode node = (GValueNode)all_values.get(i); 56 57 TreePath path = new TreePath(node.getPath()); 57 String value = node.getFullPath(false); 58 String index = model.getHIndex(value); 59 String alias = node.getAlias(index); 60 if(value.indexOf(GValueModel.PATH_SEP) != -1) { 61 value = value.substring(value.lastIndexOf(GValueModel.PATH_SEP) + GValueModel.PATH_SEP.length()); 62 } 63 write(bw, "\"" + Utility.stripNL(value) + "\"\t" + index + "\t\"" + Utility.stripNL(value) + "\""); 58 String full_value = node.getFullPath(true); 59 String index = model.getHIndex(full_value); 60 61 write(bw, "\"" + Utility.stripNL(full_value) + "\"\t" + index + "\t\"" + Utility.stripNL(full_value) + "\""); 64 62 } 65 // Very important we do this, or else buffer may not have 63 // Very important we do this, or else buffer may not have 66 64 // flushed. 67 65 bw.flush(); -
trunk/gli/src/org/greenstone/gatherer/util/StaticStrings.java
r5746 r5805 128 128 static final public String OPTIONS_ATTRIBUTE = "options"; 129 129 static final public String PERL_ARGUMENT = "-perl"; 130 static final public String PIPE_STR = "|"; 130 131 static final public String PLUGIN_ELEMENT = "Plugin"; 131 132 static final public String PLUGIN_STR = "plugin"; -
trunk/gli/src/org/greenstone/gatherer/valuetree/GValueModel.java
r5785 r5805 33 33 import org.greenstone.gatherer.msm.MSMUtils; 34 34 import org.greenstone.gatherer.util.PatternTokenizer; 35 import org.greenstone.gatherer.util.StaticStrings; 35 36 import org.greenstone.gatherer.util.Utility; 36 37 import org.w3c.dom.*; … … 39 40 * @version 2.1 40 41 */ 41 public class GValueModel 42 public class GValueModel 42 43 extends DefaultTreeModel { 43 44 static final public String PATH_SEP = "\\\\";45 static final public String PATH_SEP_PATTERN = "\\\\\\\\";46 44 47 45 private ElementWrapper element; … … 74 72 75 73 /** Value may include path ie news\newssw */ 76 public GValueNode addValue(String value) { 74 public GValueNode addValue(String value) { 77 75 try { 78 76 // Tokenize the string using the escaped character 79 PatternTokenizer tokenizer = new PatternTokenizer(value, PATH_SEP);77 PatternTokenizer tokenizer = new PatternTokenizer(value, StaticStrings.PIPE_STR); 80 78 GValueNode subject = (GValueNode) root; 81 79 while(tokenizer.hasMoreTokens() && subject != null) { … … 107 105 new_subject.appendChild(new_alias); 108 106 Text new_alias_text = document.createTextNode(alias); 109 new_alias.appendChild(new_alias_text); 110 } 107 new_alias.appendChild(new_alias_text); 108 } 111 109 value_node = new GValueNode(new_subject); 112 110 ///ystem.err.println("(GValueModel) addValue()... " + value_node); 113 114 // Figure out where this node will be inserted in subjects 111 112 // Figure out where this node will be inserted in subjects 115 113 // children. 116 114 int position = -1; … … 148 146 * @param value The value whose index you wish to determine as a <strong>String</strong>. 149 147 * @return A <strong>String</strong> containing an index such as "1", "2.1" or "18.2.5". 150 */ 148 */ 151 149 public String getHIndex(String value) { 152 150 ///ystem.err.println("getHIndex(" + value + ")"); … … 244 242 } 245 243 246 /** Called to update a certain value of metadata within a specific247 * subject within a sbject hierarchy.248 * Note that this simply in turn calls removeValue() to deal with the249 * old value, then addValue() to account for the new.250 * @param new_value A String representing the updated value.251 * @param old_value A String representing the old value.252 * @param subject An Element representing the subject you wish to update253 * this value in.254 */255 /* private GValueNode updateValue(String new_value, String old_value, GValueNode subject) {256 return addValue(new_value, subject, null);257 } */258 259 244 private GValueModel copy() { 260 245 Element document_element = ((GValueNode) root).getElement(); … … 268 253 } 269 254 } 270 return new GValueModel(element, document_copy); 255 return new GValueModel(element, document_copy); 271 256 } 272 257 273 258 private String getHIndex(GValueNode node, String value, String index) { 259 ///ystem.err.println("Get the HIndex for: " + value); 274 260 for(int i = node.size(); i != 0; i--) { 275 261 GValueNode next = (GValueNode)node.get(i - 1); 276 262 String next_str = next.toString(); 263 ///ystem.err.println("Does " + value + " start with " + next_str + "?"); 277 264 if(value.startsWith(next_str)) { 278 265 if(index == null) { … … 283 270 } 284 271 value = value.substring(next.toString().length()); 285 if(value.startsWith(PATH_SEP)) { 286 value = value.substring(2); 272 ///ystem.err.println("We matched the start so value is now: " + value); 273 if(value.startsWith(StaticStrings.PIPE_STR) || value.startsWith(StaticStrings.ESCAPE_STR)) { 274 value = value.substring(1); 287 275 index = getHIndex(next, value, index); 288 276 } 277 ///ystem.err.println("Returning " + index); 289 278 return index; 290 279 } 291 280 } 281 ///ystem.err.println("Returning " + index); 292 282 return index; 293 283 } -
trunk/gli/src/org/greenstone/gatherer/valuetree/GValueNode.java
r5785 r5805 59 59 /** This class is instantiated using a metadata element. From this parent element, which refers to a specific Element in the mds DOM model, the AssignedValues child is used as the root of a tree data-structure encompassing all of the nodes within the AssignedValues tree. This class also provide methods for adding, updating and removing nodes within this tree, as well as implementing all of the methods necessary for this node to be used as the basis of a tree model. 60 60 */ 61 public class GValueNode 61 public class GValueNode 62 62 extends DefaultMutableTreeNode { 63 63 … … 65 65 static final public int GREENSTONE = 1; 66 66 static final public int TEXT = 2; 67 67 68 68 private String element_name = null; 69 69 private String default_value = null; … … 127 127 Element element = (Element) userObject; 128 128 for(Node pos_node = element.getFirstChild(); pos_node != null; pos_node = pos_node.getNextSibling()) { 129 // And if we find such a node 129 // And if we find such a node 130 130 if(pos_node.getNodeName().equals("Alias")) { 131 131 // Retrieve its text node … … 137 137 } 138 138 } 139 } 139 } 140 140 return ""; 141 141 } … … 187 187 GValueNode node = (GValueNode) getParent(); 188 188 while(node != null && !node.getElement().getNodeName().equalsIgnoreCase("AssignedValues")) { 189 path.insert(0, StaticStrings. ESCAPE_STR + StaticStrings.ESCAPE_STR);189 path.insert(0, StaticStrings.PIPE_STR); 190 190 path.insert(0, node.toString()); 191 191 node = (GValueNode) node.getParent(); … … 274 274 } 275 275 276 /** Ensure that the children nodes of this tree are instantiated, and record the initial mappings for legacy sake. 276 /** Ensure that the children nodes of this tree are instantiated, and record the initial mappings for legacy sake. 277 277 * @param mapping A <strong>HashMap</strong> into which to write the initial mappings. 278 278 * @param prefix The prefix to use for indexes, as a <strong>String</strong>. … … 306 306 /** Resets the user object of the reciever to <I>object</I>. */ 307 307 public void setUserObject(Object object) { 308 // Can't ever change Elements from here. Have to use editor. */ 308 // Can't ever change Elements from here. Have to use editor. */ 309 309 } 310 310 … … 323 323 /** Returns a <I>String</I> representation of the reciever. If this 324 324 * happens to be the AssignedValues 'root' then we do something slightly 325 * different, otherwise we return the value of the <I>#Text</I> child of 325 * different, otherwise we return the value of the <I>#Text</I> child of 326 326 * the <I>Value</I> of this <I>Subject</I> node! 327 327 */ … … 329 329 return toString(GValueNode.TEXT); 330 330 } 331 331 332 332 public String toString(int decode_type) { 333 333 if(default_value != null) { … … 376 376 remove((MutableTreeNode)getChildAt(index)); 377 377 } 378 378 379 379 /** Removes node from the receiver. */ 380 380 public void remove(MutableTreeNode node) { … … 386 386 parent_node.removeChild(child_element); 387 387 } 388 388 389 389 /** Removes the receiver from its parent. */ 390 390 public void removeFromParent() { … … 399 399 Element element = (Element) userObject; 400 400 for(Node pos_node = element.getFirstChild(); pos_node != null; pos_node = pos_node.getNextSibling()) { 401 // And if we find such a node 401 // And if we find such a node 402 402 if(pos_node.getNodeName().equals(name)) { 403 403 // And the new value is non-null, retrieve its text node and change it.
Note:
See TracChangeset
for help on using the changeset viewer.