Refine search
if (maxLevel == -1 || currentLevel < maxLevel) { currentLevel++; PropertyIterator propIter = node.getProperties(); while (propIter.hasNext()) { propIter.nextProperty().accept(this); NodeIterator nodeIter = node.getNodes(); while (nodeIter.hasNext()) { nodeIter.nextNode().accept(this); PropertyIterator propIter = node.getProperties(); while (propIter.hasNext()) { nextQueue.addLast(propIter.nextProperty()); NodeIterator nodeIter = node.getNodes(); while (nodeIter.hasNext()) { nextQueue.addLast(nodeIter.nextNode());
@Override public long getSize() { return iterator.getSize(); }
@Override public Object next() { return iterator.next(); }
/** * Helper method to find a multivalue property. * * @param node the node to start the search from. * @return a multivalue property or null if not found any. */ public static Property searchMultivalProp(Node node) throws RepositoryException { Property multiVal = null; for (PropertyIterator props = node.getProperties(); props.hasNext();) { Property property = props.nextProperty(); if (property.getDefinition().isMultiple()) { multiVal = property; break; } } if (multiVal == null) { for (NodeIterator nodes = node.getNodes(); nodes.hasNext();) { Node n = nodes.nextNode(); multiVal = searchMultivalProp(n); if (multiVal != null) { break; } } } return multiVal; }
@Override public Set<String> keySet() { LinkedHashSet<String> result = new LinkedHashSet<String>(); try { Node node = getNode(); if (node != null) { PropertyIterator properties = node.getProperties(); while (properties.hasNext()) { Property property = properties.nextProperty(); if (!"jcr:primaryType".equals(property.getName())) { result.add(property.getName()); } } NodeIterator nodes = node.getNodes(); while (nodes.hasNext()) { Node child = nodes.nextNode(); result.add(child.getName()); } } } catch (RepositoryException ex) { handleRepositoryException(ex); } return result; }
static Node copyNodes(Node source, Node parent, String name) throws RepositoryException { Node clone = parent.addNode(name, source.getPrimaryNodeType().getName()); for (NodeType mixin : source.getMixinNodeTypes()) { clone.addMixin(mixin.getName()); } for (PropertyIterator pi = source.getProperties(); pi.hasNext(); ) { Property prop = pi.nextProperty(); if (prop.getDefinition().isProtected()) { continue; } if (prop.isMultiple()) { clone.setProperty(prop.getName(), prop.getValues()); } else { clone.setProperty(prop.getName(), prop.getValue()); } } for (NodeIterator ni = source.getNodes(); ni.hasNext(); ) { Node node = ni.nextNode(); if (isVirtual(node)) { continue; } copyNodes(node, clone, node.getName()); } return clone; }
/** * Copies nodes. * * @param node Node to copy * @param destinationParent Destination parent node * @throws RepositoryException if problem with jcr repository occurred */ public void copyNode(Node node, Node destinationParent) throws RepositoryException { LOG.debug("Copying node '{}' into '{}'", node.getPath(), destinationParent.getPath()); Node newNode = destinationParent.addNode(node.getName(), node.getPrimaryNodeType().getName()); PropertyIterator it = node.getProperties(); while (it.hasNext()) { Property property = it.nextProperty(); if (!property.getDefinition().isProtected()) { newNode .setProperty(property.getName(), property.getValue().getString(), property.getType()); } } NodeIterator nodeIterator = node.getNodes(); while (nodeIterator.hasNext()) { copyNode(nodeIterator.nextNode(), newNode); } }
@Test public void testPropertiesCanBeOverriden() throws IOException, RepositoryException { // GIVEN session = SessionTestUtil.createSession("test", "/bla/bla.prop1=default\n" + "/impl/node.prop1=new\n" + "/impl/node.extends=../../bla/bla\n" ); Node plainNode = session.getNode("impl/node"); // WHEN Node extendedNode = new ExtendingNodeWrapper(plainNode); // THEN assertEquals("new", extendedNode.getProperty("prop1").getString()); assertEquals(1, extendedNode.getProperties().getSize()); }
NodeState(Node node, boolean skipBinaries) throws RepositoryException { this.path = node.getPath(); this.userId = node.getSession().getUserID(); properties = new HashMap<String, BigInteger>(); nodes = new LinkedHashMap<String, String>(); PropertyIterator propIter = node.getProperties(); while (propIter.hasNext()) { Property property = propIter.nextProperty(); // skip binaries, to prevent them being pulled from the database if (!skipBinaries || property.getType() != PropertyType.BINARY) { if (property.getDefinition().isMultiple()) { properties.put(property.getName(), getHashCode(property.getValues())); } else { properties.put(property.getName(), getHashCode(property.getValue())); } } } NodeIterator nodeIter = node.getNodes(); while (nodeIter.hasNext()) { Node child = nodeIter.nextNode(); if (child != null) { try { nodes.put(child.getIdentifier(), child.getName()); } catch (RepositoryException e) { log.warn("Unable to add child node to list: " + e.getMessage()); log.debug("Error while adding child node to list: ", e); } } } }
public void testSingleValueWithName() throws RepositoryException { Value weakRef = vf.createValue(target, true); referring.setProperty(propertyName1, weakRef); superuser.save(); PropertyIterator it = target.getWeakReferences(propertyName1); assertTrue("no weak references returned", it.hasNext()); Property p = it.nextProperty(); assertEquals("wrong weak reference property", referring.getProperty(propertyName1).getPath(), p.getPath()); assertFalse("no more weak references expected", it.hasNext()); }
message(node.getPath()); if (node.getName().equals("jcr:system")) { return; if (node.getName().equals("jcr:content")) { return; final PropertyIterator properties = node.getProperties(); while (properties.hasNext()) { final Property property = properties.nextProperty(); if (property.getDefinition().isMultiple()) { final Value[] values = property.getValues(); for (final Value value : values) { message(property.getPath() + " = " + value.getString()); final NodeIterator nodes = node.getNodes(); while (nodes.hasNext()) { dump(nodes.nextNode());
public NodeContent(Node node, final Set<String> propertyNamesFilledWithValues) throws RepositoryException { super(node); primaryNodeTypeName = node.getPrimaryNodeType().getName(); if (node.isNodeType("mix:referenceable")) { this.uuid = node.getUUID(); for (PropertyIterator it = node.getProperties(); it.hasNext(); ) { Property prop = it.nextProperty(); if (propertyNamesFilledWithValues == null || propertyNamesFilledWithValues.contains(prop.getName())) { propertyContents.add(new PropertyContent(prop)); } else { propertyContents.add(new PropertyContent(prop.getName(), prop.getPath())); for (NodeIterator it = node.getNodes(); it.hasNext(); ) { Node childNode = it.nextNode();
@Override public void clear() { try { if (getNode() != null) { NodeIterator children = getNode().getNodes(); while (children.hasNext()) { Node child = children.nextNode(); if (!child.getDefinition().isProtected()) { child.remove(); } } PropertyIterator properties = getNode().getProperties(); while (properties.hasNext()) { Property property = properties.nextProperty(); if (!property.getDefinition().isProtected()) { property.remove(); } } } else { log.warn("Node model is not valid"); } } catch (RepositoryException ex) { log.error(ex.getMessage()); } }
@Override protected void doExecute(InstallContext ctx) throws RepositoryException, TaskExecutionException { final Session session = ctx.getJCRSession(workspaceName); final Node source = session.getNode(sourceNodePath); final Node target = session.getNode(targetNodePath); final PropertyIterator props = source.getProperties(); while (props.hasNext()) { Property prop = props.nextProperty(); final String name = prop.getName(); final String value = prop.getString(); if (target.hasProperty(name)) { target.getProperty(name).setValue(value); } else { target.setProperty(name, value); } } } }
@Override public void write(JsonWriter writer, Node t) throws IOException { if (t != null) { try { writer.beginObject(); for (PropertyIterator pi = t.getProperties(); pi.hasNext();) { Property p = (Property) pi.next(); writer.name(p.getName()); if (p.isMultiple()) { writer.beginArray(); for (Value v : p.getValues()) { writeValue(writer, v); } } else { writeValue(writer, p.getValue()); } } for (NodeIterator ni = t.getNodes(); ni.hasNext();) { Node child = ni.nextNode(); writer.name(child.getName()); write(writer, child); } writer.endObject(); } catch (RepositoryException ex) { Logger.getLogger(JcrJsonAdapter.class.getName()).log(Level.SEVERE, null, ex); throw new IOException(ex); } } }
public static Map<String, Properties> getLocalePropertiesMap( final Session session, final PentahoJcrConstants pentahoJcrConstants, final Node localesNode ) throws RepositoryException { String prefix = session.getNamespacePrefix( PentahoJcrConstants.PHO_NS ); Assert.hasText( prefix ); Map<String, Properties> localePropertiesMap = new HashMap<String, Properties>(); NodeIterator nodeItr = localesNode.getNodes(); while ( nodeItr.hasNext() ) { Node node = nodeItr.nextNode(); String locale = node.getName(); Properties properties = new Properties(); PropertyIterator propertyIterator = node.getProperties(); while ( propertyIterator.hasNext() ) { Property property = propertyIterator.nextProperty(); if ( !property.isMultiple() ) { properties.put( property.getName(), property.getValue().getString() ); } } localePropertiesMap.put( locale, properties ); } return localePropertiesMap; }
/** * Retrieve a single valued property from the given node. * * @param node * @return the property found or null if no property is found. */ public static Property searchSingleValuedProperty(Node node) throws RepositoryException, ValueFormatException { PropertyIterator props = node.getProperties(); while (props.hasNext()) { Property p = props.nextProperty(); if (!p.getDefinition().isMultiple()) { return p; } } // should never get here, since every Node must provide the jcr:primaryType // property, which is single valued. return null; } }
@Test public void getReferences() throws RepositoryException { Session session = getAdminSession(); Node referee = getNode("/foo"); referee.addMixin("mix:referenceable"); getNode(TEST_PATH).setProperty("reference", session.getValueFactory().createValue(referee)); session.save(); PropertyIterator refs = referee.getReferences(); assertTrue(refs.hasNext()); Property p = refs.nextProperty(); assertEquals("reference", p.getName()); assertFalse(refs.hasNext()); }
@Override protected void doExecute(InstallContext ctx) throws RepositoryException, TaskExecutionException { if (ctx.getConfigJCRSession().nodeExists(permissionsNodePath)) { Node permissions = ctx.getConfigJCRSession().getNode(permissionsNodePath); if (permissions.hasNode("roles") && (permissions.getNodes().getSize() - permissions.getNodes(NodeTypes.JCR_PREFIX + "*|" + NodeTypes.REP_PREFIX + "*").getSize()) == 1) { Node roles = permissions.getNode("roles"); if (roles.hasProperty("demo-project-base") && (roles.getProperties().getSize() - roles.getProperties(NodeTypes.JCR_PREFIX + "*|" + NodeTypes.MGNL_PREFIX + "*|" + NodeTypes.REP_PREFIX + "*").getSize()) == 1) { permissions.remove(); } else { log.warn("The permissions node {} could not be removed, because permissions/roles node does not have demo-project-base property or it contains another property besides demo-project-base", permissionsNodePath); } } else { log.warn("The permissions node {} could not be removed, because it does not contain roles node or it contains another node besides roles node", permissionsNodePath); } } else { log.warn("Could not find permissions node at path {}, the permissions node will not be removed", permissionsNodePath); } }
@Test public void getWeakReferences() throws RepositoryException { Session session = getAdminSession(); Node referee = getNode("/foo"); referee.addMixin("mix:referenceable"); getNode(TEST_PATH).setProperty("weak-reference", session.getValueFactory().createValue(referee, true)); session.save(); PropertyIterator refs = referee.getWeakReferences(); assertTrue(refs.hasNext()); Property p = refs.nextProperty(); assertEquals("weak-reference", p.getName()); assertFalse(refs.hasNext()); }