Changeset 24703


Ignore:
Timestamp:
2011-09-30T15:10:57+13:00 (13 years ago)
Author:
sjm84
Message:

If there is any gsf:metadata elements in the skin xsl these will now also be expanded via a second pass through config_format.xsl

File:
1 edited

Legend:

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

    r24583 r24703  
    2828import javax.xml.transform.stream.*;
    2929import org.apache.log4j.*;
     30import org.apache.tools.zip.ExtraFieldUtils;
    3031import org.apache.xerces.dom.*;
    3132import org.apache.xerces.parsers.DOMParser;
     
    754755        //System.out.println("Generate final HTML from current skin") ;
    755756        //Transformation of the XML message from the receptionist to HTML with doctype
    756 
     757       
     758        if(skinAndLibraryDoc.getElementsByTagName("gsf:metadata").getLength() > 0)
     759        {
     760            secondConfigFormatPass(collection, skinAndLibraryDoc, doc, request.getAttribute("lang"), request.getAttribute("uid"));
     761        }
     762       
     763        if (output.equals("xmlfinal"))
     764        {
     765            return doc;
     766        }
     767       
    757768        return this.transformer.transform(skinAndLibraryDoc, doc, config_params, docWithDoctype); // The default
    758769
     
    762773        //return (Element)this.transformer.transform(style_doc, doc, config_params); 
    763774        //return null; // For now - change later
     775    }
     776   
     777    protected void secondConfigFormatPass(String collection, Document skinAndLibraryDoc, Document doc, String lang, String uid)
     778    {
     779        String to = GSPath.appendLink(collection, "DocumentMetadataRetrieve"); // Hard-wired?
     780        Element metaMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
     781        Element metaRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
     782        Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     783        Element docNodeList = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
     784       
     785        NodeList metaNodes = skinAndLibraryDoc.getElementsByTagName("gsf:metadata");
     786
     787        for(int i = 0; i < metaNodes.getLength(); i++)
     788        {
     789            Element param = this.doc.createElement(GSXML.PARAM_ELEM);
     790            param.setAttribute(GSXML.NAME_ATT, "metadata");
     791            param.setAttribute(GSXML.VALUE_ATT, ((Element)metaNodes.item(i)).getAttribute(GSXML.NAME_ATT));
     792            paramList.appendChild(param);
     793        }
     794        metaRequest.appendChild(paramList);
     795       
     796        NodeList docNodes = doc.getElementsByTagName("documentNode");
     797        for(int i = 0; i < docNodes.getLength(); i++)
     798        {
     799            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));
     802            docNodeList.appendChild(docNode);
     803        }
     804        metaRequest.appendChild(docNodeList);
     805
     806        metaMessage.appendChild(metaRequest);
     807        Element response = (Element)mr.process(metaMessage);
     808
     809        NodeList metaDocNodes = response.getElementsByTagName(GSXML.DOC_NODE_ELEM);
     810        for(int i = 0; i < docNodes.getLength(); i++)
     811        {
     812            GSXML.mergeMetadataLists(docNodes.item(i), metaDocNodes.item(i));
     813        }
     814       
     815        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");
     816        Document configStylesheet_doc = this.converter.getDOM(new File(configStylesheet_file));
     817
     818        if (configStylesheet_doc != null)
     819        {
     820            Document format_doc = this.converter.newDOM();
     821            format_doc.appendChild(format_doc.importNode(skinAndLibraryDoc.getDocumentElement().cloneNode(true), true));
     822            Node result = this.transformer.transform(configStylesheet_doc, format_doc, config_params);
     823            GSXSLT.mergeStylesheets(skinAndLibraryDoc, ((Document)result).getDocumentElement());
     824        }
    764825    }
    765826
Note: See TracChangeset for help on using the changeset viewer.