jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r156314 [5/15] - in incubator/jackrabbit/trunk/contrib/jcr-server: ./ client/ client/src/ client/src/java/ client/src/java/org/ client/src/java/org/apache/ client/src/java/org/apache/jackrabbit/ client/src/java/org/apache/jackrabbit/client/ server/ server/src/ server/src/java/ server/src/java/org/ server/src/java/org/apache/ server/src/java/org/apache/jackrabbit/ server/src/java/org/apache/jackrabbit/server/ server/src/java/org/apache/jackrabbit/server/simple/ server/src/java/org/apache/jackrabbit/server/simple/dav/ server/src/java/org/apache/jackrabbit/server/simple/dav/lock/ server/src/java/org/apache/jackrabbit/webdav/ server/src/java/org/apache/jackrabbit/webdav/spi/ server/src/java/org/apache/jackrabbit/webdav/spi/lock/ server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/ server/src/java/org/apache/jackrabbit/webdav/spi/observation/ server/src/java/org/apache/jackrabbit/webdav/spi/search/ server/src/java/org/apache/jackrabbit/webdav/spi/transaction/ server/src/java/org/apache/jackrabbit/webdav/spi/version/ server/src/java/org/apache/jackrabbit/webdav/spi/version/report/ webapp/ webapp/src/ webapp/src/webapp/ webapp/src/webapp/WEB-INF/ webapp/src/webapp/WEB-INF/repository/ webdav/ webdav/src/ webdav/src/java/ webdav/src/java/org/ webdav/src/java/org/apache/ webdav/src/java/org/apache/jackrabbit/ webdav/src/java/org/apache/jackrabbit/webdav/ webdav/src/java/org/apache/jackrabbit/webdav/lock/ webdav/src/java/org/apache/jackrabbit/webdav/observation/ webdav/src/java/org/apache/jackrabbit/webdav/ordering/ webdav/src/java/org/apache/jackrabbit/webdav/property/ webdav/src/java/org/apache/jackrabbit/webdav/search/ webdav/src/java/org/apache/jackrabbit/webdav/transaction/ webdav/src/java/org/apache/jackrabbit/webdav/util/ webdav/src/java/org/apache/jackrabbit/webdav/version/ webdav/src/java/org/apache/jackrabbit/webdav/version/report/
Date Sun, 06 Mar 2005 14:03:10 GMT
Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/ItemResourceConstants.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/ItemResourceConstants.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/ItemResourceConstants.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/ItemResourceConstants.java Sun Mar  6 06:02:39 2005
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.spi;
+
+import org.jdom.Namespace;
+import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.version.DeltaVResource;
+import org.apache.jackrabbit.webdav.lock.Scope;
+import org.apache.jackrabbit.webdav.search.SearchResource;
+import org.apache.jackrabbit.webdav.observation.ObservationResource;
+
+/**
+ * <code>ItemResourceConstants</code> provides constants for any resources
+ * representing repository items.
+ */
+public interface ItemResourceConstants {
+
+    /**
+     * Complience classes common to all item resources.
+     */
+    public static final String COMPLIANCE_CLASS = DavResource.COMPLIANCE_CLASS + ", " +ObservationResource.COMPLIANCE_CLASS + ", " + DeltaVResource.COMPLIANCE_CLASS;
+
+    /**
+     * Methods common to all item resources.
+     */
+    public static final String METHODS = DavResource.METHODS + ", " + ObservationResource.METHODS + ", " + SearchResource.METHODS + ", " +DeltaVResource.METHODS;
+
+    /**
+     * The resource path of the root-item-resource.
+     */
+    public static final String ROOT_ITEM_PATH = "/";
+
+    /**
+     * The version storage item resource path.
+     */
+    public static final String VERSIONSTORAGE_PATH = "/jcr:system/jcr:versionStorage";
+
+    /**
+     * Constant for the mix:versionable node type name.
+     */
+    public static final String MIX_VERSIONABLE = "mix:versionable";
+
+    /**
+     * Constant for the mix:lockable node type name.
+     */
+    public static final String MIX_LOCKABLE = "mix:lockable";
+
+    /**
+     * The namespace for all jcr specific extensions.
+     */
+    public static final Namespace NAMESPACE = Namespace.getNamespace("jcr", "http://www.day.com/jcr/webdav/1.0");
+
+    // xml element names
+    public static final String XML_PRIMARYNODETYPE = "primarynodetype";
+    public static final String XML_VALUE = "value";
+    public static final String XML_LENGTH = "length";
+    public static final String XML_EXCLUSIVE_SESSION_SCOPED = "exclusive-session-scoped";
+
+    /**
+     * Extension to the WebDAV 'exclusive' lock, that allows to distinguish
+     * the session-scoped and open-scoped locks on a JCR node.
+     *
+     * @see javax.jcr.Node#lock(boolean, boolean)
+     */
+    public static final Scope EXCLUSIVE_SESSION = Scope.create(XML_EXCLUSIVE_SESSION_SCOPED, NAMESPACE);
+
+    /**
+     * The 'removeexisting' element is not defined by RFC 3253. If it is present
+     * in the UPDATE request body, uuid conflicts should be solved by removing
+     * the existing nodes.
+     *
+     * @see javax.jcr.Node#restore(javax.jcr.version.Version, boolean)
+     * @see javax.jcr.Workspace#restore(javax.jcr.version.Version[], boolean)
+     * @see org.apache.jackrabbit.webdav.version.UpdateInfo
+     */
+    public static final String XML_REMOVEEXISTING = "removeexisting";
+
+    /**
+     * The 'relpath' element is not defined by RFC 3253. If it is present
+     * in the UPDATE request body, the server is forced to used the text contained
+     * as 'relPath' argument for the {@link javax.jcr.Node#restore(javax.jcr.version.Version, String, boolean)
+     * Node.restore} call.
+     *
+     * @see javax.jcr.Node#restore(javax.jcr.version.Version, String, boolean)
+     * @see org.apache.jackrabbit.webdav.version.UpdateInfo
+     */
+    public static final String XML_RELPATH = "relpath";
+
+    // general property names
+    public static final DavPropertyName JCR_NAME = DavPropertyName.create("name", NAMESPACE);
+    public static final DavPropertyName JCR_PATH = DavPropertyName.create("path", NAMESPACE);
+    public static final DavPropertyName JCR_DEPTH = DavPropertyName.create("depth", NAMESPACE);
+    public static final DavPropertyName JCR_ISNEW = DavPropertyName.create("isnew", NAMESPACE);
+    public static final DavPropertyName JCR_ISMODIFIED = DavPropertyName.create("ismodified", NAMESPACE);
+
+    // property names used for resources representing jcr-nodes
+    public static final DavPropertyName JCR_PRIMARYNODETYPE = DavPropertyName.create(XML_PRIMARYNODETYPE, NAMESPACE);
+    public static final DavPropertyName JCR_MIXINNODETYPES = DavPropertyName.create("mixinnodetypes", NAMESPACE);
+    public static final DavPropertyName JCR_INDEX = DavPropertyName.create("index", NAMESPACE);
+    public static final DavPropertyName JCR_REFERENCES = DavPropertyName.create("references", NAMESPACE);
+    public static final DavPropertyName JCR_PRIMARYITEM = DavPropertyName.create("primaryitem", NAMESPACE);
+
+    // property names used for resources representing jcr-properties
+    public static final DavPropertyName JCR_TYPE = DavPropertyName.create("type", NAMESPACE);
+    public static final DavPropertyName JCR_VALUE = DavPropertyName.create("value", NAMESPACE);
+    public static final DavPropertyName JCR_VALUES = DavPropertyName.create("values", NAMESPACE);
+    public static final DavPropertyName JCR_LENGTH = DavPropertyName.create("length", NAMESPACE);
+    public static final DavPropertyName JCR_LENGTHS = DavPropertyName.create("lengths", NAMESPACE);
+
+    /**
+     * Property name for the jcr:created property present on Version items.
+     */
+    public static final DavPropertyName CREATED = DavPropertyName.create("created", ItemResourceConstants.NAMESPACE);
+
+    // JCR property names
+    public static final String PROP_LASTMODIFIED = "jcr:lastModified";
+    public static final String PROP_CREATED = "jcr:created";
+    public static final String PROP_BASEVERSION = "jcr:baseVersion";
+    public static final String PROP_PREDECESSORS = "jcr:predecessors";
+    public static final String PROP_MERGEFAILED = "jcr:mergeFailed";
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/ItemResourceConstants.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/ItemResourceConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/JcrDavException.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/JcrDavException.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/JcrDavException.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/JcrDavException.java Sun Mar  6 06:02:39 2005
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.spi;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.jdom.Element;
+
+import javax.jcr.*;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.lock.LockException;
+import javax.jcr.version.VersionException;
+import javax.jcr.nodetype.*;
+
+/**
+ * <code>JcrDavException</code> extends the {@link DavException} in order to
+ * wrap various repository exceptions.
+ */
+public class JcrDavException extends DavException {
+
+    private static Logger log = Logger.getLogger(JcrDavException.class);
+
+    private Class exceptionClass;
+
+    public JcrDavException(Exception e, int errorCode) {
+        super(errorCode, e.getMessage());
+        exceptionClass = e.getClass();
+    }
+
+    public JcrDavException(AccessDeniedException e) {
+        this(e, DavServletResponse.SC_FORBIDDEN);
+    }
+
+    public JcrDavException(ConstraintViolationException e) {
+        this(e, DavServletResponse.SC_CONFLICT);
+    }
+
+    public JcrDavException(InvalidItemStateException e) {
+        this(e, DavServletResponse.SC_CONFLICT);
+    }
+
+    public JcrDavException(InvalidSerializedDataException e) {
+        this(e, DavServletResponse.SC_BAD_REQUEST);
+    }
+
+    public JcrDavException(InvalidQueryException e) {
+        this(e, DavServletResponse.SC_BAD_REQUEST);
+    }
+
+    public JcrDavException(ItemExistsException e) {
+        this(e, DavServletResponse.SC_CONFLICT);
+    }
+
+    public JcrDavException(ItemNotFoundException e) {
+        this(e, DavServletResponse.SC_FORBIDDEN);
+    }
+
+    public JcrDavException(LockException e) {
+        this(e, DavServletResponse.SC_LOCKED);
+    }
+
+    public JcrDavException(MergeException e) {
+        this(e, DavServletResponse.SC_CONFLICT);
+    }
+
+    public JcrDavException(NamespaceException e) {
+        this(e, DavServletResponse.SC_CONFLICT);
+    }
+
+    public JcrDavException(NoSuchNodeTypeException e) {
+        this(e, DavServletResponse.SC_CONFLICT);
+    }
+
+    public JcrDavException(NoSuchWorkspaceException e) {
+        this(e, DavServletResponse.SC_CONFLICT);
+    }
+
+    public JcrDavException(PathNotFoundException e) {
+        this(e, DavServletResponse.SC_CONFLICT);
+    }
+
+    public JcrDavException(ReferentialIntegrityException e) {
+        this(e, DavServletResponse.SC_CONFLICT);
+    }
+
+    public JcrDavException(RepositoryException e) {
+        this(e, DavServletResponse.SC_FORBIDDEN);
+    }
+
+    public JcrDavException(UnsupportedRepositoryOperationException e) {
+        this(e, DavServletResponse.SC_NOT_IMPLEMENTED);
+    }
+
+    public JcrDavException(ValueFormatException e) {
+        this(e, DavServletResponse.SC_CONFLICT);
+    }
+
+    public JcrDavException(VersionException e) {
+        this(e, DavServletResponse.SC_CONFLICT);
+    }
+
+    /**
+     * Returns a DAV:error Xml element containing the exceptions class and the
+     * message as child elements.
+     *
+     * @return Xml representation of this exception.
+     */
+    public Element getError() {
+        Element error = super.getError();
+        Element excep = new Element("exception", ItemResourceConstants.NAMESPACE);
+        excep.addContent(new Element("class", ItemResourceConstants.NAMESPACE).setText(exceptionClass.getName()));
+        excep.addContent(new Element("message", ItemResourceConstants.NAMESPACE).setText(getMessage()));
+        error.addContent(excep);
+        return error;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/JcrDavException.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/JcrDavException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/RootCollection.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/RootCollection.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/RootCollection.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/RootCollection.java Sun Mar  6 06:02:39 2005
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.spi;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.*;
+
+import javax.jcr.RepositoryException;
+import java.util.*;
+import java.io.InputStream;
+
+/**
+ * <code>RootCollection</code> represent the WebDAV root resource that does not
+ * represent any repository item. A call to getMembers() returns a
+ * <code>DavResourceIterator</code> containing only <code>RootItemCollection</code>
+ * resources, thus revealing the names of the accessable workspaces.
+ */
+public class RootCollection extends AbstractResource implements DavResource {
+
+    private static Logger log = Logger.getLogger(RootCollection.class);
+
+    /**
+     * Create a new <code>RootCollection</code>.
+     *
+     * @param locator
+     * @param session
+     */
+    protected RootCollection(DavResourceLocator locator, DavSession session, DavResourceFactory factory) {
+        super(locator, session, factory);
+        setModificationTime(new Date().getTime());
+    }
+
+    /**
+     * Returns a string listing the complieance classes for this resource as it
+     * is required for the DAV response header.
+     *
+     * @return string listing the compliance classes.
+     * @see org.apache.jackrabbit.webdav.DavResource#getComplianceClass()
+     */
+    public String getComplianceClass() {
+        return DavResource.COMPLIANCE_CLASS;
+    }
+
+    /**
+     * Returns a string listing the METHODS for this resource as it
+     * is required for the "Allow" response header.
+     *
+     * @return string listing the METHODS allowed
+     * @see org.apache.jackrabbit.webdav.DavResource#getSupportedMethods()
+     */
+    public String getSupportedMethods() {
+        StringBuffer sb = new StringBuffer(DavResource.METHODS);
+        return sb.toString();
+    }
+
+    /**
+     * Returns true
+     *
+     * @return true
+     * @see org.apache.jackrabbit.webdav.DavResource#exists()
+     */
+    public boolean exists() {
+        return true;
+    }
+
+    /**
+     * Returns true
+     *
+     * @return true
+     * @see org.apache.jackrabbit.webdav.DavResource#isCollection()
+     */
+    public boolean isCollection() {
+        return true;
+    }
+
+    /**
+     * Returns an empty string.
+     *
+     * @return empty string
+     * @see org.apache.jackrabbit.webdav.DavResource#getDisplayName()
+     */
+    public String getDisplayName() {
+        return "";
+    }
+
+    /**
+     * Always returns <code>null</code>
+     *
+     * @return <code>null</code> for the root resource is not internal member
+     * of any resource.
+     * @see org.apache.jackrabbit.webdav.DavResource#getCollection()
+     */
+    public DavResource getCollection() {
+        return null;
+    }
+
+    /**
+     * Throws exception: 403 Forbidden.
+     * @see DavResource#addMember(DavResource, InputStream)
+     */
+    public void addMember(DavResource resource, InputStream in) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    /**
+     * Throws exception: 403 Forbidden.
+     * @see DavResource#addMember(org.apache.jackrabbit.webdav.DavResource)
+     */
+    public void addMember(DavResource resource) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    /**
+     * Returns an iterator over the member resources, which are all
+     * <code>RootItemCollection</code> resources, revealing
+     * the names of all available workspaces.
+     *
+     * @return members of this collection
+     * @see org.apache.jackrabbit.webdav.DavResource#getMembers()
+     */
+    public DavResourceIterator getMembers() {
+        List memberList = new ArrayList();
+        try {
+            String[] wsNames = getSession().getRepositorySession().getWorkspace().getAccessibleWorkspaceNames();
+            for (int i = 0; i < wsNames.length; i++) {
+                DavResourceLocator childLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), "/"+wsNames[i], ItemResourceConstants.ROOT_ITEM_PATH);
+                memberList.add(createResourceFromLocator(childLoc));
+            }
+        } catch (RepositoryException e) {
+            log.error(e.getMessage());
+        } catch (DavException e) {
+            // should never occur
+            log.error(e.getMessage());
+        }
+        return new DavResourceIteratorImpl(memberList);
+    }
+
+    /**
+     * Throws exception: 403 Forbidden.
+     * @see DavResource#removeMember(org.apache.jackrabbit.webdav.DavResource)
+     */
+    public void removeMember(DavResource member) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/RootCollection.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/RootCollection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/RootItemCollection.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/RootItemCollection.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/RootItemCollection.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/RootItemCollection.java Sun Mar  6 06:02:39 2005
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.spi;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.*;
+import org.apache.jackrabbit.webdav.spi.version.VersionControlledItemCollection;
+
+/**
+ * <code>RootItemCollection</code> represents the root node of the underlaying
+ * repository. However, the display name the name of the workspace is returned
+ * the root node is located.
+ *
+ * @todo currently the jcr root node is the same for all workspace resources... this is wrong...
+ */
+public class RootItemCollection extends VersionControlledItemCollection {
+
+    private static Logger log = Logger.getLogger(RootItemCollection.class);
+
+    /**
+     * Create a new <code>RootItemCollection</code>.
+     *
+     * @param locator
+     * @param session
+     */
+    protected RootItemCollection(DavResourceLocator locator, DavSession session, DavResourceFactory factory) {
+        super(locator, session, factory);
+    }
+
+    //----------------------------------------------< DavResource interface >---
+    /**
+     * Returns the name of the workspace the underlaying root item forms part of.
+     *
+     * @return The workspace name
+     * @see org.apache.jackrabbit.webdav.DavResource#getDisplayName()
+     * @see javax.jcr.Workspace#getName()
+     */
+    public String getDisplayName() {
+        return getLocator().getWorkspaceName();
+    }
+
+    /**
+     * Retrieve the collection that has all root item / workspace collections
+     * as internal members.
+     *
+     * @see org.apache.jackrabbit.webdav.DavResource#getCollection()
+     */
+    public DavResource getCollection() {
+        DavResource collection = null;
+        // create location with 'null' values for workspace-path and resource-path
+        DavResourceLocator parentLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), null, null);
+        try {
+            collection = createResourceFromLocator(parentLoc);
+        } catch (DavException e) {
+            log.error("Unexpected error while retrieving collection: " + e.getMessage());
+        }
+        return collection;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/RootItemCollection.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/RootItemCollection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/lock/JcrActiveLock.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/lock/JcrActiveLock.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/lock/JcrActiveLock.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/lock/JcrActiveLock.java Sun Mar  6 06:02:39 2005
@@ -0,0 +1,172 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.spi.lock;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.DavConstants;
+import org.apache.jackrabbit.webdav.spi.ItemResourceConstants;
+import org.apache.jackrabbit.webdav.lock.*;
+
+import javax.jcr.lock.Lock;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>JcrActiveLock</code> wraps a {@link Lock JCR lock} object.
+ */
+public class JcrActiveLock extends AbstractActiveLock implements ActiveLock, DavConstants {
+
+    private static Logger log = Logger.getLogger(JcrActiveLock.class);
+
+    private final Lock lock;
+    private final boolean sessionScoped;
+
+    /**
+     * Create a new <code>ActiveLock</code> object with type '{@link Type#WRITE write}'
+     * and scope '{@link Scope#EXCLUSIVE exclusive}'.
+     *
+     * @param lock
+     */
+    public JcrActiveLock(Lock lock) {
+        this (lock, false);
+    }
+
+    /**
+     * Create a new <code>ActiveLock</code> object with type '{@link Type#WRITE write}'
+     * and scope '{@link Scope#EXCLUSIVE exclusive}'.
+     *
+     * @param lock
+     */
+    public JcrActiveLock(Lock lock, boolean sessionScoped) {
+        if (lock == null) {
+            throw new IllegalArgumentException("Can not create a ActiveLock with a 'null' argument.");
+        }
+        this.lock = lock;
+        this.sessionScoped = sessionScoped;
+    }
+
+    /**
+     * Return true if the given lock token equals the token holding that lock.
+     *
+     * @param lockToken
+     * @return true if the given lock token equals this locks token.
+     * @see org.apache.jackrabbit.webdav.lock.ActiveLock#isLockedByToken(String)
+     */
+    public boolean isLockedByToken(String lockToken) {
+        if (lockToken != null && lockToken.equals(getToken())) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * @see ActiveLock#isExpired()
+     */
+    public boolean isExpired() {
+        return lock.isLive();
+    }
+
+    /**
+     * Return the lock token if the {@link javax.jcr.Session} that optained the lock
+     * is the lock token holder, <code>null</code> otherwise.<br>
+     * NOTE: currently the token generated by the underlaying JCR repository
+     * is not checked for compliance with RFC 2518 ("<cite>OpaqueLockToken-URI = "opaquelocktoken:"
+     * UUID [Extension] ; The UUID production is the string representation of a
+     * UUID, as defined in [ISO-11578]. Note that white space (LWS) is not allowed
+     * between elements of this production.</cite>").
+     *
+     * @see ActiveLock#getToken()
+     */
+    public String getToken() {
+        return lock.getLockToken();
+    }
+
+    /**
+     * @see ActiveLock#getOwner()
+     */
+    public String getOwner() {
+        return lock.getLockOwner();
+    }
+
+    /**
+     * @see ActiveLock#setOwner(String)
+     */
+    public void setOwner(String owner) {
+        throw new UnsupportedOperationException("setOwner is not implemented");
+    }
+
+    /**
+     * Always returns {@link DavConstants#UNDEFINED_TIMEOUT} for the timeout
+     * cannot be retrieved from the JCR lock.
+     * 
+     * @see ActiveLock#getTimeout()
+     * @see DavConstants#UNDEFINED_TIMEOUT
+     */
+    public long getTimeout() {
+        return UNDEFINED_TIMEOUT;
+    }
+
+    /**
+     * @see ActiveLock#setTimeout(long)
+     */
+    public void setTimeout(long timeout) {
+        throw new UnsupportedOperationException("setTimeout is not implemented");
+    }
+
+    /**
+     * @see ActiveLock#isDeep()
+     */
+    public boolean isDeep() {
+        boolean isDeep = true;
+        Node n = lock.getNode();
+        try {
+            // find out about deepness. if node does not hold the lock its deep anyway
+            if (n.holdsLock() && n.hasProperty("jcr:lockIsDeep")) {
+                isDeep = n.getProperty("jcr:lockIsDeep").getBoolean();
+            }
+        } catch (RepositoryException e) {
+            // ignore and keep default depth settings
+        }
+        return isDeep;
+    }
+
+    /**
+     * @see ActiveLock#setIsDeep(boolean)
+     */
+    public void setIsDeep(boolean isDeep) {
+        throw new UnsupportedOperationException("setIsDeep is not implemented");
+    }
+
+    /**
+     * Always returns {@link Type#WRITE}.
+     *
+     * @return {@link Type#WRITE}
+     * @see ActiveLock#getType()
+     */
+    public Type getType() {
+        return Type.WRITE;
+    }
+
+    /**
+     * @return The scope of this lock, which may either by an {@link Scope#EXCLUSIVE exclusive}
+     * or {@link ItemResourceConstants#EXCLUSIVE_SESSION exlusive session scoped}
+     * lock.
+     * @see ActiveLock#getScope()
+     */
+    public Scope getScope() {
+        return (sessionScoped) ? ItemResourceConstants.EXCLUSIVE_SESSION : Scope.EXCLUSIVE;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/lock/JcrActiveLock.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/lock/JcrActiveLock.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/lock/SessionScopedLockEntry.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/lock/SessionScopedLockEntry.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/lock/SessionScopedLockEntry.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/lock/SessionScopedLockEntry.java Sun Mar  6 06:02:39 2005
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.spi.lock;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.lock.LockEntry;
+import org.apache.jackrabbit.webdav.lock.Scope;
+import org.apache.jackrabbit.webdav.lock.Type;
+import org.apache.jackrabbit.webdav.lock.AbstractLockEntry;
+import org.apache.jackrabbit.webdav.spi.ItemResourceConstants;
+
+/**
+ * <code>SessionScopedLockEntry</code> represents the 'session-scoped' write
+ * lock as defined by JCR.
+ */
+public class SessionScopedLockEntry extends AbstractLockEntry {
+
+    private static Logger log = Logger.getLogger(SessionScopedLockEntry.class);
+
+    /**
+     * @return always returns {@link Type#WRITE write}.
+     * @see LockEntry#getType()
+     */
+    public Type getType() {
+        return Type.WRITE;
+    }
+
+    /**
+     * @return returns {@link ItemResourceConstants#EXCLUSIVE_SESSION}.
+     * @see LockEntry#getScope()
+     */
+    public Scope getScope() {
+        return ItemResourceConstants.EXCLUSIVE_SESSION;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/lock/SessionScopedLockEntry.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/lock/SessionScopedLockEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeConstants.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeConstants.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeConstants.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeConstants.java Sun Mar  6 06:02:39 2005
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.spi.nodetype;
+
+import org.jdom.Namespace;
+import org.apache.jackrabbit.webdav.spi.ItemResourceConstants;
+
+/**
+ * <code>NodeTypeConstants</code> used to represent nodetype definitions in
+ * Xml.
+ *
+ * @see javax.jcr.nodetype.NodeType
+ */
+public interface NodeTypeConstants {
+
+    public static final Namespace NAMESPACE = ItemResourceConstants.NAMESPACE;
+
+    public static final String XML_NODETYPE = "nodetype";
+    public static final String XML_NODETYPENAME = "nodetypename";
+
+    public static final String XML_NODETYPEDEFINITION = "nodetypedefinition";
+
+    public static final String XML_MIXIN = "mixin";
+    public static final String XML_ORDERABLECHILDNODES = "orderablechildnodes";
+    public static final String XML_PRIMARYITEMNAME = "primaryitemname";
+
+    public static final String XML_SUPERTYPES = "supertypes";
+    public static final String XML_DECLARED_SUPERTYPES = "declaredsupertypes";
+    public static final String XML_CHILDNODEDEF = "childnodedef";
+    public static final String XML_PROPERTYDEF = "propertydef";
+
+    public static final String ATTR_NAME = "name";
+    public static final String ATTR_AUTOCREATE = "autocreate";
+    public static final String ATTR_MANDATORY = "mandatory";
+    public static final String ATTR_PROTECTED = "protected";
+    public static final String ATTR_ONPARENTVERSION = "onparentversion";
+
+    public static final String ATTR_MULTIPLE = "multiple";
+    public static final String ATTR_TYPE = "type";
+
+    public static final String ATTR_SAMENAMESIBS = "samenamesibs";
+
+    public static final String XML_DECLARINGNODETYPE = "declaringnodetype";
+    
+    public static final String XML_VALUECONSTRAINTS = "valueconstraints";
+    public static final String XML_VALUECONSTRAINT = "valueconstraint";
+    public static final String XML_DEFAULTVALUES = "defaultvalues";
+    public static final String XML_DEFAULTVALUE = "defaultvalue";
+
+    public static final String XML_DEFAULTPRIMARYTYPE = "defaultprimarytype";
+    public static final String XML_REQUIREDPRIMARYTYPES = "requiredprimarytypes";
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeConstants.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeElement.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeElement.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeElement.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeElement.java Sun Mar  6 06:02:39 2005
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.spi.nodetype;
+
+import org.apache.log4j.Logger;
+import org.jdom.Element;
+
+import javax.jcr.nodetype.NodeType;
+
+/**
+ * <code>NodeTypeElement</code>...
+ */
+public class NodeTypeElement extends Element implements NodeTypeConstants {
+
+    private static Logger log = Logger.getLogger(NodeTypeElement.class);
+
+    public NodeTypeElement(NodeType nt) {
+        super(XML_NODETYPE, NodeTypeConstants.NAMESPACE);
+        addNodeTypeNameElement(nt.getName());
+    }
+
+    public NodeTypeElement(Element ntElement) {
+        super(XML_NODETYPE, NodeTypeConstants.NAMESPACE);
+        if (!XML_NODETYPE.equals(ntElement.getName())) {
+            throw new IllegalArgumentException("jcr:nodetype element expected.");
+        }
+        addNodeTypeNameElement(ntElement.getChildText(XML_NODETYPENAME, NodeTypeConstants.NAMESPACE));
+    }
+
+    private void addNodeTypeNameElement(String nodeTypeName) {
+        if (nodeTypeName != null) {
+        addContent(new Element(XML_NODETYPENAME, NodeTypeConstants.NAMESPACE).setText(nodeTypeName));
+        }
+    }
+
+    public String getNodeTypeName() {
+        return getChildText(XML_NODETYPENAME, NodeTypeConstants.NAMESPACE);
+    }
+    
+    public static NodeTypeElement[] create(NodeType[] nts) {
+        NodeTypeElement[] elems = new NodeTypeElement[nts.length];
+        for (int i = 0; i < nts.length; i++) {
+            elems[i] = new NodeTypeElement(nts[i]);
+        }
+        return elems;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeElement.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeProperty.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeProperty.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeProperty.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeProperty.java Sun Mar  6 06:02:39 2005
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.spi.nodetype;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.property.DavProperty;
+import org.apache.jackrabbit.webdav.property.AbstractDavProperty;
+import org.jdom.Element;
+
+import javax.jcr.nodetype.NodeType;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * <code>NodeTypeProperty</code>...
+ */
+public class NodeTypeProperty extends AbstractDavProperty {
+
+    private static Logger log = Logger.getLogger(NodeTypeProperty.class);
+
+    private final NodeTypeElement[] value;
+
+    public NodeTypeProperty(DavPropertyName name, NodeType nodeType, boolean isProtected) {
+        super(name, isProtected);
+        value = new NodeTypeElement[] {new NodeTypeElement(nodeType)};
+    }
+
+    public NodeTypeProperty(DavPropertyName name, NodeType[] nodeTypes, boolean isProtected) {
+        super(name, isProtected);
+        value = NodeTypeElement.create(nodeTypes);
+    }
+
+    /**
+     * Create a new <code>NodeTypeProperty</code> from the specified general
+     * DavProperty object.
+     *
+     * @param property
+     * @throws IllegalArgumentException if the content of the specified property
+     * contains elements other than {@link NodeTypeConstants#XML_NODETYPE}.
+     */
+    public NodeTypeProperty(DavProperty property) {
+        super(property.getName(), property.isProtected());
+
+        if (property.getValue() instanceof List) {
+            List ntElemList = new ArrayList();
+            Iterator it = ((List) property.getValue()).iterator();
+            while (it.hasNext()) {
+                Object content = it.next();
+                if (content instanceof Element) {
+                    ntElemList.add(new NodeTypeElement((Element)content));
+                }
+            }
+            value = (NodeTypeElement[]) ntElemList.toArray(new NodeTypeElement[ntElemList.size()]);
+        } else {
+            value = new NodeTypeElement[0];
+        }
+    }
+
+    public List getNodeTypeNames() {
+        ArrayList names = new ArrayList();
+        Object val = getValue();
+        if (val instanceof NodeTypeElement[]) {
+            NodeTypeElement[] elems = (NodeTypeElement[])val;
+            for (int i = 0; i < elems.length; i++) {
+                String ntName = elems[i].getNodeTypeName();
+                if (ntName != null) {
+                    names.add(ntName);
+                }
+            }
+        }
+        return names;
+    }
+
+    /**
+     * Returns the value of this property which is an array of {@link NodeTypeElement}
+     * objects.
+     *
+     * @return an array of {@link NodeTypeElement}s
+     */
+    public Object getValue() {
+        return value;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeProperty.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/NodeTypeProperty.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/observation/SubscriptionImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/observation/SubscriptionImpl.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/observation/SubscriptionImpl.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/observation/SubscriptionImpl.java Sun Mar  6 06:02:39 2005
@@ -0,0 +1,316 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.spi.observation;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.DavResourceLocator;
+import org.apache.jackrabbit.webdav.DavConstants;
+import org.apache.jackrabbit.webdav.observation.*;
+import org.apache.jackrabbit.webdav.util.XmlUtil;
+import org.apache.jackrabbit.core.util.uuid.UUID;
+import org.jdom.Element;
+
+import javax.jcr.observation.*;
+import javax.jcr.observation.EventListener;
+import javax.jcr.RepositoryException;
+import java.util.*;
+
+/**
+ * The <code>Subscription</code> class encapsulates a single subscription with
+ * the following responsibilities:<ul>
+ * <li>Providing access to the subscription info,</li>
+ * <li>Recording events this subscription is interested in,</li>
+ * <li>Providing access to the events.</li>
+ * </ul>
+ */
+public class SubscriptionImpl implements Subscription, ObservationConstants, EventListener {
+
+    private static Logger log = Logger.getLogger(SubscriptionImpl.class);
+    private static final long DEFAULT_TIMEOUT = 300000; // 5 minutes
+
+    private SubscriptionInfo info;
+
+    private final DavResourceLocator locator;
+    private final String subscriptionId = UUID.randomUUID().toString();
+    private final List eventBundles = new ArrayList();
+
+    /**
+     * Create a new <code>Subscription</code> with the given {@link SubscriptionInfo}
+     * and {@link org.apache.jackrabbit.webdav.observation.ObservationResource resource}.
+     *
+     * @param info
+     * @param resource
+     */
+    public SubscriptionImpl(SubscriptionInfo info, ObservationResource resource) {
+        setInfo(info);
+        locator = resource.getLocator();
+    }
+
+    /**
+     * Returns the id of this subscription.
+     *
+     * @return subscriptionId
+     */
+    public String getSubscriptionId() {
+        return subscriptionId;
+    }
+
+    /**
+     * Return the Xml representation of this <code>Subscription</code> as required
+     * for the {@link org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery} webdav property that in included
+     * in the response body of a sucessful SUBSCRIBE request or as part of a
+     * PROPFIND response.
+     *
+     * @return Xml representation
+     */
+    public Element toXml() {
+        Element subscr = new Element(XML_SUBSCRIPTION, NAMESPACE);
+        Element[] elems = info.toXml();
+        for (int i = 0; i < elems.length; i++) {
+            subscr.addContent(elems[i]);
+        }
+
+        Element id = new Element(XML_SUBSCRIPTIONID);
+        id.addContent(XmlUtil.hrefToXml(subscriptionId));
+        subscr.addContent(id);
+        return subscr;
+    }
+
+    /**
+     * Modify the {@link SubscriptionInfo} for this subscription.
+     *
+     * @param info
+     */
+    void setInfo(SubscriptionInfo info) {
+        this.info = info;
+        // validate the timeout and adjust value, if it is invalid or missing
+        long timeout = info.getTimeOut();
+        if (timeout == DavConstants.UNDEFINED_TIMEOUT) {
+            info.setTimeOut(DEFAULT_TIMEOUT);
+        }
+    }
+
+    /**
+     * @return JCR compliant integer representation of the event types defined
+     * for this {@link SubscriptionInfo}.
+     */
+    int getEventTypes() {
+        Iterator xmlTypes = info.getEventTypes().iterator();
+        int eventTypes = 0;
+        while (xmlTypes.hasNext()) {
+            eventTypes |= nametoTypeConstant(((Element)xmlTypes.next()).getName());
+        }
+        return eventTypes;
+    }
+
+    /**
+     * @return a String array with size > 0 or <code>null</code>
+     */
+    String[] getUuidFilters() {
+        return info.getFilters(XML_UUID);
+    }
+
+    /**
+     * @return a String array with size > 0 or <code>null</code>
+     */
+    String[] getNodetypeNameFilters() {
+        return info.getFilters(XML_NODETYPE_NAME);
+    }
+
+    /**
+     *
+     * @return true if a {@link ObservationConstants#XML_NOLOCAL} element
+     * is present in the {@link SubscriptionInfo}.
+     */
+    boolean isNoLocal() {
+        return info.isNoLocal();
+    }
+
+    /**
+     * @return true if this subscription is intended to be deep.
+     */
+    boolean isDeep() {
+        return info.isDeep();
+    }
+
+    /**
+     * @return the locator of the {@link ObservationResource resource} this
+     * <code>Subscription</code> was requested for.
+     */
+    DavResourceLocator getLocator() {
+        return locator;
+    }
+
+    /**
+     * Returns true if this <code>Subscription</code> matches the given
+     * resource.
+     *
+     * @param resource
+     * @return true if this <code>Subscription</code> matches the given
+     * resource.
+     */
+    boolean isSubscribedToResource(ObservationResource resource) {
+        return locator.equals(resource.getLocator());
+    }
+
+    /**
+     * Returns true if this <code>Subscription</code> is expired and therefore
+     * stopped recording events.
+     *
+     * @return true if this <code>Subscription</code> is expired
+     */
+    boolean isExpired() {
+        return System.currentTimeMillis() > info.getTimeOut() + System.currentTimeMillis();
+    }
+
+    /**
+     * Returns a {@link org.apache.jackrabbit.webdav.observation.EventDiscovery} object listing all events that were
+     * recorded since the last call to this method and clears the list of event
+     * bundles.
+     *
+     * @return object listing all events that were recorded.
+     * @see #onEvent(EventIterator)
+     */
+    synchronized EventDiscovery discoverEvents() {
+        EventDiscovery ed = new EventDiscovery();
+        Iterator it = eventBundles.iterator();
+        while (it.hasNext()) {
+            EventBundle eb = (EventBundle) it.next();
+            ed.addEventBundle(eb.toXml());
+        }
+        // clear list
+        eventBundles.clear();
+        return ed;
+    }
+
+    //--------------------------------------------< EventListener interface >---
+    /**
+     * Records the events passed as a new event bundle in order to make them
+     * available with the next {@link #discoverEvents()} request.
+     *
+     * @param events to be recorded.
+     * @see EventListener#onEvent(EventIterator)
+     * @see #discoverEvents()
+     */
+    public synchronized void onEvent(EventIterator events) {
+        // TODO: correct not to accept events after expiration? without unsubscribing?
+        if (!isExpired()) {
+            eventBundles.add(new EventBundle(events));
+        }
+    }
+
+    //--------------------------------------------------------------------------
+    /**
+     * Static utility method in order to convert the types defined by
+     * {@link javax.jcr.observation.Event} into their Xml representation.
+     *
+     * @param jcrEventType
+     * @return Xml representation of the event type.
+     */
+    static Element typeConstantToXml(int jcrEventType) {
+        String eventName;
+        switch (jcrEventType) {
+            case Event.NODE_ADDED:
+                eventName = EVENT_NODEADDED;
+                break;
+            case Event.NODE_REMOVED:
+                eventName = EVENT_NODEREMOVED;
+                break;
+            case Event.PROPERTY_ADDED:
+                eventName = EVENT_PROPERTYADDED;
+                break;
+            case Event.PROPERTY_CHANGED:
+                eventName = EVENT_PROPERTYCHANGED;
+                break;
+            default:
+                //Event.PROPERTY_REMOVED:
+                eventName = EVENT_PROPERTYREMOVED;
+                break;
+        }
+        return new Element(eventName, NAMESPACE);
+    }
+
+    /**
+     * Static utility method to convert an event type name as present in the
+     * Xml request body into the corresponding constant defined by
+     * {@link javax.jcr.observation.Event}.
+     *
+     * @param eventTypeName
+     * @return event type as defined by {@link javax.jcr.observation.Event}.
+     * @throws IllegalArgumentException if the given element cannot be translated
+     * to any of the events defined by {@link javax.jcr.observation.Event}.
+     */
+    static int nametoTypeConstant(String eventTypeName) {
+        int eType;
+        if (EVENT_NODEADDED.equals(eventTypeName)) {
+            eType = Event.NODE_ADDED;
+        } else if (EVENT_NODEREMOVED.equals(eventTypeName)) {
+            eType = Event.NODE_REMOVED;
+        } else if (EVENT_PROPERTYADDED.equals(eventTypeName)) {
+            eType = Event.PROPERTY_ADDED;
+        } else if (EVENT_PROPERTYCHANGED.equals(eventTypeName)) {
+            eType = Event.PROPERTY_CHANGED;
+        } else if (EVENT_PROPERTYREMOVED.equals(eventTypeName)) {
+            eType = Event.PROPERTY_REMOVED;
+        } else {
+            throw new IllegalArgumentException("Invalid event type: "+eventTypeName);
+        }
+        return eType;
+    }
+
+    /**
+     * Inner class <code>EventBundle</code> encapsulats an event bundle as
+     * recorded {@link SubscriptionImpl#onEvent(EventIterator) on event} and
+     * provides the possibility to retrieve the Xml representation of the
+     * bundle and the events included in order to respond to a POLL request.
+     *
+     * @see SubscriptionImpl#discoverEvents()
+     */
+    private class EventBundle {
+
+        private final EventIterator events;
+
+        private EventBundle(EventIterator events) {
+            this.events = events;
+        }
+
+        private Element toXml() {
+            Element bundle = new Element(XML_EVENTBUNDLE, NAMESPACE);
+            while (events.hasNext()) {
+                Event event = events.nextEvent();
+
+                Element eventElem = new Element(XML_EVENT, NAMESPACE);
+                // href
+                String eHref = "";
+                try {
+                    boolean isCollection = (event.getType() == Event.NODE_ADDED || event.getType() == Event.NODE_REMOVED);
+                    eHref = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), event.getPath()).getHref(isCollection);
+                } catch (RepositoryException e) {
+                    // should not occur....
+                    log.error(e.getMessage());
+                }
+                eventElem.addContent(XmlUtil.hrefToXml(eHref));
+                // eventtype
+                Element eType = new Element(XML_EVENTTYPE, NAMESPACE).addContent(typeConstantToXml(event.getType()));
+                eventElem.addContent(eType);
+                // user id
+                Element eUserId = new Element(XML_EVENTUSERID, NAMESPACE).setText(event.getUserId());
+                eventElem.addContent(eUserId);
+            }
+            return bundle;
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/observation/SubscriptionImpl.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/observation/SubscriptionImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/observation/SubscriptionManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/observation/SubscriptionManagerImpl.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/observation/SubscriptionManagerImpl.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/observation/SubscriptionManagerImpl.java Sun Mar  6 06:02:39 2005
@@ -0,0 +1,251 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.spi.observation;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.*;
+import org.apache.jackrabbit.webdav.spi.JcrDavException;
+import org.apache.jackrabbit.webdav.observation.*;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.observation.ObservationManager;
+import java.util.*;
+
+/**
+ * <code>SubscriptionManager</code> collects all subscriptions requested, handles
+ * the subscription timeout and provides METHODS to discover subscriptions
+ * present on a given resource as well as events for an specific subscription.
+ *
+ * @todo make sure all expired subscriptions are removed!
+ */
+public class SubscriptionManagerImpl implements SubscriptionManager {
+
+    private static Logger log = Logger.getLogger(SubscriptionManager.class);
+
+    /**
+     * Map containing all {@link org.apache.jackrabbit.webdav.observation.Subscription subscriptions}.
+     */
+    private final SubscriptionMap subscriptions = new SubscriptionMap();
+
+    /**
+     * Retrieve the {@link org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery} object for the given
+     * resource. Note, that the discovery object will be empty if there are
+     * no subscriptions present.
+     *
+     * @param resource
+     * @todo is it correct to return subscriptions made by another session?
+     */
+    public SubscriptionDiscovery getSubscriptionDiscovery(ObservationResource resource) {
+        Subscription[] subsForResource = subscriptions.getByPath(resource.getLocator());
+        return new SubscriptionDiscovery(subsForResource);
+    }
+
+    /**
+     * Create a new <code>Subscription</code> or update an existing <code>Subscription</code>
+     * and add it as eventlistener to the {@link javax.jcr.observation.ObservationManager}.
+     *
+     * @param info
+     * @param subscriptionId
+     * @param resource
+     * @return <code>Subscription</code> that has been added to the {@link javax.jcr.observation.ObservationManager}
+     * @throws DavException if the subscription fails
+     */
+    public Subscription subscribe(SubscriptionInfo info, String subscriptionId,
+                                  ObservationResource resource)
+            throws DavException {
+
+        SubscriptionImpl subscription;
+        DavSession session = resource.getSession();
+        if (subscriptionId == null) {
+            // new subscription
+            subscription = new SubscriptionImpl(info, resource);
+            registerSubscription(subscription, session);
+
+            // ajust references to this subscription
+            subscriptions.put(subscription.getSubscriptionId(), subscription);
+            session.addReference(subscription.getSubscriptionId());
+        } else {
+            // refresh/modify existing one
+            subscription = validate(subscriptionId, resource);
+            subscription.setInfo(info);
+            registerSubscription(subscription, session);
+        }
+        return subscription;
+    }
+
+    /**
+     * Register the event listener defined by the given subscription to the
+     * repository's observation manager.
+     *
+     * @param subscription
+     * @param session
+     * @throws DavException
+     */
+    private void registerSubscription(SubscriptionImpl subscription, DavSession session)
+            throws DavException {
+        try {
+            ObservationManager oMgr = session.getRepositorySession().getWorkspace().getObservationManager();
+            oMgr.addEventListener(subscription, subscription.getEventTypes(),
+                    subscription.getLocator().getResourcePath(), subscription.isDeep(),
+                    subscription.getUuidFilters(),
+                    subscription.getNodetypeNameFilters(),
+                    subscription.isNoLocal());
+        } catch (RepositoryException e) {
+            log.error("Unable to register eventlistener: "+e.getMessage());
+            throw new JcrDavException(e);
+        }
+    }
+
+    /**
+     * Unsubscribe the <code>Subscription</code> with the given id and remove it
+     * from the {@link javax.jcr.observation.ObservationManager} as well as
+     * from the internal map.
+     *
+     * @param subscriptionId
+     * @param resource
+     * @throws DavException
+     */
+    public void unsubscribe(String subscriptionId, ObservationResource resource)
+            throws DavException {
+
+        SubscriptionImpl subs = validate(subscriptionId, resource);
+        unregisterSubscription(subs, resource.getSession());
+    }
+
+    /**
+     * Remove the event listener defined by the specified subscription from
+     * the repository's observation manager.
+     *
+     * @param subscription
+     * @param session
+     * @throws DavException
+     */
+    private void unregisterSubscription(SubscriptionImpl subscription,
+                                        DavSession session) throws DavException {
+        try {
+            session.getRepositorySession().getWorkspace().getObservationManager().removeEventListener(subscription);
+            String sId = subscription.getSubscriptionId();
+
+            // clean up any references
+            subscriptions.remove(sId);
+            session.removeReference(sId);
+
+        } catch (RepositoryException e) {
+            log.error("Unable to remove eventlistener: "+e.getMessage());
+            throw new JcrDavException(e);
+        }
+    }
+
+    /**
+     * Retrieve all event bundles accumulated since for the subscription specified
+     * by the given id.
+     *
+     * @param subscriptionId
+     * @param resource
+     * @return object encapsulating the events.
+     */
+    public EventDiscovery poll(String subscriptionId, ObservationResource resource)
+            throws DavException {
+
+        SubscriptionImpl subs = validate(subscriptionId, resource);
+        return subs.discoverEvents();
+    }
+
+    /**
+     * Validate the given subscription id. The validation will fail under the following
+     * conditions:<ul>
+     * <li>The subscription with the given id does not exist,</li>
+     * <li>DavResource path does not match the subscription id,</li>
+     * <li>The subscription with the given id is already expired.</li>
+     * </ul>
+     *
+     * @param subscriptionId
+     * @param resource
+     * @return <code>Subscription</code> with the given id.
+     * @throws DavException if an error occured while retrieving the <code>Subscription</code>
+     */
+    private SubscriptionImpl validate(String subscriptionId, ObservationResource resource)
+            throws DavException {
+
+        SubscriptionImpl subs;
+        if (subscriptions.contains(subscriptionId)) {
+            subs = (SubscriptionImpl) subscriptions.get(subscriptionId);
+            if (!subs.isSubscribedToResource(resource)) {
+                throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Attempt to operate on subscription with invalid resource path.");
+            }
+            if (subs.isExpired()) {
+                unregisterSubscription(subs, resource.getSession());
+                throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Attempt to  operate on expired subscription.");
+            }
+            return subs;
+        } else {
+            throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Attempt to modify or to poll for non-existing subscription.");
+        }
+    }
+
+    /**
+     * Private inner class <code>SubscriptionMap</code> that allows for quick
+     * access by resource path as well as by subscription id.
+     */
+    private class SubscriptionMap {
+
+        private HashMap subscriptions = new HashMap();
+        private HashMap paths = new HashMap();
+
+        private boolean contains(String subscriptionId) {
+            return subscriptions.containsKey(subscriptionId);
+        }
+
+        private Subscription get(String subscriptionId) {
+            return (Subscription) subscriptions.get(subscriptionId);
+        }
+
+        private void put(String subscriptionId, SubscriptionImpl subscription) {
+            subscriptions.put(subscriptionId, subscription);
+            DavResourceLocator key = subscription.getLocator();
+            Set idSet;
+            if (paths.containsKey(key)) {
+                idSet = (Set) paths.get(key);
+            } else {
+                idSet = new HashSet();
+                paths.put(key, idSet);
+            }
+            if (!idSet.contains(subscriptionId)) {
+                idSet.add(subscriptionId);
+            }
+        }
+
+        private void remove(String subscriptionId) {
+            SubscriptionImpl sub = (SubscriptionImpl) subscriptions.remove(subscriptionId);
+            ((Set)paths.get(sub.getLocator())).remove(subscriptionId);
+        }
+
+        private Subscription[] getByPath(DavResourceLocator locator) {
+            Set idSet = (Set) paths.get(locator);
+            if (idSet != null && !idSet.isEmpty()) {
+                Iterator idIterator = idSet.iterator();
+                Subscription[] subsForResource = new Subscription[idSet.size()];
+                int i = 0;
+                while (idIterator.hasNext()) {
+                    subsForResource[i] = (Subscription) subscriptions.get(idIterator.next());
+                }
+                return subsForResource;
+            } else {
+                return new Subscription[0];
+            }
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/observation/SubscriptionManagerImpl.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/observation/SubscriptionManagerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/package.html?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/package.html Sun Mar  6 06:02:39 2005
@@ -0,0 +1,3 @@
+<body>
+Contains JCR specific implementations.
+</body>
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/search/SearchResourceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/search/SearchResourceImpl.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/search/SearchResourceImpl.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/search/SearchResourceImpl.java Sun Mar  6 06:02:39 2005
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.spi.search;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.*;
+import org.apache.jackrabbit.webdav.search.SearchResource;
+import org.apache.jackrabbit.webdav.search.QueryGrammerSet;
+import org.apache.jackrabbit.webdav.search.SearchRequest;
+import org.apache.jackrabbit.webdav.spi.JcrDavException;
+import org.apache.jackrabbit.webdav.spi.ItemResourceConstants;
+
+import javax.jcr.*;
+import javax.jcr.query.*;
+
+/**
+ * <code>SearchResourceImpl</code>...
+ */
+public class SearchResourceImpl implements SearchResource, ItemResourceConstants {
+
+    private static Logger log = Logger.getLogger(SearchResourceImpl.class);
+
+    private final DavSession session;
+    private final DavResourceLocator locator;
+
+    public SearchResourceImpl(DavResourceLocator locator, DavSession session) {
+        this.session = session;
+        this.locator = locator;
+    }
+
+    //-------------------------------------------< SearchResource interface >---
+    /**
+     * @see SearchResource#getQueryGrammerSet()
+     */
+    public QueryGrammerSet getQueryGrammerSet()  {
+        QueryGrammerSet qgs;
+        try {
+            QueryManager qMgr = session.getRepositorySession().getWorkspace().getQueryManager();
+            String[] langs = qMgr.getSupportedQueryLanguages();
+            qgs = new QueryGrammerSet(langs);
+        } catch (RepositoryException e) {
+            qgs = new QueryGrammerSet(new String[0]);
+        }
+        return qgs;
+    }
+
+    /**
+     * Execute the query defined by the given <code>sRequest</code>.
+     *
+     * @see SearchResource#search(org.apache.jackrabbit.webdav.search.SearchRequest)
+     */
+    public MultiStatus search(SearchRequest sRequest) throws DavException {
+        try {
+            Query q = getQuery(sRequest);
+            QueryResult qR = q.execute();
+            return queryResultToMultiStatus(qR);
+
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+
+    /**
+     * Create a query from the information present in the <code>sRequest</code>
+     * object.<br>The following JCR specific logic is applied:
+     * <ul>
+     * <li>If the requested resource represents a node with nodetype nt:query, the
+     * request body is ignored and the query defined with the node is executed
+     * instead.</li>
+     * <li>If the requested resource does not represent an existing item, the
+     * specified query is persisted by calling {@link Query#save(String)}.</li>
+     * </ul>
+     * @param sRequest defining the query to be executed
+     * @return <code>Query</code> object.
+     * @throws InvalidQueryException if the query defined by <code>sRequest</code> is invalid
+     * @throws RepositoryException the query manager cannot be accessed or if
+     * another error occurs.
+     * @throws DavException if <code>sRequest</code> is <code>null</code> and
+     * the underlaying repository item is not an nt:query node or if an error
+     * occurs when calling {@link Query#save(String)}/
+     */
+    private Query getQuery(SearchRequest sRequest)
+            throws InvalidQueryException, RepositoryException, DavException {
+
+        Node rootNode = session.getRepositorySession().getRootNode();
+        QueryManager qMgr = session.getRepositorySession().getWorkspace().getQueryManager();
+        String resourcePath = locator.getResourcePath();
+
+        // test if query is defined by requested repository node
+        if (!rootNode.getPath().equals(resourcePath)) {
+            String qNodeRelPath = resourcePath.substring(1);
+            if (rootNode.hasNode(qNodeRelPath)) {
+                Node qNode = rootNode.getNode(qNodeRelPath);
+                if (qNode.isNodeType("nt:query")) {
+                    return qMgr.getQuery(qNode);
+                }
+            }
+        }
+
+        Query q;
+        if (sRequest != null) {
+            q = qMgr.createQuery(sRequest.getQuery(), sRequest.getLanguageName());
+        } else {
+            throw new DavException(DavServletResponse.SC_BAD_REQUEST, resourcePath + " is not a nt:query node -> searchRequest body required.");
+        }
+
+        /* test if resource path does not exist -> thus indicating that
+        the query must be made persistent by calling Query.save(String) */
+        if (!session.getRepositorySession().itemExists(resourcePath)) {
+            try {
+                q.save(resourcePath);
+            } catch (RepositoryException e) {
+                // ItemExistsException should never occur.
+                new JcrDavException(e);
+            }
+        }
+        return q;
+    }
+
+    /**
+     * Build a <code>MultiStatus</code> object from the specified query result.
+     *
+     * @param qResult <code>QueryResult</code> as obtained from {@link javax.jcr.query.Query#execute()}.
+     * @return <code>MultiStatus</code> object listing the query result in
+     * Webdav compatible form.
+     * @throws RepositoryException
+     */
+    private MultiStatus queryResultToMultiStatus(QueryResult qResult)
+            throws RepositoryException {
+        MultiStatus ms = new MultiStatus();
+
+        String[] propertyNames = qResult.getPropertyNames();
+        RowIterator rowIter = qResult.getRows();
+        while (rowIter.hasNext()) {
+            Row row = rowIter.nextRow();
+            Value[] values = row.getValues();
+            String nodePath = values[0].getString();
+
+            // create a new ms-response for each row of the result set 
+            DavResourceLocator loc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), nodePath);
+            String nodeHref = loc.getHref(true);
+            MultiStatusResponse resp = new MultiStatusResponse(nodeHref);
+            // add a search-result-property for each value column
+            for (int i = 0; i < values.length; i++) {
+                resp.add(new SearchResultProperty(propertyNames[i], values[i]));
+            }
+            ms.addResponse(resp);
+        }
+        return ms;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/search/SearchResourceImpl.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/search/SearchResourceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/search/SearchResultProperty.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/search/SearchResultProperty.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/search/SearchResultProperty.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/search/SearchResultProperty.java Sun Mar  6 06:02:39 2005
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.spi.search;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
+import org.apache.jackrabbit.webdav.spi.ItemResourceConstants;
+import org.jdom.Element;
+
+import javax.jcr.Value;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>SearchResultProperty</code>...
+ */
+public class SearchResultProperty extends DefaultDavProperty {
+
+    private static Logger log = Logger.getLogger(SearchResultProperty.class);
+
+    public static final DavPropertyName SEARCH_RESULT_PROPERTY = DavPropertyName.create("search-result-property", ItemResourceConstants.NAMESPACE);
+
+    private final String propertyName;
+
+    /**
+     * Creates a new WebDAV property with the given namespace, name and value.
+     * If the property is intended to be protected the isProtected flag must
+     * be set to true.
+     *
+     * @param propertyName JCR property name
+     * @param value String representation of the property
+     */
+    public SearchResultProperty(String propertyName, Value value) {
+        super(SEARCH_RESULT_PROPERTY, value, true);
+        this.propertyName = propertyName;
+    }
+
+    /**
+     * Return the Xml representation.
+     * <pre>
+     *
+     * new SearchResultProperty("bli", new StringValue("blivalue")).toXml()
+     *
+     * returns an element with the following form:
+     *
+     * &lt;jcr:search-result-property&gt;
+     *    &lt;jcr:name&gt;bli&lt;jcr:name/&gt;
+     *    &lt;jcr:value&gt;blivalue&lt;jcr:value/&gt;
+     * &lt;/jcr:search-result-property&gt;
+     * </pre>
+     *
+     * @return the Xml representation
+     * @see org.apache.jackrabbit.webdav.property.DavProperty#toXml()
+     */
+    public Element toXml() {
+	Element elem = getName().toXml();
+        elem.addContent(ItemResourceConstants.JCR_NAME.toXml().setText(propertyName));
+        String valueStr = "";
+        if (getValue() != null) {
+            Value value = (Value) getValue();
+            try {
+                valueStr = value.getString();
+            } catch (RepositoryException e) {
+                log.error(e.getMessage());
+            }
+        }
+        elem.addContent(ItemResourceConstants.JCR_VALUE.toXml().setText(valueStr));
+	return elem;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/search/SearchResultProperty.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/spi/search/SearchResultProperty.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message