cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject cvs commit: cocoon-2.1/src/java/org/apache/cocoon/transformation CIncludeTransformer.java
Date Fri, 11 Jun 2004 20:32:20 GMT
vgritsenko    2004/06/11 13:32:20

  Modified:    src/blocks/asciiart/java/org/apache/cocoon/generation/asciiart
                        AsciiArtSVGGenerator.java
               src/blocks/html/java/org/apache/cocoon/generation
                        HTMLGenerator.java
               src/blocks/midi/java/org/apache/cocoon/generation
                        XMidiGenerator.java
               src/java/org/apache/cocoon/components/pipeline/impl
                        AbstractCachingProcessingPipeline.java
               src/java/org/apache/cocoon/components/source SourceUtil.java
               src/java/org/apache/cocoon/generation FileGenerator.java
               src/java/org/apache/cocoon/transformation
                        CIncludeTransformer.java
  Log:
  Reduce code duplication - unify SAXException handling in three generators.
  
  Revision  Changes    Path
  1.6       +24 -42    cocoon-2.1/src/blocks/asciiart/java/org/apache/cocoon/generation/asciiart/AsciiArtSVGGenerator.java
  
  Index: AsciiArtSVGGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/asciiart/java/org/apache/cocoon/generation/asciiart/AsciiArtSVGGenerator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AsciiArtSVGGenerator.java	5 Mar 2004 13:01:38 -0000	1.5
  +++ AsciiArtSVGGenerator.java	11 Jun 2004 20:32:19 -0000	1.6
  @@ -1,12 +1,12 @@
   /*
    * Copyright 1999-2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -47,7 +47,7 @@
    * @version CVS $Id$
    * @since Cocoon 2.1, 22 December 2002
    */
  -public class AsciiArtSVGGenerator 
  +public class AsciiArtSVGGenerator
       extends AbstractGenerator
       implements CacheableProcessingComponent {
   
  @@ -66,11 +66,11 @@
       /** default SVG line attributes
        */
       private final String DEFAULT_LINE_ATTRIBUTE = "stroke:black; stroke-width:1.5";
  -    
  +
       /** default SVG text attribute
        */
       private final String DEFAULT_TEXT_ATTRIBUTE = "font-size: 12; font-family:Times Roman; fill:blue;";
  -    
  +
       private String lineAttribute = DEFAULT_LINE_ATTRIBUTE;
       private String textAttribute = DEFAULT_TEXT_ATTRIBUTE;
   
  @@ -79,7 +79,7 @@
       final int DEFAULT_Y_GRID = 12;
       private int xGrid = DEFAULT_X_GRID;
       private int yGrid = DEFAULT_Y_GRID;
  -    
  +
       /**
        * Setup the AsciiArtSVG generator.
        * Try to get the last modification date of the source for caching.
  @@ -95,20 +95,20 @@
       public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
       throws ProcessingException, SAXException, IOException {
           super.setup(resolver, objectModel, src, par);
  -        
  +
           try {
               this.inputSource = resolver.resolveURI(src);
           } catch (SourceException se) {
               throw SourceUtil.handle("Error during resolving of '" + src + "'.", se);
           }
  -        
  -        // setup lineAttribute
  -        lineAttribute = par.getParameter( "line-attribute", DEFAULT_LINE_ATTRIBUTE );
  -        // setup textAttribute
  -        textAttribute = par.getParameter( "text-attribute", DEFAULT_TEXT_ATTRIBUTE );
  -        
  -        xGrid = par.getParameterAsInteger( "x-grid", DEFAULT_X_GRID );
  -        yGrid = par.getParameterAsInteger( "y-grid", DEFAULT_Y_GRID );
  +
  +        // Setup lineAttribute
  +        lineAttribute = par.getParameter("line-attribute", DEFAULT_LINE_ATTRIBUTE);
  +        // Setup textAttribute
  +        textAttribute = par.getParameter("text-attribute", DEFAULT_TEXT_ATTRIBUTE);
  +
  +        xGrid = par.getParameterAsInteger("x-grid", DEFAULT_X_GRID);
  +        yGrid = par.getParameterAsInteger("y-grid", DEFAULT_Y_GRID);
       }
   
   
  @@ -129,7 +129,7 @@
        * Generate the unique key.
        * This key must be unique inside the space of this component.
        *
  -     *@return    The generated key hashes the src
  +     * @return The generated key hashes the src
        */
       public java.io.Serializable getKey() {
           return this.inputSource.getURI();
  @@ -139,7 +139,7 @@
       /**
        * Generate the validity object.
        *
  -     *@return    The generated validity object or <code>null</code> if the
  +     * @return The generated validity object or <code>null</code> if the
        *         component is currently not cacheable.
        */
       public SourceValidity getValidity() {
  @@ -149,17 +149,13 @@
   
       /**
        * Generate XML data.
  -     *
  -     *@exception  IOException          Description of the Exception
  -     *@exception  SAXException         Description of the Exception
  -     *@exception  ProcessingException  Description of the Exception
        */
       public void generate()
  -             throws IOException, SAXException, ProcessingException {
  +    throws IOException, SAXException, ProcessingException {
           try {
  -            if (this.getLogger().isDebugEnabled()) {
  -                this.getLogger().debug("processing asciiart file " + super.source);
  -                this.getLogger().debug("asciiart file resolved to " + this.inputSource.getURI());
  +            if (getLogger().isDebugEnabled()) {
  +                getLogger().debug("Source " + super.source +
  +                                  " resolved to " + this.inputSource.getURI());
               }
   
               // read the ascii art
  @@ -206,21 +202,7 @@
               this.contentHandler.endPrefixMapping(PREFIX);
               this.contentHandler.endDocument();
           } catch (SAXException e) {
  -            final Exception cause = e.getException();
  -            if (cause != null) {
  -                if (cause instanceof ProcessingException) {
  -                    throw (ProcessingException) cause;
  -                }
  -                if (cause instanceof IOException) {
  -                    throw (IOException) cause;
  -                }
  -                if (cause instanceof SAXException) {
  -                    throw (SAXException) cause;
  -                }
  -                throw new ProcessingException("Could not read resource "
  -                         + this.inputSource.getURI(), cause);
  -            }
  -            throw e;
  +            SourceUtil.handleSAXException(this.inputSource.getURI(), e);
           }
       }
   
  
  
  
  1.13      +16 -17    cocoon-2.1/src/blocks/html/java/org/apache/cocoon/generation/HTMLGenerator.java
  
  Index: HTMLGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/html/java/org/apache/cocoon/generation/HTMLGenerator.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- HTMLGenerator.java	3 May 2004 13:07:26 -0000	1.12
  +++ HTMLGenerator.java	11 Jun 2004 20:32:19 -0000	1.13
  @@ -1,12 +1,12 @@
   /*
    * Copyright 1999-2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -56,13 +56,13 @@
    * @cocoon.sitemap.component.documentation
    * The html generator reads HTML from a source, converts it to XHTML
    * and generates SAX Events.
  - * 
  + *
    * @cocoon.sitemap.component.name   html
    * @cocoon.sitemap.component.label  content
    * @cocoon.sitemap.component.logger sitemap.generator.html
    * @cocoon.sitemap.component.documentation.caching
    *               Uses the last modification date of the xml document for validation
  - * 
  + *
    * @cocoon.sitemap.component.pooling.min   4
    * @cocoon.sitemap.component.pooling.max  32
    * @cocoon.sitemap.component.pooling.grow  4
  @@ -153,7 +153,7 @@
           super.setup(resolver, objectModel, src, par);
   
           Request request = ObjectModelHelper.getRequest(objectModel);
  -        
  +
           if (src == null) {
               // Handle this request as the StreamGenerator does (from the POST
               // request or from a request parameter), but try to make sure
  @@ -199,8 +199,9 @@
           }
   
           xpath = request.getParameter("xpath");
  -        if(xpath == null)
  +        if (xpath == null) {
               xpath = par.getParameter("xpath",null);
  +        }
   
           // append the request parameter to the URL if necessary
           if (par.getParameterAsBoolean("copy-parameters", false)
  @@ -212,8 +213,9 @@
           }
   
           try {
  -            if (source != null)
  +            if (source != null) {
                   this.inputSource = resolver.resolveURI(super.source);
  +            }
           } catch (SourceException se) {
               throw SourceUtil.handle("Unable to resolve " + super.source, se);
           }
  @@ -228,8 +230,9 @@
        *              is currently not cacheable.
        */
       public java.io.Serializable getKey() {
  -        if (this.inputSource == null)
  +        if (this.inputSource == null) {
               return null;
  +        }
   
           if (this.xpath != null) {
               StringBuffer buffer = new StringBuffer(this.inputSource.getURI());
  @@ -249,8 +252,9 @@
        *         component is currently not cacheable.
        */
       public SourceValidity getValidity() {
  -        if (this.inputSource == null)
  +        if (this.inputSource == null) {
               return null;
  +        }
           return this.inputSource.getValidity();
       }
   
  @@ -313,13 +317,8 @@
                   domStreamer.stream(doc.getDocumentElement());
               }
               this.contentHandler.endDocument();
  -        } catch (IOException e){
  -            throw new ResourceNotFoundException("Could not get resource "
  -                + this.inputSource.getURI(), e);
           } catch (SAXException e){
  -            throw e;
  -        } catch (Exception e){
  -            throw new ProcessingException("Exception in HTMLGenerator.generate()",e);
  +            SourceUtil.handleSAXException(this.inputSource.getURI(), e);
           }
       }
   
  
  
  
  1.6       +22 -42    cocoon-2.1/src/blocks/midi/java/org/apache/cocoon/generation/XMidiGenerator.java
  
  Index: XMidiGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/midi/java/org/apache/cocoon/generation/XMidiGenerator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XMidiGenerator.java	5 Mar 2004 13:02:00 -0000	1.5
  +++ XMidiGenerator.java	11 Jun 2004 20:32:19 -0000	1.6
  @@ -1,12 +1,12 @@
   /*
    * Copyright 1999-2002,2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -15,28 +15,28 @@
    */
   package org.apache.cocoon.generation;
   
  -import java.io.IOException;
  -import java.io.InputStream;
  -import java.util.Hashtable;
  -import java.util.Map;
  -
   import org.apache.avalon.framework.parameters.ParameterException;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.midi.xmidi.ByteLen;
  -import org.apache.cocoon.components.midi.xmidi.Utils;
   import org.apache.cocoon.components.midi.xmidi.Constants;
  +import org.apache.cocoon.components.midi.xmidi.Utils;
   import org.apache.cocoon.components.source.SourceUtil;
   import org.apache.cocoon.environment.SourceResolver;
  -import org.apache.cocoon.xml.XMLConsumer;
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceException;
   import org.apache.excalibur.source.SourceNotFoundException;
   import org.apache.excalibur.source.SourceValidity;
  +
   import org.xml.sax.SAXException;
   import org.xml.sax.helpers.AttributesImpl;
   
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.util.Hashtable;
  +import java.util.Map;
  +
   /**
    * Reads a standard MIDI file and generates SAX Events.
    *
  @@ -137,29 +137,16 @@
        * Generate XML data.
        */
       public void generate()
  -        throws IOException, SAXException, ProcessingException {
  +    throws IOException, SAXException, ProcessingException {
           try {
  -            if (this.getLogger().isDebugEnabled()) {
  -                this.getLogger().debug("processing file " + super.source);
  -                this.getLogger().debug(
  -                    "file resolved to " + this.inputSource.getURI());
  +            if (getLogger().isDebugEnabled()) {
  +                getLogger().debug("Source " + super.source +
  +                                  " resolved to " + this.inputSource.getURI());
               }
  -            parseMIDI(this.inputSource, super.xmlConsumer);
   
  +            parseMIDI(this.inputSource);
           } catch (SAXException e) {
  -            final Exception cause = e.getException();
  -            if (cause != null) {
  -                if (cause instanceof ProcessingException)
  -                    throw (ProcessingException) cause;
  -                if (cause instanceof IOException)
  -                    throw (IOException) cause;
  -                if (cause instanceof SAXException)
  -                    throw (SAXException) cause;
  -                throw new ProcessingException(
  -                    "Could not read resource " + this.inputSource.getURI(),
  -                    cause);
  -            }
  -            throw e;
  +            SourceUtil.handleSAXException(this.inputSource.getURI(), e);
           }
       }
   
  @@ -175,14 +162,9 @@
   
       /**
        * @param source
  -     * @param consumer
        */
  -    private void parseMIDI(Source source, XMLConsumer consumer)
  -        throws
  -            SAXException,
  -            SourceNotFoundException,
  -            IOException,
  -            ProcessingException {
  +    private void parseMIDI(Source source)
  +    throws SAXException, SourceNotFoundException, IOException, ProcessingException {
           InputStream inputStream = source.getInputStream();
   
           AttributesImpl attr = new AttributesImpl();
  @@ -664,8 +646,8 @@
       }
   
       /**
  -    add track data to DOM structure
  -    */
  +     * Add track data to DOM structure
  +     */
       void doTrack(byte[] dta, int len)
           throws SAXException, ProcessingException {
           AttributesImpl attr = new AttributesImpl();
  @@ -1036,9 +1018,8 @@
       }
   
       /**
  -    write formatted hex data to file
  -    */
  -
  +     * Write formatted hex data to file
  +     */
       void doHexData(byte[] dta, int len)
           throws ProcessingException, SAXException {
           AttributesImpl attr = new AttributesImpl();
  @@ -1064,5 +1045,4 @@
   
           this.contentHandler.endElement("", "HEXDATA", "HEXDATA");
       }
  -
   }
  
  
  
  1.21      +53 -61    cocoon-2.1/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
  
  Index: AbstractCachingProcessingPipeline.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- AbstractCachingProcessingPipeline.java	24 May 2004 11:58:06 -0000	1.20
  +++ AbstractCachingProcessingPipeline.java	11 Jun 2004 20:32:19 -0000	1.21
  @@ -1,12 +1,12 @@
   /*
    * Copyright 1999-2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -79,7 +79,7 @@
       protected PipelineCacheKey toCacheKey;
       /** The source validities used for caching */
       protected SourceValidity[] toCacheSourceValidities;
  -    
  +
       /** The index indicating to the first transformer which is not cacheable */
       protected int firstNotCacheableTransformerIndex;
       /** Cache complete response */
  @@ -89,7 +89,7 @@
       protected boolean doSmartCaching;
       /** Default setting for smart caching */
       protected boolean configuredDoSmartCaching;
  -    
  +
       /**
        * Abstract methods defined in subclasses
        */
  @@ -109,7 +109,7 @@
           this.configuredDoSmartCaching =
               params.getParameterAsBoolean("smart-caching", true);
       }
  -    
  +
       /**
        * Setup this component
        */
  @@ -179,7 +179,7 @@
                       environment.setContentLength(this.cachedResponse.length);
                       outputStream.write(this.cachedResponse);
                   }
  -            } catch ( SocketException se ) {
  +            } catch (SocketException se) {
                   if (se.getMessage().indexOf("reset") > 0
                           || se.getMessage().indexOf("aborted") > 0
                           || se.getMessage().indexOf("connection abort") > 0) {
  @@ -189,10 +189,8 @@
                       throw new ProcessingException(
                               "Failed to execute pipeline.", se);
                   }
  -            } catch ( Exception e ) {
  -                if (e instanceof ProcessingException)
  -                    throw (ProcessingException)e;
  -                throw new ProcessingException("Error executing pipeline.",e);
  +            } catch (Exception e) {
  +                throw new ProcessingException("Error executing pipeline.", e);
               }
           } else {
   
  @@ -204,10 +202,10 @@
               }
               try {
                   OutputStream os = null;
  -                
  +
                   if (this.cacheCompleteResponse && this.toCacheKey != null) {
  -                    os = new CachingOutputStream(environment.getOutputStream(
  -                            this.outputBufferSize));
  +                    os = new CachingOutputStream(
  +                            environment.getOutputStream(this.outputBufferSize));
                   }
                   if (super.serializer != super.lastConsumer) {
                       if (os == null) {
  @@ -225,14 +223,12 @@
                               os = environment.getOutputStream(0);
                           }
                           // set the output stream
  -                        ByteArrayOutputStream baos =
  -                            new ByteArrayOutputStream();
  +                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                           this.serializer.setOutputStream(baos);
  -    
  +
                           // execute the pipeline:
                           if ( this.xmlDeserializer != null ) {
  -                            this.xmlDeserializer.deserialize(
  -                                    this.cachedResponse);
  +                            this.xmlDeserializer.deserialize(this.cachedResponse);
                           } else {
                               this.generator.generate();
                           }
  @@ -240,20 +236,19 @@
                           baos.writeTo(os);
                       } else {
                           if (os == null) {
  -                            os = environment.getOutputStream(
  -                                    this.outputBufferSize);
  +                            os = environment.getOutputStream(this.outputBufferSize);
                           }
                           // set the output stream
                           this.serializer.setOutputStream(os);
                           // execute the pipeline:
                           if (this.xmlDeserializer != null) {
  -                            this.xmlDeserializer.deserialize(
  -                                    this.cachedResponse);
  +                            this.xmlDeserializer.deserialize(this.cachedResponse);
                           } else {
                               this.generator.generate();
                           }
                       }
                   }
  +
                   //
                   // Now that we have processed the pipeline,
                   // we do the actual caching
  @@ -264,17 +259,14 @@
                   if (se.getMessage().indexOf("reset") > 0
                           || se.getMessage().indexOf("aborted") > 0
                           || se.getMessage().indexOf("connection abort") > 0) {
  -                    throw new ConnectionResetException(
  -                            "Connection reset by peer", se);
  -                } else {
  -                    throw new ProcessingException(
  -                            "Failed to execute pipeline.", se);
  +                    throw new ConnectionResetException("Connection reset by peer", se);
                   }
  +
  +                throw new ProcessingException("Failed to execute pipeline.", se);
               } catch (ProcessingException e) {
                   throw e;
               } catch (Exception e) {
  -                throw new ProcessingException(
  -                        "Failed to execute pipeline.", e);
  +                throw new ProcessingException("Failed to execute pipeline.", e);
               }
               return true;
           }
  @@ -318,7 +310,7 @@
   
               while (this.firstNotCacheableTransformerIndex < transformerSize
                       && continueTest) {
  -                final Transformer trans = 
  +                final Transformer trans =
                       (Transformer)super.transformers.get(
                               this.firstNotCacheableTransformerIndex);
                   key = null;
  @@ -338,7 +330,7 @@
                       continueTest = false;
                   }
               }
  -            // all transformers are cacheable => pipeline is cacheable 
  +            // all transformers are cacheable => pipeline is cacheable
               // test serializer if this is not an internal request
               if (this.firstNotCacheableTransformerIndex == transformerSize
                   && super.serializer == this.lastConsumer) {
  @@ -368,10 +360,10 @@
               // only update validity objects if we cannot use
               // a cached response or when the cached response does
               // cache less than now is cacheable
  -            if (this.fromCacheKey == null 
  +            if (this.fromCacheKey == null
                   || this.fromCacheKey.size() < this.toCacheKey.size()) {
   
  -                this.toCacheSourceValidities = 
  +                this.toCacheSourceValidities =
                       new SourceValidity[this.toCacheKey.size()];
                   int len = this.toCacheSourceValidities.length;
                   int i = 0;
  @@ -380,7 +372,7 @@
                           this.getValidityForInternalPipeline(i);
   
                       if (validity == null) {
  -                        if (i > 0 
  +                        if (i > 0
                               && (this.fromCacheKey == null
                                       || i > this.fromCacheKey.size())) {
                               // shorten key
  @@ -417,21 +409,21 @@
       }
   
       /**
  -     * Calculate the key that can be used to get something from the cache, and 
  +     * Calculate the key that can be used to get something from the cache, and
        * handle expires properly.
  -     * 
  +     *
        */
       protected void validatePipeline(Environment environment)
       throws ProcessingException {
           this.completeResponseIsCached = this.cacheCompleteResponse;
  -        this.fromCacheKey = this.toCacheKey.copy();        
  +        this.fromCacheKey = this.toCacheKey.copy();
           this.firstProcessedTransformerIndex = this.firstNotCacheableTransformerIndex;
           this.cachedLastModified = 0L;
   
           boolean finished = false;
  -        
  +
           while (this.fromCacheKey != null && !finished) {
  -            
  +
               finished = true;
               final CachedResponse response = this.cache.get( this.fromCacheKey );
   
  @@ -439,7 +431,7 @@
               if (response != null) {
                   if (this.getLogger().isDebugEnabled()) {
                       this.getLogger().debug(
  -                        "Found cached response for '" + environment.getURI() + 
  +                        "Found cached response for '" + environment.getURI() +
                           "' using key: " + this.fromCacheKey
                       );
                   }
  @@ -475,27 +467,27 @@
                                   environment.getURI() +
                                   " regenerating content.");
                           }
  -                        
  +
                           // If an expires parameter was provided, use it. If this parameter is not available
                           // it means that the sitemap was modified, and the old expires value is not valid
                           // anymore.
                           if (expires != 0) {
                               if (this.getLogger().isDebugEnabled())
                                   this.getLogger().debug("Refreshing expires informations");
  -                            response.setExpires(new Long(expires + System.currentTimeMillis()));    
  +                            response.setExpires(new Long(expires + System.currentTimeMillis()));
                           } else {
                               if (this.getLogger().isDebugEnabled())
                                   this.getLogger().debug("No expires defined anymore for this object, setting it to no expires");
                               response.setExpires(null);
  -                        }                                   
  +                        }
                       }
                   } else {
                       // The response had no expires informations. See if it needs to be set (i.e. because the configuration has changed)
                       if (expires != 0) {
                           if (this.getLogger().isDebugEnabled())
                               this.getLogger().debug("Setting a new expires object for this resource");
  -                        response.setExpires(new Long(expires + System.currentTimeMillis()));                                
  -                    }        
  +                        response.setExpires(new Long(expires + System.currentTimeMillis()));
  +                    }
                   }
   
                   SourceValidity[] fromCacheValidityObjects = response.getValidityObjects();
  @@ -508,7 +500,7 @@
                       SourceValidity validity = fromCacheValidityObjects[i];
                       int valid = validity != null ? validity.isValid() : -1;
                       if ( valid == 0) { // don't know if valid, make second test
  -                       
  +
                           validity = this.getValidityForInternalPipeline(i);
   
                           if (validity != null) {
  @@ -586,15 +578,15 @@
                       this.completeResponseIsCached = false;
                   }
               } else {
  -                
  +
                   // no cached response found
                   if (this.getLogger().isDebugEnabled()) {
                       this.getLogger().debug(
  -                        "Cached response not found for '" + environment.getURI() + 
  +                        "Cached response not found for '" + environment.getURI() +
                           "' using key: " +  this.fromCacheKey
                       );
                   }
  -               
  +
                   if (!this.doSmartCaching) {
                       // try a shorter key
                       if (this.fromCacheKey.size() > 1) {
  @@ -632,7 +624,7 @@
           if (this.toCacheKey != null) {
               this.validatePipeline(environment);
           }
  -        this.setupValidities();        
  +        this.setupValidities();
       }
   
       /**
  @@ -807,9 +799,9 @@
        */
       public SourceValidity getValidityForEventPipeline() {
           int vals = 0;
  -        
  +
           if ( null != this.toCacheKey
  -             && !this.cacheCompleteResponse 
  +             && !this.cacheCompleteResponse
                && this.firstNotCacheableTransformerIndex == super.transformers.size()) {
                vals = this.toCacheKey.size();
           } else if ( null != this.fromCacheKey
  @@ -832,19 +824,19 @@
        * @see org.apache.cocoon.components.pipeline.ProcessingPipeline#getKeyForEventPipeline()
        */
       public String getKeyForEventPipeline() {
  -        if ( null != this.toCacheKey 
  +        if ( null != this.toCacheKey
                && !this.cacheCompleteResponse
                && this.firstNotCacheableTransformerIndex == super.transformers.size()) {
                return String.valueOf(HashUtil.hash(this.toCacheKey.toString()));
           }
  -        if ( null != this.fromCacheKey 
  +        if ( null != this.fromCacheKey
                && !this.completeResponseIsCached
                && this.firstProcessedTransformerIndex == super.transformers.size()) {
               return String.valueOf(HashUtil.hash(this.fromCacheKey.toString()));
           }
           return null;
       }
  -    
  +
       SourceValidity getValidityForInternalPipeline(int index) {
           final SourceValidity validity;
   
  @@ -874,7 +866,7 @@
           }
           return validity;
       }
  -    
  +
       /**
        * Recyclable Interface
        */
  @@ -887,7 +879,7 @@
   
           this.fromCacheKey = null;
           this.cachedResponse = null;
  -        
  +
           this.toCacheKey = null;
           this.toCacheSourceValidities = null;
   
  @@ -900,12 +892,12 @@
   
       private final AbstractCachingProcessingPipeline pipeline;
       private final int index;
  -    
  +
       public DeferredPipelineValidity(AbstractCachingProcessingPipeline pipeline, int index) {
           this.pipeline = pipeline;
           this.index = index;
       }
  -    
  +
       /**
        * @see org.apache.excalibur.source.impl.validity.DeferredValidity#getValidity()
        */
  
  
  
  1.20      +154 -119  cocoon-2.1/src/java/org/apache/cocoon/components/source/SourceUtil.java
  
  Index: SourceUtil.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/source/SourceUtil.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SourceUtil.java	25 May 2004 14:24:01 -0000	1.19
  +++ SourceUtil.java	11 Jun 2004 20:32:20 -0000	1.20
  @@ -1,12 +1,12 @@
   /*
    * Copyright 1999-2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -80,119 +80,102 @@
       }
   
       /**
  -     * Generates SAX events from the given source
  -     * <b>NOTE</b> : if the implementation can produce lexical events, care should be taken
  -     * that <code>handler</code> can actually
  -     * directly implement the LexicalHandler interface!
  +     * Generates SAX events from the given source.
  +     *
  +     * <p><b>NOTE</b>: if the implementation can produce lexical events,
  +     * care should be taken that <code>handler</code> can actually
  +     * directly implement the LexicalHandler interface!</p>
  +     *
        * @param  source    the data
        * @throws ProcessingException if no suitable converter is found
        */
  -    static public void toSAX( Source source,
  -                              ContentHandler handler)
  +    static public void toSAX(Source source,
  +                             ContentHandler handler)
       throws SAXException, IOException, ProcessingException {
  -        toSAX(EnvironmentHelper.getSitemapServiceManager(), 
  +        toSAX(EnvironmentHelper.getSitemapServiceManager(),
                 source, null, handler);
       }
   
       /**
  -     * Generates SAX events from the given source
  -     * <b>NOTE</b> : if the implementation can produce lexical events, care should be taken
  -     * that <code>handler</code> can actually
  -     * directly implement the LexicalHandler interface!
  +     * Generates SAX events from the given source by using XMLizer.
  +     * Current sitemap manager will be used to lookup XMLizer.
  +     *
  +     * <p><b>NOTE</b>: if the implementation can produce lexical events,
  +     * care should be taken that <code>handler</code> can actually
  +     * directly implement the LexicalHandler interface!</p>
  +     *
        * @param  source    the data
        * @throws ProcessingException if no suitable converter is found
        */
  -    static public void toSAX( Source source,
  -                              String mimeTypeHint,
  -                              ContentHandler handler)
  +    static public void toSAX(Source source,
  +                             String mimeTypeHint,
  +                             ContentHandler handler)
       throws SAXException, IOException, ProcessingException {
  -        toSAX(EnvironmentHelper.getSitemapServiceManager(), 
  +        toSAX(EnvironmentHelper.getSitemapServiceManager(),
                 source, mimeTypeHint, handler);
       }
   
       /**
  -     * Generates SAX events from the given source
  -     * <b>NOTE</b> : if the implementation can produce lexical events, care should be taken
  -     * that <code>handler</code> can actually
  -     * directly implement the LexicalHandler interface!
  +     * Generates SAX events from the given source by using XMLizer.
  +     *
  +     * <p><b>NOTE</b>: if the implementation can produce lexical events,
  +     * care should be taken that <code>handler</code> can actually
  +     * directly implement the LexicalHandler interface!</p>
  +     *
        * @param  source    the data
        * @throws ProcessingException if no suitable converter is found
        */
  -    static public void toSAX( ServiceManager manager, 
  -                              Source source,
  -                              String mimeTypeHint,
  -                              ContentHandler handler)
  +    static public void toSAX(ServiceManager manager,
  +                             Source source,
  +                             String mimeTypeHint,
  +                             ContentHandler handler)
       throws SAXException, IOException, ProcessingException {
  -        if ( source instanceof XMLizable ) {
  -            ((XMLizable)source).toSAX( handler );
  +        if (source instanceof XMLizable) {
  +            ((XMLizable) source).toSAX(handler);
           } else {
               String mimeType = source.getMimeType();
  -            if ( null == mimeType) mimeType = mimeTypeHint;
  -            XMLizer xmlizer = null;
  -            try {
  -                xmlizer = (XMLizer) manager.lookup( XMLizer.ROLE);
  -                xmlizer.toSAX( source.getInputStream(),
  -                               mimeType,
  -                               source.getURI(),
  -                               handler );
  -            } catch (SourceException se) {
  -                throw SourceUtil.handle(se);
  -            } catch (ServiceException ce) {
  -                throw new ProcessingException("Exception during streaming source.", ce);
  -            } finally {
  -                manager.release( xmlizer );
  +            if (null == mimeType) {
  +                mimeType = mimeTypeHint;
               }
  -        }
  -    }
   
  -    /**
  -     * Generates SAX events from the given source by parsing it.
  -     * <b>NOTE</b> : if the implementation can produce lexical events, care should be taken
  -     * that <code>handler</code> can actually
  -     * directly implement the LexicalHandler interface!
  -     * @param  source    the data
  -     * @throws ProcessingException if no suitable converter is found
  -     */
  -    static public void parse( ServiceManager manager, 
  -                              Source source,
  -                              ContentHandler handler)
  -    throws SAXException, IOException, ProcessingException {
  -        if ( source instanceof XMLizable ) {
  -            ((XMLizable)source).toSAX( handler );
  -        } else {
  -            SAXParser parser = null;
  +            XMLizer xmlizer = null;
               try {
  -                parser = (SAXParser) manager.lookup( SAXParser.ROLE);
  -                parser.parse( getInputSource( source ), handler );
  -            } catch (SourceException se) {
  -                throw SourceUtil.handle(se);
  -            } catch (ServiceException ce) {
  -                throw new ProcessingException("Exception during parsing source.", ce);
  +                xmlizer = (XMLizer) manager.lookup(XMLizer.ROLE);
  +                xmlizer.toSAX(source.getInputStream(),
  +                              mimeType,
  +                              source.getURI(),
  +                              handler);
  +            } catch (SourceException e) {
  +                throw SourceUtil.handle(e);
  +            } catch (ServiceException e) {
  +                throw new ProcessingException("Exception during streaming source.", e);
               } finally {
  -                manager.release( parser );
  +                manager.release(xmlizer);
               }
           }
       }
   
       /**
  -     * Generates SAX events from the given source
  -     * <b>NOTE</b> : if the implementation can produce lexical events, care should be taken
  -     * that <code>handler</code> can actually
  -     * directly implement the LexicalHandler interface!
  -     * 
  +     * Generates SAX events from the given source with possible URL rewriting.
  +     *
  +     * <p><b>NOTE</b>: If the implementation can produce lexical events,
  +     * care should be taken that <code>handler</code> can actually
  +     * directly implement the LexicalHandler interface!</p>
  +     *
        * @param  source    the data
        * @throws ProcessingException if no suitable converter is found
        */
  -    static public void toSAX( Source         source,
  -                              ContentHandler   handler,
  -                              Parameters       typeParameters,
  -                              boolean         filterDocumentEvent)
  +    static public void toSAX(Source source,
  +                             ContentHandler handler,
  +                             Parameters typeParameters,
  +                             boolean filterDocumentEvent)
       throws SAXException, IOException, ProcessingException {
           // Test for url rewriting
           if (typeParameters != null
  -            && typeParameters.getParameter(URLRewriter.PARAMETER_MODE, null) != null) {
  +                && typeParameters.getParameter(URLRewriter.PARAMETER_MODE, null) != null) {
               handler = new URLRewriter(typeParameters, handler);
           }
  +
           String mimeTypeHint = null;
           if (typeParameters != null) {
               mimeTypeHint = typeParameters.getParameter("mime-type", mimeTypeHint);
  @@ -206,6 +189,37 @@
       }
   
       /**
  +     * Generates SAX events from the given source by parsing it.
  +     *
  +     * <p><b>NOTE</b>: If the implementation can produce lexical events,
  +     * care should be taken that <code>handler</code> can actually
  +     * directly implement the LexicalHandler interface!</p>
  +     *
  +     * @param  source    the data
  +     * @throws ProcessingException if no suitable converter is found
  +     */
  +    static public void parse(ServiceManager manager,
  +                             Source source,
  +                             ContentHandler handler)
  +    throws SAXException, IOException, ProcessingException {
  +        if (source instanceof XMLizable) {
  +            ((XMLizable) source).toSAX(handler);
  +        } else {
  +            SAXParser parser = null;
  +            try {
  +                parser = (SAXParser) manager.lookup(SAXParser.ROLE);
  +                parser.parse(getInputSource(source), handler);
  +            } catch (SourceException e) {
  +                throw SourceUtil.handle(e);
  +            } catch (ServiceException e) {
  +                throw new ProcessingException("Exception during parsing source.", e);
  +            } finally {
  +                manager.release(parser);
  +            }
  +        }
  +    }
  +
  +    /**
        * Generates a DOM from the given source
        * @param source The data
        *
  @@ -229,7 +243,7 @@
   
           return document;
       }
  -    
  +
       /**
        * Generates a DOM from the given source
        * @param source The data
  @@ -279,14 +293,13 @@
   
           return document;
       }
  -    
  +
       /**
  -     * Make a ProcessingException from a SourceException
  -     * If the exception is a SourceNotFoundException than a
  -     * ResourceNotFoundException is thrown
  +     * Make a ProcessingException from a SourceException.
  +     * If the exception is a SourceNotFoundException then a
  +     * ResourceNotFoundException is thrown.
        *
        * @param se Source exception
  -     *
        * @return Created processing exception.
        */
       static public ProcessingException handle(SourceException se) {
  @@ -298,13 +311,12 @@
       }
   
       /**
  -     * Make a ProcessingException from a SourceException
  -     * If the exception is a SourceNotFoundException than a
  -     * ResourceNotFoundException is thrown
  +     * Make a ProcessingException from a SourceException.
  +     * If the exception is a SourceNotFoundException then a
  +     * ResourceNotFoundException is thrown.
        *
        * @param message Additional exception message.
        * @param se Source exception.
  -     *
        * @return Created processing exception.
        */
       static public ProcessingException handle(String message,
  @@ -316,6 +328,31 @@
       }
   
       /**
  +     * Handle SAXException catched in Generator's generate method.
  +     *
  +     * @param source Generator's source
  +     * @param e SAXException happened in the generator's generate method.
  +     */
  +    static public void handleSAXException(String source, SAXException e)
  +    throws ProcessingException, IOException, SAXException {
  +        final Exception cause = e.getException();
  +        if (cause != null) {
  +            if (cause instanceof ProcessingException) {
  +                throw (ProcessingException)cause;
  +            }
  +            if (cause instanceof IOException) {
  +                throw (IOException)cause;
  +            }
  +            if (cause instanceof SAXException) {
  +                throw (SAXException)cause;
  +            }
  +            throw new ProcessingException("Could not read resource " +
  +                                          source, cause);
  +        }
  +        throw e;
  +    }
  +
  +    /**
        * Get an InputSource object
        *
        * @param source Source.
  @@ -354,33 +391,31 @@
        * @throws SAXException If a SAX exception occurs.
        * @throws SourceException If the source an exception throws.
        */
  -    static public Source getSource( String           uri,
  -                                    Parameters       typeParameters,
  -                                    SourceParameters resourceParameters,
  -                                    SourceResolver   resolver)
  +    static public Source getSource(String uri,
  +                                   Parameters typeParameters,
  +                                   SourceParameters resourceParameters,
  +                                   SourceResolver resolver)
       throws IOException, SAXException, SourceException {
   
           // first step: encode parameters which are already appended to the url
           int queryPos = uri.indexOf('?');
  -
  -        if (queryPos!=-1) {
  +        if (queryPos != -1) {
               String queryString = uri.substring(queryPos+1);
               SourceParameters queries = new SourceParameters(queryString);
   
               if (queries.hasParameters()) {
  -                StringBuffer buffer;
  -
  -                buffer = new StringBuffer(uri.substring(0, queryPos));
  -                String current;
  -                Iterator iter = queries.getParameterNames();
  +                StringBuffer buffer = new StringBuffer(uri.substring(0, queryPos));
                   char separator = '?';
  -                Iterator values;
   
  +                Iterator iter = queries.getParameterNames();
                   while (iter.hasNext()==true) {
  -                    current = (String) iter.next();
  -                    values = queries.getParameterValues(current);
  +                    String current = (String) iter.next();
  +                    Iterator values = queries.getParameterValues(current);
                       while (values.hasNext()) {
  -                        buffer.append(separator).append(current).append('=').append(org.apache.excalibur.source.SourceUtil.encode((String) values.next()));
  +                        buffer.append(separator)
  +                                .append(current)
  +                                .append('=')
  +                                .append(org.apache.excalibur.source.SourceUtil.encode((String) values.next()));
                           separator = '&';
                       }
                   }
  @@ -396,8 +431,8 @@
                   !resourceParameters.hasParameters())) {
               method = "GET";
           }
  -        if (uri.startsWith("cocoon:") && (resourceParameters!=null) &&
  -            resourceParameters.hasParameters()) {
  +        if (uri.startsWith("cocoon:") && resourceParameters != null &&
  +                resourceParameters.hasParameters()) {
               int pos = uri.indexOf(";jsessionid=");
   
               if (uri.startsWith("cocoon:")==false) {
  @@ -427,7 +462,7 @@
               String encoding = typeParameters.getParameter("encoding",
                    System.getProperties().getProperty("file.encoding", "ISO-8859-1"));
               if ( encoding != null && !"".equals(encoding) ) {
  -                resolverParameters.put(SourceResolver.URI_ENCODING, encoding);                
  +                resolverParameters.put(SourceResolver.URI_ENCODING, encoding);
               }
           }
           resolverParameters.put(SourceResolver.URI_PARAMETERS,
  @@ -507,7 +542,7 @@
                       props.put(OutputKeys.ENCODING, "ISO-8859-1");
   	                final String content = XMLUtils.serializeNode(frag, props);
   	                OutputStream oStream = ws.getOutputStream();
  -	
  +
   	                oStream.write(content.getBytes());
   	                oStream.flush();
   	                oStream.close();
  @@ -515,7 +550,7 @@
               } else {
               	String content;
   				if ( null != serializerName) {
  -                    
  +
                       ServiceManager manager = EnvironmentHelper.getSitemapServiceManager();
                       ServiceSelector selector = null;
                       Serializer serializer = null;
  @@ -549,7 +584,7 @@
                       props.put(OutputKeys.ENCODING, "ISO-8859-1");
                       content = XMLUtils.serializeNode(frag, props);
   				}
  -				
  +
                   if (parameters==null) {
                       parameters = new SourceParameters();
                   } else {
  @@ -618,8 +653,8 @@
       }
   
       /**
  -     * Return the scheme of a URI. Just as there are many different methods 
  -     * of access to resources, there are a variety of schemes for identifying 
  +     * Return the scheme of a URI. Just as there are many different methods
  +     * of access to resources, there are a variety of schemes for identifying
        * such resources.
        * (see <a href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a>).
        *
  @@ -660,8 +695,8 @@
       }
   
       /**
  -     * Return the path of a URI. The path contains data, specific to the 
  -     * authority (or the scheme if there is no authority component), 
  +     * Return the path of a URI. The path contains data, specific to the
  +     * authority (or the scheme if there is no authority component),
        * identifying the resource within the scope of that scheme and authority
        * (see <a href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a>).
        *
  @@ -681,7 +716,7 @@
       }
   
       /**
  -     * Return the path of a URI, if the URI can't contains a authority. 
  +     * Return the path of a URI, if the URI can't contains a authority.
        * This implementation differ to the RFC 2396.
        *
        * @param uri Uniform resource identifier.
  @@ -700,7 +735,7 @@
       }
   
       /**
  -     * Return the query of a URI. The query is a string of information to 
  +     * Return the query of a URI. The query is a string of information to
        * be interpreted by the resource
        * (see <a href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a>).
        *
  @@ -720,10 +755,10 @@
       }
   
       /**
  -     * Return the fragment of a URI. When a URI reference is used to perform 
  -     * a retrieval action on the identified resource, the optional fragment 
  -     * identifier, consists of additional reference information to be 
  -     * interpreted by the user agent after the retrieval action has been 
  +     * Return the fragment of a URI. When a URI reference is used to perform
  +     * a retrieval action on the identified resource, the optional fragment
  +     * identifier, consists of additional reference information to be
  +     * interpreted by the user agent after the retrieval action has been
        * successfully completed
        * (see <a href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a>).
        *
  
  
  
  1.9       +9 -24     cocoon-2.1/src/java/org/apache/cocoon/generation/FileGenerator.java
  
  Index: FileGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/FileGenerator.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FileGenerator.java	1 May 2004 18:06:12 -0000	1.8
  +++ FileGenerator.java	11 Jun 2004 20:32:20 -0000	1.9
  @@ -1,12 +1,12 @@
   /*
    * Copyright 1999-2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -33,13 +33,13 @@
    * The <code>FileGenerator</code> is a class that reads XML from a source
    * and generates SAX Events.
    * The FileGenerator implements the <code>CacheableProcessingComponent</code> interface.
  - * 
  + *
    * @cocoon.sitemap.component.name   file
    * @cocoon.sitemap.component.label  content
    * @cocoon.sitemap.component.logger sitemap.generator.file
    * @cocoon.sitemap.component.documentation.caching
    *               Uses the last modification date of the xml document for validation
  - * 
  + *
    * @cocoon.sitemap.component.pooling.min   8
    * @cocoon.sitemap.component.pooling.max  32
    * @cocoon.sitemap.component.pooling.grow  4
  @@ -72,7 +72,7 @@
        * Try to get the last modification date of the source for caching.
        */
       public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
  -        throws ProcessingException, SAXException, IOException {
  +    throws ProcessingException, SAXException, IOException {
   
           super.setup(resolver, objectModel, src, par);
           try {
  @@ -106,7 +106,7 @@
        * Generate XML data.
        */
       public void generate()
  -        throws IOException, SAXException, ProcessingException {
  +    throws IOException, SAXException, ProcessingException {
   
           try {
               if (getLogger().isDebugEnabled()) {
  @@ -114,23 +114,8 @@
                                     " resolved to " + this.inputSource.getURI());
               }
               SourceUtil.parse(this.manager, this.inputSource, super.xmlConsumer);
  -
           } catch (SAXException e) {
  -            final Exception cause = e.getException();
  -            if (cause != null) {
  -                if (cause instanceof ProcessingException) {
  -                    throw (ProcessingException)cause;
  -                }
  -                if (cause instanceof IOException) {
  -                    throw (IOException)cause;
  -                }
  -                if (cause instanceof SAXException) {
  -                    throw (SAXException)cause;
  -                }
  -                throw new ProcessingException("Could not read resource " +
  -                                              this.inputSource.getURI(), cause);
  -            }
  -            throw e;
  +            SourceUtil.handleSAXException(this.inputSource.getURI(), e);
           }
       }
   }
  
  
  
  1.11      +71 -69    cocoon-2.1/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
  
  Index: CIncludeTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- CIncludeTransformer.java	17 Mar 2004 11:50:21 -0000	1.10
  +++ CIncludeTransformer.java	11 Jun 2004 20:32:20 -0000	1.11
  @@ -1,12 +1,12 @@
   /*
    * Copyright 1999-2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -76,14 +76,14 @@
    *         <!-- more can follow -->
    *     </cinclude:parameters>
    * </cinclude:includexml>
  - * 
  + *
    *
    * This transformer also supports caching of the included content.
    * Therefore it triggers for the element <code>cached-include</code> in the
    * namespace "http://apache.org/cocoon/include/1.0".
    * The <code>src</code> attribute contains the url which points to
    * an xml resource which is include instead of the element.
  - * First, it works like the usual include command. But it can be 
  + * First, it works like the usual include command. But it can be
    * configured with various parameters:
    * The most important one is the <code>expires</code> parameter.
    * If (and only if) this is set to a value greater than zero,
  @@ -102,18 +102,18 @@
    * in a series.
    * With the optional parameter <code>preemptive</code> set to <code>true</code>
    * a pre-emptive caching is activated. When a resource is requested with
  - * pre-emptive caching, this transformer always attempts to get the 
  + * pre-emptive caching, this transformer always attempts to get the
    * content from the cache. If the content is not in the cache, it is
    * of course retrieved from the original source and cached.
    * If the cached resource has expired, it is still provided. The cache
    * is updated by a background task. This task has to be started
    * beforehand.
  - * 
  + *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @author <a href="mailto:acoliver@apache.org">Andrew C. Oliver</a>
    * @version CVS $Id$
    */
  -public class CIncludeTransformer 
  +public class CIncludeTransformer
   extends AbstractSAXTransformer
   implements Disposable, CacheableProcessingComponent {
   
  @@ -142,30 +142,30 @@
   
       /** The configuration of includexml */
       protected Parameters configurationParameters;
  -    
  +
       /** The parameters for includexml */
       protected SourceParameters resourceParameters;
  -    
  +
       /** The current state: STATE_ */
       protected int state;
  -    
  +
       protected IncludeCacheManager cacheManager;
   
       protected IncludeCacheManagerSession cachingSession;
   
       protected boolean compiling;
  -    
  +
       protected IncludeXMLConsumer filter;
  -    
  +
       protected XMLSerializer recorder;
  -    
  +
       protected AttributesImpl srcAttributes = new AttributesImpl();
  -    
  +
       protected boolean supportCaching;
  -    
  +
       /** Remember the start time of the request for profiling */
       protected long startTime;
  -    
  +
      /**
        * Constructor
        * Set the namespace
  @@ -173,7 +173,7 @@
       public CIncludeTransformer() {
           this.namespaceURI = CINCLUDE_NAMESPACE_URI;
       }
  -    
  +
       /**
        * Setup the component.
        */
  @@ -198,10 +198,11 @@
        */
       public void service(ServiceManager manager) throws ServiceException {
           super.service(manager);
  -        if ( this.manager.hasService( IncludeCacheManager.ROLE )) {
  -            this.cacheManager = (IncludeCacheManager) this.manager.lookup( IncludeCacheManager.ROLE );
  +        if (this.manager.hasService(IncludeCacheManager.ROLE)) {
  +            this.cacheManager = (IncludeCacheManager) this.manager.lookup(IncludeCacheManager.ROLE);
           } else {
  -            this.getLogger().warn("The cinclude transformer cannot find the IncludeCacheManager. Therefore caching is turned off for the include transformer.");
  +            getLogger().warn("The cinclude transformer cannot find the IncludeCacheManager. " +
  +                             "Therefore caching is turned off for the include transformer.");
           }
       }
   
  @@ -230,8 +231,9 @@
           super.recycle();
           this.configurationParameters = null;
           this.resourceParameters = null;
  -        if (this.getLogger().isErrorEnabled()) {
  -            this.getLogger().debug("Finishing CachingCIncludeTransformer, time: " + (System.currentTimeMillis() - this.startTime));
  +        if (getLogger().isErrorEnabled()) {
  +            getLogger().debug("Finishing CachingCIncludeTransformer, time: " +
  +                              (System.currentTimeMillis() - this.startTime));
               this.startTime = 0;
           }
           this.filter = null;
  @@ -249,7 +251,7 @@
                                           false);
   
           // Element: include
  -        } else if (name.equals(CINCLUDE_INCLUDEXML_ELEMENT) 
  +        } else if (name.equals(CINCLUDE_INCLUDEXML_ELEMENT)
                      && this.state == STATE_OUTSIDE) {
               this.state = STATE_INCLUDE;
               String ignoreErrors = attr.getValue("", CINCLUDE_INCLUDEXML_ELEMENT_IGNORE_ERRORS_ATTRIBUTE);
  @@ -264,26 +266,26 @@
               this.ignoreWhitespaces = true;
   
           // target
  -        } else if (name.equals(CINCLUDE_SRC_ELEMENT) 
  +        } else if (name.equals(CINCLUDE_SRC_ELEMENT)
                      && this.state == STATE_INCLUDE) {
               this.startTextRecording();
   
           // configparameters
  -        } else if (name.equals(CINCLUDE_CONFIGURATION_ELEMENT) 
  +        } else if (name.equals(CINCLUDE_CONFIGURATION_ELEMENT)
                      && this.state == STATE_INCLUDE) {
               stack.push("end");
   
           // parameters
  -        } else if (name.equals(CINCLUDE_PARAMETERS_ELEMENT) 
  +        } else if (name.equals(CINCLUDE_PARAMETERS_ELEMENT)
                      && this.state == STATE_INCLUDE) {
               stack.push("end");
   
           // parameter
  -        } else if (name.equals(CINCLUDE_PARAMETER_ELEMENT) 
  +        } else if (name.equals(CINCLUDE_PARAMETER_ELEMENT)
                      && this.state == STATE_INCLUDE) {
   
           // parameter name
  -        } else if (name.equals(CINCLUDE_NAME_ELEMENT) 
  +        } else if (name.equals(CINCLUDE_NAME_ELEMENT)
                      && this.state == STATE_INCLUDE) {
               this.startTextRecording();
   
  @@ -302,32 +304,32 @@
                                                       this.cacheManager != null);
              if (this.compiling) {
                  this.srcAttributes.addAttribute("", CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE, CINCLUDE_SRC_ELEMENT, "CDATA", src);
  -               super.startTransformingElement(uri, 
  -                                              CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT, 
  -                                              raw+"p", 
  +               super.startTransformingElement(uri,
  +                                              CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT,
  +                                              raw + "p",
                                                 this.srcAttributes);
  -               this.srcAttributes.clear();                                               
  +               this.srcAttributes.clear();
              }
           } else {
               super.startTransformingElement(uri, name, raw, attr);
           }
       }
   
  -    public void endTransformingElement(String uri, String name, String raw) 
  +    public void endTransformingElement(String uri, String name, String raw)
       throws ProcessingException, IOException, SAXException {
           if (name.equals(CINCLUDE_INCLUDE_ELEMENT)) {
               // do nothing
               return;
   
  -       // Element: includexml
           } else if (name.equals(CINCLUDE_INCLUDEXML_ELEMENT)
                      && this.state == STATE_INCLUDE) {
  -                    
  +            // Element: includexml
  +
               this.state = STATE_OUTSIDE;
   
               final String resource = (String)stack.pop();
   
  -            final boolean ignoreErrors = ((String)stack.pop()).equals("true");
  +            final boolean ignoreErrors = stack.pop().equals("true");
   
               if (this.getLogger().isDebugEnabled()) {
                   getLogger().debug("Processing CIncludexml element: src=" + resource
  @@ -336,13 +338,13 @@
                                 + ", parameters=" + this.resourceParameters);
               }
               Source source = null;
  -            
  +
               try {
  -                source = SourceUtil.getSource(resource, 
  -                                              this.configurationParameters, 
  +                source = SourceUtil.getSource(resource,
  +                                              this.configurationParameters,
                                                 this.resourceParameters,
                                                 this.resolver);
  -                                              
  +
                   XMLSerializer serializer = null;
                   XMLDeserializer deserializer = null;
                   try {
  @@ -361,7 +363,7 @@
                   } finally {
                       this.manager.release( serializer );
                       this.manager.release( deserializer );
  -                }               
  +                }
               } catch (SourceException se) {
                   if (!ignoreErrors) throw SourceUtil.handle(se);
               } catch (SAXException se) {
  @@ -379,7 +381,7 @@
           // src element
           } else if (name.equals(CINCLUDE_SRC_ELEMENT)
                      && this.state == STATE_INCLUDE) {
  -                   
  +
               this.stack.push(this.endTextRecording());
   
           } else if (name.equals(CINCLUDE_PARAMETERS_ELEMENT)
  @@ -420,7 +422,7 @@
   
           } else if (name.equals(CINCLUDE_PARAMETER_ELEMENT) == true
                      && this.state == STATE_INCLUDE) {
  -            
  +
           } else if (name.equals(CINCLUDE_NAME_ELEMENT) == true
                      && this.state == STATE_INCLUDE) {
               stack.push(this.endTextRecording());
  @@ -434,9 +436,9 @@
   
           } else if (name.equals(CINCLUDE_CACHED_INCLUDE_ELEMENT)) {
               if (this.compiling) {
  -               super.endTransformingElement(uri, 
  +               super.endTransformingElement(uri,
                                               CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT,
  -                                            raw+"p");
  +                                            raw + "p");
               }
               // do nothing else
           } else {
  @@ -444,7 +446,7 @@
           }
       }
   
  -    protected String processCIncludeElement(String src, String element, 
  +    protected String processCIncludeElement(String src, String element,
                                               String select, String ns, String prefix,
                                               boolean cache)
       throws SAXException, IOException {
  @@ -478,7 +480,7 @@
               } else {
                   this.cacheManager.stream(src, this.cachingSession, this.filter);
               }
  -        
  +
               return src;
           }
   
  @@ -500,10 +502,10 @@
   
               if (!"".equals(select)) {
   
  -                
  +
                   DOMParser parser = null;
                   XPathProcessor processor = null;
  -                
  +
                   try {
                       parser = (DOMParser)this.manager.lookup(DOMParser.ROLE);
                       processor = (XPathProcessor)this.manager.lookup(XPathProcessor.ROLE);
  @@ -515,7 +517,7 @@
                       int length = list.getLength();
                       for (int i=0; i<length; i++) {
                             IncludeXMLConsumer.includeNode(list.item(i),
  -                                               this,  
  +                                               this,
                                                  this);
                       }
                   } finally {
  @@ -525,7 +527,7 @@
               } else {
                   String mimeType = null;
                   if ( null != this.configurationParameters ) {
  -                    mimeType = this.configurationParameters.getParameter("mime-type", mimeType);                    
  +                    mimeType = this.configurationParameters.getParameter("mime-type", mimeType);
                   }
                   if ( this.compiling ) {
                       SourceUtil.toSAX(source, mimeType, new IncludeXMLConsumer(this.contentHandler, this.lexicalHandler));
  @@ -555,7 +557,7 @@
           }
           return src;
       }
  -    
  +
       /**
        * Start recording of compiled xml.
        * The incomming SAX events are recorded and a compiled representation
  @@ -570,9 +572,9 @@
   
           try {
               this.recorder = (XMLSerializer)this.manager.lookup(XMLSerializer.ROLE);
  -            
  +
               this.addRecorder(recorder);
  -  
  +
           } catch (ServiceException ce) {
               throw new SAXException("Unable to lookup xml serializer for compiling xml.", ce);
           }
  @@ -592,7 +594,7 @@
           }
   
           XMLSerializer recorder = (XMLSerializer)this.removeRecorder();
  -        Object text = (byte[])recorder.getSAXFragment();
  +        Object text = recorder.getSAXFragment();
   
           if (this.getLogger().isDebugEnabled()) {
               this.getLogger().debug("END endCompiledXMLRecording text="+text);
  @@ -607,7 +609,7 @@
           this.filter = new MyFilter(this.xmlConsumer, this);
           super.startDocument();
       }
  -    
  +
       /**
        * @see org.xml.sax.ContentHandler#endDocument()
        */
  @@ -632,8 +634,8 @@
        * @see org.apache.cocoon.caching.CacheableProcessingComponent#getKey()
        */
       public Serializable getKey() {
  -        if (this.supportCaching 
  -            && null != this.cacheManager 
  +        if (this.supportCaching
  +            && null != this.cacheManager
               && this.cachingSession.getExpires() > 0) {
               return "1";
           }
  @@ -644,7 +646,7 @@
        * @see org.apache.cocoon.caching.CacheableProcessingComponent#getValidity()
        */
       public SourceValidity getValidity() {
  -        if (this.supportCaching 
  +        if (this.supportCaching
               && null != this.cacheManager
               && this.cachingSession.getExpires() > 0
               && !this.cachingSession.isPurging()) {
  @@ -652,13 +654,13 @@
           }
           return null;
       }
  -    
  +
   }
   
   final class MyFilter extends IncludeXMLConsumer {
   
       private CIncludeTransformer transformer;
  -    
  +
       /**
        * This filter class post-processes the parallel fetching
        * @param consumer
  @@ -667,17 +669,17 @@
           super(consumer);
           this.transformer = transformer;
       }
  -    
  -    
  +
  +
       public void endElement(String uri, String local, String qName)
       throws SAXException {
  -        if (uri != null 
  +        if (uri != null
               && uri.equals(CIncludeTransformer.CINCLUDE_NAMESPACE_URI)
               && local.equals(CIncludeTransformer.CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT)) {
               // this is the placeholder element: do nothing
           } else {
               super.endElement(uri, local, qName);
  -        }        
  +        }
       }
   
       public void startElement(String uri,
  @@ -685,7 +687,7 @@
                                   String qName,
                                   Attributes attr)
       throws SAXException {
  -        if (uri != null 
  +        if (uri != null
               && uri.equals(CIncludeTransformer.CINCLUDE_NAMESPACE_URI)
               && local.equals(CIncludeTransformer.CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT)) {
               // this is a placeholder
  @@ -697,7 +699,7 @@
               }
           } else {
               super.startElement(uri, local, qName, attr);
  -        }        
  +        }
       }
   
   }
  
  
  

Mime
View raw message