Author: apetrelli
Date: Tue Dec  4 11:42:08 2007
New Revision: 601059

URL: http://svn.apache.org/viewvc?rev=601059&view=rev
Log:
TILES-231
Removed the "doInclude" method in JspUtil and replaced the code with 
pageContext.include.

Modified:
    
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java
    
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspUtil.java
    
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java

Modified: 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java?rev=601059&r1=601058&r2=601059&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java
 (original)
+++ 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java
 Tue Dec  4 11:42:08 2007
@@ -26,10 +26,10 @@
 import org.apache.tiles.servlet.context.ServletTilesRequestContext;
 
 import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.PageContext;
-import javax.servlet.jsp.JspException;
 import java.io.IOException;
 
 /**
@@ -86,9 +86,9 @@
     public void include(String path) throws IOException {
         JspUtil.setForceInclude(pageContext, true);
         try {
-            JspUtil.doInclude(pageContext, path, false);
-        } catch (JspException e) {
-            LOG.error("JSPException while including path '" + path + "'. ", e);
+            pageContext.include(path, false);
+        } catch (ServletException e) {
+            LOG.error("ServletException while including path '" + path + "'. 
", e);
             throw new IOException("JSPException while including path '" + path
                     + "'. " + e.getMessage());
         }

Modified: 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspUtil.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspUtil.java?rev=601059&r1=601058&r2=601059&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspUtil.java
 (original)
+++ 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspUtil.java
 Tue Dec  4 11:42:08 2007
@@ -20,16 +20,9 @@
  */
 package org.apache.tiles.jsp.context;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.tiles.servlet.context.ServletUtil;
 
-import javax.servlet.ServletException;
-import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.PageContext;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 
 /**
  * Utility class for working within a Jsp environment.
@@ -42,67 +35,6 @@
      * Constructor, private to avoid instantiation.
      */
     private JspUtil() {
-    }
-
-    /**
-     * The logging object.
-     */
-    private static final Log LOG =
-        LogFactory.getLog(JspUtil.class);
-
-    /**
-     * JSP 2.0 include method to use which supports configurable flushing.
-     */
-    private static Method include = null;
-
-    /**
-     * Initialize the include variable with the
-     * JSP 2.0 method if available.
-     */
-    static {
-        try {
-            // get version of include method with flush argument
-            Class<?>[] args = new Class<?>[]{String.class, boolean.class};
-            include = PageContext.class.getMethod("include", args);
-        } catch (NoSuchMethodException e) {
-            LOG.debug("Could not find JSP 2.0 include method.  Using old one 
that doesn't support "
-                    + "configurable flushing.", e);
-        }
-    }
-
-    /**
-     * Includes an URI in the JSP response.
-     *
-     * @param pageContext The page context to use.
-     * @param uri The URI to include.
-     * @param flush <code>true</code> means that the buffer should be flushed 
at
-     * the end of this operation
-     * @throws JspException If an underlying exception happens.
-     */
-    public static void doInclude(PageContext pageContext, String uri, boolean 
flush)
-        throws JspException {
-
-        try {
-            // perform include with new JSP 2.0 method that supports flushing
-            if (include != null) {
-                include.invoke(pageContext, uri, flush);
-                return;
-            }
-        } catch (IllegalAccessException e) {
-            LOG.debug("Could not find JSP 2.0 include method.  Using old 
one.", e);
-        } catch (InvocationTargetException e) {
-            LOG.debug("Unable to execute JSP 2.0 include method.  Trying old 
one.", e);
-        }
-
-
-        try {
-            pageContext.include(uri);
-        } catch (IOException e) {
-            throw new JspException("IOException while including page.", e);
-        } catch (ServletException e) {
-            throw new JspException("ServletException while including page.", 
e);
-        }
-
     }
 
     /**

Modified: 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java?rev=601059&r1=601058&r2=601059&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java
 (original)
+++ 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java
 Tue Dec  4 11:42:08 2007
@@ -21,8 +21,11 @@
 
 package org.apache.tiles.jsp.taglib;
 
+import java.io.IOException;
+
 import org.apache.tiles.jsp.context.JspUtil;
 
+import javax.servlet.ServletException;
 import javax.servlet.jsp.JspException;
 
 /**
@@ -65,6 +68,18 @@
         // facility will be available, so it can be managed by the Tiles
         // container.
         JspUtil.setForceInclude(pageContext, true);
-        JspUtil.doInclude(pageContext, template, flush);
+        try {
+            pageContext.include(template, flush);
+        } catch (ServletException e) {
+            Throwable rootCause = e.getRootCause();
+            if (rootCause != null) {
+                // Replace the ServletException with a JspException
+                throw new JspException(rootCause);
+            } else {
+                throw new JspException(e);
+            }
+        } catch (IOException e) {
+            throw new JspException(e);
+        }
     }
 }


Reply via email to