use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class NodeTest method testRemoveNodeSessionSave.
/**
* Removes a node using {@link javax.jcr.Node#remove()}, then saves using
* {@link javax.jcr.Session#save()} method.
*/
public void testRemoveNodeSessionSave() throws RepositoryException {
// get default workspace test root node using superuser session
Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
// create the node
Node defaultTestNode = defaultRootNode.addNode(nodeName1, testNodeType);
// save the nodes
superuser.save();
// remove them
defaultTestNode.remove();
superuser.save();
// check if the node has been properly removed
try {
superuser.getItem(defaultRootNode.getPath() + "/" + nodeName1);
fail("Permanently removed node should no longer be adressable using Session.getItem()");
} catch (PathNotFoundException e) {
// ok, works as expected
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class SysViewContentHandler method startDocument.
/**
* Check if the given path is valid.
* Init the neccessary data.
* @throws SAXException
*/
public void startDocument() throws SAXException {
try {
// Check the given path, init the treeState stack
Item item = session.getItem(path);
checkCondition("TestPath " + path + " is not a path to a node.", item.isNode());
nodeElemStack = new Stack<NodeElemData>();
currentNodeElem = new NodeElemData();
currentNodeElem.name = item.getName();
currentNodeElem.node = (Node) item;
currentNodeElem.path = path;
prefixes = new HashMap<String, String>();
testRootDone = false;
} catch (PathNotFoundException pe) {
checkCondition("TestPath " + path + " is not a valid path." + pe.toString(), false);
} catch (RepositoryException re) {
checkCondition("Could not determine test node: " + re.toString(), false);
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class PropertyImpl method getProperty.
public Property getProperty() throws RepositoryException {
Value value = getValue();
Value pathValue = ValueHelper.convert(value, PATH, getSession().getValueFactory());
String path = pathValue.getString();
boolean absolute;
try {
Path p = sessionContext.getQPath(path);
absolute = p.isAbsolute();
} catch (RepositoryException e) {
throw new ValueFormatException("Property value cannot be converted to a PATH");
}
try {
return (absolute) ? getSession().getProperty(path) : getParent().getProperty(path);
} catch (PathNotFoundException e) {
throw new ItemNotFoundException(path);
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class PropertyImpl method getNode.
public Node getNode() throws ValueFormatException, RepositoryException {
Session session = getSession();
Value value = getValue();
int type = value.getType();
switch(type) {
case REFERENCE:
case WEAKREFERENCE:
return session.getNodeByUUID(value.getString());
case PATH:
case NAME:
String path = value.getString();
Path p = sessionContext.getQPath(path);
boolean absolute = p.isAbsolute();
try {
return (absolute) ? session.getNode(path) : getParent().getNode(path);
} catch (PathNotFoundException e) {
throw new ItemNotFoundException(path);
}
case STRING:
try {
Value refValue = ValueHelper.convert(value, REFERENCE, session.getValueFactory());
return session.getNodeByUUID(refValue.getString());
} catch (RepositoryException e) {
// try if STRING value can be interpreted as PATH value
Value pathValue = ValueHelper.convert(value, PATH, session.getValueFactory());
p = sessionContext.getQPath(pathValue.getString());
absolute = p.isAbsolute();
try {
return (absolute) ? 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 javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class DocumentViewTest method testMultiValue.
/**
* Test case for
* <a href="http://issues.apache.org/jira/browse/JCR-325">JCR-325</a>:
* docview roundtripping does not work with multivalue non-string properties
*
* @throws Exception if an unexpected error occurs
*/
public void testMultiValue() throws Exception {
String message = "JCR-325: docview roundtripping does not work with" + " multivalue non-string properties";
Node root = superuser.getRootNode();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
Node node = root.addNode("multi-value-test", "DocViewMultiValueTest");
node.setProperty("test", new String[] { "true", "false" });
superuser.exportDocumentView("/multi-value-test", buffer, true, true);
// Discard the transient multi-value-test node
superuser.refresh(false);
superuser.importXML("/", new ByteArrayInputStream(buffer.toByteArray()), ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
try {
Property property = root.getProperty("multi-value-test/test");
assertTrue(message, property.isMultiple());
assertEquals(message, property.getValues().length, 2);
assertTrue(message, property.getValues()[0].getBoolean());
assertFalse(message, property.getValues()[1].getBoolean());
} catch (PathNotFoundException e) {
fail(message);
}
}
Aggregations