My apologies James. See attached again. JellyServletContext is new. I
believe I attached it the last time round.

On Mon, 16 Dec 2002 16:26:14 -0000, James Strachan said:
>Hi Kelvin
>
>Any chance you could resend your patch by using the command
>
>cvs diff -u File >> patch.txt
>
>http://jakarta.apache.org/commons/patches.html
>
>
>I'll just help me be able to apply it.
>
>James -------
>http://radio.weblogs.com/0112098/ ----- Original Message -----
>From: "Kelvin Tan" <[EMAIL PROTECTED]> To: "Jakarta Commons
>Developers List" <commons-
>[EMAIL PROTECTED]> Sent: Wednesday, December 11, 2002 6:46 AM
>Subject: Re: [Jelly] JellyServlet
>
>
>James,
>
>On Mon, 9 Dec 2002 15:18:21 -0000, James Strachan said:
>>Thanks for the patch Kelvin, I've committed it to CVS.
>>
>>I made a minor patch so that the URI itself could denote the script
>>to run.
>>So you could just run http://localhost:8080/foo/index.jelly for
>>example, rather than requiring a template=index.jelly query
>>parameter..
>
>That's nice. I have changed the parameter "template" to "script".
>Its just that I'm so used to using Velocity. The patch you made uses
>getServletPath, which returns the url of the servlet being called.
>I've changed it to getPathInfo.
>
>Another thing. Is it really appropriate to require all scripts to be
>located beneath the web app's context root (which getResource does)?
>The previous impl using new File(script).getUrl had no such
>limitation...
>
>>
>>Some thoughts for further improvement could be...
>>
>>* implement a JellyServletContext so that the getResource() method
>>will use the ServletContext.getResource() method and allow access
>>of relative URIs when performing <j:include>'s.
>
>done.
>
>>
>>* have a parent JellyServletContext to allow access to the
>>initParams of the ServletContext via variable expressions
>>
>
>?
>
>>* implement the JSTL mappings of request parameters, session
>>parameters, cookies etc in the expression language.
>>
>>* it'd be nice to have a cache of Jelly Scripts to avoid parsing
>>them each time! :-)
>>
>
>Here's something which is a little surprise. So it means Jelly is
>not internally caching scripts? This has some implications for usage
>of Jelly as a templating subsystem for high-load systems, I imagine.
>
>In any event, perhaps it would be a better idea to cache at the
>engine level, rather than the servlet level, no?
>
>See attached for patch to JellyServlet and JellyServletContext.
>
>Regards, Kelvin
>
>--------
>The book giving manifesto     - http://how.to/sharethisbook
>
>
>
>
>
>---------------------------------------------------------------------
>-------
>----
>
>
>>--
>>To unsubscribe, e-mail:
><mailto:[EMAIL PROTECTED]>
>>For additional commands, e-mail:
><mailto:[EMAIL PROTECTED]>
>
>__________________________________________________ Do You Yahoo!?
>Everything you'll ever need on one web page from News and Sport to
>Email and Music Charts http://uk.my.yahoo.com
>
>--
>To unsubscribe, e-mail:   <mailto:commons-dev-
>[EMAIL PROTECTED]> For additional commands, e-mail:
><mailto:commons-dev-
>[EMAIL PROTECTED]>


Index: JellyServlet.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/servlet/JellyServlet.java,v

retrieving revision 1.1
diff -u -r1.1 JellyServlet.java
--- JellyServlet.java   9 Dec 2002 15:18:26 -0000       1.1
+++ JellyServlet.java   17 Dec 2002 00:40:33 -0000
@@ -1,5 +1,5 @@
 /*
- * $Header: 
/home/cvspublic/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/servlet/JellyServlet.java,v
 1.1 2002/12/09 15:18:26 jstrachan Exp $
+ * $Header: 
+/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/servlet/JellyServlet.java,v
+ 1.1 2002/12/09 15:18:26 jstrachan Exp $
  * $Revision: 1.1 $
  * $Date: 2002/12/09 15:18:26 $
  *
@@ -56,13 +56,12 @@
  * individuals on behalf of the Apache Software Foundation.  For more
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
- * 
+ *
  * $Id: JellyServlet.java,v 1.1 2002/12/09 15:18:26 jstrachan Exp $
  */
 
 package org.apache.commons.jelly.servlet;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -81,8 +80,8 @@
 
 /**
  * Servlet for handling display of Jelly-fied XML files. Modelled after 
VelocityServlet.
- * 
- * @author Kelvin Tan
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]";>Kelvin Tan</a>
  * @version $Revision: 1.1 $
  */
 public class JellyServlet extends HttpServlet {
@@ -96,11 +95,11 @@
         */
        public static final String RESPONSE = "response";
 
-       protected void doGet(
+    protected void doGet(
                HttpServletRequest request,
                HttpServletResponse response)
                throws ServletException, IOException {
-                       
+
                doRequest(request, response);
        }
 
@@ -108,7 +107,7 @@
                HttpServletRequest request,
                HttpServletResponse response)
                throws ServletException, IOException {
-                       
+
                doRequest(request, response);
        }
 
@@ -121,11 +120,11 @@
         */
        protected void doRequest(HttpServletRequest req, HttpServletResponse res)
                throws ServletException, IOException {
-                       
+
                JellyContext context = createContext(req, res);
-               URL template = getTemplate(req);
                try {
-                       runScript(template, context, req, res);
+            URL script = getScript(req);
+                       runScript(script, context, req, res);
                }
                catch (Exception e) {
                        error(req, res, e);
@@ -141,27 +140,39 @@
        protected JellyContext createContext(
                HttpServletRequest req,
                HttpServletResponse res) {
-                       
-               JellyContext ctx = new JellyContext();
+
+               JellyContext ctx = new JellyServletContext(getServletContext());
                ctx.setVariable(REQUEST, req);
                ctx.setVariable(RESPONSE, res);
                return ctx;
        }
 
        /**
+     * <p>
+     * Either use the query parameter "script", or the URI itself
+     * to denote the script to run.
+     * </p>
+     * <p>
+     * Example: script=index.jelly or http://localhost:8080/foo/index.jelly.
+     * </p>
+     *
         * @see org.apache.velocity.servlet.VelocityServlet#getTemplate
         * @param req
         * @return
         * @throws MalformedURLException
         */
-       protected URL getTemplate(HttpServletRequest req)
+       protected URL getScript(HttpServletRequest req)
                throws MalformedURLException {
-                       
-               String script = req.getParameter("template");
-               if (script == null) {
-                       script = req.getServletPath();
+
+               String scriptUrl = req.getParameter("script");
+               if (scriptUrl == null) {
+                       scriptUrl = req.getPathInfo();
                }
-               return getServletContext().getResource(script);
+               URL url = getServletContext().getResource(scriptUrl);
+        if (url == null) {
+            throw new IllegalArgumentException("Invalid script url:" + scriptUrl);
+        }
+        return url;
        }
 
        /**
@@ -180,7 +191,7 @@
                HttpServletRequest req,
                HttpServletResponse res)
                throws IOException, UnsupportedEncodingException, Exception {
-                       
+
                ServletOutputStream output = res.getOutputStream();
                XMLOutput xmlOutput = XMLOutput.createXMLOutput(output);
                context.runScript(script, xmlOutput);
@@ -205,12 +216,12 @@
                HttpServletResponse response,
                Exception cause)
                throws ServletException, IOException {
-                       
+
                StringBuffer html = new StringBuffer();
                html.append("<html>");
                html.append("<title>Error</title>");
                html.append("<body bgcolor=\"#ffffff\">");
-               html.append("<h2>JellyServlet : Error processing the template</h2>");
+               html.append("<h2>JellyServlet : Error processing the script</h2>");
                html.append("<pre>");
                String why = cause.getMessage();
                if (why != null && why.trim().length() > 0) {
--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to