Search in sources :

Example 36 with DavException

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

the class LocateByHistoryReport method setInfo.

/**
 * Set the <code>ReportInfo</code>
 *
 * @param info
 * @throws DavException if the given <code>ReportInfo</code>
 * does not contain a DAV:version-tree element.
 */
private void setInfo(ReportInfo info) throws DavException {
    if (info == null || !getType().isRequestedReportType(info)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:locate-by-history element expected.");
    }
    Element versionHistorySet = info.getContentElement(XML_VERSION_HISTORY_SET, NAMESPACE);
    if (versionHistorySet == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "The DAV:locate-by-history element must contain a DAV:version-history-set child.");
    }
    ElementIterator it = DomUtil.getChildren(versionHistorySet, DavConstants.XML_HREF, DavConstants.NAMESPACE);
    while (it.hasNext()) {
        String href = DomUtil.getText(it.nextElement());
        if (href != null) {
            vhHrefSet.add(href);
        }
    }
    this.info = info;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element)

Example 37 with DavException

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

the class PrincipalSearchReport method init.

/**
 * @see Report#init(DavResource, ReportInfo)
 */
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
    super.init(resource, info);
    // make sure the request body contains all mandatory elements
    if (!info.containsContentElement(XML_PROPERTY_SEARCH, SecurityConstants.NAMESPACE)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Request body must contain at least a single DAV:property-search element.");
    }
    List<Element> psElements = info.getContentElements(XML_PROPERTY_SEARCH, SecurityConstants.NAMESPACE);
    searchArguments = new SearchArgument[psElements.size()];
    int i = 0;
    for (Element psElement : psElements) {
        searchArguments[i++] = new SearchArgument(psElement);
    }
    if (info.containsContentElement(XML_APPLY_TO_PRINCIPAL_COLLECTION_SET, SecurityConstants.NAMESPACE)) {
        HrefProperty p = new HrefProperty(resource.getProperty(SecurityConstants.PRINCIPAL_COLLECTION_SET));
        searchRoots = p.getHrefs().toArray(new String[0]);
    } else {
        searchRoots = new String[] { resource.getHref() };
    }
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element)

Example 38 with DavException

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

the class OptionsInfo method createFromXml.

/**
 * Build an <code>OptionsInfo</code> object from the root element present
 * in the request body.
 *
 * @param optionsElement
 * @return
 * @throws DavException if the optionsElement is <code>null</code>
 * or not a DAV:options element.
 */
public static OptionsInfo createFromXml(Element optionsElement) throws DavException {
    if (!DomUtil.matches(optionsElement, DeltaVConstants.XML_OPTIONS, DeltaVConstants.NAMESPACE)) {
        log.warn("DAV:options element expected");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    OptionsInfo oInfo = new OptionsInfo();
    ElementIterator it = DomUtil.getChildren(optionsElement);
    while (it.hasNext()) {
        // todo: not correct since assuming its the deltaV-namespace
        oInfo.entriesLocalNames.add(it.nextElement().getLocalName());
    }
    return oInfo;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException)

Example 39 with DavException

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

the class RepositoryServiceImpl method getRegisteredNamespaces.

@Override
public Map<String, String> getRegisteredNamespaces(SessionInfo sessionInfo) throws RepositoryException {
    ReportInfo info = new ReportInfo(JcrRemotingConstants.REPORT_REGISTERED_NAMESPACES, ItemResourceConstants.NAMESPACE);
    HttpReport request = null;
    try {
        request = new HttpReport(uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName()), info);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        Document doc = request.getResponseBodyAsDocument(response.getEntity());
        Map<String, String> namespaces = new HashMap<String, String>();
        if (doc != null) {
            Element rootElement = doc.getDocumentElement();
            ElementIterator nsElems = DomUtil.getChildren(rootElement, JcrRemotingConstants.XML_NAMESPACE, ItemResourceConstants.NAMESPACE);
            while (nsElems.hasNext()) {
                Element elem = nsElems.nextElement();
                String prefix = DomUtil.getChildText(elem, JcrRemotingConstants.XML_PREFIX, ItemResourceConstants.NAMESPACE);
                String uri = DomUtil.getChildText(elem, JcrRemotingConstants.XML_URI, ItemResourceConstants.NAMESPACE);
                // default namespace
                if (prefix == null && uri == null) {
                    prefix = uri = "";
                }
                // any other uri must not be null
                if (uri != null) {
                    namespaces.put(prefix, uri);
                    // TODO: not correct since nsRegistry is retrieved from each session
                    nsCache.add(prefix, uri);
                } else {
                    log.error("Invalid prefix / uri pair: " + prefix + " -> " + uri);
                }
            }
        }
        return namespaces;
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : HttpReport(org.apache.jackrabbit.webdav.client.methods.HttpReport) ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) ReportInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Document(org.w3c.dom.Document)

Example 40 with DavException

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

the class RepositoryServiceImpl method resolveMergeConflict.

@Override
public void resolveMergeConflict(SessionInfo sessionInfo, NodeId nodeId, NodeId[] mergeFailedIds, NodeId[] predecessorIds) throws RepositoryException {
    HttpProppatch request = null;
    try {
        List<HrefProperty> changeList = new ArrayList<HrefProperty>();
        String[] mergeFailedHref = new String[mergeFailedIds.length];
        for (int i = 0; i < mergeFailedIds.length; i++) {
            mergeFailedHref[i] = getItemUri(mergeFailedIds[i], sessionInfo);
        }
        changeList.add(new HrefProperty(VersionControlledResource.AUTO_MERGE_SET, mergeFailedHref, false));
        if (predecessorIds != null && predecessorIds.length > 0) {
            String[] pdcHrefs = new String[predecessorIds.length];
            for (int i = 0; i < predecessorIds.length; i++) {
                pdcHrefs[i] = getItemUri(predecessorIds[i], sessionInfo);
            }
            changeList.add(new HrefProperty(VersionControlledResource.PREDECESSOR_SET, pdcHrefs, false));
        }
        request = new HttpProppatch(getItemUri(nodeId, sessionInfo), changeList);
        initMethod(request, sessionInfo, !isUnLockMethod(request));
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : HttpProppatch(org.apache.jackrabbit.webdav.client.methods.HttpProppatch) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavException(org.apache.jackrabbit.webdav.DavException) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Aggregations

DavException (org.apache.jackrabbit.webdav.DavException)157 RepositoryException (javax.jcr.RepositoryException)89 IOException (java.io.IOException)61 HttpResponse (org.apache.http.HttpResponse)47 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)34 DavResource (org.apache.jackrabbit.webdav.DavResource)30 Element (org.w3c.dom.Element)29 ArrayList (java.util.ArrayList)25 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)25 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)18 Node (javax.jcr.Node)16 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)15 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)14 ItemNotFoundException (javax.jcr.ItemNotFoundException)13 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)12 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)12 Path (java.nio.file.Path)11 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)10 Test (org.junit.Test)9 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)8