use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class NodeImpl method addNode.
/**
* @see Node#addNode(String, String)
*/
public Node addNode(String relPath, String primaryNodeTypeName) throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException {
checkIsWritable();
// build path object and retrieve parent node
Path nodePath = getPath(relPath).getNormalizedPath();
if (nodePath.getIndex() != Path.INDEX_UNDEFINED) {
String msg = "Illegal subscript specified: " + relPath;
log.debug(msg);
throw new RepositoryException(msg);
}
NodeImpl parentNode;
if (nodePath.getLength() == 1) {
parentNode = this;
} else {
Path parentPath = nodePath.getAncestor(1);
ItemManager itemMgr = getItemManager();
if (itemMgr.nodeExists(parentPath)) {
parentNode = (NodeImpl) itemMgr.getNode(parentPath);
} else if (itemMgr.propertyExists(parentPath)) {
String msg = "Cannot add a node to property " + LogUtil.safeGetJCRPath(parentPath, session.getPathResolver());
log.debug(msg);
throw new ConstraintViolationException(msg);
} else {
throw new PathNotFoundException("Cannot add a new node to a non-existing parent at " + LogUtil.safeGetJCRPath(parentPath, session.getPathResolver()));
}
}
// get names objects for node and nt
Name nodeName = nodePath.getName();
Name ntName = (primaryNodeTypeName == null) ? null : getQName(primaryNodeTypeName);
// create new node (including validation checks)
return parentNode.createNode(nodeName, ntName);
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class NodeImpl method resolveRelativePropertyPath.
/**
* Returns the id of the property at <code>relPath</code> or <code>null</code>
* if no property exists at <code>relPath</code>.
* <p>
* Note that access rights are not checked.
*
* @param relPath relative path of a (possible) property
* @return the PropertyEntry of the property at <code>relPath</code> or
* <code>null</code> if no property exists at <code>relPath</code>
* @throws RepositoryException if <code>relPath</code> is not a valid
* relative path
*/
private PropertyEntry resolveRelativePropertyPath(String relPath) throws RepositoryException {
PropertyEntry targetEntry = null;
try {
Path rp = session.getPathResolver().getQPath(relPath);
if (rp.getLength() == 1 && rp.denotesName()) {
// a single path element must always denote a name. '.' and '..'
// will never point to a property. If the NodeEntry does not
// contain such a property entry, the targetEntry is 'null;
Name propName = rp.getName();
// check if property entry exists
targetEntry = getNodeEntry().getPropertyEntry(propName, true);
} else {
// build and resolve absolute path
Path p = getPath(rp).getCanonicalPath();
try {
targetEntry = session.getHierarchyManager().getPropertyEntry(p);
} catch (PathNotFoundException e) {
// ignore -> return null;
}
}
} catch (NameException e) {
String msg = "failed to resolve property path " + relPath + " relative to " + safeGetJCRPath();
log.debug(msg);
throw new RepositoryException(msg, e);
}
return targetEntry;
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class NodeImpl method getProperty.
/**
* @see Node#getProperty(String)
*/
public Property getProperty(String relPath) throws PathNotFoundException, RepositoryException {
checkStatus();
PropertyEntry entry = resolveRelativePropertyPath(relPath);
if (entry == null) {
throw new PathNotFoundException(relPath);
}
try {
return (Property) getItemManager().getItem(entry);
} catch (AccessDeniedException e) {
throw new PathNotFoundException(relPath);
} catch (ItemNotFoundException e) {
throw new PathNotFoundException(relPath);
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class NodeImpl method getNode.
/**
* @see Node#getNode(String)
*/
public Node getNode(String relPath) throws PathNotFoundException, RepositoryException {
checkStatus();
NodeEntry nodeEntry = resolveRelativeNodePath(relPath);
if (nodeEntry == null) {
throw new PathNotFoundException(relPath);
}
try {
return (Node) getItemManager().getItem(nodeEntry);
} catch (ItemNotFoundException e) {
throw new PathNotFoundException(relPath, e);
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class PropertyImpl method getNode.
/**
* @see Property#getNode()
*/
public Node getNode() throws ValueFormatException, RepositoryException {
Value value = getValue();
switch(value.getType()) {
case PropertyType.REFERENCE:
case PropertyType.WEAKREFERENCE:
return session.getNodeByIdentifier(value.getString());
case PropertyType.PATH:
case PropertyType.NAME:
String path = value.getString();
Path p = session.getPathResolver().getQPath(path);
try {
return (p.isAbsolute()) ? session.getNode(path) : getParent().getNode(path);
} catch (PathNotFoundException e) {
throw new ItemNotFoundException(path);
}
case PropertyType.STRING:
try {
Value refValue = ValueHelper.convert(value, PropertyType.REFERENCE, session.getValueFactory());
return session.getNodeByIdentifier(refValue.getString());
} catch (ItemNotFoundException e) {
throw e;
} catch (RepositoryException e) {
// try if STRING value can be interpreted as PATH value
Value pathValue = ValueHelper.convert(value, PropertyType.PATH, session.getValueFactory());
p = session.getPathResolver().getQPath(pathValue.getString());
try {
return (p.isAbsolute()) ? session.getNode(pathValue.getString()) : getParent().getNode(pathValue.getString());
} catch (PathNotFoundException e1) {
throw new ItemNotFoundException(pathValue.getString());
}
}
default:
throw new ValueFormatException("Property value cannot be converted to a PATH, REFERENCE or WEAKREFERENCE");
}
}
Aggregations