Search in sources :

Example 1 with HrefProperty

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

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

the class VersionHistoryItemCollection method getProperty.

@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;
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) VersionIterator(javax.jcr.version.VersionIterator) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory)

Example 3 with HrefProperty

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

the class DavResourceImpl method initProperties.

/**
 * Fill the set of properties
 */
protected void initProperties() {
    if (!exists() || propsInitialized) {
        return;
    }
    try {
        config.getPropertyManager().exportProperties(getPropertyExportContext(), isCollection());
    } catch (RepositoryException e) {
        log.warn("Error while accessing resource properties", e);
    }
    // set (or reset) fundamental properties
    if (getDisplayName() != null) {
        properties.add(new DefaultDavProperty<String>(DavPropertyName.DISPLAYNAME, getDisplayName()));
    }
    if (isCollection()) {
        properties.add(new ResourceType(ResourceType.COLLECTION));
        // Windows XP support
        properties.add(new DefaultDavProperty<String>(DavPropertyName.ISCOLLECTION, "1"));
    } else {
        properties.add(new ResourceType(ResourceType.DEFAULT_RESOURCE));
        // Windows XP support
        properties.add(new DefaultDavProperty<String>(DavPropertyName.ISCOLLECTION, "0"));
    }
    if (rfc4122Uri != null) {
        properties.add(new HrefProperty(BindConstants.RESOURCEID, rfc4122Uri, true));
    }
    Set<ParentElement> parentElements = getParentElements();
    if (!parentElements.isEmpty()) {
        properties.add(new ParentSet(parentElements));
    }
    /* set current lock information. If no lock is set to this resource,
        an empty lock discovery will be returned in the response. */
    properties.add(new LockDiscovery(getLock(Type.WRITE, Scope.EXCLUSIVE)));
    /* lock support information: all locks are lockable. */
    SupportedLock supportedLock = new SupportedLock();
    supportedLock.addEntry(Type.WRITE, Scope.EXCLUSIVE);
    properties.add(supportedLock);
    propsInitialized = true;
}
Also used : ParentSet(org.apache.jackrabbit.webdav.bind.ParentSet) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) SupportedLock(org.apache.jackrabbit.webdav.lock.SupportedLock) RepositoryException(javax.jcr.RepositoryException) ResourceType(org.apache.jackrabbit.webdav.property.ResourceType) ParentElement(org.apache.jackrabbit.webdav.bind.ParentElement) LockDiscovery(org.apache.jackrabbit.webdav.lock.LockDiscovery)

Example 4 with HrefProperty

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

the class DeltaVResourceImpl method getReferenceResources.

/**
 * Return an array of <code>DavResource</code> objects that are referenced
 * by the property with the specified name.
 *
 * @param hrefPropertyName
 * @return array of <code>DavResource</code>s
 * @throws DavException
 * @see DeltaVResource#getReferenceResources(org.apache.jackrabbit.webdav.property.DavPropertyName)
 */
public DavResource[] getReferenceResources(DavPropertyName hrefPropertyName) throws DavException {
    DavProperty<?> prop = getProperty(hrefPropertyName);
    List<DavResource> resources = new ArrayList<DavResource>();
    if (prop != null && prop instanceof HrefProperty) {
        HrefProperty hp = (HrefProperty) prop;
        // process list of hrefs
        for (String href : hp.getHrefs()) {
            DavResourceLocator locator = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), href);
            resources.add(createResourceFromLocator(locator));
        }
    } else {
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    return resources.toArray(new DavResource[resources.size()]);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavException(org.apache.jackrabbit.webdav.DavException) ArrayList(java.util.ArrayList) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 5 with HrefProperty

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

the class AbstractItemResource method initProperties.

/**
 * Fill the property set for this resource.
 */
@Override
protected void initProperties() {
    super.initProperties();
    if (exists()) {
        try {
            properties.add(new DefaultDavProperty<String>(JCR_NAME, item.getName()));
            properties.add(new DefaultDavProperty<String>(JCR_PATH, item.getPath()));
            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 (depth > 0) {
                String parentHref = getLocatorFromItem(item.getParent()).getHref(true);
                properties.add(new HrefProperty(JCR_PARENT, parentHref, false));
            }
        } catch (RepositoryException e) {
            // should not get here
            log.error("Error while accessing jcr properties: " + e.getMessage());
        }
    }
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) RepositoryException(javax.jcr.RepositoryException)

Aggregations

HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)20 RepositoryException (javax.jcr.RepositoryException)14 DavException (org.apache.jackrabbit.webdav.DavException)7 DefaultDavProperty (org.apache.jackrabbit.webdav.property.DefaultDavProperty)7 Node (javax.jcr.Node)6 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)6 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 Version (javax.jcr.version.Version)4 HttpResponse (org.apache.http.HttpResponse)4 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)4 Value (javax.jcr.Value)3 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)3 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)3 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)3 Property (javax.jcr.Property)2 PropertyIterator (javax.jcr.PropertyIterator)2 VersionHistory (javax.jcr.version.VersionHistory)2 VersionIterator (javax.jcr.version.VersionIterator)2 NodeId (org.apache.jackrabbit.spi.NodeId)2