Changeset 27090

Show
Ignore:
Timestamp:
15.03.2013 14:09:47 (7 years ago)
Author:
ak19
Message:

Now XMLTransformer sets the doctype of the document generated from what the transformer object has worked this out to be from (merged) stylesheets. Now TransformingReceptionist? no longer generates a new document with a doctype (that it has to work out from merged stylesheets) to pass into XMLTransformer.transform().

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
2 modified

Legend:

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

    r26848 r27090  
    901901        } 
    902902 
     903        // We now no longer create a document with doctype before the transformation 
     904        // We let the XMLTransformer do the work of first working out the doctype from any  
     905        // that may be set in the (merged) stylesheets and then setting the doctype when transforming 
     906 
     907        /* 
    903908        // Try to get the system and public ID from the current skin xsl document 
    904909        // otherwise keep the default values. 
     
    929934 
    930935        docWithDoctype = converter.newDOM(qualifiedName, publicID, systemID); 
     936        */ 
    931937 
    932938        //System.out.println("Generate final HTML from current skin") ; 
     
    975981        } 
    976982 
    977         Node finalResult = this.transformer.transform(skinAndLibraryDoc, doc, config_params, docWithDoctype); 
     983         
     984        // The transformer will now work out the resulting doctype from any set in the (merged) stylesheets and 
     985        // will set this in the output document it creates. So don't pass in any docWithDocType to the transformer 
     986        //Node finalResult = this.transformer.transform(skinAndLibraryDoc, doc, config_params, docWithDoctype); 
     987        Node finalResult = this.transformer.transform(skinAndLibraryDoc, doc, config_params); 
    978988 
    979989        if (_debug) 
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XMLTransformer.java

    r26513 r27090  
    3636import java.util.Iterator; 
    3737import java.util.Map; 
     38import java.util.Properties; 
    3839import java.util.Set; 
    3940 
    4041import javax.xml.parsers.DocumentBuilderFactory; 
    4142import javax.xml.transform.ErrorListener; 
     43import javax.xml.transform.OutputKeys; 
    4244import javax.xml.transform.Source; 
    4345import javax.xml.transform.Transformer; 
     
    225227    } 
    226228 
     229    // This method will now set the docType in the new document created and returned, if any are specified in the 
     230    // (merged) stylesheet being applied. The docDocType parameter is therefore no longer necessary nor used by default. 
    227231    protected Node transform(Document stylesheet, Document source, HashMap<String, Comparable> parameters, Document docDocType, Document resultNode) 
    228232    { 
     
    249253            // the transformation has a DocType. For that to happen, we need to create 
    250254            // the DOMResult using a Document with a predefined docType. 
    251             // If we don't have a DocType then do the transformation with a DOMResult 
    252             // that does not contain any doctype (like we use to do before). 
    253             DOMResult result = docDocType == null ? new DOMResult() : new DOMResult(docDocType); 
     255 
     256            // When the DOCType is not explicitly specified (default case), the docDocType variable is null 
     257            // In such a case, the transformer will work out the docType and output method and the rest  
     258            // from the stylesheet. Better to let the transformer work this out than GS manually aggregating  
     259            // all xsls being applied and the GS code deciding on which output method and doctype to use. 
     260 
     261            //DOMResult result = docDocType == null ? new DOMResult() : new DOMResult(docDocType); 
     262            DOMResult result = null; 
     263 
     264            Properties props = transformer.getOutputProperties(); 
     265            if(docDocType == null) { // default case 
     266             
     267                String outputMethod = props.getProperty(OutputKeys.METHOD); 
     268                if(outputMethod.equals("html")) {                
     269                String doctype_public = props.getProperty(OutputKeys.DOCTYPE_PUBLIC); 
     270                String doctype_system = props.getProperty(OutputKeys.DOCTYPE_SYSTEM); 
     271                 
     272                if(doctype_public == null) { 
     273                    doctype_public = ""; // or default to PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"? 
     274                } 
     275                if(doctype_system == null) { 
     276                    doctype_system = ""; // or default to "http://www.w3.org/TR/html4/loose.dtd"? 
     277                } 
     278 
     279                Document docDocTypeFromTransformer = XMLConverter.newDOM(outputMethod, doctype_public, doctype_system); 
     280                result = new DOMResult(docDocTypeFromTransformer); 
     281                }  
     282                // if output method=xml, the <?xml ?> processing method goes missing hereafter, although it 
     283                // still exists in OutputKeys' VERSION, ENCODING and OMIT_XML_DECLARATION props at this point 
     284                         
     285            } else { // if document with doctype was already specified (no longer the default case) 
     286                result = new DOMResult(docDocType); 
     287            } 
     288            // At this point if we haven't initialised result yet, set it to an empty DOMResult 
     289            if(result == null) { 
     290                result = new DOMResult(); 
     291            } 
     292 
     293 
    254294            if (resultNode != null) 
    255295            {