本文整理了Java中javax.jcr.Item.getParent()
方法的一些代码示例,展示了Item.getParent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Item.getParent()
方法的具体详情如下:
包路径:javax.jcr.Item
类名称:Item
方法名:getParent
[英]Returns the parent of this Item
.
[中]返回此Item
的父项。
代码示例来源:origin: org.onehippo.cms7/hippo-repository-connector
/** {@inheritDoc} */
public Node getParent() throws ItemNotFoundException, AccessDeniedException, RepositoryException {
Node parent = item.getParent();
return factory.getNodeDecorator(session, parent);
}
代码示例来源:origin: net.adamcin.commons/net.adamcin.commons.jcr
public Node getParent() throws RepositoryException {
if (this.parent != null) {
this.parent = new NodeProxy(this.item.getParent());
}
return this.parent;
}
代码示例来源:origin: net.adamcin.oakpal/oakpal-core
@Override
public Node getParent() throws RepositoryException {
return NodeFacade.wrap(delegate.getParent(), session);
}
代码示例来源:origin: info.magnolia/magnolia-module-forum
public ForumCommandAction(D definition, List<JcrItemAdapter> items, CommandsManager commandsManager, @Named(AdmincentralEventBus.NAME) EventBus eventBus, UiContext uiContext, SimpleTranslator i18n) {
super(definition, items, commandsManager, uiContext, i18n);
this.jcrItem = items.get(0).getJcrItem();
this.uiContext = uiContext;
this.eventBus = eventBus;
this.i18n = i18n;
try {
itemIdOfChangedItem = JcrItemUtil.getItemId(jcrItem.getParent());
} catch (RepositoryException e) {
log.error("Could not execute repository operation.", e);
onError(e);
}
}
代码示例来源:origin: apache/jackrabbit-oak
private void setupACEs(Principal principal) throws RepositoryException {
int size = allPaths.size();
for (int i = 0; i < numberOfAces; i++) {
int index = (int) Math.floor(size * Math.random());
Item item = adminSession.getItem(allPaths.get(index));
Node n = (item.isNode()) ? (Node) item : item.getParent();
String path = getAccessControllablePath(n);
AccessControlUtils.addAccessControlEntry(adminSession, path, principal, new String[] {PrivilegeConstants.JCR_READ}, true);
}
}
代码示例来源:origin: apache/jackrabbit
/** {@inheritDoc} */
public RemoteNode getParent() throws RepositoryException, RemoteException {
try {
return getRemoteNode(item.getParent());
} catch (RepositoryException ex) {
throw getRepositoryException(ex);
}
}
代码示例来源:origin: info.magnolia/magnolia-module-forum
public ForumCommandAction(D definition, JcrItemAdapter item, CommandsManager commandsManager, @Named(AdmincentralEventBus.NAME) EventBus eventBus, UiContext uiContext, SimpleTranslator i18n) {
super(definition, item, commandsManager, uiContext, i18n);
this.jcrItem = item.getJcrItem();
this.uiContext = uiContext;
this.eventBus = eventBus;
this.i18n = i18n;
try {
itemIdOfChangedItem = JcrItemUtil.getItemId(jcrItem.getParent());
} catch (RepositoryException e) {
log.error("Could not execute repository operation.", e);
onError(e);
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.jcr.resource
private Item getHistoricItem(Item item, String versionSpecifier) throws RepositoryException {
Item currentItem = item;
LinkedList<String> relPath = new LinkedList<>();
Node version = null;
while (!"/".equals(currentItem.getPath())) {
if (isVersionable(currentItem)) {
version = getFrozenNode((Node) currentItem, versionSpecifier);
break;
} else {
relPath.addFirst(currentItem.getName());
currentItem = currentItem.getParent();
}
}
if (version != null) {
return getSubitem(version, StringUtils.join(relPath.iterator(), '/'));
}
return null;
}
代码示例来源:origin: brix-cms/brix-cms
public JcrNode execute() throws Exception {
return JcrNode.Wrapper.wrap(getDelegate().getParent(), getJcrSession());
}
});
代码示例来源:origin: brix-cms/brix-cms
public Node getParent() throws RepositoryException {
return NodeWrapper.wrap(getDelegate().getParent(), getSessionWrapper());
}
代码示例来源:origin: net.adamcin.commons/net.adamcin.commons.jcr
public Item getAncestor(int i) throws RepositoryException {
Item ancestor = this.item.getAncestor(i);
if (ancestor.isNode()) {
return new NodeProxy((Node) ancestor);
} else {
return new PropertyProxy((Property) ancestor, new NodeProxy(ancestor.getParent()));
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.jcr.resource
@Override
public @CheckForNull Resource getParent(final @Nonnull ResolveContext<JcrProviderState> ctx, final @Nonnull Resource child) {
if (child instanceof JcrItemResource<?>) {
try {
String version = null;
if (child.getResourceMetadata().getParameterMap() != null) {
version = child.getResourceMetadata().getParameterMap().get("v");
}
if (version == null) {
Item item = ((JcrItemResource<?>) child).getItem();
if ("/".equals(item.getPath())) {
return null;
}
Node parentNode;
try {
parentNode = item.getParent();
} catch(AccessDeniedException e) {
return null;
}
String parentPath = ResourceUtil.getParent(child.getPath());
return new JcrNodeResource(ctx.getResourceResolver(), parentPath, version, parentNode,
ctx.getProviderState().getHelperData());
}
} catch (RepositoryException e) {
logger.warn("Can't get parent for {}", child, e);
return null;
}
}
return super.getParent(ctx, child);
}
代码示例来源:origin: org.exoplatform.jcr/exo.jcr.framework.command
public boolean perform(CliAppContext ctx)
{
String output = "";
try
{
Item currentItem = ctx.getCurrentItem();
Item parentItem = currentItem.getParent();
currentItem.remove();
ctx.getSession().save();
output = "Item " + currentItem.getPath() + " removed succesfully \n";
ctx.setCurrentItem(parentItem);
output = "Current item: " + ctx.getCurrentItem().getPath() + "\n";
}
catch (Exception e)
{
output = "Can't execute command - " + e.getMessage() + "\n";
}
ctx.setOutput(output);
return false;
}
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
@Test
public void copyMutlipleItems() throws Exception {
// GIVEN
JcrItemAdapter sourceNode = mock(JcrItemAdapter.class);
when(sourceNode.getJcrItem()).thenReturn(firstItem);
when(sourceNode.getWorkspace()).thenReturn(RepositoryConstants.CONFIG);
JcrItemAdapter sourceProperty = mock(JcrItemAdapter.class);
when(sourceProperty.getJcrItem()).thenReturn(secondItem);
when(sourceProperty.getWorkspace()).thenReturn(RepositoryConstants.CONFIG);
when(sourceProperty.isNode()).thenReturn(false);
CopyContentAction action = new CopyContentAction(definition, Arrays.asList(sourceNode, sourceProperty), clipboard, uiContext, eventBus, i18n);
// WHEN
action.execute();
// THEN
verify(clipboard, times(1)).copy(itemsCaptor.capture());
List<JcrItemId> items = itemsCaptor.getValue();
assertThat(items.size(), is(2));
JcrItemId copiedNodeId = items.get(0);
assertThat(copiedNodeId.getUuid(), is(((Node) firstItem).getIdentifier()));
JcrPropertyItemId copiedPropertyId = (JcrPropertyItemId) items.get(1);
assertThat(copiedPropertyId.getUuid(), is(secondItem.getParent().getIdentifier()));
assertThat(copiedPropertyId.getPropertyName(), is(((Property) secondItem).getName()));
}
代码示例来源:origin: apache/jackrabbit-oak
/**
* @see Item#isSame(javax.jcr.Item)
*/
@Override
public boolean isSame(Item otherItem) throws RepositoryException {
if (this == otherItem) {
return true;
}
// The objects are either both Node objects or both Property objects.
if (isNode() != otherItem.isNode()) {
return false;
}
// Test if both items belong to the same repository
// created by the same Repository object
if (!getSession().getRepository().equals(otherItem.getSession().getRepository())) {
return false;
}
// Both objects were acquired through Session objects bound to the same
// repository workspace.
if (!getSession().getWorkspace().getName().equals(otherItem.getSession().getWorkspace().getName())) {
return false;
}
if (isNode()) {
return ((Node) this).getIdentifier().equals(((Node) otherItem).getIdentifier());
} else {
return getName().equals(otherItem.getName()) && getParent().isSame(otherItem.getParent());
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
/**
* @see Item#isSame(javax.jcr.Item)
*/
@Override
public boolean isSame(Item otherItem) throws RepositoryException {
if (this == otherItem) {
return true;
}
// The objects are either both Node objects or both Property objects.
if (isNode() != otherItem.isNode()) {
return false;
}
// Test if both items belong to the same repository
// created by the same Repository object
if (!getSession().getRepository().equals(otherItem.getSession().getRepository())) {
return false;
}
// Both objects were acquired through Session objects bound to the same
// repository workspace.
if (!getSession().getWorkspace().getName().equals(otherItem.getSession().getWorkspace().getName())) {
return false;
}
if (isNode()) {
return ((Node) this).getIdentifier().equals(((Node) otherItem).getIdentifier());
} else {
return getName().equals(otherItem.getName()) && getParent().isSame(otherItem.getParent());
}
}
代码示例来源:origin: org.fcrepo/modeshape-jcr
@Override
public Item getAncestor( int depth ) throws RepositoryException {
checkSession();
if (depth < 0) {
throw new ItemNotFoundException(JcrI18n.noNegativeDepth.text(depth));
}
/*
* depth argument is absolute depth from root of content graph, not relative depth from current node.
* That is, if current node is at path /foo/bar/baz, getAncestor(1) returns node at /foo, getAncestor(2)
* returns node at /foo/bar, getAncestor(3) returns node at /foo/bar/baz, getAncestor(0) returns root node,
* and any other argument results in ItemNotFoundException.
* Next statement converts depth parameter from a relative depth to an absolute depth.
*/
depth = getDepth() - depth;
if (depth < 0) {
throw new ItemNotFoundException(JcrI18n.tooDeep.text(depth));
}
Item ancestor = this;
while (--depth >= 0) {
ancestor = ancestor.getParent();
}
return ancestor;
}
代码示例来源:origin: ModeShape/modeshape
@Override
public Item getAncestor( int depth ) throws RepositoryException {
checkSession();
if (depth < 0) {
throw new ItemNotFoundException(JcrI18n.noNegativeDepth.text(depth));
}
/*
* depth argument is absolute depth from root of content graph, not relative depth from current node.
* That is, if current node is at path /foo/bar/baz, getAncestor(1) returns node at /foo, getAncestor(2)
* returns node at /foo/bar, getAncestor(3) returns node at /foo/bar/baz, getAncestor(0) returns root node,
* and any other argument results in ItemNotFoundException.
* Next statement converts depth parameter from a relative depth to an absolute depth.
*/
depth = getDepth() - depth;
if (depth < 0) {
throw new ItemNotFoundException(JcrI18n.tooDeep.text(depth));
}
Item ancestor = this;
while (--depth >= 0) {
ancestor = ancestor.getParent();
}
return ancestor;
}
代码示例来源:origin: apache/jackrabbit
/**
* Fill the property set for this resource.
*/
@Override
protected void initProperties() {
super.initProperties();
if (exists()) {
try {
properties.add(new DefaultDavProperty<String>(JCR_NAME, item.getName()));
properties.add(new DefaultDavProperty<String>(JCR_PATH, item.getPath()));
int depth = item.getDepth();
properties.add(new DefaultDavProperty<String>(JCR_DEPTH, String.valueOf(depth)));
// add href-property for the items parent unless its the root item
if (depth > 0) {
String parentHref = getLocatorFromItem(item.getParent()).getHref(true);
properties.add(new HrefProperty(JCR_PARENT, parentHref, false));
}
} catch (RepositoryException e) {
// should not get here
log.error("Error while accessing jcr properties: " + e.getMessage());
}
}
}
代码示例来源:origin: apache/jackrabbit
private void checkHierarchy() throws PathNotFoundException, RepositoryException, ItemNotFoundException,
AccessDeniedException {
for (Iterator<ItemInfo> itemInfos = itemInfoStore.getItemInfos(); itemInfos.hasNext();) {
ItemInfo itemInfo = itemInfos.next();
String jcrPath = toJCRPath(itemInfo.getPath());
Item item = session.getItem(jcrPath);
assertEquals(jcrPath, item.getPath());
if (item.getDepth() > 0) {
Node parent = item.getParent();
if (item.isNode()) {
assertTrue(item.isSame(parent.getNode(item.getName())));
}
else {
assertTrue(item.isSame(parent.getProperty(item.getName())));
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!