sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject svn commit: r1651100 - /sling/trunk/contrib/scripting/thymeleaf/src/main/java/org/apache/sling/scripting/thymeleaf/internal/ThymeleafScriptEngineFactory.java
Date Mon, 12 Jan 2015 14:13:10 GMT
Author: olli
Date: Mon Jan 12 14:13:10 2015
New Revision: 1651100

URL: http://svn.apache.org/r1651100
Log:
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

Modified:
    sling/trunk/contrib/scripting/thymeleaf/src/main/java/org/apache/sling/scripting/thymeleaf/internal/ThymeleafScriptEngineFactory.java

Modified: sling/trunk/contrib/scripting/thymeleaf/src/main/java/org/apache/sling/scripting/thymeleaf/internal/ThymeleafScriptEngineFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/thymeleaf/src/main/java/org/apache/sling/scripting/thymeleaf/internal/ThymeleafScriptEngineFactory.java?rev=1651100&r1=1651099&r2=1651100&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/thymeleaf/src/main/java/org/apache/sling/scripting/thymeleaf/internal/ThymeleafScriptEngineFactory.java
(original)
+++ sling/trunk/contrib/scripting/thymeleaf/src/main/java/org/apache/sling/scripting/thymeleaf/internal/ThymeleafScriptEngineFactory.java
Mon Jan 12 14:13:10 2015
@@ -42,7 +42,9 @@ import org.osgi.service.component.Compon
 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 ThymeleafScriptEngineFactor
     @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 ThymeleafScriptEngineFactor
         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 ThymeleafScriptEngineFactor
         if (messageResolvers.size() > 0) {
             templateEngine.setMessageResolvers(messageResolvers);
         }
+        if (dialects.size() > 0) {
+            templateEngine.setDialects(dialects);
+            final IDialect standardDialect = new StandardDialect();
+            templateEngine.addDialect(standardDialect);
+        }
     }
 
     @Override



Mime
View raw message