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 2021/07/13 14:10:44 UTC

[sling-project-archetype] 01/01: SLING-10608 - Refresh sample servlets

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

rombert pushed a commit to branch feature/SLING-10608
in repository https://gitbox.apache.org/repos/asf/sling-project-archetype.git

commit e0c993a46c209867cf798b0dc7e0b80d8d10c631
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Tue Jul 13 17:10:01 2021 +0300

    SLING-10608 - Refresh sample servlets
---
 .../src/main/java/servlet/ByPathServlet.java           |  6 ++++++
 .../src/main/java/servlet/ByResourceTypeServlet.java   |  9 +++++++++
 .../{ByResourceTypeServlet.java => ZipServlet.java}    | 18 +++++++++++++-----
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ByPathServlet.java b/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ByPathServlet.java
index 44dc8b6..3fb803e 100644
--- a/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ByPathServlet.java
+++ b/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ByPathServlet.java
@@ -36,6 +36,12 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Hello World Servlet registered by path
+ * 
+ * This servlet registers itself to a specific path, namely <tt>/hello-world-servlet</tt>.
+ * Note that this is discouraged and binding servlet resources is the preferred
+ * way.
+ * 
+ * @see <a href="https://sling.apache.org/documentation/the-sling-engine/servlets.html">Servlets and Scripts</a>
  */
 @Component(
     service = Servlet.class,
diff --git a/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ByResourceTypeServlet.java b/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ByResourceTypeServlet.java
index cde87c9..7ffeba3 100644
--- a/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ByResourceTypeServlet.java
+++ b/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ByResourceTypeServlet.java
@@ -37,6 +37,15 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Hello World Servlet registered by resource type
+ * 
+ * <p>This servlet binds to the <tt>sling/servlet/default</tt> resource type,
+ * which means that it is registered for all resources. The registration is
+ * narrowed down by the selectors and extensions.</p>
+ * 
+ * <p>Assuming the sample content is installed, it will serve requests of the form
+ * <tt>GET /${symbol_dollar}{resource}.hello.html</tt></p>
+ * 
+ * @see <a href="https://sling.apache.org/documentation/the-sling-engine/servlets.html">Servlets and Scripts</a>
  */
 @Component(
     service = Servlet.class,
diff --git a/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ByResourceTypeServlet.java b/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ZipServlet.java
similarity index 78%
copy from src/main/resources/archetype-resources/core.example/src/main/java/servlet/ByResourceTypeServlet.java
copy to src/main/resources/archetype-resources/core.example/src/main/java/servlet/ZipServlet.java
index cde87c9..7eae264 100644
--- a/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ByResourceTypeServlet.java
+++ b/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ZipServlet.java
@@ -36,20 +36,28 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Hello World Servlet registered by resource type
+ * Download servlet
+ * 
+ * <p>This servlet binds all resources of the type <tt>${appsFolderName}/home</tt>
+ * and the zip extension. It generates a simplistic zip archive of all the child
+ * pages, based on the <tt>jcr:title</tt> and <tt>jcr:content</tt> properties.</p>
+ * 
+ * <p>Assuming the sample content is installed, it will serve requests of the form 
+ * <tt>GET /content/{contentFolderName}/home.zip</tt></p>
+ * 
+ * @see <a href="https://sling.apache.org/documentation/the-sling-engine/servlets.html">Servlets and Scripts</a>
  */
 @Component(
     service = Servlet.class,
     property = {
         Constants.SERVICE_DESCRIPTION + "=Hello World Path Servlet",
         Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
-        "sling.servlet.resourceTypes=sling/servlet/default",
-        "sling.servlet.selectors=hello",
-        "sling.servlet.extensions=html",
+        "sling.servlet.resourceTypes=${appsFolderName}/home",
+        "sling.servlet.extensions=zip",
     }
 )
 @SuppressWarnings("serial")
-public class ByResourceTypeServlet extends SlingSafeMethodsServlet {
+public class ZipServlet extends SlingSafeMethodsServlet {
     
     private final Logger log = LoggerFactory.getLogger(ByResourceTypeServlet.class);