You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/03/25 20:54:43 UTC

svn commit: r640960 - in /incubator/sling/trunk/jcr/webdav: ./ src/main/java/org/apache/sling/jcr/webdav/ src/main/java/org/apache/sling/jcr/webdav/impl/ src/main/java/org/apache/sling/jcr/webdav/impl/helper/ src/main/java/org/apache/sling/jcr/webdav/i...

Author: fmeschbe
Date: Tue Mar 25 12:54:40 2008
New Revision: 640960

URL: http://svn.apache.org/viewvc?rev=640960&view=rev
Log:
SLING-342 Register SLingWebDavServlet as a global default servlet. This allows
supporting WebDAV requests inside Sling requests. For normal request processing
this should not interfere.

In addition, the bundle is reorganized to only contain classes below the impl
package. There are no exports from this bundle.

Added:
    incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/
    incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/
    incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingLocatorFactory.java
    incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceLocator.java
    incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingSessionProvider.java
    incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/
    incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/AbstractSlingWebDavServlet.java   (with props)
    incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SimpleWebDavServlet.java   (with props)
    incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java   (with props)
Removed:
    incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/SimpleWebDavServlet.java
Modified:
    incubator/sling/trunk/jcr/webdav/pom.xml

Modified: incubator/sling/trunk/jcr/webdav/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/webdav/pom.xml?rev=640960&r1=640959&r2=640960&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/webdav/pom.xml (original)
+++ incubator/sling/trunk/jcr/webdav/pom.xml Tue Mar 25 12:54:40 2008
@@ -64,7 +64,7 @@
                         <Bundle-Category>sling,jcr</Bundle-Category>
                         <!-- No Export-Package -->
                         <Private-Package>
-                            org.apache.sling.jcr.webdav,
+                            org.apache.sling.jcr.webdav.impl.*,
                             org.apache.jackrabbit;
                             org.apache.jackrabbit.commons.iterator;
                             org.apache.jackrabbit.name;

Added: incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingLocatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingLocatorFactory.java?rev=640960&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingLocatorFactory.java (added)
+++ incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingLocatorFactory.java Tue Mar 25 12:54:40 2008
@@ -0,0 +1,108 @@
+/*
+ * 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.helper;
+
+import org.apache.jackrabbit.util.Text;
+import org.apache.jackrabbit.webdav.DavLocatorFactory;
+import org.apache.jackrabbit.webdav.DavResourceLocator;
+
+public class SlingLocatorFactory implements DavLocatorFactory {
+
+    private final String workspaceName;
+
+    public SlingLocatorFactory(String workspaceName) {
+        this.workspaceName = workspaceName;
+    }
+
+    public DavResourceLocator createResourceLocator(String prefix, String href) {
+
+        if (href == null) {
+            throw new IllegalArgumentException(
+                "Request handle must not be null.");
+        }
+
+        
+        // if href starts with the prefix, cut the prefix off the href
+        if (prefix != null && prefix.length() > 0) {
+            if (href.startsWith(prefix)) {
+                href = href.substring(prefix.length());
+            }
+        }
+
+        // remove trailing "/" that is present with collections
+        if (href.endsWith("/")) {
+            href = href.substring(0, href.length() - 1);
+        }
+
+
+        // an empty requestHandle (after removal of the "/") signifies a request
+        // to the root that does not represent a repository item.
+        String resourcePath;
+        if ("".equals(href)) {
+            resourcePath = "/";
+        } else {
+            resourcePath = Text.unescape(href);
+        }
+
+        return new SlingResourceLocator(prefix, workspaceName, resourcePath,
+            this);
+    }
+
+    /**
+     * Create a new <code>DavResourceLocator</code> from the specified prefix,
+     * workspace path and resource path, whithout modifying the specified
+     * Strings. Note, that it is expected that the resource path starts with the
+     * given workspace path unless both values are <code>null</code>.
+     * 
+     * @param prefix
+     * @param workspacePath path or the workspace containing this resource or
+     *            <code>null</code>.
+     * @param resourcePath Path of the resource or <code>null</code>. Any non
+     *            null value must start with the specified workspace path.
+     * @return a new <code>DavResourceLocator</code>
+     * @see DavLocatorFactory#createResourceLocator(String, String, String)
+     */
+    public DavResourceLocator createResourceLocator(String prefix,
+            String workspacePath, String resourcePath) {
+        return createResourceLocator(prefix, workspacePath, resourcePath, true);
+    }
+
+    /**
+     * Create a new <code>DavResourceLocator</code> from the specified prefix,
+     * workspace path and resource path. If <code>isResourcePath</code> is set
+     * to <code>false</code>, the given 'resourcePath' is converted by
+     * calling {@link #getResourcePath(String, String)}. Otherwise the same
+     * restriction applies as for
+     * {@link #createResourceLocator(String, String, String)}.
+     * 
+     * @param prefix
+     * @param workspacePath
+     * @param path
+     * @param isResourcePath
+     * @return
+     * @see DavLocatorFactory#createResourceLocator(String, String, String,
+     *      boolean)
+     */
+    public DavResourceLocator createResourceLocator(String prefix,
+            String workspacePath, String resourcePath, boolean isResourcePath) {
+        return new SlingResourceLocator(prefix, workspacePath, resourcePath,
+            this);
+    }
+
+}

Added: incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceLocator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceLocator.java?rev=640960&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceLocator.java (added)
+++ incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceLocator.java Tue Mar 25 12:54:40 2008
@@ -0,0 +1,206 @@
+/*
+ * 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.helper;
+
+import org.apache.jackrabbit.util.Text;
+import org.apache.jackrabbit.webdav.DavLocatorFactory;
+import org.apache.jackrabbit.webdav.DavResourceLocator;
+
+class SlingResourceLocator implements DavResourceLocator {
+
+    private final String prefix;
+
+    private final String workspaceName;
+
+    private final String resourcePath;
+
+    private final SlingLocatorFactory factory;
+
+    private final String href;
+
+    SlingResourceLocator(String prefix, String workspaceName,
+            String resourcePath, SlingLocatorFactory factory) {
+
+        this.prefix = prefix;
+        this.workspaceName = workspaceName;
+        this.resourcePath = resourcePath;
+        this.factory = factory;
+
+        StringBuffer buf = new StringBuffer(prefix);
+        buf.append(Text.escapePath(resourcePath));
+        int length = buf.length();
+        if (length > 0 && buf.charAt(length - 1) != '/') {
+            buf.append("/");
+        }
+        href = buf.toString();
+    }
+
+    /**
+     * Return the prefix used to build the href String. This includes the
+     * initial hrefPrefix as well a the path prefix.
+     * 
+     * @return prefix String used to build the href.
+     */
+    public String getPrefix() {
+        return prefix;
+    }
+
+    /**
+     * Returns the resource path which always starts with the workspace
+     * path, if a workspace resource exists. For the top most resource
+     * (request handle '/'), <code>null</code> is returned.
+     * 
+     * @return resource path or <code>null</code>
+     * @see org.apache.jackrabbit.webdav.DavResourceLocator#getResourcePath()
+     */
+    public String getResourcePath() {
+        return resourcePath;
+    }
+
+    /**
+     * Return the workspace path or <code>null</code> if this locator
+     * object represents the '/' request handle.
+     * 
+     * @return workspace path or <code>null</code>
+     * @see org.apache.jackrabbit.webdav.DavResourceLocator#getWorkspacePath()
+     */
+    public String getWorkspacePath() {
+        return "/" + workspaceName;
+    }
+
+    /**
+     * Return the workspace name or <code>null</code> if this locator
+     * object represents the '/' request handle, which does not contain a
+     * workspace path.
+     * 
+     * @return workspace name or <code>null</code>
+     * @see org.apache.jackrabbit.webdav.DavResourceLocator#getWorkspaceName()
+     */
+    public String getWorkspaceName() {
+        return workspaceName;
+    }
+
+    /**
+     * Returns true if the specified locator object refers to a resource
+     * within the same workspace.
+     * 
+     * @param locator
+     * @return true if the workspace name obtained from the given locator
+     *         refers to the same workspace as the workspace name of this
+     *         locator.
+     * @see DavResourceLocator#isSameWorkspace(org.apache.jackrabbit.webdav.DavResourceLocator)
+     */
+    public boolean isSameWorkspace(DavResourceLocator locator) {
+        return (locator == null)
+                ? false
+                : isSameWorkspace(locator.getWorkspaceName());
+    }
+
+    /**
+     * Returns true if the specified string equals to this workspace name or
+     * if both names are null.
+     * 
+     * @param workspaceName
+     * @return true if the workspace name is equal to this workspace name.
+     * @see DavResourceLocator#isSameWorkspace(String)
+     */
+    public boolean isSameWorkspace(String workspaceName) {
+        String thisWspName = getWorkspaceName();
+        return (thisWspName == null)
+                ? workspaceName == null
+                : thisWspName.equals(workspaceName);
+    }
+
+    /**
+     * Returns an 'href' consisting of prefix and resource path (which
+     * starts with the workspace path). It assures a trailing '/' in case
+     * the href is used for collection. Note, that the resource path is
+     * {@link Text#escapePath(String) escaped}.
+     * 
+     * @param isCollection
+     * @return href String representing the text of the href element
+     * @see org.apache.jackrabbit.webdav.DavConstants#XML_HREF
+     * @see DavResourceLocator#getHref(boolean)
+     */
+    public String getHref(boolean isCollection) {
+        return (isCollection) ? href : href.substring(0, href.length() - 1);
+    }
+
+    /**
+     * Returns true if the 'workspacePath' field is <code>null</code>.
+     * 
+     * @return true if the 'workspacePath' field is <code>null</code>.
+     * @see org.apache.jackrabbit.webdav.DavResourceLocator#isRootLocation()
+     */
+    public boolean isRootLocation() {
+        return getWorkspacePath() == null;
+    }
+
+    /**
+     * Return the factory that created this locator.
+     * 
+     * @return factory
+     * @see org.apache.jackrabbit.webdav.DavResourceLocator#getFactory()
+     */
+    public DavLocatorFactory getFactory() {
+        return factory;
+    }
+
+    /**
+     * Uses {@link AbstractLocatorFactory#getRepositoryPath(String, String)}
+     * to build the repository path.
+     * 
+     * @see DavResourceLocator#getRepositoryPath()
+     */
+    public String getRepositoryPath() {
+        return getResourcePath();
+//        factory.getRepositoryPath(getResourcePath(),
+//            getWorkspacePath());
+    }
+
+    /**
+     * Computes the hash code from the href, that is built from the prefix,
+     * the workspace name and the resource path all of them representing
+     * final instance fields.
+     * 
+     * @return the hash code
+     */
+    public int hashCode() {
+        return href.hashCode();
+    }
+
+    /**
+     * Returns true, if the given object is a
+     * <code>SlingResourceLocator</code> with the same hash code.
+     * 
+     * @param obj the object to compare to
+     * @return <code>true</code> if the 2 objects are equal;
+     *         <code>false</code> otherwise
+     */
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (obj instanceof SlingResourceLocator) {
+            SlingResourceLocator other = (SlingResourceLocator) obj;
+            return hashCode() == other.hashCode();
+        }
+        return false;
+    }
+}
\ No newline at end of file

Added: incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingSessionProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingSessionProvider.java?rev=640960&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingSessionProvider.java (added)
+++ incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingSessionProvider.java Tue Mar 25 12:54:40 2008
@@ -0,0 +1,76 @@
+/*
+ * 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.helper;
+
+import javax.jcr.LoginException;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.jackrabbit.server.SessionProvider;
+
+/**
+ * The <code>SlingSessionProvider</code> is a Jackrabbit WebDAV server
+ * <code>SessionProvider</code> which returns the session stored as the
+ * <code>javax.jcr.Session</code> request attribute. This request attribute is
+ * set by the Sling Authenticator when the request is authenticated. If the
+ * request is not authenticated, the request attribute is not set and hence no
+ * session is returned.
+ * <p>
+ * This class expects an authenticated request, which is identified by the
+ * request authentication type to not be <code>null</code>. Otherwise the
+ * {@link #getSession(HttpServletRequest, Repository, String)} method throws a
+ * <code>LoginException</code> to force authentication.
+ */
+public class SlingSessionProvider implements SessionProvider {
+
+    /**
+     * The name of the request attribute providing the JCR session (value is
+     * "javax.jcr.Session").
+     */
+    private static final String ATTR_SESSION_NAME = Session.class.getName();
+
+    /**
+     * Returns the value of the <code>javax.jcr.Session</code> request
+     * attribute or <code>null</code> if the request attribute is not set. If
+     * the request is not authenticated, that is the authentication type is
+     * <code>null</code>, a <code>LoginException</code> is thrown to force
+     * authentication.
+     */
+    public Session getSession(HttpServletRequest request, Repository rep,
+            String workspace) throws LoginException {
+
+        // we do not accept the anonymous session for WebDAV !
+        if (request.getAuthType() == null) {
+            throw new LoginException("Authentication required for WebDAV");
+        }
+
+        // otherwise return the session from the request attribute
+        return (Session) request.getAttribute(ATTR_SESSION_NAME);
+    }
+
+    /**
+     * Does nothing as the session is taken from the Sling request and hence the
+     * session will be released by Sling.
+     */
+    public void releaseSession(Session session) {
+        // nothing to do, we must not logout the Sling session
+    }
+
+}

Added: incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/AbstractSlingWebDavServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/AbstractSlingWebDavServlet.java?rev=640960&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/AbstractSlingWebDavServlet.java (added)
+++ incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/AbstractSlingWebDavServlet.java Tue Mar 25 12:54:40 2008
@@ -0,0 +1,65 @@
+/*
+ * 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.servlets;
+
+import java.net.URL;
+
+import javax.jcr.Repository;
+import javax.servlet.ServletException;
+import javax.servlet.UnavailableException;
+
+import org.apache.jackrabbit.webdav.simple.ResourceConfig;
+import org.apache.jackrabbit.webdav.simple.SimpleWebdavServlet;
+import org.apache.sling.jcr.api.SlingRepository;
+
+/**
+ * The <code>SimpleWebDavServlet</code>
+ * 
+ * @scr.component
+ *  immediate="true"
+ *  metatype="false"
+ */
+abstract class AbstractSlingWebDavServlet extends SimpleWebdavServlet {
+
+    /** @scr.reference */
+    private SlingRepository repository;
+
+    @Override
+    public Repository getRepository() {
+        return repository;
+    }
+
+    @Override
+    public void init() throws ServletException {
+        super.init();
+
+        // for now, the ResourceConfig is fixed
+        final String configPath = "/webdav-resource-config.xml";
+        final ResourceConfig rc = new ResourceConfig();
+        final URL cfg = getClass().getResource(configPath);
+        if (cfg == null) {
+            throw new UnavailableException("ResourceConfig source not found:"
+                + configPath);
+        }
+        
+        rc.parse(cfg);
+        setResourceConfig(rc);
+    }
+
+}

Propchange: incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/AbstractSlingWebDavServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SimpleWebDavServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SimpleWebDavServlet.java?rev=640960&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SimpleWebDavServlet.java (added)
+++ incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SimpleWebDavServlet.java Tue Mar 25 12:54:40 2008
@@ -0,0 +1,129 @@
+/*
+ * 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.servlets;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.jcr.api.SlingRepository;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+
+/**
+ * The <code>SimpleWebDavServlet</code>
+ * 
+ * @scr.component
+ */
+public class SimpleWebDavServlet extends AbstractSlingWebDavServlet {
+
+    /** @scr.property value="/dav" */
+    private static final String PROP_CONTEXT = "dav.root";
+
+    /** @scr.property value="Sling WebDAV" */
+    private static final String PROP_REALM = "dav.realm";
+
+    private static final String DEFAULT_CONTEXT = "/dav";
+
+    /** @scr.reference */
+    private HttpService httpService;
+
+    // the alias under which the servlet is registered, null if not
+    private String contextPath;
+
+    // ---------- AbstractWebdavServlet overwrite ------------------------------
+
+    @Override
+    protected void service(HttpServletRequest request,
+            HttpServletResponse response) throws ServletException, IOException {
+
+        final String pinfo = request.getPathInfo();
+
+        if (pinfo == null || "/".equals(pinfo)) {
+            // redirect to the default workspace if directly addressing the
+            // servlet
+            // and if the default workspace name is not null (in which case we'd
+            // need
+            // to login to find out the actual workspace name, SLING-256)
+            SlingRepository slingRepo = (SlingRepository) getRepository();
+            if (slingRepo.getDefaultWorkspace() == null) {
+                response.sendError(
+                    HttpServletResponse.SC_NOT_FOUND,
+                    "JCR workspace name required, please add it to the end of the URL"
+                        + " (for the Jackrabbit embedded repository the default name is 'default') ");
+            } else {
+                String uri = request.getRequestURI();
+                if (pinfo == null) {
+                    uri += "/";
+                }
+                uri += slingRepo.getDefaultWorkspace();
+                response.sendRedirect(uri);
+            }
+        }
+
+        super.service(request, response);
+    }
+
+    // ---------- SCR integration ----------------------------------------------
+
+    protected void activate(ComponentContext componentContext)
+            throws NamespaceException, ServletException {
+
+        Dictionary<?, ?> props = componentContext.getProperties();
+
+        String context = getString(props, PROP_CONTEXT, DEFAULT_CONTEXT);
+
+        Dictionary<String, String> initparams = new Hashtable<String, String>();
+
+        initparams.put(INIT_PARAM_RESOURCE_PATH_PREFIX, context);
+
+        String value = getString(props, PROP_REALM, null);
+        if (value != null) {
+            initparams.put(INIT_PARAM_AUTHENTICATE_HEADER, "Basic Realm=\""
+                + value + "\"");
+        }
+
+        // Register servlet, and set the contextPath field to signal successful
+        // registration
+        httpService.registerServlet(context, this, initparams, null);
+        this.contextPath = context;
+    }
+
+    protected void deactivate(ComponentContext context) {
+        if (contextPath != null) {
+            httpService.unregister(contextPath);
+            contextPath = null;
+        }
+    }
+
+    // ---------- internal -----------------------------------------------------
+
+    private String getString(Dictionary<?, ?> props, String name,
+            String defaultValue) {
+        Object propValue = props.get(name);
+        return (propValue instanceof String)
+                ? (String) propValue
+                : defaultValue;
+    }
+}

Propchange: incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SimpleWebDavServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java?rev=640960&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java (added)
+++ incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java Tue Mar 25 12:54:40 2008
@@ -0,0 +1,97 @@
+/*
+ * 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.servlets;
+
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.server.SessionProvider;
+import org.apache.jackrabbit.webdav.DavLocatorFactory;
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.webdav.impl.helper.SlingLocatorFactory;
+import org.apache.sling.jcr.webdav.impl.helper.SlingSessionProvider;
+
+/**
+ * The <code>SlingWebDavServlet</code> implements the WebDAV protocol as a
+ * default servlet for Sling handling all WebDAV methods.
+ * 
+ * @scr.component
+ *  immediate="true"
+ *  metatype="false"
+ *
+ * @scr.service
+ *  interface="javax.servlet.Servlet"
+ *
+ * @scr.property
+ *  name="service.description"
+ *  value="Sling WebDAV Servlet"
+ *
+ * @scr.property
+ *  name="service.vendor"
+ *  value="The Apache Software Foundation"
+ *
+ * Use this as the default servlet for all requests to Sling
+ * @scr.property
+ *  name="sling.servlet.resourceTypes"
+ *  value="sling/servlet/default"
+ */
+public class SlingWebDavServlet extends AbstractSlingWebDavServlet {
+
+    private DavLocatorFactory locatorFactory;
+    
+    private SessionProvider sessionProvider;
+
+    //---------- SimpleWebdavServlet overwrites -------------------------------
+    
+    @Override
+    public DavLocatorFactory getLocatorFactory() {
+        if (locatorFactory == null) {
+            
+            // configured default workspace name
+            SlingRepository slingRepo = (SlingRepository) getRepository();
+            String workspace = slingRepo.getDefaultWorkspace();
+            
+            // no configuration, try to login and acquire the default name
+            if (workspace == null || workspace.length() == 0) {
+                Session tmp = null;
+                try {
+                    tmp = slingRepo.login();
+                    workspace = tmp.getWorkspace().getName();
+                } catch (Throwable t) {
+                    // TODO: log !!
+                    workspace = "default"; // fall back name
+                } finally {
+                    if (tmp != null) {
+                        tmp.logout();
+                    }
+                }
+            }
+            
+            locatorFactory = new SlingLocatorFactory(workspace);
+        }
+        return locatorFactory;
+    }
+    
+    @Override
+    public synchronized SessionProvider getSessionProvider() {
+        if (sessionProvider == null) {
+            sessionProvider = new SlingSessionProvider();
+        }
+        return sessionProvider;
+    }
+}

Propchange: incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native