svn commit: r603703 - in /ofbiz/trunk/framework: common/widget/CommonScreens.xml widget/src/org/ofbiz/widget/screen/ScreenFopViewHandler.java

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

svn commit: r603703 - in /ofbiz/trunk/framework: common/widget/CommonScreens.xml widget/src/org/ofbiz/widget/screen/ScreenFopViewHandler.java

adrianc
Author: adrianc
Date: Wed Dec 12 10:51:53 2007
New Revision: 603703

URL: http://svn.apache.org/viewvc?rev=603703&view=rev
Log:
Improved error handling in ScreenFopViewHandler.java. Original error handling was:

Try to render screen using fop
  If that fails, try to render error message using fop
    If that fails, throw an exception (results in blank screen)

The new error handling is:

Try to render screen using fop
  If that fails, try to render error message using HTML screen widget
    If that fails, log a debug message

Modified:
    ofbiz/trunk/framework/common/widget/CommonScreens.xml
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopViewHandler.java

Modified: ofbiz/trunk/framework/common/widget/CommonScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/widget/CommonScreens.xml?rev=603703&r1=603702&r2=603703&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/widget/CommonScreens.xml (original)
+++ ofbiz/trunk/framework/common/widget/CommonScreens.xml Wed Dec 12 10:51:53 2007
@@ -258,10 +258,13 @@
             <actions>
                 <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
                 <set field="logoImageUrl" value="/images/ofbiz_logo.jpg"/>
-                <!--<set field="defaultFontFamily" value="Arial"/>-->
             </actions>
             <widgets>
-                <platform-specific><html><html-template location="component://common/webcommon/error.fo.ftl"/></html></platform-specific>
+                <decorator-screen name="main-decorator" location="${parameters.mainDecoratorLocation}">
+                    <decorator-section name="body">
+<!--                <platform-specific><html><html-template location="component://common/webcommon/error.fo.ftl"/></html></platform-specific> -->
+                    </decorator-section>
+                </decorator-screen>
             </widgets>
         </section>
     </screen>

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopViewHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopViewHandler.java?rev=603703&r1=603702&r2=603703&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopViewHandler.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopViewHandler.java Wed Dec 12 10:51:53 2007
@@ -33,6 +33,7 @@
 import org.ofbiz.webapp.view.ViewHandlerException;
 import org.ofbiz.widget.fo.FoFormRenderer;
 import org.ofbiz.widget.fo.FoScreenRenderer;
+import org.ofbiz.widget.html.HtmlScreenRenderer;;
 
 /**
  * Uses XSL-FO formatted templates to generate PDF, PCL, POSTSCRIPT etc.  views
@@ -40,6 +41,7 @@
  */
 public class ScreenFopViewHandler implements ViewHandler {
     public static final String module = ScreenFopViewHandler.class.getName();
+    protected static final String DEFAULT_ERROR_TEMPLATE = "component://common/widget/CommonScreens.xml#FoError";
 
     protected ServletContext servletContext = null;
     protected FoScreenRenderer foScreenRenderer = new FoScreenRenderer();
@@ -65,8 +67,8 @@
             // this is the object used to render forms from their definitions
             screens.getContext().put("formStringRenderer", new FoFormRenderer(request, response));
             screens.render(page);
-        } catch (Throwable t) {
-            throw new ViewHandlerException("Problems with the response writer/output stream", t);
+        } catch (Exception e) {
+            throw createException("Problems with the response writer/output stream", e, request, response);
         }
 
         // set the input source (XSL-FO) and generate the output stream of contentType
@@ -82,7 +84,7 @@
             Fop fop = ApacheFopWorker.createFopInstance(out, contentType);
             ApacheFopWorker.transform(src, null, fop);
         } catch (Exception e) {
-            throw createException("Unable to transform FO file", e, response);
+            throw createException("Unable to transform FO file", e, request, response);
         }
         // set the content type and length
         response.setContentType(contentType);
@@ -93,18 +95,22 @@
             out.writeTo(response.getOutputStream());
             response.getOutputStream().flush();
         } catch (IOException e) {
-            throw createException("Unable write to browser OutputStream", e, response);
+            throw createException("Unable write to browser OutputStream", e, request, response);
         }
     }
 
-    protected ViewHandlerException createException(String msg, Exception e, HttpServletResponse response) {
+    protected ViewHandlerException createException(String msg, Exception e, HttpServletRequest request, HttpServletResponse response) {
         Debug.logError(msg + ": " + e, module);
-        String htmlString = "<html><head><title>FOP Rendering Error</title></head><body>" + msg + ": " + e.getMessage() + "</body></html>";
-        response.setContentType("text/html");
-        response.setContentLength(htmlString.length());
         try {
-            response.getOutputStream().write(htmlString.getBytes());
-        } catch (IOException i) {
+            Writer writer = new StringWriter();
+            ScreenRenderer screens = new ScreenRenderer(writer, null, new HtmlScreenRenderer());
+            screens.populateContextForRequest(request, response, servletContext);
+            screens.getContext().put("errorMessage", e.toString());
+            screens.render(DEFAULT_ERROR_TEMPLATE);
+            response.setContentType("text/html");
+            response.getOutputStream().write(writer.toString().getBytes());
+            writer.close();
+        } catch (Exception x) {
             Debug.logError("Multiple errors rendering FOP", module);
         }
         return new ViewHandlerException(msg, e);