use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class NodeImpl method getCorrespondingNodePath.
/**
* {@inheritDoc}
*/
public String getCorrespondingNodePath(String workspaceName) throws ItemNotFoundException, NoSuchWorkspaceException, AccessDeniedException, RepositoryException {
// check state of this instance
sanityCheck();
SessionImpl srcSession = null;
try {
// create session on other workspace for current subject
// (may throw NoSuchWorkspaceException and AccessDeniedException)
RepositoryImpl rep = (RepositoryImpl) getSession().getRepository();
srcSession = rep.createSession(sessionContext.getSessionImpl().getSubject(), workspaceName);
// search nearest ancestor that is referenceable
NodeImpl m1 = this;
while (m1.getDepth() != 0 && !m1.isNodeType(NameConstants.MIX_REFERENCEABLE)) {
m1 = (NodeImpl) m1.getParent();
}
// if root is common ancestor, corresponding path is same as ours
if (m1.getDepth() == 0) {
// check existence
if (!srcSession.getItemManager().nodeExists(getPrimaryPath())) {
throw new ItemNotFoundException("Node not found: " + this);
} else {
return getPath();
}
}
// get corresponding ancestor
Node m2 = srcSession.getNodeByUUID(m1.getUUID());
// return path of m2, if m1 == n1
if (m1 == this) {
return m2.getPath();
}
String relPath;
try {
Path p = m1.getPrimaryPath().computeRelativePath(getPrimaryPath());
// use prefix mappings of srcSession
relPath = sessionContext.getJCRPath(p);
} catch (NameException be) {
// should never get here...
String msg = "internal error: failed to determine relative path";
log.error(msg, be);
throw new RepositoryException(msg, be);
}
if (!m2.hasNode(relPath)) {
throw new ItemNotFoundException();
} else {
return m2.getNode(relPath).getPath();
}
} finally {
if (srcSession != null) {
// we don't need the other session anymore, logout
srcSession.logout();
}
}
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class NodeImpl method orderBefore.
/**
* Same as <code>{@link Node#orderBefore(String, String)}</code> except that
* this method takes a <code>Path.Element</code> arguments instead of
* <code>String</code>s.
*
* @param srcName
* @param dstName
* @throws UnsupportedRepositoryOperationException
* @throws VersionException
* @throws ConstraintViolationException
* @throws ItemNotFoundException
* @throws LockException
* @throws RepositoryException
*/
public synchronized void orderBefore(Path.Element srcName, Path.Element dstName) throws UnsupportedRepositoryOperationException, VersionException, ConstraintViolationException, ItemNotFoundException, LockException, RepositoryException {
// check state of this instance
sanityCheck();
if (!getPrimaryNodeType().hasOrderableChildNodes()) {
throw new UnsupportedRepositoryOperationException("child node ordering not supported on " + this);
}
// check arguments
if (srcName.equals(dstName)) {
// there's nothing to do
return;
}
// check existence
if (!hasNode(srcName.getName(), srcName.getIndex())) {
String name;
try {
Path.Element[] path = new Path.Element[] { srcName };
name = sessionContext.getJCRPath(new PathBuilder(path).getPath());
} catch (NameException e) {
name = srcName.toString();
} catch (NamespaceException e) {
name = srcName.toString();
}
throw new ItemNotFoundException(this + " has no child node with name " + name);
}
if (dstName != null && !hasNode(dstName.getName(), dstName.getIndex())) {
String name;
try {
Path.Element[] path = new Path.Element[] { dstName };
name = sessionContext.getJCRPath(new PathBuilder(path).getPath());
} catch (NameException e) {
name = dstName.toString();
} catch (NamespaceException e) {
name = dstName.toString();
}
throw new ItemNotFoundException(this + " has no child node with name " + name);
}
// make sure this node is checked-out and neither protected nor locked
int options = ItemValidator.CHECK_LOCK | ItemValidator.CHECK_CHECKED_OUT | ItemValidator.CHECK_CONSTRAINTS;
sessionContext.getItemValidator().checkModify(this, options, Permission.NONE);
/*
make sure the session is allowed to reorder child nodes.
since there is no specific privilege for reordering child nodes,
test if the the node to be reordered can be removed and added,
i.e. treating reorder similar to a move.
TODO: properly deal with sns in which case the index would change upon reorder.
*/
AccessManager acMgr = sessionContext.getAccessManager();
PathBuilder pb = new PathBuilder(getPrimaryPath());
pb.addLast(srcName.getName(), srcName.getIndex());
Path childPath = pb.getPath();
if (!acMgr.isGranted(childPath, Permission.MODIFY_CHILD_NODE_COLLECTION)) {
String msg = "Not allowed to reorder child node " + sessionContext.getJCRPath(childPath) + ".";
log.debug(msg);
throw new AccessDeniedException(msg);
}
ArrayList<ChildNodeEntry> list = new ArrayList<ChildNodeEntry>(data.getNodeState().getChildNodeEntries());
int srcInd = -1, destInd = -1;
for (int i = 0; i < list.size(); i++) {
ChildNodeEntry entry = list.get(i);
if (srcInd == -1) {
if (entry.getName().equals(srcName.getName()) && (entry.getIndex() == srcName.getIndex() || srcName.getIndex() == 0 && entry.getIndex() == 1)) {
srcInd = i;
}
}
if (destInd == -1 && dstName != null) {
if (entry.getName().equals(dstName.getName()) && (entry.getIndex() == dstName.getIndex() || dstName.getIndex() == 0 && entry.getIndex() == 1)) {
destInd = i;
if (srcInd != -1) {
break;
}
}
} else {
if (srcInd != -1) {
break;
}
}
}
// check if resulting order would be different to current order
if (destInd == -1) {
if (srcInd == list.size() - 1) {
// no change, we're done
return;
}
} else {
if ((destInd - srcInd) == 1) {
// no change, we're done
return;
}
}
// reorder list
if (destInd == -1) {
list.add(list.remove(srcInd));
} else {
if (srcInd < destInd) {
list.add(destInd, list.get(srcInd));
list.remove(srcInd);
} else {
list.add(destInd, list.remove(srcInd));
}
}
// modify the state of 'this', i.e. the parent node
NodeState thisState = (NodeState) getOrCreateTransientItemState();
thisState.setChildNodeEntries(list);
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class NodeImpl method orderBefore.
/**
* {@inheritDoc}
*/
public void orderBefore(String srcName, String destName) throws UnsupportedRepositoryOperationException, VersionException, ConstraintViolationException, ItemNotFoundException, LockException, RepositoryException {
Path.Element insertName;
try {
Path p = sessionContext.getQPath(srcName);
// p must be a relative path of length==depth==1 (to eliminate e.g. "..")
if (p.isAbsolute() || p.getLength() != 1 || p.getDepth() != 1) {
throw new RepositoryException("invalid name: " + srcName);
}
insertName = p.getNameElement();
} catch (NameException e) {
String msg = "invalid name: " + srcName;
log.debug(msg);
throw new RepositoryException(msg, e);
}
Path.Element beforeName;
if (destName != null) {
try {
Path p = sessionContext.getQPath(destName);
// p must be a relative path of length==depth==1 (to eliminate e.g. "..")
if (p.isAbsolute() || p.getLength() != 1 || p.getDepth() != 1) {
throw new RepositoryException("invalid name: " + destName);
}
beforeName = p.getNameElement();
} catch (NameException e) {
String msg = "invalid name: " + destName;
log.debug(msg);
throw new RepositoryException(msg, e);
}
} else {
beforeName = null;
}
orderBefore(insertName, beforeName);
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class WorkspaceImpl method internalCopy.
/**
* @param srcAbsPath
* @param srcWsp
* @param destAbsPath
* @param flag one of
* <ul>
* <li><code>COPY</code></li>
* <li><code>CLONE</code></li>
* <li><code>CLONE_REMOVE_EXISTING</code></li>
* </ul>
* @return the path of the node at its new position
* @throws ConstraintViolationException
* @throws AccessDeniedException
* @throws VersionException
* @throws PathNotFoundException
* @throws ItemExistsException
* @throws LockException
* @throws RepositoryException
*/
private String internalCopy(String srcAbsPath, WorkspaceImpl srcWsp, String destAbsPath, int flag) throws ConstraintViolationException, AccessDeniedException, VersionException, PathNotFoundException, ItemExistsException, LockException, RepositoryException {
Path srcPath;
try {
srcPath = context.getQPath(srcAbsPath).getNormalizedPath();
} catch (NameException e) {
String msg = "invalid path: " + srcAbsPath;
log.debug(msg);
throw new RepositoryException(msg, e);
}
if (!srcPath.isAbsolute()) {
throw new RepositoryException("not an absolute path: " + srcAbsPath);
}
Path destPath;
try {
destPath = context.getQPath(destAbsPath).getNormalizedPath();
} catch (NameException e) {
String msg = "invalid path: " + destAbsPath;
log.debug(msg);
throw new RepositoryException(msg, e);
}
if (!destPath.isAbsolute()) {
throw new RepositoryException("not an absolute path: " + destAbsPath);
}
BatchedItemOperations ops = new BatchedItemOperations(stateMgr, context);
try {
ops.edit();
} catch (IllegalStateException e) {
String msg = "unable to start edit operation";
log.debug(msg);
throw new RepositoryException(msg, e);
}
boolean succeeded = false;
try {
NodeId id = ops.copy(srcPath, srcWsp.getItemStateManager(), srcWsp.getHierarchyManager(), srcWsp.context.getAccessManager(), destPath, flag);
ops.update();
succeeded = true;
return context.getJCRPath(hierMgr.getPath(id));
} finally {
if (!succeeded) {
// update operation failed, cancel all modifications
ops.cancel();
}
}
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class WorkspaceImpl method getImportContentHandler.
/**
* {@inheritDoc}
*/
public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, RepositoryException {
// check state of this instance
sanityCheck();
Path parentPath;
try {
parentPath = context.getQPath(parentAbsPath).getNormalizedPath();
} catch (NameException e) {
String msg = "invalid path: " + parentAbsPath;
log.debug(msg);
throw new RepositoryException(msg, e);
}
if (!parentPath.isAbsolute()) {
throw new RepositoryException("not an absolute path: " + parentAbsPath);
}
Importer importer = new WorkspaceImporter(parentPath, this, context, uuidBehavior, wspConfig.getImportConfig());
return new ImportHandler(importer, getSession());
}
Aggregations