cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kpiroum...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/reading JSPReader.java
Date Mon, 22 Apr 2002 09:48:12 GMT
kpiroumian    02/04/22 02:48:12

  Modified:    src/java/org/apache/cocoon/reading JSPReader.java
  Log:
  Allow relative paths in sitemap.
  Fixes: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2631
  
  Revision  Changes    Path
  1.5       +41 -45    xml-cocoon2/src/java/org/apache/cocoon/reading/JSPReader.java
  
  Index: JSPReader.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/reading/JSPReader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JSPReader.java	22 Feb 2002 07:03:54 -0000	1.4
  +++ JSPReader.java	22 Apr 2002 09:48:12 -0000	1.5
  @@ -50,31 +50,33 @@
   */
   package org.apache.cocoon.reading;
   
  +import java.io.ByteArrayInputStream;
  +import java.io.IOException;
  +
  +import javax.servlet.ServletContext;
  +import javax.servlet.ServletException;
  +import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.http.HttpServletResponse;
  +
   import org.apache.avalon.excalibur.pool.Poolable;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
  +
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.jsp.JSPEngine;
   import org.apache.cocoon.environment.Source;
  +import org.apache.cocoon.environment.Context;
  +import org.apache.cocoon.environment.ObjectModelHelper;
   import org.apache.cocoon.environment.http.HttpEnvironment;
   
  -import javax.servlet.ServletContext;
  -import javax.servlet.ServletException;
  -import javax.servlet.http.HttpServletRequest;
  -import javax.servlet.http.HttpServletResponse;
  -import java.io.ByteArrayInputStream;
  -import java.io.File;
  -import java.io.IOException;
  -
   /**
  - * @author <a href="mailto:kpiroumian@flagship.ru">Konstantin Piroumian</a>
  - * @version CVS $Id: JSPReader.java,v 1.4 2002/02/22 07:03:54 cziegeler Exp $
  - *
    * The <code>JSPReader</code> component is used to serve JSP page output data
    * in a sitemap pipeline.
  + *
  + * @author <a href="mailto:kpiroumian@flagship.ru">Konstantin Piroumian</a>
  + * @version CVS $Id: JSPReader.java,v 1.5 2002/04/22 09:48:12 kpiroumian Exp $
    */
  -public class JSPReader extends AbstractReader
  -            implements Composable, Poolable{
  +public class JSPReader extends AbstractReader implements Composable, Poolable {
   
       private ComponentManager manager;
   
  @@ -82,26 +84,15 @@
           this.manager = manager;
       }
   
  -    /** Contextualize this class
  -    public void contextualize(Context context) throws ContextException {
  -        if (this.contextDir == null) {
  -            org.apache.cocoon.environment.Context ctx =
  -                (org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
  -            try {
  -                this.contextDir = new File(ctx.getRealPath("/")).toURL().toExternalForm();
  -                getLogger().debug("JSPReader: Context directory is " + this.contextDir);
  -            } catch (MalformedURLException e) {
  -                getLogger().error("JSPReader: Could not get context directory", e);
  -                throw new ContextException("JSPReader: Could not get context directory",
e);
  -            }
  -        }
  -    }
  -    */
       /**
        * Generates the output from JSP page.
        */
       public void generate() throws IOException, ProcessingException {
           // ensure that we are running in a servlet environment
  +        if (this.source == null) {
  +            throw new ProcessingException("JSPReader: source JSP is not specified");
  +        }
  +
           HttpServletResponse httpResponse =
               (HttpServletResponse)this.objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
           HttpServletRequest httpRequest =
  @@ -114,28 +105,34 @@
           }
   
           JSPEngine engine = null;
  -        Source src = null;
           try {
  -            // KP: A hacky way of source resolving.
  -            // Why context:// protocol returns not a string in URL format,
  -            // but a system-dependent path with 'file:' prefix?
  -            String contextDir = new File(httpContext.getRealPath("/")).toURL().toExternalForm();
  -            src = this.resolver.resolve(this.source);
  -            String url = src.getSystemId();
  -            if(url.startsWith(contextDir)) {
  -                // File is located under contextDir, using relative file name
  -                url = url.substring(contextDir.length());
  -            }
  -            if (url.startsWith("file:")) {
  -                // we need a relative path
  -                url = url.substring(5);
  +
  +            // FIXME (KP): Should we exclude not supported protocols, say 'context'?
  +            String url = this.source;
  +
  +            // -- debug info --
  +            Source src = resolver.resolve(url);
  +            System.out.println("Resolved to: " + src);
  +            java.net.URL resURL = httpContext.getResource(".");
  +            System.out.println(". resource is: " + resURL);
  +            // -- end debug --
  +
  +
  +            // absolute path is processed as is
  +            if (!url.startsWith("/")) {
  +                // get current request path
  +                String servletPath = httpRequest.getServletPath();
  +                // remove file part
  +                servletPath = servletPath.substring(0, servletPath.lastIndexOf('/') + 1);
  +                url = servletPath + url;
               }
   
  +            engine = (JSPEngine)this.manager.lookup(JSPEngine.ROLE);
  +
               getLogger().debug("JSPReader executing JSP:" + url);
   
  -            engine = (JSPEngine)this.manager.lookup(JSPEngine.ROLE);
               byte[] bytes = engine.executeJSP(url, httpRequest, httpResponse, httpContext);
  -
  +            // FIXME (KP): Make buffer size configurable
               byte[] buffer = new byte[8192];
               int length = -1;
   
  @@ -160,7 +157,6 @@
               getLogger().debug("Exception in JSPReader.generate()", e);
               throw new ProcessingException("Exception JSPReader.generate()",e);
           } finally {
  -            if (src != null) src.recycle();
               if (engine != null) this.manager.release(engine);
           }
       }
  
  
  

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


Mime
View raw message