Search in sources :

Example 6 with HrefProperty

use of org.apache.jackrabbit.webdav.property.HrefProperty in project jackrabbit by apache.

the class VersionControlledItemCollection method initProperties.

/**
 * Fill the property set for this resource.
 */
@Override
protected void initProperties() {
    super.initProperties();
    if (isVersionControlled()) {
        Node n = (Node) item;
        // workspace property already set in AbstractResource.initProperties()
        try {
            // DAV:version-history (computed)
            String vhHref = getLocatorFromItem(n.getVersionHistory()).getHref(true);
            properties.add(new HrefProperty(VERSION_HISTORY, vhHref, true));
            // DAV:auto-version property: there is no auto version, explicit CHECKOUT is required.
            properties.add(new DefaultDavProperty<String>(AUTO_VERSION, null, false));
            String baseVHref = getLocatorFromItem(n.getBaseVersion()).getHref(true);
            if (n.isCheckedOut()) {
                // DAV:predecessors property
                if (n.hasProperty(JcrConstants.JCR_PREDECESSORS)) {
                    Value[] predec = n.getProperty(JcrConstants.JCR_PREDECESSORS).getValues();
                    addHrefProperty(PREDECESSOR_SET, predec, false);
                }
                // being set results in an exception on failure.
                if (n.hasProperty(JcrConstants.JCR_MERGEFAILED)) {
                    Value[] mergeFailed = n.getProperty(JcrConstants.JCR_MERGEFAILED).getValues();
                    addHrefProperty(AUTO_MERGE_SET, mergeFailed, false);
                }
            // todo: checkout-fork, checkin-fork
            }
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
    }
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Node(javax.jcr.Node) Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException)

Example 7 with HrefProperty

use of org.apache.jackrabbit.webdav.property.HrefProperty in project jackrabbit by apache.

the class CompareBaselineReport method getVersions.

private void getVersions(DavResource collection, List<VersionResource> vList) throws DavException {
    DavResourceIterator it = collection.getMembers();
    while (it.hasNext()) {
        DavResource member = it.nextResource();
        if (member instanceof VersionControlledResource) {
            String href = new HrefProperty(member.getProperty(VersionControlledResource.CHECKED_IN)).getHrefs().get(0);
            DavResourceLocator locator = member.getLocator();
            DavResourceLocator vLocator = locator.getFactory().createResourceLocator(locator.getPrefix(), href);
            DavResource v = member.getFactory().createResource(vLocator, member.getSession());
            if (v instanceof VersionResource) {
                vList.add((VersionResource) v);
            } else {
                log.error("Internal error: DAV:checked-in property must point to a VersionResource.");
            }
        }
        if (member.isCollection()) {
            getVersions(member, vList);
        }
    }
}
Also used : DavResourceIterator(org.apache.jackrabbit.webdav.DavResourceIterator) DavResource(org.apache.jackrabbit.webdav.DavResource) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) VersionResource(org.apache.jackrabbit.webdav.version.VersionResource) VersionControlledResource(org.apache.jackrabbit.webdav.version.VersionControlledResource) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 8 with HrefProperty

use of org.apache.jackrabbit.webdav.property.HrefProperty in project jackrabbit by apache.

the class ExpandPropertyReport method getResponse.

/**
 * Builds a <code>MultiStatusResponse</code> for the given resource respecting
 * the properties specified. Any property that represents a {@link HrefProperty}
 * is expanded: It's name equals the name of a valid {@link HrefProperty}.
 * However the value of that given property (consisting of one or multiple DAV:href elements)
 * is replaced by the Xml representation of a separate
 * {@link MultiStatusResponse multistatus responses} for the
 * resource referenced by the given DAV:href elements. The responses may
 * themselves have properties, which are defined by the separate list.
 *
 * @param res
 * @param propertyElements
 * @return <code>MultiStatusResponse</code> for the given resource.
 * @see ExpandProperty
 */
private MultiStatusResponse getResponse(DavResource res, Iterator<Element> propertyElements) {
    MultiStatusResponse resp = new MultiStatusResponse(res.getHref(), null);
    while (propertyElements.hasNext()) {
        Element propertyElem = propertyElements.next();
        // retrieve the localName present in the "name" attribute
        String nameAttr = propertyElem.getAttribute(ATTR_NAME);
        if (nameAttr == null || "".equals(nameAttr)) {
            // NOTE: this is not valid according to the DTD
            continue;
        }
        // retrieve the namespace present in the "namespace" attribute
        // NOTE: if this attribute is missing the DAV: namespace represents the default.
        String namespaceAttr = propertyElem.getAttribute(ATTR_NAMESPACE);
        Namespace namespace = (namespaceAttr != null) ? Namespace.getNamespace(namespaceAttr) : NAMESPACE;
        DavPropertyName propName = DavPropertyName.create(nameAttr, namespace);
        DavProperty<?> p = res.getProperty(propName);
        if (p != null) {
            if (p instanceof HrefProperty && res instanceof DeltaVResource) {
                ElementIterator it = DomUtil.getChildren(propertyElem, XML_PROPERTY, NAMESPACE);
                resp.add(new ExpandProperty((DeltaVResource) res, (HrefProperty) p, it));
            } else {
                resp.add(p);
            }
        } else {
            resp.add(propName, DavServletResponse.SC_NOT_FOUND);
        }
    }
    return resp;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Element(org.w3c.dom.Element) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) DeltaVResource(org.apache.jackrabbit.webdav.version.DeltaVResource) Namespace(org.apache.jackrabbit.webdav.xml.Namespace) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Example 9 with HrefProperty

use of org.apache.jackrabbit.webdav.property.HrefProperty 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 10 with HrefProperty

use of org.apache.jackrabbit.webdav.property.HrefProperty 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

HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)20 RepositoryException (javax.jcr.RepositoryException)14 DavException (org.apache.jackrabbit.webdav.DavException)7 DefaultDavProperty (org.apache.jackrabbit.webdav.property.DefaultDavProperty)7 Node (javax.jcr.Node)6 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)6 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 Version (javax.jcr.version.Version)4 HttpResponse (org.apache.http.HttpResponse)4 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)4 Value (javax.jcr.Value)3 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)3 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)3 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)3 Property (javax.jcr.Property)2 PropertyIterator (javax.jcr.PropertyIterator)2 VersionHistory (javax.jcr.version.VersionHistory)2 VersionIterator (javax.jcr.version.VersionIterator)2 NodeId (org.apache.jackrabbit.spi.NodeId)2