Author: jacopoc
Date: Tue Apr 7 12:06:03 2009 New Revision: 762727 URL: http://svn.apache.org/viewvc?rev=762727&view=rev Log: Misc fixes and enhancements to the new Macro renderer stuff. Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java ofbiz/trunk/framework/widget/config/widget.properties ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/MacroScreenRenderer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/MacroScreenViewHandler.java ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java?rev=762727&r1=762726&r2=762727&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java Tue Apr 7 12:06:03 2009 @@ -89,16 +89,26 @@ // ================== Begin General Functions ================== + public static SimpleEncoder getEncoder(String type) { + if ("xml".equals(type)) { + return StringUtil.xmlEncoder; + } else if ("html".equals(type)) { + return StringUtil.htmlEncoder; + } else { + return null; + } + } + public static String internString(String value) { return value != null ? value.intern() : null; } /** - * Replaces all occurances of oldString in mainString with newString + * Replaces all occurrences of oldString in mainString with newString * @param mainString The original string * @param oldString The string to replace * @param newString The string to insert in place of the old - * @return mainString with all occurances of oldString replaced by newString + * @return mainString with all occurrences of oldString replaced by newString */ public static String replaceString(String mainString, String oldString, String newString) { if (mainString == null) { Modified: ofbiz/trunk/framework/widget/config/widget.properties URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/config/widget.properties?rev=762727&r1=762726&r2=762727&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/config/widget.properties (original) +++ ofbiz/trunk/framework/widget/config/widget.properties Tue Apr 7 12:06:03 2009 @@ -38,6 +38,7 @@ screen.formrenderer=component://widget/templates/htmlFormMacroLibrary.ftl screen.menurenderer=component://widget/templates/htmlMenuMacroLibrary.ftl screen.treerenderer=component://widget/templates/htmlTreeMacroLibrary.ftl +screen.encoder=html screen.default.contenttype=UTF-8 screen.default.encoding=none # text output @@ -52,5 +53,14 @@ screenxml.formrenderer=component://widget/templates/xmlFormMacroLibrary.ftl screenxml.menurenderer=component://widget/templates/xmlMenuMacroLibrary.ftl screenxml.treerenderer=component://widget/templates/xmlTreeMacroLibrary.ftl +screenxml.encoder=xml screenxml.default.contenttype=UTF-8 screenxml.default.encoding=none +# fo output +screenfop.screenrenderer=component://widget/templates/xmlScreenMacroLibrary.ftl +screenfop.formrenderer=component://widget/templates/xmlFormMacroLibrary.ftl +screenfop.menurenderer=component://widget/templates/xmlMenuMacroLibrary.ftl +screenfop.treerenderer=component://widget/templates/xmlTreeMacroLibrary.ftl +screenfop.encoder=xml +screenfop.default.contenttype=application/pdf +screenfop.default.encoding=none Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java?rev=762727&r1=762726&r2=762727&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java Tue Apr 7 12:06:03 2009 @@ -136,20 +136,6 @@ //writer.append(' '); } - private void makeTextString(Appendable writer, String widgetStyle, String text) throws IOException { - if (UtilValidate.isNotEmpty(text)) { - // FIXME: this is only valid for html and should be moved outside of this class - text = StringUtil.htmlEncoder.encode(text); - } - StringWriter sr = new StringWriter(); - sr.append("<@renderField "); - sr.append("text=\""); - sr.append(text); - sr.append("\""); - sr.append(" />"); - executeMacro(writer, sr.toString()); - } - public void renderLabel(Appendable writer, Map<String, Object> context, ModelScreenWidget.Label label) throws IOException { String labelText = label.getText(context); if (UtilValidate.isEmpty(labelText)) { @@ -306,7 +292,10 @@ } String value = modelFormField.getEntry(context, textareaField.getDefaultValue(context)); if (UtilValidate.isNotEmpty(value)) { - value = StringUtil.htmlEncoder.encode(value); + StringUtil.SimpleEncoder encoder = (StringUtil.SimpleEncoder)context.get("simpleEncoder"); + if (encoder != null) { + value = encoder.encode(value); + } } StringWriter sr = new StringWriter(); sr.append("<@renderTextareaField "); @@ -946,11 +935,16 @@ StringBuilder sb = new StringBuilder(); if (UtilValidate.isNotEmpty(titleText)) { if (" ".equals(titleText)) { - // If the title content is just a blank then render it colling renderFormatEmptySpace: + // FIXME: we have to change the following code because it is a solution that only works with html. + // If the title content is just a blank then render it calling renderFormatEmptySpace: // the method will set its content to work fine in most browser sb.append(" "); } else { - renderHyperlinkTitle(sb, context, modelFormField, StringUtil.htmlEncoder.encode(titleText)); + StringUtil.SimpleEncoder encoder = (StringUtil.SimpleEncoder)context.get("simpleEncoder"); + if (encoder != null) { + titleText = encoder.encode(titleText); + } + renderHyperlinkTitle(sb, context, modelFormField, titleText); } } StringWriter sr = new StringWriter(); @@ -1627,11 +1621,6 @@ } String size = Integer.toString(lookupField.getSize()); Integer maxlength = lookupField.getMaxlength(); - if (maxlength != null) { - writer.append(" maxlength=\""); - writer.append(maxlength.toString()); - writer.append('"'); - } String id = modelFormField.getIdName(); if (id == null) { @@ -1682,9 +1671,7 @@ sr.append("\" size=\""); sr.append(size); sr.append("\" maxlength=\""); - if (maxlength != null) { - sr.append(Integer.toString(maxlength)); - } + sr.append((maxlength != null? Integer.toString(maxlength): "")); sr.append("\" autocomplete=\""); sr.append(autocomplete); sr.append("\" descriptionFieldName=\""); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/MacroScreenRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/MacroScreenRenderer.java?rev=762727&r1=762726&r2=762727&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/MacroScreenRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/MacroScreenRenderer.java Tue Apr 7 12:06:03 2009 @@ -143,9 +143,6 @@ public void renderLabel(Appendable writer, Map<String, Object> context, ModelScreenWidget.Label label) throws IOException { String labelText = label.getText(context); - if(UtilValidate.isNotEmpty(labelText)){ - labelText = StringUtil.htmlEncoder.encode(labelText); - } StringWriter sr = new StringWriter(); sr.append("<@renderLabel "); sr.append("text=\""); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/MacroScreenViewHandler.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/MacroScreenViewHandler.java?rev=762727&r1=762726&r2=762727&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/MacroScreenViewHandler.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/MacroScreenViewHandler.java Tue Apr 7 12:06:03 2009 @@ -31,6 +31,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilJ2eeCompat; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; @@ -41,9 +42,10 @@ import org.xml.sax.SAXException; import org.ofbiz.widget.menu.MenuStringRenderer; +// TODO: uncomment these lines when the renderers are implemented //import org.ofbiz.widget.menu.MacroMenuRenderer; -import org.ofbiz.widget.tree.TreeStringRenderer; //import org.ofbiz.widget.tree.MacroTreeRenderer; +import org.ofbiz.widget.tree.TreeStringRenderer; import org.ofbiz.widget.form.FormStringRenderer; import org.ofbiz.widget.form.MacroFormRenderer; import org.ofbiz.widget.screen.ScreenStringRenderer; @@ -101,6 +103,10 @@ screens.populateContextForRequest(request, response, servletContext); // this is the object used to render forms from their definitions screens.getContext().put("formStringRenderer", formStringRenderer); + // TODO: uncomment these lines when the renderers are implemented + //screens.getContext().put("treeStringRenderer", treeStringRenderer); + //screens.getContext().put("menuStringRenderer", menuStringRenderer); + screens.getContext().put("simpleEncoder", StringUtil.getEncoder(UtilProperties.getPropertyValue("widget", getName() + ".encoder"))); screens.render(page); writer.flush(); } catch (TemplateException e) { Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=762727&r1=762726&r2=762727&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl (original) +++ ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Tue Apr 7 12:06:03 2009 @@ -125,10 +125,10 @@ <#list items as item> <input type="checkbox" <@renderClass className alert /><#rt/> <#if allChecked?has_content && allChecked> checked="checked" <#elseif allChecked?has_content && !allChecked><#elseif currentValue?has_content && currentValue==item.key> checked="checked"</#if> name="${name?default("")?html}" value="${item.key?default("")?html}"<#if event?has_content> ${event}="${action}"</#if>/><#rt/> -${item.description} +${item.description?default("")} </#list> </#macro> -<#macro renderRadioField items className alert currentValue noCurrentSelectedKey name event ation> +<#macro renderRadioField items className alert currentValue noCurrentSelectedKey name event action> <#list items as item> <div <@renderClass className alert />><#rt/> <input type="radio"<#if currentValue?has_content><#if rp.currentValue==item.key> checked="checked"</#if><#elseif noCurrentSelectedKey?has_content && noCurrentSelectedKey == item.key> checked="checked"</#if> name="${name?default("")?html}" value="${item.key?default("")?html}"<#if event?has_content> ${event}="${action}"</#if>/><#rt/> @@ -138,7 +138,7 @@ <#macro renderSubmitField buttonType className alert formName title name event action imgSrc> <#if buttonType=="text-link"> - <a <@renderClass className alert /> href="javascript:document.${formName}.submit()"><#if title?has_content> title="${title}"</#if> </a> + <a <@renderClass className alert /> href="javascript:document.${formName}.submit()"><#if title?has_content>${title}</#if> </a> <#elseif buttonType=="image"> <input type="image" src="${imgSrc}" <@renderClass className alert /><#if name?has_content> name="${name}"</#if><#if title?has_content> alt="${title}"</#if><#if event?has_content> ${event}="${action}"</#if> /> <#else> @@ -355,7 +355,7 @@ <#macro formatBoundaryComment boundaryType widgetType widgetName><!-- ${boundaryType} ${widgetType} ${widgetName} --></#macro> <#macro renderTooltip tooltip tooltipStyle><#if tooltip?has_content><span class="<#if tooltipStyle?has_content>${tooltipStyle}<#else>tooltip</#if>">${tooltip}</span><#rt/></#if></#macro> -<#macro renderClass className alert><#if className?has_content>class="${className}<#if alert?has_content> ${alert}</#if>"<#rt/></#if></#macro> +<#macro renderClass className="" alert=""><#if className?has_content>class="${className}<#if alert?has_content> ${alert}</#if>"<#rt/></#if></#macro> <#macro renderAsterisks requiredField requiredStyle><#if requiredField=="true"><#if requiredStyle?has_content>*</#if></#if></#macro> <#macro makeHiddenFormLinkForm actionUrl name parameters targetWindow><form method="post" action="${actionUrl}" <#if targetWindow?has_content>target="${targetWindow}"</#if> onSubmit="javascript:submitFormDisableSubmits(this)" name="${name}"><#list parameters as parameter><input name="${parameter.name}" value="${parameter.value}" type="hidden"/></#list></form></#macro> <#macro makeHiddenFormLinkAnchor linkStyle hiddenFormName event action imgSrc description><a <#if linkStyle?has_content>class="${linkStyle}"</#if> href="javascript:document.${hiddenFormName}.submit()"<#if action?has_content && event?has_content> ${event}="${action}"</#if>><#if imgSrc?has_content><img src="${imgSrc}"/></#if>${description}</a></#macro> |
Free forum by Nabble | Edit this page |