Ignore:
Timestamp:
2013-03-15T14:09:47+13:00 (11 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().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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            {
Note: See TracChangeset for help on using the changeset viewer.