Search in sources :

Example 1 with JcrSupportedPrivilegesProperty

use of org.apache.jackrabbit.webdav.jcr.security.JcrSupportedPrivilegesProperty in project jackrabbit by apache.

the class DefaultItemCollection method getProperty.

@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);
            } else if (SecurityConstants.SUPPORTED_PRIVILEGE_SET.equals(name)) {
                prop = new JcrSupportedPrivilegesProperty(getRepositorySession(), n.getPath()).asDavProperty();
            } else if (SecurityConstants.CURRENT_USER_PRIVILEGE_SET.equals(name)) {
                prop = new JcrUserPrivilegesProperty(getRepositorySession(), n.getPath()).asDavProperty();
            }
        } catch (RepositoryException e) {
            log.error("Failed to retrieve node-specific property: " + e);
        }
    }
    return prop;
}
Also used : Item(javax.jcr.Item) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) Node(javax.jcr.Node) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) OrderingType(org.apache.jackrabbit.webdav.ordering.OrderingType) RepositoryException(javax.jcr.RepositoryException) JcrSupportedPrivilegesProperty(org.apache.jackrabbit.webdav.jcr.security.JcrSupportedPrivilegesProperty) JcrUserPrivilegesProperty(org.apache.jackrabbit.webdav.jcr.security.JcrUserPrivilegesProperty)

Example 2 with JcrSupportedPrivilegesProperty

use of org.apache.jackrabbit.webdav.jcr.security.JcrSupportedPrivilegesProperty in project jackrabbit by apache.

the class WorkspaceResourceImpl method getProperty.

@Override
public DavProperty<?> getProperty(DavPropertyName name) {
    DavProperty prop = super.getProperty(name);
    if (prop == null) {
        StringWriter writer = null;
        try {
            if (ItemResourceConstants.JCR_NODETYPES_CND.equals(name)) {
                writer = new StringWriter();
                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
                    */
                prop = new DefaultDavProperty<String>(ItemResourceConstants.JCR_NODETYPES_CND, writer.toString(), true);
            } else if (SecurityConstants.SUPPORTED_PRIVILEGE_SET.equals(name)) {
                prop = new JcrSupportedPrivilegesProperty(getRepositorySession(), null).asDavProperty();
            } else if (SecurityConstants.CURRENT_USER_PRIVILEGE_SET.equals(name)) {
                prop = new JcrUserPrivilegesProperty(getRepositorySession(), null).asDavProperty();
            }
        } catch (RepositoryException e) {
            log.error("Failed to access NodeTypeManager: " + e.getMessage());
        } catch (IOException e) {
            log.error("Failed to write compact node definition: " + e.getMessage());
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                    log.error(e.getMessage());
                }
            }
        }
    }
    return prop;
}
Also used : StringWriter(java.io.StringWriter) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) JcrSupportedPrivilegesProperty(org.apache.jackrabbit.webdav.jcr.security.JcrSupportedPrivilegesProperty) JcrUserPrivilegesProperty(org.apache.jackrabbit.webdav.jcr.security.JcrUserPrivilegesProperty) CompactNodeTypeDefWriter(org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefWriter) Session(javax.jcr.Session)

Aggregations

RepositoryException (javax.jcr.RepositoryException)2 JcrSupportedPrivilegesProperty (org.apache.jackrabbit.webdav.jcr.security.JcrSupportedPrivilegesProperty)2 JcrUserPrivilegesProperty (org.apache.jackrabbit.webdav.jcr.security.JcrUserPrivilegesProperty)2 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)2 DefaultDavProperty (org.apache.jackrabbit.webdav.property.DefaultDavProperty)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Item (javax.jcr.Item)1 Node (javax.jcr.Node)1 Session (javax.jcr.Session)1 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)1 CompactNodeTypeDefWriter (org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefWriter)1 OrderingType (org.apache.jackrabbit.webdav.ordering.OrderingType)1