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] 26/50: SLING-5075 Upgrade Thymeleaf to 3.0
Date Tue, 07 Nov 2017 10:13:37 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-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-thymeleaf.git

commit 25083edfd0eeaa70cde1730f2f0038b796c6d84f
Author: Oliver Lietz <olli@apache.org>
AuthorDate: Fri May 13 12:28:13 2016 +0000

    SLING-5075 Upgrade Thymeleaf to 3.0
    
    add support for ILinkBuilder and IDecoupledTemplateLogicResolver services
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf@1743664
13f79535-47bb-0310-9956-ffa450edef68
---
 .../internal/ThymeleafScriptEngineFactory.java     | 62 ++++++++++++++++++++++
 1 file changed, 62 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 03f0387..2f58531 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
@@ -47,8 +47,10 @@ import org.thymeleaf.ITemplateEngine;
 import org.thymeleaf.TemplateEngine;
 import org.thymeleaf.cache.ICacheManager;
 import org.thymeleaf.dialect.IDialect;
+import org.thymeleaf.linkbuilder.ILinkBuilder;
 import org.thymeleaf.messageresolver.IMessageResolver;
 import org.thymeleaf.standard.StandardDialect;
+import org.thymeleaf.templateparser.markup.decoupled.IDecoupledTemplateLogicResolver;
 import org.thymeleaf.templateresolver.ITemplateResolver;
 
 @Component(
@@ -89,6 +91,23 @@ public final class ThymeleafScriptEngineFactory extends AbstractScriptEngineFact
     private List<IDialect> dialects;
 
     @Reference(
+        cardinality = ReferenceCardinality.MULTIPLE,
+        policy = ReferencePolicy.DYNAMIC,
+        bind = "addLinkBuilder",
+        unbind = "removeLinkBuilder"
+    )
+    private List<ILinkBuilder> linkBuilders;
+
+    @Reference(
+        cardinality = ReferenceCardinality.OPTIONAL,
+        policy = ReferencePolicy.DYNAMIC,
+        policyOption = ReferencePolicyOption.GREEDY,
+        bind = "setDecoupledTemplateLogicResolver",
+        unbind = "unsetDecoupledTemplateLogicResolver"
+    )
+    private volatile IDecoupledTemplateLogicResolver decoupledTemplateLogicResolver;
+
+    @Reference(
         cardinality = ReferenceCardinality.OPTIONAL,
         policy = ReferencePolicy.DYNAMIC,
         policyOption = ReferencePolicyOption.GREEDY,
@@ -164,6 +183,42 @@ public final class ThymeleafScriptEngineFactory extends AbstractScriptEngineFact
         }
     }
 
+    protected void addLinkBuilder(final ILinkBuilder linkBuilder) {
+        synchronized (lock) {
+            logger.debug("adding link builder '{}'", linkBuilder.getName());
+            if (templateEngine == null || templateEngine.isInitialized()) {
+                serviceTemplateEngine();
+            } else {
+                templateEngine.addLinkBuilder(linkBuilder);
+            }
+        }
+    }
+
+    protected void removeLinkBuilder(final ILinkBuilder linkBuilder) {
+        synchronized (lock) {
+            logger.debug("removing link builder '{}'", linkBuilder.getName());
+            serviceTemplateEngine();
+        }
+    }
+
+    protected void setDecoupledTemplateLogicResolver(final IDecoupledTemplateLogicResolver
decoupledTemplateLogicResolver) {
+        synchronized (lock) {
+            logger.debug("setting decoupled template logic resolver '{}'", decoupledTemplateLogicResolver.getClass().getName());
+            if (templateEngine == null || templateEngine.isInitialized()) {
+                serviceTemplateEngine();
+            } else {
+                templateEngine.setDecoupledTemplateLogicResolver(decoupledTemplateLogicResolver);
+            }
+        }
+    }
+
+    protected void unsetDecoupledTemplateLogicResolver(final IDecoupledTemplateLogicResolver
decoupledTemplateLogicResolver) {
+        synchronized (lock) {
+            logger.debug("unsetting decoupled template logic resolver '{}'", decoupledTemplateLogicResolver.getClass().getName());
+            serviceTemplateEngine();
+        }
+    }
+
     protected void setCacheManager(final ICacheManager cacheManager) {
         synchronized (lock) {
             logger.debug("setting cache manager '{}'", cacheManager.getClass().getName());
@@ -253,12 +308,19 @@ public final class ThymeleafScriptEngineFactory extends AbstractScriptEngineFact
             final Set<IMessageResolver> messageResolvers = new HashSet<>(this.messageResolvers);
             templateEngine.setMessageResolvers(messageResolvers);
         }
+        if (this.linkBuilders != null) {
+            final Set<ILinkBuilder> linkBuilders = new HashSet<>(this.linkBuilders);
+            templateEngine.setLinkBuilders(linkBuilders);
+        }
         if (this.dialects != null) {
             final Set<IDialect> dialects = new HashSet<>(this.dialects);
             templateEngine.setDialects(dialects);
         }
         final IDialect standardDialect = new StandardDialect();
         templateEngine.addDialect(standardDialect);
+        if (decoupledTemplateLogicResolver != null) {
+            templateEngine.setDecoupledTemplateLogicResolver(decoupledTemplateLogicResolver);
+        }
         templateEngine.setCacheManager(cacheManager);
         this.templateEngine = templateEngine;
     }

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

Mime
View raw message