Changeset 25913

Show
Ignore:
Timestamp:
10.07.2012 10:22:25 (7 years ago)
Author:
sjm84
Message:

Reformatting this file ahead of some changes

Files:
1 modified

Legend:

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

    r25847 r25913  
    4444     * named templates overwrite any existing one, while match templates are 
    4545     * just added to the end of the stylesheet 
    46  
    47      * elements are added in following order, and added to preserve original order with imported ones coming after existing ones 
    48      * import, include, output, variable, template 
     46     *  
     47     * elements are added in following order, and added to preserve original 
     48     * order with imported ones coming after existing ones import, include, 
     49     * output, variable, template 
    4950     */ 
    5051    public static void mergeStylesheetsDebug(Document main_xsl, Element extra_xsl, boolean overwrite, boolean debug, String firstDocFileName, String secondDocFileName) 
     
    5859        Element main = main_xsl.getDocumentElement(); 
    5960        Node insertion_point = null; 
    60           Element last_import = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "import"); 
    61           if (last_import != null) { 
    62             insertion_point = last_import.getNextSibling(); 
    63           } else { 
    64             insertion_point = main.getFirstChild(); 
    65           } 
    66          
     61        Element last_import = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "import"); 
     62        if (last_import != null) 
     63        { 
     64            insertion_point = last_import.getNextSibling(); 
     65        } 
     66        else 
     67        { 
     68            insertion_point = main.getFirstChild(); 
     69        } 
     70 
    6771        // imports 
    6872        NodeList children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "import"); 
    6973        for (int i = 0; i < children.getLength(); i++) 
    7074        { 
    71           Element node = (Element) children.item(i); 
     75            Element node = (Element) children.item(i); 
    7276            // If the new xsl:import element is identical (in terms of href attr value)  
    7377            // to any in the merged document, don't copy it over 
     
    7983                // only the href attribute to see if they're "identical" to any pre-existing <xsl:import> 
    8084                //main.insertBefore(main_xsl.importNode(node, true), main.getFirstChild()); 
    81               main.insertBefore(main_xsl.importNode(node, true), insertion_point); 
    82                
    83             } 
    84         } 
    85      
    86           // do we have a new insertion point?? 
    87            Element last_include = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "include"); 
    88            if (last_include != null) {               
    89              insertion_point = last_include.getNextSibling(); 
    90            } 
    91      
     85                main.insertBefore(main_xsl.importNode(node, true), insertion_point); 
     86 
     87            } 
     88        } 
     89 
     90        // do we have a new insertion point?? 
     91        Element last_include = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "include"); 
     92        if (last_include != null) 
     93        { 
     94            insertion_point = last_include.getNextSibling(); 
     95        } 
     96 
    9297        // includes 
    9398        children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "include"); 
    9499        for (int i = 0; i < children.getLength(); i++) 
    95100        { 
    96           Element node = (Element)children.item(i); 
     101            Element node = (Element) children.item(i); 
    97102            // If the new xsl:include element is identical (in terms of href attr value) 
    98103            // to any in the merged document, don't copy it over 
    99104            // Although Node.appendChild() will first remove identical nodes before appending, we check 
    100105            // only the href attribute to see if they're "identical" to any pre-existing <xsl:include> 
    101             if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "include", "href", node.getAttribute("href"))==null) 
    102             { 
    103               //main.appendChild(main_xsl.importNode(node, true)); 
    104               main.insertBefore(main_xsl.importNode(node, true), insertion_point); 
     106            if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "include", "href", node.getAttribute("href")) == null) 
     107            { 
     108                //main.appendChild(main_xsl.importNode(node, true)); 
     109                main.insertBefore(main_xsl.importNode(node, true), insertion_point); 
    105110            } 
    106111        } // for each include 
    107          
    108           // do we have a new insertion point?? 
    109            Element last_output = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "output"); 
    110            if (last_output != null) {                
    111              insertion_point = last_output.getNextSibling(); 
    112            } 
     112 
     113        // do we have a new insertion point?? 
     114        Element last_output = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "output"); 
     115        if (last_output != null) 
     116        { 
     117            insertion_point = last_output.getNextSibling(); 
     118        } 
    113119 
    114120        // outputs 
     
    116122        for (int i = 0; i < children.getLength(); i++) 
    117123        { 
    118           Element node = (Element)children.item(i); 
     124            Element node = (Element) children.item(i); 
    119125            // If the new xsl:output element is identical (in terms of the value for the method attr)  
    120126            // to any in the merged document, don't copy it over 
    121             if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "output", "method", node.getAttribute("method"))==null) 
     127            if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "output", "method", node.getAttribute("method")) == null) 
    122128            { 
    123129                main.insertBefore(main_xsl.importNode(node, true), insertion_point); 
     
    130136        for (int i = 0; i < children.getLength(); i++) 
    131137        { 
    132           Element node = (Element)children.item(i); 
     138            Element node = (Element) children.item(i); 
    133139            // If the new xsl:import element is identical (in terms of href attr value)  
    134140            // to any in the merged document, don't copy it over 
    135             if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform","variable", "name", node.getAttribute("name"))==null) 
     141            if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "variable", "name", node.getAttribute("name")) == null) 
    136142            { 
    137143                main.appendChild(main_xsl.importNode(node, true)); 
     
    144150        for (int i = 0; i < children.getLength(); i++) 
    145151        { 
    146           Element node = (Element) children.item(i); 
     152            Element node = (Element) children.item(i); 
    147153            // remove any previous occurrences of xsl:template with the same value for name or match  
    148               String template_match = node.getAttribute("match"); 
    149               String template_name = node.getAttribute("name"); 
     154            String template_match = node.getAttribute("match"); 
     155            String template_name = node.getAttribute("name"); 
    150156 
    151157            if (overwrite) 
    152158            { 
    153               // if we have a name attribute, remove any other similarly named template 
    154               if (!template_name.equals("")) { 
    155                 GSXML.removeNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "name", template_name); 
    156               } 
    157               // if we have a match attribute, remove other templates that match -  
    158               if (!template_match.equals("")) { 
    159                 GSXML.removeNamedElementsNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "match", template_match); 
    160               } 
    161               // now add our good template in 
    162               main.appendChild(main_xsl.importNode(node, true)); 
    163             } 
    164             else  
    165               { 
    166             // if overwrite is false, then we only add in templates if they don't match something else. 
    167             // In this case (eg from expanding imported stylesheets) 
    168             // there can't be any duplicate named templates, so just look for matches 
    169                 // we already have the one with highest import precedence (from the top most level) so don't add any more in 
    170                 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform","template", "match", template_match) == null) 
    171             { 
     159                // if we have a name attribute, remove any other similarly named template 
     160                if (!template_name.equals("")) 
     161                { 
     162                    GSXML.removeNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "name", template_name); 
     163                } 
     164                // if we have a match attribute, remove other templates that match -  
     165                if (!template_match.equals("")) 
     166                { 
     167                    GSXML.removeNamedElementsNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "match", template_match); 
     168                } 
     169                // now add our good template in 
    172170                main.appendChild(main_xsl.importNode(node, true)); 
    173171            } 
    174               } 
     172            else 
     173            { 
     174                // if overwrite is false, then we only add in templates if they don't match something else. 
     175                // In this case (eg from expanding imported stylesheets) 
     176                // there can't be any duplicate named templates, so just look for matches 
     177                // we already have the one with highest import precedence (from the top most level) so don't add any more in 
     178                if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "match", template_match) == null) 
     179                { 
     180                    main.appendChild(main_xsl.importNode(node, true)); 
     181                } 
     182            } 
    175183        } 
    176184 
     
    312320        } 
    313321    } 
    314  
    315  
    316  
    317322 
    318323    /**