Changeset 25925
- Timestamp:
- 2012-07-10T16:27:42+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java
r25859 r25925 19 19 package org.greenstone.gsdl3.util; 20 20 21 import java.io.Serializable; 22 import java.io.StringWriter; 23 import java.util.ArrayList; 24 import java.util.HashMap; 25 import java.util.Iterator; 26 import java.util.Map; 27 import java.util.Set; 28 import java.util.Vector; 29 30 import javax.xml.transform.OutputKeys; 31 import javax.xml.transform.Transformer; 32 import javax.xml.transform.TransformerFactory; 33 import javax.xml.transform.dom.DOMSource; 34 import javax.xml.transform.stream.StreamResult; 35 36 import org.apache.log4j.Logger; 37 import org.w3c.dom.Document; 38 import org.w3c.dom.Element; 21 39 import org.w3c.dom.NamedNodeMap; 22 40 import org.w3c.dom.Node; 23 import org.w3c.dom.Element;24 41 import org.w3c.dom.NodeList; 25 import org.w3c.dom.Document;26 42 import org.w3c.dom.Text; 27 28 import javax.xml.transform.TransformerFactory;29 import javax.xml.transform.Transformer;30 31 import java.io.Serializable;32 import java.io.StringWriter;33 import javax.xml.transform.stream.StreamResult;34 import javax.xml.transform.dom.DOMSource;35 import javax.xml.transform.OutputKeys;36 37 import java.util.Map;38 import java.util.Set;39 import java.util.HashMap;40 import java.util.Vector;41 import java.util.Iterator;42 import java.util.ArrayList;43 44 //import java.util.Locale;45 46 import org.apache.log4j.*;47 43 48 44 /** various functions for extracting info out of GS XML */ … … 283 279 public static final String GROUPS_ATT = "groups"; 284 280 public static final String BASE_URL = "baseURL"; 285 281 286 282 //for classifiers 287 283 public static final String CHILD_TYPE_ATT = "childType"; … … 289 285 public static final String HLIST = "HList"; 290 286 public static final String VLIST = "VList"; 291 287 292 288 /** 293 289 * takes a list of elements, and returns an array of strings of the values … … 709 705 return node_list; 710 706 } 711 public static NodeList getChildrenByTagNameNS(Node n, String namespace, String local_name) 707 708 public static NodeList getChildrenByTagNameNS(Node n, String namespace, String local_name) 712 709 { 713 710 MyNodeList node_list = new MyNodeList(); … … 715 712 while (child != null) 716 713 { 717 714 if (child.getNodeType() == Node.ELEMENT_NODE && child.getNamespaceURI().equals(namespace) && child.getLocalName() != null && child.getLocalName().equals(local_name)) 718 715 { 719 716 node_list.addNode(child); … … 924 921 } 925 922 926 927 923 public static Element getNamedElementNS(Element parent, String namespace_uri, String node_local_name, String attribute_name, String attribute_value) 924 { 928 925 NodeList children = parent.getChildNodes(); 929 926 for (int i = 0; i < children.getLength(); i++) 930 927 { 931 928 Node child = children.item(i); 932 if (child.getNodeType() == Node.ELEMENT_NODE && child.getNamespaceURI().equals(namespace_uri) && child.getLocalName().equals(node_local_name))929 if (child.getNodeType() == Node.ELEMENT_NODE && child.getNamespaceURI().equals(namespace_uri) && child.getLocalName().equals(node_local_name)) 933 930 { 934 931 if (((Element) child).getAttribute(attribute_name).equals(attribute_value)) … … 939 936 return null; 940 937 941 942 } 938 } 943 939 944 940 // In element main, tries to find any previous occurrence of elements with xsl-template-name=templateName, … … 946 942 // If this is the case, such a previous occurrence is removed from element main, since 947 943 // the new node will contain a more specific redefinition of this element. 948 public static void removeNamedElementNS(Element parent, String namespace_uri, String node_local_name, String attribute_name, String attribute_value) 949 { 950 if (attribute_value.equals("")) { 951 // it has no identifying attribute, so we can't find any matches 952 return; 953 } 954 944 public static void removeNamedElementNS(Element parent, String namespace_uri, String node_local_name, String attribute_name, String attribute_value) 945 { 946 if (attribute_value.equals("")) 947 { 948 // it has no identifying attribute, so we can't find any matches 949 return; 950 } 951 955 952 Element old_elem = GSXML.getNamedElementNS(parent, namespace_uri, node_local_name, attribute_name, attribute_value); 956 953 if (old_elem != null) 957 { 958 parent.removeChild(old_elem); 959 } 960 961 } 962 963 public static void removeNamedElementsNS(Element parent, String namespace, String node_local_name, String attribute_name, String attribute_value) 964 { 965 if (attribute_value.equals("")) { 966 // it has no identifying attribute, so we can't find any matches 967 return; 954 { 955 parent.removeChild(old_elem); 956 } 957 958 } 959 960 public static void removeNamedElementsNS(Element parent, String namespace, String node_local_name, String attribute_name, String attribute_value) 961 { 962 if (attribute_value.equals("")) 963 { 964 // it has no identifying attribute, so we can't find any matches 965 return; 968 966 } 969 967 970 968 NodeList children = parent.getChildNodes(); 971 for (int i = children.getLength()-1; i >= 0; i--)969 for (int i = children.getLength() - 1; i >= 0; i--) 972 970 { 973 971 Node child = children.item(i); … … 975 973 { 976 974 if (((Element) child).getAttribute(attribute_name).equals(attribute_value)) 977 parent.removeChild(child); 978 } 979 } 980 } 981 982 975 parent.removeChild(child); 976 } 977 } 978 } 983 979 984 980 /** … … 1007 1003 } 1008 1004 1009 public static Element getLastElementByTagNameNS(Element main, String namespace, String node_name) { 1010 1011 NodeList nodes = main.getElementsByTagNameNS(namespace, node_name); 1012 int len = nodes.getLength(); 1013 if (len==0) { 1014 return null; 1015 } 1016 return (Element)nodes.item(len-1); 1017 } 1018 1005 public static Element getLastElementByTagNameNS(Element main, String namespace, String node_name) 1006 { 1007 1008 NodeList nodes = main.getElementsByTagNameNS(namespace, node_name); 1009 int len = nodes.getLength(); 1010 if (len == 0) 1011 { 1012 return null; 1013 } 1014 return (Element) nodes.item(len - 1); 1015 } 1019 1016 1020 1017 public static int SORT_TYPE_STRING = 0;
Note:
See TracChangeset
for help on using the changeset viewer.