Hi all -

I've seen several rather frustrated posts from users trying to figure 
out how to make JspReader and/or JspGenerator work in Cocoon 2.0.2. This 
email describes how.

JspReader

Edit src/java/org/apache/cocoon/reading/JSPReader.java and replace the 
following lines (119-132):

             // 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().t
oExternalForm();
             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);
             }

with the following:

             String url = this.source;

             // -- debug info --
             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;
             }

JspGenerator

Edit src/java/org/apache/cocoon/generation/JspGenerator.java and replace 
the following lines (106-113):

             src = this.resolver.resolve(this.source);
             String url = src.getSystemId();
             // Guarantee src parameter is a file
             if (!url.startsWith("file:/"))
                 throw new IOException("Protocol not supported: " + url);

             url = url.substring(5);
             getLogger().debug("JspGenerator executing JSP:" + url);

with the following:

             String url = this.source;
             // 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;
             }


The rebuild Cocoon and replace your existing cocoon-2.0.2.jar with the 
new one in build/cocoon/webapp/WEB-INF/lib.

Don't forget to copy jasper-compiler.jar from $CATALINA_HOME/lib to 
WEB-INF/lib (or whatever JSP compiler you choose to use).

Finally, if you are using a sub-sitemap, any references to JSP files in 
pipelines with either JspReader or JspGenerator must have the path 
starting from the root cocoon context and MUST start with a leading 
forward slash. Thus, if you have a sub-sitemap in a directory called 
abc, with a JSP file in abc/jsps/hello.jsp, the src attribute of either 
component should be something like:

src="/abc/jsps/hello.jsp"


Cheers,

Lajos

-- 
galatea.com
Cocoon training, consulting & support



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to