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());
}
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();
}
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));
}
}
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();
}
}
}
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);
}
Aggregations