[ofbiz-framework] branch trunk updated: Improved: Allow <html-template> to accept CDATA (OFBIZ-7004)

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

[ofbiz-framework] branch trunk updated: Improved: Allow <html-template> to accept CDATA (OFBIZ-7004)

James Yong-2
This is an automated email from the ASF dual-hosted git repository.

jamesyong pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new a8eb8bc  Improved: Allow <html-template> to accept CDATA (OFBIZ-7004)
a8eb8bc is described below

commit a8eb8bc059f81ae02db9edcd6e13ebc92793f6af
Author: James Yong <[hidden email]>
AuthorDate: Thu Sep 10 09:12:05 2020 +0800

    Improved: Allow <html-template> to accept CDATA (OFBIZ-7004)
   
    Allow inline content
   
    Thanks: Jacques for review in 2016
---
 framework/widget/dtd/widget-screen.xsd                      |  2 +-
 .../main/java/org/apache/ofbiz/widget/model/HtmlWidget.java | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/framework/widget/dtd/widget-screen.xsd b/framework/widget/dtd/widget-screen.xsd
index 99f32b1..be4e5b2 100644
--- a/framework/widget/dtd/widget-screen.xsd
+++ b/framework/widget/dtd/widget-screen.xsd
@@ -518,7 +518,7 @@ under the License.
         </xs:complexType>
     </xs:element>
     <xs:attributeGroup name="attlist.html-template">
-        <xs:attribute type="xs:string" name="location" use="required" />
+        <xs:attribute type="xs:string" name="location" use="optional" />
         <xs:attribute type="xs:boolean" name="multi-block" use="optional" default="false">
             <xs:annotation>
                 <xs:documentation>
diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
index dd6593e..163fffd 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
@@ -202,11 +202,13 @@ public class HtmlWidget extends ModelScreenWidget {
     public static class HtmlTemplate extends ModelScreenWidget {
         private FlexibleStringExpander locationExdr;
         private boolean multiBlock;
+        private String inlineFTL;
 
         public HtmlTemplate(ModelScreen modelScreen, Element htmlTemplateElement) {
             super(modelScreen, htmlTemplateElement);
             this.locationExdr = FlexibleStringExpander.getInstance(htmlTemplateElement.getAttribute("location"));
             this.multiBlock = !"false".equals(htmlTemplateElement.getAttribute("multi-block"));
+            this.inlineFTL = htmlTemplateElement.getTextContent();
         }
 
         /**
@@ -229,6 +231,17 @@ public class HtmlWidget extends ModelScreenWidget {
         @Override
         public void renderWidgetString(Appendable writer, Map<String, Object> context, ScreenStringRenderer screenStringRenderer) throws IOException {
 
+            if (UtilValidate.isNotEmpty(this.inlineFTL)) {
+                try {
+                    FreeMarkerWorker.renderTemplateFromString("", this.inlineFTL, context, writer, 0, false);
+                } catch (TemplateException | IOException e) {
+                    String errMsg = "Error rendering [" + this.inlineFTL + "]: " + e.toString();
+                    Debug.logError(e, errMsg, MODULE);
+                    writeError(writer, errMsg);
+                }
+                return;
+            }
+
             if (!isMultiBlock() && !Debug.verboseOn()) {
                 renderHtmlTemplate(writer, locationExdr, context);
                 return;