Search in sources :

Example 1 with ItemVisitor

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

the class ReadDeepTreeTest method createDeepTree.

protected void createDeepTree() throws Exception {
    Node rn = adminSession.getRootNode();
    allPaths.clear();
    String testNodeName = getTestNodeName();
    long start = System.currentTimeMillis();
    if (!rn.hasNode(testNodeName)) {
        testRoot = adminSession.getRootNode().addNode(testNodeName, "nt:unstructured");
        InputStream in = getClass().getClassLoader().getResourceAsStream(getImportFileName());
        adminSession.importXML(testRoot.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
        adminSession.save();
    } else {
        testRoot = rn.getNode(testNodeName);
    }
    System.out.println("Import deep tree: " + (System.currentTimeMillis() - start));
    ItemVisitor v = new TraversingItemVisitor.Default() {

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

        @Override
        protected void entering(Property prop, int i) throws RepositoryException {
            visitingProperty(prop, i);
            super.entering(prop, i);
        }
    };
    v.visit(testRoot);
    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) Property(javax.jcr.Property)

Example 2 with ItemVisitor

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

the class ConcurrentEveryoneACLTest method beforeSuite.

@Override
public void beforeSuite() throws Exception {
    Session session = loginWriter();
    AccessControlManager acMgr = session.getAccessControlManager();
    Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
    final Node root = session.getRootNode().addNode(ROOT_NODE_NAME, "nt:unstructured");
    for (int i = 0; i < NODE_COUNT; i++) {
        Node node = root.addNode("node" + i, "nt:unstructured");
        for (int j = 0; j < NODE_COUNT; j++) {
            Node newNode = node.addNode("node" + j, "nt:unstructured");
            JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(session, newNode.getPath());
            acl.addEntry(EveryonePrincipal.getInstance(), privileges, true);
            acMgr.setPolicy(newNode.getPath(), acl);
        }
        session.save();
    }
    // deny everyone on root node
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(session, root.getPath());
    acl.addEntry(EveryonePrincipal.getInstance(), privileges, false);
    acMgr.setPolicy(root.getPath(), acl);
    session.save();
    final int[] numACEs = new int[1];
    ItemVisitor v = new TraversingItemVisitor.Default() {

        @Override
        protected void entering(Node node, int i) throws RepositoryException {
            if (node.isNodeType(AccessControlConstants.NT_REP_ACE)) {
                numACEs[0]++;
            }
            super.entering(node, i);
        }

        @Override
        protected void entering(Property prop, int i) throws RepositoryException {
            super.entering(prop, i);
        }
    };
    v.visit(root);
    System.out.println("Num ACEs: " + numACEs[0]);
    session.logout();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) ItemVisitor(javax.jcr.ItemVisitor) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) Node(javax.jcr.Node) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Property(javax.jcr.Property) Session(javax.jcr.Session)

Example 3 with ItemVisitor

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

the class ConcurrentReadAccessControlledTreeTest method beforeSuite.

@Override
protected void beforeSuite() throws Exception {
    super.beforeSuite();
    ItemVisitor visitor = new TraversingItemVisitor.Default() {

        int counter = 0;

        @Override
        protected void entering(Node node, int level) throws RepositoryException {
            if (++counter == 10) {
                addPolicy(node);
                counter = 0;
            }
            super.entering(node, level);
        }

        private void addPolicy(Node node) throws RepositoryException {
            AccessControlManager acMgr = node.getSession().getAccessControlManager();
            String path = node.getPath();
            AccessControlPolicyIterator acIterator = acMgr.getApplicablePolicies(path);
            if (acIterator.hasNext()) {
                AccessControlPolicy policy = acIterator.nextAccessControlPolicy();
                if (policy instanceof AccessControlList) {
                    AccessControlList acl = (AccessControlList) policy;
                    Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
                    if (acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privileges)) {
                        acMgr.setPolicy(path, acl);
                        node.getSession().save();
                    }
                }
            }
        }
    };
    visitor.visit(testRoot);
    for (int i = 0; i < bgReaders; i++) {
        addBackgroundJob(new RandomRead(loginReader(), false));
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) ItemVisitor(javax.jcr.ItemVisitor) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) Node(javax.jcr.Node) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) Privilege(javax.jcr.security.Privilege)

Example 4 with ItemVisitor

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

the class RepositoryServiceImpl method getItemInfos.

/**
 * {@inheritDoc}
 */
public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo, ItemId itemId) throws ItemNotFoundException, RepositoryException {
    if (!itemId.denotesNode()) {
        PropertyId propertyId = (PropertyId) itemId;
        PropertyInfo propertyInfo = getPropertyInfo(sessionInfo, propertyId);
        return Iterators.singleton(propertyInfo);
    } else {
        NodeId nodeId = (NodeId) itemId;
        final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
        Node node = getNode(nodeId, sInfo);
        Name ntName = null;
        try {
            ntName = sInfo.getNamePathResolver().getQName(node.getProperty(JcrConstants.JCR_PRIMARYTYPE).getString());
        } catch (NameException e) {
        // ignore. should never occur
        }
        int depth = batchReadConfig.getDepth(ntName);
        if (depth == BatchReadConfig.DEPTH_DEFAULT) {
            NodeInfo info;
            try {
                info = new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver());
            } catch (NameException e) {
                throw new RepositoryException(e);
            }
            return Collections.singletonList(info).iterator();
        } else {
            final List<ItemInfo> itemInfos = new ArrayList<ItemInfo>();
            ItemVisitor visitor = new TraversingItemVisitor(false, depth) {

                @Override
                protected void entering(Property property, int i) throws RepositoryException {
                    try {
                        itemInfos.add(new PropertyInfoImpl(property, idFactory, sInfo.getNamePathResolver(), getQValueFactory()));
                    } catch (NameException e) {
                        throw new RepositoryException(e);
                    }
                }

                @Override
                protected void entering(Node node, int i) throws RepositoryException {
                    try {
                        itemInfos.add(new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver()));
                    } catch (NameException e) {
                        throw new RepositoryException(e);
                    }
                }

                @Override
                protected void leaving(Property property, int i) {
                // nothing to do
                }

                @Override
                protected void leaving(Node node, int i) {
                // nothing to do
                }
            };
            visitor.visit(node);
            return itemInfos.iterator();
        }
    }
}
Also used : ItemInfo(org.apache.jackrabbit.spi.ItemInfo) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) PropertyId(org.apache.jackrabbit.spi.PropertyId) Name(org.apache.jackrabbit.spi.Name) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) ItemVisitor(javax.jcr.ItemVisitor) NodeInfo(org.apache.jackrabbit.spi.NodeInfo) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) Property(javax.jcr.Property)

Example 5 with ItemVisitor

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

the class NodeTypeDefinitionTest method testReadNodeTypeTree.

public void testReadNodeTypeTree() throws Exception {
    String ntPath = NodeTypeConstants.NODE_TYPES_PATH + '/' + NodeTypeConstants.NT_UNSTRUCTURED;
    Node ntNode = superuser.getNode(ntPath);
    ItemVisitor visitor = new TraversingItemVisitor.Default() {

        @Override
        protected void entering(Node node, int level) throws RepositoryException {
            assertTrue(superuser.nodeExists(node.getPath()));
            super.entering(node, level);
        }
    };
    visitor.visit(ntNode);
}
Also used : ItemVisitor(javax.jcr.ItemVisitor) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) Node(javax.jcr.Node)

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