svn commit: r561025 - in /ofbiz/trunk/framework/widget/src/org/ofbiz/widget: screen/HtmlWidget.java screen/ModelScreen.java screen/ScreenRenderException.java tree/ModelTree.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r561025 - in /ofbiz/trunk/framework/widget/src/org/ofbiz/widget: screen/HtmlWidget.java screen/ModelScreen.java screen/ScreenRenderException.java tree/ModelTree.java

sichen
Author: sichen
Date: Mon Jul 30 08:59:50 2007
New Revision: 561025

URL: http://svn.apache.org/viewvc?view=rev&rev=561025
Log:
Created a new ScreenRenderException to reduce the amount of error messages logged

Added:
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderException.java
Modified:
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java?view=diff&rev=561025&r1=561024&r2=561025
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java Mon Jul 30 08:59:50 2007
@@ -78,18 +78,26 @@
             } catch (MalformedURLException e) {
                 String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString();
                 Debug.logError(e, errMsg, module);
-                throw new RuntimeException(errMsg);
+                writeError(writer, errMsg);
             } catch (TemplateException e) {
                 String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString();
                 Debug.logError(e, errMsg, module);
-                throw new RuntimeException(errMsg);
+                writeError(writer, errMsg);
             } catch (IOException e) {
                 String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString();
                 Debug.logError(e, errMsg, module);
-                throw new RuntimeException(errMsg);
+                writeError(writer, errMsg);
             }
         } else {
             throw new IllegalArgumentException("Rending not yet support for the tempalte at location: " + location);
+        }
+    }
+
+    // TODO: We can make this more fancy, but for now this is very functional
+    public static void writeError(Writer writer, String message) {
+        try {
+            writer.write(message);
+        } catch (IOException e) {
         }
     }
 

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java?view=diff&rev=561025&r1=561024&r2=561025
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java Mon Jul 30 08:59:50 2007
@@ -89,7 +89,7 @@
      *   different screen elements; implementing your own makes it possible to
      *   use the same screen definitions for many types of screen UIs
      */
-    public void renderScreenString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
+    public void renderScreenString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) throws ScreenRenderException {
         // make sure the "null" object is in there for entity ops
         context.put("null", GenericEntity.NULL_FIELD);
 
@@ -134,6 +134,8 @@
 
             // render the screen, starting with the top-level section
             this.section.renderWidgetString(writer, context, screenStringRenderer);
+        } catch (ScreenRenderException e) {
+            throw e;
         } catch (RuntimeException e) {
             String errMsg = "Error rendering screen [" + this.sourceLocation + "#" + this.name + "]: " + e.toString();
             Debug.logError(errMsg + ". Rolling back transaction.", module);
@@ -144,7 +146,7 @@
                 Debug.logError(e2, "Could not rollback transaction: " + e2.toString(), module);
             }
             // after rolling back, rethrow the exception
-            throw new GeneralException(errMsg, e);
+            throw new ScreenRenderException(errMsg, e);
         } catch (Exception e) {
             String errMsg = "Error rendering screen [" + this.sourceLocation + "#" + this.name + "]: " + e.toString();
             Debug.logError(errMsg + ". Rolling back transaction.", module);
@@ -158,7 +160,7 @@
             // throw nested exception, don't need to log details here: Debug.logError(e, errMsg, module);
             
             // after rolling back, rethrow the exception
-            throw new GeneralException(errMsg, e);
+            throw new ScreenRenderException(errMsg, e);
         } finally {
             // only commit the transaction if we started one... this will throw an exception if it fails
             try {

Added: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderException.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderException.java?view=auto&rev=561025
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderException.java (added)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderException.java Mon Jul 30 08:59:50 2007
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *******************************************************************************/
+
+package org.ofbiz.widget.screen;
+
+import org.ofbiz.base.util.*;
+
+/**
+ * Wraps any exceptions encountered during the rendering of
+ * a screen.  It is thrown to the top of the recursive
+ * rendering process so that we avoid having to log redundant
+ * exceptions.
+ */
+public class ScreenRenderException extends GeneralException {
+
+    public ScreenRenderException() {
+        super();
+    }
+
+    public ScreenRenderException(Throwable nested) {
+        super(nested);    
+    }
+
+    public ScreenRenderException(String str) {
+        super(str);
+    }
+
+    public ScreenRenderException(String str, Throwable nested) {
+        super(str, nested);
+    }
+}

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java?view=diff&rev=561025&r1=561024&r2=561025
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java Mon Jul 30 08:59:50 2007
@@ -43,6 +43,7 @@
 import org.ofbiz.widget.screen.ModelScreen;
 import org.ofbiz.widget.screen.ScreenFactory;
 import org.ofbiz.widget.screen.ScreenStringRenderer;
+import org.ofbiz.widget.screen.ScreenRenderException;
 import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
@@ -474,6 +475,11 @@
                             }
                         }
                     }
+                } catch (ScreenRenderException e) {
+                    String errMsg = "Error rendering included label with name ["
+                            + name + "] : " + e.toString();
+                    Debug.logError(e, errMsg, module);
+                    throw new RuntimeException(errMsg);                    
                 } catch (SAXException e) {
                     String errMsg = "Error rendering included label with name ["
                             + name + "] : " + e.toString();