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);
}
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();
}
}
}
Aggregations