zongaro     2003/10/20 11:46:07

  Modified:    java/src/org/apache/xalan/transformer
                        TransformerIdentityImpl.java TransformerImpl.java
               java/src/org/apache/xalan/xsltc/trax 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
  1.26      +32 -1     
xml-xalan/java/src/org/apache/xalan/transformer/TransformerIdentityImpl.java
  
  Index: TransformerIdentityImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerIdentityImpl.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- TransformerIdentityImpl.java      16 Oct 2003 20:17:52 -0000      1.25
  +++ TransformerIdentityImpl.java      20 Oct 2003 18:46:07 -0000      1.26
  @@ -75,6 +75,7 @@
   import javax.xml.transform.sax.SAXResult;
   import javax.xml.transform.sax.SAXSource;
   import javax.xml.transform.sax.TransformerHandler;
  +import javax.xml.transform.stream.StreamSource;
   import javax.xml.transform.stream.StreamResult;
   import org.apache.xml.serializer.Serializer;
   import org.apache.xml.serializer.SerializerFactory;
  @@ -312,7 +313,37 @@
     {
   
       createResultContentHandler(outputTarget);
  -
  +    
  +    /*
  +     * 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)){
  +      try {
  +        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 Source
  +        if (systemID != null) {
  +          source.setSystemId(systemID);
  +        }
  +      } catch (ParserConfigurationException e){
  +        throw new TransformerException(e.getMessage());
  +      }           
  +    }
  +    
       try
       {
         if (source instanceof DOMSource)
  
  
  
  1.152     +35 -0     
xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
  
  Index: TransformerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
  retrieving revision 1.151
  retrieving revision 1.152
  diff -u -r1.151 -r1.152
  --- TransformerImpl.java      17 Oct 2003 20:59:22 -0000      1.151
  +++ TransformerImpl.java      20 Oct 2003 18:46:07 -0000      1.152
  @@ -65,6 +65,8 @@
   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;
   import javax.xml.transform.Result;
  @@ -74,8 +76,11 @@
   import javax.xml.transform.TransformerException;
   import javax.xml.transform.URIResolver;
   import javax.xml.transform.dom.DOMResult;
  +import javax.xml.transform.dom.DOMSource;
   import javax.xml.transform.sax.SAXResult;
  +import javax.xml.transform.sax.SAXSource;
   import javax.xml.transform.stream.StreamResult;
  +import javax.xml.transform.stream.StreamSource;
   
   import org.apache.xalan.extensions.ExtensionsTable;
   import org.apache.xalan.res.XSLMessages;
  @@ -656,6 +661,36 @@
         }
         setBaseURLOfSource(base);
         DTMManager mgr = m_xcontext.getDTMManager();
  +      /*
  +       * 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)){
  +        try {
  +          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 Source
  +          if (systemID != null) {
  +            source.setSystemId(systemID);
  +          }
  +        } catch (ParserConfigurationException e) {
  +          fatalError(e);
  +        }           
  +      }
         DTM dtm = mgr.getDTM(source, false, this, true, true);
         dtm.setDocumentBaseURI(base);
         
  
  
  
  1.73      +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.72
  retrieving revision 1.73
  diff -u -r1.72 -r1.73
  --- TransformerImpl.java      15 Oct 2003 18:25:11 -0000      1.72
  +++ TransformerImpl.java      20 Oct 2003 18:46:07 -0000      1.73
  @@ -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