Search in sources :

Example 96 with DavException

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

the class DefaultItemCollection method buildValuesProperty.

/**
     * Tries to parse the given input stream as xml document and build a
     * {@link ValuesProperty} out of it.
     *
     * @param in
     * @return values property or 'null' if the given stream cannot be parsed
     * into an XML document or if build the property fails.
     */
private ValuesProperty buildValuesProperty(InputStream in) {
    String errorMsg = "Cannot parse stream into a 'ValuesProperty'.";
    try {
        Document reqBody = DomUtil.parseDocument(in);
        DavProperty<?> defaultProp = DefaultDavProperty.createFromXml(reqBody.getDocumentElement());
        ValuesProperty vp = new ValuesProperty(defaultProp, PropertyType.STRING, getRepositorySession().getValueFactory());
        return vp;
    } catch (IOException e) {
        log.debug(errorMsg, e);
    } catch (ParserConfigurationException e) {
        log.debug(errorMsg, e);
    } catch (SAXException e) {
        log.debug(errorMsg, e);
    } catch (DavException e) {
        log.debug(errorMsg, e);
    } catch (RepositoryException e) {
        log.debug(errorMsg, e);
    }
    // cannot parse request body into a 'values' property
    return null;
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) ValuesProperty(org.apache.jackrabbit.webdav.jcr.property.ValuesProperty) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 97 with DavException

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

the class AbstractItemResource method getCollection.

/**
     * Returns the resource representing the parent item of the repository item
     * represented by this resource. If this resoure represents the root item
     * a {@link RootCollection} is returned.
     *
     * @return the collection this resource is internal member of. Except for the
     * repository root, the returned collection always represent the parent
     * repository node.
     * @see org.apache.jackrabbit.webdav.DavResource#getCollection()
     */
@Override
public DavResource getCollection() {
    DavResource collection = null;
    String parentPath = Text.getRelativeParent(getResourcePath(), 1);
    DavResourceLocator parentLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), getLocator().getWorkspacePath(), parentPath);
    try {
        collection = createResourceFromLocator(parentLoc);
    } catch (DavException e) {
        log.error("Unexpected error while retrieving collection: " + e.getMessage());
    }
    return collection;
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 98 with DavException

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

the class AbstractItemResource method copy.

/**
     * Copies the underlying repository item to the indicated destination. If
     * the locator of the specified destination resource indicates a different
     * workspace, {@link Workspace#copy(String, String, String)} is used to perform
     * the copy operation, {@link Workspace#copy(String, String)} otherwise.
     * <p>
     * Note, that this implementation does not support shallow copy.
     *
     * @param destination
     * @param shallow
     * @throws DavException
     * @see DavResource#copy(DavResource, boolean)
     * @see Workspace#copy(String, String)
     * @see Workspace#copy(String, String, String)
     */
@Override
public void copy(DavResource destination, boolean shallow) throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    // TODO: support shallow and deep copy is required by RFC 2518
    if (shallow) {
        throw new DavException(DavServletResponse.SC_FORBIDDEN, "Unable to perform shallow copy.");
    }
    try {
        String itemPath = getLocator().getRepositoryPath();
        String destItemPath = destination.getLocator().getRepositoryPath();
        Workspace workspace = getRepositorySession().getWorkspace();
        if (getLocator().isSameWorkspace(destination.getLocator())) {
            workspace.copy(itemPath, destItemPath);
        } else {
            log.error("Copy between workspaces is not yet implemented (src: '" + getHref() + "', dest: '" + destination.getHref() + "')");
            throw new DavException(DavServletResponse.SC_NOT_IMPLEMENTED);
        }
    } catch (PathNotFoundException e) {
        // according to RFC 2518, should not occur
        throw new DavException(DavServletResponse.SC_NOT_FOUND, 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) Workspace(javax.jcr.Workspace)

Example 99 with DavException

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

the class RepositoryServiceImpl method isGranted.

@Override
public boolean isGranted(SessionInfo sessionInfo, ItemId itemId, String[] actions) throws RepositoryException {
    HttpReport request = null;
    try {
        String uri = obtainAbsolutePathFromUri(getItemUri(itemId, sessionInfo));
        ReportInfo reportInfo = new ReportInfo(JcrRemotingConstants.REPORT_PRIVILEGES, ItemResourceConstants.NAMESPACE);
        reportInfo.setContentElement(DomUtil.hrefToXml(uri, DomUtil.createDocument()));
        request = new HttpReport(uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName()), reportInfo);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] responses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (responses.length < 1) {
            throw new ItemNotFoundException("Unable to retrieve permissions for item " + saveGetIdString(itemId, sessionInfo));
        }
        DavProperty<?> p = responses[0].getProperties(DavServletResponse.SC_OK).get(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
        if (p == null) {
            return false;
        }
        // build set of privileges from given actions. NOTE: since the actions
        // have no qualifying namespace, the {@link ItemResourceConstants#NAMESPACE}
        // is used.
        Set<Privilege> requiredPrivileges = new HashSet<Privilege>();
        for (String action : actions) {
            requiredPrivileges.add(Privilege.getPrivilege(action, ItemResourceConstants.NAMESPACE));
        }
        // build set of privileges granted to the current user.
        CurrentUserPrivilegeSetProperty privSet = new CurrentUserPrivilegeSetProperty(p);
        Collection<Privilege> privileges = privSet.getValue();
        // check privileges present against required privileges.
        return privileges.containsAll(requiredPrivileges);
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (ParserConfigurationException 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) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ReportInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) CurrentUserPrivilegeSetProperty(org.apache.jackrabbit.webdav.security.CurrentUserPrivilegeSetProperty) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SupportedPrivilege(org.apache.jackrabbit.webdav.security.SupportedPrivilege) Privilege(org.apache.jackrabbit.webdav.security.Privilege) ItemNotFoundException(javax.jcr.ItemNotFoundException) HashSet(java.util.HashSet)

Example 100 with DavException

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

the class RepositoryServiceImpl method poll.

private EventBundle[] poll(String uri, String subscriptionId, long timeout, SessionInfoImpl sessionInfo) throws RepositoryException {
    HttpPoll request = null;
    try {
        request = new HttpPoll(uri, subscriptionId, timeout);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        EventDiscovery disc = request.getResponseBodyAsEventDiscovery(response);
        EventBundle[] events;
        if (disc.isEmpty()) {
            events = new EventBundle[0];
        } else {
            Element discEl = disc.toXml(DomUtil.createDocument());
            ElementIterator it = DomUtil.getChildren(discEl, ObservationConstants.N_EVENTBUNDLE);
            List<EventBundle> bundles = new ArrayList<EventBundle>();
            while (it.hasNext()) {
                Element bundleElement = it.nextElement();
                String value = DomUtil.getAttribute(bundleElement, ObservationConstants.XML_EVENT_LOCAL, null);
                // check if it matches a batch id recently submitted
                boolean isLocal = false;
                if (value != null) {
                    isLocal = Boolean.parseBoolean(value);
                }
                bundles.add(new EventBundleImpl(buildEventList(bundleElement, sessionInfo, uri), isLocal));
            }
            events = bundles.toArray(new EventBundle[bundles.size()]);
        }
        return events;
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (ParserConfigurationException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) EventBundle(org.apache.jackrabbit.spi.EventBundle) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) HttpPoll(org.apache.jackrabbit.webdav.client.methods.HttpPoll) EventDiscovery(org.apache.jackrabbit.webdav.observation.EventDiscovery) EventBundleImpl(org.apache.jackrabbit.spi.commons.EventBundleImpl) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

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