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 09:51:19 UTC
[sling-org-apache-sling-jcr-webdav] 14/29: SLING-2185 Support
IOHandler and PropertyHandler services to extend the Jackrabbit WebDAV
functionality (thanks Timothee Maret for the patch)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.jcr.webdav-2.1.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-webdav.git
commit 6d1be1eb5b7e9ae5928cc504b5da48a33e4787bd
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Thu Sep 1 11:33:31 2011 +0000
SLING-2185 Support IOHandler and PropertyHandler services to extend the Jackrabbit WebDAV functionality (thanks Timothee Maret for the patch)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/webdav@1164020 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 12 +-
.../webdav/impl/handler/DefaultHandlerService.java | 152 +++++++++++++++++++++
.../handler/DirListingExportHandlerService.java | 37 +++++
.../webdav/impl/handler/SlingHandlerManager.java | 93 +++++++++++++
.../jcr/webdav/impl/handler/SlingIOManager.java | 61 +++++++++
.../webdav/impl/handler/SlingPropertyManager.java | 62 +++++++++
.../webdav/impl/helper/SlingResourceConfig.java | 48 ++-----
.../webdav/impl/servlets/SlingWebDavServlet.java | 128 ++++++++++++-----
.../OSGI-INF/metatype/metatype.properties | 20 +++
9 files changed, 540 insertions(+), 73 deletions(-)
diff --git a/pom.xml b/pom.xml
index 985ae3b..2e89086 100644
--- a/pom.xml
+++ b/pom.xml
@@ -55,6 +55,11 @@
<configuration>
<instructions>
<Bundle-Category>sling,jcr</Bundle-Category>
+ <_exportcontents>
+ org.apache.jackrabbit.server.io; version=2.3,
+ org.apache.jackrabbit.webdav;
+ org.apache.jackrabbit.webdav.property; version=2.3
+ </_exportcontents>
<Private-Package>
org.apache.sling.jcr.webdav.impl.*
</Private-Package>
@@ -74,7 +79,6 @@
<Embed-Dependency>
jackrabbit-jcr-server,
jackrabbit-webdav,
- xercesImpl,
jackrabbit-jcr-commons
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
@@ -117,7 +121,7 @@
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr-server</artifactId>
- <version>2.2.5</version>
+ <version>2.3-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
@@ -138,6 +142,10 @@
<!-- OSGi Libraries -->
<dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
diff --git a/src/main/java/org/apache/sling/jcr/webdav/impl/handler/DefaultHandlerService.java b/src/main/java/org/apache/sling/jcr/webdav/impl/handler/DefaultHandlerService.java
new file mode 100644
index 0000000..f25d050
--- /dev/null
+++ b/src/main/java/org/apache/sling/jcr/webdav/impl/handler/DefaultHandlerService.java
@@ -0,0 +1,152 @@
+/*
+ * 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.jcr.webdav.impl.handler;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Modified;
+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.server.io.DefaultHandler;
+import org.apache.jackrabbit.server.io.ExportContext;
+import org.apache.jackrabbit.server.io.IOHandler;
+import org.apache.jackrabbit.server.io.IOManager;
+import org.apache.jackrabbit.server.io.ImportContext;
+import org.apache.jackrabbit.server.io.PropertyExportContext;
+import org.apache.jackrabbit.server.io.PropertyHandler;
+import org.apache.jackrabbit.server.io.PropertyImportContext;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.property.PropEntry;
+import org.apache.sling.commons.osgi.OsgiUtil;
+import org.apache.sling.jcr.webdav.impl.servlets.SlingWebDavServlet;
+import org.osgi.framework.Constants;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Wraps {@link org.apache.jackrabbit.server.io.DefaultHandler} in order to run
+ * it as a service.
+ */
+@Component(metatype = true, label = "%defaulthandler.name", description = "%defaulthandler.description")
+@Properties({
+ @Property(name = Constants.SERVICE_RANKING, intValue = 1000, propertyPrivate = false),
+ @Property(name = SlingWebDavServlet.TYPE_COLLECTIONS, value = SlingWebDavServlet.TYPE_COLLECTIONS_DEFAULT, propertyPrivate = false),
+ @Property(name = SlingWebDavServlet.TYPE_NONCOLLECTIONS, value = SlingWebDavServlet.TYPE_NONCOLLECTIONS_DEFAULT, propertyPrivate = false),
+ @Property(name = SlingWebDavServlet.TYPE_CONTENT, value = SlingWebDavServlet.TYPE_CONTENT_DEFAULT, propertyPrivate = false) })
+@Service
+public class DefaultHandlerService implements IOHandler, PropertyHandler {
+
+ private DefaultHandler delegatee;
+
+ @Activate
+ @Modified
+ @SuppressWarnings("unused")
+ private void activate(final Map<String, Object> properties) {
+ final String collectionType = OsgiUtil.toString(
+ properties.get(SlingWebDavServlet.TYPE_COLLECTIONS),
+ SlingWebDavServlet.TYPE_COLLECTIONS_DEFAULT);
+ final String nonCollectionType = OsgiUtil.toString(
+ properties.get(SlingWebDavServlet.TYPE_NONCOLLECTIONS),
+ SlingWebDavServlet.TYPE_NONCOLLECTIONS_DEFAULT);
+ final String contentType = OsgiUtil.toString(
+ properties.get(SlingWebDavServlet.TYPE_CONTENT),
+ SlingWebDavServlet.TYPE_CONTENT_DEFAULT);
+
+ this.delegatee = new DefaultHandler(null, collectionType,
+ nonCollectionType, contentType);
+ }
+
+ @Deactivate
+ @SuppressWarnings("unused")
+ private void deactivate() {
+ this.delegatee = null;
+ }
+
+ public IOManager getIOManager() {
+ return delegatee.getIOManager();
+ }
+
+ public void setIOManager(IOManager ioManager) {
+ delegatee.setIOManager(ioManager);
+ }
+
+ public String getName() {
+ return delegatee.getName();
+ }
+
+ public boolean canImport(ImportContext context, boolean isCollection) {
+ return delegatee.canImport(context, isCollection);
+ }
+
+ public boolean canImport(ImportContext context, DavResource resource) {
+ return delegatee.canImport(context, resource);
+ }
+
+ public boolean importContent(ImportContext context, boolean isCollection)
+ throws IOException {
+ return delegatee.importContent(context, isCollection);
+ }
+
+ public boolean importContent(ImportContext context, DavResource resource)
+ throws IOException {
+ return delegatee.importContent(context, resource);
+ }
+
+ public boolean canExport(ExportContext context, boolean isCollection) {
+ return delegatee.canExport(context, isCollection);
+ }
+
+ public boolean canExport(ExportContext context, DavResource resource) {
+ return delegatee.canExport(context, resource);
+ }
+
+ public boolean exportContent(ExportContext context, boolean isCollection)
+ throws IOException {
+ return delegatee.exportContent(context, isCollection);
+ }
+
+ public boolean exportContent(ExportContext context, DavResource resource)
+ throws IOException {
+ return delegatee.exportContent(context, resource);
+ }
+
+ public boolean canExport(PropertyExportContext context, boolean isCollection) {
+ return delegatee.canExport(context, isCollection);
+ }
+
+ public boolean exportProperties(PropertyExportContext exportContext,
+ boolean isCollection) throws RepositoryException {
+ return delegatee.exportProperties(exportContext, isCollection);
+ }
+
+ public boolean canImport(PropertyImportContext context, boolean isCollection) {
+ return delegatee.canImport(context, isCollection);
+ }
+
+ public Map<? extends PropEntry, ?> importProperties(
+ PropertyImportContext importContext, boolean isCollection)
+ throws RepositoryException {
+ return delegatee.importProperties(importContext, isCollection);
+ }
+}
diff --git a/src/main/java/org/apache/sling/jcr/webdav/impl/handler/DirListingExportHandlerService.java b/src/main/java/org/apache/sling/jcr/webdav/impl/handler/DirListingExportHandlerService.java
new file mode 100644
index 0000000..6aaa989
--- /dev/null
+++ b/src/main/java/org/apache/sling/jcr/webdav/impl/handler/DirListingExportHandlerService.java
@@ -0,0 +1,37 @@
+/*
+ * 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.jcr.webdav.impl.handler;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.jackrabbit.server.io.DirListingExportHandler;
+import org.apache.jackrabbit.server.io.IOHandler;
+import org.apache.jackrabbit.server.io.PropertyHandler;
+import org.osgi.framework.Constants;
+
+/**
+ * Wraps {@link org.apache.jackrabbit.server.io.DirListingExportHandler} in order to run it as a service.
+ */
+@Component(metatype = true, label = "%dirlistingexporthandler.name", description = "%dirlistingexporthandler.description")
+@Property(name = Constants.SERVICE_RANKING, intValue = 100, propertyPrivate = false)
+@Service(value = {IOHandler.class, PropertyHandler.class})
+public class DirListingExportHandlerService extends DirListingExportHandler {
+
+}
diff --git a/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingHandlerManager.java b/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingHandlerManager.java
new file mode 100644
index 0000000..356eb81
--- /dev/null
+++ b/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingHandlerManager.java
@@ -0,0 +1,93 @@
+/*
+ * 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.jcr.webdav.impl.handler;
+
+import java.util.ArrayList;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * IOManager service that uses a ServiceTracker to find available IOHandlers.
+ */
+public class SlingHandlerManager<ManagedType> {
+
+ private final TreeMap<ServiceReference, ManagedType> handlerServices = new TreeMap<ServiceReference, ManagedType>();
+
+ private ComponentContext componentContext;
+
+ private final String referenceName;
+
+ private ManagedType[] handlers;
+
+ protected SlingHandlerManager(final String referenceName) {
+ this.referenceName = referenceName;
+ }
+
+ public void setComponentContext(ComponentContext componentContext) {
+ this.componentContext = componentContext;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected ManagedType[] getHandlers(ManagedType[] type) {
+ if (this.handlers == null) {
+
+ final Set<Entry<ServiceReference, ManagedType>> entries;
+ synchronized (this.handlerServices) {
+ entries = this.handlerServices.entrySet();
+ }
+
+ final ArrayList<ManagedType> ioHandlers = new ArrayList<ManagedType>(
+ entries.size());
+ for (Entry<ServiceReference, ManagedType> entry : entries) {
+ final ManagedType ioHandler;
+ if (entry.getValue() == null) {
+ // unckecked cast
+ ioHandler = (ManagedType) this.componentContext.locateService(
+ referenceName, entry.getKey());
+ entry.setValue(ioHandler);
+ } else {
+ ioHandler = entry.getValue();
+ }
+ ioHandlers.add(ioHandler);
+ }
+
+ // unckecked cast
+ this.handlers = ioHandlers.toArray(type);
+ }
+ return this.handlers;
+ }
+
+ protected void bindHandler(final ServiceReference ref) {
+ synchronized (this.handlerServices) {
+ this.handlerServices.put(ref, null);
+ this.handlers = null;
+ }
+ }
+
+ protected void unbindHandler(final ServiceReference ref) {
+ synchronized (this.handlerServices) {
+ this.handlerServices.remove(ref);
+ this.handlers = null;
+ }
+ }
+}
diff --git a/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingIOManager.java b/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingIOManager.java
new file mode 100644
index 0000000..ed1c9be
--- /dev/null
+++ b/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingIOManager.java
@@ -0,0 +1,61 @@
+/*
+ * 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.jcr.webdav.impl.handler;
+
+import org.apache.jackrabbit.server.io.IOHandler;
+import org.apache.jackrabbit.server.io.IOManagerImpl;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * IOManager service that uses a ServiceTracker to find available IOHandlers.
+ */
+public class SlingIOManager extends IOManagerImpl {
+
+ private static final IOHandler[] IOHANDLERS_PROTOTYPE = new IOHandler[0];
+
+ private final SlingHandlerManager<IOHandler> handlerManager;
+
+ public SlingIOManager(final String referenceName) {
+ handlerManager = new SlingHandlerManager<IOHandler>(referenceName);
+ }
+
+ @Override
+ public void addIOHandler(IOHandler ioHandler) {
+ throw new UnsupportedOperationException(
+ "This IOManager only supports registered IOHandler services");
+ }
+
+ @Override
+ public IOHandler[] getIOHandlers() {
+ return this.handlerManager.getHandlers(IOHANDLERS_PROTOTYPE);
+ }
+
+ public void setComponentContext(ComponentContext componentContext) {
+ this.handlerManager.setComponentContext(componentContext);
+ }
+
+ public void bindIOHandler(final ServiceReference ioHandlerReference) {
+ this.handlerManager.bindHandler(ioHandlerReference);
+ }
+
+ public void unbindIOHandler(final ServiceReference ioHandlerReference) {
+ this.handlerManager.unbindHandler(ioHandlerReference);
+ }
+}
diff --git a/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingPropertyManager.java b/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingPropertyManager.java
new file mode 100644
index 0000000..30f3d90
--- /dev/null
+++ b/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingPropertyManager.java
@@ -0,0 +1,62 @@
+/*
+ * 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.jcr.webdav.impl.handler;
+
+import org.apache.jackrabbit.server.io.PropertyHandler;
+import org.apache.jackrabbit.server.io.PropertyManagerImpl;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * PropertyManager service that uses a ServiceTracker to find available
+ * PropertyHandler.
+ */
+public class SlingPropertyManager extends PropertyManagerImpl {
+
+ private static final PropertyHandler[] PROPERTYHANDLERS_PROTOTYPE = new PropertyHandler[0];
+
+ private final SlingHandlerManager<PropertyHandler> handlerManager;
+
+ public SlingPropertyManager(final String referenceName) {
+ handlerManager = new SlingHandlerManager<PropertyHandler>(referenceName);
+ }
+
+ @Override
+ public void addPropertyHandler(PropertyHandler propertyHandler) {
+ throw new UnsupportedOperationException(
+ "This PropertyManager only supports registered PropertyHandler services");
+ }
+
+ @Override
+ public PropertyHandler[] getPropertyHandlers() {
+ return this.handlerManager.getHandlers(PROPERTYHANDLERS_PROTOTYPE);
+ }
+
+ public void setComponentContext(ComponentContext componentContext) {
+ this.handlerManager.setComponentContext(componentContext);
+ }
+
+ public void bindPropertyHandler(final ServiceReference propertyHandlerReference) {
+ this.handlerManager.bindHandler(propertyHandlerReference);
+ }
+
+ public void unbindPropertyHandler(final ServiceReference propertyHandlerReference) {
+ this.handlerManager.unbindHandler(propertyHandlerReference);
+ }
+}
diff --git a/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java b/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java
index ea519bf..42bec88 100644
--- a/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java
+++ b/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java
@@ -18,20 +18,8 @@
*/
package org.apache.sling.jcr.webdav.impl.helper;
-import java.net.URL;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import javax.jcr.Item;
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-
-import org.apache.jackrabbit.server.io.DefaultHandler;
-import org.apache.jackrabbit.server.io.DirListingExportHandler;
import org.apache.jackrabbit.server.io.IOManager;
-import org.apache.jackrabbit.server.io.IOManagerImpl;
import org.apache.jackrabbit.server.io.PropertyManager;
-import org.apache.jackrabbit.server.io.PropertyManagerImpl;
import org.apache.jackrabbit.webdav.simple.DefaultItemFilter;
import org.apache.jackrabbit.webdav.simple.ItemFilter;
import org.apache.jackrabbit.webdav.simple.ResourceConfig;
@@ -40,6 +28,13 @@ import org.apache.sling.commons.mime.MimeTypeService;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.apache.sling.jcr.webdav.impl.servlets.SlingWebDavServlet;
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
public class SlingResourceConfig extends ResourceConfig {
private final String[] collectionTypes;
@@ -55,8 +50,12 @@ public class SlingResourceConfig extends ResourceConfig {
private final Dictionary<String, String> servletInitParams;
public SlingResourceConfig(MimeTypeService mimeTypeService,
- Dictionary<?, ?> config) {
+ Dictionary<?, ?> config,
+ IOManager ioManager,
+ PropertyManager propertyManager) {
super(new SlingTikaDetector(mimeTypeService));
+ this.ioManager = ioManager;
+ this.propertyManager = propertyManager;
collectionTypes = OsgiUtil.toStringArray(
config.get(SlingWebDavServlet.COLLECTION_TYPES),
SlingWebDavServlet.COLLECTION_TYPES_DEFAULT);
@@ -76,29 +75,6 @@ public class SlingResourceConfig extends ResourceConfig {
itemFilter.setFilteredURIs(filterURIs);
itemFilter.setFilteredNodetypes(filterNodeTypes);
- String collectionType = OsgiUtil.toString(
- config.get(SlingWebDavServlet.TYPE_COLLECTIONS),
- SlingWebDavServlet.TYPE_COLLECTIONS_DEFAULT);
- String nonCollectionType = OsgiUtil.toString(
- config.get(SlingWebDavServlet.TYPE_NONCOLLECTIONS),
- SlingWebDavServlet.TYPE_NONCOLLECTIONS_DEFAULT);
- String contentType = OsgiUtil.toString(
- config.get(SlingWebDavServlet.TYPE_CONTENT),
- SlingWebDavServlet.TYPE_CONTENT_DEFAULT);
-
- // share these handlers between the IOManager and the PropertyManager
- DirListingExportHandler dirHandler = new DirListingExportHandler();
- DefaultHandler defaultHandler = new DefaultHandler(null, collectionType,
- nonCollectionType, contentType);
-
- ioManager = new IOManagerImpl();
- ioManager.addIOHandler(dirHandler);
- ioManager.addIOHandler(defaultHandler);
-
- propertyManager = new PropertyManagerImpl();
- propertyManager.addPropertyHandler(dirHandler);
- propertyManager.addPropertyHandler(defaultHandler);
-
servletContextPath = OsgiUtil.toString(
config.get(SlingWebDavServlet.PROP_CONTEXT),
SlingWebDavServlet.DEFAULT_CONTEXT);
diff --git a/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java b/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
index 6585a36..47be098 100644
--- a/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
+++ b/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
@@ -23,14 +23,28 @@ import javax.jcr.Session;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
+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.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.References;
+import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.server.SessionProvider;
+import org.apache.jackrabbit.server.io.IOHandler;
+import org.apache.jackrabbit.server.io.PropertyHandler;
import org.apache.jackrabbit.webdav.DavLocatorFactory;
import org.apache.jackrabbit.webdav.simple.SimpleWebdavServlet;
import org.apache.sling.commons.mime.MimeTypeService;
import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.webdav.impl.handler.SlingIOManager;
+import org.apache.sling.jcr.webdav.impl.handler.SlingPropertyManager;
import org.apache.sling.jcr.webdav.impl.helper.SlingLocatorFactory;
import org.apache.sling.jcr.webdav.impl.helper.SlingResourceConfig;
import org.apache.sling.jcr.webdav.impl.helper.SlingSessionProvider;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
@@ -38,7 +52,7 @@ import org.osgi.service.http.NamespaceException;
/**
* The <code>SlingWebDavServlet</code> implements the WebDAV protocol as a
* default servlet for Sling handling all WebDAV methods.
- *
+ *
* @scr.component name="org.apache.sling.jcr.webdav.impl.servlets.SimpleWebDavServlet"
* label="%dav.name" description="%dav.description"
* immediate="true"
@@ -49,68 +63,89 @@ import org.osgi.service.http.NamespaceException;
* value="sling/servlet/default" private="true"
* @scr.property name="sling.servlet.methods" value="*" private="true"
*/
+@Component(name = "org.apache.sling.jcr.webdav.impl.servlets.SimpleWebDavServlet", label = "%dav.name", description = "%dav.description", immediate = true)
+@Service(Servlet.class)
+@Properties({
+ @Property(name = Constants.SERVICE_DESCRIPTION, value = "Sling WebDAV Servlet"),
+ @Property(name = Constants.SERVICE_VENDOR, value = "The Apache Software Foundation"),
+ @Property(name = "sling.servlet.resourceTypes", value = "sling/servlet/default", propertyPrivate = true),
+ @Property(name = "sling.servlet.methods", value = "*", propertyPrivate = true) })
+ @References({
+ @Reference(name = SlingWebDavServlet.IOHANDLER_REF_NAME, referenceInterface = IOHandler.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC),
+ @Reference(name = SlingWebDavServlet.PROPERTYHANDLER_REF_NAME, referenceInterface = PropertyHandler.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
+})
public class SlingWebDavServlet extends SimpleWebdavServlet {
- /** @scr.property valueRef="DEFAULT_CONTEXT" */
+ public static final String DEFAULT_CONTEXT = "/dav";
+
+ @Property(DEFAULT_CONTEXT)
public static final String PROP_CONTEXT = "dav.root";
- /** @scr.property valueRef="DEFAULT_REALM" */
+ public static final String DEFAULT_REALM = "Sling WebDAV";
+
+ @Property(DEFAULT_REALM)
public static final String PROP_REALM = "dav.realm";
- /** @scr.property valueRef="COLLECTION_TYPES_DEFAULT" */
public static final String COLLECTION_TYPES = "collection.types";
- /** @scr.property valueRef="FILTER_PREFIXES_DEFAULT" */
- public static final String FILTER_PREFIXES = "filter.prefixes";
+ public static final String TYPE_NONCOLLECTIONS_DEFAULT = "nt:file";
- /** @scr.property valueRef="EMPTY_DEFAULT" */
- public static final String FILTER_TYPES = "filter.types";
+ public static final String TYPE_CONTENT_DEFAULT = "nt:resource";
- /** @scr.property valueRef="EMPTY_DEFAULT" */
- public static final String FILTER_URIS = "filter.uris";
+ @Property(name = COLLECTION_TYPES)
+ public static final String[] COLLECTION_TYPES_DEFAULT = new String[] {
+ TYPE_NONCOLLECTIONS_DEFAULT, TYPE_CONTENT_DEFAULT };
- /** @scr.property valueRef="TYPE_COLLECTIONS_DEFAULT" */
- public static final String TYPE_COLLECTIONS = "type.collections";
+ public static final String FILTER_PREFIXES = "filter.prefixes";
- /** @scr.property valueRef="TYPE_NONCOLLECTIONS_DEFAULT" */
- public static final String TYPE_NONCOLLECTIONS = "type.noncollections";
+ @Property(name = FILTER_PREFIXES)
+ public static final String[] FILTER_PREFIXES_DEFAULT = new String[] {
+ "rep", "jcr" };
- /** @scr.property valueRef="TYPE_CONTENT_DEFAULT" */
- public static final String TYPE_CONTENT = "type.content";
+ public static final String[] EMPTY_DEFAULT = new String[0];
- public static final String DEFAULT_CONTEXT = "/dav";
+ @Property({})
+ public static final String FILTER_TYPES = "filter.types";
- public static final String DEFAULT_REALM = "Sling WebDAV";
+ @Property({})
+ public static final String FILTER_URIS = "filter.uris";
- public static final String[] EMPTY_DEFAULT = new String[0];
+ public static final String TYPE_COLLECTIONS_DEFAULT = "sling:Folder";
- public static final String[] FILTER_PREFIXES_DEFAULT = new String[] {
- "rep", "jcr" };
+ @Property(TYPE_COLLECTIONS_DEFAULT)
+ public static final String TYPE_COLLECTIONS = "type.collections";
- public static final String TYPE_COLLECTIONS_DEFAULT = "sling:Folder";
+ @Property(TYPE_NONCOLLECTIONS_DEFAULT)
+ public static final String TYPE_NONCOLLECTIONS = "type.noncollections";
- public static final String TYPE_NONCOLLECTIONS_DEFAULT = "nt:file";
+ @Property(TYPE_CONTENT_DEFAULT)
+ public static final String TYPE_CONTENT = "type.content";
- public static final String TYPE_CONTENT_DEFAULT = "nt:resource";
+ static final String IOHANDLER_REF_NAME = "IOHandler";
- public static final String[] COLLECTION_TYPES_DEFAULT = new String[] {
- TYPE_NONCOLLECTIONS_DEFAULT, TYPE_CONTENT_DEFAULT };
+ static final String PROPERTYHANDLER_REF_NAME = "PropertyHandler";
- /** @scr.reference */
+ @Reference
private SlingRepository repository;
- /** @scr.reference */
+ @Reference
private HttpService httpService;
- /** @scr.reference */
+ @Reference
private MimeTypeService mimeTypeService;
+ private final SlingIOManager ioManager = new SlingIOManager(
+ IOHANDLER_REF_NAME);
+
+ private final SlingPropertyManager propertyManager = new SlingPropertyManager(
+ PROPERTYHANDLER_REF_NAME);
+
private SlingResourceConfig resourceConfig;
private DavLocatorFactory locatorFactory;
private SessionProvider sessionProvider;
-
+
private boolean simpleWebDavServletRegistered;
// ---------- SimpleWebdavServlet overwrites -------------------------------
@@ -118,10 +153,10 @@ public class SlingWebDavServlet extends SimpleWebdavServlet {
@Override
public void init() throws ServletException {
super.init();
-
+
setResourceConfig(resourceConfig);
}
-
+
@Override
public Repository getRepository() {
return repository;
@@ -169,8 +204,13 @@ public class SlingWebDavServlet extends SimpleWebdavServlet {
protected void activate(ComponentContext context)
throws NamespaceException, ServletException {
+ this.ioManager.setComponentContext(context);
+ this.propertyManager.setComponentContext(context);
+
resourceConfig = new SlingResourceConfig(mimeTypeService,
- context.getProperties());
+ context.getProperties(),
+ ioManager,
+ propertyManager);
// Register servlet, and set the contextPath field to signal successful
// registration
@@ -182,12 +222,30 @@ public class SlingWebDavServlet extends SimpleWebdavServlet {
}
protected void deactivate(ComponentContext context) {
-
+
if (simpleWebDavServletRegistered) {
httpService.unregister(resourceConfig.getServletContextPath());
simpleWebDavServletRegistered = false;
}
- resourceConfig = null;
+ this.resourceConfig = null;
+ this.ioManager.setComponentContext(null);
+ this.propertyManager.setComponentContext(null);
+ }
+
+ public void bindIOHandler(final ServiceReference ioHandlerReference) {
+ this.ioManager.bindIOHandler(ioHandlerReference);
+ }
+
+ public void unbindIOHandler(final ServiceReference ioHandlerReference) {
+ this.ioManager.unbindIOHandler(ioHandlerReference);
+ }
+
+ public void bindPropertyHandler(final ServiceReference propertyHandlerReference) {
+ this.propertyManager.bindPropertyHandler(propertyHandlerReference);
+ }
+
+ public void unbindPropertyHandler(final ServiceReference propertyHandlerReference) {
+ this.propertyManager.unbindPropertyHandler(propertyHandlerReference);
}
}
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties
index a90afa5..78b4793 100644
--- a/src/main/resources/OSGI-INF/metatype/metatype.properties
+++ b/src/main/resources/OSGI-INF/metatype/metatype.properties
@@ -27,6 +27,26 @@
# SimpleWebDavServlet
# (This servlet is directly registered with the HttpService besides the
# SlingMainServlet. Requests to this servlet do not pass by Sling)
+iomanager.name = Apache Sling IOManager Service
+iomanager.description = The Sling IOManager service tracks all \
+ IOHandler services running on the framework and allows to access them \
+ as a sorted list (based on the service.ranking property).
+
+propertymanager.name = Apache Sling PropertyManager Service
+propertymanager.description = The Sling PropertyManager service tracks all \
+ PropertyManager services running on the framework and allows to access them \
+ as a sorted list (based on the service.ranking property).
+
+dirlistingexporthandler.name = Apache Sling Directory Listing Exporter Service
+dirlistingexporthandler.description = The Sling Directory Listing Exporter Service \
+ wraps a org.apache.jackrabbit.server.io.DirListingExportHandler instance in order to \
+ run it as a service.
+
+defaulthandler.name = Apache Sling Default Handler Service
+defaulthandler.description = The Apache Sling Default Handler Service \
+ wraps a org.apache.jackrabbit.server.io.DefaultHandler instance in order to \
+ run it as a service.
+
dav.name = Apache Sling Simple WebDAV Servlet
dav.description = The Simple WebDAV Servlet allows direct access to the \
complete Repository. It is directly accessible in its own URL space and \
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.