javax.jcr.PropertyIterator Java Examples

The following examples show how to use javax.jcr.PropertyIterator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepositoryCFile.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
public ConsoleFile[] listFiles() throws IOException {
    try {
        if (item.isNode()) {
            Node node = (Node) item;
            ArrayList<RepositoryCFile> ret = new ArrayList<RepositoryCFile>();
            PropertyIterator piter = node.getProperties();
            while (piter.hasNext()) {
                ret.add(new RepositoryCFile(piter.nextProperty()));
            }
            NodeIterator niter = node.getNodes();
            while (niter.hasNext()) {
                ret.add(new RepositoryCFile(niter.nextNode()));
            }
            return ret.toArray(new RepositoryCFile[ret.size()]);
        } else {
            return ConsoleFile.EMPTY_ARRAY;
        }
    } catch (RepositoryException e) {
        throw new IOException(e.toString());
    }
}
 
Example #2
Source File: JcrStorageDao.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
public List<String> getReferences(String id) {
	List<String> result = new ArrayList<String>();
	try {
		Node node = checkId(id);
		PropertyIterator pi = node.getReferences();
		while (pi.hasNext()) {
			result.add(pi.nextProperty().getParent().getPath());
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return result;
}
 
Example #3
Source File: Webdav4ProviderTestCase.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/** Recursively outputs the contents of the given node. */
private static void dump(final Node node) throws RepositoryException {
    // First output the node path
    message(node.getPath());
    // Skip the virtual (and large!) jcr:system subtree
    if (node.getName().equals("jcr:system")) {
        return;
    }

    if (node.getName().equals("jcr:content")) {
        return;
    }

    // Then output the properties
    final PropertyIterator properties = node.getProperties();
    while (properties.hasNext()) {
        final Property property = properties.nextProperty();
        if (property.getDefinition().isMultiple()) {
            // A multi-valued property, print all values
            final Value[] values = property.getValues();
            for (final Value value : values) {
                message(property.getPath() + " = " + value.getString());
            }
        } else {
            // A single-valued property
            message(property.getPath() + " = " + property.getString());
        }
    }

    // Finally output all the child nodes recursively
    final NodeIterator nodes = node.getNodes();
    while (nodes.hasNext()) {
        dump(nodes.nextNode());
    }
}
 
Example #4
Source File: WebdavProviderTestCase.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/** Recursively outputs the contents of the given node. */
private static void dump(final Node node) throws RepositoryException {
    // First output the node path
    message(node.getPath());
    // Skip the virtual (and large!) jcr:system subtree
    if (node.getName().equals("jcr:system")) {
        return;
    }

    if (node.getName().equals("jcr:content")) {
        return;
    }

    // Then output the properties
    final PropertyIterator properties = node.getProperties();
    while (properties.hasNext()) {
        final Property property = properties.nextProperty();
        if (property.getDefinition().isMultiple()) {
            // A multi-valued property, print all values
            final Value[] values = property.getValues();
            for (final Value value : values) {
                message(property.getPath() + " = " + value.getString());
            }
        } else {
            // A single-valued property
            message(property.getPath() + " = " + property.getString());
        }
    }

    // Finally output all the child nodes recursively
    final NodeIterator nodes = node.getNodes();
    while (nodes.hasNext()) {
        dump(nodes.nextNode());
    }
}
 
Example #5
Source File: JcrTemplate.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Recursive method for dumping a node. This method is separate to avoid the overhead of searching and
 * opening/closing JCR sessions.
 * @param node
 * @return
 * @throws RepositoryException
 */
protected String dumpNode(Node node) throws RepositoryException {
    StringBuffer buffer = new StringBuffer();
    buffer.append(node.getPath());

    PropertyIterator properties = node.getProperties();
    while (properties.hasNext()) {
        Property property = properties.nextProperty();
        buffer.append(property.getPath()).append("=");
        if (property.getDefinition().isMultiple()) {
            Value[] values = property.getValues();
            for (int i = 0; i < values.length; i++) {
                if (i > 0) {
                    buffer.append(",");
                }
                buffer.append(values[i].getString());
            }
        } else {
            buffer.append(property.getString());
        }
        buffer.append("\n");
    }

    NodeIterator nodes = node.getNodes();
    while (nodes.hasNext()) {
        Node child = nodes.nextNode();
        buffer.append(dumpNode(child));
    }
    return buffer.toString();

}
 
Example #6
Source File: DefaultObjectWrapper.java    From sling-whiteboard with Apache License 2.0 5 votes vote down vote up
public PropertyIterator wrap(SessionWrapper s, final PropertyIterator iter) {
    return new PropertyIterator() {
        @Override
        public Property nextProperty() {
            return wrap(s, iter.nextProperty());
        }

        @Override
        public void skip(long skipNum) {
            iter.skip(skipNum);
        }

        @Override
        public long getSize() {
            return iter.getSize();
        }

        @Override
        public long getPosition() {
            return iter.getPosition();
        }

        @Override
        public boolean hasNext() {
            return iter.hasNext();
        }

        @Override
        public void remove() {
            iter.remove();
        }

        @Override
        public Object next() {
            // TODO cast to Property ok??
            return wrap(s, (Property)iter.next());
        }
    };
}
 
Example #7
Source File: BaseFilter.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean matches(Item item, int depth) throws RepositoryException {
    if (item.isNode()) {
        PropertyIterator iter = ((Node) item).getProperties();
        while (iter.hasNext()) {
            String name = iter.nextProperty().getName();
            if (!validNames.contains(name)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
 
Example #8
Source File: NodeImpl.java    From jackalope with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyIterator getProperties() throws RepositoryException {
    List<Property> children = new ArrayList<>();
    for (Item item : session.getChildren(this))
        if (!item.isNode())
            children.add((Property)item);
    return new PropertyIteratorImpl(children);
}
 
Example #9
Source File: NodeImpl.java    From jackalope with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyIterator getReferences() throws RepositoryException {
    return null;  //Not implemented
}
 
Example #10
Source File: StorageUpdate24.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
private void createOrUpdateCleanHistorySettings() throws RepositoryException, IOException {
	LOG.info("Update Clean History Settings Node");
	Node rootNode = getTemplate().getRootNode();
	Node settingsNode = rootNode.getNode(StorageConstants.NEXT_SERVER_FOLDER_NAME + StorageConstants.PATH_SEPARATOR
			+ StorageConstants.SETTINGS_FOLDER_NAME);

	NodeIterator ni = settingsNode.getNodes(StorageConstants.CLEAN_HISTORY);
	Settings s = new Settings();
	CleanHistorySettings ch = s.getCleanHistory();
	boolean found = false;
	boolean foundSettings = false;
	while (ni.hasNext()) {
		Node nn = ni.nextNode();
		// this is the node itself
		PropertyIterator ni2 = nn.getProperties();
		foundSettings = true;
		while (ni2.hasNext()) {
			Property nn2 = ni2.nextProperty();
			if (StorageConstants.DAYS_TO_DELETE.equals(nn2.getName())) {
				found = true;
				LOG.info("Found Clean History Settings Node DAYS_TO_DELETE skipping ...");
				break;
			}
		}
		if (!found) {
			nn.setProperty(StorageConstants.DAYS_TO_DELETE, ch.getDaysToDelete());
			getTemplate().save();
			LOG.info("Did not Found Clean History Settings Node DAYS_TO_DELETE adding default ...");
			break;
		}
	}

	if (!foundSettings) {
		LOG.info("Did not find Clean History Settings Node at all, adding default one");
		Node cleanHistoryNode = settingsNode.addNode(StorageConstants.CLEAN_HISTORY);
		cleanHistoryNode.addMixin("mix:referenceable");
		cleanHistoryNode.setProperty("className", CleanHistorySettings.class.getName());

		cleanHistoryNode.setProperty(StorageConstants.DAYS_TO_KEEP, ch.getDaysToKeep());
		cleanHistoryNode.setProperty(StorageConstants.CRON_EXPRESSION, ch.getCronExpression());
		cleanHistoryNode.setProperty(StorageConstants.DAYS_TO_DELETE, ch.getDaysToDelete());
		cleanHistoryNode.setProperty(StorageConstants.SHRINK_DATA_FOLDER, true);
		getTemplate().save();
	}

	
}
 
Example #11
Source File: AggregateImpl.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
/**
 * Walks the tree.
 *
 * @param aggregateWalkListener the listener
 * @param relPath rel path of node
 * @param node the current node
 * @param depth the depth of the node
 * @throws RepositoryException if an error occurs.
 */
private void walk(AggregateWalkListener aggregateWalkListener, String relPath, Node node, int depth)
        throws RepositoryException {
    if (node != null) {
        boolean included = includes(relPath);
        aggregateWalkListener.onNodeBegin(node, included, depth);
        PropertyIterator piter = node.getProperties();
        while (piter.hasNext()) {
            Property prop = piter.nextProperty();
            if (includes(relPath + "/" + prop.getName())) {
                aggregateWalkListener.onProperty(prop, depth + 1);
            }
        }
        aggregateWalkListener.onChildren(node, depth);

        // copy nodes to list
        NodeIterator niter = node.getNodes();
        long size = niter.getSize();
        List<Node> nodes = new ArrayList<Node>(size > 0 ? (int) size : 16);
        while (niter.hasNext()) {
            nodes.add(niter.nextNode());
        }

        // if node is not orderable, sort them alphabetically
        boolean hasOrderableChildNodes = node.getPrimaryNodeType().hasOrderableChildNodes();
        if (!hasOrderableChildNodes) {
            Collections.sort(nodes, NodeNameComparator.INSTANCE);
        }
        for (Node child: nodes) {
            String p = relPath + "/" + Text.getName(child.getPath());
            if (includes(p)) {
                walk(aggregateWalkListener, p, child, depth + 1);
            } else {
                // only inform if node is orderable
                if (hasOrderableChildNodes) {
                    aggregateWalkListener.onNodeIgnored(child, depth+1);
                }
            }
        }
        aggregateWalkListener.onNodeEnd(node, included, depth);
    }
}
 
Example #12
Source File: NodeImpl.java    From jackalope with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyIterator getWeakReferences(String name) throws RepositoryException {
    return null;  //Not implemented
}
 
Example #13
Source File: NodeImpl.java    From jackalope with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyIterator getWeakReferences() throws RepositoryException {
    return null;  //Not implemented
}
 
Example #14
Source File: NodeImpl.java    From jackalope with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyIterator getReferences(String name) throws RepositoryException {
    return null;  //Not implemented
}
 
Example #15
Source File: NodeWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyIterator getProperties() throws RepositoryException {
    return sessionWrapper.getObjectWrapper().wrap(sessionWrapper, delegate.getProperties());
}
 
Example #16
Source File: NodeImpl.java    From jackalope with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyIterator getProperties(String[] nameGlobs) throws RepositoryException {
    return null;  //Not implemented
}
 
Example #17
Source File: NodeImpl.java    From jackalope with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyIterator getProperties(String namePattern) throws RepositoryException {
    return null;  //Not implemented
}
 
Example #18
Source File: NodeWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyIterator getWeakReferences(String name) throws RepositoryException {
    return sessionWrapper.getObjectWrapper().wrap(sessionWrapper, delegate.getWeakReferences(name));
}
 
Example #19
Source File: NodeWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyIterator getWeakReferences() throws RepositoryException {
    return sessionWrapper.getObjectWrapper().wrap(sessionWrapper, delegate.getWeakReferences());
}
 
Example #20
Source File: NodeWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyIterator getReferences(String name) throws RepositoryException {
    return sessionWrapper.getObjectWrapper().wrap(sessionWrapper, delegate.getReferences(name));
}
 
Example #21
Source File: NodeWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyIterator getReferences() throws RepositoryException {
    return sessionWrapper.getObjectWrapper().wrap(sessionWrapper, delegate.getReferences());
}
 
Example #22
Source File: NodeWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyIterator getProperties(String[] nameGlobs) throws RepositoryException {
    return sessionWrapper.getObjectWrapper().wrap(sessionWrapper, delegate.getProperties(nameGlobs));
}
 
Example #23
Source File: NodeWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyIterator getProperties(String namePattern) throws RepositoryException {
    return sessionWrapper.getObjectWrapper().wrap(sessionWrapper, delegate.getProperties(namePattern));
}
 
Example #24
Source File: ObjectWrapper.java    From sling-whiteboard with Apache License 2.0 votes vote down vote up
PropertyIterator wrap(SessionWrapper s, final PropertyIterator iter);