Changeset 25912

Show
Ignore:
Timestamp:
10.07.2012 10:18:38 (7 years ago)
Author:
sjm84
Message:

Switching to managing imports and includes ourselves as well as some tidying

Files:
1 modified

Legend:

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

    r25872 r25912  
    9292            e.printStackTrace(); 
    9393        } 
    94  
    9594    } 
    9695 
     
    559558        //for debug purposes only 
    560559        Document oldStyle_doc = style_doc; 
    561  
    562560        Document preprocessingXsl; 
    563561        try 
     
    641639        } 
    642640 
    643         //The following code is to be uncommented if we need to append the extracted GSF statements 
    644         //after having extracted the GSLib elements. In case of a problem during postprocessing. 
    645         /* 
    646          * // put the page into a document - this is necessary for xslt to get 
    647          * // the paths right if you have paths relative to the document root // 
    648          * eg /page. Document doc = this.converter.newDOM(); 
    649          * doc.appendChild(doc.importNode(page, true)); Element page_response = 
    650          * (Element)GSXML.getChildByTagName(page, GSXML.PAGE_RESPONSE_ELEM); 
    651          * Element format_elem = (Element)GSXML.getChildByTagName(page_response, 
    652          * GSXML.FORMAT_ELEM); if (output.equals("formatelem")) { return 
    653          * format_elem; } if (format_elem != null) { 
    654          * //page_response.removeChild(format_elem); 
    655          * logger.debug("format elem="+ 
    656          * this.converter.getPrettyString(format_elem)); // need to transform 
    657          * the format info String configStylesheet_file = 
    658          * GSFile.stylesheetFile(GlobalProperties.getGSDL3Home(), 
    659          * (String)this.config_params.get(GSConstants.SITE_NAME), collection, 
    660          * (String)this.config_params.get(GSConstants.INTERFACE_NAME), 
    661          * base_interfaces, "config_format.xsl"); Document configStylesheet_doc 
    662          * = this.converter.getDOM(new File(configStylesheet_file)); if 
    663          * (configStylesheet_doc != null) { Document format_doc = 
    664          * this.converter.newDOM(); 
    665          * format_doc.appendChild(format_doc.importNode(format_elem, true)); 
    666          * Node result = this.transformer.transform(configStylesheet_doc, 
    667          * format_doc); 
    668          *  
    669          * // Since we started creating documents with DocTypes, we can end up 
    670          * with // Document objects here. But we will be working with an Element 
    671          * instead, // so we grab the DocumentElement() of the Document object 
    672          * in such a case. Element new_format; if(result.getNodeType() == 
    673          * Node.DOCUMENT_NODE) { new_format = 
    674          * ((Document)result).getDocumentElement(); } else { new_format = 
    675          * (Element)result; } 
    676          * logger.debug("new format elem="+this.converter.getPrettyString 
    677          * (new_format)); if (output.equals("newformat")) { return new_format; } 
    678          *  
    679          * // add extracted GSF statements in to the main stylesheet 
    680          * GSXSLT.mergeStylesheets(skinAndLibraryDoc, new_format); 
    681          * //System.out.println 
    682          * ("added extracted GSF statements into the main stylesheet") ; 
    683          *  
    684          * // add extracted GSF statements in to the debug test stylesheet 
    685          * //GSXSLT.mergeStylesheets(oldStyle_doc, new_format); } else { 
    686          * logger.error( 
    687          * " couldn't parse the config_format stylesheet, adding the format info as is" 
    688          * ); GSXSLT.mergeStylesheets(skinAndLibraryDoc, format_elem); // 
    689          * GSXSLT.mergeStylesheets(oldStyle_doc, format_elem); } 
    690          * logger.debug("the converted stylesheet is:"); 
    691          * logger.debug(this.converter 
    692          * .getPrettyString(skinAndLibraryDoc.getDocumentElement())); } 
    693          */ 
    694  
    695641        // there is a thing called a URIResolver which you can set for a 
    696642        // transformer or transformer factory. may be able to use this 
    697643        // instead of this absoluteIncludepaths hack 
    698644 
    699         GSXSLT.absoluteIncludePaths(skinAndLibraryDoc, GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces); 
     645        //GSXSLT.absoluteIncludePaths(skinAndLibraryDoc, GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces); 
    700646 
    701647        //Same but for the debug version when we want the do the transformation like we use to do 
     
    793739        } 
    794740 
    795         if (skinAndLibraryDoc.getElementsByTagName("gsf:metadata").getLength() > 0) 
    796         { 
    797             secondConfigFormatPass(collection, skinAndLibraryDoc, doc, new UserContext(request)); 
     741        GSXSLT.inlineImportAndIncludeFiles(skinAndLibraryDoc, null); 
     742        skinAndLibraryDoc = (Document) secondConfigFormatPass(collection, skinAndLibraryDoc, doc, new UserContext(request)); 
     743 
     744        if (_debug) 
     745        { 
     746            GSXML.addDebugSpanTags(skinAndLibraryDoc); 
    798747        } 
    799748 
     
    803752        } 
    804753 
    805         if (_debug) 
    806         { 
    807             GSXML.addDebugSpanTags(skinAndLibraryDoc); 
    808         } 
    809754        if (output.equals("skinandlibdocfinal")) 
    810755        { 
    811756            return converter.getDOM(getStringFromDocument(skinAndLibraryDoc)); 
    812757        } 
     758 
    813759        return this.transformer.transform(skinAndLibraryDoc, doc, config_params, docWithDoctype); 
    814760 
     
    820766    } 
    821767 
    822     protected void secondConfigFormatPass(String collection, Document skinAndLibraryDoc, Document doc, UserContext userContext) 
     768    protected Node secondConfigFormatPass(String collection, Document skinAndLibraryDoc, Document doc, UserContext userContext) 
    823769    { 
    824770        String to = GSPath.appendLink(collection, "DocumentMetadataRetrieve"); // Hard-wired? 
     
    863809        if (configStylesheet_doc != null) 
    864810        { 
    865             Document format_doc = XMLConverter.newDOM(); 
    866             format_doc.appendChild(format_doc.importNode(skinAndLibraryDoc.getDocumentElement().cloneNode(true), true)); 
    867             Node result = this.transformer.transform(configStylesheet_doc, format_doc, config_params); 
    868             if (_debug) 
    869             { 
    870                 GSXSLT.mergeStylesheetsDebug(skinAndLibraryDoc, ((Document) result).getDocumentElement(), true, true, "OTHER3", GSFile.collectionConfigFile(GSFile.collectDir(GSFile.siteHome(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME)) + File.separator + collection))); 
    871             } 
    872             else 
    873             { 
    874                 GSXSLT.mergeStylesheets(skinAndLibraryDoc, ((Document) result).getDocumentElement(), true); 
    875                 // we just want the result of the transform to be in skinAndLibraryDoc 
    876                 Element old_doc = skinAndLibraryDoc.getDocumentElement(); 
    877                 skinAndLibraryDoc.removeChild(old_doc); 
    878                 skinAndLibraryDoc.appendChild(skinAndLibraryDoc.importNode(((Document) result).getDocumentElement(), true)); 
    879             } 
    880         } 
     811            return this.transformer.transform(configStylesheet_doc, skinAndLibraryDoc, config_params); 
     812        } 
     813        return skinAndLibraryDoc; 
    881814    } 
    882815 
     
    933866        // now find the absolute path 
    934867        ArrayList<File> stylesheets = GSFile.getStylesheetFiles(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, name); 
    935  
    936868        if (stylesheets.size() == 0) 
    937869        { 
     
    963895                GSXSLT.mergeStylesheets(finalDoc, currentDoc.getDocumentElement(), true); 
    964896            } 
    965         } 
    966  
    967         if (_debug) 
    968         { 
    969             GSXSLT.inlineImportAndIncludeFiles(finalDoc, null, 0); 
    970897        } 
    971898