joerg 2004/04/23 18:57:19
Modified: src/blocks/jsp/java/org/apache/cocoon/generation JSPGenerator.java src/blocks/jsp/java/org/apache/cocoon/reading JSPReader.java . status.xml Log: Hopefully fixed the source resolving in JSP components finally by using standard Cocoon/Avalon Excalibur source resolving. This allows to use all known protocols and Cocoon pseudo protocols as long as the JSP file is inside the servlet's context. Revision Changes Path 1.4 +29 -26 cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/generation/JSPGenerator.java Index: JSPGenerator.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/generation/JSPGenerator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- JSPGenerator.java 5 Mar 2004 13:01:57 -0000 1.3 +++ JSPGenerator.java 24 Apr 2004 01:57:19 -0000 1.4 @@ -15,21 +15,22 @@ */ package org.apache.cocoon.generation; +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.cocoon.ProcessingException; import org.apache.cocoon.components.jsp.JSPEngine; -import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.http.HttpEnvironment; +import org.apache.excalibur.source.Source; import org.apache.excalibur.xml.sax.SAXParser; import org.xml.sax.InputSource; import org.xml.sax.SAXException; -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.IOException; - /** * Allows Servlets and JSPs to be used as a generator. * @@ -52,35 +53,35 @@ // ensure that we are running in a servlet environment if (servletResponse == null || servletRequest == null || servletContext == null) { - throw new ProcessingException("JSPReader can only be used from within a Servlet environment."); + throw new ProcessingException("JSPGenerator can only be used from within a Servlet environment."); } JSPEngine engine = null; SAXParser parser = null; + Source inputSource = null; + Source contextSource = null; try { - // TODO (KP): Should we exclude not supported protocols, say 'context'? - String url = super.source; - // absolute path is processed as is - if (!url.startsWith("/")) { - // get current request path - String servletPath = servletRequest.getServletPath(); - // remove sitemap URI part - String sitemapURI = ObjectModelHelper.getRequest(objectModel).getSitemapURI(); - if (sitemapURI != null) { - servletPath = servletPath.substring(0, servletPath.indexOf(sitemapURI)); - } else { - // for example when using cocoon:/ pseudo protocol - servletPath = servletPath.substring(0, servletPath.lastIndexOf("/") + 1); - } - url = servletPath + url; + inputSource = this.resolver.resolveURI(this.source); + contextSource = this.resolver.resolveURI("context:/"); + + String inputSourceURI = inputSource.getURI(); + String contextSourceURI = contextSource.getURI(); + + if (!inputSourceURI.startsWith(contextSourceURI)) { + throw new ProcessingException("You must not reference a file " + + "outside of the servlet context at " + contextSourceURI + "."); } - engine = (JSPEngine) super.manager.lookup(JSPEngine.ROLE); + String url = inputSourceURI.substring(contextSourceURI.length()); + if (url.charAt(0) != '/') { + url = "/" + url; + } if (getLogger().isDebugEnabled()) { getLogger().debug("JSPGenerator executing:" + url); } + engine = (JSPEngine) super.manager.lookup(JSPEngine.ROLE); byte[] bytes = engine.executeJSP(url, servletRequest, servletResponse, servletContext); InputSource input = new InputSource(new ByteArrayInputStream(bytes)); @@ -103,6 +104,8 @@ } finally { super.manager.release(parser); super.manager.release(engine); + this.resolver.release(inputSource); + this.resolver.release(contextSource); } } } 1.11 +20 -21 cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/reading/JSPReader.java Index: JSPReader.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/reading/JSPReader.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- JSPReader.java 5 Mar 2004 13:01:57 -0000 1.10 +++ JSPReader.java 24 Apr 2004 01:57:19 -0000 1.11 @@ -32,8 +32,8 @@ import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.jsp.JSPEngine; -import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.http.HttpEnvironment; +import org.apache.excalibur.source.Source; /** * The <code>JSPReader</code> component is used to serve Servlet and JSP page @@ -78,31 +78,30 @@ } JSPEngine engine = null; + Source inputSource = null; + Source contextSource = null; try { - // TODO (KP): Should we exclude not supported protocols, say 'context'? - String url = this.source; + inputSource = this.resolver.resolveURI(this.source); + contextSource = this.resolver.resolveURI("context:/"); - // absolute path is processed as is - if (!url.startsWith("/")) { - // get current request path - String servletPath = servletRequest.getServletPath(); - // remove sitemap URI part - String sitemapURI = ObjectModelHelper.getRequest(objectModel).getSitemapURI(); - if (sitemapURI != null) { - servletPath = servletPath.substring(0, servletPath.indexOf(sitemapURI)); - } else { - // for example when using cocoon:/ pseudo protocol - servletPath = servletPath.substring(0, servletPath.lastIndexOf("/") + 1); - } - url = servletPath + url; + String inputSourceURI = inputSource.getURI(); + String contextSourceURI = contextSource.getURI(); + + if (!inputSourceURI.startsWith(contextSourceURI)) { + throw new ProcessingException("You must not reference a file " + + "outside of the servlet context at " + contextSourceURI + "."); } - engine = (JSPEngine) super.manager.lookup(JSPEngine.ROLE); + String url = inputSourceURI.substring(contextSourceURI.length()); + if (url.charAt(0) != '/') { + url = "/" + url; + } if (getLogger().isDebugEnabled()) { getLogger().debug("JSPReader executing:" + url); } + engine = (JSPEngine) super.manager.lookup(JSPEngine.ROLE); byte[] bytes = engine.executeJSP(url, servletRequest, servletResponse, servletContext); if (this.outputEncoding != null) { @@ -122,9 +121,9 @@ } catch (Exception e) { throw new ProcessingException("Exception JSPReader.generate()", e); } finally { - if (engine != null) { - super.manager.release(engine); - } + super.manager.release(engine); + this.resolver.release(inputSource); + this.resolver.release(contextSource); } } 1.307 +7 -1 cocoon-2.1/status.xml Index: status.xml =================================================================== RCS file: /home/cvs/cocoon-2.1/status.xml,v retrieving revision 1.306 retrieving revision 1.307 diff -u -r1.306 -r1.307 --- status.xml 22 Apr 2004 14:45:56 -0000 1.306 +++ status.xml 24 Apr 2004 01:57:19 -0000 1.307 @@ -212,6 +212,12 @@ <changes> <release version="@version@" date="@date@"> + <action dev="JH" type="fix"> + Hopefully fixed the source resolving in JSP components finally by using + standard Cocoon/Avalon Excalibur source resolving. This allows to use all + known protocols and Cocoon pseudo protocols as long as the JSP file is + inside the servlet's context. + </action> <action dev="MPO" type="update"> [cforms] change to generated instance xml <fi:form>. Nested widgets are now grouped in <fi:widgets> and no longer in <fi:children>.