mkwan       2003/06/24 08:46:14

  Modified:    java/src/org/apache/xalan/xsltc/trax TransformerImpl.java
                        XSLTCSource.java
  Log:
  Fix for XSLTCSource (see bugzilla 21048).
  
  Revision  Changes    Path
  1.69      +26 -10    
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.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- TransformerImpl.java      17 Jun 2003 19:29:43 -0000      1.68
  +++ TransformerImpl.java      24 Jun 2003 15:46:14 -0000      1.69
  @@ -185,6 +185,12 @@
       private TransformerFactoryImpl _tfactory = null;
       
       /**
  +     * A reference to the XSLTCDTMManager which is used to build the DOM/DTM
  +     * for this transformer.
  +     */
  +    private XSLTCDTMManager _dtmManager = null;
  +    
  +    /**
        * A flag indicating whether we use incremental building of the DTM.
        */
       //private boolean _isIncremental = false;
  @@ -442,7 +448,7 @@
                                                         : false;
            // Get systemId from source
            if (source != null) {
  -                _sourceSystemId = source.getSystemId();
  +                _sourceSystemId = source.getSystemId();
            }
   
            if (source instanceof SAXSource) {
  @@ -459,10 +465,12 @@
   
                // Create a new internal DOM and set up its builder to trap
                // all content/lexical events
  -             XSLTCDTMManager dtmManager = XSLTCDTMManager.newInstance();
  +             if (_dtmManager == null) {
  +                 _dtmManager = XSLTCDTMManager.newInstance();
  +             }
   
                   //dtmManager.setIncremental(_isIncremental);
  -             saxImpl = (SAXImpl)dtmManager.getDTM(sax, false, wsfilter, 
true, false,
  +             saxImpl = (SAXImpl)_dtmManager.getDTM(sax, false, wsfilter, 
true, false,
                                                    hasUserReader, 0, 
hasIdCall);
                //final DOMBuilder builder = ((SAXImpl)dom).getBuilder();
                try {
  @@ -477,10 +485,12 @@
            }
            else if (source instanceof DOMSource) {
                // Create a new internal DTM and build it directly from DOM
  -             XSLTCDTMManager dtmManager = XSLTCDTMManager.newInstance();
  +             if (_dtmManager == null) {
  +                 _dtmManager = XSLTCDTMManager.newInstance();
  +             }
       
                   //dtmManager.setIncremental(_isIncremental);
  -             saxImpl = (SAXImpl)dtmManager.getDTM(source, false, wsfilter, 
true,
  +             saxImpl = (SAXImpl)_dtmManager.getDTM(source, false, wsfilter, 
true,
                                                    false, hasIdCall);
                saxImpl.setDocumentURI(_sourceSystemId);
            }
  @@ -494,7 +504,9 @@
   
                // Create a new internal DOM and set up its builder to trap
                // all content/lexical events
  -             XSLTCDTMManager dtmManager = XSLTCDTMManager.newInstance();
  +             if (_dtmManager == null) {
  +                 _dtmManager = XSLTCDTMManager.newInstance();
  +             }
   
                //dtmManager.setIncremental(_isIncremental);
                
  @@ -513,14 +525,18 @@
                    ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_SOURCE_ERR);
                    throw new TransformerException(err.toString());
                }
  -             saxImpl = (SAXImpl)dtmManager.getDTM(new SAXSource(reader, 
input),
  +             saxImpl = (SAXImpl)_dtmManager.getDTM(new SAXSource(reader, 
input),
                                                    false, wsfilter, true,
                                                    false, hasIdCall);
                saxImpl.setDocumentURI(_sourceSystemId);
            }
            else if (source instanceof XSLTCSource) {
                final XSLTCSource xsltcsrc = (XSLTCSource)source;
  -             dom = xsltcsrc.getDOM();
  +             if (_dtmManager == null) {
  +                 _dtmManager = XSLTCDTMManager.newInstance();
  +             }
  +             
  +             dom = xsltcsrc.getDOM(_dtmManager, _translet);
            }
            // DOM already set via a call to setDOM()
            else if (_dom != null) {
  @@ -632,7 +648,7 @@
            new DOM2TO(domsrc.getNode(), handler).parse();
        }
        else if (source instanceof XSLTCSource) {
  -         final DOM dom = ((XSLTCSource) source).getDOM();
  +         final DOM dom = ((XSLTCSource) source).getDOM(null, _translet);
            ((SAXImpl)dom).copy(handler);
        }
        else {
  
  
  
  1.8       +65 -129   
xml-xalan/java/src/org/apache/xalan/xsltc/trax/XSLTCSource.java
  
  Index: XSLTCSource.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/XSLTCSource.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XSLTCSource.java  23 Jun 2003 15:23:40 -0000      1.7
  +++ XSLTCSource.java  24 Jun 2003 15:46:14 -0000      1.8
  @@ -63,62 +63,39 @@
   
   package org.apache.xalan.xsltc.trax;
   
  -import java.io.File;
  -import java.io.IOException;
  -
  -import javax.xml.parsers.ParserConfigurationException;
  -import javax.xml.parsers.SAXParser;
  -import javax.xml.parsers.SAXParserFactory;
   import javax.xml.transform.Source;
  +import javax.xml.transform.stream.StreamSource;
   
   import org.apache.xalan.xsltc.DOM;
  +import org.apache.xalan.xsltc.StripFilter;
   import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
  -import org.apache.xalan.xsltc.dom.DOMBuilder;
  +import org.apache.xalan.xsltc.dom.DOMWSFilter;
   import org.apache.xalan.xsltc.dom.SAXImpl;
   import org.apache.xalan.xsltc.dom.XSLTCDTMManager;
  -import org.apache.xml.dtm.DTM;
  -import org.apache.xml.dtm.DTMManager;
  +import org.apache.xalan.xsltc.runtime.AbstractTranslet;
   
  -import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
  -import org.xml.sax.XMLReader;
   
   public final class XSLTCSource implements Source {
   
       private String     _systemId = null;
  -    private DOM        _dom      = null;
  -
  -    private final static String LEXICAL_HANDLER_PROPERTY =
  -     "http://xml.org/sax/properties/lexical-handler";;
  +    private Source     _source   = null;
  +    private ThreadLocal _dom     = new ThreadLocal();
   
       /**
  -     * Create a new XSLTC-specific DOM source
  -     * @param size The estimated node-count for this DOM. A good guess here
  -     * speeds up the DOM build process.
  +     * Create a new XSLTC-specific source from a system ID 
        */
  -    public XSLTCSource(int size) 
  +    public XSLTCSource(String systemId) 
       {
  -      XSLTCDTMManager dtmManager =
  -                XSLTCDTMManager.newInstance();
  -      int dtmPos = dtmManager.getFirstFreeDTMID();
  -      int documentID = dtmPos << DTMManager.IDENT_DTM_NODE_BITS;
  -      _dom = new SAXImpl(dtmManager, this, documentID, null,
  -                              null, false, size, true, false);
  -      dtmManager.addDTM((DTM)_dom, dtmPos);
  +        _systemId = systemId;
       }
   
       /**
  -     * Create a new XSLTC-specific DOM source
  +     * Create a new XSLTC-specific source from a JAXP Source
        */
  -    public XSLTCSource() 
  +    public XSLTCSource(Source source) 
       {
  -      XSLTCDTMManager dtmManager =
  -                XSLTCDTMManager.newInstance();
  -      int dtmPos = dtmManager.getFirstFreeDTMID();
  -      int documentID = dtmPos << DTMManager.IDENT_DTM_NODE_BITS;
  -      _dom = (DOM)new SAXImpl(dtmManager, this, documentID, null,
  -                              null, false, true);
  -      dtmManager.addDTM((DTM)_dom, dtmPos);
  +        _source = source;
       }
   
       /**
  @@ -130,12 +107,10 @@
        * @param systemId The system Id for this Source
        */
       public void setSystemId(String systemId) {
  -     if ((new File(systemId)).exists())
  -         _systemId = "file:"+systemId;
  -     else
  -         _systemId = systemId;
  -
  -        ((SAXImpl)_dom).setDocumentURI(_systemId);
  +        _systemId = systemId;
  +        if (_source != null) {
  +            _source.setSystemId(systemId);
  +        }
       }
   
       /**
  @@ -145,98 +120,59 @@
        *         or null if setSystemId was not called.
        */
       public String getSystemId() {
  -     return(_systemId);
  -    }
  -
  -    /**
  -     * Build the internal XSLTC-specific DOM.
  -     * @param reader An XMLReader that will pass the XML contents to the DOM
  -     * @param systemId Specifies the input file
  -     * @throws SAXException
  -     */
  -    public void build(XMLReader reader, String systemId) throws SAXException 
{
  -     try {
  -         // Make sure that the system id is set before proceding
  -         if ((systemId == null) && (_systemId == null)) {
  -             ErrorMsg err = new ErrorMsg(ErrorMsg.XSLTC_SOURCE_ERR);
  -             throw new SAXException(err.toString());
  -         }
  -
  -         // Use this method in case we need to prepend 'file:' to url
  -         if (systemId == null) systemId = _systemId;
  -         setSystemId(systemId);
  -
  -         // Create an input source for the parser first, just in case the
  -         // systemId is invalid. We don't want to waste time creating a SAX
  -         // parser before we know that we actually have some valid input.
  -         InputSource input = new InputSource(systemId);
  -
  -         DOMBuilder builder;
  -        // Can we assume we're dealing with SAX here and therefore use 
SAXIMPL??
  -            // if (_dom instanceof DOMImpl)
  -            //   builder = ((DOMImpl)_dom).getBuilder();
  -            // else
  -            builder = ((SAXImpl)_dom).getBuilder();
  -
  -         // Set the DOM builder up to receive content and lexical events
  -         reader.setContentHandler(builder);
  -         reader.setDTDHandler(builder);
  -         try {
  -             reader.setProperty(LEXICAL_HANDLER_PROPERTY, builder);
  -         }
  -         catch (SAXException e) {
  -             // quitely ignored
  -         }
  -
  -         // Now, finally - parse the input document
  -         reader.parse(input);
  +     if (_source != null) {
  +         return _source.getSystemId();
        }
  -     catch (IOException e) {
  -         throw new SAXException(e);
  +     else {
  +         return(_systemId);
        }
       }
  -
  +    
       /**
  -     * Build the internal XSLTC-specific DOM.
  -     * @param systemId Specifies the input file
  -     * @throws SAXException
  +     * Internal interface which returns a DOM for a given DTMManager and 
translet.
        */
  -    public void build(String systemId) throws SAXException {
  -     try {
  -         // Create an XMLReader (SAX parser) for processing the input
  -         final SAXParserFactory factory = SAXParserFactory.newInstance();
  -         final SAXParser parser = factory.newSAXParser();
  -         final XMLReader reader = parser.getXMLReader();
  -
  -         build(reader, systemId);
  -     }
  -     catch (ParserConfigurationException e) {
  -         throw new SAXException(e);
  -     }
  -    }
  -
  -    /**
  -     * Build the internal XSLTC-specific DOM.
  -     * @param reader An XMLReader that will pass the XML contents to the DOM
  -     * @throws SAXException
  -     */
  -    public void build(XMLReader reader) throws SAXException {
  -     build(reader, _systemId);
  +    protected DOM getDOM(XSLTCDTMManager dtmManager, AbstractTranslet 
translet)
  +        throws SAXException
  +    {
  +        SAXImpl idom = (SAXImpl)_dom.get();
  +                
  +        if (idom != null) {
  +            if (dtmManager != null) {
  +                idom.migrateTo(dtmManager);
  +            }
  +        }
  +        else {
  +            Source source = _source;
  +            if (source == null) {
  +                if (_systemId != null && _systemId.length() > 0) {
  +                    source = new StreamSource(_systemId);
  +                }
  +                else {
  +                    ErrorMsg err = new ErrorMsg(ErrorMsg.XSLTC_SOURCE_ERR);
  +                    throw new SAXException(err.toString());
  +                }
  +            }
  +            
  +            DOMWSFilter wsfilter = null;
  +            if (translet != null && translet instanceof StripFilter) {
  +                wsfilter = new DOMWSFilter(translet);
  +            }
  +                
  +            boolean hasIdCall = (translet != null) ? translet.hasIdCall() : 
false;
  +            
  +            if (dtmManager == null) {
  +                dtmManager = XSLTCDTMManager.newInstance();
  +            }
  +            
  +            idom = (SAXImpl)dtmManager.getDTM(source, true, wsfilter, false, 
false, hasIdCall);
  +            
  +            String systemId = getSystemId();
  +            if (systemId != null) {
  +                idom.setDocumentURI(systemId);
  +            }
  +            _dom.set(idom);
  +        }
  +        return idom;
       }
   
  -    /**
  -     * Build the internal XSLTC-specific DOM.
  -     * The setSystemId() must be called prior to this method.
  -     * @throws SAXException
  -     */
  -    public void build() throws SAXException {
  -     build(_systemId);
  -    }    
  -
  -    /**
  -     * Returns the internal DOM that is encapsulated in this Source
  -     */
  -    protected DOM getDOM() {
  -     return(_dom);
  -    }
   }
  
  
  

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

Reply via email to