use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class TreeComparator method showTree.
/**
* Recursive display of source and target tree
*/
public void showTree(Node n, int level) throws RepositoryException {
StringBuffer sb = new StringBuffer();
for (int t = 0; t < level; t++) {
sb.append("-");
}
sb.append(n.getName() + " ");
sb.append(n.getPrimaryNodeType().getName() + " [ ");
PropertyIterator pi = n.getProperties();
while (pi.hasNext()) {
Property p = (Property) pi.next();
sb.append(p.getName() + " ");
}
sb.append("]");
sc.log(sb.toString());
NodeIterator ni = n.getNodes();
while (ni.hasNext()) {
showTree((Node) ni.next(), level + 1);
}
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class NodeImpl method getWeakReferences.
/**
* {@inheritDoc}
*/
public PropertyIterator getWeakReferences() throws RepositoryException {
// check state of this instance
sanityCheck();
// shortcut if node isn't referenceable
if (!isNodeType(NameConstants.MIX_REFERENCEABLE)) {
return PropertyIteratorAdapter.EMPTY;
}
Value ref = getSession().getValueFactory().createValue(this, true);
List<Property> props = new ArrayList<Property>();
QueryManagerImpl qm = (QueryManagerImpl) getSession().getWorkspace().getQueryManager();
for (Node n : qm.getWeaklyReferringNodes(this)) {
for (PropertyIterator it = n.getProperties(); it.hasNext(); ) {
Property p = it.nextProperty();
if (p.getType() == PropertyType.WEAKREFERENCE) {
Collection<Value> refs;
if (p.isMultiple()) {
refs = Arrays.asList(p.getValues());
} else {
refs = Collections.singleton(p.getValue());
}
if (refs.contains(ref)) {
props.add(p);
}
}
}
}
return new PropertyIteratorAdapter(props);
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class BTreeManager method getProperties.
/**
* Returns a {@link SizedIterator} of the properties of <code>node</code>
* which excludes the <code>jcr.primaryType</code> property.
*/
@SuppressWarnings({ "deprecation", "unchecked" })
protected SizedIterator<Property> getProperties(Node node) throws RepositoryException {
final PropertyIterator properties = node.getProperties();
long size = properties.getSize();
for (Iterator<String> ignored = ignoredProperties.iterator(); size > 0 && ignored.hasNext(); ) {
if (node.hasProperty(ignored.next())) {
size--;
}
}
return getSizedIterator(filterProperties(properties), size);
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class AbstractNode method getProperty.
/**
* Returns the property at the given relative path from this node.
* <p>
* The default implementation looks up the parent node of the given
* relative path and iterates through the properties of that node to
* find and return the identified property.
*
* @param relPath relative path of the property
* @return property
* @throws PathNotFoundException if the property is not found
* @throws RepositoryException if an error occurs
*/
public Property getProperty(String relPath) throws PathNotFoundException, RepositoryException {
// Corner case, remove any "/." self references at the end of the path
while (relPath.endsWith("/.")) {
relPath = relPath.substring(0, relPath.length() - 2);
}
// Find the parent node of the identified property
Node node = this;
int slash = relPath.lastIndexOf('/');
if (slash == 0) {
node = getSession().getRootNode();
relPath = relPath.substring(1);
} else if (slash > 0) {
node = getNode(relPath.substring(0, slash));
relPath = relPath.substring(slash + 1);
}
// Look for the named property. Must iterate and re-check for the name
// since the client could have used an invalid path like "./a|b".
PropertyIterator properties = node.getProperties(relPath);
while (properties.hasNext()) {
Property property = (Property) properties.next();
if (relPath.equals(property.getName())) {
return property;
}
}
throw new PathNotFoundException("Property not found: " + relPath);
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class NodeReadMethodsTest method testGetProperties.
/**
* Test if all returned items are of type node.
*/
public void testGetProperties() throws RepositoryException {
PropertyIterator properties = testRootNode.getProperties();
while (properties.hasNext()) {
Item item = (Item) properties.next();
assertFalse("Item is not a property", item.isNode());
}
}
Aggregations