Ignore:
Timestamp:
2012-08-01T13:57:10+12:00 (12 years ago)
Author:
sjm84
Message:

Adding constants for the various XML namespaces used in the code

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util
Files:
3 edited

Legend:

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

    r26027 r26055  
    1919package org.greenstone.gsdl3.util;
    2020
    21 import java.io.File;
    22 //import org.apache.soap.encoding.soapenc.Base64;
    23 import org.apache.axis.encoding.Base64;
    2421import java.io.BufferedInputStream;
    2522import java.io.BufferedOutputStream;
     23import java.io.File;
    2624import java.io.FileInputStream;
    2725import java.io.FileOutputStream;
    28 import java.io.InputStream;
    2926import java.io.IOException;
    30 import java.lang.ClassLoader; // to find files on the class path
    31 import java.net.URL;
    3227import java.nio.channels.FileChannel;
    3328import java.util.ArrayList;
    34 import java.util.Collection;
    35 
    36 import org.apache.log4j.*;
     29
     30import org.apache.axis.encoding.Base64;
     31import org.apache.log4j.Logger;
    3732import org.greenstone.util.GlobalProperties;
    3833
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r26047 r26055  
    291291    public static final String VLIST = "VList";
    292292
     293    //for namespaces
     294    public static final String XSL_NAMESPACE = "http://www.w3.org/1999/XSL/Transform";
     295    public static final String GSF_NAMESPACE = "http://www.greenstone.org/greenstone3/schema/ConfigFormat";
     296    public static final String JAVA_NAMESPACE = "http://xml.apache.org/xslt/java";
     297    public static final String UTIL_NAMESPACE = "xalan://org.greenstone.gsdl3.util.XSLTUtil";
     298
    293299    /**
    294300     * takes a list of elements, and returns an array of strings of the values
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXSLT.java

    r25988 r26055  
    6161        Element main = main_xsl.getDocumentElement();
    6262        Node insertion_point = null;
    63         Element last_import = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "import");
     63        Element last_import = GSXML.getLastElementByTagNameNS(main, GSXML.XSL_NAMESPACE, "import");
    6464        if (last_import != null)
    6565        {
     
    7272
    7373        // imports
    74         NodeList children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "import");
     74        NodeList children = extra_xsl.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "import");
    7575        for (int i = 0; i < children.getLength(); i++)
    7676        {
     
    7878            // If the new xsl:import element is identical (in terms of href attr value)
    7979            // to any in the merged document, don't copy it over
    80             if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "import", "href", node.getAttribute("href")) == null)
     80            if (GSXML.getNamedElementNS(main, GSXML.XSL_NAMESPACE, "import", "href", node.getAttribute("href")) == null)
    8181            {
    8282                // Import statements should be the first children of an xsl:stylesheet element
     
    9090
    9191        // do we have a new insertion point??
    92         Element last_include = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "include");
     92        Element last_include = GSXML.getLastElementByTagNameNS(main, GSXML.XSL_NAMESPACE, "include");
    9393        if (last_include != null)
    9494        {
     
    9797
    9898        // includes
    99         children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "include");
     99        children = extra_xsl.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "include");
    100100        for (int i = 0; i < children.getLength(); i++)
    101101        {
     
    105105            // Although Node.appendChild() will first remove identical nodes before appending, we check
    106106            // only the href attribute to see if they're "identical" to any pre-existing <xsl:include>
    107             if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "include", "href", node.getAttribute("href")) == null)
     107            if (GSXML.getNamedElementNS(main, GSXML.XSL_NAMESPACE, "include", "href", node.getAttribute("href")) == null)
    108108            {
    109109                //main.appendChild(main_xsl.importNode(node, true));
     
    112112        } // for each include
    113113
    114         if (main.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "output").getLength() == 0)
     114        if (main.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "output").getLength() == 0)
    115115        {
    116116            // outputs
    117             children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "output");
     117            children = extra_xsl.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "output");
    118118            for (int i = 0; i < children.getLength(); i++)
    119119            {
     
    128128        // variables - only top level ones!!
    129129        // append to end of document
    130         children = GSXML.getChildrenByTagNameNS(extra_xsl, "http://www.w3.org/1999/XSL/Transform", "variable");
     130        children = GSXML.getChildrenByTagNameNS(extra_xsl, GSXML.XSL_NAMESPACE, "variable");
    131131        for (int i = 0; i < children.getLength(); i++)
    132132        {
     
    134134            // If the new xsl:import element is identical (in terms of href attr value)
    135135            // to any in the merged document, don't copy it over
    136             if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "variable", "name", node.getAttribute("name")) == null)
     136            if (GSXML.getNamedElementNS(main, GSXML.XSL_NAMESPACE, "variable", "name", node.getAttribute("name")) == null)
    137137            {
    138138                main.appendChild(main_xsl.importNode(node, true));
     
    142142        // params - only top level ones!!
    143143        // append to end of document
    144         children = GSXML.getChildrenByTagNameNS(extra_xsl, "http://www.w3.org/1999/XSL/Transform", "param");
     144        children = GSXML.getChildrenByTagNameNS(extra_xsl, GSXML.XSL_NAMESPACE, "param");
    145145        for (int i = 0; i < children.getLength(); i++)
    146146        {
     
    148148            // If the new xsl:import element is identical (in terms of href attr value)
    149149            // to any in the merged document, don't copy it over
    150             if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "param", "name", node.getAttribute("name")) == null)
     150            if (GSXML.getNamedElementNS(main, GSXML.XSL_NAMESPACE, "param", "name", node.getAttribute("name")) == null)
    151151            {
    152152                main.appendChild(main_xsl.importNode(node, true));
     
    156156        // templates
    157157        // append to end of document
    158         children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "template");
     158        children = extra_xsl.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "template");
    159159        for (int i = 0; i < children.getLength(); i++)
    160160        {
     
    168168            {
    169169                // if we have a name attribute, remove any other similarly named template
    170                 GSXML.removeElementsWithAttributesNS(main, "http://www.w3.org/1999/XSL/Transform", "template", new String[] { "name", "match", "mode" }, new String[] { template_name, template_match, template_mode });
     170                GSXML.removeElementsWithAttributesNS(main, GSXML.XSL_NAMESPACE, "template", new String[] { "name", "match", "mode" }, new String[] { template_name, template_match, template_mode });
    171171
    172172                // now add our good template in
     
    179179                // there can't be any duplicate named templates, so just look for matches
    180180                // we already have the one with highest import precedence (from the top most level) so don't add any more in
    181                 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)
     181                if (GSXML.getElementsWithAttributesNS(main, GSXML.XSL_NAMESPACE, "template", new String[] { "name", "match", "mode" }, new String[] { template_name, template_match, template_mode }).getLength() == 0)
    182182                {
    183183                    main.appendChild(main_xsl.importNode(node, true));
     
    204204                Element xslParent = (Element) current.getParentNode();
    205205
    206                 while (xslParent.getNamespaceURI() != "http://www.w3.org/1999/XSL/Transform" && !xslParent.getNodeName().startsWith("xsl:"))
     206                while (xslParent.getNamespaceURI() != GSXML.XSL_NAMESPACE && !xslParent.getNodeName().startsWith("xsl:"))
    207207                {
    208208                    xslParent = (Element) xslParent.getParentNode();
     
    220220    }
    221221
    222   public static void inlineImportAndIncludeFiles(Document doc, String pathExtra, String site, String collection, String interface_name, ArrayList<String> base_interfaces)
    223     {
    224       inlineImportAndIncludeFilesDebug(doc, pathExtra, false, null, site, collection, interface_name, base_interfaces);
    225     }
    226 
    227   public static void inlineImportAndIncludeFilesDebug(Document doc, String pathExtra, boolean debug, String docFileName, String site, String collection, String interface_name, ArrayList<String> base_interfaces)
     222    public static void inlineImportAndIncludeFiles(Document doc, String pathExtra, String site, String collection, String interface_name, ArrayList<String> base_interfaces)
     223    {
     224        inlineImportAndIncludeFilesDebug(doc, pathExtra, false, null, site, collection, interface_name, base_interfaces);
     225    }
     226
     227    public static void inlineImportAndIncludeFilesDebug(Document doc, String pathExtra, boolean debug, String docFileName, String site, String collection, String interface_name, ArrayList<String> base_interfaces)
    228228    {
    229229        XMLConverter converter = new XMLConverter();
     
    231231        String path = (pathExtra == null) ? "" : pathExtra;
    232232
    233         NodeList importList = doc.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "import");
    234         NodeList includeList = doc.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "include");
     233        NodeList importList = doc.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "import");
     234        NodeList includeList = doc.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "include");
    235235
    236236        for (int i = 0; i < importList.getLength() + includeList.getLength(); i++)
     
    243243            try
    244244            {
    245               //Document inlineDoc = converter.getDOM(new File(filePath), "UTF-8");
    246               Document inlineDoc = mergedXSLTDocumentCascade(path+href, site, collection, interface_name, base_interfaces, debug);
     245                //Document inlineDoc = converter.getDOM(new File(filePath), "UTF-8");
     246                Document inlineDoc = mergedXSLTDocumentCascade(path + href, site, collection, interface_name, base_interfaces, debug);
    247247                String newPath = path;
    248248                int lastSepIndex = href.lastIndexOf("/");
     
    253253
    254254                //Do this recursively
    255                 inlineImportAndIncludeFilesDebug(inlineDoc, newPath, debug, "merged "+href/*filePath*/, site, collection, interface_name, base_interfaces);
    256 
    257                 GSXSLT.mergeStylesheetsDebug(doc, inlineDoc.getDocumentElement(), false, debug, docFileName, /*filePath*/"merged "+href);
     255                inlineImportAndIncludeFilesDebug(inlineDoc, newPath, debug, "merged " + href/* filePath */, site, collection, interface_name, base_interfaces);
     256
     257                GSXSLT.mergeStylesheetsDebug(doc, inlineDoc.getDocumentElement(), false, debug, docFileName, /* filePath */"merged " + href);
    258258            }
    259259            catch (Exception ex)
     
    276276    }
    277277
    278         public static Document mergedXSLTDocumentCascade(String xslt_filename, String site, String collection, String this_interface, ArrayList<String> base_interfaces, boolean debug) {
    279           XMLConverter converter = new XMLConverter();
    280           // find the list of stylesheets with this name
    281           ArrayList<File> stylesheets = GSFile.getStylesheetFiles(GlobalProperties.getGSDL3Home(), site, collection, this_interface, base_interfaces, xslt_filename);
     278    public static Document mergedXSLTDocumentCascade(String xslt_filename, String site, String collection, String this_interface, ArrayList<String> base_interfaces, boolean debug)
     279    {
     280        XMLConverter converter = new XMLConverter();
     281        // find the list of stylesheets with this name
     282        ArrayList<File> stylesheets = GSFile.getStylesheetFiles(GlobalProperties.getGSDL3Home(), site, collection, this_interface, base_interfaces, xslt_filename);
    282283        if (stylesheets.size() == 0)
    283284        {
     
    314315    }
    315316
    316 
    317 
    318317    public static void modifyConfigFormatForDebug(Document doc, String fileName)
    319318    {
    320         NodeList templateNodes = doc.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "template");
     319        NodeList templateNodes = doc.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "template");
    321320        if (templateNodes.getLength() == 0)
    322321        {
     
    331330
    332331        XMLConverter converter = new XMLConverter();
    333         Element debugElement = (Element) converter.getDOM("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xslt:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:xslt=\"output.xsl\" xmlns:gsf=\"http://www.greenstone.org/greenstone3/schema/ConfigFormat\">" + debugElementString + "</xslt:stylesheet>").getDocumentElement().getFirstChild();
     332        Element debugElement = (Element) converter.getDOM("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xslt:stylesheet version=\"1.0\" xmlns:xsl=\"" + GSXML.XSL_NAMESPACE + "\" xmlns:xslt=\"output.xsl\" xmlns:gsf=\"" + GSXML.GSF_NAMESPACE + "\">" + debugElementString + "</xslt:stylesheet>").getDocumentElement().getFirstChild();
    334333
    335334        for (int i = 0; i < templateNodes.getLength(); i++)
     
    419418    public static void mergeFormatElements(Element mainFormat, Element secondaryFormat, boolean overwrite)
    420419    {
    421         NodeList xslChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.w3.org/1999/XSL/Transform", "variable");
    422         NodeList gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.greenstone.org/greenstone3/schema/ConfigFormat", "variable");
     420        NodeList xslChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.XSL_NAMESPACE, "variable");
     421        NodeList gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.GSF_NAMESPACE, "variable");
    423422        for (int i = 0; i < xslChildren.getLength() + gsfChildren.getLength(); i++)
    424423        {
     
    430429        }
    431430
    432         xslChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.w3.org/1999/XSL/Transform", "param");
    433         gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.greenstone.org/greenstone3/schema/ConfigFormat", "param");
     431        xslChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.XSL_NAMESPACE, "param");
     432        gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.GSF_NAMESPACE, "param");
    434433        for (int i = 0; i < xslChildren.getLength() + gsfChildren.getLength(); i++)
    435434        {
     
    441440        }
    442441
    443         xslChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.w3.org/1999/XSL/Transform", "template");
    444         gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.greenstone.org/greenstone3/schema/ConfigFormat", "template");
     442        xslChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.XSL_NAMESPACE, "template");
     443        gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.GSF_NAMESPACE, "template");
    445444        for (int i = 0; i < xslChildren.getLength() + gsfChildren.getLength(); i++)
    446445        {
     
    457456            {
    458457                // if we have a name attribute, remove any other similarly named template
    459                 GSXML.removeElementsWithAttributesNS(mainFormat, "http://www.w3.org/1999/XSL/Transform", "template", attributeNames, attributeValues);
    460                 GSXML.removeElementsWithAttributesNS(mainFormat, "http://www.greenstone.org/greenstone3/schema/ConfigFormat", "template", attributeNames, attributeValues);
     458                GSXML.removeElementsWithAttributesNS(mainFormat, GSXML.XSL_NAMESPACE, "template", attributeNames, attributeValues);
     459                GSXML.removeElementsWithAttributesNS(mainFormat, GSXML.GSF_NAMESPACE, "template", attributeNames, attributeValues);
    461460
    462461                // now add our good template in
     
    476475        }
    477476
    478         gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.greenstone.org/greenstone3/schema/ConfigFormat", "option");
     477        gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.GSF_NAMESPACE, "option");
    479478        for (int i = 0; i < gsfChildren.getLength(); i++)
    480479        {
    481480            Element node = (Element) gsfChildren.item(i);
    482             if (GSXML.getNamedElementNS(mainFormat, "http://www.greenstone.org/greenstone3/schema/ConfigFormat", "option", "name", node.getAttribute("name")) == null)
     481            if (GSXML.getNamedElementNS(mainFormat, GSXML.GSF_NAMESPACE, "option", "name", node.getAttribute("name")) == null)
    483482            {
    484483                mainFormat.appendChild(node);
Note: See TracChangeset for help on using the changeset viewer.