use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class MembershipCache method collectDeclaredMembershipFromReferences.
/**
* Collects the declared memberships for the given authorizable by resolving the week references to the authorizable.
* If the lookup fails, <code>null</code> is returned. This most likely the case if the authorizable does not exit (yet)
* in the session that is used for the lookup.
*
* @param authorizableNodeIdentifier Identifier of the authorizable node
* @param session the session to read from
* @return a collection of group node ids or <code>null</code> if the lookup failed.
* @throws RepositoryException if an error occurs
*/
private Collection<String> collectDeclaredMembershipFromReferences(String authorizableNodeIdentifier, Session session) throws RepositoryException {
Set<String> pIds = new HashSet<String>();
Set<String> nIds = new HashSet<String>();
// Try to get membership information from references
PropertyIterator refs = getMembershipReferences(authorizableNodeIdentifier, session);
if (refs == null) {
return null;
}
while (refs.hasNext()) {
try {
PropertyImpl pMember = (PropertyImpl) refs.nextProperty();
NodeImpl nGroup = (NodeImpl) pMember.getParent();
Set<String> groupNodeIdentifiers;
if (P_MEMBERS.equals(pMember.getQName())) {
// Found membership information in members property
groupNodeIdentifiers = pIds;
} else {
// Found membership information in members node
groupNodeIdentifiers = nIds;
while (nGroup.isNodeType(NT_REP_MEMBERS)) {
nGroup = (NodeImpl) nGroup.getParent();
}
}
if (nGroup.isNodeType(NT_REP_GROUP)) {
groupNodeIdentifiers.add(nGroup.getIdentifier());
} else {
// weak-ref property 'rep:members' that doesn't reside under an
// group node -> doesn't represent a valid group member.
log.debug("Invalid member reference to '{}' -> Not included in membership set.", this);
}
} catch (ItemNotFoundException e) {
// group node doesn't exist -> -> ignore exception
// and skip this reference from membership list.
} catch (AccessDeniedException e) {
// not allowed to see the group node -> ignore exception
// and skip this reference from membership list.
}
}
// Based on the user's setting return either of the found membership information
return select(pIds, nIds);
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class Exporter method getProperties.
/**
* Returns a sorted map of the properties of the given node.
*
* @param node JCR node
* @return sorted map (keyed by name) of properties
* @throws RepositoryException if a repository error occurs
*/
private SortedMap getProperties(Node node) throws RepositoryException {
SortedMap properties = new TreeMap();
PropertyIterator iterator = node.getProperties();
while (iterator.hasNext()) {
Property property = iterator.nextProperty();
properties.put(property.getName(), property);
}
return properties;
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class JsonWriter method write.
private void write(Node node, int currentLevel, int maxLevels) throws RepositoryException, IOException {
// start of node info
writer.write('{');
// append the jcr properties as JSON pairs.
PropertyIterator props = node.getProperties();
while (props.hasNext()) {
Property prop = props.nextProperty();
writeProperty(prop);
// add separator: next json pair/member is either a property or
// a childnode or the special no-children-present pair.
writer.write(',');
}
// for jcr child nodes include member unless the max-depths is reached.
// in case there are no children at all, append a special pair.
final NodeIterator children = node.getNodes();
if (!children.hasNext()) {
// no child present at all -> add special property.
writeKeyValue("::NodeIteratorSize", 0);
} else {
// the child nodes
while (children.hasNext()) {
final Node n = children.nextNode();
String name = n.getName();
int index = n.getIndex();
if (index > 1) {
writeKey(name + "[" + index + "]");
} else {
writeKey(name);
}
if (maxLevels < 0 || currentLevel < maxLevels) {
write(n, currentLevel + 1, maxLevels);
} else {
/**
* In order to be able to compute the set of child-node entries
* upon Node creation -> add incomplete "node info" JSON
* object for the child node omitting properties and child
* information except for the jcr:uuid property (if present
* at all).
* the latter is required in order to build the correct SPI
* ChildInfo for Node n.
*/
writeChildInfo(n);
}
if (children.hasNext()) {
writer.write(',');
}
}
}
// end of node info
writer.write('}');
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class ExportDocViewTest method comparePropNumber.
/**
* Count the number of exported properties of a given node and compare with
* the number of the properties expected to be exported.
*
* @param node
* @param elem
* @throws RepositoryException
*/
private void comparePropNumber(Node node, Element elem) throws RepositoryException {
PropertyIterator iter = node.getProperties();
long size = getSize(node.getProperties());
long exported = new AttributeSeparator(elem).getNonNsAttrs().size();
while (iter.hasNext()) {
Property prop = iter.nextProperty();
String name = prop.getName();
boolean isMultiple = prop.getDefinition().isMultiple();
// props not exported so we decrease the expected size.
if (!exportInvalidXmlNames && !XMLChar.isValidName(name)) {
size--;
} else if (!exportMultivalProps && isMultiple) {
size--;
}
}
assertEquals("The number of properties exported of node " + node.getPath() + " is not correct.", size, exported);
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class RetentionPolicyTest method testPropertyPath.
public void testPropertyPath() throws RepositoryException, NotExecutableException {
String propPath = null;
for (PropertyIterator it = testRootNode.getProperties(); it.hasNext(); ) {
String path = it.nextProperty().getPath();
if (!superuser.nodeExists(path)) {
propPath = path;
break;
}
}
if (propPath == null) {
throw new NotExecutableException();
}
try {
retentionMgr.getRetentionPolicy(propPath);
fail("Accessing retention policy from property must throw PathNotFoundException.");
} catch (PathNotFoundException e) {
// success
}
try {
retentionMgr.setRetentionPolicy(propPath, getApplicableRetentionPolicy());
fail("Setting retention policy for property must throw PathNotFoundException.");
} catch (PathNotFoundException e) {
// success
}
try {
retentionMgr.removeRetentionPolicy(propPath);
fail("Removing retention policy at property path must throw PathNotFoundException.");
} catch (PathNotFoundException e) {
// success
}
}
Aggregations