Search in sources :

Example 1 with DefaultDavProperty

use of org.apache.jackrabbit.webdav.property.DefaultDavProperty in project jackrabbit by apache.

the class VersionItemCollection method getProperty.

@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;
}
Also used : LabelSetProperty(org.apache.jackrabbit.webdav.version.LabelSetProperty) Node(javax.jcr.Node) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) PropertyIterator(javax.jcr.PropertyIterator) RepositoryException(javax.jcr.RepositoryException) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Version(javax.jcr.version.Version) ArrayList(java.util.ArrayList) List(java.util.List) Property(javax.jcr.Property) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) LabelSetProperty(org.apache.jackrabbit.webdav.version.LabelSetProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty)

Example 2 with DefaultDavProperty

use of org.apache.jackrabbit.webdav.property.DefaultDavProperty 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 3 with DefaultDavProperty

use of org.apache.jackrabbit.webdav.property.DefaultDavProperty 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)

Example 4 with DefaultDavProperty

use of org.apache.jackrabbit.webdav.property.DefaultDavProperty in project jackrabbit by apache.

the class VersionControlledResourceImpl method initProperties.

/**
     * Fill the property set for this resource.
     * @see DavResourceImpl#initProperties()
     */
@Override
protected void initProperties() {
    if (!propsInitialized) {
        super.initProperties();
        if (isVersionControlled()) {
            Node n = getNode();
            // properties defined by RFC 3253 for version-controlled resources
            try {
                // DAV:version-history (computed)
                String vhHref = getLocatorFromNode(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(AUTO_VERSION, null, true));
                // baseVersion -> used for DAV:checked-out or DAV:checked-in
                String baseVHref = getLocatorFromNode(n.getBaseVersion()).getHref(false);
                if (n.isCheckedOut()) {
                    // DAV:predecessors property
                    if (n.hasProperty(JcrConstants.JCR_PREDECESSORS)) {
                        Value[] pv = n.getProperty(JcrConstants.JCR_PREDECESSORS).getValues();
                        Node[] predecessors = new Node[pv.length];
                        for (int i = 0; i < pv.length; i++) {
                            predecessors[i] = n.getSession().getNodeByIdentifier(pv[i].getString());
                        }
                        properties.add(getHrefProperty(VersionResource.PREDECESSOR_SET, predecessors, true, false));
                    }
                    // DAV:checked-out property (protected)
                    properties.add(new HrefProperty(CHECKED_OUT, baseVHref, true));
                } else {
                    // DAV:checked-in property (protected)
                    properties.add(new HrefProperty(CHECKED_IN, baseVHref, true));
                }
            } catch (RepositoryException e) {
                log.error(e.getMessage());
            }
        }
    }
}
Also used : DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Node(javax.jcr.Node) Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException)

Example 5 with DefaultDavProperty

use of org.apache.jackrabbit.webdav.property.DefaultDavProperty in project jackrabbit by apache.

the class VersionResourceImpl method initProperties.

/**
     * Fill the property set for this resource.
     */
@Override
protected void initProperties() {
    if (!propsInitialized) {
        super.initProperties();
        Version v = (Version) getNode();
        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
            properties.add(getHrefProperty(VersionResource.PREDECESSOR_SET, v.getPredecessors(), true, false));
            properties.add(getHrefProperty(SUCCESSOR_SET, v.getSuccessors(), true, false));
            // required DAV:version-history (computed) property
            String vhHref = getLocatorFromNode(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);
                    }
                }
            }
            properties.add(getHrefProperty(CHECKOUT_SET, nodeList.toArray(new Node[nodeList.size()]), true, false));
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
    }
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Version(javax.jcr.version.Version) LabelSetProperty(org.apache.jackrabbit.webdav.version.LabelSetProperty) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) LabelSetProperty(org.apache.jackrabbit.webdav.version.LabelSetProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty)

Aggregations

DefaultDavProperty (org.apache.jackrabbit.webdav.property.DefaultDavProperty)10 RepositoryException (javax.jcr.RepositoryException)8 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)7 Node (javax.jcr.Node)5 Property (javax.jcr.Property)5 ArrayList (java.util.ArrayList)4 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)4 StringWriter (java.io.StringWriter)2 PropertyIterator (javax.jcr.PropertyIterator)2 Version (javax.jcr.version.Version)2 LengthsProperty (org.apache.jackrabbit.webdav.jcr.property.LengthsProperty)2 ValuesProperty (org.apache.jackrabbit.webdav.jcr.property.ValuesProperty)2 JcrSupportedPrivilegesProperty (org.apache.jackrabbit.webdav.jcr.security.JcrSupportedPrivilegesProperty)2 JcrUserPrivilegesProperty (org.apache.jackrabbit.webdav.jcr.security.JcrUserPrivilegesProperty)2 LabelSetProperty (org.apache.jackrabbit.webdav.version.LabelSetProperty)2 XmlSerializable (org.apache.jackrabbit.webdav.xml.XmlSerializable)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 IOException (java.io.IOException)1 List (java.util.List)1