use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class RepositoryServiceImpl method getPropertyInfo.
@Override
public PropertyInfo getPropertyInfo(SessionInfo sessionInfo, PropertyId propertyId) throws RepositoryException {
HttpGet request = null;
try {
String uri = getItemUri(propertyId, sessionInfo);
request = new HttpGet(uri);
HttpResponse response = executeRequest(sessionInfo, request);
int status = response.getStatusLine().getStatusCode();
if (status != DavServletResponse.SC_OK) {
throw ExceptionConverter.generate(new DavException(status, response.getStatusLine().getReasonPhrase()));
}
Path path = uriResolver.getQPath(uri, sessionInfo);
HttpEntity entity = response.getEntity();
ContentType ct = ContentType.get(entity);
boolean isMultiValued;
QValue[] values;
int type;
NamePathResolver resolver = getNamePathResolver(sessionInfo);
if (ct != null && ct.getMimeType().startsWith("jcr-value")) {
type = JcrValueType.typeFromContentType(ct.getMimeType());
QValue v;
if (type == PropertyType.BINARY) {
v = getQValueFactory().create(entity.getContent());
} else {
Reader reader = new InputStreamReader(entity.getContent(), ct.getCharset());
StringBuffer sb = new StringBuffer();
int c;
while ((c = reader.read()) > -1) {
sb.append((char) c);
}
Value jcrValue = valueFactory.createValue(sb.toString(), type);
if (jcrValue instanceof QValueValue) {
v = ((QValueValue) jcrValue).getQValue();
} else {
v = ValueFormat.getQValue(jcrValue, resolver, getQValueFactory());
}
}
values = new QValue[] { v };
isMultiValued = false;
} else if (ct != null && ct.getMimeType().equals("text/xml")) {
// jcr:values property spooled
values = getValues(entity.getContent(), resolver, propertyId);
type = (values.length > 0) ? values[0].getType() : loadType(uri, getClient(sessionInfo), propertyId, sessionInfo, resolver);
isMultiValued = true;
} else {
throw new ItemNotFoundException("Unable to retrieve the property with id " + saveGetIdString(propertyId, resolver));
}
return new PropertyInfoImpl(propertyId, path, type, isMultiValued, values);
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} catch (NameException e) {
throw new RepositoryException(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class RepositoryServiceImpl method getChildInfos.
@Override
public Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws RepositoryException {
// set of properties to be retrieved
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_INDEX_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_UUID_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(DavPropertyName.RESOURCETYPE);
HttpPropfind request = null;
try {
String uri = getItemUri(parentId, sessionInfo);
request = new HttpPropfind(uri, nameSet, DEPTH_1);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
List<ChildInfo> childEntries;
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length < 1) {
throw new ItemNotFoundException("Unable to retrieve the node with id " + saveGetIdString(parentId, sessionInfo));
} else if (mresponses.length == 1) {
// no child nodes nor properties
childEntries = Collections.emptyList();
return childEntries.iterator();
}
childEntries = new ArrayList<ChildInfo>();
for (MultiStatusResponse mresponse : mresponses) {
if (!isSameResource(uri, mresponse)) {
DavPropertySet childProps = mresponse.getProperties(DavServletResponse.SC_OK);
if (childProps.contains(DavPropertyName.RESOURCETYPE) && childProps.get(DavPropertyName.RESOURCETYPE).getValue() != null) {
childEntries.add(buildChildInfo(childProps, sessionInfo));
}
// else: property -> ignore
}
// else: ignore the response related to the parent
}
return childEntries.iterator();
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class ExceptionConverter method generate.
public static RepositoryException generate(DavException davExc, int methodCode, String name) {
String msg = davExc.getMessage();
if (davExc.hasErrorCondition()) {
try {
Element error = davExc.toXml(DomUtil.createDocument());
if (DomUtil.matches(error, DavException.XML_ERROR, DavConstants.NAMESPACE)) {
if (DomUtil.hasChildElement(error, "exception", null)) {
Element exc = DomUtil.getChildElement(error, "exception", null);
if (DomUtil.hasChildElement(exc, "message", null)) {
msg = DomUtil.getChildText(exc, "message", null);
}
if (DomUtil.hasChildElement(exc, "class", null)) {
Class<?> cl = Class.forName(DomUtil.getChildText(exc, "class", null));
Constructor<?> excConstr = cl.getConstructor(String.class);
if (excConstr != null) {
Object o = excConstr.newInstance(msg);
if (o instanceof PathNotFoundException && methodCode == DavMethods.DAV_POST) {
// see JCR-2536
return new InvalidItemStateException(msg);
} else if (o instanceof RepositoryException) {
return (RepositoryException) o;
} else if (o instanceof Exception) {
return new RepositoryException(msg, (Exception) o);
}
}
}
}
}
} catch (Exception e) {
return new RepositoryException(e);
}
}
// make sure an exception is generated
switch(davExc.getErrorCode()) {
// TODO: mapping DAV_error to jcr-exception is ambiguous. to be improved
case DavServletResponse.SC_NOT_FOUND:
switch(methodCode) {
case DavMethods.DAV_DELETE:
case DavMethods.DAV_MKCOL:
case DavMethods.DAV_PUT:
case DavMethods.DAV_POST:
// been made.
return new InvalidItemStateException(msg, davExc);
default:
return new ItemNotFoundException(msg, davExc);
}
case DavServletResponse.SC_LOCKED:
return new LockException(msg, davExc);
case DavServletResponse.SC_METHOD_NOT_ALLOWED:
return new ConstraintViolationException(msg, davExc);
case DavServletResponse.SC_CONFLICT:
return new InvalidItemStateException(msg, davExc);
case DavServletResponse.SC_PRECONDITION_FAILED:
return new LockException(msg, davExc);
case DavServletResponse.SC_NOT_IMPLEMENTED:
if (methodCode > 0 && name != null) {
return new UnsupportedRepositoryOperationException("Missing implementation: Method " + name + " could not be executed", davExc);
} else {
return new UnsupportedRepositoryOperationException("Missing implementation", davExc);
}
default:
return new RepositoryException(msg, davExc);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class RepositoryServiceImpl method loadType.
private int loadType(String propertyURI, HttpClient client, PropertyId propertyId, SessionInfo sessionInfo, NamePathResolver resolver) throws IOException, DavException, RepositoryException {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
HttpPropfind request = null;
try {
request = new HttpPropfind(propertyURI, nameSet, DEPTH_0);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length == 1) {
DavPropertySet props = mresponses[0].getProperties(DavServletResponse.SC_OK);
DavProperty<?> type = props.get(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
if (type != null) {
return PropertyType.valueFromName(type.getValue().toString());
} else {
throw new RepositoryException("Internal error. Cannot retrieve property type at " + saveGetIdString(propertyId, resolver));
}
} else {
throw new ItemNotFoundException("Internal error. Cannot retrieve property type at " + saveGetIdString(propertyId, resolver));
}
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class RepositoryServiceImpl method getLockInfo.
@Override
public LockInfo getLockInfo(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
// set of Dav-properties to be retrieved
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(DavPropertyName.LOCKDISCOVERY);
nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
HttpPropfind request = null;
try {
String uri = getItemUri(nodeId, sessionInfo);
request = new HttpPropfind(uri, nameSet, DEPTH_0);
initMethod(request, sessionInfo, false);
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 LockInfo. No such node " + saveGetIdString(nodeId, sessionInfo));
}
DavPropertySet ps = mresponses[0].getProperties(DavServletResponse.SC_OK);
if (ps.contains(DavPropertyName.LOCKDISCOVERY)) {
DavProperty<?> p = ps.get(DavPropertyName.LOCKDISCOVERY);
LockDiscovery ld = LockDiscovery.createFromXml(p.toXml(DomUtil.createDocument()));
NodeId parentId = getParentId(uri, ps, sessionInfo);
return retrieveLockInfo(ld, sessionInfo, nodeId, parentId);
} else {
// no lock present
log.debug("No Lock present on node with id " + saveGetIdString(nodeId, sessionInfo));
return null;
}
} 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();
}
}
}
Aggregations