[ 
https://issues.apache.org/jira/browse/OFBIZ-6504?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14644187#comment-14644187
 ] 

Jacques Le Roux commented on OFBIZ-6504:
----------------------------------------

OK by percent encoding  (ie %27) the ' char (single-quote or apostrophe)
 {code}
 (indeed html entity encoding (ie ') did not work)
 {code}
I could bypass the issue due to this call to renderDropDownField macro, where 
having ' inside *'Annuler l'exemple (En projet)'* could not work
{code}
<@renderDropDownField [...] 
options=[{'key':'EXST_DEFINED','description':'Définition complète (En 
projet)'},{'key':'EXST_CANCELLED','description':'Annuler l%27exemple (En 
projet)'}] [...]  />
{code}

Since there are many (200+) single quotes used in CommonErrorUiLabels.xml (not 
only in French) I looked for a more general option to percent encode the 
description when creating the options in 
MacroFormRenderer.renderDropDownField(). Actually there the private encode() 
method, which relies on the simpleEncoder or String encoder, is already used. 
In this case, so far and I guess ever, we only need to encode the the ' char. 
So It's easier to simply force it using a String.replaceAll("'", "%27"). This 
workd, but has an annoying side-effect: then the localised labels containing a 
single quote are rendered in drop-downs with "%27" instead of '. I thought I 
could try to change that inside renderDropDownField macro in 
htmlFormMacroLibrary.ftl. But I was unable to replace "%27" by ' with 
Freemarker by using
{code}
item.description?replace("%27", "'")
{code}
I tried many solutions using regexps rather, like
{code}
replace("[%]27", "'", "r")
{code}
none worked.

So this would be my patch if I could replace % in Freemarker. BTW I'm not even 
sure it will not reintroduce the issue I'm fighting :/

{code}
Index: 
framework/widget/src/org/ofbiz/widget/renderer/macro/MacroFormRenderer.java
===================================================================
--- framework/widget/src/org/ofbiz/widget/renderer/macro/MacroFormRenderer.java 
(revision 1692606)
+++ framework/widget/src/org/ofbiz/widget/renderer/macro/MacroFormRenderer.java 
(working copy)
@@ -849,7 +849,7 @@
             if (textSize > 0 && description.length() > textSize) {
                 description = description.substring(0, textSize - 8) + "..." + 
description.substring(description.length() - 5);
             }
-            options.append(encode(description, modelFormField, context));
+            options.append(encode(description.replaceAll("'", "%27"), 
modelFormField, context));

             if (UtilValidate.isNotEmpty(currentValueList)) {
                 options.append("'");
Index: framework/widget/templates/htmlFormMacroLibrary.ftl
===================================================================
--- framework/widget/templates/htmlFormMacroLibrary.ftl (revision 1692606)
+++ framework/widget/templates/htmlFormMacroLibrary.ftl (working copy)
@@ -231,7 +231,7 @@
   <span class="ui-widget">
     <select name="${name?default("")}<#rt/>" <@renderClass className alert 
/><#if id?has_content> id="${id}"</#if><#if multiple?has_content> 
multiple="multiple"</#if><#if otherFieldSize gt 0> 
onchange="process_choice(this,document.${formName}.${otherFieldName})"</#if><#if
 event?has_content> ${event}="${action}"</#if><#if size?has_content> 
size="${size}"</#if><#if tabindex?has_content> 
tabindex="${tabindex}"</#if><#rt/>>
       <#if firstInList?has_content && currentValue?has_content && 
!multiple?has_content>
-        <option selected="selected" 
value="${currentValue}">${explicitDescription}</option><#rt/>
+        <option selected="selected" 
value="${currentValue}">${explicitDescription?replace("%27", 
"'")}</option><#rt/>
         <option value="${currentValue}">---</option><#rt/>
       </#if>
       <#if allowEmpty?has_content || !options?has_content>
@@ -239,9 +239,9 @@
       </#if>
       <#list options as item>
         <#if multiple?has_content>
-          <option<#if currentValue?has_content && item.selected?has_content> 
selected="${item.selected}" <#elseif !currentValue?has_content && 
noCurrentSelectedKey?has_content && noCurrentSelectedKey == item.key> 
selected="selected" </#if> 
value="${item.key}">${item.description}</option><#rt/>
+          <option<#if currentValue?has_content && item.selected?has_content> 
selected="${item.selected}" <#elseif !currentValue?has_content && 
noCurrentSelectedKey?has_content && noCurrentSelectedKey == item.key> 
selected="selected" </#if> 
value="${item.key}">${item.description?replace("%27", "'")}</option><#rt/>
         <#else>
-          <option<#if currentValue?has_content && currentValue == item.key && 
dDFCurrent?has_content && "selected" == dDFCurrent> selected="selected"<#elseif 
!currentValue?has_content && noCurrentSelectedKey?has_content && 
noCurrentSelectedKey == item.key> selected="selected"</#if> 
value="${item.key}">${item.description}</option><#rt/>
+          <option<#if currentValue?has_content && currentValue == item.key && 
dDFCurrent?has_content && "selected" == dDFCurrent> selected="selected"<#elseif 
!currentValue?has_content && noCurrentSelectedKey?has_content && 
noCurrentSelectedKey == item.key> selected="selected"</#if> 
value="${item.key}">${item.description?replace("[%]27", "'", 
"r")}</option><#rt/>
         </#if>
       </#list>
     </select>
{code}

> how to Create PDF with password Protected in Ofbiz
> --------------------------------------------------
>
>                 Key: OFBIZ-6504
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-6504
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: ALL APPLICATIONS
>         Environment: linux
>            Reporter: Sachin Manjule
>            Assignee: Shi Jinghai
>            Priority: Trivial
>             Fix For: Upcoming Branch
>
>         Attachments: localhost.png, trunk demo.png
>
>
> We can create PDF using FTL that is OK, but how to generate PDF with 
> Encryption password protected?
> itext is best option for this. but can we emmber in ftl or other places?
> pleas Help us.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to