Search in sources :

Example 16 with DavResourceLocator

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

the class AbstractItemResource method getWorkspaceHref.

/**
     * @return href of the workspace or <code>null</code> if this resource
     * does not represent a repository item.
     *
     * @see AbstractResource#getWorkspaceHref()
     */
@Override
protected String getWorkspaceHref() {
    String workspaceHref = null;
    DavResourceLocator locator = getLocator();
    if (locator != null && locator.getWorkspacePath() != null) {
        String wspPath = locator.getWorkspacePath();
        DavResourceLocator wspLocator = locator.getFactory().createResourceLocator(locator.getPrefix(), wspPath, wspPath);
        workspaceHref = wspLocator.getHref(true);
    }
    log.debug(workspaceHref);
    return workspaceHref;
}
Also used : DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 17 with DavResourceLocator

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

the class AbstractItemResource method move.

/**
     * Moves the underlying repository item to the indicated destination.
     *
     * @param destination
     * @throws DavException
     * @see DavResource#move(DavResource)
     * @see javax.jcr.Session#move(String, String)
     */
@Override
public void move(DavResource destination) throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    DavResourceLocator destLocator = destination.getLocator();
    if (!getLocator().isSameWorkspace(destLocator)) {
        throw new DavException(DavServletResponse.SC_FORBIDDEN);
    }
    try {
        String itemPath = getLocator().getRepositoryPath();
        String destItemPath = destination.getLocator().getRepositoryPath();
        if (getTransactionId() == null) {
            // if not part of a transaction directly import on workspace
            getRepositorySession().getWorkspace().move(itemPath, destItemPath);
        } else {
            // changes will not be persisted unless the tx is completed.
            getRepositorySession().move(itemPath, destItemPath);
        }
    // no use in calling 'complete' that would fail for a moved item anyway.
    } catch (PathNotFoundException e) {
        // according to rfc 2518
        throw new DavException(DavServletResponse.SC_CONFLICT, e.getMessage());
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 18 with DavResourceLocator

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

the class DavResourceImpl method getCollection.

/**
     * @see DavResource#getCollection()
     */
public DavResource getCollection() {
    DavResource parent = null;
    if (getResourcePath() != null && !getResourcePath().equals("/")) {
        String parentPath = Text.getRelativeParent(getResourcePath(), 1);
        if (parentPath.equals("")) {
            parentPath = "/";
        }
        DavResourceLocator parentloc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), parentPath);
        try {
            parent = factory.createResource(parentloc, session);
        } catch (DavException e) {
        // should not occur
        }
    }
    return parent;
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 19 with DavResourceLocator

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

the class LocatorFactoryImplExTest method testCollectionNameEqualsWorkspaceName.

/**
     * Test for issue https://issues.apache.org/jira/browse/JCR-1679: An top
     * level resource (node directly below the root) whose name equals the
     * workspace name results in wrong collection behaviour (garbeled locator
     * of child resources).
     */
public void testCollectionNameEqualsWorkspaceName() {
    String prefix = "http://localhost:8080/jackrabbit/repository";
    String workspacePath = "/default";
    String nodePath = "/default/another";
    DavResourceLocator locator = factory.createResourceLocator(prefix, workspacePath, nodePath, false);
    assertTrue(locator.getHref(true).indexOf("/default/default") > 0);
    DavResourceLocator locator2 = factory.createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), locator.getResourcePath());
    assertEquals(locator, locator2);
    assertEquals(nodePath, locator2.getRepositoryPath());
}
Also used : DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 20 with DavResourceLocator

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

the class VersionControlledResourceImpl method getVersionHistory.

/**
     * Returns the {@link javax.jcr.version.VersionHistory} associated with the repository node.
     * If the node is not versionable an exception is thrown.
     *
     * @return the {@link VersionHistoryResource} associated with this resource.
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#getVersionHistory()
     * @see javax.jcr.Node#getVersionHistory()
     */
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    if (!isVersionControlled()) {
        throw new DavException(DavServletResponse.SC_FORBIDDEN);
    }
    try {
        VersionHistory vh = getNode().getVersionHistory();
        DavResourceLocator loc = getLocatorFromNode(vh);
        DavResource vhr = createResourceFromLocator(loc);
        if (vhr instanceof VersionHistoryResource) {
            return (VersionHistoryResource) vhr;
        } else {
            // severe error since resource factory doesn't behave correctly.
            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } 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) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) 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