Search in sources :

Example 71 with PathNotFoundException

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

Example 72 with PathNotFoundException

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

Example 73 with PathNotFoundException

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);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 74 with PathNotFoundException

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");
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 75 with PathNotFoundException

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

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