sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-scripting-thymeleaf] 07/27: SLING-4296 add support for custom dialects
Date Tue, 07 Nov 2017 10:12:50 GMT
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.6
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-thymeleaf.git

commit c1f41d96a2a3b47b849f5f5ea8be8f772b4b096a
Author: Oliver Lietz <olli@apache.org>
AuthorDate: Mon Jan 12 14:13:10 2015 +0000

    SLING-4296 add support for custom dialects
    
    * template engine uses dialects (org.thymeleaf.dialect.IDialect) provided as OSGi service
    * org.thymeleaf.standard.StandardDialect is provided by default
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/scripting/thymeleaf@1651100
13f79535-47bb-0310-9956-ffa450edef68
---
 .../internal/ThymeleafScriptEngineFactory.java     | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/main/java/org/apache/sling/scripting/thymeleaf/internal/ThymeleafScriptEngineFactory.java
b/src/main/java/org/apache/sling/scripting/thymeleaf/internal/ThymeleafScriptEngineFactory.java
index 24174fd..74e5eab 100644
--- a/src/main/java/org/apache/sling/scripting/thymeleaf/internal/ThymeleafScriptEngineFactory.java
+++ b/src/main/java/org/apache/sling/scripting/thymeleaf/internal/ThymeleafScriptEngineFactory.java
@@ -42,7 +42,9 @@ import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.thymeleaf.TemplateEngine;
+import org.thymeleaf.dialect.IDialect;
 import org.thymeleaf.messageresolver.IMessageResolver;
+import org.thymeleaf.standard.StandardDialect;
 import org.thymeleaf.templateresolver.ITemplateResolver;
 
 @Component(
@@ -65,6 +67,9 @@ public class ThymeleafScriptEngineFactory extends AbstractScriptEngineFactory
{
     @Reference(referenceInterface = IMessageResolver.class, cardinality = ReferenceCardinality.MANDATORY_MULTIPLE,
policy = ReferencePolicy.DYNAMIC)
     final private Set<IMessageResolver> messageResolvers = new LinkedHashSet<IMessageResolver>();
 
+    @Reference(referenceInterface = IDialect.class, cardinality = ReferenceCardinality.MANDATORY_MULTIPLE,
policy = ReferencePolicy.DYNAMIC)
+    final private Set<IDialect> dialects = new LinkedHashSet<IDialect>();
+
     private TemplateEngine templateEngine;
 
     public static final String DEFAULT_EXTENSION = "html";
@@ -131,6 +136,18 @@ public class ThymeleafScriptEngineFactory extends AbstractScriptEngineFactory
{
         configureTemplateEngine();
     }
 
+    protected synchronized void bindDialects(final IDialect dialect) {
+        logger.debug("binding a dialect for prefix '{}'", dialect.getPrefix());
+        dialects.add(dialect);
+        configureTemplateEngine();
+    }
+
+    protected synchronized void unbindDialects(final IDialect dialect) {
+        logger.debug("unbinding a dialect for prefix '{}'", dialect.getPrefix());
+        dialects.remove(dialect);
+        configureTemplateEngine();
+    }
+
     private synchronized void configure(final ComponentContext componentContext) {
         final Dictionary properties = componentContext.getProperties();
 
@@ -156,6 +173,11 @@ public class ThymeleafScriptEngineFactory extends AbstractScriptEngineFactory
{
         if (messageResolvers.size() > 0) {
             templateEngine.setMessageResolvers(messageResolvers);
         }
+        if (dialects.size() > 0) {
+            templateEngine.setDialects(dialects);
+            final IDialect standardDialect = new StandardDialect();
+            templateEngine.addDialect(standardDialect);
+        }
     }
 
     @Override

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

Mime
View raw message