use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class RepositoryServiceImpl method getValues.
private QValue[] getValues(InputStream response, NamePathResolver resolver, ItemId id) throws RepositoryException {
try {
Document doc = DomUtil.parseDocument(response);
Element prop = DomUtil.getChildElement(doc, JcrRemotingConstants.JCR_VALUES_LN, ItemResourceConstants.NAMESPACE);
if (prop == null) {
// not representation of a jcr-property
throw new ItemNotFoundException("No property found at " + saveGetIdString(id, resolver));
} else {
DavProperty<?> p = DefaultDavProperty.createFromXml(prop);
Value[] jcrVs = ValueUtil.valuesFromXml(p.getValue(), PropertyType.STRING, valueFactory);
QValue[] qvs = new QValue[jcrVs.length];
int type = (jcrVs.length > 0) ? jcrVs[0].getType() : PropertyType.STRING;
for (int i = 0; i < jcrVs.length; i++) {
if (jcrVs[i] instanceof QValueValue) {
qvs[i] = ((QValueValue) jcrVs[i]).getQValue();
} else if (type == PropertyType.BINARY) {
qvs[i] = qValueFactory.create(jcrVs[i].getStream());
} else {
qvs[i] = ValueFormat.getQValue(jcrVs[i], resolver, qValueFactory);
}
}
return qvs;
}
} catch (SAXException e) {
log.warn("Internal error: {}", e.getMessage());
throw new RepositoryException(e);
} catch (IOException e) {
log.warn("Internal error: {}", e.getMessage());
throw new RepositoryException(e);
} catch (ParserConfigurationException e) {
log.warn("Internal error: {}", e.getMessage());
throw new RepositoryException(e);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class ItemManager method getNode.
/**
* @param path
* @return
* @throws PathNotFoundException
* @throws AccessDeniedException
* @throws RepositoryException
*/
public NodeImpl getNode(Path path) throws PathNotFoundException, AccessDeniedException, RepositoryException {
NodeId id = hierMgr.resolveNodePath(path);
if (id == null) {
throw new PathNotFoundException(safeGetJCRPath(path));
}
NodeId parentId = null;
if (!path.denotesRoot()) {
parentId = hierMgr.resolveNodePath(path.getAncestor(1));
}
try {
if (parentId == null) {
return (NodeImpl) getItem(id, path, true);
}
// parent
return getNode(id, parentId);
} catch (ItemNotFoundException infe) {
throw new PathNotFoundException(safeGetJCRPath(path));
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class HierarchyManagerImpl method isShareAncestor.
/**
* {@inheritDoc}
*/
public boolean isShareAncestor(NodeId ancestor, NodeId descendant) throws ItemNotFoundException, RepositoryException {
if (ancestor.equals(descendant)) {
// can't be ancestor of self
return false;
}
try {
ItemState state = getItemState(descendant);
Set<NodeId> parentIds = getParentIds(state, false);
while (parentIds.size() > 0) {
if (parentIds.contains(ancestor)) {
return true;
}
Set<NodeId> grandparentIds = new LinkedHashSet<NodeId>();
for (NodeId parentId : parentIds) {
grandparentIds.addAll(getParentIds(getItemState(parentId), false));
}
parentIds = grandparentIds;
}
// not an ancestor
return false;
} catch (NoSuchItemStateException nsise) {
String msg = "failed to determine degree of relationship of " + ancestor + " and " + descendant;
log.debug(msg);
throw new ItemNotFoundException(msg, nsise);
} catch (ItemStateException ise) {
String msg = "failed to determine degree of relationship of " + ancestor + " and " + descendant;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class HierarchyManagerImpl method getDepth.
/**
* {@inheritDoc}
*/
public int getDepth(ItemId id) throws ItemNotFoundException, RepositoryException {
// shortcut
if (id.equals(rootNodeId)) {
return 0;
}
try {
ItemState state = getItemState(id);
NodeId parentId = getParentId(state);
int depth = 0;
while (parentId != null) {
depth++;
state = getItemState(parentId);
parentId = getParentId(state);
}
return depth;
} catch (NoSuchItemStateException nsise) {
String msg = "failed to determine depth of " + id;
log.debug(msg);
throw new ItemNotFoundException(msg, nsise);
} catch (ItemStateException ise) {
String msg = "failed to determine depth of " + id;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class HierarchyManagerImpl method getRelativeDepth.
/**
* {@inheritDoc}
*/
public int getRelativeDepth(NodeId ancestorId, ItemId descendantId) throws ItemNotFoundException, RepositoryException {
if (ancestorId.equals(descendantId)) {
return 0;
}
int depth = 1;
try {
ItemState state = getItemState(descendantId);
NodeId parentId = getParentId(state);
while (parentId != null) {
if (parentId.equals(ancestorId)) {
return depth;
}
depth++;
state = getItemState(parentId);
parentId = getParentId(state);
}
// not an ancestor
return -1;
} catch (NoSuchItemStateException nsise) {
String msg = "failed to determine depth of " + descendantId + " relative to " + ancestorId;
log.debug(msg);
throw new ItemNotFoundException(msg, nsise);
} catch (ItemStateException ise) {
String msg = "failed to determine depth of " + descendantId + " relative to " + ancestorId;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
}
Aggregations