Changeset 25925


Ignore:
Timestamp:
2012-07-10T16:27:42+12:00 (12 years ago)
Author:
sjm84
Message:

Reformatting and tidying the imports of this file before some changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r25859 r25925  
    1919package org.greenstone.gsdl3.util;
    2020
     21import java.io.Serializable;
     22import java.io.StringWriter;
     23import java.util.ArrayList;
     24import java.util.HashMap;
     25import java.util.Iterator;
     26import java.util.Map;
     27import java.util.Set;
     28import java.util.Vector;
     29
     30import javax.xml.transform.OutputKeys;
     31import javax.xml.transform.Transformer;
     32import javax.xml.transform.TransformerFactory;
     33import javax.xml.transform.dom.DOMSource;
     34import javax.xml.transform.stream.StreamResult;
     35
     36import org.apache.log4j.Logger;
     37import org.w3c.dom.Document;
     38import org.w3c.dom.Element;
    2139import org.w3c.dom.NamedNodeMap;
    2240import org.w3c.dom.Node;
    23 import org.w3c.dom.Element;
    2441import org.w3c.dom.NodeList;
    25 import org.w3c.dom.Document;
    2642import 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.*;
    4743
    4844/** various functions for extracting info out of GS XML */
     
    283279    public static final String GROUPS_ATT = "groups";
    284280    public static final String BASE_URL = "baseURL";
    285    
     281
    286282    //for classifiers
    287283    public static final String CHILD_TYPE_ATT = "childType";
     
    289285    public static final String HLIST = "HList";
    290286    public static final String VLIST = "VList";
    291    
     287
    292288    /**
    293289     * takes a list of elements, and returns an array of strings of the values
     
    709705        return node_list;
    710706    }
    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)
    712709    {
    713710        MyNodeList node_list = new MyNodeList();
     
    715712        while (child != null)
    716713        {
    717           if (child.getNodeType() == Node.ELEMENT_NODE && child.getNamespaceURI().equals(namespace) && child.getLocalName() != null && child.getLocalName().equals(local_name))
     714            if (child.getNodeType() == Node.ELEMENT_NODE && child.getNamespaceURI().equals(namespace) && child.getLocalName() != null && child.getLocalName().equals(local_name))
    718715            {
    719716                node_list.addNode(child);
     
    924921    }
    925922
    926   public static Element getNamedElementNS(Element parent, String namespace_uri, String node_local_name, String attribute_name, String attribute_value)
    927   {
     923    public static Element getNamedElementNS(Element parent, String namespace_uri, String node_local_name, String attribute_name, String attribute_value)
     924    {
    928925        NodeList children = parent.getChildNodes();
    929926        for (int i = 0; i < children.getLength(); i++)
    930927        {
    931928            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))
    933930            {
    934931                if (((Element) child).getAttribute(attribute_name).equals(attribute_value))
     
    939936        return null;
    940937
    941 
    942   }
     938    }
    943939
    944940    // In element main, tries to find any previous occurrence of elements with xsl-template-name=templateName,
     
    946942    // If this is the case, such a previous occurrence is removed from element main, since
    947943    // 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
    955952        Element old_elem = GSXML.getNamedElementNS(parent, namespace_uri, node_local_name, attribute_name, attribute_value);
    956953        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;
    968966        }
    969967
    970968        NodeList children = parent.getChildNodes();
    971   for (int i = children.getLength()-1; i >= 0; i--)
     969        for (int i = children.getLength() - 1; i >= 0; i--)
    972970        {
    973971            Node child = children.item(i);
     
    975973            {
    976974                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    }
    983979
    984980    /**
     
    10071003    }
    10081004
    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    }
    10191016
    10201017    public static int SORT_TYPE_STRING = 0;
Note: See TracChangeset for help on using the changeset viewer.