cancel
Showing results for 
Search instead for 
Did you mean: 

character encoding problem with processTemplate?

alrice
Champ in-the-making
Champ in-the-making
All, I am getting very productive with the webscripts environment. It's great. But i ran into an urgent and puzzing character encoding issue. Any suggestions greatly appreciated- thanks in advance. We have lots of foreign names in this application, so it's important to be able to support accented characters at least, and preferably in utf-8 unicode.

So i've been writing all my html forms in dreamweaver doctype xhtml, and
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
The html forms have this type and charset specified also:
<form action="${url.serviceContext}/apply/postdoc08/edit?guest=true" 
        method="post"
        enctype="multipart/form-data"
      charset="utf-8">
I have a freemarker template applicant.xml.ftl that starts off
<?xml version="1.0" encoding="UTF-8"?>
So everything should be utf8 right? Indeed if i edit my source xml document with extended characters,  and save as UTF8 in TextEdit or Oxygen.app, then all my html pages render the text just fine. Those freemarker templates are xhtml, utf-8, and are loading the xml file thusly:
<#assign dom=document.xmlNodeModel>
So that all works, but the problems arises when submitting the html form. The POST is received by a .js file, which applies the template and saves the result out to the repository. Here is where i think the character encoding is getting lost:
var tScriptSpace = companyhome.childByNamePath( gPathToScriptSpace  );
var tXMLTemplateNode = tScriptSpace.childByNamePath( gXMLTemplate );
var tArgs = formFieldsToArgsArray();
var tNewApplicantXMLStr = tApplicantXMLNode.processTemplate( tXMLTemplateNode, tArgs);
tApplicantXMLNode.content = tNewApplicantXMLStr;

My best guess is the call to processTemplate() is returning the wrong character encoding somehow? Not sure. Where have I gone wrong or is it a problem with processTemplate or something i have overlooked?
14 REPLIES 14

kevinr
Star Contributor
Star Contributor
I'll assume you are using 2.1.

I haven't tried this myself (i will do) but I think you may need to override the FreeMarkerProcessor bean definition in the Spring config thus:

    <bean id="freeMarkerProcessor" parent="baseTemplateProcessor" class="org.alfresco.repo.template.FreeMarkerProcessor">
        <property name="name">
            <value>freemarker</value>
        </property>
        <property name="extension">
            <value>ftl</value>
        </property>
        <property name="defaultEncoding">
            <value>UTF-8</value>
        </property>
    </bean>

As the JavaScript API is going direct to the template processor, it does not know the encoding of the source webscript page that is executing within. I'll take a look as it should be possible to fix this for a future version.

Thanks,

Kevin

alrice
Champ in-the-making
Champ in-the-making
Kevin, thanks but i am unable to get this fix to work. I added your bean definition to web-client-config-custom.xml in /opt/tomcat/shared/classes/alfresco/extension and then restarted tomcat.
I get the same result when I enter UTF8 characters into my form and save it.

alrice
Champ in-the-making
Champ in-the-making
Also yes: Alfresco Enterprise Network v2.1.0 (112)

kevinr
Star Contributor
Star Contributor
Sorry the bean config i sent is not web-client config. It is repository config and therefore will go in your custom-db-and-data-context.xml or similar.

Thanks,

Kevin

alrice
Champ in-the-making
Champ in-the-making
Kevin, i tried putting it in /opt/tomcat/shared/classes/alfresco/extension/custom-db-and-data-context.xml
but the same problem still.

alrice
Champ in-the-making
Champ in-the-making
Also i opened a support incident on this yesterday- just wanted to let you know so efforts are not duplicated.

kevinr
Star Contributor
Star Contributor
Thanks. I have opened a JIRA item to track the bug investigation and fix: http://issues.alfresco.com/browse/AR-1829

Kevin

kevinr
Star Contributor
Star Contributor
The issue has been investigated and fixed.

For your testing purposes, I have provided the modified .class file here. You can patch it into your alfresco-web-client.jar inside the alfresco.war file and check it works for you. I think the config change I posted above should fix any issues with processTemplate() - but that doesn't look like it was the issue anyway.

Thanks,

Kevin

alrice
Champ in-the-making
Champ in-the-making
Kevin, thanks i will test and reply as soon as I am able. what is the best method of testing actually? i am not sure how to "patch it into your alfresco-web-client.jar inside the alfresco.war file"
I am not that familiar with how tomcat expands these files.