Search in sources :

Example 46 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class ServerNode method getVersionByUUID.

//---------- Implementation helper -----------------------------------------
/**
     * Returns the {@link Version} instance for the given UUID.
     *
     * @param versionUUID The UUID of the version.
     *
     * @return The version node.
     *
     * @throws RepositoryException if an error occurrs accessing the version
     *      node or if the UUID does not denote a version.
     */
protected Version getVersionByUUID(String versionUUID) throws RepositoryException {
    // get the version node by its UUID from the version history's session
    Session session = node.getSession();
    Node versionNode = session.getNodeByUUID(versionUUID);
    // the correct type).
    if (versionNode instanceof Version) {
        return (Version) versionNode;
    }
    // otherwise fail
    throw new RepositoryException("Cannot find version " + versionUUID);
}
Also used : Version(javax.jcr.version.Version) RemoteVersion(org.apache.jackrabbit.rmi.remote.RemoteVersion) RemoteNode(org.apache.jackrabbit.rmi.remote.RemoteNode) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 47 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class SerializationTest method doTestLockException.

// ----------------< locking exceptions tests >----------------------------
/**
     * Tests whether importing a tree respects locking.
     */
public void doTestLockException(boolean useWorkspace, boolean useHandler) throws Exception {
    exportRepository(SKIPBINARY, RECURSE);
    if (isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
        //A LockException is thrown if a lock prevents the addition of the subtree.
        Node lNode = testRootNode.addNode(nodeName1);
        ensureMixinType(lNode, mixLockable);
        testRootNode.getSession().save();
        Lock lock = lNode.lock(true, true);
        //remove the token, so the lock is for me, too
        session.removeLockToken(lock.getLockToken());
        FileInputStream in = new FileInputStream(file);
        try {
            doImport(lNode.getPath(), in, useWorkspace, useHandler);
        } catch (LockException e) {
        // success
        } finally {
            try {
                in.close();
            } catch (IOException ignore) {
            }
        }
    } else {
        log.println("Locking not supported.");
    }
}
Also used : LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Lock(javax.jcr.lock.Lock)

Example 48 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class SerializationTest method doTestOverwriteException.

// ---------------< Overwrite existing target node tests     >------------------------------
// ---------------< in case same name siblings not supported >------------------------------
/**
     * Tries to overwrite an existing node. This only works for nodes that do
     * not allow same-name siblings.
     */
public void doTestOverwriteException(boolean useWorkspace, boolean useHandler) throws Exception {
    //If deserialization would overwrite an existing item,
    // an ItemExistsException respective a SAXException is thrown.
    Node folder = testRootNode.addNode("myFolder", treeComparator.sc.sameNameSibsFalseChildNodeDefinition);
    Node subfolder = folder.addNode("subfolder");
    session.save();
    FileOutputStream out = new FileOutputStream(file);
    try {
        session.exportSystemView(subfolder.getPath(), out, true, true);
    } finally {
        out.close();
    }
    FileInputStream in = new FileInputStream(file);
    try {
        if (useHandler) {
            try {
                doImport(folder.getPath(), in, useWorkspace, useHandler);
                fail("Overwriting an existing node during import must throw a SAXException");
            } catch (SAXException e) {
            // success
            }
        } else {
            try {
                doImport(folder.getPath(), in, useWorkspace, useHandler);
                fail("Overwriting an existing node during import must throw an ItemExistsException");
            } catch (ItemExistsException e) {
            // success
            }
        }
    } finally {
        try {
            in.close();
        } catch (IOException ignore) {
        }
    }
}
Also used : ItemExistsException(javax.jcr.ItemExistsException) Node(javax.jcr.Node) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException)

Example 49 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class PropertyTypeTest method typeCheckChildren.

private void typeCheckChildren(Node parentNode) throws RepositoryException {
    NodeIterator nodes = parentNode.getNodes();
    while (nodes.hasNext()) {
        Node node = nodes.nextNode();
        PropertyIterator props = node.getProperties();
        while (props.hasNext()) {
            Property prop = props.nextProperty();
            int reqType = prop.getDefinition().getRequiredType();
            int type = PropertyType.UNDEFINED;
            boolean isEmptyMultipleArray = false;
            if (prop.getDefinition().isMultiple()) {
                if (prop.getValues().length > 0) {
                    type = prop.getValues()[0].getType();
                } else {
                    isEmptyMultipleArray = true;
                }
            } else {
                type = prop.getValue().getType();
            }
            if (!isEmptyMultipleArray && reqType != PropertyType.UNDEFINED) {
                assertFalse("The type of a property must not " + "be UNDEFINED", type == PropertyType.UNDEFINED);
                assertEquals("The type of a property has to match " + "the type of the property definition.", type, reqType);
            }
        }
        typeCheckChildren(node);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 50 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class PropertyTest method testIsSameMustNotCompareStates.

/**
     * Tests if <code>Item.isSame(Item otherItem)</code> will return true when
     * two <code>Property</code> objects representing the same actual repository
     * item have been retrieved through two different sessions and one has been
     * modified.
     * 
     * @since JCR 2.0
     */
public void testIsSameMustNotCompareStates() throws RepositoryException {
    // create a node, add a property and save it
    Node testNode1 = testRootNode.addNode(nodeName1, testNodeType);
    Property prop1 = testNode1.setProperty(propertyName1, "value1");
    testRootNode.getSession().save();
    // accuire the same property through a different session
    Session session = getHelper().getSuperuserSession();
    try {
        Property prop2 = session.getProperty(prop1.getPath());
        // change the value of prop2
        prop2.setValue("value2");
        assertTrue("Two references of same property must return true for " + "property1.isSame(property2)", prop1.isSame(prop2));
    } finally {
        session.logout();
    }
}
Also used : Node(javax.jcr.Node) Property(javax.jcr.Property) Session(javax.jcr.Session)

Aggregations

Node (javax.jcr.Node)2620 Session (javax.jcr.Session)645 Test (org.junit.Test)643 RepositoryException (javax.jcr.RepositoryException)317 Property (javax.jcr.Property)251 NodeIterator (javax.jcr.NodeIterator)214 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)182 Value (javax.jcr.Value)158 Version (javax.jcr.version.Version)155 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)151 Query (javax.jcr.query.Query)122 QueryResult (javax.jcr.query.QueryResult)108 Event (javax.jcr.observation.Event)103 VersionManager (javax.jcr.version.VersionManager)97 Resource (org.apache.sling.api.resource.Resource)96 ArrayList (java.util.ArrayList)93 AccessDeniedException (javax.jcr.AccessDeniedException)89 InvalidItemStateException (javax.jcr.InvalidItemStateException)82 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)82 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)81