svn commit: r545225 - in /ofbiz/trunk: applications/accounting/widget/ framework/common/config/ framework/widget/src/org/ofbiz/widget/fo/ framework/widget/src/org/ofbiz/widget/screen/

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

svn commit: r545225 - in /ofbiz/trunk: applications/accounting/widget/ framework/common/config/ framework/widget/src/org/ofbiz/widget/fo/ framework/widget/src/org/ofbiz/widget/screen/

jacopoc
Author: jacopoc
Date: Thu Jun  7 08:58:26 2007
New Revision: 545225

URL: http://svn.apache.org/viewvc?view=rev&rev=545225
Log:
Implemented first simple version of the Screen Widget Renderer for Fo (Formatting Objects): OFBIZ-809
It is now possible to decorate the screen definition with container and label elements.
For a poc see the agreement item product report.

Added:
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java   (with props)
Modified:
    ofbiz/trunk/applications/accounting/widget/AgreementScreens.xml
    ofbiz/trunk/framework/common/config/fo-styles.properties
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopViewHandler.java

Modified: ofbiz/trunk/applications/accounting/widget/AgreementScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/AgreementScreens.xml?view=diff&rev=545225&r1=545224&r2=545225
==============================================================================
--- ofbiz/trunk/applications/accounting/widget/AgreementScreens.xml (original)
+++ ofbiz/trunk/applications/accounting/widget/AgreementScreens.xml Thu Jun  7 08:58:26 2007
@@ -337,7 +337,13 @@
             <widgets>
                 <decorator-screen name="FoDecorator" location="component://common/widget/CommonScreens.xml">
                     <decorator-section name="body">
+                        <container>
+                            <label style="head1">${uiLabelMap.AccountingAgreement}</label>
+                        </container>
                         <include-form name="ViewAgreementInfoForReport" location="component://accounting/webapp/accounting/agreement/AgreementForms.xml"/>
+                        <container>
+                            <label style="head2">${uiLabelMap.AccountingAgreementItem}</label>
+                        </container>
                         <include-form name="ViewAgreementItemInfoForReport" location="component://accounting/webapp/accounting/agreement/AgreementForms.xml"/>
                         <include-form name="ListAgreementItemProductsForReport" location="component://accounting/webapp/accounting/agreement/AgreementForms.xml"/>
                     </decorator-section>

Modified: ofbiz/trunk/framework/common/config/fo-styles.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/config/fo-styles.properties?view=diff&rev=545225&r1=545224&r2=545225
==============================================================================
--- ofbiz/trunk/framework/common/config/fo-styles.properties (original)
+++ ofbiz/trunk/framework/common/config/fo-styles.properties Thu Jun  7 08:58:26 2007
@@ -22,3 +22,7 @@
 tableheadsmall=column-width=\"0.5in\"
 tableheadmedium=column-width=\"1.5in\"
 tableheadwide=column-width=\"3in\"
+head1=font-size=\"12\" font-weight=\"bold\"
+head2=font-weight=\"bold\"
+head3=font-weight=\"bold\" font-style=\"italic\"
+error=color=\"red\"

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java?view=diff&rev=545225&r1=545224&r2=545225
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java Thu Jun  7 08:58:26 2007
@@ -24,7 +24,6 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilFormatOut;
 import org.ofbiz.widget.form.FormStringRenderer;
@@ -75,19 +74,11 @@
         //buffer.append(' ');
     }
 
-    private String getFoStyle(String styleName) {
-        String value = UtilProperties.getPropertyValue("fo-styles.properties", styleName);
-        if (value.equals(styleName)) {
-            return "";
-        }
-        return value;
-    }
-
     private void makeBlockString(StringBuffer buffer, String widgetStyle, String text) {
         buffer.append("<fo:block");
         if (UtilValidate.isNotEmpty(widgetStyle)) {
             buffer.append(" ");
-            buffer.append(getFoStyle(widgetStyle));
+            buffer.append(FoScreenRenderer.getFoStyle(widgetStyle));
         }
         buffer.append(">");
         buffer.append(UtilFormatOut.encodeXmlValue(text));
@@ -204,7 +195,7 @@
             String areaStyle = childField.getTitleAreaStyle();
             if (UtilValidate.isNotEmpty(areaStyle)) {
                 buffer.append(" ");
-                buffer.append(getFoStyle(areaStyle));
+                buffer.append(FoScreenRenderer.getFoStyle(areaStyle));
             }
             buffer.append("/>");
             this.appendWhitespace(buffer);
@@ -272,7 +263,7 @@
         if (UtilValidate.isEmpty(areaStyle)) {
             areaStyle = "tabletext";
         }
-        buffer.append(getFoStyle(areaStyle));
+        buffer.append(FoScreenRenderer.getFoStyle(areaStyle));
         buffer.append(">");
         this.appendWhitespace(buffer);
     }

Added: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java?view=auto&rev=545225
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java (added)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java Thu Jun  7 08:58:26 2007
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * 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.fo;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.GeneralException;
+import org.ofbiz.base.util.UtilFormatOut;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.webapp.control.RequestHandler;
+import org.ofbiz.webapp.taglib.ContentUrlTag;
+import org.ofbiz.widget.WidgetContentWorker;
+import org.ofbiz.widget.screen.ModelScreenWidget;
+import org.ofbiz.widget.screen.ScreenStringRenderer;
+import org.ofbiz.service.LocalDispatcher;
+import javolution.util.FastMap;
+
+/**
+ * Widget Library - HTML Form Renderer implementation
+ */
+public class FoScreenRenderer implements ScreenStringRenderer {
+
+    public static final String module = FoScreenRenderer.class.getName();
+
+    public FoScreenRenderer() {}
+
+    // This is a util method to get the style from a property file
+    public static String getFoStyle(String styleName) {
+        String value = UtilProperties.getPropertyValue("fo-styles.properties", styleName);
+        if (value.equals(styleName)) {
+            return "";
+        }
+        return value;
+    }
+
+    public void renderSectionBegin(Writer writer, Map context, ModelScreenWidget.Section section) throws IOException {
+        // do nothing, this is just a place holder container for HTML
+    }
+    public void renderSectionEnd(Writer writer, Map context, ModelScreenWidget.Section section) throws IOException {
+        // do nothing, this is just a place holder container for HTML
+    }
+
+    public void renderContainerBegin(Writer writer, Map context, ModelScreenWidget.Container container) throws IOException {
+        writer.write("<fo:block");
+
+        String style = container.getStyle(context);
+        if (UtilValidate.isNotEmpty(style)) {
+            writer.append(" ");
+            writer.append(FoScreenRenderer.getFoStyle(style));
+        }
+        writer.write(">");
+        appendWhitespace(writer);
+    }
+    public void renderContainerEnd(Writer writer, Map context, ModelScreenWidget.Container container) throws IOException {
+        writer.write("</fo:block>");
+        appendWhitespace(writer);
+    }
+
+    public void renderLabel(Writer writer, Map context, ModelScreenWidget.Label label) throws IOException {
+        String labelText = label.getText(context);
+        if (UtilValidate.isEmpty(labelText)) {
+            // nothing to render
+            return;
+        }
+        // open tag
+        String style = label.getStyle(context);
+        if (UtilValidate.isNotEmpty(style)) {
+            writer.write("<fo:inline ");
+            writer.append(FoScreenRenderer.getFoStyle(style));
+            writer.write(">");
+            // the text
+            writer.write(labelText);
+            // close tag
+            writer.write("</fo:inline>");
+        } else {
+            writer.write(labelText);
+        }
+        appendWhitespace(writer);
+    }
+
+    public void renderLink(Writer writer, Map context, ModelScreenWidget.Link link) throws IOException {
+        // TODO: not implemented
+    }
+
+    public void renderImage(Writer writer, Map context, ModelScreenWidget.Image image) throws IOException {
+        // TODO: not implemented
+    }
+
+    public void renderContentBegin(Writer writer, Map context, ModelScreenWidget.Content content) throws IOException {
+        // TODO: not implemented
+    }
+
+    public void renderContentBody(Writer writer, Map context, ModelScreenWidget.Content content) throws IOException {
+        // TODO: not implemented
+    }
+
+    public void renderContentEnd(Writer writer, Map context, ModelScreenWidget.Content content) throws IOException {
+        // TODO: not implemented
+    }
+
+    public void renderContentFrame(Writer writer, Map context, ModelScreenWidget.Content content) throws IOException {
+        // TODO: not implemented
+    }
+
+    public void renderSubContentBegin(Writer writer, Map context, ModelScreenWidget.SubContent content) throws IOException {
+        // TODO: not implemented
+    }
+
+    public void renderSubContentBody(Writer writer, Map context, ModelScreenWidget.SubContent content) throws IOException {
+        // TODO: not implemented
+    }
+
+    public void renderSubContentEnd(Writer writer, Map context, ModelScreenWidget.SubContent content) throws IOException {
+        // TODO: not implemented
+    }
+
+    public void appendWhitespace(Writer writer) throws IOException {
+        // appending line ends for now, but this could be replaced with a simple space or something
+        writer.write("\r\n");
+    }
+}

Propchange: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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?view=diff&rev=545225&r1=545224&r2=545225
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopViewHandler.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopViewHandler.java Thu Jun  7 08:58:26 2007
@@ -20,6 +20,7 @@
 
 import java.io.*;
 
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.xml.transform.*;
@@ -33,17 +34,29 @@
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.webapp.view.ViewHandler;
 import org.ofbiz.webapp.view.ViewHandlerException;
 import org.ofbiz.webapp.view.ApacheFopFactory;
 import org.ofbiz.widget.fo.FoFormRenderer;
+import org.ofbiz.widget.fo.FoScreenRenderer;
 
 /**
  * Uses XSL-FO formatted templates to generate PDF, PCL, POSTSCRIPT etc.  views
  * This handler will use JPublish to generate the XSL-FO
  */
-public class ScreenFopViewHandler extends ScreenWidgetViewHandler {
+public class ScreenFopViewHandler implements ViewHandler {
     public static final String module = ScreenFopViewHandler.class.getName();
 
+    protected ServletContext servletContext = null;
+    protected FoScreenRenderer foScreenRenderer = new FoScreenRenderer();
+
+    /**
+     * @see org.ofbiz.webapp.view.ViewHandler#init(javax.servlet.ServletContext)
+     */
+    public void init(ServletContext context) throws ViewHandlerException {
+        this.servletContext = context;
+    }
+
     /**
      * @see org.ofbiz.content.webapp.view.ViewHandler#render(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      */
@@ -59,7 +72,7 @@
         FopFactory fopFactory = ApacheFopFactory.instance();
 
         try {
-            ScreenRenderer screens = new ScreenRenderer(writer, null, htmlScreenRenderer);
+            ScreenRenderer screens = new ScreenRenderer(writer, null, foScreenRenderer);
             screens.populateContextForRequest(request, response, servletContext);
 
             // this is the object used to render forms from their definitions