use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class JcrRemotingServlet method writeMultiple.
private void writeMultiple(JsonWriter writer, Node node, String[] includes, int depth) throws RepositoryException, IOException {
Collection<Node> nodes = new ArrayList<Node>();
Set<String> alreadyAdded = new HashSet<String>();
for (String include : includes) {
try {
Node n;
if (include.startsWith("/")) {
n = node.getSession().getNode(include);
} else {
n = node.getNode(include);
}
String np = n.getPath();
if (!alreadyAdded.contains(np)) {
nodes.add(n);
alreadyAdded.add(np);
}
} catch (PathNotFoundException e) {
// skip missing node
}
}
writer.write(nodes, depth);
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class DocumentViewImportTest method checkImportSimpleXMLTree.
/**
* Tests if the simple xml document defined in createSimpleDocument() is
* imported correctly according the specification rules given in 7.3.2
*/
public void checkImportSimpleXMLTree() throws RepositoryException, IOException {
Node parent = (Node) session.getItem(target);
try {
// check the node names
String prefix = session.getNamespacePrefix(unusedURI);
String rootName = prefix + ":" + rootElem;
//String rootName = rootElem;
Node rootNode = parent.getNode(rootName);
Node child = rootNode.getNode(childElem);
Node xmlTextNode = rootNode.getNode(xmltextElem);
Node grandChild = xmlTextNode.getNode(grandChildElem);
// check xmltext
checkXmlTextNode(xmlTextNode);
// check the property names and values
Property prop = grandChild.getProperty(attributeName);
Property prop2 = xmlTextNode.getProperty(attributeName);
String value = prop.getString();
String value2 = prop2.getString();
assertEquals("Value " + attributeValue + " of attribute " + attributeName + " is imported to different property values.", value, value2);
assertEquals("Value " + attributeValue + " of attribute " + attributeName + " is not correctly imported.", value, attributeValue);
// check the encoded names and values
Property decodedProp;
// is decoded
try {
child.getNode(decodedElemName);
decodedProp = child.getProperty(decodedAttributeName);
String propVal = decodedProp.getString();
// both possibilities
if (!propVal.equals(encodedAttributeValue) && !propVal.equals(decodedAttributeValue)) {
fail("Value " + encodedAttributeValue + " of attribute " + decodedAttributeName + " is not correctly imported.");
}
} catch (PathNotFoundException pnfe) {
try {
// is not decoded
child.getNode(encodedElemName);
decodedProp = child.getProperty(encodedAttributeName);
String propVal = decodedProp.getString();
// both possibilities
if (!propVal.equals(encodedAttributeValue) && !propVal.equals(decodedAttributeValue)) {
fail("Value " + encodedAttributeValue + " of attribute " + encodedAttributeName + " is not correctly imported.");
}
} catch (PathNotFoundException pnfe2) {
fail("XML Element " + encodedElemName + " or attribute " + encodedAttributeName + " not imported: " + pnfe2);
}
}
} catch (PathNotFoundException pne) {
fail("Element or attribute is not imported: " + pne);
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class SessionTest method testMovePathNotFoundExceptionDestInvalid.
/**
* Calls {@link javax.jcr.Session#move(String src, String dest)}
* with invalid destination path.
* <p>
* Should throw a {@link javax.jcr.PathNotFoundException}.
*/
public void testMovePathNotFoundExceptionDestInvalid() throws RepositoryException {
// get default workspace test root node using superuser session
Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
// create parent node
Node srcParentNode = defaultRootNode.addNode(nodeName1, testNodeType);
// create node to move
Node moveNode = srcParentNode.addNode(nodeName2, testNodeType);
// save the new nodes
superuser.save();
// move the node
try {
superuser.move(moveNode.getPath(), defaultRootNode.getPath() + "/" + nodeName2 + "/" + nodeName1);
fail("Invalid destination path during Session.move() must throw PathNotFoundException");
} catch (PathNotFoundException e) {
// ok, works as expected
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class SerializationTest method testWorkspaceImportXmlExceptions.
/**
* Tests the exceptions when importing: If the parent node does not exist,
* and if an IO error occurs.
*/
public void testWorkspaceImportXmlExceptions() throws RepositoryException, IOException {
exportRepository(SKIPBINARY, RECURSE);
FileInputStream in = new FileInputStream(file);
//If no node exists at parentAbsPath, a PathNotFoundException is thrown.
try {
workspace.importXML(treeComparator.targetFolder + "/thisNodeDoesNotExist", in, 0);
fail("Importing to a non-existing node does not throw a PathNotFoundException.");
} catch (PathNotFoundException e) {
// success
} finally {
try {
in.close();
} catch (IOException ignore) {
}
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class SerializationTest method testSessionImportXmlExceptions.
/**
* Tests the exception when importing: If the parent node does not exist.
*/
public void testSessionImportXmlExceptions() throws RepositoryException, IOException {
exportRepository(SKIPBINARY, RECURSE);
FileInputStream in = new FileInputStream(file);
// If no node exists at parentAbsPath, a PathNotFoundException is thrown.
try {
session.importXML(treeComparator.targetFolder + "/thisNodeDoesNotExist", in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
fail("Importing to a non-existing node does not throw a PathNotFoundException.");
} catch (PathNotFoundException e) {
// success
} finally {
try {
in.close();
} catch (IOException ignore) {
}
}
}
Aggregations