mmidy       01/02/02 17:15:38

  Modified:    java/compat_src/org/apache/xalan/xslt XSLTEngineImpl.java
  Log:
  Fix problem where source file was being parsed more than once and if using an 
input stream, we would get a read error
  
  Revision  Changes    Path
  1.21      +65 -75    
xml-xalan/java/compat_src/org/apache/xalan/xslt/XSLTEngineImpl.java
  
  Index: XSLTEngineImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/compat_src/org/apache/xalan/xslt/XSLTEngineImpl.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- XSLTEngineImpl.java       2001/02/02 19:17:42     1.20
  +++ XSLTEngineImpl.java       2001/02/03 01:15:37     1.21
  @@ -328,8 +328,7 @@
         Boolean totalTimeID = new Boolean(true);
         pushTime(totalTimeID);
         Node sourceTree = null;
  -      if(null != inputSource)
  -        sourceTree = getSourceTreeFromInput(inputSource);
  +      
         Templates templates = null;
         if (m_needToEval)
         {
  @@ -372,63 +371,67 @@
           }  
           
         }      
  -      else if(null != sourceTree)
  -      {
  -        String stylesheetURI = null;
  -        Stack hrefs = new Stack();
  -        for(Node child=sourceTree.getFirstChild(); null != child; 
child=child.getNextSibling())
  +      else if(null != inputSource)
  +      {        
  +        sourceTree = getSourceTreeFromInput(inputSource);
  +        if(null != sourceTree)
           {
  -          if(Node.PROCESSING_INSTRUCTION_NODE == child.getNodeType())
  +          String stylesheetURI = null;
  +          Stack hrefs = new Stack();
  +          for(Node child=sourceTree.getFirstChild(); null != child; 
child=child.getNextSibling())
             {
  -            ProcessingInstruction pi = (ProcessingInstruction)child;
  -            if(pi.getNodeName().equals("xml-stylesheet")
  -               || pi.getNodeName().equals("xml:stylesheet"))
  +            if(Node.PROCESSING_INSTRUCTION_NODE == child.getNodeType())
               {
  -              boolean isOK = true;
  -              StringTokenizer tokenizer = new 
StringTokenizer(pi.getNodeValue(), " \t=");
  -              while(tokenizer.hasMoreTokens())
  +              ProcessingInstruction pi = (ProcessingInstruction)child;
  +              if(pi.getNodeName().equals("xml-stylesheet")
  +                 || pi.getNodeName().equals("xml:stylesheet"))
                 {
  -                if(tokenizer.nextToken().equals("type"))
  +                boolean isOK = true;
  +                StringTokenizer tokenizer = new 
StringTokenizer(pi.getNodeValue(), " \t=");
  +                while(tokenizer.hasMoreTokens())
                   {
  -                  String typeVal = tokenizer.nextToken();
  -                  typeVal = typeVal.substring(1, typeVal.length()-1);
  -                  if(!typeVal.equals("text/xsl"))
  +                  if(tokenizer.nextToken().equals("type"))
                     {
  -                    isOK = false;
  +                    String typeVal = tokenizer.nextToken();
  +                    typeVal = typeVal.substring(1, typeVal.length()-1);
  +                    if(!typeVal.equals("text/xsl"))
  +                    {
  +                      isOK = false;
  +                    }
                     }
                   }
  -              }
   
  -              if(isOK)
  -              {
  -                tokenizer = new StringTokenizer(pi.getNodeValue(), " \t=");
  -                while(tokenizer.hasMoreTokens())
  +                if(isOK)
                   {
  -                  if(tokenizer.nextToken().equals("href"))
  +                  tokenizer = new StringTokenizer(pi.getNodeValue(), " \t=");
  +                  while(tokenizer.hasMoreTokens())
                     {
  -                    stylesheetURI = tokenizer.nextToken();
  -                    stylesheetURI = stylesheetURI.substring(1, 
stylesheetURI.length()-1);
  -                    hrefs.push(stylesheetURI);
  -                  }
  -                }                
  +                    if(tokenizer.nextToken().equals("href"))
  +                    {
  +                      stylesheetURI = tokenizer.nextToken();
  +                      stylesheetURI = stylesheetURI.substring(1, 
stylesheetURI.length()-1);
  +                      hrefs.push(stylesheetURI);
  +                    }
  +                  }                
  +                }
                 }
               }
  -          }
  -        } // end for(int i = 0; i < nNodes; i++)
  -        boolean isRoot = true;
  -        Stylesheet prevStylesheet = null;
  -        while(!hrefs.isEmpty())
  -        {
  -          Stylesheet stylesheet = 
getStylesheetFromPIURL((String)hrefs.pop(), sourceTree,
  -                                                         (null != 
inputSource)
  -                                                         ? 
inputSource.getSystemId() : null,
  -                                                         isRoot);
  -          if(false == isRoot)
  +          } // end for(int i = 0; i < nNodes; i++)
  +          boolean isRoot = true;
  +          Stylesheet prevStylesheet = null;
  +          while(!hrefs.isEmpty())
             {
  -            prevStylesheet.setImport((StylesheetComposed)stylesheet);
  +            Stylesheet stylesheet = 
getStylesheetFromPIURL((String)hrefs.pop(), sourceTree,
  +                                                           (null != 
inputSource)
  +                                                           ? 
inputSource.getSystemId() : null,
  +                                                           isRoot);
  +            if(false == isRoot)
  +            {
  +              prevStylesheet.setImport((StylesheetComposed)stylesheet);
  +            }
  +            prevStylesheet = stylesheet;
  +            isRoot = false;
             }
  -          prevStylesheet = stylesheet;
  -          isRoot = false;
           }
         }
         else
  @@ -448,14 +451,14 @@
           }  
         }
   
  -      if(null != sourceTree)
  +      if(null != templates)
         {
           try{
             m_transformerImpl = (TransformerImpl)templates.newTransformer(); 
             if (m_problemListener != null)
               m_transformerImpl.setErrorListener(m_problemListener);
             if (m_liaison != null)
  -          m_transformerImpl.getXPathContext().setDOMHelper(m_liaison);
  +            m_transformerImpl.getXPathContext().setDOMHelper(m_liaison);
      
           }
           catch (TransformerConfigurationException tce)
  @@ -563,10 +566,9 @@
       m_stylesheetRoot = null;
       try
       {
  -      m_stylesheetRoot = 
createStylesheetRoot(stylesheetSource.getSystemId());
  -      addTraceListenersToStylesheet();
         StylesheetHandler stylesheetProcessor
  -        = new StylesheetHandler((TransformerFactoryImpl)m_tfactory); //this, 
m_stylesheetRoot); 
  +          = new StylesheetHandler((TransformerFactoryImpl)m_tfactory); 
//this, m_stylesheetRoot); 
  +        
         Source ssSource = stylesheetSource.getSourceObject();
         if(ssSource instanceof DOMSource)
         {
  @@ -583,6 +585,10 @@
         }
         else
         {
  +        m_stylesheetRoot = 
createStylesheetRoot(stylesheetSource.getSystemId());
  +        addTraceListenersToStylesheet();
  +        
  +        
           stylesheetProcessor.pushStylesheet(m_stylesheetRoot.getObject());    
  
           diag("========= Parsing "+xslIdentifier+" ==========");
           pushTime(xslIdentifier);
  @@ -710,15 +716,15 @@
           diag("========= Parsing "+xmlIdentifier+" ==========");
           pushTime(xmlIdentifier);
           
  -        String liaisonClassName = 
System.getProperty("org.apache.xalan.source.liaison");
  +        //String liaisonClassName = 
System.getProperty("org.apache.xalan.source.liaison");
   
  -        if(null != liaisonClassName)
  +        if(null != m_liaison)
           {
  -          DOM2Helper liaison =  
(DOM2Helper)(Class.forName(liaisonClassName).newInstance());
  -          liaison.parse(SAXSource.sourceToInputSource(iSource));
  +          //DOM2Helper liaison =  
(DOM2Helper)(Class.forName(liaisonClassName).newInstance());
  +          m_liaison.parse(SAXSource.sourceToInputSource(iSource));
             if(null != m_diagnosticsPrintWriter)
               displayDuration("Parse of "+xmlIdentifier, xmlIdentifier);
  -          sourceTree = liaison.getDocument();
  +          sourceTree = m_liaison.getDocument();
           }
           else
           {      
  @@ -938,31 +944,15 @@
         URL xslURL = getURLFromString(xslURLString, xmlBaseIdent);
   
         XSLTInputSource inputSource = new XSLTInputSource(xslURL.toString());
  -      String liaisonClassName = 
System.getProperty("org.apache.xalan.source.liaison");
  +      String liaisonClassName = m_liaison.getClass().getName();
   
  -      if(null != liaisonClassName)
  +      if(null != m_liaison)
         {
           try{
  -          DOM2Helper liaison =  
(DOM2Helper)(Class.forName(liaisonClassName).newInstance());
  -          
liaison.parse(SAXSource.sourceToInputSource(inputSource.getSourceObject()));
  +          //DOM2Helper liaison =  
(DOM2Helper)(Class.forName(liaisonClassName).newInstance());
  +          
m_liaison.parse(SAXSource.sourceToInputSource(inputSource.getSourceObject()));
           }
  -        catch (ClassNotFoundException e1) 
  -        {
  -          throw new SAXException("XML Liaison class " + liaisonClassName +
  -            " specified but not found", e1);
  -        } 
  -        catch (IllegalAccessException e2) 
  -        {
  -          throw new SAXException("XML Liaison class " + liaisonClassName +
  -            " found but cannot be loaded", e2);
  -        } 
  -        catch (InstantiationException e3) 
  -        {
  -          throw new SAXException("XML Liaison class " + liaisonClassName +
  -            " loaded but cannot be instantiated (no empty public 
constructor?)",
  -            e3);
  -        }
  -        
  +                
           catch (TransformerException tce)
           {
             throw new SAXException(tce);
  
  
  

Reply via email to