本文整理了Java中org.apache.jackrabbit.oak.api.Tree
类的一些代码示例,展示了Tree
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tree
类的具体详情如下:
包路径:org.apache.jackrabbit.oak.api.Tree
类名称:Tree
[英]A tree instance represents a snapshot of the ContentRepositorytree at the time the instance was acquired from a ContentSession. Tree instances may become invalid over time due to garbage collection of old content, at which point an outdated snapshot will start throwing IllegalStateExceptions to indicate that the snapshot is no longer available. Order and orderability The children of a Tree are generally unordered. That is, the sequence of the children returned by #getChildren() may change over time as this Tree is modified either directly or through some other session. Calling #orderBefore(String) will persist the current order and maintain the order as new children are added or removed. In this case a new child will be inserted after the last child as seen by #getChildren(). State and state transitions A tree instance belongs to the client and its state is only modified in response to method calls made by the client. The various accessors on this interface mirror these of the underlying NodeStateinterface. However, since instances of this class are mutable return values may change between invocations.
All tree instances created in the context of a content session become invalid after the content session is closed. Any method called on an invalid tree instance will throw an InvalidStateException.
Tree instances may become non existing after a call to Root#refresh(), Root#rebase() or Root#commit(). Any write access to non existing Tree instances will cause an InvalidStateException.
Thread safety Tree instances are not thread-safe for write access, so writing clients need to ensure that they are not accessed concurrently from multiple threads. Instances are however thread-safe for read access, so implementations need to ensure that all reading clients see a coherent state. Visibility and access control The data returned by this class and intermediary objects such as are access controlled governed by the ContentSession instance from which the containing Root was obtained. Existence and iterability of trees
The #getChild(String) method is special in that it never returns a null value, even if the named tree does not exist. Instead a client should use the #exists() method on the returned tree to check whether that tree exists.
The iterability of a tree is a related to existence. A node state is iterable if it is included in the return values of the #getChildrenCount(long) and #getChildren() methods. An iterable node is guaranteed to exist, though not all existing nodes are necessarily iterable.
Furthermore, a non-existing node is guaranteed to contain no properties or iterable child nodes. It can, however contain non-iterable children. Such scenarios are typically the result of access control restrictions.
[中]树实例表示从ContentSession获取实例时ContentRepositorytree的快照。随着时间的推移,树实例可能会由于旧内容的垃圾收集而变得无效,此时过时的快照将开始抛出IllegalStateExceptions,以指示快照不再可用。有序性和有序性树的子树通常是无序的。也就是说,#getChildren()返回的子级序列可能会随着时间的推移而改变,因为该树可以直接修改,也可以通过其他会话修改。调用#orderBefore(String)将保留当前顺序,并在添加或删除新的子项时保持该顺序。在这种情况下,将在#getChildren()看到的最后一个子项之后插入一个新的子项。状态和状态转换树实例属于客户端,其状态仅在响应客户端的方法调用时被修改。该接口上的各种访问器反映了底层NodeStateinterface的这些访问器。然而,由于这个类的实例是可变的,所以返回值在调用之间可能会发生变化。
内容会话关闭后,在内容会话上下文中创建的所有树实例都将无效。在无效树实例上调用的任何方法都将抛出InvalidStateException。
在调用Root#refresh()、Root#rebase()或Root#commit()后,树实例可能不存在。对不存在的树实例的任何写访问都将导致InvalidStateException。
线程安全树实例对于写访问来说不是线程安全的,所以写客户端需要确保它们不会从多个线程并发访问。然而,实例对于读取访问来说是线程安全的,所以实现需要确保所有读取客户端都能看到一致的状态。可见性和访问控制此类和中间对象(如访问控制)返回的数据由获取包含根的ContentSession实例控制。树木的存在性和可遗传性
#getChild(String)方法的特殊之处在于它从不返回空值,即使指定的树不存在。相反,客户端应该在返回的树上使用#exists()方法来检查该树是否存在。
一棵树的“可遗传性”与存在有关。如果节点状态包含在#getChildrenCount(long)和#getChildrenCount()方法的返回值中,则该节点状态为iterable。iterable节点保证存在,但并非所有现有节点都必须是iterable的。
此外,一个不存在的节点保证不包含任何属性或iterable子节点。然而,它可以包含不可移植的子对象。这种情况通常是访问控制限制的结果。
代码示例来源:origin: apache/jackrabbit-oak
static Tree createIndex(Tree index, String name, Set<String> propNames) {
Tree def = index.addChild(INDEX_DEFINITIONS_NAME).addChild(name);
def.setProperty(JcrConstants.JCR_PRIMARYTYPE,
INDEX_DEFINITIONS_NODE_TYPE, Type.NAME);
def.setProperty(TYPE_PROPERTY_NAME, LuceneIndexConstants.TYPE_LUCENE);
def.setProperty(REINDEX_PROPERTY_NAME, true);
def.setProperty(FulltextIndexConstants.FULL_TEXT_ENABLED, false);
def.setProperty(PropertyStates.createProperty(FulltextIndexConstants.INCLUDE_PROPERTY_NAMES, propNames, Type.STRINGS));
def.setProperty(LuceneIndexConstants.SAVE_DIR_LISTING, true);
return index.getChild(INDEX_DEFINITIONS_NAME).getChild(name);
}
代码示例来源:origin: apache/jackrabbit-oak
private static boolean hasRestrictionProperty(Tree aceTree, String name) {
if (aceTree.hasProperty(name)) {
return true;
}
Tree restrictionTree = aceTree.getChild(AccessControlConstants.REP_RESTRICTIONS);
return restrictionTree.exists() && restrictionTree.hasProperty(name);
}
代码示例来源:origin: org.apache.jackrabbit/oak-remote
private void copy(Tree source, Tree targetParent, String targetName) {
Tree target = targetParent.addChild(targetName);
for (PropertyState property : source.getProperties()) {
target.setProperty(property);
}
for (Tree child : source.getChildren()) {
copy(child, target, child.getName());
}
}
代码示例来源:origin: apache/jackrabbit-oak
private static Tree getOrCreateChild(Tree tree, String name){
if (tree.hasChild(name)){
return tree.getChild(name);
}
Tree child = tree.addChild(name);
child.setOrderableChildren(true);
child.setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME);
return child;
}
代码示例来源:origin: apache/jackrabbit-oak
/**
* Remove the property
*/
@Override
public boolean remove() {
if (parent.hasProperty(name)) {
parent.removeProperty(name);
return true;
} else {
return false;
}
}
代码示例来源:origin: apache/jackrabbit-oak
private static void checkEqual(Tree tree1, Tree tree2) {
assertEquals(tree1.getChildrenCount(Long.MAX_VALUE), tree2.getChildrenCount(Long.MAX_VALUE));
assertEquals(tree1.getPropertyCount(), tree2.getPropertyCount());
for (PropertyState property1 : tree1.getProperties()) {
assertEquals(property1, tree2.getProperty(property1.getName()));
}
for (Tree child1 : tree1.getChildren()) {
checkEqual(child1, tree2.getChild(child1.getName()));
}
}
}
代码示例来源:origin: apache/jackrabbit-oak
@Before
public void before() {
existingTree = Mockito.mock(Tree.class);
when(existingTree.exists()).thenReturn(true);
when(existingTree.getName()).thenReturn(PathUtils.ROOT_NAME);
when(existingTree.getPath()).thenReturn(PathUtils.ROOT_PATH);
when(existingTree.hasProperty(JcrConstants.JCR_PRIMARYTYPE)).thenReturn(true);
when(existingTree.getProperty(JcrConstants.JCR_PRIMARYTYPE)).thenReturn(PropertyStates.createProperty(JcrConstants.JCR_PRIMARYTYPE, "rep:root"));
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void testChangeDeletedNode() throws CommitFailedException {
theirRoot.getTree("/x").remove();
ourRoot.getTree("/x").setProperty("p", OUR_VALUE);
theirRoot.commit();
ourRoot.commit();
Tree n = ourRoot.getTree("/x");
assertTrue(n.exists());
assertEquals(OUR_VALUE, n.getProperty("p").getValue(STRING));
}
代码示例来源:origin: org.apache.jackrabbit/oak-core
private String getOakName(Tree tree) {
PropertyState property = tree.getProperty(JCR_NODETYPENAME);
if (property != null) {
return property.getValue(Type.NAME);
} else {
return tree.getName();
}
}
代码示例来源:origin: apache/jackrabbit-oak
static void assertMemberList(@NotNull Tree groupTree, int cntRefTrees, int cnt) {
Tree list = groupTree.getChild(REP_MEMBERS_LIST);
assertTrue(list.exists());
assertEquals(cntRefTrees, list.getChildrenCount(5));
for (Tree c : list.getChildren()) {
PropertyState repMembers = c.getProperty(REP_MEMBERS);
assertNotNull(repMembers);
assertTrue(SIZE_TH == repMembers.count() || cnt == repMembers.count());
}
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void testVersionableWithUnsupportedType() throws Exception {
Tree versionable = root.getTree("/content");
Tree vh = checkNotNull(versionManager.getVersionHistory(versionable));
Tree frozen = vh.getChild("1.0").getChild(JCR_FROZENNODE).getChild("a").getChild("b").getChild("c");
Tree invalidFrozen = frozen.addChild(REP_CUG_POLICY);
invalidFrozen.setProperty(JCR_PRIMARYTYPE, NT_REP_CUG_POLICY);
CugPermissionProvider pp = createCugPermissionProvider(ImmutableSet.of(SUPPORTED_PATH, SUPPORTED_PATH2));
TreePermission tp = getTreePermission(root, PathUtils.concat(vh.getPath(), "1.0", JCR_FROZENNODE, "a/b/c"), pp);
TreePermission tpForUnsupportedType = pp.getTreePermission(invalidFrozen, TreeType.VERSION, tp);
assertEquals(TreePermission.NO_RECOURSE, tpForUnsupportedType);
}
代码示例来源:origin: apache/jackrabbit-oak
private static TreeLocation createNonExistingTreeLocation(@NotNull String path) {
String name = Text.getName(path);
Tree nonExistingTree = Mockito.mock(Tree.class);
when(nonExistingTree.exists()).thenReturn(false);
when(nonExistingTree.getName()).thenReturn(name);
when(nonExistingTree.getPath()).thenReturn(path);
when(nonExistingTree.getChild(name)).thenReturn(nonExistingTree);
return TreeLocation.create(nonExistingTree);
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void removeNew() {
Tree tree = root.getTree("/");
Tree t = tree.addChild("new");
tree.getChild("new").remove();
assertFalse(t.exists());
assertFalse(tree.getChild("new").exists());
}
代码示例来源:origin: apache/jackrabbit-oak
private void enableIndexDefinitionIndex() throws CommitFailedException {
Tree nodetype = root.getTree("/oak:index/nodetype");
assertTrue(nodetype.exists());
List<String> nodetypes = Lists.newArrayList();
if (nodetype.hasProperty(DECLARING_NODE_TYPES)){
nodetypes = Lists.newArrayList(nodetype.getProperty(DECLARING_NODE_TYPES).getValue(Type.STRINGS));
}
nodetypes.add(INDEX_DEFINITIONS_NODE_TYPE);
nodetype.setProperty(DECLARING_NODE_TYPES, nodetypes, Type.NAMES);
nodetype.setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true);
root.commit();
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void moveNew() {
Root root = session.getLatestRoot();
Tree tree = root.getTree("/");
Tree t = tree.addChild("new");
root.move("/new", "/y/new");
assertEquals("/y/new", t.getPath());
assertFalse(tree.getChild("new").exists());
}
代码示例来源:origin: apache/jackrabbit-oak
private static Tree createMemberRefTree(@NotNull Tree groupTree, @NotNull Tree membersList) {
if (!membersList.exists()) {
membersList = groupTree.addChild(UserConstants.REP_MEMBERS_LIST);
membersList.setProperty(JcrConstants.JCR_PRIMARYTYPE, UserConstants.NT_REP_MEMBER_REFERENCES_LIST, NAME);
}
Tree refTree = membersList.addChild(nextRefNodeName(membersList));
refTree.setProperty(JcrConstants.JCR_PRIMARYTYPE, UserConstants.NT_REP_MEMBER_REFERENCES, NAME);
return refTree;
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void testAddExistingNode() throws CommitFailedException {
theirRoot.getTree("/").addChild("n").setProperty("p", THEIR_VALUE);
ourRoot.getTree("/").addChild("n").setProperty("p", OUR_VALUE);
theirRoot.commit();
ourRoot.commit();
Tree n = ourRoot.getTree("/n");
assertTrue(n.exists());
assertEquals(OUR_VALUE, n.getProperty("p").getValue(STRING));
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void testRemoveTokenRemovesNode() throws Exception {
TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
Tree userTree = root.getTree(getUserManager(root).getAuthorizable(userId).getPath());
Tree tokens = userTree.getChild(TOKENS_NODE_NAME);
String tokenNodePath = tokens.getChildren().iterator().next().getPath();
info.remove();
assertFalse(root.getTree(tokenNodePath).exists());
}
代码示例来源:origin: apache/jackrabbit-oak
private static boolean isa(Tree types, String typeName, String superName) {
if (typeName.equals(superName)) {
return true;
}
Tree type = types.getChild(typeName);
if (!type.exists()) {
return false;
}
PropertyState supertypes = type.getProperty(REP_SUPERTYPES);
return supertypes != null
&& contains(supertypes.getValue(Type.NAMES), superName);
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void testTokenizeCN() throws Exception {
Tree t = root.getTree("/").addChild("containsCN");
Tree one = t.addChild("one");
one.setProperty("t", "美女衬衫");
root.commit();
assertQuery("//*[jcr:contains(., '美女')]", "xpath",
ImmutableList.of(one.getPath()));
}
内容来源于网络,如有侵权,请联系作者删除!