Author: pier
Date: Wed Nov  3 17:03:08 2004
New Revision: 56545

Added:
   cocoon/whiteboard/kernel/sources/blocks/jasper/src/
   cocoon/whiteboard/kernel/sources/blocks/jasper/src/org/
   cocoon/whiteboard/kernel/sources/blocks/jasper/src/org/apache/
   cocoon/whiteboard/kernel/sources/blocks/jasper/src/org/apache/cocoon/
   cocoon/whiteboard/kernel/sources/blocks/jasper/src/org/apache/cocoon/blocks/
   
cocoon/whiteboard/kernel/sources/blocks/jasper/src/org/apache/cocoon/blocks/jasper/
   
cocoon/whiteboard/kernel/sources/blocks/jasper/src/org/apache/cocoon/blocks/jasper/JasperServlet.java
   cocoon/whiteboard/kernel/sources/webapp/test.jsp
   cocoon/whiteboard/kernel/sources/webapp/test.kjsp
Modified:
   cocoon/whiteboard/kernel/etc/webdefault.xml
   cocoon/whiteboard/kernel/sources/blocks/jasper/cocoon.xml
   cocoon/whiteboard/kernel/sources/webapp/WEB-INF/configuration.xml
   cocoon/whiteboard/kernel/sources/webapp/WEB-INF/web.xml
Log:
Reworking Jasper block after moving JSPs back into the container

Modified: cocoon/whiteboard/kernel/etc/webdefault.xml
==============================================================================
--- cocoon/whiteboard/kernel/etc/webdefault.xml (original)
+++ cocoon/whiteboard/kernel/etc/webdefault.xml Wed Nov  3 17:03:08 2004
@@ -1,39 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 
2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd";>   
+
+<!DOCTYPE web-app
+    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+    "http://java.sun.com/dtd/web-app_2_3.dtd";>
 
 <!-- ===================================================================== -->
 <!-- This file contains the default descriptor for web applications.       -->
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-<!-- The original of this file is included as a resource in the            -->
-<!-- org.mortbay.jetty.jar file and is loaded by default for all web       -->
-<!-- applications before there own WEB-INF/web.xml file is loaded          -->
-<!--                                                                       -->
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-<!-- THE COPY OF THIS FILE in $JETTY_HOME/etc IS NOT USED BY DEFAULT!      -->
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-<!-- If the version in $JETTY_HOME/etc/ is to be used, then the            -->
-<!-- setDefaultsDescriptor method must be called on each context,          -->
-<!-- giving the location of the default web.xml file to use.               -->
-<!-- eg of setting the defaultsDescriptor in jetty.xml:
-
-    <Call name="addWebApplication">
-      <Arg>/mycontext</Arg>
-      <Arg><SystemProperty name="jetty.home" 
default=".">/webapps/mywebapp</Arg>
-      <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" 
default="."/>/etc/webdefault.xml</Set>
-    </Call>
-                                                                           -->
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-
 <!-- ===================================================================== -->
+
 <web-app>
   <description>
-    Default web.xml file.  
     This file is applied to a Web application before it's own WEB_INF/web.xml 
file
   </description>
 
-
-
   <!-- ==================================================================== -->
   <!-- Context params to control Session Cookies                            -->
   <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  -->
@@ -54,8 +33,6 @@
   </context-param>
   -->
 
-
-
   <!-- ==================================================================== -->
   <!-- The default servlet.                                                 -->
   <!-- This servlet, normally mapped to /, provides the handling for static -->
@@ -162,11 +139,11 @@
   <!-- * Set the "jspCompilerPlugin" initialization parameter to            -->
   <!--   "org.apache.jasper.compiler.JikesJavaCompiler".                    -->
   <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  -->
-  <!--servlet>
+  <servlet>
     <servlet-name>jsp</servlet-name>
     <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
     <load-on-startup>0</load-on-startup>
-  </servlet-->
+  </servlet>
 
   <!-- ==================================================================== -->
   <!-- Dynamic Servlet Invoker.                                             -->
@@ -187,7 +164,7 @@
   <!--  *                        All other parameters are copied to the     -->
   <!--                           each dynamic servlet as init parameters    -->
   <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  -->
-  <!--servlet>
+  <servlet>
     <servlet-name>invoker</servlet-name>
     <servlet-class>org.mortbay.jetty.servlet.Invoker</servlet-class>
     <init-param>
@@ -203,7 +180,7 @@
       <param-value>anyValue</param-value>
     </init-param>
     <load-on-startup>0</load-on-startup>
-  </servlet-->
+  </servlet>
 
   <!-- ==================================================================== -->
   <servlet-mapping>
@@ -212,23 +189,16 @@
   </servlet-mapping>
 
   <!-- ==================================================================== -->
-  <!--servlet-mapping>
+  <servlet-mapping>
     <servlet-name>jsp</servlet-name>
     <url-pattern>*.jsp</url-pattern>
-  </servlet-mapping-->
-
-  <!-- ==================================================================== -->
-  <!--servlet-mapping>
-    <servlet-name>jsp</servlet-name>
-    <url-pattern>*.jspf</url-pattern>
-  </servlet-mapping-->
+  </servlet-mapping>
 
   <!-- ==================================================================== -->
-  <!--servlet-mapping>
+  <servlet-mapping>
     <servlet-name>invoker</servlet-name>
     <url-pattern>/servlet/*</url-pattern>
-  </servlet-mapping-->
-
+  </servlet-mapping>
 
   <!-- ==================================================================== -->
   <session-config>
@@ -251,7 +221,6 @@
   <!-- ==================================================================== -->
   <welcome-file-list>
     <welcome-file>index.html</welcome-file>
-    <welcome-file>index.htm</welcome-file>
     <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
 

Modified: cocoon/whiteboard/kernel/sources/blocks/jasper/cocoon.xml
==============================================================================
--- cocoon/whiteboard/kernel/sources/blocks/jasper/cocoon.xml   (original)
+++ cocoon/whiteboard/kernel/sources/blocks/jasper/cocoon.xml   Wed Nov  3 
17:03:08 2004
@@ -3,19 +3,10 @@
 <block xmlns="http://apache.org/cocoon/kernel/descriptor/1.0";
     id="http://cocoon.apache.org/kernel/blocks/jasper/4.1.30";>
 
-  <requirements>
-    <requires module="http://cocoon.apache.org/kernel/modules/ant/1.6.2"/>
-  </requirements>
-
   <implementations>  
     <implements 
interface="http://cocoon.apache.org/kernel/interfaces/servlet/2.3"/>
   </implementations>
 
-  <libraries>
-    <library href="jasper-compiler-4.1.30.jar"/>
-    <library href="jasper-runtime-4.1.30.jar"/>
-  </libraries>
-  
-  <provides component="org.apache.jasper.servlet.JspServlet"/>
+  <provides component="org.apache.cocoon.blocks.jasper.JasperServlet"/>
 
 </block>

Added: 
cocoon/whiteboard/kernel/sources/blocks/jasper/src/org/apache/cocoon/blocks/jasper/JasperServlet.java
==============================================================================
--- (empty file)
+++ 
cocoon/whiteboard/kernel/sources/blocks/jasper/src/org/apache/cocoon/blocks/jasper/JasperServlet.java
       Wed Nov  3 17:03:08 2004
@@ -0,0 +1,150 @@
+/* 
=============================================================================== 
*
+ * Copyright (C) 1999-2004, The Apache Software Foundation.   All rights 
reserved. *
+ *                                                                             
    *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not 
use *
+ * this file except in  compliance with the License.  You may obtain a copy of 
the *
+ * License at <http://www.apache.org/licenses/LICENSE-2.0>.                    
    *
+ *                                                                             
    *
+ * Unless required by applicable law or agreed to in writing, software 
distributed *
+ * under the License  is distributed on an  "AS IS"  BASIS,  WITHOUT 
WARRANTIES OR *
+ * CONDITIONS  OF ANY KIND,  either express  or implied.  See the License  for 
the *
+ * specific language governing permissions and limitations under the License.  
    *
+ * 
=============================================================================== 
*/
+package org.apache.cocoon.blocks.jasper;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.cocoon.kernel.Kernel;
+import org.apache.cocoon.kernel.startup.ServletWrapper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jasper.servlet.JspServlet;
+
+/**
+ * <p>TODO.</p> 
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
+ * @author Copyright &copy; 2000-2004 <a href="http://www.apache.org/";>The 
Apache
+ *         Software Foundation</a>. All rights reserved.
+ */
+public class JasperServlet extends JspServlet {
+
+    /** <p>Our [EMAIL PROTECTED] Log} instance.</p> */
+    private Log log = LogFactory.getLog(JasperServlet.class);
+    /** <p>Our [EMAIL PROTECTED] Kernel} instance, if supplied.</p> */
+    private Kernel kernel = null;
+
+    /**
+     * <p>Create a new [EMAIL PROTECTED] JasperServlet} instance.</p>
+     */
+    public JasperServlet() {
+        super();
+    }
+
+    /**
+     * <p>Receive the [EMAIL PROTECTED] Kernel} instance.</p>
+     */
+    public void setKernel(Kernel kernel) {
+        this.kernel = kernel;
+    }
+
+    /**
+     * <p>Return the [EMAIL PROTECTED] Kernel} instance.</p>
+     */
+    public Kernel getKernel() {
+        return this.kernel;
+    }
+
+    /**
+     * <p>Initialize the servlet wrapped by this [EMAIL PROTECTED] 
ServletWrapper}.</p>
+     */
+    public void init(ServletConfig config)
+    throws ServletException {
+        StringBuffer buffer = new StringBuffer();
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        while (loader != null) {
+            if (!(loader instanceof URLClassLoader)) {
+                loader = loader.getParent();
+                continue;
+            }
+
+            URL urls[] = ((URLClassLoader)loader).getURLs();
+            for (int x = 0 ; x < urls.length; x ++) {
+                try {
+                    if (!("file".equals(urls[x].getProtocol()))) continue;
+                    File file = new File(urls[x].getPath()).getCanonicalFile();
+                    buffer.append(System.getProperty("path.separator"));
+                    buffer.append(file.getPath());
+                    log.debug("Added \"" + file.getPath() + "\"");
+                } catch (Throwable throwable) {
+                    log.error("Exception adding file", throwable);
+                }
+            }
+
+            loader = loader.getParent();
+        }
+
+        String classpath = buffer.substring(1);
+        log.debug("Jasper classpath: " + classpath);
+        super.init(new Config(config, classpath));
+    }
+
+    /**
+     * <p>Service a reques.</p>
+     */
+    public void service(ServletRequest request, ServletResponse response)
+    throws ServletException, IOException {
+        Kernel kernel = this.getKernel();
+        if (kernel != null) request.setAttribute("cocoon-kernel", kernel);
+        super.service(request, response);
+    }
+    
+    /**
+     * <p>A simple [EMAIL PROTECTED] ServletConfig} wrapper.</p>
+     */
+    private static final class Config implements ServletConfig {
+        
+        ServletConfig instance = null;
+        String classpath = null;
+        
+        private Config(ServletConfig instance, String classpath) {
+            this.classpath = classpath;
+            this.instance = instance;
+        }
+
+        public String getServletName() {
+            return this.instance.getServletName();
+        }
+
+        public ServletContext getServletContext() {
+            return this.instance.getServletContext();
+        }
+
+        public String getInitParameter(String arg0) {
+            if ("classpath".equals(arg0)) return(this.classpath);
+            return this.instance.getInitParameter(arg0);
+        }
+
+        public Enumeration getInitParameterNames() {
+            Vector vector = new Vector();
+            Enumeration enum = this.instance.getInitParameterNames();
+            while (enum.hasMoreElements()) vector.add(enum.nextElement());
+            vector.add("classpath");
+            return vector.elements();
+        }
+    }
+}

Modified: cocoon/whiteboard/kernel/sources/webapp/WEB-INF/configuration.xml
==============================================================================
--- cocoon/whiteboard/kernel/sources/webapp/WEB-INF/configuration.xml   
(original)
+++ cocoon/whiteboard/kernel/sources/webapp/WEB-INF/configuration.xml   Wed Nov 
 3 17:03:08 2004
@@ -15,7 +15,6 @@
   <descriptor href="kernel/interfaces/servlet/cocoon.xml"/>
 
   <!-- The abstract descriptors available to this kernel -->
-  <descriptor href="kernel/modules/ant/cocoon.xml"/>
   <descriptor href="kernel/modules/commons-collections/cocoon.xml"/>
   <descriptor href="kernel/modules/commons-pool/cocoon.xml"/>
 
@@ -35,4 +34,8 @@
     <set property="maxActive" value="5"/>
   </instance>
   
+  <instance name="jasper"  
block="http://cocoon.apache.org/kernel/blocks/jasper/4.1.30";>
+    <set property="kernel" kernel="true"/>
+  </instance>
+
 </configuration>

Modified: cocoon/whiteboard/kernel/sources/webapp/WEB-INF/web.xml
==============================================================================
--- cocoon/whiteboard/kernel/sources/webapp/WEB-INF/web.xml     (original)
+++ cocoon/whiteboard/kernel/sources/webapp/WEB-INF/web.xml     Wed Nov  3 
17:03:08 2004
@@ -1,38 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-  Copyright 1999-2004 The Apache Software Foundation
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-
-<!--+
-    | This is the Cocoon web-app configurations file
-    +-->
 
 <!DOCTYPE web-app
     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
-    "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd";>
+    "http://java.sun.com/dtd/web-app_2_3.dtd";>
 
 <web-app>
 
-  <!-- Context Configuration ========================================== -->
-
-  <!--+
-      | Set a context property useful to allow you to ProxyPass your
-      | web application mounted to a different URI without loosing the
-      | ability to do cookie-based sessions.
-      | WARNING: this is Jetty specific!
-      +-->
   <context-param>
     <param-name>kernel-configuration</param-name>
     <param-value>/WEB-INF/configuration.xml</param-value>
@@ -41,6 +14,40 @@
   <listener>
     
<listener-class>org.apache.cocoon.kernel.startup.ServletLoader</listener-class>
   </listener>
+
+  <servlet>
+    <servlet-name>jasper</servlet-name>
+    
<servlet-class>org.apache.cocoon.kernel.startup.ServletWrapper</servlet-class>
+    <init-param>
+      <param-name>block-instance</param-name>
+      <param-value>jasper</param-value>
+    </init-param>
+    <init-param>
+      <param-name>supply-kernel</param-name>
+      <param-value>true</param-value>
+    </init-param>
+    <init-param>
+      <param-name>logVerbosityLevel</param-name>
+      <param-value>debug</param-value>
+    </init-param>
+    <!--init-param>
+      <param-name>classpath</param-name>
+      
<param-value>/Users/pier/Workspace/ivory/webapps/root/WEB-INF/kernel/blocks/commons-dbcp/commons-dbcp-1.2.1.jar:/Users/pier/Workspace/ivory/webapps/root/WEB-INF/kernel/cocoon-kernel-runtime-0.1.jar:/Users/pier/Workspace/ivory/webapps/root/WEB-INF/kernel/extensions/logging/commons-logging-1.0.4.jar:/Users/pier/Workspace/ivory/webapps/root/WEB-INF/kernel/extensions/logging/local.jar:/Users/pier/Workspace/ivory/webapps/root/WEB-INF/kernel/extensions/logging/log4j-1.2.9.jar:/Users/pier/Workspace/ivory/webapps/root/WEB-INF/kernel/modules/commons-collections/commons-collections-3.1.jar:/Users/pier/Workspace/ivory/webapps/root/WEB-INF/kernel/modules/commons-pool/commons-pool-1.2.jar:/Users/pier/Workspace/ivory/webapps/root/WEB-INF/lib/cocoon-kernel-startup-0.1.jar</param-value>
+    </init-param-->
+
+    <load-on-startup>0</load-on-startup>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>jasper</servlet-name>
+    <url-pattern>*.kjsp</url-pattern>
+  </servlet-mapping>
+
+  <welcome-file-list>
+    <welcome-file>index.html</welcome-file>
+    <welcome-file>index.kjsp</welcome-file>
+    <welcome-file>index.jsp</welcome-file>
+  </welcome-file-list>
 
 </web-app>
 

Added: cocoon/whiteboard/kernel/sources/webapp/test.jsp
==============================================================================
--- (empty file)
+++ cocoon/whiteboard/kernel/sources/webapp/test.jsp    Wed Nov  3 17:03:08 2004
@@ -0,0 +1,10 @@
+<%@ page session="false" %>
+
+<html>
+  <head>
+    <title>Hello world!</title>
+  </head>
+  <body>
+    <% out.println("Hello world from a normal JSP!"); %>
+  </body>
+</html>
\ No newline at end of file

Added: cocoon/whiteboard/kernel/sources/webapp/test.kjsp
==============================================================================
--- (empty file)
+++ cocoon/whiteboard/kernel/sources/webapp/test.kjsp   Wed Nov  3 17:03:08 2004
@@ -0,0 +1,19 @@
+<%@ page session="false" %>
+<%@ page import="org.apache.cocoon.kernel.Kernel" %>
+
+<html>
+  <head>
+    <title>This page has been generated by the kernel</title>
+  </head>
+  <body>
+    <% 
+      out.println("Hello world from inside the kernel!<br />");
+      Kernel kernel = (Kernel) request.getAttribute("cocoon-kernel");
+      if (kernel == null) {
+        out.println("The Kernel instance has not been supplied.");
+      } else {
+        out.println("The Kernel is " + kernel.getClass().getName());
+      }
+    %>
+  </body>
+</html>
\ No newline at end of file

Reply via email to