/** {@inheritDoc} */ public Node getParent() throws ItemNotFoundException, AccessDeniedException, RepositoryException { Node parent = item.getParent(); return factory.getNodeDecorator(session, parent); }
public Node getParent() throws RepositoryException { if (this.parent != null) { this.parent = new NodeProxy(this.item.getParent()); } return this.parent; }
@Override public Node getParent() throws RepositoryException { return NodeFacade.wrap(delegate.getParent(), session); }
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); } }
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); } }
/** {@inheritDoc} */ public RemoteNode getParent() throws RepositoryException, RemoteException { try { return getRemoteNode(item.getParent()); } catch (RepositoryException ex) { throw getRepositoryException(ex); } }
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); } }
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; }
public JcrNode execute() throws Exception { return JcrNode.Wrapper.wrap(getDelegate().getParent(), getJcrSession()); } });
public Node getParent() throws RepositoryException { return NodeWrapper.wrap(getDelegate().getParent(), getSessionWrapper()); }
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())); } }
@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); }
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; } }
@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())); }
/** * @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()); } }
/** * @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()); } }
@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; }
@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; }
/** * 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()); } } }
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()))); } } } }