zongaro     2003/10/20 12:11:09

  Modified:    java/src/org/apache/xalan/xsltc/trax Tag: xslt20-compiled
                        TransformerImpl.java
  Log:
  Patch from Christine Li ([EMAIL PROTECTED]) for Bugzilla bug report 22167.
  
  When the zero-argument constructor of DOMSource, StreamSource or SAXSource is
  invoked, and no setter method is called to specify an actual source, the
  source should be treated as if it contained only a root node.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.71.2.2  +33 -3     
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.71.2.1
  retrieving revision 1.71.2.2
  diff -u -r1.71.2.1 -r1.71.2.2
  --- TransformerImpl.java      15 Oct 2003 18:28:27 -0000      1.71.2.1
  +++ TransformerImpl.java      20 Oct 2003 19:11:09 -0000      1.71.2.2
  @@ -79,6 +79,8 @@
   import java.util.StringTokenizer;
   import java.util.Vector;
   
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
   import javax.xml.parsers.ParserConfigurationException;
   import javax.xml.transform.ErrorListener;
   import javax.xml.transform.OutputKeys;
  @@ -391,7 +393,7 @@
                if (systemId.startsWith("file:")) {
                       url = new URL(systemId);
                    _tohFactory.setOutputStream(
  -                     new FileOutputStream(url.getFile()));
  +                     new FileOutputStream(url.getFile()));
                    return _tohFactory.getSerializationHandler();
                   }
                   else if (systemId.startsWith("http:")) {
  @@ -404,7 +406,7 @@
                       // system id is just a filename
                       url = new File(systemId).toURL();
                    _tohFactory.setOutputStream(
  -                     new FileOutputStream(url.getFile()));
  +                     new FileOutputStream(url.getFile()));
                    return _tohFactory.getSerializationHandler();
                   }
            }
  @@ -665,6 +667,34 @@
        String encoding) throws TransformerException 
       {
        try {
  +            /*
  +             * According to JAXP1.2, new SAXSource()/StreamSource()
  +             * should create an empty input tree, with a default root node. 
  +             * new DOMSource()creates an empty document using 
DocumentBuilder.
  +             * newDocument(); Use DocumentBuilder.newDocument() for all 3 
  +             * situations, since there is no clear spec. how to create 
  +             * an empty tree when both SAXSource() and StreamSource() are 
used.
  +             */
  +             if ((source instanceof StreamSource && 
source.getSystemId()==null 
  +                && ((StreamSource)source).getInputStream()==null &&
  +                ((StreamSource)source).getReader()==null)||
  +                (source instanceof SAXSource &&
  +                ((SAXSource)source).getInputSource()==null &&
  +                ((SAXSource)source).getXMLReader()==null )||
  +                (source instanceof DOMSource && 
  +                ((DOMSource)source).getNode()==null)){
  +                        DocumentBuilderFactory builderF = 
  +                                DocumentBuilderFactory.newInstance();
  +                        DocumentBuilder builder = 
  +                                builderF.newDocumentBuilder();
  +                        String systemID = source.getSystemId();
  +                        source = new DOMSource(builder.newDocument());
  +
  +                        // Copy system ID from original, empty Source to new
  +                        if (systemID != null) {
  +                          source.setSystemId(systemID);
  +                        }
  +             }           
            if (_isIdentity) {
                transformIdentity(source, handler);
            }
  
  
  

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

Reply via email to