Search in sources :

Example 1 with TraversingItemVisitor

use of javax.jcr.util.TraversingItemVisitor 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 2 with TraversingItemVisitor

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

the class ReadTest method assertEntry.

private void assertEntry(final int index, final boolean isAllow) throws RepositoryException {
    AccessControlEntry first = AccessControlUtils.getAccessControlList(superuser, path).getAccessControlEntries()[index];
    assertEquals(testUser.getPrincipal(), first.getPrincipal());
    Node n = superuser.getNode("/jcr:system/rep:permissionStore/default/" + testUser.getPrincipal().getName());
    TraversingItemVisitor v = new TraversingItemVisitor.Default(true, -1) {

        @Override
        protected void entering(Node node, int level) throws RepositoryException {
            if (node.isNodeType("rep:Permissions") && node.hasProperty("rep:accessControlledPath") && path.equals(node.getProperty("rep:accessControlledPath").getString())) {
                assertEquals(index, node.getProperty("rep:index").getLong());
                assertEquals(isAllow, node.getProperty("rep:isAllow").getBoolean());
            }
        }
    };
    v.visit(n);
}
Also used : Node(javax.jcr.Node) AccessControlEntry(javax.jcr.security.AccessControlEntry) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor)

Aggregations

Node (javax.jcr.Node)2 TraversingItemVisitor (javax.jcr.util.TraversingItemVisitor)2 ArrayList (java.util.ArrayList)1 ItemVisitor (javax.jcr.ItemVisitor)1 Property (javax.jcr.Property)1 RepositoryException (javax.jcr.RepositoryException)1 AccessControlEntry (javax.jcr.security.AccessControlEntry)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 PropertyInfo (org.apache.jackrabbit.spi.PropertyInfo)1 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)1