Changeset 8000
- Timestamp:
- 2004-08-18T17:16:31+12:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/msm/MSMUtils.java
r7260 r8000 136 136 * @return <i>true</i> if the two trees are equal, <i>false</i> otherwise. 137 137 */ 138 static final p ublicboolean assignedValuesEqual(Node avt, Node bvt) {138 static final private boolean assignedValuesEqual(Node avt, Node bvt) { 139 139 if(avt == null && bvt == null) { 140 140 return true; // Both are null so both are equal. … … 186 186 } 187 187 188 /** Method to determine if a certain path of elements can be found in another tree. This method tests by comparing node names, and finally the #text node past the leaf end of the path.189 * @param tree The root <strong>Node</strong> of the tree to be searched.190 * @param path The <strong>Node[]</strong> path to be found.191 * @return <i>true</i> if the path was found (including matching #text elements at the leaf), or <i>false</i> otherwise.192 */193 /* static final private boolean containsPath(Node tree, Node path[]) {194 // If there is no tree then there are no values.195 if(tree == null) {196 return false;197 }198 // Ensure we are comparing equivent things.199 if(tree.getNodeName().equals("AssignedValues") && path[0].getNodeName().equals("AssignedValues")) {200 int index = 1;201 while(index < path.length && tree != null) {202 Node next = null;203 for(Node n = tree.getFirstChild(); n != null && next == null; n = n.getNextSibling()) {204 if(n.getNodeName().equals(path[index].getNodeName())) {205 next = n;206 index++;207 }208 tree = next;209 }210 }211 // Tree may now be pointing at the same node as212 // path[path.length - 1] so we should test their child text nodes.213 if(tree != null) {214 Node tree_text = tree.getFirstChild();215 Node path_text = path[path.length - 1].getFirstChild();216 if(tree_text.getNodeValue().equals(path_text.getNodeValue())) {217 // Path found!218 return true;219 }220 }221 }222 return false;223 } */224 188 /** Method to compare two metadata elements (of type Element, which is bound to get more than a bit confusing) for equality. This test may only check the structural (ie pretty much unchanging) consistancy, or may include the AssignedValue tree as well (which will be different for each collection I'd imagine). 225 189 * @param a_set The <strong>MetadataSet</strong> a comes from. … … 365 329 * @return An <i>int</i> which is the number of attribute nodes. 366 330 */ 367 static final p ublicint getAttributeCount(Node element) {331 static final private int getAttributeCount(Node element) { 368 332 int count = 0; 369 333 for(Node n = element.getFirstChild(); n != null; … … 374 338 } 375 339 return count; 376 }377 378 /*************************************************************************/379 /** This method is a slight variation on getNodeNamed in that it is especially written to retrieve the attribute Nodes of a certain name present under the given element. Note that this method is language specific.380 * @param element The target element <strong>Node</strong>.381 * @param name The name of the attribute you wish to return.382 * @return An <strong>Element[]</strong> containing the attributes you requested, or <i>null</i> if no such attributes exists.383 */384 static final public Element getAttributeNodeNamed(Node element, String name) {385 Element attribute = null;386 String language_code = Gatherer.config.getLanguage();387 for(Node n = element.getFirstChild(); n != null; n = n.getNextSibling()) {388 if(n.getNodeName().equals("Attribute")) {389 Element e = (Element)n;390 if(e.getAttribute("name").equals(name)) {391 if(e.getAttribute("language").equalsIgnoreCase(language_code)) {392 return e;393 }394 else if(e.getAttribute("language").equalsIgnoreCase("en")) {395 attribute = e;396 }397 else if(attribute == null) {398 attribute = e;399 }400 }401 e = null;402 }403 }404 return attribute;405 340 } 406 341 … … 468 403 * @see org.greenstone.gatherer.util.StaticStrings#NAME_ATTRIBUTE 469 404 */ 470 static p ublicString getElementAttribute(Element element_element, String attribute_name_str, String language_code_str) {405 static private String getElementAttribute(Element element_element, String attribute_name_str, String language_code_str) { 471 406 boolean found = false; 472 407 String result = StaticStrings.EMPTY_STR; … … 646 581 } 647 582 648 /** This method traces the path between the 'root' node given and the target node. This path is returned starting at the root.649 * @param root The root <strong>Node</strong> to start this path at.650 * @param target The final <strong>Node</strong> to end up at.651 * @return A <strong>Node[]</strong> that contains the sequence of nodes from root to target.652 */653 static final public Node[] getPath(Node root, Node target) {654 if(root == target) {655 return ArrayTools.add(null, root);656 }657 else {658 return ArrayTools.add(getPath(root, target.getParentNode()), target);659 }660 }661 583 662 584 /** This method extracts the structural details from a certain element and stores them in an array, all ready for passing to the <strong>Dictionary</strong>. … … 724 646 * @param values A <strong>Hashtable</strong> containing the mapping discovered so far in our tree traversal. 725 647 */ 726 static final p ublicvoid getValueMappings(Node current, String prefix, Hashtable values) {648 static final private void getValueMappings(Node current, String prefix, Hashtable values) { 727 649 if(current != null) { 728 650 String name = current.getNodeName(); 729 651 String new_prefix = prefix; 730 // If we've found the outer layer of a new value, add it to our 731 // mapping. 652 // If we've found the outer layer of a new value, add it to our mapping 732 653 if(name.equals("Subject")) { 733 654 Node value_node = getNodeFromNamed(current, "Value"); … … 761 682 * @see org.greenstone.gatherer.util.StaticStrings#LANGUAGEDEPENDANT_ATTRIBUTE 762 683 */ 763 static p ublicboolean isAttributeLanguageDependant(Document document, String attribute_name_str) {684 static private boolean isAttributeLanguageDependant(Document document, String attribute_name_str) { 764 685 String language_specific_attributes = document.getDocumentElement().getAttribute(StaticStrings.LANGUAGEDEPENDANT_ATTRIBUTE).toLowerCase(); 765 686 return language_specific_attributes.indexOf(attribute_name_str) != -1; … … 772 693 * @see org.greenstone.gatherer.util.StaticStrings#EMPTY_STR 773 694 */ 774 static p ublicboolean isLegacyMDS(Document document) {695 static private boolean isLegacyMDS(Document document) { 775 696 ///ystem.err.println("isLegacyMDS(): l_d = " + document.getDocumentElement().getAttribute(StaticStrings.LANGUAGEDEPENDANT_ATTRIBUTE)); 776 697 return (document.getDocumentElement().getAttribute(StaticStrings.LANGUAGEDEPENDANT_ATTRIBUTE)).equals(StaticStrings.EMPTY_STR); … … 783 704 * TODO Implementation 784 705 */ 785 static final p ublicboolean optionListsEqual(Node al, Node bl) {706 static final private boolean optionListsEqual(Node al, Node bl) { 786 707 // Compare the 'restricted' attribute of the two lists. 787 708 Element ae = (Element) al; … … 1056 977 * @return A <i>boolean</i> which is <i>true</i> if the two value nodes are equal, <i>false</i> otherwise. 1057 978 */ 1058 static final p ublicboolean valuesEqual(Node av, Node bv) {979 static final private boolean valuesEqual(Node av, Node bv) { 1059 980 // Check we are comparing apples and apples... 1060 981 if(av.getNodeName().equals("Value") &&
Note:
See TracChangeset
for help on using the changeset viewer.