cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rica...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/producer ProducerFromFile.java
Date Sat, 15 Jan 2000 11:19:19 GMT
ricardo     00/01/15 03:19:19

  Modified:    src/org/apache/cocoon/producer ProducerFromFile.java
  Log:
  Moved method getBasename to Utils
  
  Revision  Changes    Path
  1.4       +5 -41     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ProducerFromFile.java	2000/01/10 21:50:51	1.3
  +++ ProducerFromFile.java	2000/01/15 11:19:19	1.4
  @@ -1,4 +1,4 @@
  -/*-- $Id: ProducerFromFile.java,v 1.3 2000/01/10 21:50:51 stefano Exp $ -- 
  +/*-- $Id: ProducerFromFile.java,v 1.4 2000/01/15 11:19:19 ricardo 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.3 $ $Date: 2000/01/10 21:50:51 $
  + * @version $Revision: 1.4 $ $Date: 2000/01/15 11:19:19 $
    */
   
   public class ProducerFromFile extends AbstractProducer implements Status {
  @@ -72,57 +72,21 @@
       private Monitor monitor = new Monitor(10);
       
       public Reader getStream(HttpServletRequest request) throws IOException {
  -        File file = new File(this.getBasename(request));
  +        File file = new File(Utils.getBasename(request, this.context));
           this.monitor.watch(Utils.encode(request), file);
           return new InputStreamReader(new FileInputStream(file));
       }
   
       public String getPath(HttpServletRequest request) {
  -        String basename = this.getBasename(request);
  +        String basename = Utils.getBasename(request, this.context);
           return basename.substring(0, basename.lastIndexOf('/') + 1);
       }
       
       public boolean hasChanged(Object context) {
           return this.monitor.hasChanged(Utils.encode((HttpServletRequest) context));
       }
  -
  -    /**
  -     * XXX: This is a dirty hack. The worst piece of code I ever wrote
  -     * and it clearly shows how Cocoon must change to support the Servlet API
  -     * 2.2 which has _much_ better mapping support thru the use of "getResource()"
  -     * but then, all the file system abstraction should be URL based.
  -     *
  -     * So, for now, leave the dirty code even if totally deprecated and work
  -     * out a better solution in the future.
  -     */
  -    protected String getBasename(HttpServletRequest request) {
  -        try {
  -            // detect if the engine supports at least Servlet API 2.2
  -            request.getContextPath();
  -            URL resource = ((ServletContext) context).getResource(request.getServletPath());
  -            if (resource.getProtocol().equals("file")) {
  -                return resource.getFile();
  -            } else {
  -                throw new RuntimeException("Cannot handle remote resources.");
  -            }
  -        } catch (NoSuchMethodError e) {
  -            // if there is no such method we must be in Servlet API 2.1
  -            if (request.getPathInfo() != null) {
  -                // this must be Apache JServ
  -                return request.getPathTranslated().replace('\\','/');
  -            } else {
  -                // otherwise use the deprecated method on all other servlet engines.
  -                return request.getRealPath(request.getRequestURI());
  -            }
  -        } catch (MalformedURLException e) {
  -            throw new RuntimeException("Malformed request URL.");
  -        } catch (NullPointerException e) {
  -            // if there is no context set, we must be called from the command line
  -            return request.getPathTranslated().replace('\\','/');
  -        }
  -    }
       
       public String getStatus() {
           return "Producer from local file";
       }
  -}
  \ No newline at end of file
  +}
  
  
  

Mime
View raw message