use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.
the class SessionImpl method getVersionState.
/**
* Returns the NodeState of the given Node and asserts that the state is
* listed in the hierarchy built by this Session. If the version
* was obtained from a different session, the 'corresponding' version
* state for this session is retrieved.
*
* @param version
* @return the NodeState associated with the specified version.
*/
NodeState getVersionState(Version version) throws RepositoryException {
NodeState nodeState;
if (version.getSession() == this) {
nodeState = (NodeState) ((NodeImpl) version).getItemState();
} else {
Path p = getQPath(version.getPath());
Path parentPath = p.getAncestor(1);
HierarchyEntry parentEntry = getHierarchyManager().lookup(parentPath);
if (parentEntry != null) {
// make sure the parent entry is up to date
parentEntry.invalidate(false);
}
nodeState = getHierarchyManager().getNodeState(p);
}
return nodeState;
}
use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.
the class SessionImpl method getImportContentHandler.
/**
* @see Session#getImportContentHandler(String, int)
*/
public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, RepositoryException {
checkSupportedOption(Repository.LEVEL_2_SUPPORTED);
checkIsAlive();
Path parentPath = getQPath(parentAbsPath);
// NOTE: check if path corresponds to Node and is writable is performed
// within the SessionImporter.
Importer importer = new SessionImporter(parentPath, this, itemStateManager, uuidBehavior);
return new ImportHandler(importer, getNamespaceResolver(), workspace.getNamespaceRegistry(), getNameFactory(), getPathFactory());
}
use of org.apache.jackrabbit.spi.Path 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 org.apache.jackrabbit.spi.Path 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 org.apache.jackrabbit.spi.Path in project jackrabbit by apache.
the class NodeImpl method orderBefore.
/**
* @see Node#orderBefore(String, String)
*/
public synchronized void orderBefore(String srcChildRelPath, String destChildRelPath) throws UnsupportedRepositoryOperationException, VersionException, ConstraintViolationException, ItemNotFoundException, LockException, RepositoryException {
checkIsWritable();
if (!getPrimaryNodeType().hasOrderableChildNodes()) {
throw new UnsupportedRepositoryOperationException("Child node ordering not supported on node " + safeGetJCRPath());
}
// check arguments
if (srcChildRelPath.equals(destChildRelPath)) {
// there's nothing to do
return;
}
// check existence
if (!hasNode(srcChildRelPath)) {
throw new ItemNotFoundException("Node " + safeGetJCRPath() + " has no child node with name " + srcChildRelPath);
}
if (destChildRelPath != null && !hasNode(destChildRelPath)) {
throw new ItemNotFoundException("Node " + safeGetJCRPath() + " has no child node with name " + destChildRelPath);
}
Path srcPath = getReorderPath(srcChildRelPath);
Path beforePath = null;
if (destChildRelPath != null) {
beforePath = getReorderPath(destChildRelPath);
}
Operation op = ReorderNodes.create(getNodeState(), srcPath, beforePath);
session.getSessionItemStateManager().execute(op);
}
Aggregations