use of org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter in project jackrabbit by apache.
the class NodeImpl method getSharedSet.
//-------------------------------------------------------< shareable nodes >
/**
* Returns an iterator over all nodes that are in the shared set of this
* node. If this node is not shared then the returned iterator contains
* only this node.
*
* @return a <code>NodeIterator</code>
* @throws RepositoryException if an error occurs.
* @since JCR 2.0
*/
public NodeIterator getSharedSet() throws RepositoryException {
// check state of this instance
sanityCheck();
ArrayList<NodeImpl> list = new ArrayList<NodeImpl>();
if (!isShareable()) {
list.add(this);
} else {
NodeState state = data.getNodeState();
for (NodeId parentId : state.getSharedSet()) {
list.add(itemMgr.getNode(getNodeId(), parentId));
}
}
return new NodeIteratorAdapter(list);
}
use of org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter in project jackrabbit by apache.
the class TraversingNodeResolver method findNodes.
/**
* @inheritDoc
*/
@Override
public NodeIterator findNodes(Set<Name> propertyNames, String value, Name ntName, boolean exact, long maxSize) throws RepositoryException {
String sr = getSearchRoot(ntName);
if (getSession().nodeExists(sr)) {
try {
Node root = getSession().getNode(sr);
Set<Node> matchSet = new HashSet<Node>();
collectNodes(value, propertyNames, ntName, root.getNodes(), matchSet, exact, maxSize);
return new NodeIteratorAdapter(matchSet);
} catch (PathNotFoundException e) {
// should not get here
log.warn("Error while retrieving node " + sr);
}
}
// else: searchRoot does not exist yet -> omit the search
return NodeIteratorAdapter.EMPTY;
}
use of org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter in project jackrabbit by apache.
the class TraversingNodeResolver method findNodes.
/**
* @inheritDoc
*/
@Override
public NodeIterator findNodes(Path relPath, String value, int authorizableType, boolean exact, long maxSize) throws RepositoryException {
String sr = getSearchRoot(authorizableType);
if (getSession().nodeExists(sr)) {
try {
String path = getNamePathResolver().getJCRPath(relPath);
AuthorizableTypePredicate pred = getAuthorizableTypePredicate(authorizableType, relPath.getLength() > 1);
Node root = getSession().getNode(sr);
Map<String, Node> matchingNodes = new HashMap<String, Node>();
collectNodes(value, path, pred, root.getNodes(), matchingNodes, exact, maxSize);
return new NodeIteratorAdapter(matchingNodes.values());
} catch (PathNotFoundException e) {
// should not get here
log.warn("Error while retrieving node " + sr);
}
}
// else: searchRoot does not exist yet -> omit the search
return NodeIteratorAdapter.EMPTY;
}
use of org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter in project jackrabbit by apache.
the class TraverseNodes method execute.
public NodeIterator execute() throws Exception {
FilterContentPackage pack = new FilterContentPackage();
pack.addContent(getPath(), new IsNodePredicate());
return new NodeIteratorAdapter(pack.getItems(getSession()));
}
use of org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter 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();
}
Aggregations