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);
}
use of org.apache.jackrabbit.spi.Path 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");
}
}
use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.
the class NodeImpl method getCorrespondingNodePath.
/**
* @see Node#getCorrespondingNodePath(String)
*/
public String getCorrespondingNodePath(String workspaceName) throws ItemNotFoundException, NoSuchWorkspaceException, AccessDeniedException, RepositoryException {
checkStatus();
SessionImpl srcSession = null;
try {
// create session on other workspace for current subject
// (may throw NoSuchWorkspaceException and AccessDeniedException)
srcSession = session.switchWorkspace(workspaceName);
// search nearest ancestor that is referenceable
NodeImpl referenceableNode = this;
while (referenceableNode.getDepth() != Path.ROOT_DEPTH && !referenceableNode.isNodeType(NameConstants.MIX_REFERENCEABLE)) {
referenceableNode = (NodeImpl) referenceableNode.getParent();
}
// if root is common ancestor, corresponding path is same as ours
// otherwise access referenceable ancestor and calculate correspond. path.
String correspondingPath;
if (referenceableNode.getDepth() == Path.ROOT_DEPTH) {
if (!srcSession.getItemManager().nodeExists(getQPath())) {
throw new ItemNotFoundException("No corresponding path found in workspace " + workspaceName + "(" + safeGetJCRPath() + ")");
} else {
correspondingPath = getPath();
}
} else {
// get corresponding ancestor
Node correspNode = srcSession.getNodeByUUID(referenceableNode.getUUID());
// path of m2 found, if m1 == n1
if (referenceableNode == this) {
correspondingPath = correspNode.getPath();
} else {
Path p = referenceableNode.getQPath().computeRelativePath(getQPath());
// use prefix mappings of srcSession
String relPath = session.getPathResolver().getJCRPath(p);
if (!correspNode.hasNode(relPath)) {
throw new ItemNotFoundException("No corresponding path found in workspace " + workspaceName + "(" + safeGetJCRPath() + ")");
} else {
correspondingPath = correspNode.getNode(relPath).getPath();
}
}
}
return correspondingPath;
} finally {
if (srcSession != null) {
// we don't need the other session anymore, logout
srcSession.logout();
}
}
}
use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.
the class NodeImpl method resolveRelativeNodePath.
/**
* Returns the <code>NodeEntry</code> at <code>relPath</code> or
* <code>null</code> if no node exists at <code>relPath</code>.
* <p>
* Note that access rights are not checked.
*
* @param relPath relative path of a (possible) node.
* @return the HierarchyEntry of the node at <code>relPath</code> or
* <code>null</code> if no node exists at <code>relPath</code>.
* @throws RepositoryException if <code>relPath</code> is not a valid
* relative path.
*/
private NodeEntry resolveRelativeNodePath(String relPath) throws RepositoryException {
NodeEntry targetEntry = null;
try {
Path rp = session.getPathResolver().getQPath(relPath);
// shortcut
if (rp.getLength() == 1) {
if (rp.denotesCurrent()) {
targetEntry = getNodeEntry();
} else if (rp.denotesParent()) {
targetEntry = getNodeEntry().getParent();
} else {
// try to get child entry + force loading of not known yet
targetEntry = getNodeEntry().getNodeEntry(rp.getName(), rp.getNormalizedIndex(), true);
}
} else {
// rp length > 1
Path p = getPath(rp);
targetEntry = session.getHierarchyManager().getNodeEntry(p.getCanonicalPath());
}
} catch (PathNotFoundException e) {
// item does not exist -> ignore and return null
} catch (NameException e) {
String msg = "Invalid relative path: " + relPath;
log.debug(msg);
throw new RepositoryException(msg, e);
}
return targetEntry;
}
use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.
the class WorkspaceImpl method move.
/**
* @see javax.jcr.Workspace#move(String, String)
*/
public void move(String srcAbsPath, String destAbsPath) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException {
session.checkSupportedOption(Repository.LEVEL_2_SUPPORTED);
session.checkIsAlive();
Path srcPath = session.getQPath(srcAbsPath);
Path destPath = session.getQPath(destAbsPath);
Operation op = Move.create(srcPath, destPath, getHierarchyManager(), getPathResolver(), false);
getUpdatableItemStateManager().execute(op);
}
Aggregations