You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@locus.apache.org on 2000/03/01 03:32:44 UTC

cvs commit: xml-xalan/src/org/apache/xalan/xslt StylesheetRoot.java XSLTEngineImpl.java

sboag       00/02/29 18:32:44

  Modified:    src/org/apache/xalan/xpath/xml XMLParserLiaisonDefault.java
               src/org/apache/xalan/xslt StylesheetRoot.java
                        XSLTEngineImpl.java
  Log:
  Switch to Xerces liaison if the source node or result node are Xerces nodes.  Fix variable resolution in piped transforms.
  
  Revision  Changes    Path
  1.28      +22 -0     xml-xalan/src/org/apache/xalan/xpath/xml/XMLParserLiaisonDefault.java
  
  Index: XMLParserLiaisonDefault.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/XMLParserLiaisonDefault.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- XMLParserLiaisonDefault.java	2000/02/24 21:24:53	1.27
  +++ XMLParserLiaisonDefault.java	2000/03/01 02:32:43	1.28
  @@ -308,6 +308,28 @@
     }
     
     /**
  +   * Copy attributes from another liaison.
  +   */
  +  public void copyFromOtherLiaison(XMLParserLiaisonDefault from)
  +    throws SAXException
  +  {
  +    if(null != from) // defensive
  +    {
  +      this.setAcceptLanguage(from.getAcceptLanguage());
  +      this.setErrorHandler(from.getErrorHandler());
  +      this.setProblemListener(from.getProblemListener());
  +      this.setUseValidation(from.getUseValidation());
  +      this.setEntityResolver(from.m_entityResolver);
  +      this.setLocale(from.m_locale);
  +      this.setDTDHandler(from.m_DTDHandler);
  +      this.m_indent = from.m_indent;
  +      this.m_shouldExpandEntityRefs = from.m_shouldExpandEntityRefs;
  +      this.m_use_validation = from.m_use_validation;
  +      this.m_attrSpecialChars = from.m_attrSpecialChars;
  +    }
  + }
  +  
  +  /**
       * Allow an application to request a locale for errors and warnings.
       *
       * <p>SAX parsers are not required to provide localisation for errors
  
  
  
  1.30      +2 -0      xml-xalan/src/org/apache/xalan/xslt/StylesheetRoot.java
  
  Index: StylesheetRoot.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/StylesheetRoot.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- StylesheetRoot.java	2000/02/24 21:11:02	1.29
  +++ StylesheetRoot.java	2000/03/01 02:32:43	1.30
  @@ -309,6 +309,8 @@
       XSLTEngineImpl processor = (XSLTEngineImpl)iprocessor; // TODO: Check for class cast exception
       synchronized(processor)
       {
  +      processor.switchLiaisonsIfNeeded(sourceTree, outputTarget.getNode());
  +      
         processor.m_stylesheetRoot = this;
   
         OutputStream ostream = null;
  
  
  
  1.51      +66 -31    xml-xalan/src/org/apache/xalan/xslt/XSLTEngineImpl.java
  
  Index: XSLTEngineImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/XSLTEngineImpl.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- XSLTEngineImpl.java	2000/02/29 23:17:42	1.50
  +++ XSLTEngineImpl.java	2000/03/01 02:32:43	1.51
  @@ -96,7 +96,6 @@
     //==========================================================
     // SECTION: Member variables
     //==========================================================
  -  private void ____GENERAL_VARIABLES____(){}
   
     /**
      * The root of a linked set of stylesheets.
  @@ -336,11 +335,6 @@
       return m_countersTable;
     }
   
  -  //==========================================================
  -  // SECTION: Constructors
  -  //==========================================================
  -  private void ____CONSTRUCTORS____(){}
  -
     /**
      * Construct an XSLT processor that uses the default DTM (Document Table Model) liaison
      * and XML parser. As a general rule, you should use XSLTProcessorFactory to create an
  @@ -405,8 +399,7 @@
      */
     public XSLTEngineImpl(XMLParserLiaison parserLiason)
     {
  -    m_parserLiaison = parserLiason;
  -    m_parserLiaison.setEnvSupport(this);
  +    setExecContext(parserLiason);
     }
   
     /**
  @@ -421,8 +414,7 @@
      */
     XSLTEngineImpl(XMLParserLiaison parserLiason, XPathFactory xpathFactory)
     {
  -    m_parserLiaison = parserLiason;
  -    m_parserLiaison.setEnvSupport(this);
  +    setExecContext(parserLiason);
     }
   
     /**
  @@ -465,10 +457,34 @@
       error(XSLTErrorResources.ER_CANNOT_SERIALIZE_XSLPROCESSOR); //,"Can not serialize an XSLTEngineImpl!");
     }
   
  -  //==========================================================
  -  // SECTION: Main API Functions
  -  //==========================================================
  -  private void ____MAIN_API____(){}
  +  /**
  +   * Switch the liaisons if needed according to the type of 
  +   * the source and result nodes.
  +   */
  +  void switchLiaisonsIfNeeded(Node sourceNode, Node resultNode)
  +    throws SAXException
  +  {
  +    // If the result node is a xerces node, try to be smart about which 
  +    // liaison is going to be used.
  +    if((null != resultNode) && (resultNode instanceof org.apache.xerces.dom.NodeImpl) &&
  +       (m_parserLiaison instanceof org.apache.xalan.xpath.dtm.DTMLiaison))
  +    {
  +      if((null != sourceNode) 
  +         && (!(sourceNode instanceof org.apache.xalan.xpath.xdom.XercesLiaison)))
  +        throw new SAXException("Can not mix DTM input with DOM output!");
  +      
  +      XMLParserLiaisonDefault newLiaison = new org.apache.xalan.xpath.xdom.XercesLiaison();
  +      newLiaison.copyFromOtherLiaison((XMLParserLiaisonDefault)m_parserLiaison);
  +      setExecContext(newLiaison);
  +    }
  +    else if((null != sourceNode)&& (sourceNode instanceof org.apache.xerces.dom.NodeImpl) &&
  +       (m_parserLiaison instanceof org.apache.xalan.xpath.dtm.DTMLiaison))
  +    {
  +      XMLParserLiaisonDefault newLiaison = new org.apache.xalan.xpath.xdom.XercesLiaison();
  +      newLiaison.copyFromOtherLiaison((XMLParserLiaisonDefault)m_parserLiaison);
  +      setExecContext(newLiaison);
  +    }
  +  }
   
     /**
      * Transform the source tree to the output in the given
  @@ -487,6 +503,10 @@
     {
       try
       {
  +      // If the result node is a xerces node, try to be smart about which 
  +      // liaison is going to be used.
  +      switchLiaisonsIfNeeded(inputSource.getNode(), outputTarget.getNode());
  +      
         String xslIdentifier = ((null == stylesheetSource) ||
                                 (null == stylesheetSource.getSystemId()))
                                ? "Input XSL" : stylesheetSource.getSystemId();
  @@ -740,7 +760,6 @@
     //==========================================================
     // SECTION: XML Parsing Functions
     //==========================================================
  -  private void ____XML_PARSING_FUNCTIONS____(){}
   
     /**
      * Take a user string and try and parse XML, and also return
  @@ -1123,7 +1142,6 @@
     //==========================================================
     // SECTION: Source Tree Tables
     //==========================================================
  -  private void ____SOURCE_TREE_TABLES____(){}
   
     /**
      * Given a DOM Document, tell what URI was used to parse it.
  @@ -1155,9 +1173,6 @@
       m_parserLiaison.getSourceDocsTable().put(uri, doc);
     }
   
  -
  -  private void ____EXTENSION_HANDLING____(){}
  -
     // BEGIN SANJIVA CODE
     /**
      * Output an object to the result tree by doing the right conversions.
  @@ -1310,7 +1325,6 @@
     //==========================================================
     // SECTION: Diagnostic functions
     //==========================================================
  -  private void ____ERROR_AND_DIAGNOSTIC____(){}
   
     /**
      * List of listeners who are interested in tracing what's
  @@ -1861,7 +1875,6 @@
     //==========================================================
     // SECTION: Functions that create nodes in the result tree
     //==========================================================
  -  private void ____RESULT_TREE_CREATION___(){}
   
     /**
      * Clone an element with or without children.
  @@ -2121,7 +2134,6 @@
     //==========================================================
     // SECTION: Function to do with attribute handling
     //==========================================================
  -  private void ____ATTRIBUTES___(){}
   
     /**
      * Tell if a given element name should output it's text
  @@ -2631,7 +2643,6 @@
     //==========================================================
     // SECTION: Functions for controling whitespace
     //==========================================================
  -  private void ____WHITESPACE____(){}
   
     /**
      * Tells, through the combination of the default-space attribute
  @@ -2995,7 +3006,6 @@
     //==========================================================
     // SECTION: Support functions in fairly random order
     //==========================================================
  -  private void ____SUPPORT____(){}
   
     /**
      * Get the execution context for XPath.
  @@ -3006,6 +3016,15 @@
     }
   
     /**
  +   * Set the execution context for XPath.
  +   */
  +  public void setExecContext(XMLParserLiaison liaison)
  +  {
  +    m_parserLiaison = liaison;
  +    liaison.setEnvSupport(this);
  +  }
  +
  +  /**
      * Get the XML Parser Liaison that this processor uses.
      */
     public XMLParserLiaison getXMLProcessorLiaison()
  @@ -3459,8 +3478,6 @@
       return m_parserLiaison.getProblemListener();
     }
   
  -  private void ____FormatterListener_INTERFACE____(){}
  -
     private FormatterToDOM m_sourceTreeHandler = null;
   
     private java.io.OutputStream m_outputStream = null;
  @@ -3488,12 +3505,30 @@
     public void startDocument ()
       throws SAXException
     {
  -    m_sourceTreeHandler = new FormatterToDOM(m_parserLiaison.createDocument());
       ErrorHandler errHandler = m_parserLiaison.getErrorHandler();
  -    m_parserLiaison = new org.apache.xalan.xpath.xdom.XercesLiaison(errHandler);
  -    StylesheetRoot stylesheet = m_stylesheetRoot;
  -    reset();
  -    m_stylesheetRoot = stylesheet;
  +    
  +    // Force a XercesLiaison for right now, since we can't 
  +    // do the DTM with SAX right now.
  +    XMLParserLiaisonDefault liaison = new org.apache.xalan.xpath.xdom.XercesLiaison(errHandler);
  +    liaison.copyFromOtherLiaison((XMLParserLiaisonDefault)m_parserLiaison);
  +    setExecContext(liaison);
  +    
  +    Document sourceTree = m_parserLiaison.createDocument();
  +    m_sourceTreeHandler = new FormatterToDOM(sourceTree);
  +    resetCurrentState(sourceTree);
  +    m_rootDoc = sourceTree;
  +    // StylesheetRoot stylesheet = m_stylesheetRoot;
  +    // reset();
  +    try
  +    {
  +      getVarStack().pushContextMarker();
  +      resolveTopLevelParams();
  +    }
  +    catch(Exception e)
  +    {
  +      throw new SAXException(e.getMessage(), e);
  +    }
  +    // m_stylesheetRoot = stylesheet;
       m_sourceTreeHandler.startDocument();
     }