Search in sources :

Example 21 with QItemDefinition

use of org.apache.jackrabbit.spi.QItemDefinition in project jackrabbit by apache.

the class ItemStateValidator method checkRemoveConstraints.

/**
     * An item state cannot be removed if it is protected.
     *
     * @param itemState
     * @throws ConstraintViolationException
     * @see #checkProtection(ItemState)
     */
private void checkRemoveConstraints(ItemState itemState) throws ConstraintViolationException, RepositoryException {
    QItemDefinition definition;
    if (itemState.isNode()) {
        definition = ((NodeState) itemState).getDefinition();
    } else {
        definition = ((PropertyState) itemState).getDefinition();
    }
    checkProtection(definition);
}
Also used : QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition)

Example 22 with QItemDefinition

use of org.apache.jackrabbit.spi.QItemDefinition in project jackrabbit by apache.

the class RepositoryServiceImpl method getItemDefinition.

/**
     *
     * @param sessionInfo
     * @param itemId
     * @return
     * @throws RepositoryException
     */
private QItemDefinition getItemDefinition(SessionInfo sessionInfo, ItemId itemId) throws RepositoryException {
    // set of properties to be retrieved
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_DEFINITION_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(DavPropertyName.RESOURCETYPE);
    HttpPropfind request = null;
    try {
        String uri = getItemUri(itemId, sessionInfo);
        request = new HttpPropfind(uri, nameSet, DEPTH_0);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length < 1) {
            throw new ItemNotFoundException("Unable to retrieve the item definition for " + saveGetIdString(itemId, sessionInfo));
        }
        if (mresponses.length > 1) {
            throw new RepositoryException("Internal error: ambigous item definition found '" + saveGetIdString(itemId, sessionInfo) + "'.");
        }
        DavPropertySet propertySet = mresponses[0].getProperties(DavServletResponse.SC_OK);
        // check if definition matches the type of the id
        DavProperty<?> rType = propertySet.get(DavPropertyName.RESOURCETYPE);
        if (rType.getValue() == null && itemId.denotesNode()) {
            throw new RepositoryException("Internal error: requested node definition and got property definition.");
        }
        NamePathResolver resolver = getNamePathResolver(sessionInfo);
        // build the definition
        QItemDefinition definition = null;
        DavProperty<?> prop = propertySet.get(JcrRemotingConstants.JCR_DEFINITION_LN, ItemResourceConstants.NAMESPACE);
        if (prop != null) {
            Object value = prop.getValue();
            if (value != null && value instanceof Element) {
                Element idfElem = (Element) value;
                if (itemId.denotesNode()) {
                    definition = DefinitionUtil.createQNodeDefinition(null, idfElem, resolver);
                } else {
                    definition = DefinitionUtil.createQPropertyDefinition(null, idfElem, resolver, getQValueFactory());
                }
            }
        }
        if (definition == null) {
            throw new RepositoryException("Unable to retrieve definition for item with id '" + saveGetIdString(itemId, resolver) + "'.");
        }
        return definition;
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Aggregations

QItemDefinition (org.apache.jackrabbit.spi.QItemDefinition)22 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 Name (org.apache.jackrabbit.spi.Name)10 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)9 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)9 ArrayList (java.util.ArrayList)7 RepositoryException (javax.jcr.RepositoryException)6 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)6 NodeState (org.apache.jackrabbit.core.state.NodeState)5 HashSet (java.util.HashSet)4 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)4 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)4 AccessDeniedException (javax.jcr.AccessDeniedException)3 ItemNotFoundException (javax.jcr.ItemNotFoundException)3 NodeId (org.apache.jackrabbit.core.id.NodeId)3 PropertyId (org.apache.jackrabbit.core.id.PropertyId)3 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)3 NodeTypeRegistry (org.apache.jackrabbit.core.nodetype.NodeTypeRegistry)3 AccessManager (org.apache.jackrabbit.core.security.AccessManager)3 PropertyState (org.apache.jackrabbit.core.state.PropertyState)3