Search in sources :

Example 1 with ParentElement

use of org.apache.jackrabbit.webdav.bind.ParentElement in project jackrabbit by apache.

the class DavResourceImpl method getParentElements.

/**
     * @see org.apache.jackrabbit.webdav.bind.BindableResource#getParentElements()
     */
public Set<ParentElement> getParentElements() {
    try {
        if (node.getDepth() > 0) {
            Set<ParentElement> ps = new HashSet<ParentElement>();
            NodeIterator sharedSetIterator = node.getSharedSet();
            while (sharedSetIterator.hasNext()) {
                Node sharednode = sharedSetIterator.nextNode();
                DavResourceLocator loc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), sharednode.getParent().getPath(), false);
                ps.add(new ParentElement(loc.getHref(true), sharednode.getName()));
            }
            return ps;
        }
    } catch (UnsupportedRepositoryOperationException e) {
        log.debug("unable to calculate parent set", e);
    } catch (RepositoryException e) {
        log.warn("unable to calculate parent set", e);
    }
    return Collections.emptySet();
}
Also used : NodeIterator(javax.jcr.NodeIterator) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) ParentElement(org.apache.jackrabbit.webdav.bind.ParentElement) HashSet(java.util.HashSet) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 2 with ParentElement

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

use of org.apache.jackrabbit.webdav.bind.ParentElement in project jackrabbit by apache.

the class BindTest method testParentSet.

public void testParentSet() throws Exception {
    String testcol = this.root + "testParentSet/";
    String subcol1 = testcol + "bindtest1/";
    String testres1 = subcol1 + "res1";
    String subcol2 = testcol + "bindtest2/";
    String testres2 = subcol2 + "res2";
    int status;
    try {
        HttpMkcol mkcol = new HttpMkcol(testcol);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        mkcol = new HttpMkcol(subcol1);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        mkcol = new HttpMkcol(subcol2);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        //create new resource R with path testSimpleBind/bindtest1/res1
        HttpPut put = new HttpPut(testres1);
        put.setEntity(new StringEntity("foo", ContentType.create("text/plain", "UTF-8")));
        status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        //create new binding of R with path testSimpleBind/bindtest2/res2
        HttpBind bind = new HttpBind(subcol2, new BindInfo(testres1, "res2"));
        status = this.client.execute(bind, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        //check if both bindings report the same DAV:resource-id
        assertEquals(this.getResourceId(testres1), this.getResourceId(testres2));
        //verify values of parent-set properties
        List<String> hrefs1 = new ArrayList<String>();
        List<String> segments1 = new ArrayList<String>();
        List<String> hrefs2 = new ArrayList<String>();
        List<String> segments2 = new ArrayList<String>();
        Object ps1 = this.getParentSet(testres1).getValue();
        Object ps2 = this.getParentSet(testres2).getValue();
        assertTrue(ps1 instanceof List);
        assertTrue(ps2 instanceof List);
        List plist1 = (List) ps1;
        List plist2 = (List) ps2;
        assertEquals(2, plist1.size());
        assertEquals(2, plist2.size());
        for (int k = 0; k < 2; k++) {
            Object pObj1 = plist1.get(k);
            Object pObj2 = plist2.get(k);
            assertTrue(pObj1 instanceof Element);
            assertTrue(pObj2 instanceof Element);
            ParentElement p1 = ParentElement.createFromXml((Element) pObj1);
            ParentElement p2 = ParentElement.createFromXml((Element) pObj2);
            hrefs1.add(p1.getHref());
            hrefs2.add(p2.getHref());
            segments1.add(p1.getSegment());
            segments2.add(p2.getSegment());
        }
        Collections.sort(hrefs1);
        Collections.sort(hrefs2);
        Collections.sort(segments1);
        Collections.sort(segments2);
        assertEquals(hrefs1, hrefs2);
        assertEquals(segments1, segments2);
    } finally {
        delete(testcol);
    }
}
Also used : HttpBind(org.apache.jackrabbit.webdav.client.methods.HttpBind) ParentElement(org.apache.jackrabbit.webdav.bind.ParentElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ParentElement(org.apache.jackrabbit.webdav.bind.ParentElement) HttpPut(org.apache.http.client.methods.HttpPut) StringEntity(org.apache.http.entity.StringEntity) HttpMkcol(org.apache.jackrabbit.webdav.client.methods.HttpMkcol) ArrayList(java.util.ArrayList) List(java.util.List) BindInfo(org.apache.jackrabbit.webdav.bind.BindInfo)

Aggregations

ParentElement (org.apache.jackrabbit.webdav.bind.ParentElement)3 RepositoryException (javax.jcr.RepositoryException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Node (javax.jcr.Node)1 NodeIterator (javax.jcr.NodeIterator)1 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1 HttpPut (org.apache.http.client.methods.HttpPut)1 StringEntity (org.apache.http.entity.StringEntity)1 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)1 BindInfo (org.apache.jackrabbit.webdav.bind.BindInfo)1 ParentSet (org.apache.jackrabbit.webdav.bind.ParentSet)1 HttpBind (org.apache.jackrabbit.webdav.client.methods.HttpBind)1 HttpMkcol (org.apache.jackrabbit.webdav.client.methods.HttpMkcol)1 LockDiscovery (org.apache.jackrabbit.webdav.lock.LockDiscovery)1 SupportedLock (org.apache.jackrabbit.webdav.lock.SupportedLock)1 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)1 ResourceType (org.apache.jackrabbit.webdav.property.ResourceType)1 Element (org.w3c.dom.Element)1