Search in sources :

Example 26 with DavResourceLocator

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

the class VersionControlledItemCollection method merge.

/**
     * Merge the repository node represented by this resource according to the
     * information present in the given {@link MergeInfo} object.
     *
     * @param mergeInfo
     * @return <code>MultiStatus</code> recording all repository items modified
     * by this merge call as well as the resources that a client must modify to
     * complete the merge (see <a href="http://www.webdav.org/specs/rfc3253.html#METHOD_MERGE">RFC 3253</a>)
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#merge(org.apache.jackrabbit.webdav.version.MergeInfo)
     * @see Node#merge(String, boolean)
     */
//TODO: with jcr the node must not be versionable in order to perform Node.merge
@Override
public MultiStatus merge(MergeInfo mergeInfo) throws DavException {
    if (mergeInfo == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    MultiStatus ms = new MultiStatus();
    try {
        // NOTE: RFC requires that all modified resources are reported in the
        // multistatus response. this doesn't work however with the remoting
        // there is no way to distinguish the 'failedId's from any other
        // resources that got modified by this merge operation -> omitted.
        // todo: RFC allows multiple href elements inside the DAV:source element
        String workspaceName = getLocatorFromHref(mergeInfo.getSourceHrefs()[0]).getWorkspaceName();
        String depth = DomUtil.getChildTextTrim(mergeInfo.getMergeElement(), DavConstants.XML_DEPTH, DavConstants.NAMESPACE);
        boolean isShallow = "0".equals(depth);
        NodeIterator failed = getVersionManager().merge(item.getPath(), workspaceName, !mergeInfo.isNoAutoMerge(), isShallow);
        // add resources to the multistatus, that failed to be merged
        while (failed.hasNext()) {
            Node failedNode = failed.nextNode();
            DavResourceLocator loc = getLocatorFromItem(failedNode);
            DavResource res = createResourceFromLocator(loc);
            ms.addResponse(new MultiStatusResponse(res, mergeInfo.getPropertyNameSet()));
        }
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
    return ms;
}
Also used : NodeIterator(javax.jcr.NodeIterator) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) Node(javax.jcr.Node) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 27 with DavResourceLocator

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

the class LocateByUuidReport method init.

/**
     * @see Report#init(DavResource, ReportInfo)
     */
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
    // delegate basic validation to super class
    super.init(resource, info);
    // make also sure, the info contains a DAV:href child element
    if (!info.containsContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "dcr:locate-by-uuid element must at least contain a single DAV:href child.");
    }
    // immediately build the final multistatus element
    try {
        Element hrefElem = info.getContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE);
        String uuid = DomUtil.getTextTrim(hrefElem);
        DavResourceLocator resourceLoc = resource.getLocator();
        Node n = getRepositorySession().getNodeByUUID(uuid);
        DavResourceLocator loc = resourceLoc.getFactory().createResourceLocator(resourceLoc.getPrefix(), resourceLoc.getWorkspacePath(), n.getPath(), false);
        DavResource locatedResource = resource.getFactory().createResource(loc, resource.getSession());
        ms = new MultiStatus();
        ms.addResourceProperties(locatedResource, info.getPropertyNameSet(), info.getDepth());
    } 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) Element(org.w3c.dom.Element) Node(javax.jcr.Node) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 28 with DavResourceLocator

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

the class JcrPrivilegeReport method init.

/**
     * @see Report#init(DavResource, ReportInfo)
     */
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
    // delegate basic validation to super class
    super.init(resource, info);
    // make also sure, the info contains a DAV:href child element
    if (!info.containsContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "dcr:privileges element must at least contain a single DAV:href child.");
    }
    // immediately build the final multistatus element
    Element hrefElem = info.getContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE);
    String href = DomUtil.getTextTrim(hrefElem);
    // TODO: we should check whether the authority component matches
    href = obtainAbsolutePathFromUri(href);
    DavResourceLocator resourceLoc = resource.getLocator();
    DavResourceLocator loc = resourceLoc.getFactory().createResourceLocator(resourceLoc.getPrefix(), href);
    // immediately build the final multistatus element
    addResponses(loc);
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 29 with DavResourceLocator

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

the class AbstractResource method getResourceFromHref.

/**
     * Retrieve the <code>DavResource</code> object that is represented by
     * the given href String.
     *
     * @param href
     * @return <code>DavResource</code> object
     */
private DavResource getResourceFromHref(String href) throws DavException {
    // build a new locator: remove trailing prefix
    DavResourceLocator locator = getLocator();
    String prefix = locator.getPrefix();
    DavResourceLocator loc = locator.getFactory().createResourceLocator(prefix, href);
    // create a new resource object
    try {
        DavResource res;
        if (getRepositorySession().itemExists(loc.getRepositoryPath())) {
            res = createResourceFromLocator(loc);
        } else {
            throw new DavException(DavServletResponse.SC_NOT_FOUND);
        }
        return res;
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 30 with DavResourceLocator

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

the class DavResourceFactoryImpl method createResource.

/**
     * Create a new <code>DavResource</code> from the specified locator and request
     * objects. Note, that in contrast to
     * {@link #createResource(DavResourceLocator, DavSession)} the locator may
     * point to a non-existing resource.
     * <p>
     * If the request contains a {@link org.apache.jackrabbit.webdav.version.DeltaVServletRequest#getLabel()
     * Label header}, the resource is build from the indicated
     * {@link org.apache.jackrabbit.webdav.version.VersionResource version} instead.
     *
     * @param locator
     * @param request
     * @param response
     * @return
     * @see DavResourceFactory#createResource(org.apache.jackrabbit.webdav.DavResourceLocator, org.apache.jackrabbit.webdav.DavServletRequest, org.apache.jackrabbit.webdav.DavServletResponse)
     */
public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavServletResponse response) throws DavException {
    JcrDavSession.checkImplementation(request.getDavSession());
    JcrDavSession session = (JcrDavSession) request.getDavSession();
    DavResource resource;
    String type = request.getParameter("type");
    if (locator.isRootLocation()) {
        // root
        resource = new RootCollection(locator, session, this);
    } else if ("journal".equals(type) && locator.getResourcePath().equals(locator.getWorkspacePath())) {
        // feed/event journal resource
        try {
            EventJournal ej = session.getRepositorySession().getWorkspace().getObservationManager().getEventJournal();
            if (ej == null) {
                throw new DavException(HttpServletResponse.SC_NOT_IMPLEMENTED, "event journal not supported");
            }
            resource = new EventJournalResourceImpl(ej, locator, session, request, this);
        } catch (AccessDeniedException ex) {
            // EventJournal only allowed for admin?
            throw new DavException(HttpServletResponse.SC_UNAUTHORIZED, ex);
        } catch (RepositoryException ex) {
            throw new DavException(HttpServletResponse.SC_BAD_REQUEST, ex);
        }
    } else if (locator.getResourcePath().equals(locator.getWorkspacePath())) {
        // workspace resource
        resource = new WorkspaceResourceImpl(locator, session, this);
    } else {
        // resource corresponds to a repository item
        try {
            resource = createResourceForItem(locator, session);
            Item item = getItem(session, locator);
            boolean versionable = item.isNode() && ((Node) item).isNodeType(JcrConstants.MIX_VERSIONABLE);
            /* if the created resource is version-controlled and the request
                contains a Label header, the corresponding Version must be used
                instead.*/
            if (request instanceof DeltaVServletRequest && versionable) {
                String labelHeader = ((DeltaVServletRequest) request).getLabel();
                if (labelHeader != null && DavMethods.isMethodAffectedByLabel(request) && isVersionControlled(resource)) {
                    Version v = ((Node) item).getVersionHistory().getVersionByLabel(labelHeader);
                    DavResourceLocator vloc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), v.getPath(), false);
                    resource = new VersionItemCollection(vloc, session, this, v);
                }
            }
        } catch (PathNotFoundException e) {
            /* item does not exist yet: create the default resources
                Note: MKCOL request forces a collection-resource even if there already
                exists a repository-property with the given path. the MKCOL will
                in that particular case fail with a 405 (method not allowed).*/
            if (DavMethods.getMethodCode(request.getMethod()) == DavMethods.DAV_MKCOL) {
                resource = new VersionControlledItemCollection(locator, session, this, null);
            } else {
                resource = new DefaultItemResource(locator, session, this, null);
            }
        } catch (RepositoryException e) {
            log.error("Failed to build resource from item '" + locator.getRepositoryPath() + "'");
            throw new JcrDavException(e);
        }
    }
    if (request instanceof TransactionDavServletRequest && resource instanceof TransactionResource) {
        ((TransactionResource) resource).init(txMgr, ((TransactionDavServletRequest) request).getTransactionId());
    }
    if (resource instanceof ObservationResource) {
        ((ObservationResource) resource).init(subsMgr);
    }
    return resource;
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException) TransactionResource(org.apache.jackrabbit.webdav.transaction.TransactionResource) EventJournal(javax.jcr.observation.EventJournal) Item(javax.jcr.Item) Version(javax.jcr.version.Version) TransactionDavServletRequest(org.apache.jackrabbit.webdav.transaction.TransactionDavServletRequest) ObservationResource(org.apache.jackrabbit.webdav.observation.ObservationResource) DeltaVServletRequest(org.apache.jackrabbit.webdav.version.DeltaVServletRequest) VersionItemCollection(org.apache.jackrabbit.webdav.jcr.version.VersionItemCollection) PathNotFoundException(javax.jcr.PathNotFoundException) 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