Author: hlship
Date: Mon Jan 12 11:23:07 2009
New Revision: 733872

URL: http://svn.apache.org/viewvc?rev=733872&view=rev
Log:
TAP5-447: ExceptionDisplay should render uninteresting stack frames but include 
a client-side control to toggle their visibility

Added:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/exceptiondisplay.js
Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ExceptionDisplay.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/ExceptionDisplay.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImpl.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ExceptionDisplay.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ExceptionDisplay.java?rev=733872&r1=733871&r2=733872&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ExceptionDisplay.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ExceptionDisplay.java
 Mon Jan 12 11:23:07 2009
@@ -1,4 +1,4 @@
-// Copyright 2008 The Apache Software Foundation
+// Copyright 2008, 2009 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.
@@ -14,6 +14,9 @@
 
 package org.apache.tapestry5.corelib.components;
 
+import org.apache.tapestry5.RenderSupport;
+import org.apache.tapestry5.annotations.Environmental;
+import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
 import org.apache.tapestry5.annotations.Parameter;
 import org.apache.tapestry5.annotations.Property;
 import org.apache.tapestry5.internal.InternalConstants;
@@ -31,6 +34,7 @@
  *
  * @see org.apache.tapestry5.ioc.services.ExceptionAnalyzer
  */
+...@includejavascriptlibrary("exceptiondisplay.js")
 public class ExceptionDisplay
 {
     /**
@@ -58,11 +62,21 @@
     @Property
     private List<ExceptionInfo> stack;
 
+    @Environmental
+    private RenderSupport renderSupport;
+
+    @Property
+    private String toggleId;
+
+    private boolean sawDoFilter;
+
     void setupRender()
     {
         ExceptionAnalysis analysis = analyzer.analyze(exception);
 
         stack = analysis.getExceptionInfos();
+
+        toggleId = renderSupport.allocateClientId("toggleStack");
     }
 
     public boolean getShowPropertyList()
@@ -79,8 +93,20 @@
 
     public String getFrameClass()
     {
-        if (frame.getClassName().startsWith(appPackage) && 
frame.getLineNumber() > 0) return "t-usercode-frame";
+        String className = frame.getClassName();
+        int lineNumber = frame.getLineNumber();
+
+        if (sawDoFilter || className.startsWith("$") && lineNumber <= 0) 
return "t-omitted-frame";
+
+        sawDoFilter |= frame.getMethodName().equals("doFilter");
+
+        if (className.startsWith(appPackage) && lineNumber > 0) return 
"t-usercode-frame";
 
         return null;
     }
+
+    void afterRender()
+    {
+        renderSupport.addScript("Tapestry.stackFrameToggle('%s');", toggleId);
+    }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/ExceptionDisplay.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/ExceptionDisplay.tml?rev=733872&r1=733871&r2=733872&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/ExceptionDisplay.tml
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/ExceptionDisplay.tml
 Mon Jan 12 11:23:07 2009
@@ -17,7 +17,13 @@
                             </dd>
                         </t:loop>
                         <t:if test="info.stackTrace">
-                            <dt>Stack trace</dt>
+                            <dt>
+                                <span class="t-exception-stack-controls">
+                                    <input type="checkbox" id="${toggleId}" 
checked="checked"/>
+                                    <label for="${toggleId}">Hide 
uninteresting stack frames</label>
+                                </span>
+                                Stack trace
+                            </dt>
                             <dd>
                                 <ul class="t-stack-trace">
                                     <t:loop source="info.stackTrace" 
value="frame">

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/exceptiondisplay.js
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/exceptiondisplay.js?rev=733872&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/exceptiondisplay.js
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/exceptiondisplay.js
 Mon Jan 12 11:23:07 2009
@@ -0,0 +1,29 @@
+// Copyright 2009 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.
+
+Tapestry.stackFrameToggle = function(id)
+{
+    var checkbox = $(id);
+
+    checkbox.observe("change", function()
+    {
+        var newDisplay = checkbox.checked ? "none" : "list-item";
+
+        $$("LI.t-omitted-frame").each(function(e)
+        {
+            e.style.display = newDisplay;
+            e.style.listStyleType = "square";
+        });
+    });
+}

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css?rev=733872&r1=733871&r2=733872&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css
 Mon Jan 12 11:23:07 2009
@@ -96,6 +96,11 @@
     font-weight: bold;
 }
 
+SPAN.t-exception-stack-controls {
+    display: block;
+    float: right;
+}
+
 UL.t-stack-trace LI {
     font-family: Monaco, Times, monospace;
     font-size: 10pt;
@@ -108,6 +113,12 @@
     color: blue;
 }
 
+LI.t-omitted-frame {
+    display: none;
+    color: gray;
+    list-style: square;
+}
+
 H1.t-exception-report {
     font-family: "Trebuchet MS", Arial, sans-serif;
     color: red;

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImpl.java?rev=733872&r1=733871&r2=733872&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImpl.java
 Mon Jan 12 11:23:07 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 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.
@@ -17,10 +17,7 @@
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.services.*;
 
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 public class ExceptionAnalyzerImpl implements ExceptionAnalyzer
 {
@@ -117,25 +114,9 @@
         // Usually, I'd use a terniary expression here, but Generics gets in
         // the way here.
 
-        if (t.getCause() == null) stackTrace = extractStackTrace(t);
+        if (t.getCause() == null)
+            stackTrace = Arrays.asList(t.getStackTrace());
 
         return new ExceptionInfoImpl(t, properties, stackTrace);
     }
-
-    private List<StackTraceElement> extractStackTrace(Throwable t)
-    {
-        List<StackTraceElement> trace = CollectionFactory.newList();
-
-        for (StackTraceElement e : t.getStackTrace())
-        {
-            // Edit out IoC Proxy classes. They always start with a '$'
-            // and don't have any line number information.
-
-            if (e.getClassName().startsWith("$") && e.getLineNumber() < 0) 
continue;
-
-            trace.add(e);
-        }
-
-        return trace;
-    }
 }


Reply via email to