cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/processor/xslt XSLTProcessor.java
Date Wed, 16 Feb 2000 01:11:18 GMT
stefano     00/02/15 17:11:18

  Modified:    src/org/apache/cocoon/processor/xslt XSLTProcessor.java
  Log:
  patched to allow better synch when stylesheets are updated.
  
  Thanks to Sean Timm for this. (yes, Sean, I've seen it :)
  
  Revision  Changes    Path
  1.7       +38 -36    xml-cocoon/src/org/apache/cocoon/processor/xslt/XSLTProcessor.java
  
  Index: XSLTProcessor.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xslt/XSLTProcessor.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSLTProcessor.java	2000/02/13 18:29:34	1.6
  +++ XSLTProcessor.java	2000/02/16 01:11:18	1.7
  @@ -1,36 +1,36 @@
  -/*-- $Id: XSLTProcessor.java,v 1.6 2000/02/13 18:29:34 stefano Exp $ -- 
  +/*-- $Id: XSLTProcessor.java,v 1.7 2000/02/16 01:11:18 stefano Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  - 
  +
    Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  - 
  +
    Redistribution and use in source and binary forms, with or without modifica-
    tion, are permitted provided that the following conditions are met:
  - 
  +
    1. Redistributions of  source code must  retain the above copyright  notice,
       this list of conditions and the following disclaimer.
  - 
  +
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
  - 
  +
    3. The end-user documentation included with the redistribution, if any, must
       include  the following  acknowledgment:  "This product includes  software
       developed  by the  Apache Software Foundation  (http://www.apache.org/)."
       Alternately, this  acknowledgment may  appear in the software itself,  if
       and wherever such third-party acknowledgments normally appear.
  - 
  +
    4. The names "Cocoon" and  "Apache Software Foundation"  must not be used to
       endorse  or promote  products derived  from this  software without  prior
       written permission. For written permission, please contact
       apache@apache.org.
  - 
  +
    5. Products  derived from this software may not  be called "Apache", nor may
       "Apache" appear  in their name,  without prior written permission  of the
       Apache Software Foundation.
  - 
  +
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  @@ -41,14 +41,14 @@
    ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
    (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  - 
  +
    This software  consists of voluntary contributions made  by many individuals
    on  behalf of the Apache Software  Foundation and was  originally created by
  - Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
  + Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
    Software Foundation, please see <http://www.apache.org/>.
  - 
  +
    */
  - 
  +
   package org.apache.cocoon.processor.xslt;
   
   import java.io.*;
  @@ -70,13 +70,13 @@
    * This class implements an XSLT processor.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.6 $ $Date: 2000/02/13 18:29:34 $
  + * @version $Revision: 1.7 $ $Date: 2000/02/16 01:11:18 $
    */
   
   public class XSLTProcessor implements Actor, Processor, Status, Defaults {
   
       private Monitor monitor = new Monitor(10);
  -    
  +
       private Parser parser;
       private Store store;
       private Transformer transformer;
  @@ -88,14 +88,14 @@
       }
   
       public Document process(Document document, Dictionary parameters) throws Exception
{
  -        
  +
           Document sheet = (Document) parameters.get("stylesheet");
           if (sheet != null) return sheet;
   
           HttpServletRequest request = (HttpServletRequest) parameters.get("request");
           String path = (String) parameters.get("path");
           String browser = (String) parameters.get("browser");
  -        
  +
           try {
               Object resource = getResource(document, path, browser);
               Document stylesheet = getStylesheet(resource, document, request);
  @@ -107,19 +107,19 @@
       }
   
       private Object getResource(Document document, String path, String browser) throws ProcessorException
{
  -        
  +
           Object resource = null;
  -        
  +
           Enumeration pis = Utils.getAllPIs(document, STYLESHEET_PI).elements();
           while (pis.hasMoreElements()) {
               Hashtable attributes = Utils.getPIPseudoAttributes((ProcessingInstruction)
pis.nextElement());
  -            
  +
               String type = (String) attributes.get("type");
               if ((type != null) && (type.equals("text/xsl"))) {
                   String url = (String) attributes.get("href");
                   if (url != null) {
                       Object local = null;
  -                    
  +
                       try {
                           if (url.indexOf("://") < 0) {
                               local = new File(path + url);
  @@ -127,12 +127,12 @@
                               local = new URL(url);
                           }
                       } catch (MalformedURLException e) {
  -                        throw new ProcessorException("Could not associate stylesheet to
document: " 
  +                        throw new ProcessorException("Could not associate stylesheet to
document: "
                               + url + " is a malformed URL.");
                       }
  -                
  +
                       String media = (String) attributes.get("media");
  -                    
  +
                       if (media == null) {
                           resource = local;
                           if (browser == null) break;
  @@ -153,29 +153,31 @@
               return resource;
           }
       }
  -     
  +
       private Document getStylesheet(Object resource, Document document, HttpServletRequest
request) throws ProcessorException {
   
           try {
               Document sheet;
  -            
  -            if (this.hasChanged(request)) {
  +            String stylesheetKey = Utils.encode(request, true) + resource.toString();
  +
  +            if (this.hasChanged(stylesheetKey)) {
                   sheet = getDocument(resource);
                   this.store.hold(resource, sheet);
  -                this.monitor.watch(Utils.encode(request, true), resource);
  +                this.monitor.watch(stylesheetKey, resource);
               } else {
                   Object o = this.store.get(resource);
                   if (o != null) {
                       sheet = (Document) o;
                   } else {
  -                    sheet  = getDocument(resource);
  +                    sheet = getDocument(resource);
                       this.store.hold(resource, sheet);
  +                    this.monitor.watch(stylesheetKey, resource);
                   }
               }
  -            
  +
               return sheet;
           } catch (Exception e) {
  -            throw new ProcessorException("Could not associate stylesheet to document: "

  +            throw new ProcessorException("Could not associate stylesheet to document: "
                   + " error reading " + resource + ": " + e.getMessage());
           }
       }
  @@ -183,7 +185,7 @@
       private Document getDocument(Object resource) throws Exception {
           InputSource input = new InputSource();
           input.setSystemId(resource.toString());
  -        
  +
           if (resource instanceof File) {
               input.setCharacterStream(new FileReader(((File) resource)));
           } else if (resource instanceof URL) {
  @@ -192,15 +194,15 @@
               // should never happen
               throw new Error("Fatal error: Could not elaborate given resource: " + resource);
           }
  -        
  +
           // do not validate stylesheets
           return this.parser.parse(input, false);
       }
  -    
  +
       public boolean hasChanged(Object context) {
  -        return this.monitor.hasChanged(Utils.encode((HttpServletRequest) context, true));
  +        return this.monitor.hasChanged((String) context);
       }
  -    
  +
       public String getStatus() {
           return "XSLT Processor";
       }
  
  
  

Mime
View raw message