use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class ExportViewReport method init.
/**
* @see Report#init(DavResource, ReportInfo)
*/
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
// delegate validation to super class
super.init(resource, info);
// report specific validation: resource must represent an existing
// repository node
absNodePath = resource.getLocator().getRepositoryPath();
try {
if (!(getRepositorySession().itemExists(absNodePath) && getRepositorySession().getItem(absNodePath).isNode())) {
throw new JcrDavException(new PathNotFoundException(absNodePath + " does not exist."));
}
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class NodeReadMethodsTest method testGetNode.
// -----------< tests of Node specific methods >----------------------------
/**
* Test if getNode(String relPath) returns the correct node and if a
* PathNotFoundException is thrown when Node at relPath does not exist
*/
public void testGetNode() throws NotExecutableException, RepositoryException {
StringBuffer notExistingPath = new StringBuffer("X");
NodeIterator nodes = testRootNode.getNodes();
while (nodes.hasNext()) {
// build a path that for sure is not existing
// (":" of namespace prefix will be replaced later on)
notExistingPath.append(nodes.nextNode().getName());
}
try {
testRootNode.getNode(notExistingPath.toString().replaceAll(":", ""));
fail("getNode(String relPath) must throw a PathNotFoundException" + "if no node exists at relPath");
} catch (PathNotFoundException e) {
// success
}
try {
NodeIterator nodes2 = testRootNode.getNodes();
Node node = nodes2.nextNode();
assertTrue("Node from Iterator is not the same as the Node from getNode()", testRootNode.getNode(node.getName()).isSame(node));
} catch (NoSuchElementException e) {
throw new NotExecutableException("Workspace does not have sufficient content for this test. " + "Root node must have at least one child node.");
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class NodeRemoveMixinTest method testRemoveSuccessfully.
/**
* Tests if <code>Node.removeMixin(String mixinName)</code> removes the
* requested mixin properly
*/
public void testRemoveSuccessfully() throws NotExecutableException, RepositoryException {
Session session = testRootNode.getSession();
Node node = testRootNode.addNode(nodeName1, testNodeType);
String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
if (mixinName == null) {
throw new NotExecutableException("No testable mixin node type found");
}
node.addMixin(mixinName);
testRootNode.getSession().save();
try {
node.removeMixin(mixinName);
} catch (ConstraintViolationException e) {
/**
* In some implementations it may not be possible to remove mixin node
* types (short of removing the node itself). In these cases this
* method will throw a ConstraintViolationException.
*/
throw new NotExecutableException("Repository does not support remove of mixin.");
}
// or set to an empty array when removing the last mixin type
try {
Property mixinProps = node.getProperty(jcrMixinTypes);
// getValues() returns an empty array
assertTrue("Node.removeMixin(String mixinName) did not remove mixin from " + "property " + jcrMixinTypes + ".", mixinProps.getValues().length == 0);
} catch (PathNotFoundException e) {
// success (property jcr:mixinTypes has been completely removed)
}
// it is implementation-specific if a removed mixin isn't available
// before or after save therefore save before further tests
testRootNode.getSession().save();
// test if removed mixin isn't available anymore by node.getMixinNodeTypes()
assertTrue("removeMixin(String mixinName) did not remove mixin.", node.getMixinNodeTypes().length == 0);
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class SetValueLockExceptionTest method createReferenceableNode.
/**
* Create a referenceable node under the testRootNode
* or null if it is not possible to create one.
* @param name
* @throws RepositoryException
*/
public Node createReferenceableNode(String name) throws RepositoryException {
// remove a yet existing node at the target
try {
Node node = testRootNode.getNode(name);
node.remove();
superuser.save();
} catch (PathNotFoundException pnfe) {
// ok
}
// a referenceable node
Node n1 = testRootNode.addNode(name, testNodeType);
if (n1.canAddMixin(mixReferenceable)) {
n1.addMixin(mixReferenceable);
// make sure jcr:uuid is available
superuser.save();
return n1;
} else {
return null;
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class BatchedItemOperations method verifyCanWrite.
/**
* Verifies that the node at <code>nodePath</code> is writable. The
* following conditions must hold true:
* <ul>
* <li>the node must exist</li>
* <li>the current session must be granted read & write access on it</li>
* <li>the node must not be locked by another session</li>
* <li>the node must not be checked-in</li>
* <li>the node must not be protected</li>
* <li>the node must not be affected by a hold or a retention policy</li>
* </ul>
*
* @param nodePath path of node to check
* @throws PathNotFoundException if no node exists at
* <code>nodePath</code> of the current
* session is not granted read access
* to the specified path
* @throws AccessDeniedException if write access to the specified
* path is not allowed
* @throws ConstraintViolationException if the node at <code>nodePath</code>
* is protected
* @throws VersionException if the node at <code>nodePath</code>
* is checked-in
* @throws LockException if the node at <code>nodePath</code>
* is locked by another session
* @throws RepositoryException if another error occurs
*/
public void verifyCanWrite(Path nodePath) throws PathNotFoundException, AccessDeniedException, ConstraintViolationException, VersionException, LockException, RepositoryException {
NodeState node = getNodeState(nodePath);
// access rights
// make sure current session is granted read access on node
AccessManager accessMgr = context.getAccessManager();
if (!accessMgr.isGranted(nodePath, Permission.READ)) {
throw new PathNotFoundException(safeGetJCRPath(node.getNodeId()));
}
// TODO: removed check for 'WRITE' permission on node due to the fact,
// TODO: that add_node and set_property permission are granted on the
// TODO: items to be create/modified and not on their parent.
// in any case, the ability to add child-nodes and properties is checked
// while executing the corresponding operation.
// locking status
verifyUnlocked(nodePath);
// node type constraints
verifyNotProtected(nodePath);
// versioning status
verifyCheckedOut(nodePath);
RetentionRegistry retentionReg = context.getSessionImpl().getRetentionRegistry();
if (retentionReg.hasEffectiveHold(nodePath, false)) {
throw new RepositoryException("Unable to write. Node is affected by a hold.");
}
if (retentionReg.hasEffectiveRetention(nodePath, false)) {
throw new RepositoryException("Unable to write. Node is affected by a retention.");
}
}
Aggregations