You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:12:23 UTC

[sling-org-apache-sling-scripting-thymeleaf] 07/17: SLING-3649 make encoding for reading templates configurable

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

rombert pushed a commit to annotated tag org.apache.sling.scripting.thymeleaf-0.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-thymeleaf.git

commit 0cc1b60e452acf7db0035942b2eca3056c4eb695
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Thu Jun 12 09:35:13 2014 +0000

    SLING-3649 make encoding for reading templates configurable
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/scripting/thymeleaf@1602107 13f79535-47bb-0310-9956-ffa450edef68
---
 README.md                                                     |  1 -
 .../scripting/thymeleaf/ThymeleafScriptEngineFactory.java     |  2 --
 .../scripting/thymeleaf/impl/NonCachingTemplateResolver.java  | 11 +++++++++--
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 85faa4d..07ed35d 100644
--- a/README.md
+++ b/README.md
@@ -12,4 +12,3 @@ Features
 * out of the box support for _legacy_ HTML5 through embedded _NekoHTML_
 * runtime configurable `TemplateModeHandler`s for _XML_, _VALIDXML_, _XHTML_, _VALIDXHTML_, _HTML5_ and _LEGACYHTML5_
 * `MessageResolver` backed by `ResourceBundleProvider` from `org.apache.sling.i18n`
-* uses `UTF-8` charset for reading templates
diff --git a/src/main/java/org/apache/sling/scripting/thymeleaf/ThymeleafScriptEngineFactory.java b/src/main/java/org/apache/sling/scripting/thymeleaf/ThymeleafScriptEngineFactory.java
index 57eb200..486f6b5 100644
--- a/src/main/java/org/apache/sling/scripting/thymeleaf/ThymeleafScriptEngineFactory.java
+++ b/src/main/java/org/apache/sling/scripting/thymeleaf/ThymeleafScriptEngineFactory.java
@@ -82,8 +82,6 @@ public class ThymeleafScriptEngineFactory extends AbstractScriptEngineFactory {
     @Property(value = {DEFAULT_NAME}, unbounded = PropertyUnbounded.ARRAY)
     public static final String NAMES_PARAMETER = "org.apache.sling.scripting.thymeleaf.names";
 
-    public static final String TEMPLATE_CHARSET = "UTF-8";
-
     private final Logger logger = LoggerFactory.getLogger(ThymeleafScriptEngineFactory.class);
 
     public ThymeleafScriptEngineFactory() {
diff --git a/src/main/java/org/apache/sling/scripting/thymeleaf/impl/NonCachingTemplateResolver.java b/src/main/java/org/apache/sling/scripting/thymeleaf/impl/NonCachingTemplateResolver.java
index 4d6af69..6d6e777 100644
--- a/src/main/java/org/apache/sling/scripting/thymeleaf/impl/NonCachingTemplateResolver.java
+++ b/src/main/java/org/apache/sling/scripting/thymeleaf/impl/NonCachingTemplateResolver.java
@@ -34,7 +34,6 @@ import org.apache.felix.scr.annotations.ReferencePolicy;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.scripting.thymeleaf.SlingTemplateModeHandler;
-import org.apache.sling.scripting.thymeleaf.ThymeleafScriptEngineFactory;
 import org.osgi.framework.Constants;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
@@ -72,6 +71,13 @@ public class NonCachingTemplateResolver implements ITemplateResolver {
     @Property(intValue = DEFAULT_ORDER)
     public static final String ORDER_PARAMETER = "org.apache.sling.scripting.thymeleaf.impl.NonCachingTemplateResolver.order";
 
+    private String encoding;
+
+    public static final String DEFAULT_ENCODING = "UTF-8";
+
+    @Property(value = DEFAULT_ENCODING)
+    public static final String ENCODING_PARAMETER = "org.apache.sling.scripting.thymeleaf.impl.NonCachingTemplateResolver.encoding";
+
     private final Logger logger = LoggerFactory.getLogger(NonCachingTemplateResolver.class);
 
     public NonCachingTemplateResolver() {
@@ -107,6 +113,7 @@ public class NonCachingTemplateResolver implements ITemplateResolver {
     private synchronized void configure(final ComponentContext componentContext) {
         final Dictionary properties = componentContext.getProperties();
         order = PropertiesUtil.toInteger(properties.get(ORDER_PARAMETER), DEFAULT_ORDER);
+        encoding = PropertiesUtil.toString(properties.get(ENCODING_PARAMETER), DEFAULT_ENCODING);
     }
 
     @Override
@@ -123,7 +130,7 @@ public class NonCachingTemplateResolver implements ITemplateResolver {
     public TemplateResolution resolveTemplate(TemplateProcessingParameters templateProcessingParameters) {
         final String templateName = templateProcessingParameters.getTemplateName();
         final String resourceName = templateName; // TODO
-        final String characterEncoding = ThymeleafScriptEngineFactory.TEMPLATE_CHARSET;
+        final String characterEncoding = encoding;
         final String templateMode = computeTemplateMode(templateName);
         final ITemplateResolutionValidity validity = new NonCacheableTemplateResolutionValidity();
         return new TemplateResolution(templateName, resourceName, resourceResolver, characterEncoding, templateMode, validity);

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.