Search in sources :

Example 96 with PathNotFoundException

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);
}
Also used : Node(javax.jcr.Node) ArrayList(java.util.ArrayList) PathNotFoundException(javax.jcr.PathNotFoundException) HashSet(java.util.HashSet)

Example 97 with PathNotFoundException

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);
    }
}
Also used : Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property)

Example 98 with PathNotFoundException

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
    }
}
Also used : Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 99 with PathNotFoundException

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) {
        }
    }
}
Also used : PathNotFoundException(javax.jcr.PathNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 100 with PathNotFoundException

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) {
        }
    }
}
Also used : PathNotFoundException(javax.jcr.PathNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

PathNotFoundException (javax.jcr.PathNotFoundException)136 Node (javax.jcr.Node)58 RepositoryException (javax.jcr.RepositoryException)46 ItemNotFoundException (javax.jcr.ItemNotFoundException)24 Session (javax.jcr.Session)23 Path (org.apache.jackrabbit.spi.Path)22 AccessDeniedException (javax.jcr.AccessDeniedException)14 Property (javax.jcr.Property)14 Test (org.junit.Test)14 Item (javax.jcr.Item)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 NodeIterator (javax.jcr.NodeIterator)9 Value (javax.jcr.Value)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 Name (org.apache.jackrabbit.spi.Name)8 PropertyIterator (javax.jcr.PropertyIterator)7 NodeDelegate (org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)7 HashSet (java.util.HashSet)6 ItemExistsException (javax.jcr.ItemExistsException)6 ValueFormatException (javax.jcr.ValueFormatException)6