Search in sources :

Example 1 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.

the class SearchResourceImpl method search.

/**
 * Execute the query defined by the given <code>sInfo</code>.
 *
 * @see SearchResource#search(org.apache.jackrabbit.webdav.search.SearchInfo)
 */
public MultiStatus search(SearchInfo sInfo) throws DavException {
    try {
        QueryResult result = getQuery(sInfo).execute();
        MultiStatus ms = new MultiStatus();
        if (ItemResourceConstants.NAMESPACE.equals(sInfo.getLanguageNameSpace())) {
            ms.setResponseDescription("Columns: " + encode(result.getColumnNames()) + "\nSelectors: " + encode(result.getSelectorNames()));
        } else {
            ms.setResponseDescription(encode(result.getColumnNames()));
        }
        queryResultToMultiStatus(result, ms);
        return ms;
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) QueryResult(javax.jcr.query.QueryResult) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException)

Example 2 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.

the class VersionItemCollection method getVersionHistory.

/**
 * Returns the {@link VersionHistory} associated with the repository version.
 * Note: in contrast to a versionable node, the version history of a version
 * item is always represented by its nearest ancestor.
 *
 * @return the {@link VersionHistoryResource} associated with this resource.
 * @throws org.apache.jackrabbit.webdav.DavException
 * @see org.apache.jackrabbit.webdav.version.VersionResource#getVersionHistory()
 * @see javax.jcr.Item#getParent()
 */
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    try {
        VersionHistory vh = getVersionHistoryItem();
        DavResourceLocator loc = getLocatorFromItem(vh);
        return (VersionHistoryResource) createResourceFromLocator(loc);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) 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)

Example 3 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.

the class VersionHistoryResourceImpl method removeMember.

/**
 * Removing a version resource is achieved by calling <code>removeVersion</code>
 * on the versionhistory item this version belongs to.
 *
 * @throws DavException if the version does not exist or if an error occurs
 * while deleting.
 * @see DavResource#removeMember(org.apache.jackrabbit.webdav.DavResource)
 */
@Override
public void removeMember(DavResource member) throws DavException {
    if (exists()) {
        VersionHistory versionHistory = (VersionHistory) getNode();
        try {
            String itemPath = member.getLocator().getRepositoryPath();
            // Retrieve the last segment of the given path and removes the index if present.
            if (itemPath == null) {
                throw new IllegalArgumentException("Cannot retrieve name from a 'null' item path.");
            }
            String name = Text.getName(itemPath);
            // remove index
            if (name.endsWith("]")) {
                name = name.substring(0, name.lastIndexOf('['));
            }
            versionHistory.removeVersion(name);
        } catch (RepositoryException e) {
            throw new JcrDavException(e);
        }
    } else {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory)

Example 4 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException 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 5 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.

the class VersionHistoryItemCollection method getVersions.

// -----------------------------------< VersionHistoryResource interface >---
/**
 * Return an array of {@link VersionResource}s representing all versions
 * present in the underlying JCR version history.
 *
 * @return array of {@link VersionResource}s representing all versions
 * present in the underlying JCR version history.
 * @throws DavException
 * @see org.apache.jackrabbit.webdav.version.VersionHistoryResource#getVersions()
 */
public VersionResource[] getVersions() throws DavException {
    try {
        VersionIterator vIter = ((VersionHistory) item).getAllVersions();
        ArrayList<VersionResource> l = new ArrayList<VersionResource>();
        while (vIter.hasNext()) {
            DavResourceLocator versionLoc = getLocatorFromItem(vIter.nextVersion());
            VersionResource vr = (VersionResource) createResourceFromLocator(versionLoc);
            l.add(vr);
        }
        return l.toArray(new VersionResource[l.size()]);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : 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)

Aggregations

RepositoryException (javax.jcr.RepositoryException)24 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)24 DavException (org.apache.jackrabbit.webdav.DavException)17 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)8 Node (javax.jcr.Node)6 Session (javax.jcr.Session)6 VersionHistory (javax.jcr.version.VersionHistory)6 JcrDavSession (org.apache.jackrabbit.webdav.jcr.JcrDavSession)5 DavResource (org.apache.jackrabbit.webdav.DavResource)4 DavSession (org.apache.jackrabbit.webdav.DavSession)3 VersionHistoryResource (org.apache.jackrabbit.webdav.version.VersionHistoryResource)3 ArrayList (java.util.ArrayList)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 VersionIterator (javax.jcr.version.VersionIterator)2 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)2 VersionResource (org.apache.jackrabbit.webdav.version.VersionResource)2 Element (org.w3c.dom.Element)2 IOException (java.io.IOException)1 Map (java.util.Map)1 Item (javax.jcr.Item)1