Search in sources :

Example 6 with DavResourceLocator

use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.

the class LocateCorrespondingNodeReport method getCorrespondingResourceHref.

/**
     * Retrieve the href of the corresponding resource in the indicated workspace.
     *
     * @param resource
     * @param session Session object used to access the {@link Node} object
     * represented by the given resource.
     * @param workspaceHref
     * @return
     * @throws RepositoryException
     */
private static String getCorrespondingResourceHref(DavResource resource, Session session, String workspaceHref) throws RepositoryException {
    DavResourceLocator rLoc = resource.getLocator();
    String itemPath = rLoc.getRepositoryPath();
    Item item = session.getItem(itemPath);
    if (item.isNode()) {
        String workspaceName = rLoc.getFactory().createResourceLocator(rLoc.getPrefix(), workspaceHref).getWorkspaceName();
        String corrPath = ((Node) item).getCorrespondingNodePath(workspaceName);
        DavResourceLocator corrLoc = rLoc.getFactory().createResourceLocator(rLoc.getPrefix(), "/" + workspaceName, corrPath, false);
        return corrLoc.getHref(true);
    } else {
        throw new PathNotFoundException("Node with path " + itemPath + " does not exist.");
    }
}
Also used : Item(javax.jcr.Item) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 7 with DavResourceLocator

use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.

the class VersionHistoryResourceImpl method getMembers.

//--------------------------------------------------------< DavResource >---
/**
     * Show all versions of this history as members.
     *
     * @return
     * @see DavResource#getMembers()
     */
@Override
public DavResourceIterator getMembers() {
    ArrayList<DavResource> list = new ArrayList<DavResource>();
    if (exists() && isCollection()) {
        try {
            // only display versions as members of the vh. the jcr:versionLabels
            // node is an internal structure.
            VersionIterator it = ((VersionHistory) getNode()).getAllVersions();
            while (it.hasNext()) {
                // omit item filter here. if the version history is visible
                // its versions should be visible as well.
                Version v = it.nextVersion();
                DavResourceLocator vhLocator = getLocator();
                DavResourceLocator resourceLocator = vhLocator.getFactory().createResourceLocator(vhLocator.getPrefix(), vhLocator.getWorkspacePath(), v.getPath(), false);
                DavResource childRes = getFactory().createResource(resourceLocator, getSession());
                list.add(childRes);
            }
        } catch (RepositoryException e) {
            // should not occur
            log.error("Unexpected error", e);
        } catch (DavException e) {
            // should not occur
            log.error("Unexpected error", e);
        }
    }
    return new DavResourceIteratorImpl(list);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) Version(javax.jcr.version.Version) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavResourceIteratorImpl(org.apache.jackrabbit.webdav.DavResourceIteratorImpl) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 8 with DavResourceLocator

use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.

the class VersionHistoryResourceImpl method getVersions.

//---------------------------------------------< VersionHistoryResource >---
/**
     * Return an array of {@link org.apache.jackrabbit.webdav.version.VersionResource}s representing all versions
     * present in the underlying JCR version history.
     *
     * @return array of {@link org.apache.jackrabbit.webdav.version.VersionResource}s representing all versions
     * present in the underlying JCR version history.
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionHistoryResource#getVersions()
     */
public VersionResource[] getVersions() throws DavException {
    try {
        VersionIterator vIter = ((VersionHistory) getNode()).getAllVersions();
        ArrayList<VersionResource> l = new ArrayList<VersionResource>();
        while (vIter.hasNext()) {
            DavResourceLocator versionLoc = getLocatorFromNode(vIter.nextVersion());
            DavResource vr = createResourceFromLocator(versionLoc);
            if (vr instanceof VersionResource) {
                l.add((VersionResource) vr);
            } else {
                // severe error since resource factory doesn't behave correctly.
                throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
            }
        }
        return l.toArray(new VersionResource[l.size()]);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) VersionResource(org.apache.jackrabbit.webdav.version.VersionResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 9 with DavResourceLocator

use of org.apache.jackrabbit.webdav.DavResourceLocator 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 10 with DavResourceLocator

use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.

the class DefaultItemCollection method getMembers.

/**
     * @see org.apache.jackrabbit.webdav.DavResource#getMembers()
     */
@Override
public DavResourceIterator getMembers() {
    ArrayList<DavResource> memberList = new ArrayList<DavResource>();
    if (exists()) {
        try {
            Node n = (Node) item;
            // add all node members
            NodeIterator it = n.getNodes();
            while (it.hasNext()) {
                Node node = it.nextNode();
                DavResourceLocator loc = getLocatorFromItem(node);
                memberList.add(createResourceFromLocator(loc));
            }
            // add all property members
            PropertyIterator propIt = n.getProperties();
            while (propIt.hasNext()) {
                Property prop = propIt.nextProperty();
                DavResourceLocator loc = getLocatorFromItem(prop);
                memberList.add(createResourceFromLocator(loc));
            }
        } catch (RepositoryException e) {
            // ignore
            log.error(e.getMessage());
        } catch (DavException e) {
            // should never occur.
            log.error(e.getMessage());
        }
    }
    return new DavResourceIteratorImpl(memberList);
}
Also used : NodeIterator(javax.jcr.NodeIterator) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) DavResourceIteratorImpl(org.apache.jackrabbit.webdav.DavResourceIteratorImpl) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) PropertyIterator(javax.jcr.PropertyIterator) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) JcrUserPrivilegesProperty(org.apache.jackrabbit.webdav.jcr.security.JcrUserPrivilegesProperty) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) JcrSupportedPrivilegesProperty(org.apache.jackrabbit.webdav.jcr.security.JcrSupportedPrivilegesProperty) NodeTypeProperty(org.apache.jackrabbit.webdav.jcr.nodetype.NodeTypeProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) ValuesProperty(org.apache.jackrabbit.webdav.jcr.property.ValuesProperty) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Aggregations

DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)34 DavException (org.apache.jackrabbit.webdav.DavException)25 RepositoryException (javax.jcr.RepositoryException)20 DavResource (org.apache.jackrabbit.webdav.DavResource)19 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)11 Node (javax.jcr.Node)10 ArrayList (java.util.ArrayList)7 VersionHistory (javax.jcr.version.VersionHistory)7 NodeIterator (javax.jcr.NodeIterator)5 DavResourceIteratorImpl (org.apache.jackrabbit.webdav.DavResourceIteratorImpl)5 VersionHistoryResource (org.apache.jackrabbit.webdav.version.VersionHistoryResource)5 PathNotFoundException (javax.jcr.PathNotFoundException)4 Item (javax.jcr.Item)3 Session (javax.jcr.Session)3 Version (javax.jcr.version.Version)3 VersionIterator (javax.jcr.version.VersionIterator)3 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)3 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)3 VersionResource (org.apache.jackrabbit.webdav.version.VersionResource)3 Element (org.w3c.dom.Element)3