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/producer ProducerFromFile.java
Date Mon, 10 Jan 2000 21:50:52 GMT
stefano     00/01/10 13:50:52

  Modified:    src/org/apache/cocoon Engine.java
               src/org/apache/cocoon/processor/xslt XSLTProcessor.java
               src/org/apache/cocoon/producer ProducerFromFile.java
  Log:
  fixed problems with command line operation, also moved back some cleanup since it was breaking
the cache (stupid file:/// doesn't return lastModifiedTime, grrr!)
  
  Revision  Changes    Path
  1.9       +5 -7      xml-cocoon/src/org/apache/cocoon/Engine.java
  
  Index: Engine.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Engine.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Engine.java	2000/01/03 01:39:42	1.8
  +++ Engine.java	2000/01/10 21:50:50	1.9
  @@ -1,4 +1,4 @@
  -/*-- $Id: Engine.java,v 1.8 2000/01/03 01:39:42 stefano Exp $ --
  +/*-- $Id: Engine.java,v 1.9 2000/01/10 21:50:50 stefano Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -72,7 +72,7 @@
    * This class implements the engine that does all the document processing.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.8 $ $Date: 2000/01/03 01:39:42 $
  + * @version $Revision: 1.9 $ $Date: 2000/01/10 21:50:50 $
    */
   
   public class Engine implements Defaults {
  @@ -119,12 +119,10 @@
           // stores the engine context
           if ((context != null) && (context instanceof ServletContext)) {
               this.servletContext = (ServletContext) context;
  -        } else {
  -            throw new Exception("Engine can't work in given context.");
  -        }
   
  -        // register the context
  -        manager.setRole("context", context);
  +            // register the context
  +            manager.setRole("context", context);
  +        }
   
           // Create the parser and register it
           parser = (Parser) manager.create((String) configurations.get(PARSER_PROP,
  
  
  
  1.4       +20 -11    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XSLTProcessor.java	2000/01/09 23:46:13	1.3
  +++ XSLTProcessor.java	2000/01/10 21:50:51	1.4
  @@ -1,4 +1,4 @@
  -/*-- $Id: XSLTProcessor.java,v 1.3 2000/01/09 23:46:13 stefano Exp $ -- 
  +/*-- $Id: XSLTProcessor.java,v 1.4 2000/01/10 21:50:51 stefano Exp $ -- 
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -70,7 +70,7 @@
    * This class implements an XSLT processor.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.3 $ $Date: 2000/01/09 23:46:13 $
  + * @version $Revision: 1.4 $ $Date: 2000/01/10 21:50:51 $
    */
   
   public class XSLTProcessor implements Actor, Processor, Status, Defaults {
  @@ -97,7 +97,7 @@
           String browser = (String) parameters.get("browser");
           
           try {
  -            URL resource = getResource(document, path, browser);
  +            Object resource = getResource(document, path, browser);
               Document stylesheet = getStylesheet(resource, document, request);
               Document result = this.parser.createEmptyDocument();
               return transformer.transform(document, null, stylesheet, resource.toString(),
result);
  @@ -106,9 +106,9 @@
           }
       }
   
  -    private URL getResource(Document document, String path, String browser) throws ProcessorException
{
  +    private Object getResource(Document document, String path, String browser) throws ProcessorException
{
           
  -        URL resource = null;
  +        Object resource = null;
           
           Enumeration pis = Utils.getAllPIs(document, STYLESHEET_PI).elements();
           while (pis.hasMoreElements()) {
  @@ -118,11 +118,11 @@
               if ((type != null) && (type.equals("text/xsl"))) {
                   String url = (String) attributes.get("href");
                   if (url != null) {
  -                    URL local = null;
  +                    Object local = null;
                       
                       try {
                           if (url.indexOf("://") < 0) {
  -                            local = new URL("file:///" + path + url);
  +                            local = new File(path + url);
                           } else {
                               local = new URL(url);
                           }
  @@ -147,14 +147,14 @@
           }
   
           if (resource == null) {
  -            throw new ProcessorException("Could not assiciate stylesheet to document: "
  +            throw new ProcessorException("Could not associate stylesheet to document: "
                   + " no matching stylesheet for: " + browser);
           } else {
               return resource;
           }
       }
        
  -    private Document getStylesheet(URL resource, Document document, HttpServletRequest
request) throws ProcessorException {
  +    private Document getStylesheet(Object resource, Document document, HttpServletRequest
request) throws ProcessorException {
   
           try {
               Document sheet;
  @@ -180,10 +180,19 @@
           }
       }
   
  -    private Document getDocument(URL resource) throws Exception {
  +    private Document getDocument(Object resource) throws Exception {
           InputSource input = new InputSource();
           input.setSystemId(resource.toString());
  -        input.setCharacterStream(new InputStreamReader(resource.openStream()));
  +        
  +        if (resource instanceof File) {
  +            input.setCharacterStream(new FileReader(((File) resource)));
  +        } else if (resource instanceof URL) {
  +            input.setCharacterStream(new InputStreamReader(((URL) resource).openStream()));
  +        } else {
  +            // should never happen
  +            throw new Error("Fatal error: Could not elaborate given resource: " + resource);
  +        }
  +        
           return this.parser.parse(input);
       }
       
  
  
  
  1.3       +4 -3      xml-cocoon/src/org/apache/cocoon/producer/ProducerFromFile.java
  
  Index: ProducerFromFile.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/producer/ProducerFromFile.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProducerFromFile.java	1999/12/16 11:45:07	1.2
  +++ ProducerFromFile.java	2000/01/10 21:50:51	1.3
  @@ -1,4 +1,4 @@
  -/*-- $Id: ProducerFromFile.java,v 1.2 1999/12/16 11:45:07 stefano Exp $ -- 
  +/*-- $Id: ProducerFromFile.java,v 1.3 2000/01/10 21:50:51 stefano Exp $ -- 
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -64,7 +64,7 @@
    * available, even if we should use getResource().
    * 
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.2 $ $Date: 1999/12/16 11:45:07 $
  + * @version $Revision: 1.3 $ $Date: 2000/01/10 21:50:51 $
    */
   
   public class ProducerFromFile extends AbstractProducer implements Status {
  @@ -117,7 +117,8 @@
           } catch (MalformedURLException e) {
               throw new RuntimeException("Malformed request URL.");
           } catch (NullPointerException e) {
  -            throw new RuntimeException("Context cannot be null.");
  +            // if there is no context set, we must be called from the command line
  +            return request.getPathTranslated().replace('\\','/');
           }
       }
       
  
  
  

Mime
View raw message