cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r226971 - in /cocoon/branches/BRANCH_2_1_X/src: java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java java/org/apache/cocoon/util/ExceptionUtils.java webapp/stylesheets/system/exception2html.xslt
Date Tue, 02 Aug 2005 08:45:20 GMT
Author: sylvain
Date: Tue Aug  2 01:45:13 2005
New Revision: 226971

URL: http://svn.apache.org/viewcvs?rev=226971&view=rev
Log:
Ensure JDK 1.4 exception chaining is properly setup, add flowscript engine to Cocoon stacktraces

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ExceptionUtils.java
    cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java?rev=226971&r1=226970&r2=226971&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
Tue Aug  2 01:45:13 2005
@@ -711,7 +711,7 @@
                 Thread.currentThread().getContextClassLoader();
             FOM_Cocoon cocoon = null;
             try {
-                try {
+//                try {
                     setupContext(redirector, context, thrScope);
                     cocoon = (FOM_Cocoon) thrScope.get("cocoon", thrScope);
 
@@ -753,27 +753,27 @@
 
                     thrScope.setLock(true);
                     ScriptRuntime.call(context, fun, thrScope, funArgs, thrScope);
-                } catch (JavaScriptException ex) {
-                    EvaluatorException ee = Context.reportRuntimeError(
-                                                                       ToolErrorReporter.getMessage("msg.uncaughtJSException",
-                                                                                        
           ex.getMessage()));
-                    Throwable unwrapped = unwrap(ex);
-                    if (unwrapped instanceof ProcessingException) {
-                        throw (ProcessingException) unwrapped;
-                    }
-                    throw new CascadingRuntimeException(ee.getMessage(),
-                                                        unwrapped);
-                } catch (EcmaError ee) {
-                    String msg = ToolErrorReporter.getMessage("msg.uncaughtJSException",
ee.toString());
-                    if (ee.getSourceName() != null) {
-                        Context.reportRuntimeError(msg, ee.getSourceName(),
-                                                   ee.getLineNumber(), ee.getLineSource(),
-                                                   ee.getColumnNumber());
-                    } else {
-                        Context.reportRuntimeError(msg);
-                    }
-                    throw new CascadingRuntimeException(ee.getMessage(), ee);
-                }
+//                } catch (JavaScriptException ex) {
+//                    EvaluatorException ee = Context.reportRuntimeError(
+//                                                                       ToolErrorReporter.getMessage("msg.uncaughtJSException",
+//                                                                                      
             ex.getMessage()));
+//                    Throwable unwrapped = unwrap(ex);
+//                    if (unwrapped instanceof ProcessingException) {
+//                        throw (ProcessingException) unwrapped;
+//                    }
+//                    throw new CascadingRuntimeException(ee.getMessage(),
+//                                                        unwrapped);
+//                } catch (EcmaError ee) {
+//                    String msg = ToolErrorReporter.getMessage("msg.uncaughtJSException",
ee.toString());
+//                    if (ee.getSourceName() != null) {
+//                        Context.reportRuntimeError(msg, ee.getSourceName(),
+//                                                   ee.getLineNumber(), ee.getLineSource(),
+//                                                   ee.getColumnNumber());
+//                    } else {
+//                        Context.reportRuntimeError(msg);
+//                    }
+//                    throw new CascadingRuntimeException(ee.getMessage(), ee);
+//                }
             } finally {
                 thrScope.setLock(false);
                 setSessionScope(thrScope);
@@ -839,30 +839,30 @@
                 fom_wk.setPrototype(ScriptableObject.getClassPrototype(kScope,
                                                                        fom_wk.getClassName()));
                 Object[] args = new Object[] {k, fom_wk};
-                try {
+//                try {
                     ScriptableObject.callMethod(cocoon,
                                                 "handleContinuation", args);
-                } catch (JavaScriptException ex) {
-                    EvaluatorException ee = Context.reportRuntimeError(
-                                                                       ToolErrorReporter.getMessage("msg.uncaughtJSException",
-                                                                                        
           ex.getMessage()));
-                    Throwable unwrapped = unwrap(ex);
-                    if (unwrapped instanceof ProcessingException) {
-                        throw (ProcessingException)unwrapped;
-                    }
-                    throw new CascadingRuntimeException(ee.getMessage(),
-                                                        unwrapped);
-                } catch (EcmaError ee) {
-                    String msg = ToolErrorReporter.getMessage("msg.uncaughtJSException",
ee.toString());
-                    if (ee.getSourceName() != null) {
-                        Context.reportRuntimeError(msg, ee.getSourceName(),
-                                                   ee.getLineNumber(), ee.getLineSource(),
-                                                   ee.getColumnNumber());
-                    } else {
-                        Context.reportRuntimeError(msg);
-                    }
-                    throw new CascadingRuntimeException(ee.getMessage(), ee);
-                }
+//                } catch (JavaScriptException ex) {
+//                    EvaluatorException ee = Context.reportRuntimeError(
+//                                                                       ToolErrorReporter.getMessage("msg.uncaughtJSException",
+//                                                                                      
             ex.getMessage()));
+//                    Throwable unwrapped = unwrap(ex);
+//                    if (unwrapped instanceof ProcessingException) {
+//                        throw (ProcessingException)unwrapped;
+//                    }
+//                    throw new CascadingRuntimeException(ee.getMessage(),
+//                                                        unwrapped);
+//                } catch (EcmaError ee) {
+//                    String msg = ToolErrorReporter.getMessage("msg.uncaughtJSException",
ee.toString());
+//                    if (ee.getSourceName() != null) {
+//                        Context.reportRuntimeError(msg, ee.getSourceName(),
+//                                                   ee.getLineNumber(), ee.getLineSource(),
+//                                                   ee.getColumnNumber());
+//                    } else {
+//                        Context.reportRuntimeError(msg);
+//                    }
+//                    throw new CascadingRuntimeException(ee.getMessage(), ee);
+//                }
             } finally {
                 kScope.setLock(false);
                 setSessionScope(kScope);

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ExceptionUtils.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ExceptionUtils.java?rev=226971&r1=226970&r2=226971&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ExceptionUtils.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ExceptionUtils.java Tue Aug
 2 01:45:13 2005
@@ -15,6 +15,8 @@
  */
 package org.apache.cocoon.util;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.Vector;
 
 import javax.xml.transform.SourceLocator;
@@ -35,7 +37,20 @@
  * @version $Id$
  */
 public class ExceptionUtils extends org.apache.commons.lang.exception.ExceptionUtils {
+    
+    private static Method initCauseMethod;
 
+    static {
+        // Add the method used by Rhino to access wrapped exception, which is not part
+        // of the standard method set of ExceptionUtils.
+        org.apache.commons.lang.exception.ExceptionUtils.addCauseMethodName("getWrappedException");
+        
+        try {
+            initCauseMethod = Throwable.class.getMethod("initCause", new Class[] {Throwable.class});
+        } catch(Exception e) {
+            // Ignore
+        }
+    }
     /**
      * Get the cause of a <code>Throwable</code>
      * 
@@ -43,18 +58,30 @@
      * @return <code>thr</code>'s parent, or <code>null</code> if
none exists.
      */
     public static final Throwable getCause(Throwable thr) {
-        // Specific case of JavaScriptException, which holds the wrapped exception
-        // in its 'value' property, which ExceptionUtils cannot find
-        if (thr instanceof JavaScriptException) {
-            Object obj = ((JavaScriptException)thr).getValue();
-            if (obj instanceof Throwable) {
-                return (Throwable)obj;
-            } else {
-                return null;
+        Throwable result;
+//        // Specific case of JavaScriptException, which holds the wrapped exception
+//        // in its 'value' property, which ExceptionUtils cannot find
+//        if (thr instanceof JavaScriptException) {
+//            Object obj = ((JavaScriptException)thr).getValue();
+//            if (obj instanceof Throwable) {
+//                result = (Throwable)obj;
+//            } else {
+//                result = null;
+//            }
+//        } else {
+            result = org.apache.commons.lang.exception.ExceptionUtils.getCause(thr);
+//        }
+
+        // Ensure JDK 1.4's exception chaining is properly set up (this should really be
done in Commons-Lang).
+        if (result != null && initCauseMethod != null) {
+            try {
+                initCauseMethod.invoke(thr, new Throwable[]{result});
+            } catch (Exception e) {
+                // Ignore
             }
-        } else {
-            return org.apache.commons.lang.exception.ExceptionUtils.getCause(thr);
         }
+        
+        return result;
     }
 
     /**
@@ -112,13 +139,15 @@
 
         } else if (thr instanceof JavaScriptException) {
             JavaScriptException ex = (JavaScriptException)thr;
-            Vector stackTrace = ex.getJSStackTrace();
-            if (stackTrace != null) {
-                // see JavaScriptException.getMessage()
-                int i = stackTrace.size() - 1;
-                String sourceName = (String)stackTrace.elementAt(i-2);
-                int lineNum = ((Integer)stackTrace.elementAt(i)).intValue();
-                return new Location(sourceName, lineNum, -1);
+            if (ex.sourceName() != null) {
+                return new Location(ex.sourceName(), ex.lineNumber(), -1);
+//            Vector stackTrace = ex.getJSStackTrace();
+//            if (stackTrace != null) {
+//                // see JavaScriptException.getMessage()
+//                int i = stackTrace.size() - 1;
+//                String sourceName = (String)stackTrace.elementAt(i-2);
+//                int lineNum = ((Integer)stackTrace.elementAt(i)).intValue();
+//                return new Location(sourceName, lineNum, -1);
             } else {
                 return null;
             }

Modified: cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt?rev=226971&r1=226970&r2=226971&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt (original)
+++ cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt Tue Aug
 2 01:45:13 2005
@@ -19,7 +19,9 @@
 
 <xsl:stylesheet version="1.0"
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-                xmlns:ex="http://apache.org/cocoon/exception/1.0">
+                xmlns:ex="http://apache.org/cocoon/exception/1.0"
+                xmlns:str="http://exslt.org/strings"
+                extension-element-prefixes="str">
 
   <xsl:param name="contextPath"/>
   <xsl:param name="realPath"/>
@@ -51,7 +53,13 @@
 
         <h1><xsl:value-of select="$pageTitle"/></h1>
         <p class="message">
-          <xsl:value-of select="@class"/>:<br/><xsl:value-of select="ex:message"/>
+          <xsl:value-of select="@class"/>:
+          <xsl:for-each select="str:split(ex:message, '&#10;')">
+             <xsl:if test="normalize-space(.)">
+                <br/>
+                <xsl:value-of select="."/>
+             </xsl:if>
+          </xsl:for-each>
           <xsl:if test="@uri">
              <br/><span style="font-weight: normal"><xsl:call-template name="dump-location"/></span>
           </xsl:if>
@@ -64,8 +72,15 @@
           <div id="locations">
             <xsl:for-each select="ex:locations/*">
               <xsl:sort select="position()" order="descending"/>
-              <p><strong><xsl:value-of select="."/></strong><br/>
-              <xsl:call-template name="dump-location"/>
+              <p>
+                 <strong>
+                    <xsl:for-each select="str:split(., '&#10;')">
+                       <xsl:if test="normalize-space(.)">
+                         <xsl:value-of select="."/><br/>
+                       </xsl:if>
+                    </xsl:for-each>
+                 </strong>
+                 <xsl:call-template name="dump-location"/>
               </p>
             </xsl:for-each>
           </div>



Mime
View raw message