@Override public boolean itemExists( String absPath ) throws RepositoryException { try { return getItem(absPath) != null; } catch (PathNotFoundException error) { return false; } }
@Override public boolean itemExists( String absPath ) throws RepositoryException { try { return getItem(absPath) != null; } catch (PathNotFoundException error) { return false; } }
@Override public void removeItem( String absPath ) throws VersionException, LockException, ConstraintViolationException, AccessDeniedException, RepositoryException { getItem(absPath).remove(); }
@Override public void removeItem( String absPath ) throws VersionException, LockException, ConstraintViolationException, AccessDeniedException, RepositoryException { getItem(absPath).remove(); }
@Override public AbstractJcrItem getItem( String absPath ) throws PathNotFoundException, RepositoryException { checkLive(); CheckArg.isNotEmpty(absPath, "absPath"); Path path = absolutePathFor(absPath); return getItem(path); }
@Override public AbstractJcrItem getItem( String absPath ) throws PathNotFoundException, RepositoryException { checkLive(); CheckArg.isNotEmpty(absPath, "absPath"); Path path = absolutePathFor(absPath); return getItem(path); }
@Test public void shouldProvideChildrenByPath() throws Exception { initializeData(); Item item = session.getItem("/a"); assertThat(item, instanceOf(Node.class)); item = session.getItem("/a/b"); assertThat(item, instanceOf(Node.class)); item = session.getItem("/a/b/booleanProperty"); assertThat(item, instanceOf(Property.class)); }
@Test public void shouldGetItemByIdentifierPath() throws Exception { initializeData(); // Look up the node by the identifier path ... Item item = session.getItem(identifierPathFor("/a")); assertThat(item, instanceOf(Node.class)); assertThat(item.getPath(), is("/a")); item = session.getItem(identifierPathFor("/a/b")); assertThat(item, instanceOf(Node.class)); assertThat(item.getPath(), is("/a/b")); item = session.getItem(identifierPathFor("/")); assertThat(item, instanceOf(Node.class)); assertThat(item.getPath(), is("/")); }
final AbstractJcrItem findItem( AbstractJcrNode node, Path relativePath ) throws RepositoryException { assert !relativePath.isAbsolute(); if (relativePath.size() == 1) { Segment last = relativePath.getLastSegment(); if (last.isSelfReference()) return node; if (last.isParentReference()) return node.getParent(); } // Find the path to the referenced node ... Path nodePath = node.path(); Path absolutePath = nodePath.resolve(relativePath); if (absolutePath.isAtOrBelow(nodePath)) { // Find the item starting at 'node' ... } return getItem(absolutePath); }
final AbstractJcrItem findItem( AbstractJcrNode node, Path relativePath ) throws RepositoryException { assert !relativePath.isAbsolute(); if (relativePath.size() == 1) { Segment last = relativePath.getLastSegment(); if (last.isSelfReference()) return node; if (last.isParentReference()) return node.getParent(); } // Find the path to the referenced node ... Path nodePath = node.path(); Path absolutePath = nodePath.resolve(relativePath); if (absolutePath.isAtOrBelow(nodePath)) { // Find the item starting at 'node' ... } return getItem(absolutePath); }
@Test @FixFor( "MODE-2482 ") public void shouldSupportMultipleMixinsInDocumentView() throws Exception { registerNodeTypes("cnd/mixins.cnd"); Node test = session.getRootNode().addNode("a", "nt:set"); test.addMixin("mix:a"); test.addMixin("mix:b"); test.setProperty("jcr:a", "a"); test.setProperty("jcr:b", "b"); session.save(); File file = new File("target/test-classes/document_view_mode_2482.xml"); FileUtil.delete(file); FileOutputStream outputStream = new FileOutputStream(file); exportDocumentView("/a", outputStream); session.getRootNode().addNode("b", "nt:folder"); session.save(); importFile("/b", file.getName(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); assertNotNull("/b/a"); assertEquals("a", ((Property)session.getItem("/b/a/jcr:a")).getString()); assertEquals("b", ((Property) session.getItem("/b/a/jcr:b")).getString()); }
@Test @FixFor( "MODE-2482" ) public void shouldSupportMultiValuedPropertiesInDocumentView() throws Exception { Node test = session.getRootNode().addNode("testRoot"); test.setProperty("prop1", "value 1"); String[] values = { "value 1", "value 2", "value 3" }; test.setProperty("prop2", values); session.save(); File file = new File("target/test-classes/document_view_multi_prop.xml"); FileUtil.delete(file); FileOutputStream outputStream = new FileOutputStream(file); exportDocumentView("/testRoot", outputStream); session.getNode("/testRoot").remove(); session.save(); importFile("/", file.getName(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); assertNotNull(session.getNode("/testRoot")); Property p1 = (Property)session.getItem("/testRoot/prop1"); assertFalse(p1.isMultiple()); assertEquals("value 1", p1.getString()); Property p2 = (Property)session.getItem("/testRoot/prop2"); assertTrue(p2.isMultiple()); Value[] jcrValues = p2.getValues(); List<String> actualValues = new ArrayList<>(jcrValues.length); for (Value jcrValue : jcrValues) { actualValues.add(jcrValue.getString()); } assertArrayEquals(values, actualValues.toArray()); }
@Test public void shouldProvidePropertiesByPath() throws Exception { initializeData(); Item item = session.getItem("/a/b/booleanProperty"); assertThat(item, instanceOf(Property.class)); Property property = session.getProperty("/a/b/booleanProperty"); assertThat(property, instanceOf(Property.class)); }
@Test @FixFor("MODE-1961") public void shouldBeAbleToImportTwiceWithoutLoosingMixins() throws Exception { tools.registerNodeTypes(session, "cnd/brix.cnd"); session.save(); InputStream brixWorkspace = resourceStream("io/brixWorkspace.xml"); session.importXML("/", brixWorkspace, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING); session.save(); JcrNode root = (JcrNode)session.getItem("/brix:root"); Set<Name> rootMixins = root.getMixinTypeNames(); assertTrue(rootMixins.contains(session.nameFactory().create("brix:node"))); brixWorkspace = resourceStream("io/brixWorkspace.xml"); session.importXML("/", brixWorkspace, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING); session.save(); root = (JcrNode)session.getItem("/brix:root"); rootMixins = root.getMixinTypeNames(); assertTrue(rootMixins.contains(session.nameFactory().create("brix:node"))); }
@Test @FixFor( "MODE-2172" ) public void shouldDocumentImportCheckedInNodes() throws Exception { Node node1 = session.getRootNode().addNode("node1"); node1.addMixin("mix:versionable"); Node node2 = session.getRootNode().addNode("node2"); node2.addMixin("mix:versionable"); session.save(); JcrVersionManager versionManager = session.getWorkspace().getVersionManager(); versionManager.checkpoint("/node1"); session.getNode("/node1").setProperty("11", "some string"); session.getNode("/node1").setProperty("11a1", "some string"); session.save(); versionManager.checkin("/node1"); versionManager.checkpoint("/node2"); //export the data ByteArrayOutputStream baos = new ByteArrayOutputStream(); session.exportDocumentView("/", baos, false, false); session.getWorkspace().importXML("/", new ByteArrayInputStream(baos.toByteArray()), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING); assertEquals(((org.modeshape.jcr.api.Property) session.getItem("/node1/11")).getString(), "some string"); assertEquals(((org.modeshape.jcr.api.Property) session.getItem("/node1/11a1")).getString(), "some string"); }
Item inputItem = inputSession.getItem(work.getInputPath()); Property changedProperty = null; if (inputItem instanceof Property) {
Item inputItem = inputSession.getItem(work.getInputPath()); Property changedProperty = null; if (inputItem instanceof Property) {