use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class AuthorizableImplTest method testUserGetProperties.
public void testUserGetProperties() throws RepositoryException, NotExecutableException {
AuthorizableImpl user = (AuthorizableImpl) getTestUser(superuser);
NodeImpl n = user.getNode();
for (PropertyIterator it = n.getProperties(); it.hasNext(); ) {
PropertyImpl p = (PropertyImpl) it.nextProperty();
if (p.getDefinition().isProtected()) {
assertFalse(user.hasProperty(p.getName()));
assertNull(user.getProperty(p.getName()));
} else {
// authorizable defined property
assertTrue(user.hasProperty(p.getName()));
assertNotNull(user.getProperty(p.getName()));
}
}
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class VersionItemCollection method getProperty.
@Override
public DavProperty<?> getProperty(DavPropertyName name) {
DavProperty prop = super.getProperty(name);
if (prop == null && exists()) {
Version v = (Version) item;
try {
if (VERSION_NAME.equals(name)) {
// required, protected DAV:version-name property
prop = new DefaultDavProperty<String>(VERSION_NAME, v.getName(), true);
} else if (VERSION_HISTORY.equals(name)) {
// required DAV:version-history (computed) property
String vhHref = getLocatorFromItem(getVersionHistoryItem()).getHref(true);
prop = new HrefProperty(VERSION_HISTORY, vhHref, true);
} else if (PREDECESSOR_SET.equals(name)) {
// required DAV:predecessor-set (protected) property
prop = getHrefProperty(VersionResource.PREDECESSOR_SET, v.getPredecessors(), true);
} else if (SUCCESSOR_SET.equals(name)) {
// required DAV:successor-set (computed) property
prop = getHrefProperty(SUCCESSOR_SET, v.getSuccessors(), true);
} else if (LABEL_NAME_SET.equals(name)) {
// required, protected DAV:label-name-set property
String[] labels = getVersionHistoryItem().getVersionLabels(v);
prop = new LabelSetProperty(labels);
} else if (CHECKOUT_SET.equals(name)) {
// required DAV:checkout-set (computed) property
PropertyIterator it = v.getReferences();
List<Node> nodeList = new ArrayList<Node>();
while (it.hasNext()) {
Property p = it.nextProperty();
if (JcrConstants.JCR_BASEVERSION.equals(p.getName())) {
Node n = p.getParent();
if (n.isCheckedOut()) {
nodeList.add(n);
}
}
}
prop = getHrefProperty(CHECKOUT_SET, nodeList.toArray(new Node[nodeList.size()]), true);
}
} catch (RepositoryException e) {
log.error(e.getMessage());
}
}
return prop;
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class JsonWriterTest method testDoubleOutput.
@Test
public void testDoubleOutput() throws Exception {
StringWriter writer = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(writer);
Node parent = createMock(Node.class);
Property doubleProperty = createMock(Property.class);
Value doublePropertyValue = createMock(Value.class);
expect(doubleProperty.getType()).andReturn(PropertyType.DOUBLE).anyTimes();
expect(doubleProperty.getName()).andReturn("singleValued").anyTimes();
expect(doubleProperty.isMultiple()).andReturn(false).anyTimes();
expect(doubleProperty.getValue()).andReturn(doublePropertyValue).anyTimes();
expect(doublePropertyValue.getType()).andReturn(PropertyType.DOUBLE).anyTimes();
expect(doublePropertyValue.getDouble()).andReturn(5d).anyTimes();
expect(doublePropertyValue.getString()).andReturn("5").anyTimes();
Property mvDoubleProperty = createMock(Property.class);
Value mvDoublePropertyValue1 = createMock(Value.class);
Value mvDoublePropertyValue2 = createMock(Value.class);
expect(mvDoubleProperty.getType()).andReturn(PropertyType.DOUBLE).anyTimes();
expect(mvDoubleProperty.getName()).andReturn("multiValued").anyTimes();
expect(mvDoubleProperty.isMultiple()).andReturn(true).anyTimes();
expect(mvDoubleProperty.getValues()).andReturn(new Value[] { mvDoublePropertyValue1, mvDoublePropertyValue2 }).anyTimes();
expect(mvDoublePropertyValue1.getType()).andReturn(PropertyType.DOUBLE).anyTimes();
expect(mvDoublePropertyValue1.getDouble()).andReturn(42d).anyTimes();
expect(mvDoublePropertyValue1.getString()).andReturn("42").anyTimes();
expect(mvDoublePropertyValue2.getType()).andReturn(PropertyType.DOUBLE).anyTimes();
expect(mvDoublePropertyValue2.getDouble()).andReturn(98.6).anyTimes();
expect(mvDoublePropertyValue2.getString()).andReturn("98.6").anyTimes();
final List<Property> properties = new ArrayList<Property>();
properties.add(doubleProperty);
properties.add(mvDoubleProperty);
expect(parent.getProperties()).andAnswer(new IAnswer<PropertyIterator>() {
@Override
public PropertyIterator answer() throws Throwable {
return new PropertyIteratorAdapter(properties.iterator());
}
});
expect(parent.getNodes()).andAnswer(new IAnswer<NodeIterator>() {
@Override
public NodeIterator answer() throws Throwable {
return new NodeIteratorAdapter(Collections.<Node>emptyIterator());
}
});
replayAll();
jsonWriter.write(parent, 1);
assertEquals("{\":singleValued\":\"Double\",\"singleValued\":5,\":multiValued\":\"Double\",\"multiValued\":[42,98.6],\"::NodeIteratorSize\":0}", writer.toString());
verifyAll();
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class PropertyUtil method searchMultivalProp.
/**
* 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;
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class PropertyUtil method searchMultivalProp.
/**
* Helper method to find a multivalue property of a given type.
*
* @param node the node to start the search from.
* @param type the property type.
* @return a multivalue property or null if not found any.
*/
public static Property searchMultivalProp(Node node, int type) throws RepositoryException {
Property multiVal = null;
for (PropertyIterator props = node.getProperties(); props.hasNext(); ) {
Property property = props.nextProperty();
if (property.getDefinition().isMultiple() && property.getType() == type) {
multiVal = property;
break;
}
}
if (multiVal == null) {
for (NodeIterator nodes = node.getNodes(); nodes.hasNext(); ) {
Node n = nodes.nextNode();
multiVal = searchMultivalProp(n, type);
if (multiVal != null) {
break;
}
}
}
return multiVal;
}
Aggregations