Changeset 24884


Ignore:
Timestamp:
2011-12-13T09:55:30+13:00 (12 years ago)
Author:
sjm84
Message:

Added the ability to do an inline template in the cgi arguments with the ilt parameter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java

    r24703 r24884  
    1515
    1616// other java classes
     17import java.io.ByteArrayInputStream;
    1718import java.io.File;
     19import java.io.StringReader;
    1820import java.io.StringWriter;
    1921import java.io.FileReader;
     
    449451        Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    450452        String collection = "";
     453        String inlineTemplate = "";
    451454        if (cgi_param_list != null)
    452455        {
    453456            // Don't waste time getting all the parameters
    454             HashMap params = GSXML.extractParams(cgi_param_list, false, GSParams.COLLECTION);
     457            HashMap params = GSXML.extractParams(cgi_param_list, false);
    455458            collection = (String) params.get(GSParams.COLLECTION);
    456459            if (collection == null)
     460            {
    457461                collection = "";
     462            }
     463
     464            inlineTemplate = (String) params.get(GSParams.INLINE_TEMPLATE);
    458465        }
    459466
     
    535542        try
    536543        {
    537             preprocessingXsl = getPreprocessDoc();
     544            preprocessingXsl = getDoc(preprocess_xsl_filename);
    538545            String errMsg = ((XMLConverter.ParseErrorHandler) parser.getErrorHandler()).getErrorMessage();
    539546            if (errMsg != null)
     
    556563        try
    557564        {
    558             libraryXsl = getLibraryDoc();
     565            libraryXsl = getDoc(this.getLibraryXSLFilename());
    559566            String errMsg = ((XMLConverter.ParseErrorHandler) parser.getErrorHandler()).getErrorMessage();
    560567            if (errMsg != null)
     
    755762        //System.out.println("Generate final HTML from current skin") ;
    756763        //Transformation of the XML message from the receptionist to HTML with doctype
     764
     765        if(inlineTemplate != null)
     766        {
     767            try
     768            {
     769                Document inlineTemplateDoc = this.converter.getDOM("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:java=\"http://xml.apache.org/xslt/java\" xmlns:util=\"xalan://org.greenstone.gsdl3.util.XSLTUtil\" xmlns:gsf=\"http://www.greenstone.org/greenstone3/schema/ConfigFormat\">" + inlineTemplate + "</xsl:stylesheet>");
     770                GSXSLT.mergeStylesheets(skinAndLibraryDoc, inlineTemplateDoc.getDocumentElement());
     771            }
     772            catch(Exception ex)
     773            {
     774                ex.printStackTrace();
     775            }
     776        }
    757777       
    758         if(skinAndLibraryDoc.getElementsByTagName("gsf:metadata").getLength() > 0)
     778        if (skinAndLibraryDoc.getElementsByTagName("gsf:metadata").getLength() > 0)
    759779        {
    760780            secondConfigFormatPass(collection, skinAndLibraryDoc, doc, request.getAttribute("lang"), request.getAttribute("uid"));
    761781        }
    762        
     782
    763783        if (output.equals("xmlfinal"))
    764784        {
    765785            return doc;
    766786        }
    767        
     787
    768788        return this.transformer.transform(skinAndLibraryDoc, doc, config_params, docWithDoctype); // The default
    769789
     
    774794        //return null; // For now - change later
    775795    }
    776    
     796
    777797    protected void secondConfigFormatPass(String collection, Document skinAndLibraryDoc, Document doc, String lang, String uid)
    778798    {
     
    782802        Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    783803        Element docNodeList = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
    784        
     804
    785805        NodeList metaNodes = skinAndLibraryDoc.getElementsByTagName("gsf:metadata");
    786806
    787         for(int i = 0; i < metaNodes.getLength(); i++)
     807        for (int i = 0; i < metaNodes.getLength(); i++)
    788808        {
    789809            Element param = this.doc.createElement(GSXML.PARAM_ELEM);
    790810            param.setAttribute(GSXML.NAME_ATT, "metadata");
    791             param.setAttribute(GSXML.VALUE_ATT, ((Element)metaNodes.item(i)).getAttribute(GSXML.NAME_ATT));
     811            param.setAttribute(GSXML.VALUE_ATT, ((Element) metaNodes.item(i)).getAttribute(GSXML.NAME_ATT));
    792812            paramList.appendChild(param);
    793813        }
    794814        metaRequest.appendChild(paramList);
    795        
     815
    796816        NodeList docNodes = doc.getElementsByTagName("documentNode");
    797         for(int i = 0; i < docNodes.getLength(); i++)
     817        for (int i = 0; i < docNodes.getLength(); i++)
    798818        {
    799819            Element docNode = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    800             docNode.setAttribute(GSXML.NODE_ID_ATT, ((Element)docNodes.item(i)).getAttribute(GSXML.NODE_ID_ATT));
    801             docNode.setAttribute(GSXML.NODE_TYPE_ATT, ((Element)docNodes.item(i)).getAttribute(GSXML.NODE_TYPE_ATT));
     820            docNode.setAttribute(GSXML.NODE_ID_ATT, ((Element) docNodes.item(i)).getAttribute(GSXML.NODE_ID_ATT));
     821            docNode.setAttribute(GSXML.NODE_TYPE_ATT, ((Element) docNodes.item(i)).getAttribute(GSXML.NODE_TYPE_ATT));
    802822            docNodeList.appendChild(docNode);
    803823        }
     
    805825
    806826        metaMessage.appendChild(metaRequest);
    807         Element response = (Element)mr.process(metaMessage);
     827        Element response = (Element) mr.process(metaMessage);
    808828
    809829        NodeList metaDocNodes = response.getElementsByTagName(GSXML.DOC_NODE_ELEM);
    810         for(int i = 0; i < docNodes.getLength(); i++)
     830        for (int i = 0; i < docNodes.getLength(); i++)
    811831        {
    812832            GSXML.mergeMetadataLists(docNodes.item(i), metaDocNodes.item(i));
    813833        }
    814        
     834
    815835        String configStylesheet_file = GSFile.stylesheetFile(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, "config_format.xsl");
    816836        Document configStylesheet_doc = this.converter.getDOM(new File(configStylesheet_file));
     
    821841            format_doc.appendChild(format_doc.importNode(skinAndLibraryDoc.getDocumentElement().cloneNode(true), true));
    822842            Node result = this.transformer.transform(configStylesheet_doc, format_doc, config_params);
    823             GSXSLT.mergeStylesheets(skinAndLibraryDoc, ((Document)result).getDocumentElement());
     843            GSXSLT.mergeStylesheets(skinAndLibraryDoc, ((Document) result).getDocumentElement());
    824844        }
    825845    }
     
    850870    }
    851871
    852     protected Document getPreprocessDoc() throws Exception
    853     {
    854 
    855         File xslt_file = new File(preprocess_xsl_filename);
     872    protected synchronized Document getDoc(String docName) throws Exception
     873    {
     874        File xslt_file = new File(docName);
    856875
    857876        FileReader reader = new FileReader(xslt_file);
     
    863882    }
    864883
    865     protected Document getLibraryDoc() throws Exception
    866     {
    867         Document doc = null;
    868         File xslt_file = new File(this.getLibraryXSLFilename());
    869 
    870         FileReader reader = new FileReader(xslt_file);
    871         InputSource xml_source = new InputSource(reader);
    872         this.parser.parse(xml_source);
    873 
    874         doc = this.parser.getDocument();
    875         return doc;
    876     }
    877 
    878884    protected Document getXSLTDocument(String action, String subaction, String collection)
    879885    {
     
    898904        }
    899905        logger.debug("Stylesheet: " + name);
    900        
    901         Document finalDoc = this.converter.getDOM(stylesheets.get(stylesheets.size() -1), "UTF-8");
    902         if(finalDoc == null)
     906
     907        Document finalDoc = this.converter.getDOM(stylesheets.get(stylesheets.size() - 1), "UTF-8");
     908        if (finalDoc == null)
    903909        {
    904910            return null;
    905911        }
    906        
    907         for(int i = stylesheets.size() - 2; i >= 0; i--)
     912
     913        for (int i = stylesheets.size() - 2; i >= 0; i--)
    908914        {
    909915            Document currentDoc = this.converter.getDOM(stylesheets.get(i), "UTF-8");
    910             if(currentDoc == null)
     916            if (currentDoc == null)
    911917            {
    912918                return null;
    913919            }
    914            
     920
    915921            GSXSLT.mergeStylesheets(finalDoc, currentDoc.getDocumentElement());
    916922        }
    917        
     923
    918924        return finalDoc;
    919925    }
Note: See TracChangeset for help on using the changeset viewer.