santiagopg    2002/06/17 11:37:12

  Modified:    java/src/org/apache/xalan/xsltc/compiler Output.java
                        Parser.java Stylesheet.java XSLTC.java
               java/src/org/apache/xalan/xsltc/trax
                        TemplatesHandlerImpl.java TemplatesImpl.java
                        TransformerFactoryImpl.java TransformerImpl.java
  Log:
  Fixed layering of output properties in Trax.
  
  Revision  Changes    Path
  1.14      +87 -24    
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Output.java
  
  Index: Output.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Output.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Output.java       11 Jun 2002 20:11:18 -0000      1.13
  +++ Output.java       17 Jun 2002 18:37:11 -0000      1.14
  @@ -65,9 +65,11 @@
   package org.apache.xalan.xsltc.compiler;
   
   import java.util.Vector;
  +import java.util.Properties;
   import java.util.Enumeration;
   import java.util.StringTokenizer;
   import java.io.OutputStreamWriter;
  +import javax.xml.transform.OutputKeys;
   
   import org.apache.bcel.generic.*;
   import org.apache.bcel.classfile.JavaClass;
  @@ -96,7 +98,8 @@
   
       // Some global constants
       private final static String STRING_SIG = "Ljava/lang/String;";
  -    private final static String ONE_DOT_ZERO_STRING = "1.0";
  +    private final static String XML_VERSION = "1.0";
  +    private final static String HTML_VERSION = "4.0";
   
       /**
        * Displays the contents of this element (for debugging)
  @@ -123,6 +126,7 @@
        * Scans the attribute list for the xsl:output instruction
        */
       public void parseContents(Parser parser) {
  +     final Properties outputProperties = new Properties();
   
        // Ask the parser if it wants this <xsl:output> element
        parser.setOutput(this);
  @@ -132,25 +136,30 @@
   
        String attrib = null;
   
  -     // Get the output XML version - only version "1.0" should be used
  +     // Get the output version
        _version = getAttribute("version");
  -     if ((_version == null) || (_version.equals(Constants.EMPTYSTRING))) {
  -         _version = ONE_DOT_ZERO_STRING;
  +     if (_version == null || _version.equals(Constants.EMPTYSTRING)) {
  +         _version = null;
        }
  -     if (!_version.equals(ONE_DOT_ZERO_STRING)) {
  -         ErrorMsg msg = new ErrorMsg(ErrorMsg.OUTPUT_VERSION_ERR, this);
  -         parser.reportError(Constants.WARNING, msg);
  +     else {
  +         outputProperties.setProperty(OutputKeys.VERSION, _version);
        }
   
        // Get the output method - "xml", "html", "text" or <qname>
        _method = getAttribute("method");
  -     if (_method.equals(Constants.EMPTYSTRING)) _method = null;
  -     if (_method != null) _method = _method.toLowerCase();
  +     if (_method.equals(Constants.EMPTYSTRING)) {
  +         _method = null;
  +     }
  +     if (_method != null) {
  +         _method = _method.toLowerCase();
  +         outputProperties.setProperty(OutputKeys.METHOD, _method);
  +     }
   
        // Get the output encoding - any value accepted here
        _encoding = getAttribute("encoding");
  -     if (_encoding.equals(Constants.EMPTYSTRING))
  +     if (_encoding.equals(Constants.EMPTYSTRING)) {
            _encoding = null;
  +     }
        else {
            try {
                OutputStreamWriter writer =
  @@ -161,42 +170,96 @@
                                            _encoding, this);
                parser.reportError(Constants.WARNING, msg);
            }
  +         outputProperties.setProperty(OutputKeys.ENCODING, _encoding);
        }
   
        // Should the XML header be omitted - translate to true/false
        attrib = getAttribute("omit-xml-declaration");
  -     if ((attrib != null) && (attrib.equals("yes"))) _omitHeader = true;
  +     if (attrib != null && !attrib.equals(Constants.EMPTYSTRING)) {
  +         if (attrib.equals("yes")) {
  +             _omitHeader = true;
  +         }
  +         outputProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, 
attrib);
  +     }
   
        // Add 'standalone' decaration to output - use text as is
        _standalone = getAttribute("standalone");
  -     if (_standalone.equals(Constants.EMPTYSTRING)) _standalone = null;
  +     if (_standalone.equals(Constants.EMPTYSTRING)) {
  +         _standalone = null;
  +     }
  +     else {
  +         outputProperties.setProperty(OutputKeys.STANDALONE, _standalone);
  +     }
   
        // Get system/public identifiers for output DOCTYPE declaration
        _doctypeSystem = getAttribute("doctype-system");
  -     if (_doctypeSystem.equals(Constants.EMPTYSTRING)) _doctypeSystem = null;
  +     if (_doctypeSystem.equals(Constants.EMPTYSTRING)) {
  +         _doctypeSystem = null;
  +     }
  +     else {
  +         outputProperties.setProperty(OutputKeys.DOCTYPE_SYSTEM, 
_doctypeSystem);
  +     }
  +
  +
        _doctypePublic = getAttribute("doctype-public");
  -     if (_doctypePublic.equals(Constants.EMPTYSTRING)) _doctypePublic = null;
  +     if (_doctypePublic.equals(Constants.EMPTYSTRING)) {
  +         _doctypePublic = null;
  +     }
  +     else {
  +         outputProperties.setProperty(OutputKeys.DOCTYPE_PUBLIC, 
_doctypePublic);
  +     }
   
        // Names the elements of whose text contents should be output as CDATA
        _cdata = getAttribute("cdata-section-elements");
  -     if ((_cdata != null) && (_cdata.equals(Constants.EMPTYSTRING)))
  +     if (_cdata != null && _cdata.equals(Constants.EMPTYSTRING)) {
            _cdata = null;
  +     }
  +     else {
  +         outputProperties.setProperty(OutputKeys.CDATA_SECTION_ELEMENTS, 
_cdata);
  +     }
   
        // Get the indent setting - only has effect for xml and html output
        attrib = getAttribute("indent");
  -     if ((attrib != null) && (!attrib.equals(EMPTYSTRING))) {
  -         if (attrib.equals("yes")) _indent = true;
  +     if (attrib != null && !attrib.equals(EMPTYSTRING)) {
  +         if (attrib.equals("yes")) {
  +             _indent = true;
  +         }
  +         outputProperties.setProperty(OutputKeys.INDENT, attrib);
        }
  -     else if ((_method != null) && (_method.equals("html"))) {
  +
  +     else if (_method != null && _method.equals("html")) {
            _indent = true;
        }
   
  -     // Get the MIME type for the output file - we don't do anythign with it,
  -     // but our client may use it to specify a data transport type, etc.
  +     // Get the MIME type for the output file
        _mediaType = getAttribute("media-type");
  -     if (_mediaType.equals(Constants.EMPTYSTRING)) _mediaType = null;
  +     if (_mediaType.equals(Constants.EMPTYSTRING)) {
  +         _mediaType = null;
  +     }
  +     else {
  +         outputProperties.setProperty(OutputKeys.MEDIA_TYPE, _mediaType);
  +     }
  +
  +     // Implied properties
  +     if (_method != null) {
  +         if (_method.equals("html")) {
  +             if (_version == null) {
  +                 _version = HTML_VERSION;
  +             }
  +             if (_mediaType == null) {
  +                 _mediaType = "text/html";
  +             }
  +             _indent = true;
  +         }
  +         else if (_method.equals("text")) {
  +             if (_mediaType == null) {
  +                 _mediaType = "text/plain";
  +             }
  +         }
  +     }
   
  -     // parseChildren(parser); - the element is always empty
  +     // Set output properties in current stylesheet
  +     parser.getCurrentStylesheet().setOutputProperties(outputProperties);
       }
   
       /**
  @@ -215,7 +278,7 @@
           il.append(classGen.loadTranslet());
   
        // Only update _version field if set and different from default
  -     if ((_version != null) && (!_version.equals(ONE_DOT_ZERO_STRING))) {
  +     if ((_version != null) && (!_version.equals(XML_VERSION))) {
            field = cpg.addFieldref(TRANSLET_CLASS, "_version", STRING_SIG);
            il.append(DUP);
            il.append(new PUSH(cpg, _version));
  
  
  
  1.45      +6 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- Parser.java       30 May 2002 17:47:40 -0000      1.44
  +++ Parser.java       17 Jun 2002 18:37:11 -0000      1.45
  @@ -70,6 +70,7 @@
   import java.net.URL;
   import java.util.Vector;
   import java.util.Hashtable;
  +import java.util.Properties;
   import java.util.Dictionary;
   import java.util.Enumeration;
   import java.util.StringTokenizer;
  @@ -164,6 +165,10 @@
   
       public Output getOutput() {
        return _output;
  +    }
  +
  +    public Properties getOutputProperties() {
  +     return getTopLevelStylesheet().getOutputProperties();
       }
   
       public void addVariable(Variable var) {
  
  
  
  1.42      +19 -1     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java
  
  Index: Stylesheet.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- Stylesheet.java   8 May 2002 13:28:49 -0000       1.41
  +++ Stylesheet.java   17 Jun 2002 18:37:11 -0000      1.42
  @@ -66,6 +66,7 @@
   
   import java.util.Vector;
   import java.util.Hashtable;
  +import java.util.Properties;
   import java.util.Enumeration;
   import java.util.StringTokenizer;
   import java.util.Iterator;
  @@ -132,6 +133,8 @@
   
       private boolean _forwardReference = false;
   
  +    private Properties _outputProperties = null;
  +
       public void setForwardReference() {
        _forwardReference = true;
       }
  @@ -152,6 +155,21 @@
        _simplified = true;
       }
       
  +    public void setOutputProperty(String key, String value) {
  +     if (_outputProperties == null) {
  +         _outputProperties = new Properties();
  +     }
  +     _outputProperties.setProperty(key, value);
  +    }
  +
  +    public void setOutputProperties(Properties props) {
  +     _outputProperties = props;
  +    }
  +
  +    public Properties getOutputProperties() {
  +     return _outputProperties;
  +    }
  +
       public void setMultiDocument(boolean flag) {     
        _multiDocument = flag;
       }
  
  
  
  1.39      +10 -2     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java
  
  Index: XSLTC.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- XSLTC.java        3 May 2002 14:20:25 -0000       1.38
  +++ XSLTC.java        17 Jun 2002 18:37:11 -0000      1.39
  @@ -67,9 +67,10 @@
   package org.apache.xalan.xsltc.compiler;
   
   import java.io.*;
  +import java.util.Set;
   import java.util.Vector;
   import java.util.Hashtable;
  -import java.util.Set;
  +import java.util.Properties;
   import java.util.HashSet;
   import java.util.Iterator;
   import java.util.Enumeration;
  @@ -162,6 +163,13 @@
        */
       public void setOutputType(int type) {
        _outputType = type;
  +    }
  +
  +    /**
  +     * Only for user by the internal TrAX implementation.
  +     */
  +    public Properties getOutputProperties() {
  +     return _parser.getOutputProperties();
       }
   
       /**
  
  
  
  1.11      +2 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java
  
  Index: TemplatesHandlerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TemplatesHandlerImpl.java 11 Jun 2002 20:11:18 -0000      1.10
  +++ TemplatesHandlerImpl.java 17 Jun 2002 18:37:11 -0000      1.11
  @@ -170,7 +170,7 @@
                final byte[][] bytecodes = xsltc.getBytecodes();
                if (bytecodes != null) {
                    return new TemplatesImpl(xsltc.getBytecodes(), 
transletName, 
  -                                          _oldOutputSystem);
  +                      getOutputProperties(), _oldOutputSystem);
                }
            }
        }
  
  
  
  1.14      +7 -3      
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java
  
  Index: TemplatesImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TemplatesImpl.java        11 Jun 2002 20:11:18 -0000      1.13
  +++ TemplatesImpl.java        17 Jun 2002 18:37:11 -0000      1.14
  @@ -97,6 +97,8 @@
       // and _bytecodes arrays (above).
       private int _transletIndex = -1;
       
  +    private Properties _outputProperties; 
  +
       // Temporary
       private boolean _oldOutputSystem;
   
  @@ -131,10 +133,11 @@
        * the main translet class, must be supplied
        */
       protected TemplatesImpl(byte[][] bytecodes, String transletName,
  -     boolean oldOutputSystem) 
  +     Properties outputProperties, boolean oldOutputSystem) 
       {
        _bytecodes = bytecodes;
        _name      = transletName;
  +     _outputProperties = outputProperties;
        _oldOutputSystem = oldOutputSystem;
       }
   
  @@ -262,7 +265,8 @@
        */
       public Transformer newTransformer()
        throws TransformerConfigurationException {
  -        return new TransformerImpl(getTransletInstance(), _oldOutputSystem);
  +        return new TransformerImpl(getTransletInstance(), _outputProperties,
  +         _oldOutputSystem);
       }
   
       /**
  
  
  
  1.40      +8 -5      
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java
  
  Index: TransformerFactoryImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- TransformerFactoryImpl.java       11 Jun 2002 20:11:18 -0000      1.39
  +++ TransformerFactoryImpl.java       17 Jun 2002 18:37:11 -0000      1.40
  @@ -346,10 +346,12 @@
   
        // Create a Transformer object and store for other calls
        Templates templates = new TemplatesImpl(bytecodes, _defaultTransletName,
  -                                             _oldOutputSystem);
  +         xsltc.getOutputProperties(), _oldOutputSystem);
        _copyTransformer = templates.newTransformer();
  -     if (_uriResolver != null) _copyTransformer.setURIResolver(_uriResolver);
  -     return(_copyTransformer);
  +     if (_uriResolver != null) {
  +         _copyTransformer.setURIResolver(_uriResolver);
  +     }
  +     return _copyTransformer;
       }
   
       /**
  @@ -527,7 +529,8 @@
            ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
            throw new TransformerConfigurationException(err.toString());
        }
  -     return new TemplatesImpl(bytecodes, transletName, _oldOutputSystem);
  +     return new TemplatesImpl(bytecodes, transletName, 
  +         xsltc.getOutputProperties(), _oldOutputSystem);
       }
   
       /**
  
  
  
  1.46      +117 -122  
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java
  
  Index: TransformerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- TransformerImpl.java      11 Jun 2002 20:11:18 -0000      1.45
  +++ TransformerImpl.java      17 Jun 2002 18:37:11 -0000      1.46
  @@ -120,7 +120,7 @@
   
       private ErrorListener _errorListener = this;
       private URIResolver   _uriResolver = null;
  -    private Properties    _properties = null;
  +    private Properties    _properties, _propertiesClone;
   
       // Used for default output property settings
       private final static String EMPTY_STRING = "";
  @@ -147,17 +147,20 @@
        * Implements JAXP's Transformer constructor
        * Our Transformer objects always need a translet to do the actual work
        */
  -    protected TransformerImpl(Translet translet, boolean oldOutputSystem) {
  -     _translet = (AbstractTranslet)translet;
  -     _properties = createOutputProperties();
  +    protected TransformerImpl(Translet translet, Properties outputProperties,
  +     boolean oldOutputSystem) 
  +    {
  +     _translet = (AbstractTranslet) translet;
  +     _properties = createOutputProperties(outputProperties);
        _oldOutputSystem = oldOutputSystem;
  +     _propertiesClone = (Properties) _properties.clone();
       }
   
       /**
        * Returns the translet wrapped inside this Transformer
        */
       protected AbstractTranslet getTranslet() {
  -     return(_translet);
  +     return _translet;
       }
   
       /**
  @@ -168,8 +171,8 @@
        * @throws TransformerException
        */
       public void transform(Source source, Result result)
  -     throws TransformerException {
  -
  +     throws TransformerException 
  +    {
        if (_translet == null) {
            ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_TRANSLET_ERR);
            throw new TransformerException(err.toString());
  @@ -227,12 +230,8 @@
        throws TransformerException 
       {
        // Try to get the encoding from the translet (may not be set)
  -     if (_translet._encoding != null) {
  -            _encoding = _translet._encoding;
  -        }
  -        else {
  -            _encoding = "UTF-8"; // default output encoding
  -        }
  +     _encoding = (_translet._encoding != null) ? _translet._encoding 
  +         : "UTF-8";
   
        _tohFactory = TransletOutputHandlerFactory.newInstance();
        _tohFactory.setEncoding(
  @@ -758,7 +757,7 @@
        * @return Properties in effect for this Transformer
        */
       public Properties getOutputProperties() {
  -     return(_properties);
  +     return (Properties) _properties.clone();
       }
   
       /**
  @@ -771,12 +770,13 @@
        * @throws IllegalArgumentException if the property name is not known
        */
       public String getOutputProperty(String name)
  -     throws IllegalArgumentException {
  +     throws IllegalArgumentException 
  +    {
        if (!validOutputProperty(name)) {
            ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_PROP_ERR, name);
            throw new IllegalArgumentException(err.toString());
        }
  -     return(_properties.getProperty(name));
  +     return _properties.getProperty(name);
       }
   
       /**
  @@ -791,11 +791,22 @@
       public void setOutputProperties(Properties properties)
        throws IllegalArgumentException 
       {
  -     // Notice that _properties.putAll() will not copy default props
  -     final Enumeration propertyNames = properties.propertyNames();
  -     while (propertyNames.hasMoreElements()) {
  -         final String prop = (String) propertyNames.nextElement();
  -         _properties.setProperty(prop, (String) 
properties.getProperty(prop));
  +     if (properties != null) {
  +         final Enumeration names = properties.propertyNames();
  +
  +         while (names.hasMoreElements()) {
  +             final String name = (String) names.nextElement();
  +             if (validOutputProperty(name)) {
  +                 _properties.setProperty(name, properties.getProperty(name));
  +             }
  +             else {
  +                 ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_PROP_ERR, 
name);
  +                 throw new IllegalArgumentException(err.toString());
  +             }
  +         }
  +     }
  +     else {
  +         _properties = _propertiesClone;
        }
       }
   
  @@ -810,7 +821,8 @@
        * @throws IllegalArgumentException Never, errors are ignored
        */
       public void setOutputProperty(String name, String value)
  -     throws IllegalArgumentException {
  +     throws IllegalArgumentException 
  +    {
        if (!validOutputProperty(name)) {
            ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_PROP_ERR, name);
            throw new IllegalArgumentException(err.toString());
  @@ -823,44 +835,46 @@
        * initiating the transformation
        */
       private void setOutputProperties(AbstractTranslet translet,
  -                                  Properties properties) {
  +                                  Properties properties) 
  +    {
        // Return right now if no properties are set
        if (properties == null) return;
   
        // Get a list of all the defined properties
        Enumeration names = properties.propertyNames();
        while (names.hasMoreElements()) {
  -         // Get the next property name and value
  -         String name  = (String)names.nextElement();
  -         // bug fix # 6636- contributed by Tim Elcott
  -         String value = (String)properties.getProperty(name);
  +         String name  = (String) names.nextElement();
  +         String value = (String) properties.getProperty(name);
   
            // Pass property value to translet - override previous setting
  -         if (name.equals(OutputKeys.ENCODING))
  +         if (name.equals(OutputKeys.ENCODING)) {
                translet._encoding = value;
  -         else if (name.equals(OutputKeys.METHOD))
  +         }
  +         else if (name.equals(OutputKeys.METHOD)) {
                translet._method = value;
  -         else if (name.equals(OutputKeys.DOCTYPE_PUBLIC))
  +         }
  +         else if (name.equals(OutputKeys.DOCTYPE_PUBLIC)) {
                translet._doctypePublic = value;
  -         else if (name.equals(OutputKeys.DOCTYPE_SYSTEM))
  +         }
  +         else if (name.equals(OutputKeys.DOCTYPE_SYSTEM)) {
                translet._doctypeSystem = value;
  -         else if (name.equals(OutputKeys.MEDIA_TYPE))
  +         }
  +         else if (name.equals(OutputKeys.MEDIA_TYPE)) {
                translet._mediaType = value;
  -         else if (name.equals(OutputKeys.STANDALONE))
  +         }
  +         else if (name.equals(OutputKeys.STANDALONE)) {
                translet._standalone = value;
  -         else if (name.equals(OutputKeys.VERSION))
  +         }
  +         else if (name.equals(OutputKeys.VERSION)) {
                translet._version = value;
  +         }
            else if (name.equals(OutputKeys.OMIT_XML_DECLARATION)) {
  -             if ((value != null) && (value.toLowerCase().equals("yes")))
  -                 translet._omitHeader = true;
  -             else
  -                 translet._omitHeader = false;
  +             translet._omitHeader = 
  +                 (value != null && value.toLowerCase().equals("yes"));
            }
            else if (name.equals(OutputKeys.INDENT)) {
  -             if ((value != null) && (value.toLowerCase().equals("yes")))
  -                 translet._indent = true;
  -             else
  -                 translet._indent = false;
  +             translet._indent = 
  +                 (value != null && value.toLowerCase().equals("yes"));
            }
            else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
                if (value != null) {
  @@ -875,68 +889,45 @@
       }
   
       /**
  -     * Internal method to pass any properties to the translet prior to
  -     * initiating the transformation
  -     */
  -    private Properties createOutputProperties() {
  -     
  -     // Level3: Return the default property value
  -     // bug # 6751 fixed by removing setProperty lines for 
  -     //  OutputKeys.(DOCTYPE_PUBLIC|DOCTYPE_SYSTEM|CDATA_SECTION_ELEMENTS)
  -     //  instead of setting them to "" (EMPTY_STRING). Fix contributed
  -     //  by Derek Sayeau.   
  -     Properties third = new Properties();
  -     third.setProperty(OutputKeys.ENCODING, "UTF-8");
  -     third.setProperty(OutputKeys.METHOD, XML_STRING);
  -     third.setProperty(OutputKeys.INDENT, NO_STRING);
  -     third.setProperty(OutputKeys.MEDIA_TYPE, "text/xml");
  -     third.setProperty(OutputKeys.OMIT_XML_DECLARATION, NO_STRING);
  -     third.setProperty(OutputKeys.VERSION, "1.0");
  -
  -     // Level2: Return the property value is set in the translet
  -     // Creating these properties with the third-level properties as default
  -     Properties second = new Properties(third);
  -     if (_translet != null) {
  -         String value = _translet._encoding;
  -         if (value != null) second.setProperty(OutputKeys.ENCODING, value);
  -
  -         value = _translet._method;
  -         if (value != null) second.setProperty(OutputKeys.METHOD, value);
  -
  -         if (_translet._indent)
  -             second.setProperty(OutputKeys.INDENT, "yes");
  -         else
  -             second.setProperty(OutputKeys.INDENT, "no");
  -
  -         value = _translet._doctypePublic;
  -         if (value != null) 
  -             second.setProperty(OutputKeys.DOCTYPE_PUBLIC, value);
  -
  -         value = _translet._doctypeSystem;
  -         if (value != null) 
  -             second.setProperty(OutputKeys.DOCTYPE_SYSTEM, value);
  -
  -         value = makeCDATAString(_translet._cdata);
  -         if (value != null) 
  -             second.setProperty(OutputKeys.CDATA_SECTION_ELEMENTS,value);
  -
  -         value = _translet._mediaType;
  -         if (value != null) second.setProperty(OutputKeys.MEDIA_TYPE, value);
  -
  -         if (_translet._omitHeader)
  -             second.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
  -         else
  -             second.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
  -
  -         value = _translet._standalone;
  -         if (value != null) second.setProperty(OutputKeys.STANDALONE, value);
  +     * Internal method to create the initial set of properties. There
  +     * are two layers of properties: the default layer and the base layer.
  +     * The latter contains properties defined in the stylesheet or by
  +     * the user using this API.
  +     */
  +    private Properties createOutputProperties(Properties outputProperties) {
  +     final Properties defaults = new Properties();
  +     defaults.setProperty(OutputKeys.ENCODING, "UTF-8");
  +     defaults.setProperty(OutputKeys.METHOD, XML_STRING);
  +     defaults.setProperty(OutputKeys.INDENT, NO_STRING);
  +     defaults.setProperty(OutputKeys.MEDIA_TYPE, "text/xml");
  +     defaults.setProperty(OutputKeys.OMIT_XML_DECLARATION, NO_STRING);
  +     defaults.setProperty(OutputKeys.STANDALONE, NO_STRING);
  +     defaults.setProperty(OutputKeys.VERSION, "1.0");
  +
  +     // Copy propeties set in stylesheet to base
  +     final Properties base = new Properties(defaults);
  +     if (outputProperties != null) {
  +         final Enumeration names = outputProperties.propertyNames();
  +         while (names.hasMoreElements()) {
  +             final String name = (String) names.nextElement();
  +             base.setProperty(name, outputProperties.getProperty(name));
  +         }
  +     }
   
  -         value = _translet._version;
  -         if (value != null) second.setProperty(OutputKeys.VERSION, value);
  +     // Update defaults based on output method
  +     final String method = base.getProperty(OutputKeys.METHOD);
  +     if (method != null) {
  +         if (method.equals("html")) {
  +             defaults.setProperty(OutputKeys.INDENT, "yes");
  +             defaults.setProperty(OutputKeys.VERSION, "4.0");
  +             defaults.setProperty(OutputKeys.MEDIA_TYPE, "text/html");
  +         }
  +         else if (method.equals("text")) {
  +             defaults.setProperty(OutputKeys.MEDIA_TYPE, "text/plain");
  +         }
        }
   
  -     // Creating the properties with the second-level properties as default
  -     return(new Properties(second));
  +     return base; 
       }
   
       /**
  @@ -944,18 +935,17 @@
        * the JAXP 1.1 / TrAX spec
        */
       private boolean validOutputProperty(String name) {
  -     if (name.equals(OutputKeys.ENCODING)) return true;
  -     if (name.equals(OutputKeys.METHOD)) return true;
  -     if (name.equals(OutputKeys.INDENT)) return true;
  -     if (name.equals(OutputKeys.DOCTYPE_PUBLIC)) return true;
  -     if (name.equals(OutputKeys.DOCTYPE_SYSTEM)) return true;
  -     if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) return true;
  -     if (name.equals(OutputKeys.MEDIA_TYPE)) return true;
  -     if (name.equals(OutputKeys.OMIT_XML_DECLARATION)) return true;
  -     if (name.equals(OutputKeys.STANDALONE)) return true;
  -     if (name.equals(OutputKeys.VERSION)) return true;
  -     if (name.charAt(0) == '{') return true;
  -     return false;
  +     return (name.equals(OutputKeys.ENCODING) ||
  +             name.equals(OutputKeys.METHOD) ||
  +             name.equals(OutputKeys.INDENT) ||
  +             name.equals(OutputKeys.DOCTYPE_PUBLIC) ||
  +             name.equals(OutputKeys.DOCTYPE_SYSTEM) ||
  +             name.equals(OutputKeys.CDATA_SECTION_ELEMENTS) ||
  +             name.equals(OutputKeys.MEDIA_TYPE) ||
  +             name.equals(OutputKeys.OMIT_XML_DECLARATION)   ||
  +             name.equals(OutputKeys.STANDALONE) ||
  +             name.equals(OutputKeys.VERSION) ||
  +             name.charAt(0) == '{');
       }
   
       /**
  @@ -1049,8 +1039,9 @@
        * the transformation (always does in our case).
        */
       public void error(TransformerException e)
  -     throws TransformerException {
  -     System.err.println("ERROR: "+e.getMessageAndLocation());
  +     throws TransformerException 
  +    {
  +     System.err.println("ERROR: " + e.getMessageAndLocation());
        throw(e);       
       }
   
  @@ -1068,11 +1059,13 @@
        * the transformation (always does in our case).
        */
       public void fatalError(TransformerException e)
  -     throws TransformerException {
  -     System.err.println("FATAL: "+e.getMessageAndLocation());
  +     throws TransformerException 
  +    {
  +     System.err.println("FATAL: " + e.getMessageAndLocation());
        Throwable wrapped = e.getException();
  -     if (wrapped != null)
  +     if (wrapped != null) {
            System.err.println("     : "+wrapped.getMessage());
  +     }
        throw(e);
       }
   
  @@ -1090,11 +1083,13 @@
        * the transformation (never does in our case).
        */
       public void warning(TransformerException e)
  -     throws TransformerException {
  -     System.err.println("WARNING: "+e.getMessageAndLocation());
  +     throws TransformerException 
  +    {
  +     System.err.println("WARNING: " + e.getMessageAndLocation());
        Throwable wrapped = e.getException();
  -     if (wrapped != null)
  +     if (wrapped != null) {
            System.err.println("       : "+wrapped.getMessage());
  +     }
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to