You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2019/09/22 09:13:45 UTC

[sling-org-apache-sling-scripting-freemarker] branch master updated (bf14d1e -> 4ab98f7)

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

olli pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-freemarker.git.


    from bf14d1e  SLING-8504 Update Felix Framework to 6.0.3
     new 30c5b87  polish HTML
     new aba3a60  SLING-8729 Make value map of current resource available in bindings as properties
     new a57ffe0  style
     new 4ab98f7  move initial content to directory initial-content

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../internal/FreemarkerBindingsValuesProvider.java | 45 ++++++++++++++++++++++
 ...ava => FreemarkerBindingsValuesProviderIT.java} | 17 +++-----
 .../freemarker/it/tests/FreemarkerTestSupport.java |  6 +--
 .../scripting/freemarker/it/tests/SimpleIT.java    |  2 +-
 .../apps/freemarker/page/adaptto/html.ftl          |  2 +-
 .../apps/freemarker/page/bindings}/html.ftl        |  5 +--
 .../apps/freemarker/page/include/html.ftl          |  2 +-
 .../apps/freemarker/page/simple/html.ftl           |  2 +-
 .../apps/jsp/page/resource/html.jsp                |  0
 .../{ => initial-content}/content/freemarker.json  |  8 +++-
 10 files changed, 64 insertions(+), 25 deletions(-)
 create mode 100644 src/main/java/org/apache/sling/scripting/freemarker/internal/FreemarkerBindingsValuesProvider.java
 copy src/test/java/org/apache/sling/scripting/freemarker/it/tests/{SimpleIT.java => FreemarkerBindingsValuesProviderIT.java} (82%)
 rename src/test/resources/{ => initial-content}/apps/freemarker/page/adaptto/html.ftl (98%)
 copy src/test/resources/{apps/freemarker/page/simple => initial-content/apps/freemarker/page/bindings}/html.ftl (89%)
 rename src/test/resources/{ => initial-content}/apps/freemarker/page/include/html.ftl (98%)
 rename src/test/resources/{ => initial-content}/apps/freemarker/page/simple/html.ftl (98%)
 rename src/test/resources/{ => initial-content}/apps/jsp/page/resource/html.jsp (100%)
 rename src/test/resources/{ => initial-content}/content/freemarker.json (75%)


[sling-org-apache-sling-scripting-freemarker] 03/04: style

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-freemarker.git

commit a57ffe0240eacc069aab40f7e60d73bdc32f2136
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Sun Sep 22 11:05:27 2019 +0200

    style
---
 .../java/org/apache/sling/scripting/freemarker/it/tests/SimpleIT.java   | 2 +-
 src/test/resources/content/freemarker.json                              | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/test/java/org/apache/sling/scripting/freemarker/it/tests/SimpleIT.java b/src/test/java/org/apache/sling/scripting/freemarker/it/tests/SimpleIT.java
index cf4d5ae..a8c05ca 100644
--- a/src/test/java/org/apache/sling/scripting/freemarker/it/tests/SimpleIT.java
+++ b/src/test/java/org/apache/sling/scripting/freemarker/it/tests/SimpleIT.java
@@ -68,7 +68,7 @@ public class SimpleIT extends FreemarkerTestSupport {
 
     @Test
     public void testTitle() {
-        assertThat(document.title(), is("freemarker simple"));
+        assertThat(document.title(), is("FreeMarker Simple"));
     }
 
     @Test
diff --git a/src/test/resources/content/freemarker.json b/src/test/resources/content/freemarker.json
index ab27dd8..101fe12 100644
--- a/src/test/resources/content/freemarker.json
+++ b/src/test/resources/content/freemarker.json
@@ -7,7 +7,7 @@
         "jcr:primaryType": "nt:unstructured",
         "sling:resourceType": "freemarker/page/simple",
         "sling:resourceSuperType": "freemarker/page",
-        "title": "freemarker simple"
+        "title": "FreeMarker Simple"
     },
     "adaptto": {
         "jcr:primaryType": "nt:unstructured",


[sling-org-apache-sling-scripting-freemarker] 04/04: move initial content to directory initial-content

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-freemarker.git

commit 4ab98f796e1f97622dd578e804add9e21356c7a4
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Sun Sep 22 11:13:08 2019 +0200

    move initial content to directory initial-content
---
 .../sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java  | 6 +-----
 .../{ => initial-content}/apps/freemarker/page/adaptto/html.ftl     | 0
 .../{ => initial-content}/apps/freemarker/page/bindings/html.ftl    | 0
 .../{ => initial-content}/apps/freemarker/page/include/html.ftl     | 0
 .../{ => initial-content}/apps/freemarker/page/simple/html.ftl      | 0
 .../resources/{ => initial-content}/apps/jsp/page/resource/html.jsp | 0
 src/test/resources/{ => initial-content}/content/freemarker.json    | 0
 7 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java b/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java
index 5f64874..209c244 100644
--- a/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java
+++ b/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java
@@ -86,11 +86,7 @@ public abstract class FreemarkerTestSupport extends TestSupport {
     public TestProbeBuilder probeConfiguration(final TestProbeBuilder testProbeBuilder) {
         testProbeBuilder.setHeader(Constants.EXPORT_PACKAGE, "org.apache.sling.scripting.freemarker.it.app");
         testProbeBuilder.setHeader("Sling-Model-Packages", "org.apache.sling.scripting.freemarker.it.app");
-        testProbeBuilder.setHeader("Sling-Initial-Content", String.join(",",
-            "apps/freemarker;path:=/apps/freemarker;overwrite:=true;uninstall:=true",
-            "apps/jsp;path:=/apps/jsp;overwrite:=true;uninstall:=true",
-            "content;path:=/content;overwrite:=true;uninstall:=true"
-        ));
+        testProbeBuilder.setHeader("Sling-Initial-Content", "initial-content");
         return testProbeBuilder;
     }
 
diff --git a/src/test/resources/apps/freemarker/page/adaptto/html.ftl b/src/test/resources/initial-content/apps/freemarker/page/adaptto/html.ftl
similarity index 100%
rename from src/test/resources/apps/freemarker/page/adaptto/html.ftl
rename to src/test/resources/initial-content/apps/freemarker/page/adaptto/html.ftl
diff --git a/src/test/resources/apps/freemarker/page/bindings/html.ftl b/src/test/resources/initial-content/apps/freemarker/page/bindings/html.ftl
similarity index 100%
rename from src/test/resources/apps/freemarker/page/bindings/html.ftl
rename to src/test/resources/initial-content/apps/freemarker/page/bindings/html.ftl
diff --git a/src/test/resources/apps/freemarker/page/include/html.ftl b/src/test/resources/initial-content/apps/freemarker/page/include/html.ftl
similarity index 100%
rename from src/test/resources/apps/freemarker/page/include/html.ftl
rename to src/test/resources/initial-content/apps/freemarker/page/include/html.ftl
diff --git a/src/test/resources/apps/freemarker/page/simple/html.ftl b/src/test/resources/initial-content/apps/freemarker/page/simple/html.ftl
similarity index 100%
rename from src/test/resources/apps/freemarker/page/simple/html.ftl
rename to src/test/resources/initial-content/apps/freemarker/page/simple/html.ftl
diff --git a/src/test/resources/apps/jsp/page/resource/html.jsp b/src/test/resources/initial-content/apps/jsp/page/resource/html.jsp
similarity index 100%
rename from src/test/resources/apps/jsp/page/resource/html.jsp
rename to src/test/resources/initial-content/apps/jsp/page/resource/html.jsp
diff --git a/src/test/resources/content/freemarker.json b/src/test/resources/initial-content/content/freemarker.json
similarity index 100%
rename from src/test/resources/content/freemarker.json
rename to src/test/resources/initial-content/content/freemarker.json


[sling-org-apache-sling-scripting-freemarker] 01/04: polish HTML

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-freemarker.git

commit 30c5b87119eb40d4482e5c39e9a94c820a7303d9
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Sat Sep 21 11:27:19 2019 +0200

    polish HTML
---
 src/test/resources/apps/freemarker/page/adaptto/html.ftl | 2 +-
 src/test/resources/apps/freemarker/page/include/html.ftl | 2 +-
 src/test/resources/apps/freemarker/page/simple/html.ftl  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/test/resources/apps/freemarker/page/adaptto/html.ftl b/src/test/resources/apps/freemarker/page/adaptto/html.ftl
index 10ce5c0..0e49f13 100644
--- a/src/test/resources/apps/freemarker/page/adaptto/html.ftl
+++ b/src/test/resources/apps/freemarker/page/adaptto/html.ftl
@@ -18,7 +18,7 @@
     under the License.
 -->
 <#assign page = sling.adaptTo(request, "org.apache.sling.scripting.freemarker.it.app.Page")>
-<html>
+<html lang="en">
 <head>
   <meta charset="UTF-8"/>
   <title>${page.title!'title'?html}</title>
diff --git a/src/test/resources/apps/freemarker/page/include/html.ftl b/src/test/resources/apps/freemarker/page/include/html.ftl
index bf05d44..3cb2828 100644
--- a/src/test/resources/apps/freemarker/page/include/html.ftl
+++ b/src/test/resources/apps/freemarker/page/include/html.ftl
@@ -17,7 +17,7 @@
     specific language governing permissions and limitations
     under the License.
 -->
-<html>
+<html lang="en">
 <head>
   <meta charset="UTF-8"/>
   <title>Sling Include (with JSP)</title>
diff --git a/src/test/resources/apps/freemarker/page/simple/html.ftl b/src/test/resources/apps/freemarker/page/simple/html.ftl
index f754155..70085e0 100644
--- a/src/test/resources/apps/freemarker/page/simple/html.ftl
+++ b/src/test/resources/apps/freemarker/page/simple/html.ftl
@@ -17,7 +17,7 @@
     specific language governing permissions and limitations
     under the License.
 -->
-<html>
+<html lang="en">
 <head>
   <meta charset="UTF-8"/>
   <title>${resource.valueMap.title!''?html}</title>


[sling-org-apache-sling-scripting-freemarker] 02/04: SLING-8729 Make value map of current resource available in bindings as properties

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-freemarker.git

commit aba3a6083579e4fa2711350e8f7055998a9cb876
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Sun Sep 22 11:04:36 2019 +0200

    SLING-8729 Make value map of current resource available in bindings as properties
---
 .../internal/FreemarkerBindingsValuesProvider.java | 45 +++++++++++++
 .../tests/FreemarkerBindingsValuesProviderIT.java  | 73 ++++++++++++++++++++++
 .../apps/freemarker/page/bindings/html.ftl         | 27 ++++++++
 src/test/resources/content/freemarker.json         |  6 ++
 4 files changed, 151 insertions(+)

diff --git a/src/main/java/org/apache/sling/scripting/freemarker/internal/FreemarkerBindingsValuesProvider.java b/src/main/java/org/apache/sling/scripting/freemarker/internal/FreemarkerBindingsValuesProvider.java
new file mode 100644
index 0000000..989abb8
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/freemarker/internal/FreemarkerBindingsValuesProvider.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.scripting.freemarker.internal;
+
+import javax.script.Bindings;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.scripting.api.BindingsValuesProvider;
+import org.osgi.service.component.annotations.Component;
+
+@Component(
+    property = {
+        "javax.script.name=freemarker"
+    }
+)
+public class FreemarkerBindingsValuesProvider implements BindingsValuesProvider {
+
+    private static final String PROPERTIES = "properties";
+
+    @Override
+    public void addBindings(final Bindings bindings) {
+        if (!bindings.containsKey(PROPERTIES)) {
+            final Resource resource = (Resource) bindings.get(SlingBindings.RESOURCE);
+            if (resource != null) {
+                bindings.put(PROPERTIES, resource.getValueMap());
+            }
+        }
+    }
+
+}
diff --git a/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerBindingsValuesProviderIT.java b/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerBindingsValuesProviderIT.java
new file mode 100644
index 0000000..434fdfa
--- /dev/null
+++ b/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerBindingsValuesProviderIT.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.scripting.freemarker.it.tests;
+
+import java.io.IOException;
+
+import javax.inject.Inject;
+
+import org.apache.sling.resource.presence.ResourcePresence;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.Filter;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class FreemarkerBindingsValuesProviderIT extends FreemarkerTestSupport {
+
+    private Document document;
+
+    @Inject
+    @Filter(value = "(path=/apps/freemarker/page/bindings/html.ftl)")
+    private ResourcePresence resourcePresence;
+
+    @Configuration
+    public Option[] configuration() {
+        return new Option[]{
+            baseConfiguration(),
+            factoryConfiguration("org.apache.sling.resource.presence.internal.ResourcePresenter")
+                .put("path", "/apps/freemarker/page/bindings/html.ftl")
+                .asOption(),
+        };
+    }
+
+    @Before
+    public void setup() throws IOException {
+        final String url = String.format("http://localhost:%s/freemarker/bindings.html", httpPort());
+        document = Jsoup.connect(url).get();
+    }
+
+    @Test
+    public void testTitle() {
+        assertThat(document.title(), is("FreeMarker Bindings"));
+    }
+
+}
diff --git a/src/test/resources/apps/freemarker/page/bindings/html.ftl b/src/test/resources/apps/freemarker/page/bindings/html.ftl
new file mode 100644
index 0000000..f99a537
--- /dev/null
+++ b/src/test/resources/apps/freemarker/page/bindings/html.ftl
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<html lang="en">
+<head>
+  <meta charset="UTF-8"/>
+  <title>${properties.title!''?html}</title>
+</head>
+<body>
+</body>
+</html>
diff --git a/src/test/resources/content/freemarker.json b/src/test/resources/content/freemarker.json
index ec418d9..ab27dd8 100644
--- a/src/test/resources/content/freemarker.json
+++ b/src/test/resources/content/freemarker.json
@@ -15,6 +15,12 @@
         "sling:resourceSuperType": "freemarker/page",
         "title": "Sling Models adaptTo()"
     },
+    "bindings": {
+        "jcr:primaryType": "nt:unstructured",
+        "sling:resourceType": "freemarker/page/bindings",
+        "sling:resourceSuperType": "freemarker/page",
+        "title": "FreeMarker Bindings"
+    },
     "include": {
         "jcr:primaryType": "nt:unstructured",
         "sling:resourceType": "freemarker/page/include",