SLING-6704 : Migrate to R6 annotations, clean up dependencies
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1788403 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 530b114..a185055 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>26</version>
+ <version>30</version>
<relativePath />
</parent>
@@ -51,19 +51,8 @@
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
- <artifactId>maven-scr-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
- <configuration>
- <instructions>
- <Private-Package>
- org.apache.sling.servlets.get.*
- </Private-Package>
- </instructions>
- </configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -79,7 +68,7 @@
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
+ <artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.jcr</groupId>
@@ -98,12 +87,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.commons.osgi</artifactId>
- <version>2.0.6</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr-commons</artifactId>
<version>2.2.9</version>
@@ -111,20 +94,12 @@
</dependency>
<dependency>
<groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
+ <artifactId>osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.scr.annotations</artifactId>
- </dependency>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
diff --git a/src/main/java/org/apache/sling/servlets/get/impl/DefaultGetServlet.java b/src/main/java/org/apache/sling/servlets/get/impl/DefaultGetServlet.java
index b1960e0..df7a82c 100644
--- a/src/main/java/org/apache/sling/servlets/get/impl/DefaultGetServlet.java
+++ b/src/main/java/org/apache/sling/servlets/get/impl/DefaultGetServlet.java
@@ -17,7 +17,6 @@
package org.apache.sling.servlets.get.impl;
import java.io.IOException;
-import java.util.Dictionary;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
@@ -26,90 +25,115 @@
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingConstants;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceNotFoundException;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
-import org.apache.sling.commons.osgi.OsgiUtil;
+import org.apache.sling.servlets.get.impl.helpers.HeadServletResponse;
import org.apache.sling.servlets.get.impl.helpers.HtmlRendererServlet;
import org.apache.sling.servlets.get.impl.helpers.JsonRendererServlet;
import org.apache.sling.servlets.get.impl.helpers.PlainTextRendererServlet;
import org.apache.sling.servlets.get.impl.helpers.StreamRendererServlet;
import org.apache.sling.servlets.get.impl.helpers.XMLRendererServlet;
-import org.apache.sling.servlets.get.impl.helpers.HeadServletResponse;
-import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A SlingSafeMethodsServlet that renders the current Resource as simple HTML
*/
-@Component(immediate=true, metatype=true, name="org.apache.sling.servlets.get.DefaultGetServlet", label="%servlet.get.name", description="%servlet.get.description")
-@Service(Servlet.class)
-@Properties({
- @Property(name="service.description", value="Default GET Servlet"),
- @Property(name="service.vendor", value="The Apache Software Foundation"),
-
- // Use this as a default servlet for Sling
- @Property(name="sling.servlet.resourceTypes", value="sling/servlet/default", propertyPrivate=true),
- @Property(name="sling.servlet.prefix", intValue=-1, propertyPrivate=true),
-
- // Generic handler for all get requests
- @Property(name="sling.servlet.methods", value={"GET", "HEAD"}, propertyPrivate=true)
-})
+@Component(service = Servlet.class,
+ name="org.apache.sling.servlets.get.DefaultGetServlet",
+ property = {
+ "service.description=Default GET Servlet",
+ "service.vendor=The Apache Software Foundation",
+
+ // Use this as a default servlet for Sling
+ "sling.servlet.resourceTypes=sling/servlet/default",
+ "sling.servlet.prefix:Integer=-1",
+
+ // Generic handler for all get requests
+ "sling.servlet.methods=GET",
+ "sling.servlet.methods=HEAD"
+ })
+@Designate(ocd=DefaultGetServlet.Config.class)
public class DefaultGetServlet extends SlingSafeMethodsServlet {
- private static final long serialVersionUID = -5815904221043005085L;
+ private static final long serialVersionUID = -2714152339750885354L;
+
+ @ObjectClassDefinition(name="Apache Sling GET Servlet",
+ description="The Sling GET servlet is registered as the default servlet to handle GET requests.")
+ public @interface Config {
+
+ @AttributeDefinition(name = "Extension Aliases",
+ description="The aliases can be used to map several extensions to a " +
+ "single servlet. For instance \"xml:pdf,rtf\" maps the extensions \".pdf\" and " +
+ "\".rtf\" to the servlet helper handling the \".xml\" extension.")
+ String[] aliases();
+
+ @AttributeDefinition(name = "Auto Index",
+ description="Controls whether a simple directory index is rendered for " +
+ "a directory request. A directory request is a request to a resource with a " +
+ "trailing slash (/) character, for example http://host/apps/. If none of the " +
+ "index resources exists, the default GET servlet may automatically render an " +
+ "index listing of the child resources if this option is checked, which is the " +
+ "default. If this option is not checked, the request to the resource is " +
+ "forbidden and results in a status 403/FORBIDDEN. This configuration " +
+ "corresponds to the \"Index\" option of the Options directive of Apache HTTP " +
+ "Server (httpd).")
+ boolean index() default false;
+
+ @AttributeDefinition(name = "Index Resources",
+ description = "List of child resources to be considered for rendering " +
+ "the index of a \"directory\". The default value is [ \"index\", \"index.html\" ]. " +
+ "Each entry in the list is checked and the first entry found is included to " +
+ "render the index. If an entry is selected, which has not extension (for " +
+ "example the \"index\" resource), the extension \".html\" is appended for the " +
+ "inclusion to indicate the desired text/html rendering. If the resource name " +
+ "has an extension (as in \"index.html\"), no additional extension is appended " +
+ "for the inclusion. This configuration corresponds to the <DirectoryIndex> " +
+ "directive of Apache HTTP Server (httpd).")
+ String[] index_files() default { "index","index.html" };
+
+ @AttributeDefinition(name = "Enable HTML",
+ description = "Whether the renderer for HTML of the default GET servlet is enabled or not. By default the HTML renderer is enabled.")
+ boolean enable_html() default true;
+
+ @AttributeDefinition(name = "Enable JSON",
+ description = "Whether the renderer for JSON of the default GET servlet is enabled or not. By default the JSON renderer is enabled.")
+ boolean enable_json() default true;
+
+ @AttributeDefinition(name = "Enable Plain Text",
+ description = "Whether the renderer for plain text of the default GET servlet is enabled or not. By default the plain text renderer is enabled.")
+ boolean enable_txt() default true;
+
+ @AttributeDefinition(name = "Enable XML",
+ description = "Whether the renderer for XML of the default GET servlet is enabled or not. By default the XML renderer is enabled.")
+ boolean enable_xml() default true;
+
+ @AttributeDefinition(name = "JSON Max results",
+ description = "The maximum number of resources that should " +
+ "be returned when doing a node.5.json or node.infinity.json. In JSON terms " +
+ "this basically means the number of Objects to return. Default value is " +
+ "200.")
+ int json_maximumresults() default 200;
+ }
private final Logger logger = LoggerFactory.getLogger(getClass());
- private Map<String, Servlet> rendererMap = new HashMap<String, Servlet>();
+ private Map<String, Servlet> rendererMap = new HashMap<>();
private Servlet streamerServlet;
- @Property
- private static final String ALIAS_PROPERTY = "aliases";
-
- private static final boolean DEFAULT_INDEX_PROPERTY = false;
-
- @Property(boolValue=DEFAULT_INDEX_PROPERTY)
- private static final String INDEX_PROPERTY = "index";
-
- private static final String[] DEFAULT_INDEX_FILES_PROPERTY = { "index",
- "index.html" };
-
- @Property(value={ "index", "index.html" })
- private static final String INDEX_FILES_PROPERTY = "index.files";
-
- /** Default value for renderer selection (value is "true"). */
- private static final boolean DEFAULT_RENDERER_PROPERTY = true;
-
- @Property(boolValue=DEFAULT_RENDERER_PROPERTY)
- private static final String HTML_RENDERER_PROPERTY = "enable.html";
-
- @Property(boolValue=DEFAULT_RENDERER_PROPERTY)
- private static final String TXT_RENDERER_PROPERTY = "enable.txt";
-
- @Property(boolValue=DEFAULT_RENDERER_PROPERTY)
- private static final String JSON_RENDERER_PROPERTY = "enable.json";
-
- @Property(boolValue=DEFAULT_RENDERER_PROPERTY)
- private static final String XML_RENDERER_PROPERTY = "enable.xml";
-
- /** Default value for the maximum amount of results that should be returned by the jsonResourceWriter */
- public static final int DEFAULT_JSON_RENDERER_MAXIMUM_RESULTS = 200;
-
- @Property(intValue=DEFAULT_JSON_RENDERER_MAXIMUM_RESULTS)
- public static final String JSON_RENDERER_MAXIMUM_RESULTS_PROPERTY = "json.maximumresults";
-
private int jsonMaximumResults;
-
+
/** Additional aliases. */
private String[] aliases;
@@ -127,27 +151,24 @@
private boolean enableXml;
- protected void activate(ComponentContext ctx) {
- Dictionary<?, ?> props = ctx.getProperties();
- this.aliases = OsgiUtil.toStringArray(props.get(ALIAS_PROPERTY));
- this.index = OsgiUtil.toBoolean(props.get(INDEX_PROPERTY),
- DEFAULT_INDEX_PROPERTY);
- this.indexFiles = OsgiUtil.toStringArray(
- props.get(INDEX_FILES_PROPERTY), DEFAULT_INDEX_FILES_PROPERTY);
+ @Activate
+ protected void activate(Config cfg) {
+ this.aliases = cfg.aliases();
+ this.index = cfg.index();
+ this.indexFiles = cfg.index_files();
+ if ( this.indexFiles == null ) {
+ this.indexFiles = new String[0];
+ }
- this.enableHtml = OsgiUtil.toBoolean(props.get(HTML_RENDERER_PROPERTY),
- DEFAULT_RENDERER_PROPERTY);
- this.enableTxt = OsgiUtil.toBoolean(props.get(TXT_RENDERER_PROPERTY),
- DEFAULT_RENDERER_PROPERTY);
- this.enableJson = OsgiUtil.toBoolean(props.get(JSON_RENDERER_PROPERTY),
- DEFAULT_RENDERER_PROPERTY);
- this.enableXml = OsgiUtil.toBoolean(props.get(XML_RENDERER_PROPERTY),
- DEFAULT_RENDERER_PROPERTY);
- this.jsonMaximumResults = OsgiUtil.toInteger(props.get(JSON_RENDERER_MAXIMUM_RESULTS_PROPERTY),
- DEFAULT_JSON_RENDERER_MAXIMUM_RESULTS);
+ this.enableHtml = cfg.enable_html();
+ this.enableTxt = cfg.enable_txt();
+ this.enableJson = cfg.enable_json();
+ this.enableXml = cfg.enable_xml();
+ this.jsonMaximumResults = cfg.json_maximumresults();
}
- protected void deactivate(ComponentContext ctx) {
+ @Deactivate
+ protected void deactivate() {
this.aliases = null;
this.index = false;
this.indexFiles = null;
diff --git a/src/main/java/org/apache/sling/servlets/get/impl/RedirectServlet.java b/src/main/java/org/apache/sling/servlets/get/impl/RedirectServlet.java
index a93b3ac..14050d1 100644
--- a/src/main/java/org/apache/sling/servlets/get/impl/RedirectServlet.java
+++ b/src/main/java/org/apache/sling/servlets/get/impl/RedirectServlet.java
@@ -19,16 +19,11 @@
package org.apache.sling.servlets.get.impl;
import java.io.IOException;
-import java.util.Dictionary;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingConstants;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
@@ -37,9 +32,12 @@
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
-import org.apache.sling.commons.osgi.OsgiUtil;
import org.apache.sling.servlets.get.impl.helpers.JsonRendererServlet;
-import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -61,17 +59,29 @@
* also appended to the redirect URL.
*/
@SuppressWarnings("serial")
-@Component(immediate=true, metatype=true)
-@Service(Servlet.class)
-@Properties({
- @Property(name="service.description", value="Request Redirect Servlet"),
- @Property(name="service.vendor", value="The Apache Software Foundation"),
- @Property(name="sling.servlet.resourceTypes", value="sling:redirect", propertyPrivate=true),
- @Property(name="sling.servlet.methods", value="GET", propertyPrivate=true),
- @Property(name="sling.servlet.prefix", intValue=-1, propertyPrivate=true)
-})
+@Component(service = Servlet.class,
+ property = {
+ "service.description=Request Redirect Servlet",
+ "service.vendor=The Apache Software Foundation",
+ "sling.servlet.resourceTypes=sling:redirect",
+ "sling.servlet.methods=GET",
+ "sling.servlet.prefix:Integer=-1"
+ })
+@Designate(ocd = RedirectServlet.Config.class)
public class RedirectServlet extends SlingSafeMethodsServlet {
+ @ObjectClassDefinition(name="Apache Sling Redirect Servlet",
+ description="The Sling servlet handling redirect resources.")
+ public @interface Config {
+
+ @AttributeDefinition(name = "JSON Max results",
+ description = "The maximum number of resources that should " +
+ "be returned when doing a node.5.json or node.infinity.json. In JSON terms " +
+ "this basically means the number of Objects to return. Default value is " +
+ "200.")
+ int json_maximumresults() default 200;
+ }
+
/** The name of the target property */
public static final String TARGET_PROP = "sling:target";
@@ -83,18 +93,11 @@
private Servlet jsonRendererServlet;
- /** Default value for the maximum amount of results that should be returned by the jsonResourceWriter */
- public static final int DEFAULT_JSON_RENDERER_MAXIMUM_RESULTS = 200;
-
- @Property(intValue=DEFAULT_JSON_RENDERER_MAXIMUM_RESULTS)
- public static final String JSON_RENDERER_MAXIMUM_RESULTS_PROPERTY = "json.maximumresults";
-
private int jsonMaximumResults;
- protected void activate(ComponentContext ctx) {
- Dictionary<?, ?> props = ctx.getProperties();
- this.jsonMaximumResults = OsgiUtil.toInteger(props.get(JSON_RENDERER_MAXIMUM_RESULTS_PROPERTY),
- DEFAULT_JSON_RENDERER_MAXIMUM_RESULTS);
+ @Activate
+ protected void activate(Config cfg) {
+ this.jsonMaximumResults = cfg.json_maximumresults();
// When the maximumResults get updated, we force a reset for the jsonRendererServlet.
jsonRendererServlet = getJsonRendererServlet();
}
diff --git a/src/main/java/org/apache/sling/servlets/get/impl/helpers/HeadServletResponse.java b/src/main/java/org/apache/sling/servlets/get/impl/helpers/HeadServletResponse.java
index f5bed63..238f85e 100644
--- a/src/main/java/org/apache/sling/servlets/get/impl/helpers/HeadServletResponse.java
+++ b/src/main/java/org/apache/sling/servlets/get/impl/helpers/HeadServletResponse.java
@@ -18,13 +18,15 @@
package org.apache.sling.servlets.get.impl.helpers;
-import org.apache.sling.api.SlingHttpServletResponse;
-import org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper;
-
-import javax.servlet.ServletOutputStream;
import java.io.PrintWriter;
import java.io.Writer;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.WriteListener;
+
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper;
+
/**
* The <code>HeadServletResponse</code> is a Sling response wrapper which
* ensures that nothing will ever be written by return null writers or
@@ -87,6 +89,15 @@
@Override
public void write(byte[] b, int off, int len) {
}
+
+ @Override
+ public boolean isReady() {
+ return true;
+ }
+
+ @Override
+ public void setWriteListener(WriteListener writeListener) {
+ }
}
/**
diff --git a/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java b/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
index e17d535..4908257 100644
--- a/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
+++ b/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
@@ -87,7 +87,7 @@
/**
* Full range marker.
*/
- private static ArrayList<Range> FULL = new ArrayList<Range>(0);
+ private static ArrayList<Range> FULL = new ArrayList<>(0);
static final int IO_BUFFER_SIZE = 2048;
@@ -393,11 +393,11 @@
contentType = ct;
}
}
-
+
if (contentType == null) {
contentType = defaultContentType;
}
-
+
response.setContentType(contentType);
String encoding = meta.getCharacterEncoding();
@@ -560,7 +560,7 @@
ostream.println();
ostream.print("--" + mimeSeparation + "--");
-
+
if(exception != null) {
throw exception;
}
@@ -682,7 +682,7 @@
// Vector which will contain all the ranges which are successfully
// parsed.
- ArrayList<Range> result = new ArrayList<Range>();
+ ArrayList<Range> result = new ArrayList<>();
StringTokenizer commaTokenizer = new StringTokenizer(rangeHeader, ",");
// Parsing the range list
diff --git a/src/main/java/org/apache/sling/servlets/get/impl/impl/info/SlingInfoServlet.java b/src/main/java/org/apache/sling/servlets/get/impl/impl/info/SlingInfoServlet.java
index 36264bc..a2872e0 100644
--- a/src/main/java/org/apache/sling/servlets/get/impl/impl/info/SlingInfoServlet.java
+++ b/src/main/java/org/apache/sling/servlets/get/impl/impl/info/SlingInfoServlet.java
@@ -27,36 +27,32 @@
import javax.servlet.Servlet;
import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
-import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
/**
- * The <code>SlingInfoServlet</code> TODO
+ * The <code>SlingInfoServlet</code>
*/
@SuppressWarnings("serial")
-@Component(immediate=true)
-@Service(Servlet.class)
-@Properties({
- @Property(name="service.description", value="Sling Info Servlet"),
- @Property(name="service.vendor", value="The Apache Software Foundation"),
- @Property(name="sling.servlet.paths", value="/system/sling/info")
-})
+@Component(service = Servlet.class,
+ property = {
+ "service.description=Sling Info Servlet",
+ "service.vendor=The Apache Software Foundation",
+ "sling.servlet.paths=/system/sling/info"
+ })
public class SlingInfoServlet extends SlingSafeMethodsServlet {
-
+
/**
- *
+ *
*/
private static final String CACHE_CONTROL_HEADER = "Cache-Control";
- private static final String CACHE_CONTROL_HEADER_VALUE =
+ private static final String CACHE_CONTROL_HEADER_VALUE =
"private, no-store, no-cache, max-age=0, must-revalidate";
private Map<String, SlingInfoProvider> infoProviders = new HashMap<String, SlingInfoProvider>();
@@ -197,7 +193,8 @@
// --------- SCR integration -----------------------------------------------
- protected void activate(ComponentContext context) {
+ @Activate
+ protected void activate() {
infoProviders.put(SessionInfoProvider.PROVIDER_LABEL,
new SessionInfoProvider());
}
diff --git a/src/main/java/org/apache/sling/servlets/get/impl/version/VersionInfoServlet.java b/src/main/java/org/apache/sling/servlets/get/impl/version/VersionInfoServlet.java
index 24d2aa8..e277e75 100644
--- a/src/main/java/org/apache/sling/servlets/get/impl/version/VersionInfoServlet.java
+++ b/src/main/java/org/apache/sling/servlets/get/impl/version/VersionInfoServlet.java
@@ -33,11 +33,6 @@
import javax.servlet.Servlet;
import javax.servlet.ServletException;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.JcrConstants;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
@@ -47,6 +42,11 @@
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.json.io.JSONRenderer;
import org.apache.sling.commons.json.jcr.JsonItemWriter;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
/**
* The <code>VersionInfoServlet</code> renders list of versions available for
@@ -54,19 +54,27 @@
*
* At the moment only JCR nodes are supported.
*/
-@Component(immediate=true, metatype=true, name="org.apache.sling.servlets.get.impl.version.VersionInfoServlet", label="%servlet.version.name", description="%servlet.version.description", policy=ConfigurationPolicy.REQUIRE)
-@Service(Servlet.class)
-@Properties({
- @Property(name="service.description", value="Version info servlet"),
- @Property(name="service.vendor", value="The Apache Software Foundation"),
-
- @Property(name="sling.servlet.resourceTypes", value="sling/servlet/default", propertyPrivate=true),
- @Property(name="sling.servlet.selectors", value="V"),
- @Property(name="sling.servlet.methods", value="GET", propertyPrivate=true),
- @Property(name="sling.servlet.extensions", value="json", propertyPrivate=true),
-})
+@Component(name="org.apache.sling.servlets.get.impl.version.VersionInfoServlet",
+ configurationPolicy=ConfigurationPolicy.REQUIRE,
+ service = Servlet.class,
+ property = {
+ "service.description=Version info servlet",
+ "service.vendor=The Apache Software Foundation",
+ "sling.servlet.resourceTypes=sling/servlet/default",
+ "sling.servlet.methods=GET",
+ "sling.servlet.selectors=V",
+ "sling.servlet.extensions=json"
+ })
+@Designate(ocd = VersionInfoServlet.Config.class)
public class VersionInfoServlet extends SlingSafeMethodsServlet {
+ @ObjectClassDefinition(name = "Apache Sling Version Info Servlet",
+ description = "The Sling Version Info Servlet renders list of versions available for the current resource")
+ public @interface Config {
+
+ @AttributeDefinition(name = "Selector", description="List of selectors this servlet handles to display the versions")
+ String[] sling_servlet_selectors() default "V";
+ }
private static final long serialVersionUID = 1656887064561951302L;
/** Selector that means "pretty-print the output */
@@ -83,6 +91,7 @@
private final JSONRenderer renderer = new JSONRenderer();
+ @Override
public void doGet(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws ServletException,
IOException {
resp.setContentType(req.getResponseContentType());
@@ -127,7 +136,7 @@
}
private static Collection<String> getNames(Version[] versions) throws RepositoryException {
- final List<String> result = new ArrayList<String>();
+ final List<String> result = new ArrayList<>();
for (Version s : versions) {
result.add(s.getName());
}
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties
deleted file mode 100644
index 8fce4ef..0000000
--- a/src/main/resources/OSGI-INF/metatype/metatype.properties
+++ /dev/null
@@ -1,81 +0,0 @@
-#
-# 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.
-#
-
-
-#
-# This file contains localization strings for configuration labels and
-# descriptions as used in the metatype.xml descriptor generated by the
-# the Sling SCR plugin
-
-servlet.get.name = Apache Sling GET Servlet
-servlet.get.description = The Sling GET servlet is registered as the default \
- servlet to handle GET requests.
-
-servlet.version.name = Apache Sling Version Info Servlet
-servlet.version.description = The Sling Version Info Servlet renders list of \
-versions available for the current resource
-
-aliases.name = Extension Aliases
-aliases.description = The aliases can be used to map several extensions to a \
- single servlet. For instance "xml:pdf,rtf" maps the extensions ".pdf" and \
- ".rtf" to the servlet helper handling the ".xml" extension.
-
-index.files.name = Index Resources
-index.files.description = List of child resources to be considered for rendering \
- the index of a "directory". The default value is [ "index", "index.html" ]. \
- Each entry in the list is checked and the first entry found is included to \
- render the index. If an entry is selected, which has not extension (for \
- example the "index" resource), the extension ".html" is appended for the \
- inclusion to indicate the desired text/html rendering. If the resource name \
- has an extension (as in "index.html"), no additional extension is appended \
- for the inclusion. This configuration corresponds to the <DirectoryIndex> \
- directive of Apache HTTP Server (httpd).
-
-index.name = Auto Index
-index.description = Controls whether a simple directory index is rendered for \
- a directory request. A directory request is a request to a resource with a \
- trailing slash (/) character, for example http://host/apps/. If none of the \
- index resources exists, the default GET servlet may automatically render an \
- index listing of the child resources if this option is checked, which is the \
- default. If this option is not checked, the request to the resource is \
- forbidden and results in a status 403/FORBIDDEN. This configuration \
- corresponds to the "Index" option of the Options directive of Apache HTTP \
- Server (httpd).
-
-enable.html.name = Enable HTML
-enable.html.description = Whether the renderer for HTML of the default GET \
- servlet is enabled or not. By default the HTML renderer is enabled.
-enable.txt.name = Enable Plain Text
-enable.txt.description = Whether the renderer for plain text of the default GET \
- servlet is enabled or not. By default the plain text renderer is enabled.
-enable.json.name = Enable JSON
-enable.json.description = Whether the renderer for JSON of the default GET \
- servlet is enabled or not. By default the JSON renderer is enabled.
-enable.xml.name = Enable XML
-enable.xml.description = Whether the renderer for XML of the default GET \
- servlet is enabled or not. By default the XML renderer is enabled.
-
-org.apache.sling.servlets.get.impl.RedirectServlet.name = Apache Sling Redirect Servlet
-org.apache.sling.servlets.get.impl.RedirectServlet.description = The Sling servlet \
- handling redirect resources.
-json.maximumresults.name = JSON Max results
-json.maximumresults.description = The maximum number of resources that should \
- be returned when doing a node.5.json or node.infinity.json. In JSON terms \
- this basically means the number of Objects to return. Default value is \
- 200.