Search in sources :

Example 76 with DavException

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

the class VersionControlledItemCollection method checkin.

//--------------------------------< VersionControlledResource interface >---
/**
     * Calls {@link javax.jcr.Node#checkin()} on the underlying repository node.
     *
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#checkin()
     */
@Override
public String checkin() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    if (!isVersionControlled()) {
        throw new DavException(DavServletResponse.SC_METHOD_NOT_ALLOWED);
    }
    try {
        Version v = getVersionManager().checkin(item.getPath());
        String versionHref = getLocatorFromItem(v).getHref(true);
        return versionHref;
    } catch (RepositoryException e) {
        // UnsupportedRepositoryException should not occur
        throw new JcrDavException(e);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Version(javax.jcr.version.Version) RepositoryException(javax.jcr.RepositoryException)

Example 77 with DavException

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

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

the class NodeTypesReport method getNodeTypes.

/**
     * Parse the Xml element in the info object an return an interator over
     * the specified node types.
     *
     * @return
     * @throws RepositoryException
     * @throws DavException
     */
private static NodeTypeIterator getNodeTypes(Session session, ReportInfo info) throws RepositoryException, DavException {
    NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
    // check the simple types first...
    if (info.containsContentElement(XML_REPORT_ALLNODETYPES, ItemResourceConstants.NAMESPACE)) {
        return ntMgr.getAllNodeTypes();
    } else if (info.containsContentElement(XML_REPORT_MIXINNODETYPES, ItemResourceConstants.NAMESPACE)) {
        return ntMgr.getMixinNodeTypes();
    } else if (info.containsContentElement(XML_REPORT_PRIMARYNODETYPES, ItemResourceConstants.NAMESPACE)) {
        return ntMgr.getPrimaryNodeTypes();
    } else {
        // None of the simple types. test if a report for individual
        // nodetype was request. If not, the request body is not valid.
        List<Element> elemList = info.getContentElements(XML_NODETYPE, ItemResourceConstants.NAMESPACE);
        if (elemList.isEmpty()) {
            // throw exception if the request body does not contain a single nodetype element
            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "NodeTypes report: request body has invalid format.");
        }
        // todo: find better solution...
        List<NodeType> ntList = new ArrayList<NodeType>();
        for (Element el : elemList) {
            String nodetypeName = DomUtil.getChildTextTrim(el, XML_NODETYPENAME, ItemResourceConstants.NAMESPACE);
            if (nodetypeName != null) {
                ntList.add(ntMgr.getNodeType(nodetypeName));
            }
        }
        return new NodeTypeIteratorAdapter(ntList);
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) Element(org.w3c.dom.Element) NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) NodeTypeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)

Example 79 with DavException

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

the class TxLockManagerImpl method refreshLock.

/**
     * Reset the timeout of the lock identified by the given lock token.
     *
     * @param lockInfo
     * @param lockToken
     * @param resource
     * @return
     * @throws DavException if the lock did not exist or is expired.
     */
private synchronized ActiveLock refreshLock(LockInfo lockInfo, String lockToken, TransactionResource resource) throws DavException {
    TransactionMap responsibleMap = getMap(resource);
    Transaction tx = responsibleMap.get(lockToken);
    if (tx == null) {
        throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "No valid transaction lock found for resource '" + resource.getResourcePath() + "'");
    } else if (tx.getLock().isExpired()) {
        removeExpired(tx, responsibleMap, resource);
        throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Transaction lock for resource '" + resource.getResourcePath() + "' was already expired.");
    } else {
        tx.getLock().setTimeout(lockInfo.getTimeout());
    }
    return tx.getLock();
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException)

Example 80 with DavException

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

the class AbstractJcrReport method init.

/**
     * Performs basic validation checks common to all JCR specific reports.
     *
     * @param resource
     * @param info
     * @throws DavException
     * @see Report#init(DavResource, ReportInfo)
     */
public void init(DavResource resource, ReportInfo info) throws DavException {
    if (resource == null || info == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Unable to run report: WebDAV Resource and ReportInfo must not be null.");
    }
    if (!getType().isRequestedReportType(info)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Expected report type: '" + getType().getReportName() + "', found: '" + info.getReportName() + ";" + "'.");
    }
    if (info.getDepth() > DavConstants.DEPTH_0) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid Depth header: " + info.getDepth());
    }
    DavSession davSession = resource.getSession();
    if (davSession == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "The resource must provide a non-null session object in order to create '" + getType().getReportName() + "' report.");
    }
    session = JcrDavSession.getRepositorySession(resource.getSession());
    if (session == null) {
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal error: Unable to access repository session.");
    }
    reportInfo = info;
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) DavSession(org.apache.jackrabbit.webdav.DavSession)

Aggregations

DavException (org.apache.jackrabbit.webdav.DavException)129 RepositoryException (javax.jcr.RepositoryException)89 IOException (java.io.IOException)51 HttpResponse (org.apache.http.HttpResponse)47 Element (org.w3c.dom.Element)29 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)25 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)25 DavResource (org.apache.jackrabbit.webdav.DavResource)21 ArrayList (java.util.ArrayList)19 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)17 Node (javax.jcr.Node)16 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)15 ItemNotFoundException (javax.jcr.ItemNotFoundException)13 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)13 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)12 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)12 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)8 Document (org.w3c.dom.Document)8 Session (javax.jcr.Session)7 Version (javax.jcr.version.Version)7