Refine search
/** * @see org.apache.jackrabbit.commons.predicate.DepthPredicate#matches(javax.jcr.Item) */ @Override protected boolean matches(Item item) throws RepositoryException { if (item.isNode()) { return ((Node) item).getDefinition().isMandatory() == isMandatory; } return ((Property) item).getDefinition().isMandatory() == isMandatory; } }
public void moveTo(TreeItem newParent) throws JcrDiffException { if (!(newParent instanceof JcrTreeNode)) { throw new IllegalArgumentException("newParent must be a JcrTreeNode"); } JcrTreeItem jcrTreeNode = (JcrTreeItem) newParent; try { String name = jcrItem.getName(); Session session = jcrItem.getSession(); Node targetParent = (Node) jcrTreeNode.jcrItem; if (jcrItem instanceof Node) { session.move(jcrItem.getPath(), targetParent.getPath() + "/" + name); NodeIterator nodes = targetParent.getNodes(name); while (nodes.hasNext()) { jcrItem = nodes.nextNode(); } } else { Property property = (Property) jcrItem; Property newProp; if (!property.isMultiple()) { newProp = targetParent.setProperty(property.getName(), property.getValue()); } else { newProp = targetParent.setProperty(property.getName(), property.getValues(), property.getType()); } property.remove(); jcrItem = newProp; } } catch (RepositoryException e) { throw new JcrDiffException("Could not move item to new parent", e); } }
/** * {@inheritDoc} */ @Override public String deleteNote(String path) { String message = "The note was successfully deleted!"; try { session.getItem(path).remove(); session.save(); } catch (RepositoryException e) { log.error("deleteNote: error while deleting note {}: ", e); message = "Failed to delete to note! Error: " + e.getMessage(); } return message; }
public void move(Object src, Object dstParent, String name) throws PersistenceException { try { final Session session = ((Item)src).getSession(); final Item source = ((Item)src); final String targetParentPath = ((Node)dstParent).getPath(); final String targetPath = (targetParentPath.equals("/") ? "" : targetParentPath) + '/' + name; session.move(source.getPath(), targetPath); } catch ( final RepositoryException re) { throw new PersistenceException(re.getMessage(), re); } }
/** * * @param item * @return */ private boolean isFilteredNamespace(Item item) { try { return isFilteredNamespace(item.getName(), item.getSession()); } catch (RepositoryException e) { log.warn(e.getMessage()); } return false; }
public void testGetExternallyChangedNode() throws RepositoryException { // Access node1 through session 1 Node node1 = (Node) readOnly.getItem(node1Path); // Add node and property through session 2 Node n2 = testRootNode.getNode(nodeName1).addNode(nodeName2); Property p3 = n2.setProperty(propertyName1, "test"); testRootNode.save(); // Assert added nodes are visible in session 1 after refresh node1.refresh(false); assertTrue(readOnly.itemExists(n2.getPath())); assertTrue(readOnly.itemExists(p3.getPath())); Item m2 = readOnly.getItem(n2.getPath()); assertTrue(m2.isNode()); assertTrue(((Node) m2).hasProperty(propertyName1)); // Remove property through session 2 p3.remove(); testRootNode.save(); // Assert removal is visible through session 1 node1.refresh(false); assertFalse(((Node) m2).hasProperty(propertyName1)); }
public void testGetExternallyChangedProperty() throws RepositoryException { // Access node1 through session 1 Node node1 = (Node) readOnly.getItem(node1Path); // Add node and property through session 2 Node n2 = testRootNode.getNode(nodeName1).addNode(nodeName2); Property p3 = n2.setProperty(propertyName1, "test"); p3.setValue("v3"); testRootNode.save(); // Assert added nodes are visible in session 1 after refresh node1.refresh(false); assertTrue(readOnly.itemExists(n2.getPath())); assertTrue(readOnly.itemExists(p3.getPath())); Item q3 = readOnly.getItem(p3.getPath()); assertFalse(q3.isNode()); assertTrue("v3".equals(((Property) q3).getString())); // Change property value through session 2 p3.setValue("v3_modified"); testRootNode.save(); // Assert modification is visible through session 1 node1.refresh(false); assertTrue("v3_modified".equals(((Property) q3).getString())); }
@Test public void sessionRefresh() throws RepositoryException { Session session = getAdminSession(); // Add some items and ensure they are accessible through this session session.getNode("/").addNode("node1"); session.getNode("/node1").addNode("node2"); session.getNode("/").addNode("node1/node3"); Node node1 = session.getNode("/node1"); assertEquals("/node1", node1.getPath()); Node node2 = session.getNode("/node1/node2"); assertEquals("/node1/node2", node2.getPath()); Node node3 = session.getNode("/node1/node3"); assertEquals("/node1/node3", node3.getPath()); node3.setProperty("property1", "value1"); Item property1 = session.getProperty("/node1/node3/property1"); assertFalse(property1.isNode()); assertEquals("value1", ((Property) property1).getString()); // Make sure these items are still accessible after refresh(true); session.refresh(true); assertTrue(session.itemExists("/node1")); assertTrue(session.itemExists("/node1/node2")); assertTrue(session.itemExists("/node1/node3")); assertTrue(session.itemExists("/node1/node3/property1")); session.refresh(false); // Make sure these items are not accessible after refresh(false); assertFalse(session.itemExists("/node1")); assertFalse(session.itemExists("/node1/node2")); assertFalse(session.itemExists("/node1/node3")); assertFalse(session.itemExists("/node1/node3/property1")); }
public RichTextLink loadLink(String relPath) throws RichTextException { if (Strings.isEmpty(relPath)) { throw new IllegalArgumentException("Link path is empty"); } relPath = RichTextUtil.decode(relPath); try { Node node = nodeModel.getNode(); Node linkNode = node.getNode(relPath); if (linkNode.isNodeType(HippoNodeType.NT_FACETSELECT)) { String uuid = linkNode.getProperty(HippoNodeType.HIPPO_DOCBASE).getValue().getString(); Item item = node.getSession().getNodeByUUID(uuid); if (item != null) { JcrNodeModel model = new JcrNodeModel(item.getPath()); return new RichTextLink(model, relPath); } else { throw new RichTextException("Facetselect points to non-existing uuid" + uuid); } } else { throw new RichTextException("Found node is not a facetselect"); } } catch (PathNotFoundException e) { throw new RichTextException("Error finding facet node for relative path " + relPath, e); } catch (RepositoryException e) { throw new RichTextException("Error finding facet node for relative path " + relPath, e); } }
private RepositorySource getRepositoryTemplate(String absPath) { String template = null; Session session = null; try { session = getSession(); if(session.itemExists(absPath)) { Item item = session.getItem(absPath); if(item.isNode()) { template = ((Node)item).getProperty(HstNodeTypes.SCRIPT_PROPERTY_TEMPLATE).getValue().getString(); } else { template = ((Property)item).getValue().getString(); } return new RepositorySource(template); } } catch (RepositoryException e) { e.printStackTrace(); } finally { if(session != null) { session.logout(); } } if(template == null ) { template = "Template source '"+ absPath +"' not found in the repository. "; } return RepositorySource.repositorySourceNotFound; }
private boolean isValid(IDetachable targetId) { if (!(targetId instanceof JcrNodeModel)) { return false; } JcrNodeModel selectedModel = (JcrNodeModel) targetId; Node node = selectedModel.getObject(); if (node == null) { return false; } try { if (node.isNodeType("hippo:handle")) { Node doc = node.getNode(node.getName()); Item primary = JcrHelper.getPrimaryItem(doc); return (primary.isNode() && ((Node) primary).isNodeType("hippo:resource")); } } catch (RepositoryException e) { log.error(e.getMessage()); } return false; }
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()))); } } } }
public Void doInJcr( final Session session ) throws RepositoryException { if ( !session.itemExists( absPath ) ) { int lastSlashIdx = absPath.lastIndexOf( '/' ); String parentPath = absPath.substring( 0, lastSlashIdx ); Node parentNode = (Node) session.getItem( parentPath ); Calendar cal = Calendar.getInstance(); cal.setTime( date ); parentNode.setProperty( absPath.substring( lastSlashIdx + 1 ), cal ); } else { Item item = session.getItem( absPath ); Assert.isTrue( !item.isNode() ); Calendar cal = Calendar.getInstance(); cal.setTime( date ); ( (Property) item ).setValue( cal ); } session.save(); return null; } } );
try { session = createSession(); if (session.itemExists(absPath)) { Item item = session.getItem(absPath); if (item.isNode()) { Node templateNode = (Node) item; if (templateNode.isNodeType(JcrConstants.NT_FILE)) { return createRepositorySourceFromBinary(templateNode, absPath); } else { return createRepositorySource(((Property) item).getValue().getString(), absPath); } finally { if (session != null) { session.logout();
public void testRemove() throws RepositoryException { String srcPath = moveNode.getPath(); doMove(srcPath, destinationPath); // now remove the moved node testRootNode.getSession().getItem(destinationPath).remove(); assertFalse(superuser.itemExists(srcPath)); assertFalse(superuser.itemExists(destinationPath)); testRootNode.save(); assertFalse(superuser.itemExists(srcPath)); assertFalse(superuser.itemExists(destinationPath)); assertFalse(destParentNode.isModified()); assertFalse(srcParentNode.isModified()); }
public void testRevert() throws RepositoryException { String srcPath = moveNode.getPath(); doMove(srcPath, destinationPath); // now remove the moved node testRootNode.getSession().getItem(destinationPath).remove(); testRootNode.refresh(false); assertTrue(superuser.itemExists(srcPath)); assertFalse(superuser.itemExists(destinationPath)); assertFalse(moveNode.isModified()); assertFalse(destParentNode.isModified()); assertFalse(srcParentNode.isModified()); }
/** * @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()); } }
@Test public void getJcrItemProperty() throws RepositoryException { // GIVEN Node node1 = AbstractJcrContainerTest.createNode(rootNode, "node1", NodeTypes.Content.NAME, PROPERTY_1, "name1"); node1.getSession().save(); // WHEN JcrPropertyItemId propertyId = new JcrPropertyItemId(node1.getIdentifier(), workspace, PROPERTY_1); Item res = container.getJcrItem(propertyId); // THEN assertNotNull(res); assertFalse(res.isNode()); }
@Test public void testSetCommonAttributesWithProperty() throws Exception { // GIVEN String nodeName = "nodeName"; Node testNode = session.getRootNode().addNode(nodeName); String propertyName = "propertyName"; String propertyValue = "propertyValue"; Property testProperty = testNode.setProperty(propertyName, propertyValue); // WHEN DummyJcrAdapter adapter = new DummyJcrAdapter(testProperty); // THEN assertFalse(adapter.isNode()); assertEquals(workspaceName, adapter.getWorkspace()); assertEquals(JcrItemUtil.getItemId(testProperty), adapter.getItemId()); assertEquals(testProperty.getPath(), adapter.getJcrItem().getPath()); }