Return-Path: Delivered-To: apmail-xml-cocoon-cvs-archive@xml.apache.org Received: (qmail 49447 invoked by uid 500); 16 Jul 2001 13:35:53 -0000 Mailing-List: contact cocoon-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: cocoon-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cocoon-cvs@xml.apache.org Received: (qmail 49436 invoked by uid 500); 16 Jul 2001 13:35:53 -0000 Delivered-To: apmail-xml-cocoon2-cvs@apache.org Date: 16 Jul 2001 13:35:13 -0000 Message-ID: <20010716133513.91595.qmail@icarus.apache.org> From: dims@apache.org To: xml-cocoon2-cvs@apache.org Subject: cvs commit: xml-cocoon2/webapp cocoon.xconf sitemap.xmap X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N dims 01/07/16 06:35:13 Modified: src/org/apache/cocoon cocoon.roles src/org/apache/cocoon/components/language/generator ProgramGeneratorImpl.java src/org/apache/cocoon/generation JspGenerator.java webapp cocoon.xconf sitemap.xmap Log: Componentize the JSP Engine. Revision Changes Path 1.16 +5 -1 xml-cocoon2/src/org/apache/cocoon/cocoon.roles Index: cocoon.roles =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/cocoon.roles,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- cocoon.roles 2001/07/07 11:43:11 1.15 +++ cocoon.roles 2001/07/16 13:35:12 1.16 @@ -16,7 +16,7 @@ shorthand="store" default-class="org.apache.cocoon.components.store.MemoryStore"/> - @@ -40,6 +40,10 @@ + + ProgramGenerator * @author Ricardo Rocha - * @version CVS $Revision: 1.10 $ $Date: 2001/07/13 19:07:32 $ + * @version CVS $Revision: 1.11 $ $Date: 2001/07/16 13:35:12 $ */ public class ProgramGeneratorImpl extends AbstractLoggable implements ProgramGenerator, Contextualizable, Composable, Configurable, ThreadSafe, Disposable { @@ -118,7 +118,7 @@ public void configure(Configuration conf) throws ConfigurationException { Parameters params = Parameters.fromConfiguration(conf); this.autoReload = params.getParameterAsBoolean("auto-reload", autoReload); - this.rootPackage = params.getParameter("root-package", "org.apache.cocoon"); + this.rootPackage = params.getParameter("root-package", "org.apache.cocoon.www"); this.preload = params.getParameterAsBoolean("preload", preload); } 1.12 +16 -218 xml-cocoon2/src/org/apache/cocoon/generation/JspGenerator.java Index: JspGenerator.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/generation/JspGenerator.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- JspGenerator.java 2001/07/16 11:47:20 1.11 +++ JspGenerator.java 2001/07/16 13:35:13 1.12 @@ -7,107 +7,71 @@ *****************************************************************************/ package org.apache.cocoon.generation; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.OutputStream; import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.PrintWriter; -import java.security.Principal; -import java.util.Enumeration; -import java.util.Locale; +import java.io.IOException; import java.util.Map; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpSession; -import javax.servlet.Servlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.avalon.framework.component.Component; +import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.logger.AbstractLoggable; import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.components.jsp.JSPEngine; import org.apache.cocoon.components.parser.Parser; import org.apache.cocoon.environment.http.HttpEnvironment; import org.apache.cocoon.xml.AbstractXMLProducer; import org.apache.cocoon.xml.XMLProducer; -import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.log.Logger; import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** * Allows JSP to be used as a generator. Builds upon the JSP servlet - * functionallity - overrides the output method in order to pipe the + * functionality - overrides the output method in order to pipe the * results into SAX events. * * @author Davanum Srinivas - * @version CVS $Revision: 1.11 $ $Date: 2001/07/16 11:47:20 $ + * @version CVS $Revision: 1.12 $ $Date: 2001/07/16 13:35:13 $ */ public class JspGenerator extends ServletGenerator implements Recyclable, Configurable { - /** The Servlet Include Path */ - public static final String INC_SERVLET_PATH = "javax.servlet.include.servlet_path"; - - /** The Default Servlet Class Name for Tomcat 3.X and 4.X*/ - public static final String DEFAULT_SERVLET_CLASS = "org.apache.jasper.servlet.JspServlet"; - - /** Servlet Class Name */ - public String jspServletClass = DEFAULT_SERVLET_CLASS; - public void configure(Configuration conf) throws ConfigurationException { - if (conf != null) - { - Configuration child = conf.getChild("jsp-servlet-class"); - this.jspServletClass = child.getValue(DEFAULT_SERVLET_CLASS); - getLogger().debug("JspServlet class is " + this.jspServletClass); - } } /** * Generate XML data from JSP. */ - public void generate() throws IOException, SAXException, ProcessingException { + public void generate() throws ProcessingException { // ensure that we are running in a servlet environment HttpServletResponse httpResponse = (HttpServletResponse)this.objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT); HttpServletRequest httpRequest = (HttpServletRequest)this.objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT); - if (httpResponse == null || httpRequest == null) { - throw new ProcessingException("HttpServletRequest or HttpServletResponse object not available"); + ServletContext httpContext = + (ServletContext)this.objectModel.get(HttpEnvironment.HTTP_SERVLET_CONTEXT); + + if (httpResponse == null || httpRequest == null || httpContext == null) { + throw new ProcessingException("HttpServletRequest or HttpServletResponse or ServletContext object not available"); } + JSPEngine engine = null; Parser parser = null; try { - MyServletRequest request = new MyServletRequest(httpRequest, this.source); - MyServletResponse response = new MyServletResponse(httpResponse); - - // start JSPServlet. - Class clazz = Thread.currentThread().getContextClassLoader().loadClass(this.jspServletClass); - Servlet jsp = (Servlet) clazz.newInstance(); - jsp.init(new config((ServletContext)this.objectModel.get(HttpEnvironment.HTTP_SERVLET_CONTEXT))); - jsp.service(request, response); - - byte[] bytes = response.toByteArray(); + engine = (JSPEngine)this.manager.lookup(JSPEngine.ROLE); + byte[] bytes = engine.executeJSP(this.source, httpRequest, httpResponse, httpContext); ByteArrayInputStream input = new ByteArrayInputStream(bytes); // pipe the results into the parser parser = (Parser)this.manager.lookup(Parser.ROLE); parser.setConsumer(this.xmlConsumer); parser.parse(new InputSource(input)); - - // clean up - jsp.destroy(); } catch (ServletException e) { getLogger().debug("ServletException in JspGenerator.generate()", e); getLogger().debug("Embedded ServletException JspGenerator.generate()", e.getRootCause()); @@ -118,178 +82,12 @@ throw new ProcessingException("SAXException JspGenerator.generate()",e.getException()); } catch (IOException e) { getLogger().debug("IOException in JspGenerator.generate()", e); - throw e; + throw new ProcessingException("IOException JspGenerator.generate()",e); } catch (Exception e) { getLogger().debug("Exception in JspGenerator.generate()", e); - throw new SAXException(e); + throw new ProcessingException("Exception JspGenerator.generate()",e); } finally { if (parser != null) this.manager.release(parser); } } - - /** - * Stub implementation of Servlet Config - */ - class config implements ServletConfig { - ServletContext c; - public config(ServletContext c) {this.c = c; } - - public String getServletName() { return "JspGenerator"; } - public Enumeration getInitParameterNames() - { return c.getInitParameterNames(); } - public ServletContext getServletContext() { return c; } - public String getInitParameter(String name) { return null; } - } - - /** - * Stub implementation of HttpServletRequest - */ - class MyServletRequest implements HttpServletRequest { - HttpServletRequest request; - String jspFile; - - public MyServletRequest(HttpServletRequest request, String jspFile) { - this.request = request; - this.jspFile = jspFile; - } - public String getAuthType(){ return request.getAuthType(); } - public Cookie[] getCookies(){ return request.getCookies(); } - public long getDateHeader(String s){ return request.getDateHeader(s); } - public String getHeader(String s){ return request.getHeader(s); } - public Enumeration getHeaders(String s){ return request.getHeaders(s); } - public Enumeration getHeaderNames(){ return request.getHeaderNames(); } - public int getIntHeader(String s){ return request.getIntHeader(s); } - public String getMethod(){ return request.getMethod(); } - public String getPathInfo(){ return request.getPathInfo(); } - public String getPathTranslated(){ return request.getPathTranslated(); } - public String getContextPath(){ return request.getContextPath(); } - public String getQueryString(){ return request.getQueryString(); } - public String getRemoteUser(){ return request.getRemoteUser(); } - public boolean isUserInRole(String s){ return request.isUserInRole(s); } - public Principal getUserPrincipal(){ return request.getUserPrincipal(); } - public String getRequestedSessionId(){ return request.getRequestedSessionId(); } - public String getRequestURI(){ return request.getRequestURI(); } - public String getServletPath(){ return request.getServletPath(); } - public HttpSession getSession(boolean flag){ return request.getSession(flag); } - public HttpSession getSession(){ return request.getSession(); } - public boolean isRequestedSessionIdValid(){ return request.isRequestedSessionIdValid(); } - public boolean isRequestedSessionIdFromCookie(){ return request.isRequestedSessionIdFromCookie(); } - public boolean isRequestedSessionIdFromURL(){ return request.isRequestedSessionIdFromURL(); } - public boolean isRequestedSessionIdFromUrl(){ return request.isRequestedSessionIdFromUrl(); } - public Object getAttribute(String s){ - if(s != null && s.equals(INC_SERVLET_PATH)) - return jspFile; - return request.getAttribute(s); - } - public Enumeration getAttributeNames(){ return request.getAttributeNames(); } - public String getCharacterEncoding(){ return request.getCharacterEncoding(); } - public int getContentLength(){ return request.getContentLength(); } - public String getContentType(){ return request.getContentType(); } - public ServletInputStream getInputStream() throws IOException{ return request.getInputStream(); } - public String getParameter(String s){ return request.getParameter(s); } - public Enumeration getParameterNames(){ return request.getParameterNames(); } - public String[] getParameterValues(String s){ return request.getParameterValues(s); } - public String getProtocol(){ return request.getProtocol(); } - public String getScheme(){ return request.getScheme(); } - public String getServerName(){ return request.getServerName(); } - public int getServerPort(){ return request.getServerPort(); } - public BufferedReader getReader() - throws IOException{ return request.getReader(); } - public String getRemoteAddr(){ return request.getRemoteAddr(); } - public String getRemoteHost(){ return request.getRemoteHost(); } - public void setAttribute(String s, Object obj){ request.setAttribute(s,obj); } - public void removeAttribute(String s){ request.removeAttribute(s); } - public Locale getLocale(){ return request.getLocale(); } - public Enumeration getLocales(){ return request.getLocales(); } - public boolean isSecure(){ return request.isSecure(); } - public RequestDispatcher getRequestDispatcher(String s){ return request.getRequestDispatcher(s); } - public String getRealPath(String s){ return request.getRealPath(s); } - public java.lang.StringBuffer getRequestURL() { return null; } - public java.util.Map getParameterMap() { return null; } - public void setCharacterEncoding(java.lang.String $1) { } - } - - /** - * Stub implementation of HttpServletResponse - */ - class MyServletResponse implements HttpServletResponse { - HttpServletResponse response; - MyServletOutputStream output; - - public MyServletResponse(HttpServletResponse response){ - this.response = response; - this.output = new MyServletOutputStream(); - } - public void flushBuffer() throws IOException { } - public int getBufferSize() { return 1024; } - public String getCharacterEncoding() { return this.response.getCharacterEncoding();} - public Locale getLocale(){ return this.response.getLocale();} - public PrintWriter getWriter() { - return this.output.getWriter(); - } - public boolean isCommitted() { return false; } - public void reset() {} - public void setBufferSize(int size) {} - public void setContentLength(int len) {} - public void setContentType(java.lang.String type) {} - public void setLocale(java.util.Locale loc) {} - public ServletOutputStream getOutputStream() { - return this.output; - } - public void addCookie(Cookie cookie){ response.addCookie(cookie); } - public boolean containsHeader(String s){ return response.containsHeader(s); } - public String encodeURL(String s){ return response.encodeURL(s); } - public String encodeRedirectURL(String s){ return response.encodeRedirectURL(s); } - public String encodeUrl(String s){ return response.encodeUrl(s); } - public String encodeRedirectUrl(String s){ return response.encodeRedirectUrl(s); } - public void sendError(int i, String s) - throws IOException{response.sendError(i,s); } - public void sendError(int i) - throws IOException{response.sendError(i); } - public void sendRedirect(String s) - throws IOException{response.sendRedirect(s); } - public void setDateHeader(String s, long l){response.setDateHeader(s, l); } - public void addDateHeader(String s, long l){response.addDateHeader(s, l); } - public void setHeader(String s, String s1){response.setHeader(s, s1); } - public void addHeader(String s, String s1){response.addHeader(s, s1); } - public void setIntHeader(String s, int i){response.setIntHeader(s, i); } - public void addIntHeader(String s, int i){response.addIntHeader(s, i); } - public void setStatus(int i){response.setStatus(i); } - public void setStatus(int i, String s){response.setStatus(i, s); } - public void resetBuffer(){} - - public byte[] toByteArray() { - return output.toByteArray(); - } - } - - /** - * Stub implementation of ServletOutputStream - */ - class MyServletOutputStream extends ServletOutputStream { - ByteArrayOutputStream output; - PrintWriter writer; - - public MyServletOutputStream() { - this.output = new ByteArrayOutputStream(); - this.writer = new PrintWriter(output, true); - } - public PrintWriter getWriter() { - return this.writer; - } - public void write(byte[] b) throws java.io.IOException { - output.write(b); - } - public void write(byte[] b, int off, int len) throws java.io.IOException { - output.write(b,off,len); - } - public void write(int b) throws java.io.IOException { - output.write(b); - } - public byte[] toByteArray() { - this.writer.flush(); - byte[] bytes = output.toByteArray(); - return bytes; - } - } } 1.19 +4 -0 xml-cocoon2/webapp/cocoon.xconf Index: cocoon.xconf =================================================================== RCS file: /home/cvs/xml-cocoon2/webapp/cocoon.xconf,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- cocoon.xconf 2001/07/13 20:47:46 1.18 +++ cocoon.xconf 2001/07/16 13:35:13 1.19 @@ -66,6 +66,10 @@ + + + +