Changeset 25914


Ignore:
Timestamp:
2012-07-10T10:25:12+12:00 (9 years ago)
Author:
sjm84
Message:

Some fixes so that we can manage xsl imports and includes by outselves

File:
1 edited

Legend:

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

    r25913 r25914  
    1919package org.greenstone.gsdl3.util;
    2020
    21 import java.io.BufferedWriter;
    2221import java.io.File;
    23 import java.io.FileWriter;
    2422import java.util.ArrayList;
    2523import java.util.Vector;
     
    2826import org.w3c.dom.Document;
    2927import org.w3c.dom.Element;
    30 import org.w3c.dom.NamedNodeMap;
    3128import org.w3c.dom.Node;
    3229import org.w3c.dom.NodeList;
     
    8481                //main.insertBefore(main_xsl.importNode(node, true), main.getFirstChild());
    8582                main.insertBefore(main_xsl.importNode(node, true), insertion_point);
    86 
    8783            }
    8884        }
     
    111107        } // for each include
    112108
    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         }
    119 
    120         // outputs
    121         children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "output");
    122         for (int i = 0; i < children.getLength(); i++)
    123         {
    124             Element node = (Element) children.item(i);
    125             // If the new xsl:output element is identical (in terms of the value for the method attr)
    126             // to any in the merged document, don't copy it over
    127             if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "output", "method", node.getAttribute("method")) == null)
    128             {
     109        if (main.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "output").getLength() == 0)
     110        {
     111            // outputs
     112            children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "output");
     113            for (int i = 0; i < children.getLength(); i++)
     114            {
     115                Element node = (Element) children.item(i);
     116                // If the new xsl:output element is identical (in terms of the value for the method attr)
     117                // to any in the merged document, don't copy it over
     118
    129119                main.insertBefore(main_xsl.importNode(node, true), insertion_point);
    130120            }
     
    140130            // to any in the merged document, don't copy it over
    141131            if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "variable", "name", node.getAttribute("name")) == null)
     132            {
     133                main.appendChild(main_xsl.importNode(node, true));
     134            }
     135        }
     136
     137        // params - only top level ones!!
     138        // append to end of document
     139        children = GSXML.getChildrenByTagNameNS(extra_xsl, "http://www.w3.org/1999/XSL/Transform", "param");
     140        for (int i = 0; i < children.getLength(); i++)
     141        {
     142            Element node = (Element) children.item(i);
     143            // If the new xsl:import element is identical (in terms of href attr value)
     144            // to any in the merged document, don't copy it over
     145            if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "param", "name", node.getAttribute("name")) == null)
    142146            {
    143147                main.appendChild(main_xsl.importNode(node, true));
     
    180184                    main.appendChild(main_xsl.importNode(node, true));
    181185                }
     186
     187                if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "name", template_name) == null)
     188                {
     189                    main.appendChild(main_xsl.importNode(node, true));
     190                }
    182191            }
    183192        }
     
    217226    }
    218227
    219     public static void inlineImportAndIncludeFiles(Document doc, String pathExtra, int depth)
    220     {
    221         inlineImportAndIncludeFilesDebug(doc, pathExtra, depth, false, null);
    222     }
    223 
    224     public static void inlineImportAndIncludeFilesDebug(Document doc, String pathExtra, int depth, boolean debug, String docFileName)
     228    public static void inlineImportAndIncludeFiles(Document doc, String pathExtra)
     229    {
     230        inlineImportAndIncludeFilesDebug(doc, pathExtra, false, null);
     231    }
     232
     233    public static void inlineImportAndIncludeFilesDebug(Document doc, String pathExtra, boolean debug, String docFileName)
    225234    {
    226235        XMLConverter converter = new XMLConverter();
    227236
    228         String path = pathExtra;
    229         if (path == null)
    230         {
    231             path = "";
    232         }
     237        String path = (pathExtra == null) ? "" : pathExtra;
    233238
    234239        NodeList importList = doc.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "import");
    235240        NodeList includeList = doc.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "include");
    236241
    237         if (importList.getLength() == 0)
    238         {
    239             importList = doc.getElementsByTagName("xsl:import");
    240         }
    241         if (includeList.getLength() == 0)
    242         {
    243             includeList = doc.getElementsByTagName("xsl:include");
    244         }
    245 
    246242        for (int i = 0; i < importList.getLength() + includeList.getLength(); i++)
    247243        {
    248244            Element current = (Element) ((i < importList.getLength()) ? importList.item(i) : includeList.item(i - importList.getLength()));
    249245            String href = current.getAttribute("href");
    250 
    251             String filePath = GSFile.interfaceHome(GlobalProperties.getGSDL3Home(), "oran") + File.separator + "transform" + File.separator + path.replace("/", File.separator) + href.replace("/", File.separator);
     246            String filePath = GSFile.interfaceHome(GlobalProperties.getGSDL3Home(), "default") + File.separator + "transform" + File.separator + path.replace("/", File.separator) + href.replace("/", File.separator);
     247            System.err.println("ADDING IN " + filePath);
    252248
    253249            try
    254250            {
    255                 Document inlineDoc = converter.getDOM(new File(filePath));
     251                Document inlineDoc = converter.getDOM(new File(filePath), "UTF-8");
    256252
    257253                String newPath = path;
     
    263259
    264260                //Do this recursively
    265                 inlineImportAndIncludeFilesDebug(inlineDoc, newPath, depth + 1, debug, filePath);
     261                inlineImportAndIncludeFilesDebug(inlineDoc, newPath, debug, filePath);
     262
    266263                GSXSLT.mergeStylesheetsDebug(doc, inlineDoc.getDocumentElement(), false, debug, docFileName, filePath);
    267264            }
Note: See TracChangeset for help on using the changeset viewer.