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:13:48 UTC

[sling-org-apache-sling-scripting-thymeleaf] 37/50: SLING-5075 Upgrade Thymeleaf to 3.0

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 cbf96a588818d6e4cff852cda8991edcd8169314
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Mon May 16 20:57:11 2016 +0000

    SLING-5075 Upgrade Thymeleaf to 3.0
    
    fix getBaseName():String and implement relative(String):ITemplateResource
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf@1744135 13f79535-47bb-0310-9956-ffa450edef68
---
 .../scripting/thymeleaf/internal/SlingTemplateResource.java  | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/scripting/thymeleaf/internal/SlingTemplateResource.java b/src/main/java/org/apache/sling/scripting/thymeleaf/internal/SlingTemplateResource.java
index 00c7230..fa46f0e 100644
--- a/src/main/java/org/apache/sling/scripting/thymeleaf/internal/SlingTemplateResource.java
+++ b/src/main/java/org/apache/sling/scripting/thymeleaf/internal/SlingTemplateResource.java
@@ -23,8 +23,11 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 
+import org.apache.commons.io.FilenameUtils;
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.path.PathBuilder;
 import org.thymeleaf.templateresource.ITemplateResource;
 
 public class SlingTemplateResource implements ITemplateResource {
@@ -44,7 +47,7 @@ public class SlingTemplateResource implements ITemplateResource {
 
     @Override
     public String getBaseName() {
-        return resource.getName();
+        return FilenameUtils.getBaseName(resource.getName());
     }
 
     @Override
@@ -63,7 +66,12 @@ public class SlingTemplateResource implements ITemplateResource {
 
     @Override
     public ITemplateResource relative(final String relativeLocation) {
-        throw new UnsupportedOperationException("not yet implemented"); // TODO
+        final PathBuilder pathBuilder = new PathBuilder(resource.getPath());
+        final String path = pathBuilder.append("..").append(relativeLocation).toString();
+        final ResourceResolver resourceResolver = resource.getResourceResolver();
+        final Resource relative = resourceResolver.getResource(path);
+        // final Resource relative = resource.getParent().getChild(relativeLocation);
+        return new SlingTemplateResource(relative);
     }
 
 }

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