You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2018/05/29 08:18:37 UTC

[sling-org-apache-sling-servlets-annotations] 05/09: SLING-7624 simplify servlet annotations

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

kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-annotations.git

commit 9a1a5b451bd53217d1c65c279f1ffa38b4746007
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Fri May 25 10:27:50 2018 +0200

    SLING-7624 simplify servlet annotations
---
 .../servlets/annotations/SlingServletName.java     |  2 +-
 ...ngServletByPath.java => SlingServletPaths.java} | 45 ++++------------------
 ...gServletByPath.java => SlingServletPrefix.java} | 31 +++------------
 ...rceType.java => SlingServletResourceTypes.java} | 28 +-------------
 4 files changed, 16 insertions(+), 90 deletions(-)

diff --git a/src/main/java/org/apache/sling/servlets/annotations/SlingServletName.java b/src/main/java/org/apache/sling/servlets/annotations/SlingServletName.java
index 79dd1f9..ef68ac8 100644
--- a/src/main/java/org/apache/sling/servlets/annotations/SlingServletName.java
+++ b/src/main/java/org/apache/sling/servlets/annotations/SlingServletName.java
@@ -22,7 +22,7 @@ import org.osgi.service.component.annotations.ComponentPropertyType;
 /**
  * Component Property Type (as defined by OSGi DS 1.4) for Sling Servlets.
  * Takes care of writing the relevant component properties to set a name for a Sling Servlet.
- * Must be combined with either {@link SlingServletByResourceType} or {@link SlingServletByPath}.
+ * Must be combined with either {@link SlingServletResourceTypes} or {@link SlingServletPaths}.
  *
  * @see <a href="https://github.com/apache/felix/blob/trunk/tools/org.apache.felix.scr.annotations/src/main/java/org/apache/felix/scr/annotations/sling/SlingServlet.java">Felix SCR annotations</a>
  * @see ServletResolverConstants
diff --git a/src/main/java/org/apache/sling/servlets/annotations/SlingServletByPath.java b/src/main/java/org/apache/sling/servlets/annotations/SlingServletPaths.java
similarity index 57%
copy from src/main/java/org/apache/sling/servlets/annotations/SlingServletByPath.java
copy to src/main/java/org/apache/sling/servlets/annotations/SlingServletPaths.java
index 9bbdc5c..61fe06d 100644
--- a/src/main/java/org/apache/sling/servlets/annotations/SlingServletByPath.java
+++ b/src/main/java/org/apache/sling/servlets/annotations/SlingServletPaths.java
@@ -22,29 +22,22 @@ import org.osgi.service.component.annotations.ComponentPropertyType;
  * Component Property Type (as defined by OSGi DS 1.4) for Sling Servlets.
  * Takes care of writing the relevant component properties as being used by the Sling Servlet Resolver ({@link ServletResolverConstants})
  * to register the annotated servlet component as Sling servlet for a specific path.
- * Preferably register Sling servlets by resource type ({@link SlingServletByResourceType}) though 
+ * Preferably register Sling servlets by resource type ({@link SlingServletResourceTypes}) though 
  * for reasons outlined at <a href="https://sling.apache.org/documentation/the-sling-engine/servlets.html#caveats-when-binding-servlets-by-path">
- * Caveats when binding servlets by path</a>
+ * Caveats when binding servlets by path</a>.
  *
  * @see <a href="https://sling.apache.org/documentation/the-sling-engine/servlets.html">Sling Servlets</a>
  * @see ServletResolverConstants
  * @see <a href="https://github.com/apache/felix/blob/trunk/tools/org.apache.felix.scr.annotations/src/main/java/org/apache/felix/scr/annotations/sling/SlingServlet.java">Felix SCR annotation</a>
  */
 @ComponentPropertyType
-public @interface SlingServletByPath {
-
-    /**
-     * Prefix for every property being generated from the annotations elements (as defined in OSGi 7 Compendium, 112.8.2.1)
-     */
-    static final String PREFIX_ = "sling.servlet.";
-    
+public @interface SlingServletPaths {
     /**
      * The absolute paths under which the servlet is accessible as a resource.
      * A relative path is made absolute by prefixing it with the value set through the
-     * {@link #sling_servlet_prefix()} element.
+     * {@link SlingServletPrefix} annotation.
      * <p>
-     * Either this property or the {@link #SLING_SERVLET_RESOURCE_TYPES}
-     * property must be set or the servlet is ignored.
+     * This annotation or {@link SlingServletResourceTypes} should be used to properly register the servlet in Sling.
      * If both are set the servlet is registered using both ways.
      * <p>
      * A servlet using this property might be ignored unless its path is included
@@ -53,29 +46,7 @@ public @interface SlingServletByPath {
      * 
      * @see ServletResolverConstants#SLING_SERVLET_PATHS
      */
-    String[] paths();
-    
-    /**
-     * The prefix/index to be used to register this servlet.
-     * It only is applied as prefix to {@link #sling_servlet_paths()} and 
-     * in case they do not start with a "/".
-     * </p>
-     * <ul>
-     * <li>If the value of this element is a number, it defines the index of the search
-     * path entries from the resource resolver. The defined search path is used as
-     * a prefix to mount this servlet. The number can be -1 which always points to the
-     * last search entry. If the specified value is higher than than the highest index
-     * of the search paths, the last entry is used. The index starts with 0.
-     * If the value of this property is a string and parseable as a number, the above
-     * logic is used.</li>
-     * <li>If the value of this element is a string starting with "/", this value is applied
-     * as a prefix, regardless of the configured search paths!</li>
-     * <li>If the value is anything else, it is ignored.</li>
-     * </ul>
-     * If this property is empty, the configuration of the {@code org.apache.sling.servlets.resolver.internal.SlingServletResolver}
-     * service is used.
-     * In case even that one is not set "/" is used as prefix.
-     * @see ServletResolverConstants#SLING_SERVLET_PREFIX
-     */
-    String prefix() default "";
+    String[] value();
+
+    // TODO: does not work due to https://github.com/bndtools/bnd/issues/2445
 }
diff --git a/src/main/java/org/apache/sling/servlets/annotations/SlingServletByPath.java b/src/main/java/org/apache/sling/servlets/annotations/SlingServletPrefix.java
similarity index 72%
rename from src/main/java/org/apache/sling/servlets/annotations/SlingServletByPath.java
rename to src/main/java/org/apache/sling/servlets/annotations/SlingServletPrefix.java
index 9bbdc5c..a34bbc5 100644
--- a/src/main/java/org/apache/sling/servlets/annotations/SlingServletByPath.java
+++ b/src/main/java/org/apache/sling/servlets/annotations/SlingServletPrefix.java
@@ -22,7 +22,7 @@ import org.osgi.service.component.annotations.ComponentPropertyType;
  * Component Property Type (as defined by OSGi DS 1.4) for Sling Servlets.
  * Takes care of writing the relevant component properties as being used by the Sling Servlet Resolver ({@link ServletResolverConstants})
  * to register the annotated servlet component as Sling servlet for a specific path.
- * Preferably register Sling servlets by resource type ({@link SlingServletByResourceType}) though 
+ * Preferably register Sling servlets by resource type ({@link SlingServletResourceTypes}) though 
  * for reasons outlined at <a href="https://sling.apache.org/documentation/the-sling-engine/servlets.html#caveats-when-binding-servlets-by-path">
  * Caveats when binding servlets by path</a>
  *
@@ -31,33 +31,11 @@ import org.osgi.service.component.annotations.ComponentPropertyType;
  * @see <a href="https://github.com/apache/felix/blob/trunk/tools/org.apache.felix.scr.annotations/src/main/java/org/apache/felix/scr/annotations/sling/SlingServlet.java">Felix SCR annotation</a>
  */
 @ComponentPropertyType
-public @interface SlingServletByPath {
+public @interface SlingServletPrefix {
 
     /**
-     * Prefix for every property being generated from the annotations elements (as defined in OSGi 7 Compendium, 112.8.2.1)
-     */
-    static final String PREFIX_ = "sling.servlet.";
-    
-    /**
-     * The absolute paths under which the servlet is accessible as a resource.
-     * A relative path is made absolute by prefixing it with the value set through the
-     * {@link #sling_servlet_prefix()} element.
-     * <p>
-     * Either this property or the {@link #SLING_SERVLET_RESOURCE_TYPES}
-     * property must be set or the servlet is ignored.
-     * If both are set the servlet is registered using both ways.
-     * <p>
-     * A servlet using this property might be ignored unless its path is included
-     * in the Execution Paths {@code servletresolver.paths} configuration setting of the
-     * {@code org.apache.sling.servlets.resolver.internal.SlingServletResolver} service.
-     * 
-     * @see ServletResolverConstants#SLING_SERVLET_PATHS
-     */
-    String[] paths();
-    
-    /**
      * The prefix/index to be used to register this servlet.
-     * It only is applied as prefix to {@link #sling_servlet_paths()} and 
+     * It only is applied as prefix to {@link SlingServletPaths} or {@link SlingServletResourceTypes#resourceTypes()} 
      * in case they do not start with a "/".
      * </p>
      * <ul>
@@ -77,5 +55,6 @@ public @interface SlingServletByPath {
      * In case even that one is not set "/" is used as prefix.
      * @see ServletResolverConstants#SLING_SERVLET_PREFIX
      */
-    String prefix() default "";
+    String value();
+    // TODO: does not work due to https://github.com/bndtools/bnd/issues/2445
 }
diff --git a/src/main/java/org/apache/sling/servlets/annotations/SlingServletByResourceType.java b/src/main/java/org/apache/sling/servlets/annotations/SlingServletResourceTypes.java
similarity index 70%
rename from src/main/java/org/apache/sling/servlets/annotations/SlingServletByResourceType.java
rename to src/main/java/org/apache/sling/servlets/annotations/SlingServletResourceTypes.java
index 096df75..0881303 100644
--- a/src/main/java/org/apache/sling/servlets/annotations/SlingServletByResourceType.java
+++ b/src/main/java/org/apache/sling/servlets/annotations/SlingServletResourceTypes.java
@@ -28,7 +28,7 @@ import org.osgi.service.component.annotations.ComponentPropertyType;
  * @see <a href="https://github.com/apache/felix/blob/trunk/tools/org.apache.felix.scr.annotations/src/main/java/org/apache/felix/scr/annotations/sling/SlingServlet.java">Felix SCR annotation</a>
  */
 @ComponentPropertyType
-public @interface SlingServletByResourceType {
+public @interface SlingServletResourceTypes {
 
     /**
      * Prefix for every property being generated from the annotations elements (as defined in OSGi 7 Compendium, 112.8.2.1)
@@ -39,7 +39,7 @@ public @interface SlingServletByResourceType {
      * The resource type(s) supported by the servlet (value
      * is "sling.servlet.resourceTypes").
      * A relative resource type is made absolute by prefixing it with the value set through the
-     * {@link #sling_servlet_prefix()} property.
+     * {@link SlingServletPrefix} annotation.
      * <p>
      */
     String[] resourceTypes();
@@ -72,28 +72,4 @@ public @interface SlingServletByResourceType {
      * @see <a href="https://tools.ietf.org/html/rfc7231#section-4.3">HTTP 1.1 Spec Methods</a>
      */
     String[] methods() default {};
-    
-    /**
-     * The prefix/index to be used to register this servlet.
-     * It only is applied as prefix to {@link #sling_servlet_paths()} and 
-     * in case they do not start with a "/".
-     * </p>
-     * <ul>
-     * <li>If the value of this element is a number, it defines the index of the search
-     * path entries from the resource resolver. The defined search path is used as
-     * a prefix to mount this servlet. The number can be -1 which always points to the
-     * last search entry. If the specified value is higher than than the highest index
-     * of the search paths, the last entry is used. The index starts with 0.
-     * If the value of this property is a string and parseable as a number, the above
-     * logic is used.</li>
-     * <li>If the value of this element is a string starting with "/", this value is applied
-     * as a prefix, regardless of the configured search paths!</li>
-     * <li>If the value is anything else, it is ignored.</li>
-     * </ul>
-     * If this property is empty, the configuration of the {@code org.apache.sling.servlets.resolver.internal.SlingServletResolver}
-     * service is used.
-     * In case even that one is not set "/" is used as prefix.
-     * @see ServletResolverConstants#SLING_SERVLET_PREFIX
-     */
-    String prefix() default "";
 }

-- 
To stop receiving notification emails like this one, please contact
kwin@apache.org.