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

cvs commit: xml-cocoon/src/org/apache/cocoon/util HashUtil.java

cziegeler    01/04/11 03:53:11

  Modified:    src/org/apache/cocoon Tag: xml-cocoon2 Roles.java
                        cocoon.roles
               src/org/apache/cocoon/components/pipeline Tag: xml-cocoon2
                        NonCachingEventPipeline.java
               src/org/apache/cocoon/generation Tag: xml-cocoon2
                        FileGenerator.java
               src/org/apache/cocoon/transformation Tag: xml-cocoon2
                        Transformer.java TraxTransformer.java
  Added:       src/org/apache/cocoon/caching Tag: xml-cocoon2
                        CacheValidity.java Cacheable.java CachedObject.java
                        ComponentCacheKey.java EventCache.java
                        EventMemoryCache.java PipelineCacheKey.java
                        TimeStampCacheValidity.java
               src/org/apache/cocoon/components/pipeline Tag: xml-cocoon2
                        AbstractEventPipeline.java
                        CachingEventPipeline.java
               src/org/apache/cocoon/components/sax Tag: xml-cocoon2
                        CompiledXMLInputStream.java
                        CompiledXMLOutputStream.java FastInputStream.java
                        XMLByteStreamCompiler.java
                        XMLByteStreamInterpreter.java XMLDeserializer.java
                        XMLSerializer.java XMLTeePipe.java
               src/org/apache/cocoon/util Tag: xml-cocoon2 HashUtil.java
  Log:
  The first caching implementation with Cacheable FileGenerator and TraxTransformer
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.11  +6 -1      xml-cocoon/src/org/apache/cocoon/Attic/Roles.java
  
  Index: Roles.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/Roles.java,v
  retrieving revision 1.1.2.10
  retrieving revision 1.1.2.11
  diff -u -r1.1.2.10 -r1.1.2.11
  --- Roles.java	2001/04/05 15:18:42	1.1.2.10
  +++ Roles.java	2001/04/11 10:52:00	1.1.2.11
  @@ -12,7 +12,7 @@
    * Created this interface to specify the Avalon role names.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.1.2.10 $ $Date: 2001/04/05 15:18:42 $
  + * @version CVS $Revision: 1.1.2.11 $ $Date: 2001/04/11 10:52:00 $
    */
   
   public interface Roles {
  @@ -43,4 +43,9 @@
   
       String EVENT_PIPELINE       = "org.apache.cocoon.components.pipeline.EventPipeline";
       String STREAM_PIPELINE      = "org.apache.cocoon.components.pipeline.StreamPipeline";
  +
  +    String XML_SERIALIZER = "org.apache.cocoon.components.sax.XMLSerializer";
  +    String XML_DESERIALIZER = "org.apache.cocoon.components.sax.XMLDeserializer";
  +    String EVENT_CACHE = "org.apache.cocoon.caching.EventCache";
  +
   }
  
  
  
  1.1.2.2   +12 -0     xml-cocoon/src/org/apache/cocoon/Attic/cocoon.roles
  
  Index: cocoon.roles
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/cocoon.roles,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- cocoon.roles	2001/04/10 17:09:03	1.1.2.1
  +++ cocoon.roles	2001/04/11 10:52:02	1.1.2.2
  @@ -94,4 +94,16 @@
          shorthand="reader"
          default-class="org.apache.cocoon.sitemap.SitemapComponentSelector"/>
   
  +<role name="org.apache.cocoon.components.sax.XMLSerializer"
  +       shorthand="xml-serializer"
  +       default-class="org.apache.cocoon.components.sax.XMLByteStreamCompiler"/>
  +
  + <role name="org.apache.cocoon.components.sax.XMLDeserializer"
  +       shorthand="xml-deserializer"
  +       default-class="org.apache.cocoon.components.sax.XMLByteStreamInterpreter"/>
  +
  +<role name="org.apache.cocoon.caching.EventCache"
  +       shorthand="event-cache"
  +       default-class="org.apache.cocoon.caching.EventMemoryCache"/>
  +
   </role-list>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +27 -0     xml-cocoon/src/org/apache/cocoon/caching/Attic/CacheValidity.java
  
  
  
  
  1.1.2.1   +35 -0     xml-cocoon/src/org/apache/cocoon/caching/Attic/Cacheable.java
  
  
  
  
  1.1.2.1   +56 -0     xml-cocoon/src/org/apache/cocoon/caching/Attic/CachedObject.java
  
  
  
  
  1.1.2.1   +53 -0     xml-cocoon/src/org/apache/cocoon/caching/Attic/ComponentCacheKey.java
  
  
  
  
  1.1.2.1   +22 -0     xml-cocoon/src/org/apache/cocoon/caching/Attic/EventCache.java
  
  
  
  
  1.1.2.1   +23 -0     xml-cocoon/src/org/apache/cocoon/caching/Attic/EventMemoryCache.java
  
  
  
  
  1.1.2.1   +45 -0     xml-cocoon/src/org/apache/cocoon/caching/Attic/PipelineCacheKey.java
  
  
  
  
  1.1.2.1   +41 -0     xml-cocoon/src/org/apache/cocoon/caching/Attic/TimeStampCacheValidity.java
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +2 -215    xml-cocoon/src/org/apache/cocoon/components/pipeline/Attic/NonCachingEventPipeline.java
  
  Index: NonCachingEventPipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/pipeline/Attic/NonCachingEventPipeline.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- NonCachingEventPipeline.java	2001/04/09 21:25:54	1.1.2.2
  +++ NonCachingEventPipeline.java	2001/04/11 10:52:34	1.1.2.3
  @@ -36,225 +36,12 @@
   
   /**
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.2.2 $ $Date: 2001/04/09 21:25:54 $
  + * @version CVS $Revision: 1.1.2.3 $ $Date: 2001/04/11 10:52:34 $
    */
  -public class NonCachingEventPipeline extends AbstractXMLProducer implements EventPipeline {
  -    private Generator generator;
  -    private Parameters generatorParam;
  -    private String generatorSource;
  -    private ArrayList transformers = new ArrayList();
  -    private ArrayList transformerParams = new ArrayList();
  -    private ArrayList transformerSources = new ArrayList();
  -    private ArrayList connectors = new ArrayList();
  +public class NonCachingEventPipeline extends AbstractEventPipeline {
   
  -    /** the component manager */
  -    private ComponentManager manager;
  -
  -    public void compose (ComponentManager manager) {
  -        this.manager = manager;
  -    }
  -
  -    public void setGenerator (String role, String source, Parameters param, Exception e)
  -    throws Exception {
  -        this.setGenerator (role, source, param);
  -        // FIXME(CZ) What can be done if this is not an ErrorNotifier?
  -        // (The sitemap uses this setGenerator() method only from inside
  -        // the error pipeline, when a ErrorNotifier is explicitly generated.)
  -        if (this.generator instanceof ErrorNotifier) {
  -            ((ErrorNotifier)this.generator).setException(e);
  -        }
  -    }
  -
  -    public void setGenerator (String role, String source, Parameters param)
  -    throws Exception {
  -        if (this.generator != null) {
  -            throw new ProcessingException ("Generator already set. You can only select one Generator (" + role + ")");
  -        }
  -        ComponentSelector selector = (ComponentSelector) this.manager.lookup(Roles.GENERATORS);
  -        this.generator = (Generator) selector.select(role);
  -        this.generatorSource = source;
  -        this.generatorParam = param;
  -    }
  -
  -    public void addTransformer (String role, String source, Parameters param)
  -    throws Exception {
  -        ComponentSelector selector = (ComponentSelector) this.manager.lookup(Roles.TRANSFORMERS);
  -        this.transformers.add ((Transformer)selector.select(role));
  -        this.transformerSources.add (source);
  -        this.transformerParams.add (param);
  -    }
  -
  -    public boolean process(Environment environment) throws Exception {
  -        if ( !checkPipeline() ) {
  -            throw new ProcessingException("Attempted to process incomplete pipeline.");
  -        }
  -        
  -        setupPipeline(environment);
  -        connectPipeline(environment);
  -
  -        // execute the pipeline:
  -        try {
  -            this.generator.generate();
  -        } catch ( Exception e ) {
  -            throw new ProcessingException(
  -                "Failed to execute pipeline.",
  -                e
  -            );
  -        }
  -        return true;
  -    }
  -
  -    /** Sanity check the non-reader pipeline.
  -     * @return true if the pipeline is 'sane', false otherwise.
  -     */
  -    private boolean checkPipeline() {
  -        if ( this.generator == null ) {
  -            return false;
  -        }
  -
  -        Iterator itt = this.transformers.iterator();
  -        while ( itt.hasNext() ) {
  -            if ( itt.next() == null) {
  -                return false;
  -            }
  -        }
  -
  -        if (super.xmlConsumer == null) {
  -            return false;
  -        }
  -        return true;
  -    }
  -
  -    /** Setup pipeline components.
  -     */
  -    private void setupPipeline(Environment environment)
  -    throws ProcessingException {
  -        try {
  -            // setup the generator
  -            this.generator.setup(
  -                (EntityResolver)environment,
  -                environment.getObjectModel(),
  -                generatorSource,
  -                generatorParam
  -            );
  -
  -            Iterator transformerItt = this.transformers.iterator();
  -            Iterator transformerSourceItt = this.transformerSources.iterator();
  -            Iterator transformerParamItt = this.transformerParams.iterator();
  -
  -            while ( transformerItt.hasNext() ) {
  -                Transformer trans = (Transformer)transformerItt.next();
  -                trans.setup(
  -                    (EntityResolver)environment,
  -                    environment.getObjectModel(),
  -                    (String)transformerSourceItt.next(),
  -                    (Parameters)transformerParamItt.next()
  -                );
  -            }
  -        } catch (SAXException e) {
  -            throw new ProcessingException(
  -                "Could not setup pipeline.",
  -                e
  -            );
  -        } catch (IOException e) {
  -            throw new ProcessingException(
  -                "Could not setup pipeline.",
  -                e
  -            );
  -        }
  -
  -
  -    }
  -
  -    /** Connect the pipeline.
  -     */
  -    private void connectPipeline(Environment environment) throws ProcessingException {
  -        XMLProducer prev = (XMLProducer) this.generator;
  -        XMLConsumer next;
  -
  -        try {
  -            Iterator itt = this.transformers.iterator();
  -            while ( itt.hasNext() ) {
  -                // connect SAXConnector
  -                SAXConnector connect = (SAXConnector) this.manager.lookup(Roles.SAX_CONNECTOR);
  -                connect.setup((EntityResolver)environment,environment.getObjectModel(),null,null);
  -                this.connectors.add(connect);
  -                next = (XMLConsumer) connect;
  -                prev.setConsumer(next);
  -                prev = (XMLProducer) connect;
  -
  -                // Connect next component.
  -                Transformer trans = (Transformer) itt.next();
  -                next = (XMLConsumer) trans;
  -                prev.setConsumer(next);
  -                prev = (XMLProducer) trans;
  -            }
  -
  -            // insert SAXConnector
  -            SAXConnector connect = (SAXConnector) this.manager.lookup(Roles.SAX_CONNECTOR);
  -            this.connectors.add(connect);
  -            next = (XMLConsumer) connect;
  -            prev.setConsumer(next);
  -            prev = (XMLProducer) connect;
  -
  -            // insert this consumer
  -            prev.setConsumer(super.xmlConsumer);
  -        } catch ( IOException e ) {
  -            throw new ProcessingException(
  -                "Could not connect pipeline.",
  -                e
  -            );
  -        } catch ( SAXException e ) {
  -            throw new ProcessingException(
  -                "Could not connect pipeline.",
  -                e
  -            );
  -        } catch ( ComponentManagerException e ) {
  -            throw new ProcessingException(
  -                "Could not connect pipeline.",
  -                e
  -            );
  -        }
  -
  -    }
  -
       public void recycle() {
           getLogger().debug("Recycling of NonCachingEventPipeline");
  -
           super.recycle();
  -        try {
  -            // release generator
  -            if ( this.generator != null ) {
  -                ((ComponentSelector) this.manager.lookup(Roles.GENERATORS))
  -                    .release(this.generator);
  -            }
  -            this.generator = null;
  -
  -            // Release transformers
  -            ComponentSelector transformerSelector;
  -            transformerSelector = (ComponentSelector)this.manager.lookup(Roles.TRANSFORMERS);
  -            Iterator itt = this.transformers.iterator();
  -            while ( itt.hasNext() ) {
  -                transformerSelector.release((Component)itt.next());
  -            }
  -            this.transformers.clear();
  -            this.transformerParams.clear();
  -            this.transformerSources.clear();
  -
  -            // Release connectors
  -            Iterator itc = this.connectors.iterator();
  -            while ( itc.hasNext() ) {
  -                this.manager.release((Component) itc.next());
  -            }
  -            this.connectors.clear();
  -        } catch ( ComponentManagerException e ) {
  -            getLogger().warn(
  -                "Failed to release components from non caching event pipeline.",
  -                e
  -            );
  -        } finally {
  -            this.generator = null;
  -            this.transformers.clear();
  -        }
       }
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +263 -0    xml-cocoon/src/org/apache/cocoon/components/pipeline/Attic/AbstractEventPipeline.java
  
  
  
  
  1.1.2.1   +301 -0    xml-cocoon/src/org/apache/cocoon/components/pipeline/Attic/CachingEventPipeline.java
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +139 -0    xml-cocoon/src/org/apache/cocoon/components/sax/Attic/CompiledXMLInputStream.java
  
  
  
  
  1.1.2.1   +100 -0    xml-cocoon/src/org/apache/cocoon/components/sax/Attic/CompiledXMLOutputStream.java
  
  
  
  
  1.1.2.1   +116 -0    xml-cocoon/src/org/apache/cocoon/components/sax/Attic/FastInputStream.java
  
  
  
  
  1.1.2.1   +277 -0    xml-cocoon/src/org/apache/cocoon/components/sax/Attic/XMLByteStreamCompiler.java
  
  
  
  
  1.1.2.1   +124 -0    xml-cocoon/src/org/apache/cocoon/components/sax/Attic/XMLByteStreamInterpreter.java
  
  
  
  
  1.1.2.1   +38 -0     xml-cocoon/src/org/apache/cocoon/components/sax/Attic/XMLDeserializer.java
  
  
  
  
  1.1.2.1   +30 -0     xml-cocoon/src/org/apache/cocoon/components/sax/Attic/XMLSerializer.java
  
  
  
  
  1.1.2.1   +175 -0    xml-cocoon/src/org/apache/cocoon/components/sax/Attic/XMLTeePipe.java
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.26  +57 -14    xml-cocoon/src/org/apache/cocoon/generation/Attic/FileGenerator.java
  
  Index: FileGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/generation/Attic/FileGenerator.java,v
  retrieving revision 1.1.2.25
  retrieving revision 1.1.2.26
  diff -u -r1.1.2.25 -r1.1.2.26
  --- FileGenerator.java	2001/03/19 21:20:32	1.1.2.25
  +++ FileGenerator.java	2001/04/11 10:52:59	1.1.2.26
  @@ -13,6 +13,9 @@
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
   import java.util.Map;
  +import org.apache.cocoon.caching.Cacheable;
  +import org.apache.cocoon.caching.CacheValidity;
  +import org.apache.cocoon.caching.TimeStampCacheValidity;
   import org.apache.cocoon.components.parser.Parser;
   import org.apache.cocoon.components.store.Store;
   import org.apache.cocoon.ProcessingException;
  @@ -21,6 +24,7 @@
   import org.apache.cocoon.xml.XMLCompiler;
   import org.apache.cocoon.xml.XMLInterpreter;
   import org.apache.cocoon.xml.XMLMulticaster;
  +import org.apache.cocoon.util.HashUtil;
   import org.xml.sax.EntityResolver;
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
  @@ -58,10 +62,11 @@
    *
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @author <a href="mailto:cziegeler@sundn.de">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.1.2.25 $ $Date: 2001/03/19 21:20:32 $
  + * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  + * @version CVS $Revision: 1.1.2.26 $ $Date: 2001/04/11 10:52:59 $
    */
  -public class FileGenerator extends ComposerGenerator implements Poolable, Configurable {
  +public class FileGenerator extends ComposerGenerator
  +implements Configurable, Cacheable {
   
       /** The store service instance */
       private Store store = null;
  @@ -72,6 +77,10 @@
       /** The default configuration for useStore */
       private boolean defaultUseStore;
   
  +    /** The input source */
  +    private InputSource inputSource;
  +    private String      systemID;
  +
       /**
        * Set the current <code>ComponentManager</code> instance used by this
        * <code>Composer</code>.
  @@ -86,6 +95,12 @@
           }
       }
   
  +    public void recycle() {
  +        super.recycle();
  +        this.inputSource = null;
  +        this.systemID = null;
  +    }
  +
       /**
        * Configure this generator.
        */
  @@ -103,10 +118,40 @@
       public void setup(EntityResolver resolver, Map objectModel, String src, Parameters par)
           throws ProcessingException, SAXException, IOException {
           super.setup(resolver, objectModel, src, par);
  +        this.inputSource = super.resolver.resolveEntity(null, super.source);
  +        this.systemID = this.inputSource.getSystemId();
           this.useStore = par.getParameterAsBoolean("use-store", this.defaultUseStore);
       }
   
       /**
  +     * Generate the unique key.
  +     * This key must be unique inside the space of this component.
  +     *
  +     * @return The generated key hashes the src
  +     */
  +    public long generateKey() {
  +        if (this.systemID.startsWith("file:") == true) {
  +            return HashUtil.hash(super.source);
  +        } else {
  +            return 0;
  +        }
  +    }
  +
  +    /**
  +     * Generate the validity object.
  +     *
  +     * @return The generated validity object or <code>null</code> if the
  +     *         component is currently not cacheable.
  +     */
  +    public CacheValidity generateValidity() {
  +        if (this.systemID.startsWith("file:") == true) {
  +            File xmlFile = new File(this.systemID.substring("file:".length()));
  +            return new TimeStampCacheValidity(xmlFile.lastModified());
  +        }
  +        return null;
  +    }
  +
  +   /**
        * Generate XML data.
        */
       public void generate()
  @@ -117,19 +162,17 @@
               // Using the entity resolver we get the filename of the current file:
               // The systemID of such a resource starts with file:.
               getLogger().debug("processing file " + super.source);
  -            InputSource src = super.resolver.resolveEntity(null, super.source);
  -            String      systemID = src.getSystemId();
  -            getLogger().debug("file resolved to " + systemID);
  +            getLogger().debug("file resolved to " + this.systemID);
               byte[]      cxml = null;
   
               if (this.useStore == true)
               {
                   // Is this a local file
  -                if (systemID.startsWith("file:") == true) {
  +                if (this.systemID.startsWith("file:") == true) {
                       // Stored is an array of the compiled xml and the caching time
  -                    if (store.containsKey(systemID) == true) {
  -                        Object[] cxmlAndTime = (Object[])store.get(systemID);
  -                        File xmlFile = new File(systemID.substring("file:".length()));
  +                    if (store.containsKey(this.systemID) == true) {
  +                        Object[] cxmlAndTime = (Object[])store.get(this.systemID);
  +                        File xmlFile = new File(this.systemID.substring("file:".length()));
                           long storedTime = ((Long)cxmlAndTime[1]).longValue();
                           if (storedTime >= xmlFile.lastModified()) {
                               cxml = (byte[])cxmlAndTime[0];
  @@ -143,7 +186,7 @@
                   Parser parser = (Parser)this.manager.lookup(Roles.PARSER);
                   try {
                       // use the xmlcompiler for local files if storing is on
  -                    if (this.useStore == true && systemID.startsWith("file:") == true)
  +                    if (this.useStore == true && this.systemID.startsWith("file:") == true)
                       {
                           ByteArrayOutputStream baos = new ByteArrayOutputStream();
                           XMLCompiler compiler = new XMLCompiler();
  @@ -153,17 +196,17 @@
   
                           parser.setContentHandler(multicaster);
                           parser.setLexicalHandler(multicaster);
  -                        parser.parse(src);
  +                        parser.parse(this.inputSource);
   
                           // Stored is an array of the cxml and the current time
                           Object[] cxmlAndTime = new Object[2];
                           cxmlAndTime[0] = baos.toByteArray();
                           cxmlAndTime[1] = new Long(System.currentTimeMillis());
  -                        store.hold(systemID, cxmlAndTime);
  +                        store.hold(this.systemID, cxmlAndTime);
                       } else {
                           parser.setContentHandler(this.contentHandler);
                           parser.setLexicalHandler(this.lexicalHandler);
  -                        parser.parse(src);
  +                        parser.parse(this.inputSource);
                       }
                   } finally {
                       this.manager.release((Component) parser);
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.5   +3 -4      xml-cocoon/src/org/apache/cocoon/transformation/Attic/Transformer.java
  
  Index: Transformer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/transformation/Attic/Transformer.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- Transformer.java	2000/08/04 21:12:14	1.1.2.4
  +++ Transformer.java	2001/04/11 10:53:03	1.1.2.5
  @@ -8,14 +8,13 @@
   package org.apache.cocoon.transformation;
   
   import org.apache.cocoon.sitemap.SitemapModelComponent;
  -import org.apache.cocoon.xml.XMLConsumer;
  -import org.apache.cocoon.xml.XMLProducer;
  +import org.apache.cocoon.xml.XMLPipe;
   
   /**
    *
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/08/04 21:12:14 $
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2001/04/11 10:53:03 $
    */
  -public interface Transformer extends XMLProducer, XMLConsumer, SitemapModelComponent {
  +public interface Transformer extends XMLPipe, SitemapModelComponent {
   }
  
  
  
  1.1.2.14  +79 -21    xml-cocoon/src/org/apache/cocoon/transformation/Attic/TraxTransformer.java
  
  Index: TraxTransformer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/transformation/Attic/TraxTransformer.java,v
  retrieving revision 1.1.2.13
  retrieving revision 1.1.2.14
  diff -u -r1.1.2.13 -r1.1.2.14
  --- TraxTransformer.java	2001/03/30 17:14:40	1.1.2.13
  +++ TraxTransformer.java	2001/04/11 10:53:04	1.1.2.14
  @@ -34,6 +34,10 @@
   import org.apache.cocoon.Roles;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.store.Store;
  +import org.apache.cocoon.caching.Cacheable;
  +import org.apache.cocoon.caching.CacheValidity;
  +import org.apache.cocoon.caching.TimeStampCacheValidity;
  +import org.apache.cocoon.util.HashUtil;
   import org.apache.cocoon.xml.XMLConsumer;
   import org.apache.cocoon.xml.ContentHandlerWrapper;
   
  @@ -57,11 +61,11 @@
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
    * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
  - * @author <a href="mailto:cziegeler@sundn.de">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.1.2.13 $ $Date: 2001/03/30 17:14:40 $
  + * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  + * @version CVS $Revision: 1.1.2.14 $ $Date: 2001/04/11 10:53:04 $
    */
   public class TraxTransformer extends ContentHandlerWrapper
  -implements Transformer, Composer, Poolable, Recyclable, Configurable {
  +implements Transformer, Composer, Recyclable, Configurable, Cacheable {
       private static String FILE = "file:/";
   
       /** The store service instance */
  @@ -76,15 +80,21 @@
       /** Is the store turned on? (default is on) */
       private boolean useStore = true;
   
  -    TransformerHandler getTransformerHandler(EntityResolver resolver, String xsluri)
  +    /** The InputSource */
  +    private InputSource inputSource;
  +    private String systemID;
  +    private String xsluri;
  +    private Parameters par;
  +    private Map objectModel;
  +    private EntityResolver resolver;
  +
  +    TransformerHandler getTransformerHandler(EntityResolver resolver)
         throws SAXException, ProcessingException, IOException, TransformerConfigurationException
       {
           // Only local files are checked for modification for compatibility reasons!
           // Using the entity resolver we get the filename of the current file:
           // The systemID if such a resource starts with file://.
           Templates templates = null;
  -        InputSource src = resolver.resolveEntity(null, xsluri);
  -        String      systemID = src.getSystemId();
   
           if (this.useStore == true)
           {
  @@ -160,21 +170,71 @@
       public void setup(EntityResolver resolver, Map objectModel, String src, Parameters par)
       throws SAXException, ProcessingException, IOException {
   
  -        /** The Request object */
  -        Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
  -
           // Check the stylesheet uri
  -        String xsluri = src;
  -        if (xsluri == null) {
  +        this.xsluri = src;
  +        if (this.xsluri == null) {
               throw new ProcessingException("Stylesheet URI can't be null");
           }
  +        this.par = par;
  +        this.objectModel = objectModel;
  +        this.inputSource = resolver.resolveEntity(null, this.xsluri);
  +        this.systemID = inputSource.getSystemId();
  +        this.resolver = resolver;
  +    }
  +
  +    /**
  +     * Generate the unique key.
  +     * This key must be unique inside the space of this component.
  +     *
  +     * @return The generated key hashes the src
  +     */
  +    public long generateKey() {
  +        if (this.systemID.startsWith("file:") == true) {
  +            return HashUtil.hash(this.xsluri);
  +        } else {
  +            return 0;
  +        }
  +    }
  +
  +    /**
  +     * Generate the validity object.
  +     *
  +     * @return The generated validity object or <code>null</code> if the
  +     *         component is currently not cacheable.
  +     */
  +    public CacheValidity generateValidity() {
  +        if (this.systemID.startsWith("file:") == true) {
  +            File xslFile = new File(this.systemID.substring("file:".length()));
  +            return new TimeStampCacheValidity(xslFile.lastModified());
  +        }
  +        return null;
  +    }
   
  +    /**
  +     * Set the <code>XMLConsumer</code> that will receive XML data.
  +     * <br>
  +     * This method will simply call <code>setContentHandler(consumer)</code>
  +     * and <code>setLexicalHandler(consumer)</code>.
  +     */
  +    public void setConsumer(XMLConsumer consumer) {
  +        /** The Request object */
  +        Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
  +
           /** Get a Transformer Handler */
           try {
  -            transformerHandler = getTransformerHandler(resolver,xsluri);
  +            transformerHandler = getTransformerHandler(resolver);
           } catch (TransformerConfigurationException e){
  +            log.error("Problem in getTransformer:", e);
  +            throw new RuntimeException("Problem in getTransformer:" + e.getMessage());
  +        } catch (SAXException e){
  +            log.error("Problem in getTransformer:", e);
  +            throw new RuntimeException("Problem in getTransformer:" + e.getMessage());
  +        } catch (IOException e){
               log.error("Problem in getTransformer:", e);
  -            throw new ProcessingException("Problem in getTransformer:" + e.getMessage(), e);
  +            throw new RuntimeException("Problem in getTransformer:" + e.getMessage());
  +        } catch (ProcessingException e){
  +            log.error("Problem in getTransformer:", e);
  +            throw new RuntimeException("Problem in getTransformer:" + e.getMessage());
           }
   
           if (request != null) {
  @@ -209,15 +269,7 @@
           }
           if(transformerHandler instanceof org.xml.sax.ext.LexicalHandler)
               this.setLexicalHandler((org.xml.sax.ext.LexicalHandler)transformerHandler);
  -    }
   
  -    /**
  -     * Set the <code>XMLConsumer</code> that will receive XML data.
  -     * <br>
  -     * This method will simply call <code>setContentHandler(consumer)</code>
  -     * and <code>setLexicalHandler(consumer)</code>.
  -     */
  -    public void setConsumer(XMLConsumer consumer) {
           this.setContentHandler(consumer);
       }
   
  @@ -287,6 +339,12 @@
               log.debug("Exception in recycle:", e);
           }
           this.transformerHandler = null;
  +        this.objectModel = null;
  +        this.inputSource = null;
  +        this.par = null;
  +        this.systemID = null;
  +        this.xsluri = null;
  +        this.resolver = null;
           super.recycle();
       }
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +200 -0    xml-cocoon/src/org/apache/cocoon/util/Attic/HashUtil.java
  
  
  
  

----------------------------------------------------------------------
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