webwork/src/main/webwork/view/taglib BasicPropertyTag.java,1.7,1.8 URLTag.java,1.23,1.24

[email protected] Mon, 28 Feb 2005 10:44:01 -0800
Newsgroups gmane.comp.java.open-symphony.cvs
Message-ID <[email protected]>
Update of /cvsroot/opensymphony/webwork/src/main/webwork/view/taglib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32149/src/main/webwork/view/taglib

Modified Files:
	BasicPropertyTag.java URLTag.java 
Log Message:
Wrap IOExceptions correctly in tags
Unwrap InvocationTargetExceptions in VS so we can actually see the underlying error

Index: BasicPropertyTag.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/view/taglib/BasicPropertyTag.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- BasicPropertyTag.java	6 Nov 2003 14:23:54 -0000	1.7
+++ BasicPropertyTag.java	28 Feb 2005 18:43:29 -0000	1.8
@@ -1,160 +1,158 @@
-/*
- * WebWork, Web Application Framework
- *
- * Distributable under Apache license.
- * See terms of license at opensource.org
- */
-package webwork.view.taglib;
-
-import webwork.util.TextUtil;
-import webwork.util.BeanUtil;
-
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.JspTagException;
-import javax.servlet.jsp.PageContext;
-import java.util.Iterator;
-
-import org.apache.commons.logging.*;
-
-/**
- *  Access the value of a named property. By default (implicitly),
- *  this tag will escape its contents if it does *not* have a body.
- *  If it does have a body, the tag will not escape the contents.
- *  You can explicitly tell the tag to escape or not.
- *  Quoted text that is escaped will have its quotes stripped off.
- *
- * @author Rickard Öberg ([email protected])
- * @author Matt Baldree ([email protected])
- * @version $Revision$
- */
-public class BasicPropertyTag
-      extends WebWorkBodyTagSupport
-{
-   protected static Log log = LogFactory.getLog(BasicPropertyTag.class);
-
-   // Attributes ----------------------------------------------------
-   protected String valueAttr;
-   protected Boolean escape;
-   protected boolean hadBody;
-
-   // Public --------------------------------------------------------
-   public void setValue(String inName)
-   {
-      valueAttr = inName;
-   }
-
-   public void setEscape(boolean inEscape)
-   {
-      escape = new Boolean(inEscape);
-   }
-
-   // BodyTag implementation ----------------------------------------
-   public int doStartTag() throws JspException
-   {
-      hadBody = false;
-      Object value = findValue(valueAttr);
-      getStack().pushValue(value);
-
-      String id = getId();
-      if (id != null && value != null) {
-         pageContext.setAttribute(id, value);
-         pageContext.setAttribute(id, value, PageContext.REQUEST_SCOPE);
-      }
-      return EVAL_BODY_BUFFERED;
-   }
-
-   public int doAfterBody() throws JspException
-   {
-      // This is a workaround for a bug in Jasper.
-      // http://znutar.cortexity.com/BugRatViewer/ShowReport/652
-      // Resin 1.2.1 also has this bug (i.e. body is called even though it is empty)
-
-      // If the bodyContent is null then just return
-      if (bodyContent == null)
-         return SKIP_BODY;
-      String body = null;
-      try {
-         body = bodyContent.getString();
-      } catch (Exception e) {
-         //do nothing - leave body as null
-      }
-
-      //Added null check - Fixes WW-195 on Resin.
-      hadBody = body != null && body.length() != 0;
-
-      if (hadBody) {
-         try {
-            if (shouldEscape()) {
-               body = TextUtil.escapeHTML(body);
-            }
-            bodyContent.getEnclosingWriter().write(body);
-         } catch (java.io.IOException e) {
-            throw new JspTagException("Could not show attribute " + valueAttr + ":" + e);
-         }
-      }
-      return SKIP_BODY;
-   }
-
-   public int doEndTag() throws JspException
-   {
-      Object value = getStack().popValue();
-
-      if (!hadBody) {
-         // No body used. This means that we want to print the parameter out
-         try {
-            //LogFactory.getLog(this.getClass()).debug("Property value:"+value);
-            if (value != null && getId() == null)
-               if (value instanceof Iterator) {
-                  Iterator enum = (Iterator) value;
-                  if (enum.hasNext()) {
-                     if (shouldEscape()) {
-                        pageContext.getOut().write(TextUtil.escapeHTML(BeanUtil.toStringValue(enum.next())));
-                     } else {
-                        pageContext.getOut().write(BeanUtil.toStringValue(enum.next()));
-                     }
-                  }
-               } else if (value instanceof char[]) {
-                  if (shouldEscape()) {
-                     pageContext.getOut().write(TextUtil.escapeHTML(String.valueOf((char[]) value)));
-                  } else {
-                     pageContext.getOut().write(String.valueOf((char[]) value));
-                  }
-               } else {
-                  if (shouldEscape()) {
-                     pageContext.getOut().write(TextUtil.escapeHTML(BeanUtil.toStringValue(value)));
-                  } else {
-                     pageContext.getOut().write(BeanUtil.toStringValue(value));
-                  }
-               }
-            else
-               pageContext.getOut().write(""); // Printing out null gives no output
-         } catch (Throwable t) {
-            String msg = "Could not show value: " + valueAttr;
-            log.error(msg, t);
-            throw new JspException(msg + ", throwable: " + t);
-         }
-      }
-
-      return EVAL_PAGE;
-   }
-
-    /**
-     * The BasicPropertyTag should escape IF the escape value has been set to true. At
-     * all other times it will false (ie not escape data).
-     *
-     * CHANGE THIS METHOD ON PAIN OF DEATH -mike :)
-     *
-     * @see PropertyTag#shouldEscape()
-     */
-    protected boolean shouldEscape()
-    {
-        if (escape == null)
-        {
-            return false;
-        }
-
-        return escape.booleanValue();
-    }
-}
-
-
+/*
+ * WebWork, Web Application Framework
+ *
+ * Distributable under Apache license.
+ * See terms of license at opensource.org
+ */
+package webwork.view.taglib;
+
+import webwork.util.TextUtil;
+import webwork.util.BeanUtil;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+import java.util.Iterator;
+
+import org.apache.commons.logging.*;
+
+/**
+ *  Access the value of a named property. By default (implicitly),
+ *  this tag will escape its contents if it does *not* have a body.
+ *  If it does have a body, the tag will not escape the contents.
+ *  You can explicitly tell the tag to escape or not.
+ *  Quoted text that is escaped will have its quotes stripped off.
+ *
+ * @author Rickard �berg ([email protected])
+ * @author Matt Baldree ([email protected])
+ * @version $Revision$
+ */
+public class BasicPropertyTag
+      extends WebWorkBodyTagSupport
+{
+   protected static Log log = LogFactory.getLog(BasicPropertyTag.class);
+
+   // Attributes ----------------------------------------------------
+   protected String valueAttr;
+   protected Boolean escape;
+   protected boolean hadBody;
+
+   // Public --------------------------------------------------------
+   public void setValue(String inName)
+   {
+      valueAttr = inName;
+   }
+
+   public void setEscape(boolean inEscape)
+   {
+      escape = new Boolean(inEscape);
+   }
+
+   // BodyTag implementation ----------------------------------------
+   public int doStartTag() throws JspException
+   {
+      hadBody = false;
+      Object value = findValue(valueAttr);
+      getStack().pushValue(value);
+
+      String id = getId();
+      if (id != null && value != null) {
+         pageContext.setAttribute(id, value);
+         pageContext.setAttribute(id, value, PageContext.REQUEST_SCOPE);
+      }
+      return EVAL_BODY_BUFFERED;
+   }
+
+   public int doAfterBody() throws JspException
+   {
+      // This is a workaround for a bug in Jasper.
+      // http://znutar.cortexity.com/BugRatViewer/ShowReport/652
+      // Resin 1.2.1 also has this bug (i.e. body is called even though it is empty)
+
+      // If the bodyContent is null then just return
+      if (bodyContent == null)
+         return SKIP_BODY;
+      String body = null;
+      try {
+         body = bodyContent.getString();
+      } catch (Exception e) {
+         //do nothing - leave body as null
+      }
+
+      //Added null check - Fixes WW-195 on Resin.
+      hadBody = body != null && body.length() != 0;
+
+      if (hadBody) {
+         try {
+            if (shouldEscape()) {
+               body = TextUtil.escapeHTML(body);
+            }
+            bodyContent.getEnclosingWriter().write(body);
+         } catch (java.io.IOException e) {
+            throw new JspException("Could not show attribute " + valueAttr, e);
+         }
+      }
+      return SKIP_BODY;
+   }
+
+   public int doEndTag() throws JspException
+   {
+      Object value = getStack().popValue();
+
+      if (!hadBody) {
+         // No body used. This means that we want to print the parameter out
+         try {
+            //LogFactory.getLog(this.getClass()).debug("Property value:"+value);
+            if (value != null && getId() == null)
+               if (value instanceof Iterator) {
+                  Iterator enum = (Iterator) value;
+                  if (enum.hasNext()) {
+                     if (shouldEscape()) {
+                        pageContext.getOut().write(TextUtil.escapeHTML(BeanUtil.toStringValue(enum.next())));
+                     } else {
+                        pageContext.getOut().write(BeanUtil.toStringValue(enum.next()));
+                     }
+                  }
+               } else if (value instanceof char[]) {
+                  if (shouldEscape()) {
+                     pageContext.getOut().write(TextUtil.escapeHTML(String.valueOf((char[]) value)));
+                  } else {
+                     pageContext.getOut().write(String.valueOf((char[]) value));
+                  }
+               } else {
+                  if (shouldEscape()) {
+                     pageContext.getOut().write(TextUtil.escapeHTML(BeanUtil.toStringValue(value)));
+                  } else {
+                     pageContext.getOut().write(BeanUtil.toStringValue(value));
+                  }
+               }
+            else
+               pageContext.getOut().write(""); // Printing out null gives no output
+         } catch (Throwable t) {
+            String msg = "Could not show value: " + valueAttr;
+            throw new JspException(msg + ", throwable: " + t, t);
+         }
+      }
+
+      return EVAL_PAGE;
+   }
+
+    /**
+     * The BasicPropertyTag should escape IF the escape value has been set to true. At
+     * all other times it will false (ie not escape data).
+     *
+     * CHANGE THIS METHOD ON PAIN OF DEATH -mike :)
+     *
+     * @see PropertyTag#shouldEscape()
+     */
+    protected boolean shouldEscape()
+    {
+        if (escape == null)
+        {
+            return false;
+        }
+
+        return escape.booleanValue();
+    }
+}
+
+

Index: URLTag.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/view/taglib/URLTag.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- URLTag.java	8 Jan 2004 17:13:44 -0000	1.23
+++ URLTag.java	28 Feb 2005 18:43:29 -0000	1.24
@@ -25,7 +25,7 @@
  * additional request parameters.
  *
  * @see ParamTag
- * @author Rickard Öberg ([email protected])
+ * @author Rickard �berg ([email protected])
  * @version $Revision$
  */
 public class URLTag
@@ -224,7 +224,7 @@
          try {
             pageContext.getOut().write(result);
          } catch (IOException _ioe) {
-            throw new JspException("IOError: " + _ioe.getMessage());
+            throw new JspException("IOError: " + _ioe.getMessage(), _ioe);
 		 }
       }
 



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click