Search in sources :

Example 1 with LabelSetProperty

use of org.apache.jackrabbit.webdav.version.LabelSetProperty 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 LabelSetProperty

use of org.apache.jackrabbit.webdav.version.LabelSetProperty 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

ArrayList (java.util.ArrayList)2 Node (javax.jcr.Node)2 Property (javax.jcr.Property)2 PropertyIterator (javax.jcr.PropertyIterator)2 RepositoryException (javax.jcr.RepositoryException)2 Version (javax.jcr.version.Version)2 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)2 DefaultDavProperty (org.apache.jackrabbit.webdav.property.DefaultDavProperty)2 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)2 LabelSetProperty (org.apache.jackrabbit.webdav.version.LabelSetProperty)2 List (java.util.List)1