You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2001/12/13 21:29:04 UTC

cvs commit: xml-cocoon2/src/org/apache/cocoon/components/xslt XSLTProcessorImpl.java

vgritsenko    01/12/13 12:29:04

  Modified:    src/org/apache/cocoon/components/xslt Tag: cocoon_20_branch
                        XSLTProcessorImpl.java
  Log:
  Applied patch from Eisert, Wolfram [Wolfram.Eisert@Dresdner-Bank.com] to fix
  "XSP page getting called TWICE! (using pipeline as a transformer)" issue.
  Complex debug statements surrounded by if().
  Make debug output more consistent.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.4.2.9   +72 -57    xml-cocoon2/src/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java
  
  Index: XSLTProcessorImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java,v
  retrieving revision 1.4.2.8
  retrieving revision 1.4.2.9
  diff -u -r1.4.2.8 -r1.4.2.9
  --- XSLTProcessorImpl.java	2001/11/25 23:13:35	1.4.2.8
  +++ XSLTProcessorImpl.java	2001/12/13 20:29:04	1.4.2.9
  @@ -30,7 +30,12 @@
   import org.xml.sax.XMLReader;
   import org.xml.sax.helpers.XMLReaderFactory;
   
  -import javax.xml.transform.*;
  +import javax.xml.transform.URIResolver;
  +import javax.xml.transform.TransformerException;
  +import javax.xml.transform.TransformerFactory;
  +import javax.xml.transform.Templates;
  +import javax.xml.transform.Result;
  +import javax.xml.transform.Transformer;
   import javax.xml.transform.sax.SAXSource;
   import javax.xml.transform.sax.SAXTransformerFactory;
   import javax.xml.transform.sax.TemplatesHandler;
  @@ -105,7 +110,6 @@
       this.entityResolver = (Resolver)manager.lookup(Resolver.ROLE);
     }
   
  -
     public void dispose()
     {
       if (this.manager != null)
  @@ -151,12 +155,15 @@
       throws ProcessingException
     {
       try {
  -      Templates templates = getTemplates(stylesheet);
  +      final InputSource is = stylesheet.getInputSource();
  +      final String id = is.getSystemId();
  +      Templates templates = getTemplates(stylesheet, id);
         if(templates == null) {
  -        InputSource is = stylesheet.getInputSource();
  -        getLogger().debug("Creating new Templates in " + this + " for " + is);
  -        if (is.getSystemId() != null)
  -          getLogger().debug("  with system id " + is.getSystemId());
  +        if (this.getLogger().isDebugEnabled()) {
  +          getLogger().debug("Creating new Templates in " + this + " for " + is);
  +          if (id != null)
  +            getLogger().debug("  with system id " + id);
  +        }
   
           //templates = getTransformerFactory().newTemplates(new SAXSource(is));
   
  @@ -173,25 +180,30 @@
           if (filter != null) {
             filter.setParent(reader);
             filter.setContentHandler(templatesHandler);
  -        }
  -        else
  +        } else {
             reader.setContentHandler(templatesHandler);
  -        if(this.entityResolver != null)
  +        }
  +        if (this.entityResolver != null)
               reader.setEntityResolver(this.entityResolver);
   
  -        getLogger().debug("InputSource = " + is
  -                          + ", templatesHandler = " + templatesHandler
  -                          + ", reader = " + reader);
  +        if (this.getLogger().isDebugEnabled()) {
  +          getLogger().debug("InputSource = " + is
  +                            + ", templatesHandler = " + templatesHandler
  +                            + ", reader = " + reader);
  +        }
           // Parse the stylesheet.
           reader.parse(is);
   
           // Get the Templates object (generated during the parsing of
           // the stylesheet) from the TemplatesHandler.
           templates = templatesHandler.getTemplates();
  -        putTemplates (templates, stylesheet);
  +        putTemplates (templates, stylesheet, id);
         } else {
  -        getLogger().debug("Reusing Templates in " + this + " for "
  -                          + stylesheet.getInputSource().getSystemId());
  +        if (this.getLogger().isDebugEnabled()) {
  +          getLogger().debug("Reusing Templates in " + this + " for " + is);
  +          if (id != null)
  +            getLogger().debug("  with system id " + id);
  +        }
         }
   
         TransformerHandler handler
  @@ -199,19 +211,20 @@
         if (handler == null) {
           /* If there is a problem in getting the handler, try using a
            * brand new Templates object */
  -        getLogger().debug("Re-creating new Templates in " + this + " for"
  -                          + stylesheet.getInputSource().getSystemId());
  -        InputSource is = stylesheet.getInputSource();
  +        if (this.getLogger().isDebugEnabled()) {
  +          getLogger().debug("Re-creating new Templates in " + this + " for" + is);
  +          if (id != null)
  +            getLogger().debug("  with system id " + id);
  +        }
           templates = getTransformerFactory().newTemplates(new SAXSource(is));
  -        putTemplates (templates, stylesheet);
  +        putTemplates (templates, stylesheet, id);
           handler = getTransformerFactory().newTransformerHandler(templates);
         }
   
         handler.getTransformer()
           .setErrorListener(new TraxErrorHandler(getLogger()));
         return handler;
  -    }
  -    catch (Exception e) {
  +    } catch (Exception e) {
         throw new ProcessingException("Error in creating Transform Handler", e);
       }
     }
  @@ -221,10 +234,12 @@
       throws ProcessingException
     {
       try {
  -      getLogger().debug("XSLTProcessorImpl: transform source = " + source
  -                        + ", stylesheet = " + stylesheet
  -                        + ", parameters = " + params
  -                        + ", result = " + result);
  +      if (this.getLogger().isDebugEnabled()) {
  +        getLogger().debug("XSLTProcessorImpl: transform source = " + source
  +                          + ", stylesheet = " + stylesheet
  +                          + ", parameters = " + params
  +                          + ", result = " + result);
  +      }
         TransformerHandler handler = getTransformerHandler(stylesheet);
         Transformer transformer = handler.getTransformer();
   
  @@ -240,19 +255,20 @@
         transformer.transform(new StreamSource(is.getByteStream(),
                                                is.getSystemId()),
                               result);
  -      getLogger().debug("XSLTProcessorImpl: transform done");
  -      if (result instanceof StreamResult) {
  -        Writer writer = ((StreamResult)result).getWriter();
  -        getLogger().debug("XSLTProcessorImpl: transform result = "
  -                          + writer);
  -        if (writer instanceof StringWriter) {
  -          StringBuffer stringBuffer = ((StringWriter)writer).getBuffer();
  +      if (this.getLogger().isDebugEnabled()) {
  +        getLogger().debug("XSLTProcessorImpl: transform done");
  +        if (result instanceof StreamResult) {
  +          Writer writer = ((StreamResult)result).getWriter();
             getLogger().debug("XSLTProcessorImpl: transform result = "
  -                            + stringBuffer);
  +                            + writer);
  +          if (writer instanceof StringWriter) {
  +            StringBuffer stringBuffer = ((StringWriter)writer).getBuffer();
  +            getLogger().debug("XSLTProcessorImpl: transform result = "
  +                              + stringBuffer);
  +          }
           }
         }
  -    }
  -    catch (Exception e) {
  +    } catch (Exception e) {
         throw new ProcessingException("Error in running Transformation", e);
       }
     }
  @@ -281,7 +297,7 @@
       return tfactory;
     }
   
  -  private Templates getTemplates(Source stylesheet)
  +  private Templates getTemplates(Source stylesheet, String id)
       throws IOException, ProcessingException
     {
       Templates templates = null;
  @@ -289,40 +305,35 @@
       if (useStore == false)
         return null;
   
  -    InputSource is = stylesheet.getInputSource();
  -    getLogger().debug("XSLTProcessorImpl getTemplates: stylesheet "
  -                      + is.getSystemId());
  +    getLogger().debug("XSLTProcessorImpl getTemplates: stylesheet " + id);
   
       // only stylesheets with a last modification date are stored
       if (stylesheet.getLastModified() != 0) {
   
         // Stored is an array of the template and the caching time
  -      if (store.containsKey(is.getSystemId())) {
  -        Object[] templateAndTime
  -          = (Object[])store.get(is.getSystemId());
  +      if (store.containsKey(id)) {
  +        Object[] templateAndTime = (Object[])store.get(id);
   
           if(templateAndTime != null && templateAndTime[1] != null) {
             long storedTime = ((Long)templateAndTime[1]).longValue();
   
             if (storedTime < stylesheet.getLastModified()) {
  -            store.remove(is.getSystemId());
  -          }
  -          else {
  +            store.remove(id);
  +          } else {
               templates = (Templates)templateAndTime[0];
             }
           }
         }
  -    }
  -    else {
  +    } else {
         // remove an old template if it exists
  -      if (store.containsKey(is.getSystemId())) {
  -        store.remove(is.getSystemId());
  +      if (store.containsKey(id)) {
  +        store.remove(id);
         }
       }
  -   return templates;
  +    return templates;
     }
   
  -  private void putTemplates (Templates templates, Source stylesheet)
  +  private void putTemplates (Templates templates, Source stylesheet, String id)
       throws IOException, ProcessingException
     {
       if (useStore == false)
  @@ -335,7 +346,7 @@
         Object[] templateAndTime = new Object[2];
         templateAndTime[0] = templates;
         templateAndTime[1] = new Long(stylesheet.getLastModified());
  -      store.hold(stylesheet.getInputSource().getSystemId(), templateAndTime);
  +      store.hold(id, templateAndTime);
       }
     }
   
  @@ -356,8 +367,10 @@
     public javax.xml.transform.Source resolve(String href, String base)
       throws TransformerException
     {
  -    getLogger().debug("XSLTProcessorImpl: resolve(href = " + href
  -                      + ", base = " + base + "); resolver = " + resolver);
  +    if (this.getLogger().isDebugEnabled()) {
  +      getLogger().debug("XSLTProcessorImpl: resolve(href = " + href
  +                        + ", base = " + base + "); resolver = " + resolver);
  +    }
   
       try {
         Source xslSource;
  @@ -389,8 +402,10 @@
           }
         }
         InputSource is = xslSource.getInputSource();
  -      getLogger().debug("xslSource = " + xslSource
  -                        + ", system id = " + is.getSystemId());
  +      if (this.getLogger().isDebugEnabled()) {
  +        getLogger().debug("xslSource = " + xslSource
  +                          + ", system id = " + is.getSystemId());
  +      }
         return new StreamSource(is.getByteStream(),
                                 is.getSystemId());
       } catch (ResourceNotFoundException rnfe) {
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org