jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1155296 [1/2] - in /jackrabbit/trunk: jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/property/ jackrabbit-jcr-server/src/main/java/org/apache/jackr...
Date Tue, 09 Aug 2011 10:14:51 GMT
Author: angela
Date: Tue Aug  9 10:14:50 2011
New Revision: 1155296

URL: http://svn.apache.org/viewvc?rev=1155296&view=rev
Log:
JCR-2946 - Improve implementation of DavResource#getProperty(DavPropertyName)
JCR-2948 - Add possibility to PROPFIND the JCR_NODETYPES_CND_LN property

Added:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/property/JcrDavPropertyNameSet.java   (with props)
    jackrabbit/trunk/jackrabbit-spi2dav/src/test/java/org/apache/jackrabbit/spi2dav/DavPropertyTest.java   (with props)
Modified:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractItemResource.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/VersionControlledItemCollection.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/WorkspaceResourceImpl.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/DavResource.java
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/MultiStatusResponse.java

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractItemResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractItemResource.java?rev=1155296&r1=1155295&r2=1155296&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractItemResource.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractItemResource.java Tue Aug  9 10:14:50 2011
@@ -24,12 +24,13 @@ import org.apache.jackrabbit.webdav.DavR
 import org.apache.jackrabbit.webdav.DavServletResponse;
 import org.apache.jackrabbit.webdav.DavCompliance;
 import org.apache.jackrabbit.webdav.io.OutputContext;
+import org.apache.jackrabbit.webdav.jcr.property.JcrDavPropertyNameSet;
+import org.apache.jackrabbit.webdav.observation.ObservationConstants;
 import org.apache.jackrabbit.webdav.observation.ObservationResource;
 import org.apache.jackrabbit.webdav.observation.SubscriptionManager;
 import org.apache.jackrabbit.webdav.observation.Subscription;
 import org.apache.jackrabbit.webdav.observation.SubscriptionInfo;
 import org.apache.jackrabbit.webdav.observation.EventDiscovery;
-import org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery;
 import org.apache.jackrabbit.webdav.jcr.nodetype.ItemDefinitionImpl;
 import org.apache.jackrabbit.webdav.jcr.nodetype.NodeDefinitionImpl;
 import org.apache.jackrabbit.webdav.jcr.nodetype.PropertyDefinitionImpl;
@@ -39,6 +40,7 @@ import org.apache.jackrabbit.webdav.prop
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
 import org.apache.jackrabbit.webdav.security.CurrentUserPrivilegeSetProperty;
 import org.apache.jackrabbit.webdav.security.Privilege;
+import org.apache.jackrabbit.webdav.security.SecurityConstants;
 import org.apache.jackrabbit.webdav.transaction.TxLockEntry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -71,6 +73,8 @@ abstract class AbstractItemResource exte
      *
      * @param locator
      * @param session
+     * @param factory
+     * @param item
      */
     AbstractItemResource(DavResourceLocator locator, JcrDavSession session,
                          DavResourceFactory factory, Item item) {
@@ -96,6 +100,67 @@ abstract class AbstractItemResource exte
         );
     }
 
+    @Override
+    public DavProperty<?> getProperty(DavPropertyName name) {
+        DavProperty prop = super.getProperty(name);
+        if (prop == null) {
+            if (JCR_DEFINITION.equals(name)) {
+                if (exists()) {
+                    try {
+
+                        // protected 'definition' property revealing the item definition
+                        ItemDefinitionImpl val;
+                        if (item.isNode()) {
+                            val = NodeDefinitionImpl.create(((Node)item).getDefinition());
+                        } else {
+                            val = PropertyDefinitionImpl.create(((Property)item).getDefinition());
+                        }
+                        prop = new DefaultDavProperty<ItemDefinitionImpl>(JCR_DEFINITION, val, true);
+                    } catch (RepositoryException e) {
+                        // should not get here
+                        log.error("Error while accessing item definition: " + e.getMessage());
+                    }
+                }
+            } else if (JCR_ISNEW.equals(name)) {
+                // transaction resource additional protected properties
+                if (exists() && item.isNew()) {
+                    prop = new DefaultDavProperty<String>(JCR_ISNEW, null, true);
+                }
+            } else if (JCR_ISMODIFIED.equals(name)) {
+                // transaction resource additional protected properties
+                if (exists() && item.isModified()) {
+                    prop = new DefaultDavProperty<String>(JCR_ISMODIFIED, null, true);
+                }
+            } else if (ObservationConstants.SUBSCRIPTIONDISCOVERY.equals(name)) {
+                // observation resource
+                prop = subsMgr.getSubscriptionDiscovery(this);
+            } else if (SecurityConstants.CURRENT_USER_PRIVILEGE_SET.equals(name)) {
+                // TODO complete set of properties defined by RFC 3744
+                Privilege[] allPrivs = new Privilege[] {PRIVILEGE_JCR_READ,
+                        PRIVILEGE_JCR_ADD_NODE,
+                        PRIVILEGE_JCR_SET_PROPERTY,
+                        PRIVILEGE_JCR_REMOVE};
+                List<Privilege> currentPrivs = new ArrayList<Privilege>();
+                for (Privilege priv : allPrivs) {
+                    try {
+                        String path = getLocator().getRepositoryPath();
+                        getRepositorySession().checkPermission(path, priv.getName());
+                        currentPrivs.add(priv);
+                    } catch (AccessControlException e) {
+                        // ignore
+                        log.debug(e.toString());
+                    } catch (RepositoryException e) {
+                        // ignore
+                        log.debug(e.toString());
+                    }
+                }
+                prop =  new CurrentUserPrivilegeSetProperty(currentPrivs.toArray(new Privilege[currentPrivs.size()]));
+            }
+        }
+
+        return prop;
+    }
+
     /**
      * @see org.apache.jackrabbit.webdav.DavResource#getSupportedMethods()
      */
@@ -117,7 +182,7 @@ abstract class AbstractItemResource exte
      * Retrieves the last segment of the item path (or the resource path if
      * this resource does not exist). An item path is in addition first translated
      * to the corresponding resource path.<br>
-     * NOTE: the displayname is not equivalent to {@link Item#getName() item name}
+     * NOTE: the display name is not equivalent to {@link Item#getName() item name}
      * which is exposed with the {@link ItemResourceConstants#JCR_NAME
      * &#123;http://www.day.com/jcr/webdav/1.0&#125;name} property.
      *
@@ -322,6 +387,28 @@ abstract class AbstractItemResource exte
         }
     }
 
+    @Override
+    protected void initPropertyNames() {
+        super.initPropertyNames();
+        if (exists()) {
+            names.addAll(JcrDavPropertyNameSet.EXISTING_ITEM_BASE_SET);
+            try {
+                if (item.getDepth() > 0) {
+                    names.add(JCR_PARENT);
+                }
+            } catch (RepositoryException e) {
+                log.warn("Error while accessing node depth: " + e.getMessage());
+            }
+            if (item.isNew()) {
+                names.add(JCR_ISNEW);
+            } else if (item.isModified()) {
+                names.add(JCR_ISMODIFIED);
+            }
+        } else {
+            names.addAll(JcrDavPropertyNameSet.ITEM_BASE_SET);
+        }
+    }
+
     /**
      * Fill the property set for this resource.
      */
@@ -332,57 +419,18 @@ abstract class AbstractItemResource exte
             try {
                 properties.add(new DefaultDavProperty<String>(JCR_NAME, item.getName()));
                 properties.add(new DefaultDavProperty<String>(JCR_PATH, item.getPath()));
-                properties.add(new DefaultDavProperty<String>(JCR_DEPTH, String.valueOf(item.getDepth())));
+                int depth = item.getDepth();
+                properties.add(new DefaultDavProperty<String>(JCR_DEPTH, String.valueOf(depth)));
                 // add href-property for the items parent unless its the root item
-                if (item.getDepth() > 0) {
+                if (depth > 0) {
                     String parentHref = getLocatorFromItem(item.getParent()).getHref(true);
                     properties.add(new HrefProperty(JCR_PARENT, parentHref, false));
                 }
-                // protected 'definition' property revealing the item definition
-                ItemDefinitionImpl val;
-                if (item.isNode()) {
-                    val = NodeDefinitionImpl.create(((Node)item).getDefinition());
-                } else {
-                    val = PropertyDefinitionImpl.create(((Property)item).getDefinition());
-                }
-                properties.add(new DefaultDavProperty<ItemDefinitionImpl>(JCR_DEFINITION, val, true));
             } catch (RepositoryException e) {
                 // should not get here
                 log.error("Error while accessing jcr properties: " + e.getMessage());
             }
-
-            // transaction resource additional protected properties
-            if (item.isNew()) {
-                properties.add(new DefaultDavProperty<String>(JCR_ISNEW, null, true));
-            } else if (item.isModified()) {
-                properties.add(new DefaultDavProperty<String>(JCR_ISMODIFIED, null, true));
-            }
-        }
-
-        // observation resource
-        SubscriptionDiscovery subsDiscovery = subsMgr.getSubscriptionDiscovery(this);
-        properties.add(subsDiscovery);
-
-        // TODO complete set of properties defined by RFC 3744
-        Privilege[] allPrivs = new Privilege[] {PRIVILEGE_JCR_READ,
-                                                PRIVILEGE_JCR_ADD_NODE,
-                                                PRIVILEGE_JCR_SET_PROPERTY,
-                                                PRIVILEGE_JCR_REMOVE};
-        List<Privilege> currentPrivs = new ArrayList<Privilege>();
-        for (Privilege priv : allPrivs) {
-            try {
-                String path = getLocator().getRepositoryPath();
-                getRepositorySession().checkPermission(path, priv.getName());
-                currentPrivs.add(priv);
-            } catch (AccessControlException e) {
-                // ignore
-                log.debug(e.toString());
-            } catch (RepositoryException e) {
-                // ignore
-                log.debug(e.toString());
-            }
         }
-        properties.add(new CurrentUserPrivilegeSetProperty(currentPrivs.toArray(new Privilege[currentPrivs.size()])));
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java?rev=1155296&r1=1155295&r2=1155296&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java Tue Aug  9 10:14:50 2011
@@ -27,6 +27,7 @@ import org.apache.jackrabbit.webdav.DavS
 import org.apache.jackrabbit.webdav.MultiStatus;
 import org.apache.jackrabbit.webdav.MultiStatusResponse;
 import org.apache.jackrabbit.webdav.DavCompliance;
+import org.apache.jackrabbit.webdav.jcr.property.JcrDavPropertyNameSet;
 import org.apache.jackrabbit.webdav.util.HttpDateFormat;
 import org.apache.jackrabbit.webdav.jcr.search.SearchResourceImpl;
 import org.apache.jackrabbit.webdav.jcr.transaction.TxLockManagerImpl;
@@ -111,6 +112,7 @@ abstract class AbstractResource implemen
 
     protected boolean initedProps;
     protected DavPropertySet properties = new DavPropertySet();
+    protected DavPropertyNameSet names;
     protected SupportedLock supportedLock = new SupportedLock();
     protected SupportedReportSetProperty supportedReports = new SupportedReportSetProperty();
 
@@ -119,6 +121,7 @@ abstract class AbstractResource implemen
      *
      * @param locator
      * @param session
+     * @param factory
      */
     AbstractResource(DavResourceLocator locator, JcrDavSession session,
                      DavResourceFactory factory) {
@@ -179,14 +182,37 @@ abstract class AbstractResource implemen
      * @see org.apache.jackrabbit.webdav.DavResource#getPropertyNames()
      */
     public DavPropertyName[] getPropertyNames() {
-        return getProperties().getPropertyNames();
+        initPropertyNames();
+        return names.getContent().toArray(new DavPropertyName[names.getContentSize()]);
     }
 
     /**
      * @see org.apache.jackrabbit.webdav.DavResource#getProperty(org.apache.jackrabbit.webdav.property.DavPropertyName)
      */
     public DavProperty<?> getProperty(DavPropertyName name) {
-        return getProperties().get(name);
+        DavProperty prop = getProperties().get(name);
+        if (prop == null) {
+            if (DeltaVConstants.SUPPORTED_METHOD_SET.equals(name)) {
+                prop = new SupportedMethodSetProperty(getSupportedMethods().split(",\\s"));
+            } else if (DeltaVConstants.SUPPORTED_REPORT_SET.equals(name)) {
+                prop = supportedReports;
+            } else if (DeltaVConstants.CREATOR_DISPLAYNAME.equals(name)) {
+                // DAV:creator-displayname default value : not available
+                prop = new DefaultDavProperty<String>(DeltaVConstants.CREATOR_DISPLAYNAME, getCreatorDisplayName(), true);
+            } else if (DeltaVConstants.COMMENT.equals(name)) {
+                // DAV:comment not value available from jcr
+                prop = new DefaultDavProperty<String>(DeltaVConstants.COMMENT, null, true);
+            } else if (DeltaVConstants.WORKSPACE.equals(name)) {
+                // 'workspace' property as defined by RFC 3253
+                String workspaceHref = getWorkspaceHref();
+                if (workspaceHref != null) {
+                    prop = new HrefProperty(DeltaVConstants.WORKSPACE, workspaceHref, true);
+                }
+            }
+        }
+
+        // TODO: required supported-live-property-set  
+        return prop;
     }
 
     /**
@@ -446,7 +472,7 @@ abstract class AbstractResource implemen
             Report report = ReportType.getType(reportInfo).createReport(this, reportInfo);
             return report;
         } else {
-            throw new DavException(DavServletResponse.SC_UNPROCESSABLE_ENTITY, "Unkown report "+ reportInfo.getReportName() +"requested.");
+            throw new DavException(DavServletResponse.SC_UNPROCESSABLE_ENTITY, "Unknown report "+ reportInfo.getReportName() +"requested.");
         }
     }
 
@@ -536,6 +562,13 @@ abstract class AbstractResource implemen
 
     //--------------------------------------------------------------------------
     /**
+     * Property names common to all resources.
+     */
+    protected void initPropertyNames() {
+        names = new DavPropertyNameSet(JcrDavPropertyNameSet.BASE_SET);
+    }
+
+    /**
      * Fill the set of default properties
      */
     protected void initProperties() {
@@ -558,7 +591,7 @@ abstract class AbstractResource implemen
         properties.add(new DefaultDavProperty<String>(DavPropertyName.GETLASTMODIFIED, lastModified));
 
         // default creation time
-        properties.add(new DefaultDavProperty<String>(DavPropertyName.CREATIONDATE, HttpDateFormat.creationDateFormat().format(new Date(0))));
+        properties.add(new DefaultDavProperty<String>(DavPropertyName.CREATIONDATE, getCreationDate()));
 
         // supported lock property
         properties.add(supportedLock);
@@ -567,31 +600,16 @@ abstract class AbstractResource implemen
         // an empty xlockdiscovery will be returned in the response.
         properties.add(new LockDiscovery(getLocks()));
 
-        properties.add(new SupportedMethodSetProperty(getSupportedMethods().split(",\\s")));
-
-        // DeltaV properties
-        properties.add(supportedReports);
-        // DAV:creator-displayname default value : not available
-        properties.add(new DefaultDavProperty<String>(DeltaVConstants.CREATOR_DISPLAYNAME, null, true));
-        // DAV:comment not value available from jcr
-        properties.add(new DefaultDavProperty<String>(DeltaVConstants.COMMENT, null, true));
-
-        // 'workspace' property as defined by RFC 3253
-        String workspaceHref = getWorkspaceHref();
-        if (workspaceHref != null) {
-            properties.add(new HrefProperty(DeltaVConstants.WORKSPACE, workspaceHref, true));
-        }
         // name of the jcr workspace
         properties.add(new DefaultDavProperty<String>(ItemResourceConstants.JCR_WORKSPACE_NAME,
                 getRepositorySession().getWorkspace().getName()));
-
-        // TODO: required supported-live-property-set
     }
 
     /**
      * Create a new <code>DavResource</code> from the given locator.
      * @param loc
      * @return new <code>DavResource</code>
+     * @throws org.apache.jackrabbit.webdav.DavException
      */
     protected DavResource createResourceFromLocator(DavResourceLocator loc)
             throws DavException {
@@ -680,6 +698,26 @@ abstract class AbstractResource implemen
      */
     abstract protected String getWorkspaceHref();
 
+    /**
+     * Returns the display name of the creator which is used for the protected
+     * {@link DeltaVConstants#CREATOR_DISPLAYNAME} property.
+     *
+     * @return always <code>null</code>; subclasses may provide a regular value.
+     */
+    protected String getCreatorDisplayName() {
+        return null;
+    }
+
+    /**
+     * Returns the creation date which is used for the
+     * {@link DavPropertyName#CREATIONDATE} property.
+     *
+     * @return a dummy date; subclasses may provide a reasonable value.
+     */
+    protected String getCreationDate() {
+        return HttpDateFormat.creationDateFormat().format(new Date(0));
+    }
+
     //--------------------------------------------------------------------------
     /**
      * Register the specified event listener with the observation manager present

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java?rev=1155296&r1=1155295&r2=1155296&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java Tue Aug  9 10:14:50 2011
@@ -61,7 +61,7 @@ import org.apache.jackrabbit.webdav.DavR
 import org.apache.jackrabbit.webdav.DavResourceLocator;
 import org.apache.jackrabbit.webdav.DavServletResponse;
 import org.apache.jackrabbit.webdav.MultiStatusResponse;
-import org.apache.jackrabbit.webdav.version.DeltaVConstants;
+import org.apache.jackrabbit.webdav.jcr.property.JcrDavPropertyNameSet;
 import org.apache.jackrabbit.webdav.util.HttpDateFormat;
 import org.apache.jackrabbit.webdav.io.InputContext;
 import org.apache.jackrabbit.webdav.io.OutputContext;
@@ -105,6 +105,8 @@ public class DefaultItemCollection exten
      *
      * @param locator
      * @param session
+     * @param factory
+     * @param item
      */
     protected DefaultItemCollection(DavResourceLocator locator,
                                     JcrDavSession session,
@@ -199,6 +201,42 @@ public class DefaultItemCollection exten
         }
     }
 
+    @Override
+    public DavProperty<?> getProperty(DavPropertyName name) {
+        DavProperty prop = super.getProperty(name);
+
+        if (prop == null && exists()) {
+            Node n = (Node) item;
+
+            // add node-specific resource properties
+            try {
+                if (JCR_INDEX.equals(name)) {
+                    prop = new DefaultDavProperty<Integer>(JCR_INDEX, n.getIndex(), true);
+                } else if (JCR_REFERENCES.equals(name)) {
+                    prop = getHrefProperty(JCR_REFERENCES, n.getReferences(), true);
+                } else if (JCR_WEAK_REFERENCES.equals(name)) {
+                    prop = getHrefProperty(JCR_WEAK_REFERENCES, n.getWeakReferences(), true);
+                } else if (JCR_UUID.equals(name)) {
+                    if (isReferenceable()) {
+                        prop = new DefaultDavProperty<String>(JCR_UUID, n.getUUID(), true);
+                    }
+                } else if (JCR_PRIMARYITEM.equals(name)) {
+                    if (hasPrimaryItem()) {
+                        Item primaryItem = n.getPrimaryItem();
+                        prop = getHrefProperty(JCR_PRIMARYITEM, new Item[] {primaryItem}, true);
+                    }
+                } else if (OrderingConstants.ORDERING_TYPE.equals(name) && isOrderable()) {
+                    // property defined by RFC 3648: this resource always has custom ordering!                    
+                    prop = new OrderingType(OrderingConstants.ORDERING_TYPE_CUSTOM);
+                }
+            } catch (RepositoryException e) {
+                log.error("Failed to retrieve node-specific property: " + e);
+            }          
+        }
+
+        return prop;
+    }
+
     /**
      * This implementation of the <code>DavResource</code> does only allow
      * to set the mixinnodetypes property. Please note that the existing list of
@@ -878,6 +916,25 @@ public class DefaultItemCollection exten
         }
     }
 
+    @Override
+    protected void initPropertyNames() {
+        super.initPropertyNames();
+
+        if (exists()) {
+            names.addAll(JcrDavPropertyNameSet.NODE_SET);
+            
+            if (isReferenceable()) {
+                names.add(JCR_UUID);
+            }
+            if (hasPrimaryItem()) {
+                names.add(JCR_PRIMARYITEM);
+            }
+            if (isOrderable()) {
+                names.add(OrderingConstants.ORDERING_TYPE);
+            }
+        }
+    }
+                                              
     /**
      * Fill the property set for this resource.
      */
@@ -888,49 +945,64 @@ public class DefaultItemCollection exten
             // resource is serialized as system-view (xml)
             properties.add(new DefaultDavProperty<String>(DavPropertyName.GETCONTENTTYPE, "text/xml"));
             Node n = (Node)item;
-            // overwrite the default creation date and creator-displayname if possible
-            try {
-                if (n.hasProperty(JcrConstants.JCR_CREATED)) {
-                    long creationTime = n.getProperty(JcrConstants.JCR_CREATED).getValue().getLong();
-                    properties.add(new DefaultDavProperty<String>(DavPropertyName.CREATIONDATE,
-                        HttpDateFormat.creationDateFormat().format(new Date(creationTime))));
-                }
-                // DAV:creator-displayname -> use jcr:createBy if present.
-                if (n.hasProperty(Property.JCR_CREATED_BY)) {
-                    String createdBy = n.getProperty(Property.JCR_CREATED_BY).getString();
-                    properties.add(new DefaultDavProperty<String>(DeltaVConstants.CREATOR_DISPLAYNAME, createdBy, true));
-                }
-            } catch (RepositoryException e) {
-                log.warn("Error while accessing jcr:created or jcr:createdBy property");
-            }
 
             // add node-specific resource properties
             try {
                 properties.add(new NodeTypeProperty(JCR_PRIMARYNODETYPE, n.getPrimaryNodeType(), false));
                 properties.add(new NodeTypeProperty(JCR_MIXINNODETYPES, n.getMixinNodeTypes(), false));
-                properties.add(new DefaultDavProperty<Integer>(JCR_INDEX, n.getIndex(), true));
-                addHrefProperty(JCR_REFERENCES, n.getReferences(), true);
-                addHrefProperty(JCR_WEAK_REFERENCES, n.getWeakReferences(), true);
-                if (n.isNodeType(JcrConstants.MIX_REFERENCEABLE)) {
-                    properties.add(new DefaultDavProperty<String>(JCR_UUID, n.getUUID(), true));
-                }
             } catch (RepositoryException e) {
                 log.error("Failed to retrieve node-specific property: " + e);
             }
-            try {
-                Item primaryItem = n.getPrimaryItem();
-                addHrefProperty(JCR_PRIMARYITEM, new Item[] {primaryItem}, true);
-            } catch (ItemNotFoundException e) {
-                log.debug("No primary item present on this node '" + getResourcePath() + "'");
-            } catch (RepositoryException e) {
-                log.error("Error while retrieving primary item: " + e.getMessage());
+        }
+    }  
+
+    @Override
+    protected String getCreatorDisplayName() {
+        // overwrite the default creation date and creator-displayname if possible
+        try {
+            // DAV:creator-displayname -> use jcr:createBy if present.
+            if (exists() && ((Node) item).hasProperty(Property.JCR_CREATED_BY)) {
+                return ((Node) item).getProperty(Property.JCR_CREATED_BY).getString();
             }
+        } catch (RepositoryException e) {
+            log.warn("Error while accessing jcr:createdBy property");
+        }
 
-            // property defined by RFC 3648: this resource always has custom ordering!
-            if (isOrderable()) {
-                properties.add(new OrderingType(OrderingConstants.ORDERING_TYPE_CUSTOM));
+        // fallback
+        return super.getCreatorDisplayName();
+    }
+
+    @Override
+    protected String getCreationDate() {
+        // overwrite the default creation date and creator-displayname if possible
+        try {
+            if (exists() && ((Node) item).hasProperty(JcrConstants.JCR_CREATED)) {
+                long creationTime = ((Node) item).getProperty(JcrConstants.JCR_CREATED).getValue().getLong();
+                return HttpDateFormat.creationDateFormat().format(new Date(creationTime));
             }
+        } catch (RepositoryException e) {
+            log.warn("Error while accessing jcr:created property");
         }
+
+        // fallback
+        return super.getCreationDate();
+    }
+
+    /**
+     * Creates a new HrefProperty with the specified name using the given
+     * array of items as value.
+     * 
+     * @param name
+     * @param values
+     * @param isProtected
+     * @return
+     */
+    protected HrefProperty getHrefProperty(DavPropertyName name, Item[] values, boolean isProtected) {
+        String[] pHref = new String[values.length];
+        for (int i = 0; i < values.length; i++) {
+            pHref[i] = getLocatorFromItem(values[i]).getHref(true);
+        }
+        return new HrefProperty(name, pHref, isProtected);
     }
 
     /**
@@ -943,19 +1015,31 @@ public class DefaultItemCollection exten
      * @param isProtected
      */
     protected void addHrefProperty(DavPropertyName name, Item[] values, boolean isProtected) {
-        if (values == null) {
-            return;
-        }
-        String[] pHref = new String[values.length];
-        for (int i = 0; i < values.length; i++) {
-            pHref[i] = getLocatorFromItem(values[i]).getHref(true);
+        properties.add(getHrefProperty(name, values, isProtected));
+    }
+
+    /**
+     * Creates a new {@link HrefProperty href property} to the property set, where
+     * all properties present in the specified iterator are referenced in the
+     * resulting property.
+     * 
+     * @param name
+     * @param itemIterator
+     * @param isProtected
+     * @return
+     */
+    protected HrefProperty getHrefProperty(DavPropertyName name, PropertyIterator itemIterator,
+                                           boolean isProtected) {
+        ArrayList<Property> l = new ArrayList<Property>();
+        while (itemIterator.hasNext()) {
+            l.add(itemIterator.nextProperty());
         }
-        properties.add(new HrefProperty(name, pHref, isProtected));
+        return getHrefProperty(name, l.toArray(new Property[l.size()]), isProtected);
     }
 
     /**
      * Add a new {@link HrefProperty href property} to the property set, where
-     * all properties present in the specifed iterator are referenced in the
+     * all properties present in the specified iterator are referenced in the
      * resulting property.
      *
      * @param name
@@ -965,29 +1049,39 @@ public class DefaultItemCollection exten
      */
     protected void addHrefProperty(DavPropertyName name, PropertyIterator itemIterator,
                                    boolean isProtected) {
-        ArrayList<Property> l = new ArrayList<Property>();
-        while (itemIterator.hasNext()) {
-            l.add(itemIterator.nextProperty());
-        }
-        addHrefProperty(name, l.toArray(new Property[l.size()]), isProtected);
+        properties.add(getHrefProperty(name, itemIterator, isProtected));
     }
 
     /**
      * Add a new {@link HrefProperty href property} to the property set, where
-     * all versions present in the specifed iterator are referenced in the
+     * all versions present in the specified iterator are referenced in the
      * resulting property.
      *
      * @param name
      * @param itemIterator
      * @param isProtected
      */
-    protected void addHrefProperty(DavPropertyName name, VersionIterator itemIterator,
+    protected HrefProperty getHrefProperty(DavPropertyName name, VersionIterator itemIterator,
                                    boolean isProtected) {
         ArrayList<Version> l = new ArrayList<Version>();
         while (itemIterator.hasNext()) {
             l.add(itemIterator.nextVersion());
         }
-        addHrefProperty(name, l.toArray(new Version[l.size()]), isProtected);
+        return getHrefProperty(name, l.toArray(new Version[l.size()]), isProtected);
+    }
+
+    /**
+     * Add a new {@link HrefProperty href property} to the property set, where
+     * all versions present in the specified iterator are referenced in the
+     * resulting property.
+     *
+     * @param name
+     * @param itemIterator
+     * @param isProtected
+     */
+    protected void addHrefProperty(DavPropertyName name, VersionIterator itemIterator,
+                                   boolean isProtected) {
+        properties.add(getHrefProperty(name, itemIterator, isProtected));
     }
 
     /**
@@ -1019,4 +1113,22 @@ public class DefaultItemCollection exten
         // cannot parse request body into a 'values' property
         return null;
     }
+
+    private boolean hasPrimaryItem() {
+        try {
+            return exists() && ((Node) item).getPrimaryNodeType().getPrimaryItemName() != null;
+        } catch (RepositoryException e) {
+            log.warn(e.getMessage());
+        }
+        return false;
+    }
+    
+    private boolean isReferenceable() {
+        try {
+            return exists() && ((Node) item).isNodeType(JcrConstants.MIX_REFERENCEABLE);
+        } catch (RepositoryException e) {
+            log.warn(e.getMessage());
+        }
+        return false;
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java?rev=1155296&r1=1155295&r2=1155296&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java Tue Aug  9 10:14:50 2011
@@ -28,6 +28,7 @@ import org.apache.jackrabbit.webdav.DavS
 import org.apache.jackrabbit.webdav.MultiStatusResponse;
 import org.apache.jackrabbit.webdav.io.InputContext;
 import org.apache.jackrabbit.webdav.io.OutputContext;
+import org.apache.jackrabbit.webdav.jcr.property.JcrDavPropertyNameSet;
 import org.apache.jackrabbit.webdav.jcr.property.LengthsProperty;
 import org.apache.jackrabbit.webdav.jcr.property.ValuesProperty;
 import org.apache.jackrabbit.webdav.lock.ActiveLock;
@@ -35,6 +36,7 @@ import org.apache.jackrabbit.webdav.lock
 import org.apache.jackrabbit.webdav.lock.Type;
 import org.apache.jackrabbit.webdav.property.DavProperty;
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
 import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
 import org.apache.jackrabbit.webdav.property.PropEntry;
 import org.apache.jackrabbit.webdav.xml.DomUtil;
@@ -109,7 +111,7 @@ public class DefaultItemResource extends
 
     /**
      * In case an underlying repository {@link Property property} exists the following
-     * logic is applyed to spool the property content:
+     * logic is applied to spool the property content:
      * <ul>
      * <li>Property is not multi valued: Return the {@link javax.jcr.Value#getStream()
      * stream representation} of the property value.</li>
@@ -175,6 +177,27 @@ public class DefaultItemResource extends
         }
     }
 
+    @Override
+    public DavProperty<?> getProperty(DavPropertyName name) {
+        DavProperty prop = super.getProperty(name);
+
+        if (prop == null && exists()) {
+            try {
+                Property p = (Property) item;
+                if (JCR_LENGTH.equals(name) && !isMultiple()) {
+                    long length = p.getLength();
+                    prop = new DefaultDavProperty<String>(JCR_LENGTH, String.valueOf(length), true);
+                } else if (JCR_LENGTHS.equals(name) && isMultiple()) {
+                    prop = new LengthsProperty(p.getLengths());
+                }
+            } catch (RepositoryException e) {
+                log.error("Failed to retrieve resource properties: "+e.getMessage());
+            }
+        }
+
+        return prop;
+    }
+
     /**
      * Sets the given property. Note, that {@link #JCR_VALUE} and {@link #JCR_VALUES}
      * are the only resource properties that are allowed to be modified. Any other
@@ -319,6 +342,17 @@ public class DefaultItemResource extends
     }
 
     //--------------------------------------------------------------------------
+    @Override
+    protected void initPropertyNames() {
+        super.initPropertyNames();
+        if (exists()) {
+            DavPropertyNameSet propNames = (isMultiple() ?
+                    JcrDavPropertyNameSet.PROPERTY_MV_SET :
+                    JcrDavPropertyNameSet.PROPERTY_SET);
+            names.addAll(propNames);
+        }
+    }
+
     /**
      * Add resource specific properties.
      */
@@ -344,11 +378,8 @@ public class DefaultItemResource extends
                 properties.add(new DefaultDavProperty<String>(JCR_TYPE, PropertyType.nameFromValue(type)));
                 if (isMultiple()) {
                     properties.add(new ValuesProperty(prop.getValues()));
-                    properties.add(new LengthsProperty(prop.getLengths()));
                 } else {
                     properties.add(new ValuesProperty(prop.getValue()));
-                    long length = prop.getLength();
-                    properties.add(new DefaultDavProperty<String>(JCR_LENGTH, String.valueOf(length), true));
                 }
             } catch (RepositoryException e) {
                 log.error("Failed to retrieve resource properties: "+e.getMessage());

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/VersionControlledItemCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/VersionControlledItemCollection.java?rev=1155296&r1=1155295&r2=1155296&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/VersionControlledItemCollection.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/VersionControlledItemCollection.java Tue Aug  9 10:14:50 2011
@@ -26,6 +26,7 @@ import org.apache.jackrabbit.webdav.DavR
 import org.apache.jackrabbit.webdav.DavServletResponse;
 import org.apache.jackrabbit.webdav.MultiStatus;
 import org.apache.jackrabbit.webdav.MultiStatusResponse;
+import org.apache.jackrabbit.webdav.jcr.property.JcrDavPropertyNameSet;
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
 import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
 import org.apache.jackrabbit.webdav.property.HrefProperty;
@@ -75,6 +76,8 @@ public class VersionControlledItemCollec
      *
      * @param locator
      * @param session
+     * @param factory
+     * @param item
      */
     public VersionControlledItemCollection(DavResourceLocator locator,
                                            JcrDavSession session,
@@ -98,7 +101,7 @@ public class VersionControlledItemCollec
         StringBuffer sb = new StringBuffer(super.getSupportedMethods());
         // Versioning support
         sb.append(", ").append(VersionableResource.METHODS);
-        if (this.isVersionControlled()) {
+        if (isVersionControlled()) {
             try {
                 if (((Node)item).isCheckedOut()) {
                     sb.append(", ").append(VersionControlledResource.methods_checkedOut);
@@ -113,6 +116,35 @@ public class VersionControlledItemCollec
         return sb.toString();
     }
 
+    @Override
+    public DavProperty<?> getProperty(DavPropertyName name) {
+        DavProperty prop = super.getProperty(name);
+        if (prop == null && isVersionControlled()) {
+            Node n = (Node) item;
+            // properties defined by RFC 3253 for version-controlled resources
+            // workspace property already set in AbstractResource.initProperties()
+            try {
+                if (VERSION_HISTORY.equals(name)) {
+                    // DAV:version-history (computed)
+                    String vhHref = getLocatorFromItem(n.getVersionHistory()).getHref(true);
+                    prop  = new HrefProperty(VERSION_HISTORY, vhHref, true);
+                } else if (CHECKED_OUT.equals(name) && n.isCheckedOut()) {
+                    // DAV:checked-out property (protected)
+                    String baseVHref = getLocatorFromItem(n.getBaseVersion()).getHref(true);
+                    prop = new HrefProperty(CHECKED_OUT, baseVHref, true);
+                } else if (CHECKED_IN.equals(name) && !n.isCheckedOut()) {
+                    // DAV:checked-in property (protected)
+                    String baseVHref = getLocatorFromItem(n.getBaseVersion()).getHref(true);
+                    prop = new HrefProperty(CHECKED_IN, baseVHref, true);
+                }
+            } catch (RepositoryException e) {
+                log.error(e.getMessage());
+            }
+        }
+                
+        return prop;
+    }
+
     /**
      * @param changeList
      * @throws DavException
@@ -523,50 +555,69 @@ public class VersionControlledItemCollec
         }
     }
 
+    @Override
+    protected void initPropertyNames() {
+        super.initPropertyNames();
+
+        if (isVersionControlled()) {
+            names.addAll(JcrDavPropertyNameSet.VERSIONABLE_SET);
+
+            Node n = (Node) item;
+            try {
+                if (n.isCheckedOut()) {
+                    names.add(CHECKED_OUT);
+                    if (n.hasProperty(JcrConstants.JCR_PREDECESSORS)) {
+                        names.add(PREDECESSOR_SET);
+                    }
+                    if (n.hasProperty(JcrConstants.JCR_MERGEFAILED)) {
+                        names.add(AUTO_MERGE_SET);
+                    }
+                    // todo: checkout-fork, checkin-fork
+                } else {
+                    names.add(CHECKED_IN);
+                }
+            } catch (RepositoryException e) {
+                log.warn(e.getMessage());
+            }
+        }
+    }
+
     /**
      * Fill the property set for this resource.
      */
     @Override
     protected void initProperties() {
         super.initProperties();
-        if (exists()) {
+        if (isVersionControlled()) {
             Node n = (Node)item;
             // properties defined by RFC 3253 for version-controlled resources
-            if (isVersionControlled()) {
-                // workspace property already set in AbstractResource.initProperties()
-                try {
-                    // DAV:version-history (computed)
-                    String vhHref = getLocatorFromItem(n.getVersionHistory()).getHref(true);
-                    properties.add(new HrefProperty(VERSION_HISTORY, vhHref, true));
-
-                    // DAV:auto-version property: there is no auto version, explicit CHECKOUT is required.
-                    properties.add(new DefaultDavProperty<String>(AUTO_VERSION, null, false));
-
-                    String baseVHref = getLocatorFromItem(n.getBaseVersion()).getHref(true);
-                    if (n.isCheckedOut()) {
-                        // DAV:checked-out property (protected)
-                        properties.add(new HrefProperty(CHECKED_OUT, baseVHref, true));
-
-                        // DAV:predecessors property
-                        if (n.hasProperty(JcrConstants.JCR_PREDECESSORS)) {
-                            Value[] predec = n.getProperty(JcrConstants.JCR_PREDECESSORS).getValues();
-                            addHrefProperty(PREDECESSOR_SET, predec, false);
-                        }
-                        // DAV:auto-merge-set property. NOTE: the DAV:merge-set
-                        // never occurs, because merging without bestEffort flag
-                        // being set results in an exception on failure.
-                        if (n.hasProperty(JcrConstants.JCR_MERGEFAILED)) {
-                            Value[] mergeFailed = n.getProperty(JcrConstants.JCR_MERGEFAILED).getValues();
-                            addHrefProperty(AUTO_MERGE_SET, mergeFailed, false);
-                        }
-                        // todo: checkout-fork, checkin-fork
-                    } else {
-                        // DAV:checked-in property (protected)
-                        properties.add(new HrefProperty(CHECKED_IN, baseVHref, true));
+            // workspace property already set in AbstractResource.initProperties()
+            try {
+                // DAV:version-history (computed)
+                String vhHref = getLocatorFromItem(n.getVersionHistory()).getHref(true);
+                properties.add(new HrefProperty(VERSION_HISTORY, vhHref, true));
+
+                // DAV:auto-version property: there is no auto version, explicit CHECKOUT is required.
+                properties.add(new DefaultDavProperty<String>(AUTO_VERSION, null, false));
+
+                String baseVHref = getLocatorFromItem(n.getBaseVersion()).getHref(true);
+                if (n.isCheckedOut()) {
+                    // DAV:predecessors property
+                    if (n.hasProperty(JcrConstants.JCR_PREDECESSORS)) {
+                        Value[] predec = n.getProperty(JcrConstants.JCR_PREDECESSORS).getValues();
+                        addHrefProperty(PREDECESSOR_SET, predec, false);
+                    }
+                    // DAV:auto-merge-set property. NOTE: the DAV:merge-set
+                    // never occurs, because merging without bestEffort flag
+                    // being set results in an exception on failure.
+                    if (n.hasProperty(JcrConstants.JCR_MERGEFAILED)) {
+                        Value[] mergeFailed = n.getProperty(JcrConstants.JCR_MERGEFAILED).getValues();
+                        addHrefProperty(AUTO_MERGE_SET, mergeFailed, false);
                     }
-                } catch (RepositoryException e) {
-                    log.error(e.getMessage());
+                    // todo: checkout-fork, checkin-fork
                 }
+            } catch (RepositoryException e) {
+                log.error(e.getMessage());
             }
         }
     }

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/WorkspaceResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/WorkspaceResourceImpl.java?rev=1155296&r1=1155295&r2=1155296&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/WorkspaceResourceImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/WorkspaceResourceImpl.java Tue Aug  9 10:14:50 2011
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.webdav.jcr;
 
 import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader;
+import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefWriter;
 import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory;
 import org.apache.jackrabbit.commons.cnd.ParseException;
 import org.apache.jackrabbit.commons.cnd.TemplateBuilderFactory;
@@ -32,9 +33,12 @@ import org.apache.jackrabbit.webdav.Mult
 import org.apache.jackrabbit.webdav.MultiStatusResponse;
 import org.apache.jackrabbit.webdav.io.InputContext;
 import org.apache.jackrabbit.webdav.io.OutputContext;
+import org.apache.jackrabbit.webdav.jcr.property.JcrDavPropertyNameSet;
 import org.apache.jackrabbit.webdav.jcr.property.NamespacesProperty;
 import org.apache.jackrabbit.webdav.jcr.version.report.JcrPrivilegeReport;
 import org.apache.jackrabbit.webdav.property.DavProperty;
+import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
 import org.apache.jackrabbit.webdav.property.PropEntry;
 import org.apache.jackrabbit.webdav.search.SearchResource;
 import org.apache.jackrabbit.webdav.version.DeltaVResource;
@@ -55,6 +59,7 @@ import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Workspace;
+import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeTypeTemplate;
 import javax.jcr.observation.EventListener;
@@ -63,6 +68,7 @@ import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.StringReader;
+import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -93,6 +99,47 @@ public class WorkspaceResourceImpl exten
         initSupportedReports();
     }
 
+    @Override
+    public DavProperty<?> getProperty(DavPropertyName name) {
+        DavProperty prop = super.getProperty(name);
+        if (prop == null && ItemResourceConstants.JCR_NODETYPES_CND.equals(name)) {
+            StringWriter writer = new StringWriter();
+            try {
+                Session s = getRepositorySession();
+
+                CompactNodeTypeDefWriter cndWriter = new CompactNodeTypeDefWriter(writer, s, true);
+                NodeTypeIterator ntIterator = s.getWorkspace().getNodeTypeManager().getAllNodeTypes();
+                while (ntIterator.hasNext()) {
+                    cndWriter.write(ntIterator.nextNodeType());
+                }
+                cndWriter.close();
+                /*
+                NOTE: avoid having JCR_NODETYPES_CND exposed upon allprop
+                      PROPFIND request since it needs to be calculated.
+                      nevertheless, this property can be altered using
+                      PROPPATCH, which is not consistent with the specification
+                 */
+                return new DefaultDavProperty<String>(ItemResourceConstants.JCR_NODETYPES_CND, writer.toString(), true);
+            } catch (RepositoryException e) {
+                log.error("Failed to access NodeTypeManager: " + e.getMessage());
+                return null;
+            } catch (IOException e) {
+                log.error("Failed to write compact node definition: " + e.getMessage());
+                return null;
+            } finally {
+                try {
+                    writer.close();
+                } catch (IOException e) {
+                    log.error(e.getMessage());
+                }
+            }
+        }
+
+        // TODO: required property DAV:workspace-checkout-set (computed)
+
+        return prop;
+    }
+
     //--------------------------------------------------------< DavResource >---
 
     public String getSupportedMethods() {
@@ -317,7 +364,7 @@ public class WorkspaceResourceImpl exten
                     }
                 }
 
-                // TODO: for simplicity it's currently it's either registration or unregistration as nt-modifications are immediately persisted.
+                // TODO: for simplicity it's currently either registration or unregistration as nt-modifications are immediately persisted.
                 Session s = getRepositorySession();
                 NodeTypeManager ntMgr = s.getWorkspace().getNodeTypeManager();
                 if (registerCnd != null) {
@@ -361,8 +408,7 @@ public class WorkspaceResourceImpl exten
             if (propEntry instanceof DavProperty
                     && (ItemResourceConstants.JCR_NAMESPACES.equals(((DavProperty<?>)propEntry).getName())
                     || ItemResourceConstants.JCR_NODETYPES_CND.equals(((DavProperty<?>)propEntry).getName()))) {
-                DavProperty<?> namespaceProp = (DavProperty<?>) propEntry;
-                setProperty(namespaceProp);
+                setProperty((DavProperty<?>) propEntry);
             } else {
                 // attempt to remove the namespace property
                 throw new DavException(DavServletResponse.SC_CONFLICT);
@@ -510,6 +556,12 @@ public class WorkspaceResourceImpl exten
     }
 
     @Override
+    protected void initPropertyNames() {
+        super.initPropertyNames();
+        names.addAll(JcrDavPropertyNameSet.WORKSPACE_SET);
+    }
+
+    @Override
     protected void initProperties() {
         super.initProperties();
         try {
@@ -520,8 +572,5 @@ public class WorkspaceResourceImpl exten
         } catch (RepositoryException e) {
             log.error("Failed to access NamespaceRegistry: " + e.getMessage());
         }
-
-        // TODO: required property DAV:workspace-checkout-set (computed)
-        // TODO: create node type cnd property only if explicitly requested (see JCR-2946 and patch at JCR-2454) 
     }
 }

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/property/JcrDavPropertyNameSet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/property/JcrDavPropertyNameSet.java?rev=1155296&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/property/JcrDavPropertyNameSet.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/property/JcrDavPropertyNameSet.java Tue Aug  9 10:14:50 2011
@@ -0,0 +1,157 @@
+/*
+ * 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.jackrabbit.webdav.jcr.property;
+
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.apache.jackrabbit.webdav.observation.ObservationConstants;
+import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
+import org.apache.jackrabbit.webdav.security.SecurityConstants;
+import org.apache.jackrabbit.webdav.version.DeltaVConstants;
+import org.apache.jackrabbit.webdav.version.VersionControlledResource;
+import org.apache.jackrabbit.webdav.version.VersionHistoryResource;
+import org.apache.jackrabbit.webdav.version.VersionResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <code>JcrDavPropertyNameSet</code>...
+ */
+public final class JcrDavPropertyNameSet implements ItemResourceConstants {
+
+    /**
+     * logger instance
+     */
+    private static final Logger log = LoggerFactory.getLogger(JcrDavPropertyNameSet.class);
+
+
+    //------------------------------------------------< property name sets >----
+    /**
+     * Default property names present with all resources.
+     */
+    public static final DavPropertyNameSet BASE_SET = new DavPropertyNameSet();
+    static {
+        BASE_SET.add(DavPropertyName.DISPLAYNAME);
+        BASE_SET.add(DavPropertyName.RESOURCETYPE);
+        BASE_SET.add(DavPropertyName.ISCOLLECTION);
+        BASE_SET.add(DavPropertyName.GETLASTMODIFIED);
+        BASE_SET.add(DavPropertyName.CREATIONDATE);
+        BASE_SET.add(DavPropertyName.SUPPORTEDLOCK);
+        BASE_SET.add(DavPropertyName.LOCKDISCOVERY);
+        BASE_SET.add(DeltaVConstants.SUPPORTED_METHOD_SET);
+        BASE_SET.add(DeltaVConstants.SUPPORTED_REPORT_SET);
+        BASE_SET.add(DeltaVConstants.CREATOR_DISPLAYNAME);
+        BASE_SET.add(DeltaVConstants.COMMENT);
+        BASE_SET.add(JCR_WORKSPACE_NAME);
+    }
+
+    /**
+     * Property names defined for JCR workspace resources.
+     */
+    public static final DavPropertyNameSet WORKSPACE_SET = new DavPropertyNameSet();
+    static {
+        WORKSPACE_SET.add(DeltaVConstants.WORKSPACE);
+        WORKSPACE_SET.add(JCR_NAMESPACES);
+        WORKSPACE_SET.add(JCR_NODETYPES_CND);
+    }
+
+    /**
+     * Additional property names defined for existing and non-existing item resources.
+     */
+    public static final DavPropertyNameSet ITEM_BASE_SET = new DavPropertyNameSet();
+    static {
+        ITEM_BASE_SET.add(DavPropertyName.GETCONTENTTYPE);        
+        ITEM_BASE_SET.add(DeltaVConstants.WORKSPACE);
+        ITEM_BASE_SET.add(ObservationConstants.SUBSCRIPTIONDISCOVERY);
+        ITEM_BASE_SET.add(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
+    }
+
+    /**
+     * Additional property names defined for existing item resources.
+     */
+    public static final DavPropertyNameSet EXISTING_ITEM_BASE_SET = new DavPropertyNameSet(ITEM_BASE_SET);
+    static {
+        EXISTING_ITEM_BASE_SET.add(JCR_NAME);
+        EXISTING_ITEM_BASE_SET.add(JCR_PATH);
+        EXISTING_ITEM_BASE_SET.add(JCR_DEPTH);
+        EXISTING_ITEM_BASE_SET.add(JCR_DEFINITION);
+    }
+
+    /**
+     * Additional property names defined by single value JCR properties.
+     */
+    public static final DavPropertyNameSet PROPERTY_SET = new DavPropertyNameSet();
+    static {
+        PROPERTY_SET.add(JCR_TYPE);
+        PROPERTY_SET.add(JCR_VALUE);
+        PROPERTY_SET.add(JCR_LENGTH);
+    }
+
+    /**
+     * Additional property names defined by single value JCR properties.
+     */
+    public static final DavPropertyNameSet PROPERTY_MV_SET = new DavPropertyNameSet();
+    static {
+        PROPERTY_MV_SET.add(JCR_TYPE);
+        PROPERTY_MV_SET.add(JCR_VALUES);
+        PROPERTY_MV_SET.add(JCR_LENGTHS);
+    }
+
+    /**
+     * Additional property names defined by regular JCR nodes.
+     */
+    public static final DavPropertyNameSet NODE_SET = new DavPropertyNameSet();
+    static {
+        NODE_SET.add(JCR_PRIMARYNODETYPE);
+        NODE_SET.add(JCR_MIXINNODETYPES);
+        NODE_SET.add(JCR_INDEX);
+        NODE_SET.add(JCR_REFERENCES);
+        NODE_SET.add(JCR_WEAK_REFERENCES);
+    }
+
+    /**
+     * Additional property names defined by versionable JCR nodes.
+     */
+    public static final DavPropertyNameSet VERSIONABLE_SET = new DavPropertyNameSet();
+    static {
+        VERSIONABLE_SET.add(VersionControlledResource.VERSION_HISTORY);
+        VERSIONABLE_SET.add(VersionControlledResource.AUTO_VERSION);
+    }
+
+    /**
+     * Additional property names defined by JCR version nodes.
+     */
+    public static final DavPropertyNameSet VERSION_SET = new DavPropertyNameSet();
+    static {
+        VERSION_SET.add(VersionResource.VERSION_NAME);
+        VERSION_SET.add(VersionResource.LABEL_NAME_SET);
+        VERSION_SET.add(VersionResource.PREDECESSOR_SET);
+        VERSION_SET.add(VersionResource.SUCCESSOR_SET);
+        VERSION_SET.add(VersionResource.VERSION_HISTORY);
+        VERSION_SET.add(VersionResource.CHECKOUT_SET);
+    }
+
+    /**
+     * Additional property names defined by JCR version history nodes.
+     */
+    public static final DavPropertyNameSet VERSIONHISTORY_SET = new DavPropertyNameSet();
+    static { 
+        VERSIONHISTORY_SET.add(VersionHistoryResource.ROOT_VERSION);
+        VERSIONHISTORY_SET.add(VersionHistoryResource.VERSION_SET);
+        VERSIONHISTORY_SET.add(JCR_VERSIONABLEUUID);
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/property/JcrDavPropertyNameSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/property/JcrDavPropertyNameSet.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java?rev=1155296&r1=1155295&r2=1155296&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java Tue Aug  9 10:14:50 2011
@@ -25,6 +25,9 @@ import org.apache.jackrabbit.webdav.jcr.
 import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
 import org.apache.jackrabbit.webdav.jcr.JcrDavException;
 import org.apache.jackrabbit.webdav.jcr.JcrDavSession;
+import org.apache.jackrabbit.webdav.jcr.property.JcrDavPropertyNameSet;
+import org.apache.jackrabbit.webdav.property.DavProperty;
+import org.apache.jackrabbit.webdav.property.DavPropertyName;
 import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
 import org.apache.jackrabbit.webdav.property.HrefProperty;
 import org.apache.jackrabbit.webdav.property.ResourceType;
@@ -77,6 +80,28 @@ public class VersionHistoryItemCollectio
         return sb.toString();
     }
 
+    @Override
+    public DavProperty<?> getProperty(DavPropertyName name) {
+        DavProperty prop = super.getProperty(name);
+        if (prop == null) {
+            // required, protected version-set property for version-history resource
+            try {
+                if (ROOT_VERSION.equals(name)) {
+                    // required root-version property for version-history resource
+                    String rootVersionHref = getLocatorFromItem(((VersionHistory)item).getRootVersion()).getHref(true);
+                    prop = new HrefProperty(ROOT_VERSION, rootVersionHref, true);
+                } else if (VERSION_SET.equals(name)) {
+                    VersionIterator vIter = ((VersionHistory) item).getAllVersions();
+                    prop = getHrefProperty(VERSION_SET, vIter, true);
+                }
+            } catch (RepositoryException e) {
+                log.error(e.getMessage());
+            }
+        }
+        
+        return prop;
+    }
+
     /**
      * Removing a version resource is achieved by calling <code>removeVersion</code>
      * on the versionhistory item this version belongs to.
@@ -124,6 +149,15 @@ public class VersionHistoryItemCollectio
     }
 
     //--------------------------------------------------------------------------
+    @Override
+    protected void initPropertyNames() {
+        super.initPropertyNames();
+
+        if (exists()) {
+            names.addAll(JcrDavPropertyNameSet.VERSIONHISTORY_SET);
+        }
+    }
+
     /**
      * Fill the property set for this resource.
      */
@@ -140,21 +174,5 @@ public class VersionHistoryItemCollectio
         } catch (RepositoryException e) {
             log.error(e.getMessage());
         }
-
-        // required root-version property for version-history resource
-        try {
-            String rootVersionHref = getLocatorFromItem(((VersionHistory)item).getRootVersion()).getHref(true);
-            properties.add(new HrefProperty(VersionHistoryResource.ROOT_VERSION, rootVersionHref, true));
-        } catch (RepositoryException e) {
-            log.error(e.getMessage());
-        }
-
-        // required, protected version-set property for version-history resource
-        try {
-            VersionIterator vIter = ((VersionHistory) item).getAllVersions();
-            addHrefProperty(VersionHistoryResource.VERSION_SET, vIter, true);
-        } catch (RepositoryException e) {
-            log.error(e.getMessage());
-        }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java?rev=1155296&r1=1155295&r2=1155296&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java Tue Aug  9 10:14:50 2011
@@ -21,6 +21,8 @@ import org.apache.jackrabbit.webdav.DavE
 import org.apache.jackrabbit.webdav.DavResourceFactory;
 import org.apache.jackrabbit.webdav.DavResourceLocator;
 import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.jcr.property.JcrDavPropertyNameSet;
+import org.apache.jackrabbit.webdav.property.DavProperty;
 import org.apache.jackrabbit.webdav.util.HttpDateFormat;
 import org.apache.jackrabbit.webdav.jcr.DefaultItemCollection;
 import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
@@ -73,6 +75,52 @@ public class VersionItemCollection exten
         }
     }
 
+    @Override
+    public DavProperty<?> getProperty(DavPropertyName name) {
+        DavProperty prop = super.getProperty(name);
+        if (prop == null && exists()) {
+            Version v = (Version) item;
+            try {
+                if (VERSION_NAME.equals(name)) {
+                    // required, protected DAV:version-name property
+                    prop = new DefaultDavProperty<String>(VERSION_NAME, v.getName(), true);
+                } else if (VERSION_HISTORY.equals(name)) {
+                    // required DAV:version-history (computed) property
+                    String vhHref = getLocatorFromItem(getVersionHistoryItem()).getHref(true);
+                    prop = new HrefProperty(VERSION_HISTORY, vhHref, true);
+                } else if (PREDECESSOR_SET.equals(name)) {
+                    // required DAV:predecessor-set (protected) property
+                    prop = getHrefProperty(VersionResource.PREDECESSOR_SET, v.getPredecessors(), true);
+                } else if (SUCCESSOR_SET.equals(name)) {
+                    // required DAV:successor-set (computed) property
+                    prop = getHrefProperty(SUCCESSOR_SET, v.getSuccessors(), true);
+                } else if (LABEL_NAME_SET.equals(name)) {
+                    // required, protected DAV:label-name-set property
+                    String[] labels = getVersionHistoryItem().getVersionLabels(v);
+                    prop = new LabelSetProperty(labels);
+                } else if (CHECKOUT_SET.equals(name)) {
+                    // required DAV:checkout-set (computed) property
+                    PropertyIterator it = v.getReferences();
+                    List<Node> nodeList = new ArrayList<Node>();
+                    while (it.hasNext()) {
+                        Property p = it.nextProperty();
+                        if (JcrConstants.JCR_BASEVERSION.equals(p.getName())) {
+                            Node n = p.getParent();
+                            if (n.isCheckedOut()) {
+                                nodeList.add(n);
+                            }
+                        }
+                    }
+                    prop = getHrefProperty(CHECKOUT_SET, nodeList.toArray(new Node[nodeList.size()]), true);
+                }
+            } catch (RepositoryException e) {
+                log.error(e.getMessage());
+            }
+        }
+        
+        return prop;
+    }
+
     //----------------------------------------------< DavResource interface >---
     /**
      * @see org.apache.jackrabbit.webdav.DavResource#getSupportedMethods()
@@ -166,53 +214,27 @@ public class VersionItemCollection exten
         }
     }
 
-    /**
-     * Fill the property set for this resource.
-     */
     @Override
-    protected void initProperties() {
-        super.initProperties();
+    protected void initPropertyNames() {
+        super.initPropertyNames();
 
         if (exists()) {
-            Version v = (Version)item;
-            // created and creationDate properties
-            try {
-                String creationDate = HttpDateFormat.creationDateFormat().format(v.getCreated().getTime());
-                // replace dummy creation date from default collection
-                properties.add(new DefaultDavProperty<String>(DavPropertyName.CREATIONDATE, creationDate));
-
-                // required, protected DAV:version-name property
-                properties.add(new DefaultDavProperty<String>(VERSION_NAME, v.getName(), true));
-
-                // required, protected DAV:label-name-set property
-                String[] labels = getVersionHistoryItem().getVersionLabels(v);
-                properties.add(new LabelSetProperty(labels));
-
-                // required DAV:predecessor-set (protected) and DAV:successor-set (computed) properties
-                addHrefProperty(VersionResource.PREDECESSOR_SET, v.getPredecessors(), true);
-                addHrefProperty(SUCCESSOR_SET, v.getSuccessors(), true);
-
-                // required DAV:version-history (computed) property
-                String vhHref = getLocatorFromItem(getVersionHistoryItem()).getHref(true);
-                properties.add(new HrefProperty(VersionResource.VERSION_HISTORY, vhHref, true));
-
-                // required DAV:checkout-set (computed) property
-                PropertyIterator it = v.getReferences();
-                List<Node> nodeList = new ArrayList<Node>();
-                while (it.hasNext()) {
-                    Property p = it.nextProperty();
-                    if (JcrConstants.JCR_BASEVERSION.equals(p.getName())) {
-                        Node n = p.getParent();
-                        if (n.isCheckedOut()) {
-                           nodeList.add(n);
-                        }
-                    }
-                }
-                addHrefProperty(CHECKOUT_SET, nodeList.toArray(new Node[nodeList.size()]), true);
+            names.addAll(JcrDavPropertyNameSet.VERSION_SET);
+        }
+    }
 
+    @Override
+    protected String getCreationDate() {
+        if (exists()) {
+            Version v = (Version) item;
+            try {
+                return HttpDateFormat.creationDateFormat().format(v.getCreated().getTime());
             } catch (RepositoryException e) {
                 log.error(e.getMessage());
             }
         }
+
+        // fallback
+        return super.getCreationDate();
     }
 }



Mime
View raw message