Author: jacopoc
Date: Tue Aug 8 22:09:45 2006 New Revision: 429966 URL: http://svn.apache.org/viewvc?rev=429966&view=rev Log: First version of the class to render fo templates out of form widgets: * a new FoFormRenderer class that implements the FormStringRenderer interface in order to provide a fo representation of a form widget definition. * small change to ModelForm class (new getter method) needed because I have to read the form's list * moved the initialization of the "formStringRenderer" object, from the ScreenRenderer class to the ScreenFopPdfViewHandler and ScreenWidgetViewHandler classes (so that the former can instantiate the new FoFormRenderer class and the latter the HtmlFormRenderer) The FoFormRenderer class is far from complete: * in single forms, the position attribute is ignored (nulti columns single forms are not still supported) * all the style attributes from the form definitions are ignored * in list forms, all the columns are rendered with the same size * left/center/right alignment of cells' content is not supported * field groups are not supported * banner and image fields are not supported * in general see the TODO comments near the methods that should be implemented However we can now render both list and single forms in a nice PDF format without errors. Added: incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/ incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java (with props) Modified: incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopPdfViewHandler.java incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenWidgetViewHandler.java Added: incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java?rev=429966&view=auto ============================================================================== --- incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java (added) +++ incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java Tue Aug 8 22:09:45 2006 @@ -0,0 +1,378 @@ +/* + * Copyright 2001-2006 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. + */ +package org.ofbiz.widget.fo; + +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.HashSet; +import java.util.Calendar; +import java.sql.Timestamp; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.webapp.control.RequestHandler; +import org.ofbiz.webapp.taglib.ContentUrlTag; +import org.ofbiz.widget.WidgetWorker; +import org.ofbiz.widget.form.FormStringRenderer; +import org.ofbiz.widget.form.ModelForm; +import org.ofbiz.widget.form.ModelFormField; +import org.ofbiz.widget.form.ModelFormField.CheckField; +import org.ofbiz.widget.form.ModelFormField.DateFindField; +import org.ofbiz.widget.form.ModelFormField.DateTimeField; +import org.ofbiz.widget.form.ModelFormField.DisplayEntityField; +import org.ofbiz.widget.form.ModelFormField.DisplayField; +import org.ofbiz.widget.form.ModelFormField.DropDownField; +import org.ofbiz.widget.form.ModelFormField.FileField; +import org.ofbiz.widget.form.ModelFormField.HiddenField; +import org.ofbiz.widget.form.ModelFormField.HyperlinkField; +import org.ofbiz.widget.form.ModelFormField.IgnoredField; +import org.ofbiz.widget.form.ModelFormField.ImageField; +import org.ofbiz.widget.form.ModelFormField.LookupField; +import org.ofbiz.widget.form.ModelFormField.PasswordField; +import org.ofbiz.widget.form.ModelFormField.RadioField; +import org.ofbiz.widget.form.ModelFormField.RangeFindField; +import org.ofbiz.widget.form.ModelFormField.ResetField; +import org.ofbiz.widget.form.ModelFormField.SubmitField; +import org.ofbiz.widget.form.ModelFormField.TextField; +import org.ofbiz.widget.form.ModelFormField.TextFindField; +import org.ofbiz.widget.form.ModelFormField.TextareaField; + + +/** + * Widget Library - FO Form Renderer implementation + * + */ +public class FoFormRenderer implements FormStringRenderer { + + public static final String module = FoFormRenderer.class.getName(); + + HttpServletRequest request; + HttpServletResponse response; + + protected FoFormRenderer() {} + + public FoFormRenderer(HttpServletRequest request, HttpServletResponse response) { + this.request = request; + this.response = response; + } + + public void appendWhitespace(StringBuffer buffer) { + // appending line ends for now, but this could be replaced with a simple space or something + buffer.append("\r\n"); + //buffer.append(' '); + } + + private void makeBlockString(StringBuffer buffer, String widgetStyle, String text) { + buffer.append("<fo:block>"); + buffer.append(text); + buffer.append("</fo:block>"); + /* + if (UtilValidate.isNotEmpty(widgetStyle)) { + buffer.append(" class=\""); + buffer.append(widgetStyle); + buffer.append("\""); + } + */ + } + + public void renderDisplayField(StringBuffer buffer, Map context, DisplayField displayField) { + ModelFormField modelFormField = displayField.getModelFormField(); + this.makeBlockString(buffer, modelFormField.getWidgetStyle(), displayField.getDescription(context)); + this.appendWhitespace(buffer); + } + + public void renderHyperlinkField(StringBuffer buffer, Map context, HyperlinkField hyperlinkField) { + ModelFormField modelFormField = hyperlinkField.getModelFormField(); + this.makeBlockString(buffer, modelFormField.getWidgetStyle(), hyperlinkField.getDescription(context)); + this.appendWhitespace(buffer); + } + + public void renderTextField(StringBuffer buffer, Map context, TextField textField) { + ModelFormField modelFormField = textField.getModelFormField(); + this.makeBlockString(buffer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textField.getDefaultValue(context))); + this.appendWhitespace(buffer); + } + + public void renderTextareaField(StringBuffer buffer, Map context, TextareaField textareaField) { + ModelFormField modelFormField = textareaField.getModelFormField(); + this.makeBlockString(buffer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textareaField.getDefaultValue(context))); + this.appendWhitespace(buffer); + } + + public void renderDateTimeField(StringBuffer buffer, Map context, DateTimeField dateTimeField) { + ModelFormField modelFormField = dateTimeField.getModelFormField(); + String paramName = modelFormField.getParameterName(context); + String defaultDateTimeString = dateTimeField.getDefaultDateTimeString(context); + this.makeBlockString(buffer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, dateTimeField.getDefaultValue(context))); + this.appendWhitespace(buffer); + } + + public void renderDropDownField(StringBuffer buffer, Map context, DropDownField dropDownField) { + ModelFormField modelFormField = dropDownField.getModelFormField(); + ModelForm modelForm = modelFormField.getModelForm(); + this.makeBlockString(buffer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context)); + this.appendWhitespace(buffer); + } + + public void renderCheckField(StringBuffer buffer, Map context, CheckField checkField) { + } + + public void renderRadioField(StringBuffer buffer, Map context, RadioField radioField) { + } + + public void renderSubmitField(StringBuffer buffer, Map context, SubmitField submitField) { + } + + public void renderResetField(StringBuffer buffer, Map context, ResetField resetField) { + } + + public void renderHiddenField(StringBuffer buffer, Map context, HiddenField hiddenField) { + } + + public void renderHiddenField(StringBuffer buffer, Map context, ModelFormField modelFormField, String value) { + } + + public void renderIgnoredField(StringBuffer buffer, Map context, IgnoredField ignoredField) { + } + + public void renderFieldTitle(StringBuffer buffer, Map context, ModelFormField modelFormField) { + String tempTitleText = modelFormField.getTitle(context); + buffer.append(tempTitleText); + } + + public void renderSingleFormFieldTitle(StringBuffer buffer, Map context, ModelFormField modelFormField) { + renderFieldTitle(buffer, context, modelFormField); + } + + public void renderFormOpen(StringBuffer buffer, Map context, ModelForm modelForm) { + } + + public void renderFormClose(StringBuffer buffer, Map context, ModelForm modelForm) { + } + + public void renderMultiFormClose(StringBuffer buffer, Map context, ModelForm modelForm) { + } + + public void renderFormatListWrapperOpen(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("<fo:table border=\"solid black\">"); + Iterator fieldListIter = modelForm.getFieldList().iterator(); + while (fieldListIter.hasNext()) { + ModelFormField childField = (ModelFormField)fieldListIter.next(); + int childFieldType = childField.getFieldInfo().getFieldType(); + if (childFieldType == ModelFormField.FieldInfo.HIDDEN || childFieldType == ModelFormField.FieldInfo.IGNORED) { + continue; + } + buffer.append("<fo:table-column/>"); + this.appendWhitespace(buffer); + } + this.appendWhitespace(buffer); + } + + public void renderFormatListWrapperClose(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("</fo:table-body>"); + buffer.append("</fo:table>"); + this.appendWhitespace(buffer); + } + + public void renderFormatHeaderRowOpen(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("<fo:table-header>"); + buffer.append("<fo:table-row>"); + this.appendWhitespace(buffer); + } + + public void renderFormatHeaderRowClose(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("</fo:table-row>"); + buffer.append("</fo:table-header>"); + buffer.append("<fo:table-body>"); + this.appendWhitespace(buffer); + } + + public void renderFormatHeaderRowCellOpen(StringBuffer buffer, Map context, ModelForm modelForm, ModelFormField modelFormField) { + buffer.append("<fo:table-cell font-weight=\"bold\" text-align=\"center\" border=\"solid black\" padding=\"2pt\">"); + buffer.append("<fo:block>"); + this.appendWhitespace(buffer); + } + + public void renderFormatHeaderRowCellClose(StringBuffer buffer, Map context, ModelForm modelForm, ModelFormField modelFormField) { + buffer.append("</fo:block>"); + buffer.append("</fo:table-cell>"); + this.appendWhitespace(buffer); + } + + public void renderFormatHeaderRowFormCellOpen(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("<fo:table-cell>"); + this.appendWhitespace(buffer); + } + + public void renderFormatHeaderRowFormCellClose(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("</fo:table-cell>"); + this.appendWhitespace(buffer); + } + + public void renderFormatHeaderRowFormCellTitleSeparator(StringBuffer buffer, Map context, ModelForm modelForm, ModelFormField modelFormField, boolean isLast) { + } + + public void renderFormatItemRowOpen(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("<fo:table-row>"); + this.appendWhitespace(buffer); + } + + public void renderFormatItemRowClose(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("</fo:table-row>"); + this.appendWhitespace(buffer); + } + + public void renderFormatItemRowCellOpen(StringBuffer buffer, Map context, ModelForm modelForm, ModelFormField modelFormField) { + buffer.append("<fo:table-cell border-left=\"solid black\" border-right=\"solid black\" padding-left=\"2pt\" padding-top=\"2pt\">"); + this.appendWhitespace(buffer); + } + + public void renderFormatItemRowCellClose(StringBuffer buffer, Map context, ModelForm modelForm, ModelFormField modelFormField) { + buffer.append("</fo:table-cell>"); + this.appendWhitespace(buffer); + } + + public void renderFormatItemRowFormCellOpen(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("<fo:table-cell>"); + this.appendWhitespace(buffer); + } + + public void renderFormatItemRowFormCellClose(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("</fo:table-cell>"); + this.appendWhitespace(buffer); + } + + // TODO: multi columns (position attribute) in single forms are still not implemented + public void renderFormatSingleWrapperOpen(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("<fo:table>"); + this.appendWhitespace(buffer); + buffer.append("<fo:table-column column-width=\"2in\"/>"); + this.appendWhitespace(buffer); + buffer.append("<fo:table-column/>"); + this.appendWhitespace(buffer); + buffer.append("<fo:table-body>"); + this.appendWhitespace(buffer); + } + public void renderFormatSingleWrapperClose(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("</fo:table-body>"); + buffer.append("</fo:table>"); + this.appendWhitespace(buffer); + } + + public void renderFormatFieldRowOpen(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("<fo:table-row>"); + this.appendWhitespace(buffer); + } + + public void renderFormatFieldRowClose(StringBuffer buffer, Map context, ModelForm modelForm) { + buffer.append("</fo:table-row>"); + this.appendWhitespace(buffer); + } + + + public void renderFormatFieldRowTitleCellOpen(StringBuffer buffer, Map context, ModelFormField modelFormField) { + buffer.append("<fo:table-cell font-weight=\"bold\" text-align=\"right\" padding=\"3pt\">"); + buffer.append("<fo:block>"); + this.appendWhitespace(buffer); + } + + public void renderFormatFieldRowTitleCellClose(StringBuffer buffer, Map context, ModelFormField modelFormField) { + buffer.append("</fo:block>"); + buffer.append("</fo:table-cell>"); + this.appendWhitespace(buffer); + } + + public void renderFormatFieldRowSpacerCell(StringBuffer buffer, Map context, ModelFormField modelFormField) { + } + + public void renderFormatFieldRowWidgetCellOpen(StringBuffer buffer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) { + buffer.append("<fo:table-cell text-align=\"left\" padding=\"2pt\" padding-left=\"5pt\">"); + this.appendWhitespace(buffer); + } + + public void renderFormatFieldRowWidgetCellClose(StringBuffer buffer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) { + buffer.append("</fo:table-cell>"); + this.appendWhitespace(buffer); + } + + public void renderFormatEmptySpace(StringBuffer buffer, Map context, ModelForm modelForm) { + // TODO + } + + public void renderTextFindField(StringBuffer buffer, Map context, TextFindField textFindField) { + ModelFormField modelFormField = textFindField.getModelFormField(); + this.makeBlockString(buffer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textFindField.getDefaultValue(context))); + this.appendWhitespace(buffer); + } + + public void renderRangeFindField(StringBuffer buffer, Map context, RangeFindField rangeFindField) { + ModelFormField modelFormField = rangeFindField.getModelFormField(); + this.makeBlockString(buffer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, rangeFindField.getDefaultValue(context))); + this.appendWhitespace(buffer); + } + + public void renderDateFindField(StringBuffer buffer, Map context, DateFindField dateFindField) { + ModelFormField modelFormField = dateFindField.getModelFormField(); + this.makeBlockString(buffer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, dateFindField.getDefaultValue(context))); + this.appendWhitespace(buffer); + } + + public void renderLookupField(StringBuffer buffer, Map context, LookupField lookupField) { + ModelFormField modelFormField = lookupField.getModelFormField(); + this.makeBlockString(buffer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, lookupField.getDefaultValue(context))); + this.appendWhitespace(buffer); + } + + public void renderNextPrev(StringBuffer buffer, Map context, ModelForm modelForm) { + } + + public void renderFileField(StringBuffer buffer, Map context, FileField textField) { + ModelFormField modelFormField = textField.getModelFormField(); + this.makeBlockString(buffer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textField.getDefaultValue(context))); + this.appendWhitespace(buffer); + } + + public void renderPasswordField(StringBuffer buffer, Map context, PasswordField passwordField) { + } + + public void renderImageField(StringBuffer buffer, Map context, ImageField imageField) { + // TODO + } + + public void renderFieldGroupOpen(StringBuffer buffer, Map context, ModelForm.FieldGroup fieldGroup) { + // TODO + } + + public void renderFieldGroupClose(StringBuffer buffer, Map context, ModelForm.FieldGroup fieldGroup) { + // TODO + } + + public void renderBanner(StringBuffer buffer, Map context, ModelForm.Banner banner) { + // TODO + } + + public void renderHyperlinkTitle(StringBuffer buffer, Map context, ModelFormField modelFormField, String titleText) { + } +} Propchange: incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=429966&r1=429965&r2=429966&view=diff ============================================================================== --- incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original) +++ incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Tue Aug 8 22:09:45 2006 @@ -1894,6 +1894,10 @@ return value != null ? value.intValue() : (getHighIndex(context) - getLowIndex(context)); } + public List getFieldList() { + return fieldList; + } + public void getListLimits(Map context, Object entryList) { int listSize = 0; int viewIndex = 0; Modified: incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopPdfViewHandler.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopPdfViewHandler.java?rev=429966&r1=429965&r2=429966&view=diff ============================================================================== --- incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopPdfViewHandler.java (original) +++ incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopPdfViewHandler.java Tue Aug 8 22:09:45 2006 @@ -32,6 +32,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilXml; import org.ofbiz.webapp.view.ViewHandlerException; +import org.ofbiz.widget.fo.FoFormRenderer; import org.w3c.dom.Document; import org.xml.sax.InputSource; @@ -55,6 +56,8 @@ try { ScreenRenderer screens = new ScreenRenderer(writer, null, htmlScreenRenderer); screens.populateContextForRequest(request, response, servletContext); + // 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); Modified: incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java?rev=429966&r1=429965&r2=429966&view=diff ============================================================================== --- incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java (original) +++ incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java Tue Aug 8 22:09:45 2006 @@ -229,9 +229,6 @@ // ========== setup values that are specific to OFBiz webapps - // this is the object used to render forms from their definitions - context.put("formStringRenderer", new HtmlFormRenderer(request, response)); - context.put("request", request); context.put("response", response); context.put("session", session); Modified: incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenWidgetViewHandler.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenWidgetViewHandler.java?rev=429966&r1=429965&r2=429966&view=diff ============================================================================== --- incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenWidgetViewHandler.java (original) +++ incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenWidgetViewHandler.java Tue Aug 8 22:09:45 2006 @@ -30,6 +30,7 @@ import org.ofbiz.webapp.view.ViewHandler; import org.ofbiz.webapp.view.ViewHandlerException; import org.ofbiz.widget.html.HtmlScreenRenderer; +import org.ofbiz.widget.html.HtmlFormRenderer; import org.xml.sax.SAXException; /** @@ -72,6 +73,8 @@ ScreenRenderer screens = new ScreenRenderer(writer, null, htmlScreenRenderer); screens.populateContextForRequest(request, response, servletContext); + // this is the object used to render forms from their definitions + screens.getContext().put("formStringRenderer", new HtmlFormRenderer(request, response)); screens.render(page); } catch (IOException e) { throw new ViewHandlerException("Error in the response writer/output stream: " + e.toString(), e); |
Free forum by Nabble | Edit this page |