Search in sources :

Example 6 with ItemVisitor

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

the class NodeTypesInContentTest method testDefaultValues.

/**
 * Test for <a href="https://issues.apache.org/jira/browse/JCR-1964">JCR-1964</a>
 *
 * @throws javax.jcr.RepositoryException If an exception occurs.
 */
public void testDefaultValues() throws RepositoryException {
    ItemVisitor visitor = new TraversingItemVisitor.Default() {

        public void visit(Property property) throws RepositoryException {
            if (JcrConstants.JCR_DEFAULTVALUES.equals(property.getName())) {
                int type = property.getType();
                Value[] vs = property.getValues();
                for (int i = 0; i < vs.length; i++) {
                    assertEquals("Property type must match the value(s) type", type, vs[i].getType());
                }
            }
        }
    };
    Node start = (Node) superuser.getItem("/jcr:system/jcr:nodeTypes");
    visitor.visit(start);
}
Also used : ItemVisitor(javax.jcr.ItemVisitor) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) Node(javax.jcr.Node) Value(javax.jcr.Value) Property(javax.jcr.Property)

Example 7 with ItemVisitor

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

the class NodeReadMethodsTest method testAccept.

/**
 */
public void testAccept() throws RepositoryException {
    final Node n = testRootNode;
    ItemVisitor itemVisitor = new ItemVisitor() {

        public void visit(Property property) {
            fail("Wrong accept method executed.");
        }

        public void visit(Node node) throws RepositoryException {
            assertTrue("Visited node is not the same as the one passed in method visit(Node)", n.isSame(node));
        }
    };
    n.accept(itemVisitor);
}
Also used : ItemVisitor(javax.jcr.ItemVisitor) Node(javax.jcr.Node) Property(javax.jcr.Property)

Example 8 with ItemVisitor

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

the class PropertyReadMethodsTest method testAccept.

/**
 * Tests if a Property calls the correct visit method on an {@link
 * ItemVisitor}.
 */
public void testAccept() throws RepositoryException {
    final Property p = property;
    ItemVisitor itemVisitor = new ItemVisitor() {

        public void visit(Property property) throws RepositoryException {
            assertTrue("Visited Property is not the same as the one returned by visit(Property).", p.isSame(property));
        }

        public void visit(Node node) {
            fail("Wrong accept method executed.");
        }
    };
    p.accept(itemVisitor);
}
Also used : ItemVisitor(javax.jcr.ItemVisitor) Node(javax.jcr.Node) Property(javax.jcr.Property)

Example 9 with ItemVisitor

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

the class AbstractDeepTreeTest method beforeSuite.

@Override
protected void beforeSuite() throws Exception {
    adminSession = getRepository().login(getCredentials());
    String name = getClass().getSimpleName();
    Node rn = adminSession.getRootNode();
    if (!rn.hasNode(name)) {
        testRoot = adminSession.getRootNode().addNode(name, "nt:unstructured");
        InputStream in = getClass().getClassLoader().getResourceAsStream("deepTree.xml");
        adminSession.importXML(testRoot.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
        adminSession.save();
    } else {
        testRoot = rn.getNode(name);
    }
    final List<String> paths = new ArrayList<String>();
    ItemVisitor v = new TraversingItemVisitor.Default() {

        @Override
        protected void entering(Node node, int i) throws RepositoryException {
            paths.add(node.getPath());
            super.entering(node, i);
        }

        @Override
        protected void entering(Property prop, int i) throws RepositoryException {
            paths.add(prop.getPath());
            super.entering(prop, i);
        }
    };
    v.visit(testRoot);
    allPaths = paths;
    System.out.println("All paths: " + allPaths.size());
}
Also used : ItemVisitor(javax.jcr.ItemVisitor) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) InputStream(java.io.InputStream) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) Property(javax.jcr.Property)

Aggregations

ItemVisitor (javax.jcr.ItemVisitor)9 Node (javax.jcr.Node)9 Property (javax.jcr.Property)7 TraversingItemVisitor (javax.jcr.util.TraversingItemVisitor)7 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 AccessControlManager (javax.jcr.security.AccessControlManager)2 Privilege (javax.jcr.security.Privilege)2 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 Value (javax.jcr.Value)1 AccessControlList (javax.jcr.security.AccessControlList)1 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)1 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)1 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)1 ItemInfo (org.apache.jackrabbit.spi.ItemInfo)1 Name (org.apache.jackrabbit.spi.Name)1 NodeId (org.apache.jackrabbit.spi.NodeId)1 NodeInfo (org.apache.jackrabbit.spi.NodeInfo)1 PropertyId (org.apache.jackrabbit.spi.PropertyId)1