Changeset 25926
- Timestamp:
- 2012-07-10T16:28:41+12:00 (11 years ago)
- Location:
- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java
r25925 r25926 935 935 // not found 936 936 return null; 937 937 } 938 939 public static NodeList getNamedElementsNS(Element parent, String namespace_uri, String node_local_name, String attribute_name, String attribute_value) 940 { 941 MyNodeList result = new MyNodeList(); 942 NodeList children = parent.getChildNodes(); 943 for (int i = 0; i < children.getLength(); i++) 944 { 945 Node child = children.item(i); 946 if (child.getNodeType() == Node.ELEMENT_NODE && child.getNamespaceURI().equals(namespace_uri) && child.getLocalName().equals(node_local_name)) 947 { 948 if (((Element) child).getAttribute(attribute_name).equals(attribute_value)) 949 result.addNode(child); 950 } 951 } 952 return result; 953 } 954 955 public static NodeList getElementsWithAttributesNS(Element parent, String namespace_uri, String node_local_name, String[] attribute_names, String[] attribute_values) 956 { 957 if (attribute_names.length == 0 || attribute_names.length != attribute_values.length) 958 { 959 return new MyNodeList(); 960 } 961 962 MyNodeList result = new MyNodeList(); 963 964 NodeList matchingNodes = GSXML.getNamedElementsNS(parent, namespace_uri, node_local_name, attribute_names[0], attribute_values[0]); 965 for (int i = 0; i < matchingNodes.getLength(); i++) 966 { 967 Element current = (Element) matchingNodes.item(i); 968 boolean nodeMatches = true; 969 for (int j = 1; j < attribute_names.length; j++) 970 { 971 String currentName = attribute_names[j]; 972 String currentValue = attribute_values[j]; 973 if (!current.getAttribute(currentName).equals(currentValue)) 974 { 975 nodeMatches = false; 976 break; 977 } 978 } 979 980 if (nodeMatches) 981 { 982 result.addNode(current); 983 } 984 } 985 986 return result; 987 } 988 989 public static void removeElementsWithAttributesNS(Element parent, String namespace_uri, String node_local_name, String[] attribute_names, String[] attribute_values) 990 { 991 NodeList matchingNodes = GSXML.getElementsWithAttributesNS(parent, namespace_uri, node_local_name, attribute_names, attribute_values); 992 for (int i = 0; i < matchingNodes.getLength(); i++) 993 { 994 parent.removeChild(matchingNodes.item(i)); 995 } 938 996 } 939 997 … … 955 1013 parent.removeChild(old_elem); 956 1014 } 957 958 1015 } 959 1016 -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXSLT.java
r25924 r25926 163 163 { 164 164 // if we have a name attribute, remove any other similarly named template 165 if (!template_name.equals("")) 166 { 167 GSXML.removeNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "name", template_name); 168 } 169 // if we have a match attribute, remove other templates that match - 170 if (!template_match.equals("")) 171 { 172 GSXML.removeNamedElementsNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "match", template_match); 173 } 165 GSXML.removeElementsWithAttributesNS(main, "http://www.w3.org/1999/XSL/Transform", "template", new String[]{"name", "match", "mode"}, new String[]{template_name, template_match, template_mode}); 166 174 167 // now add our good template in 175 168 main.appendChild(main_xsl.importNode(node, true)); … … 181 174 // there can't be any duplicate named templates, so just look for matches 182 175 // we already have the one with highest import precedence (from the top most level) so don't add any more in 183 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "match", template_match) == null) 184 { 185 main.appendChild(main_xsl.importNode(node, true)); 186 } 187 188 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "name", template_name) == null) 176 if (GSXML.getElementsWithAttributesNS(main, "http://www.w3.org/1999/XSL/Transform", "template", new String[]{"name", "match", "mode"}, new String[]{template_name, template_match, template_mode}).getLength() == 0) 189 177 { 190 178 main.appendChild(main_xsl.importNode(node, true));
Note:
See TracChangeset
for help on using the changeset viewer.