dims        00/11/07 08:47:09

  Modified:    src/org/apache/cocoon/transformation Tag: xml-cocoon2
                        XalanTransformer.java
  Log:
  Patch from Carsten Ziegeler for file caching using time-stamp comparsion.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.18  +42 -4     
xml-cocoon/src/org/apache/cocoon/transformation/Attic/XalanTransformer.java
  
  Index: XalanTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/transformation/Attic/XalanTransformer.java,v
  retrieving revision 1.1.2.17
  retrieving revision 1.1.2.18
  diff -u -r1.1.2.17 -r1.1.2.18
  --- XalanTransformer.java     2000/11/01 15:01:42     1.1.2.17
  +++ XalanTransformer.java     2000/11/07 16:47:08     1.1.2.18
  @@ -8,6 +8,7 @@
   package org.apache.cocoon.transformation;
   
   import java.io.IOException;
  +import java.io.File;
   import java.util.Enumeration;
   import java.util.Map;
   import java.util.Hashtable;
  @@ -45,7 +46,8 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
    * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
  - * @version CVS $Revision: 1.1.2.17 $ $Date: 2000/11/01 15:01:42 $
  + * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
  + * @version CVS $Revision: 1.1.2.18 $ $Date: 2000/11/07 16:47:08 $
    */
   public class XalanTransformer extends ContentHandlerWrapper
   implements Transformer, Composer, Poolable, Configurable {
  @@ -65,13 +67,49 @@
       private org.apache.trax.Transformer getTransformer(EntityResolver 
resolver, String xsluri)
         throws SAXException, ProcessingException, IOException
       {
  +        // Only local files are checked for midification 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;
  -        if (this.useCache == true) templates = 
(Templates)templatesCache.get(xsluri);
  +        InputSource src = resolver.resolveEntity(null, xsluri);
  +        String      systemID = src.getSystemId();
  +        if (this.useCache == true)
  +        {
  +            // Is this a local file
  +            if (systemID.startsWith("file:/") == true) {
  +                // Cached is an array of the template and the caching time
  +                Object[] templateAndTime = 
(Object[])templatesCache.get(xsluri);
  +                if (templateAndTime != null) {
  +                    File xslFile = new File(systemID.substring(6));
  +                    long cachedTime = ((Long)templateAndTime[1]).longValue();
  +                    if (cachedTime < xslFile.lastModified()) {
  +                        templates = null;
  +                    } else {
  +                        templates = (Templates)templateAndTime[0];
  +                    }
  +                }
  +            } else {
  +                // only the template is cached
  +                templates = (Templates)templatesCache.get(xsluri);
  +            }
  +        }
           if(templates == null)
           {
            Processor processor = Processor.newInstance("xslt");
  -             templates = processor.process(resolver.resolveEntity(null, 
xsluri));
  -            if (this.useCache == true) templatesCache.put(xsluri,templates);
  +            templates = processor.process(src);
  +            if (this.useCache == true)
  +            {
  +                // Is this a local file
  +                if (systemID.startsWith("file:/") == true) {
  +                    // Cached is an array of the template and the current 
time
  +                    Object[] templateAndTime = new Object[2];
  +                    templateAndTime[0] = templates;
  +                    templateAndTime[1] = new 
Long(System.currentTimeMillis());
  +                    templatesCache.put(xsluri, templateAndTime);
  +                } else {
  +                    templatesCache.put(xsluri,templates);
  +                }
  +            }
           }
           return templates.newTransformer();
       }
  
  
  

Reply via email to