Search in sources :

Example 1 with NodeIteratorAdapter

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);
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ArrayList(java.util.ArrayList) NodeId(org.apache.jackrabbit.core.id.NodeId) NodeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter)

Example 2 with NodeIteratorAdapter

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;
}
Also used : Node(javax.jcr.Node) NodeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter) PathNotFoundException(javax.jcr.PathNotFoundException) HashSet(java.util.HashSet)

Example 3 with NodeIteratorAdapter

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;
}
Also used : HashMap(java.util.HashMap) Node(javax.jcr.Node) NodeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 4 with NodeIteratorAdapter

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()));
}
Also used : FilterContentPackage(org.apache.jackrabbit.commons.packaging.FilterContentPackage) IsNodePredicate(org.apache.jackrabbit.commons.predicate.IsNodePredicate) NodeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter)

Example 5 with NodeIteratorAdapter

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();
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PropertyIteratorAdapter(org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter) ArrayList(java.util.ArrayList) PropertyIterator(javax.jcr.PropertyIterator) NodeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter) StringWriter(java.io.StringWriter) Value(javax.jcr.Value) Property(javax.jcr.Property) Test(org.junit.Test)

Aggregations

NodeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter)8 Node (javax.jcr.Node)4 NodeIterator (javax.jcr.NodeIterator)3 PathNotFoundException (javax.jcr.PathNotFoundException)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 RepositoryException (javax.jcr.RepositoryException)2 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 Pattern (java.util.regex.Pattern)1 Property (javax.jcr.Property)1 PropertyIterator (javax.jcr.PropertyIterator)1 RangeIterator (javax.jcr.RangeIterator)1 Value (javax.jcr.Value)1 RowIterator (javax.jcr.query.RowIterator)1 PropertyIteratorAdapter (org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter)1 FilterContentPackage (org.apache.jackrabbit.commons.packaging.FilterContentPackage)1 IsNodePredicate (org.apache.jackrabbit.commons.predicate.IsNodePredicate)1