Copyright© 2008-2022 Sitevision AB, all rights reserved.
@Requireable(value="NodeTreeUtil") public interface NodeTreeUtil
An instance of the Sitevision class implementing this interface can be obtained via
Utils.getNodeTreeUtil()
.
See Utils
for how to obtain an instance of the Utils
interface.
Modifier and Type | Method and Description |
---|---|
Node |
findPortletByName(Node aPageNode,
String aPortletName)
Find a portlet with a specific name on a page node.
|
List<Node> |
findPortletsByName(Node aPageNode,
String aPortletName)
Find all portlets with a specific name on a page node.
|
List<Node> |
findPortletsByName(Node aPageNode,
String aPortletName,
Filter<Node> aNodeFilter)
Find all portlets with a specific name on a page node and applies a node filter to the result.
|
List<Node> |
findPortletsByType(Node aPageNode,
String aPortletType)
Find all portlets of a specific type on a page node.
|
List<Node> |
findPortletsByType(Node aPageNode,
String aPortletType,
Filter<Node> aNodeFilter)
Find all portlets with a specific type on a page node and applies a node filter to the result.
|
Node |
getNode(Node aNode,
String aRelPath)
Gets a node relative to another node.
|
Node |
getParent(Node aNode)
Gets the parent of a node.
|
List<Node> |
getWebPathNodes(Node aDescendantNode)
Returns a top-down list of all web nodes from the site page down to a specified page tree node.
|
boolean |
isDescendantOf(Node aDescendantNode,
Node aParentNode)
Check if a given page tree node is a descendant of another page tree node.
|
Node getNode(Node aNode, String aRelPath)
Note! This is mere a convenience alias for Node.getNode(String)
but unlike the original,
this method returns null instead of throwing an exception if no node could be retrieved at a specified path.
aNode
- the nodeaRelPath
- the relative path (of aNode
) to the node to retrieveaRelPath
, or null
if no such node could be retrievedNode getParent(Node aNode)
Note! This is mere a convenience alias for Item.getParent()
but unlike the original,
this method returns null instead of throwing an exception if no parent node could be retrieved.
aNode
- the nodeaNode
, or null
if no parent could be retrievedboolean isDescendantOf(Node aDescendantNode, Node aParentNode)
aDescendantNode
- the presumed descendant page tree Node
(e.g. "child node")aParentNode
- the presumed parent page tree Node
of the descendanttrue
if aDescendantNode
is a descendant of aParentNode
, false
otherwiseNode findPortletByName(Node aPageNode, String aPortletName)
The name of the portlet is determined by the displayName property.
aPageNode
- the page node that has content, typically a sv:page or sv:articleaPortletName
- the name of the sv:portlet that should be foundaPortletName
, or null
if no such portlet can be found
or if aPageNode
is not a page nodefindPortletsByName(Node,String)
List<Node> findPortletsByName(Node aPageNode, String aPortletName)
The name of the portlet is determined by the displayName property.
aPageNode
- the page node that has content, typically a sv:page or sv:articleaPortletName
- the name of the sv:portlet that should be foundaPortletName
.
If no such portlets can be found or if aPageNode
is not a page node, an empty List
is returnedfindPortletByName(Node,String)
List<Node> findPortletsByName(Node aPageNode, String aPortletName, Filter<Node> aNodeFilter)
The name of the portlet is determined by the displayName property.
Tip! NodeFilterUtil
can be used to create a node filter.
aPageNode
- the page node that has content, typically a sv:page or sv:articleaPortletName
- the name of the sv:portlet that should be foundaNodeFilter
- a node filter to refine the result of all portlets with specified nameaPortletName
that also applies to the aNodeFilter
filter.
If no such portlets can be found or if aPageNode
is not a page node, an empty List
is returnedList<Node> findPortletsByType(Node aPageNode, String aPortletType)
The type of the portlet is determined by the portletName property. This is typically
the value that is specified in the <portlet-name> element of the portlet in portlet.xml
.
Types for some common portlets:
text
image
aPageNode
- the page node that has content, typically a sv:page or sv:articleaPortletType
- the type of sv:portlet that should be foundaPortletType
.
If no such portlets can be found or if aPageNode
is not a page node, an empty List
is returnedList<Node> findPortletsByType(Node aPageNode, String aPortletType, Filter<Node> aNodeFilter)
The type of the portlet is determined by the portletName property. This is typically
the value that is specified in the <portlet-name> element of the portlet in portlet.xml
.
Types for some common portlets:
text
image
Tip! NodeFilterUtil
can be used to create a node filter.
Below is a Velocity example that demonstrates how to extract all Image portlets from the content of a specified page. A node filter is applied to only return the Image portlets that has a display name that contains the word logo.
## Create a filter that matches nodes that has a displayName that contains "logo"
#set ($nodeFilterUtil = $sitevisionUtils.NodeFilterUtil)
#set ($containsLogoFilter = $nodeFilterUtil.getContainsStringPropertyFilter('displayName', 'logo'))
## Extract all matching Image portlets from the page
#set ($logoImagePortlets = $nodeTreeUtil.findPortletsByType($thePage, 'image', $containsLogoFilter))
#if (!$logoImagePortlets.isEmpty())
## Handle matching image portlets
...
#end
Below is another Velocity example. A node filter is applied to only return the Image portlets that uses images that has a width between 24px and 132px (an Image portlet has a 'image' property that can be resolved as a sv:image Node and such node has a 'width' property).
## Create a filter that matches nodes that has a nested width between [24..132]
#set ($nodeFilterUtil = $sitevisionUtils.NodeFilterUtil)
#set ($imageWidthFilter = $nodeFilterUtil.getRangeNestedIntPropertyFilter('image', 'width', 24, 132))
## Extract all Image portlets that uses an "appropriate" image
#set ($foundImagePortlets = $nodeTreeUtil.findPortletsByType($thePage, 'image', $imageWidthFilter))
#if (!$foundImagePortlets.isEmpty())
## Handle matching image portlets
...
#end
aPageNode
- the page node that has content, typically a sv:page or sv:articleaPortletType
- the type of sv:portlet that should be foundaNodeFilter
- a node filter to refine the result of all portlets of specified typeaPortletType
that also applies to the aNodeFilter
filter.
If no such portlets can be found or if aPageNode
is not a page node, an empty List
is returnedList<Node> getWebPathNodes(Node aDescendantNode)
This method traverses the site page tree and returns a list of all web nodes, from the site page to a descendant. The tree traversal will use a maximum tree depth of 50. If the specified node is deeper down in the tree than that, an incomplete list will be returned (top nodes will be missing).
Note! Mentioned "web nodes" are by this method considered to be all child nodes of the site page node you can see in the Sitevision editor Navigator that are accessible from the location bar of a browser (e.g. pages and articles but not folders and archives). File and image nodes are also recognized as web nodes - even if they are in the "site global" archive (i.e. in the site tree, not actually in the site page tree). In other words, though they are accessible from the location bar of a browser - a portlet node or layout node is not considered to be a web node by this method.
Tip! If you should render a linked "path to this page", consider using the renderWebPathNodes
utility of OutputUtil
.
aDescendantNode
- a page tree node that is a descendant/child of the site page, typically a sv:page or sv:articleaDescendantNode
(the site page node and the descendant node are both included in the list).
An empty list will be returned if aDescendantNode
is null
or not a descendant of the site page.OutputUtil.renderWebPathNodes(javax.jcr.Node, senselogic.sitevision.api.render.LinkRenderer, String)
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.