Copyright© 2008-2022 Sitevision AB, all rights reserved.
@Requireable(value="NodeIteratorUtil") public interface NodeIteratorUtil
An instance of the Sitevision class implementing this interface can be obtained via
Utils.getNodeIteratorUtil()
.
See Utils
for how to obtain an instance of the Utils
interface.
Modifier and Type | Method and Description |
---|---|
List<Node> |
findAll(NodeIterator aNodeIterator,
Filter<Node> aFilter)
Gets a list of all nodes from a node iterator that matches a specified filter.
|
Node |
findFirst(NodeIterator aNodeIterator,
Filter<Node> aFilter)
Gets the first node from a node iterator that matches a specified filter.
|
List<Node> |
findNodes(NodeIterator aNodeIterator,
Filter<Node> aFilter,
int aMaxNodesToFind)
Gets a max-sized node list from a node iterator that matches a specified filter.
|
NodeIterator |
getFilteredNodeIterator(NodeIterator aNodeIterator,
Filter<Node> aNodeFilter)
Gets a filtered NodeIterator.
|
NodeIterator |
getMenuItems(Node aParent)
Gets an iterator for default menu items (i.e. non-hidden pages, link pages etc. where current user has read permission)
|
NodeIterator |
getMenuItemsByIdentifier(String aIdentifier)
Gets an iterator for default menu items via a node identifier.
|
NodeIterator |
getMenuItemsIncludingFolders(Node aParent)
Gets an iterator for default menu items (i.e. getMenuItems(Node)), including folders
|
NodeIterator |
getMenuItemsIncludingFoldersByIdentifier(String aIdentifier)
Gets an iterator for default menu items (including folders) via a node identifier.
|
NodeIterator |
getNodeIteratorByIdentifier(String aIdentifier)
Gets a node iterator via a node identifier.
|
FilterSplit<Node> |
split(NodeIterator aNodeIterator,
Filter<Node> aFilter)
Gets the filtering result of a split operation for a node iterator with a node filter as divider.
|
List<Node> |
toList(NodeIterator aNodeIterator)
Gets a list of all nodes of a node iterator.
|
NodeIterator getFilteredNodeIterator(NodeIterator aNodeIterator, Filter<Node> aNodeFilter)
This NodeIterator decorates a NodeIterator with a Filter, i.e. it will only return nodes that matches given filter.
This server-side Javascript example demonstrates how to create a node iterator that is very similar to the
MenuItems
iterator but this node iterator is not respecting the "visibleInMenus" property.
const nodeFilterUtil = require('NodeFilterUtil');
const nodeIteratorUtil = require('NodeIteratorUtil');
const startNode = ...
const filter = nodeFilterUtil.getAnyOfPrimaryNodeTypesFilter([
'sv:page', 'sv:structurePage', 'sv:article', 'sv:link', 'sv:structureLink', 'sv:collaborationGroupPage'
]);
const nodes = nodeIteratorUtil.getFilteredNodeIterator(startNode.getNodes(), filter);
while (nodes.hasNext()) {
let node = nodes.nextNode();
...
}
aNodeIterator
- a NodeIterator, must not be nullaNodeFilter
- a Node Filter, must not be nullNullPointerException
- if aNodeIterator or aNodeFilter is nullNodeFilterUtil
NodeIterator getNodeIteratorByIdentifier(String aIdentifier)
The purpose of this method is twofold:
Session.getNodeByIdentifier(String)
and Node.getNodes()
,
i.e. a shortcut to get an iterator without having to actually lookup/resolve the parent node.
aIdentifier
- a node identifierNodeIterator
for the sub nodes of the Node resolved via aIdentifier
, or null
if indeterminableNodeIterator getMenuItems(Node aParent)
aParent
- the base node for the iteratorNodeIterator
for the sub nodes of aParent
, or null
if indeterminable
(i.e. aParent
is not a Node
in the page tree)NodeIterator getMenuItemsByIdentifier(String aIdentifier)
The purpose of this method is twofold:
Session.getNodeByIdentifier(String)
and getMenuItems(Node)
,
i.e. a shortcut to get a menu iterator without having to actually lookup/resolve the parent node.
aIdentifier
- a node identifierNodeIterator
for the sub nodes of the Node resolved via aIdentifier
, or null
if indeterminablegetMenuItems(Node)
NodeIterator getMenuItemsIncludingFolders(Node aParent)
aParent
- the base node for the iteratorNodeIterator
for the sub nodes of aParent
, or null
if indeterminable
(i.e. aParent
is not a Node
in the page tree)getMenuItems(Node)
NodeIterator getMenuItemsIncludingFoldersByIdentifier(String aIdentifier)
The purpose of this method is twofold:
Session.getNodeByIdentifier(String)
and
getMenuItemsIncludingFolders(Node)
, i.e. a shortcut to get a menu iterator without having to actually
lookup/resolve the parent node.
aIdentifier
- a node identifierNodeIterator
for the sub nodes of the Node resolved via aIdentifier
, or null
if indeterminablegetMenuItemsIncludingFolders(Node)
Node findFirst(NodeIterator aNodeIterator, Filter<Node> aFilter)
Tip! Use NodeFilterUtil
to get
an appropriate node filter.
aNodeIterator
- a node iteratoraFilter
- a node filteraFilter
, or null
.
If aFilter
is null
, the filter will be ignored (all nodes will be accepted).
If aNodeIterator
is null
, null
will be returned.List<Node> findNodes(NodeIterator aNodeIterator, Filter<Node> aFilter, int aMaxNodesToFind)
Tip! Use NodeFilterUtil
to get
an appropriate node filter. If the list of nodes should be sorted by a specific property value,
you would typically use NodeComparatorUtil
to get an appropriate Comparator
.
aNodeIterator
- a node iteratoraFilter
- a node filteraMaxNodesToFind
- max number of nodes to include in the resultaFilter
, never null
.
The list will contain at most aMaxNodesToFind
nodes.
If aFilter
is null
, the filter will be ignored (all nodes will be accepted).
If aNodeIterator
is null
, an empty list will be returned.
If aMaxNodesToFind
is negative, an empty list will be returned.List<Node> findAll(NodeIterator aNodeIterator, Filter<Node> aFilter)
Tip! Use NodeFilterUtil
to get
an appropriate node filter. If the list of nodes should be sorted by a specific property value,
you would typically use NodeComparatorUtil
to get an appropriate Comparator
.
aNodeIterator
- a node iteratoraFilter
- a node filteraFilter
, never null
.
If aFilter
is null
, the filter will be ignored (all nodes will be accepted).
If aNodeIterator
is null
, an empty list will be returned.List<Node> toList(NodeIterator aNodeIterator)
Note! This is a convenience method to use only when you must get nodes as a list!
The only apparent reason is when you need need to sort the nodes! If you don't, you should use
the NodeIterator
instead and do your processing for each node.
Sorting tip! When the list of nodes should be sorted by a specific property value,
you would typically use NodeComparatorUtil
to get an appropriate
Comparator
. The list can then be sorted by Collections.sort(List, Comparator)
.
When using Velocity, you must use the non-static class CollectionsInstance
.
aNodeIterator
- a node iteratoraNodeIterator
, never null
.FilterSplit<Node> split(NodeIterator aNodeIterator, Filter<Node> aFilter)
This method would typically be used instead of findAll(javax.jcr.NodeIterator, senselogic.sitevision.api.base.Filter)
when you are also interested in the nodes that does NOT match the filter.
Note! If aFilter
is null
, no nodes will match (all nodes
gathered via aNodeIterator
will be rejected in the resulting filter split).
aNodeIterator
- a node iteratoraFilter
- a node filterNodeFilterUtil.split(java.util.Collection, senselogic.sitevision.api.base.Filter)
Sitevision - Portal and Content Management Made Easy
Sitevision is an advanced Java enterprise portal product and a portlet container (JSR 286) that implements Java Content Repository (JSR 283).
Copyright© 2008-2022 Sitevision AB, all rights reserved.