Copyright© 2008-2022 Sitevision AB, all rights reserved.
@Requireable(value="OutputUtil") public interface OutputUtil extends VelocityAccess.OutputUtilConstants
An instance of the Sitevision class implementing this interface can be obtained via Utils.getOutputUtil()
.
See Utils
for how to obtain an instance of the Utils
interface.
Modifier and Type | Field and Description |
---|---|
static int |
CONTENT_TYPE_TEXT_HTML
The "text/html" content-type marker
|
static int |
CONTENT_TYPE_TEXT_PLAIN
The "text/plain" content-type marker
|
static int |
CONTENT_TYPE_TEXT_XML
The "text/xml" content-type marker
|
Modifier and Type | Method and Description |
---|---|
String |
getEscapedHtmlText(String aPlainText,
Node aFontNode)
Gets a text escaped and embedded in a html element with a class attribute.
|
String |
getEscapedHtmlText(String aPlainText,
Node aFontNode,
String aStyle)
Gets a text escaped and embedded in a html element with a class attribute and a style attribute.
|
String |
getHtmlText(String aText,
Node aFontNode)
Gets a text embedded in a html element with a class attribute.
|
String |
getHtmlText(String aText,
Node aFontNode,
String aStyle)
Gets a text embedded in a html element with a class attribute and a style attribute.
|
String |
getHyperlinkedText(String aText)
Hyperlinks text.
|
String |
getHyperlinkedText(String aText,
String aClass,
String aStyle)
Hyperlinks text and uses a specified css class for created anchors.
|
String |
getNodeAsText(Node aNode)
Deprecated.
|
String |
getNodeInfoAsHTML(Node aNode)
Debug method that returns info about the properties of a node and all its sub nodes.
|
String |
getNodeInfoAsHTML(Node aNode,
int aDepth)
Debug method that returns info about the properties of a node and all its sub nodes recursively until a given sub level
aDepth is reached. |
String |
getNodeOutput(Node aPageNode,
Node aPagePartNode,
int aContentType)
Gets the output as a specific content-type from a page node or a page content node.
|
String |
renderWebPathNodes(Node aDescendantNode,
LinkRenderer aLinkRenderer,
String aSeparator)
Convenience method for rendering a linked web path to a specified node.
|
getCONTENT_TYPE_TEXT_HTML, getCONTENT_TYPE_TEXT_PLAIN, getCONTENT_TYPE_TEXT_XML
static final int CONTENT_TYPE_TEXT_PLAIN
static final int CONTENT_TYPE_TEXT_HTML
static final int CONTENT_TYPE_TEXT_XML
String getHtmlText(String aText, Node aFontNode)
aFontNode
. The html element in the returned result
will always be a paragraph (<p>
) with no class attribute if aFontNode
is null
or not of primary type sv:font
.
Some examples:
Method call: getHtmlText("Hello world! one < two", myFontNode)
will return any of the following:
<h1 class="selectorTextOfMyFontNode">Hello world! one < two</h1>
<h2 class="selectorTextOfMyFontNode">Hello world! one < two</h2>
<h3 class="selectorTextOfMyFontNode">Hello world! one < two</h3>
<h4 class="selectorTextOfMyFontNode">Hello world! one < two</h4>
<h5 class="selectorTextOfMyFontNode">Hello world! one < two</h5>
<h6 class="selectorTextOfMyFontNode">Hello world! one < two</h6>
<p class="selectorTextOfMyFontNode">Hello world! one < two</p>
<span class="selectorTextOfMyFontNode">Hello world! one < two</span>
<code class="selectorTextOfMyFontNode">Hello world! one < two</code>
<sub class="selectorTextOfMyFontNode">Hello world! one < two</sub>
<sup class="selectorTextOfMyFontNode">Hello world! one < two</sup>
Method call: getHtmlText("Hello world! one < two", null)
will return this:
<p>Hello world! one < two</p>
aText
- the text to be embedded in a html elementaFontNode
- a Node
of primary type sv:font
that determines the type of html element to use and the
class attribute value of the elementaText
embedded in a html element, or empty String
if aText
is null
getEscapedHtmlText(String, javax.jcr.Node)
String getHtmlText(String aText, Node aFontNode, String aStyle)
aFontNode
. The html element in the returned result
will always be a paragraph (<p>
) with no class attribute if aFontNode
is null
or not of primary type sv:font
.
aStyle
will be ignored if it is null
.
Some examples:
Method call: getHtmlText("Hello world! one < two", myFontNode, "padding-left:0.7em")
will return any of the following:
<h1 class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</h1>
<h2 class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</h2>
<h3 class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</h3>
<h4 class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</h4>
<h5 class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</h5>
<h6 class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</h6>
<p class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</p>
<span class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</span>
<code class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</code>
<sub class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</sub>
<sup class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</sup>
Method call: getHtmlText("Hello world! one < two", null, "padding-left:0.7em")
will return this:
<p style="padding-left:0.7em">Hello world! one < two</p>
Method call: getHtmlText("Hello world! one < two", null, null)
will return this:
<p>Hello world! one < two</p>
Method call: getHtmlText("Hello world! one < two", myFontNode, null)
will return the same result as if the getHtmlText(String, Node)
method had been invoked.
aText
- the text to be embedded in a html elementaFontNode
- a Node
of primary type sv:font
that determines the type of html element to use and the
class attribute value of the elementaStyle
- the style that should be inserted in the style attribute of the elementaText
embedded in a html element, or empty String
if aText
is null
getEscapedHtmlText(String, javax.jcr.Node, String)
String getEscapedHtmlText(String aPlainText, Node aFontNode)
aFontNode
. The html element in the returned result
will always be a paragraph (<p>
) with no class attribute if aFontNode
is null
or not of primary type sv:font
.
Some examples:
Method call: getEscapedHtmlText("Hello world! one < two", myFontNode)
will return any of the following:
<h1 class="selectorTextOfMyFontNode">Hello world! one < two</h1>
<h2 class="selectorTextOfMyFontNode">Hello world! one < two</h2>
<h3 class="selectorTextOfMyFontNode">Hello world! one < two</h3>
<h4 class="selectorTextOfMyFontNode">Hello world! one < two</h4>
<h5 class="selectorTextOfMyFontNode">Hello world! one < two</h5>
<h6 class="selectorTextOfMyFontNode">Hello world! one < two</h6>
<p class="selectorTextOfMyFontNode">Hello world! one < two</p>
<span class="selectorTextOfMyFontNode">Hello world! one < two</span>
<code class="selectorTextOfMyFontNode">Hello world! one < two</code>
<sub class="selectorTextOfMyFontNode">Hello world! one < two</sub>
<sup class="selectorTextOfMyFontNode">Hello world! one < two</sup>
Method call: getEscapedHtmlText("Hello world! one < two", null)
will return this:
<p>Hello world! one < two</p>
aPlainText
- the text to be escaped and embedded in a html elementaFontNode
- a Node
of primary type sv:font
that determines the type of html element to use and the
class attribute value of the elementaPlainText
escaped and embedded in a html element, or empty String if aPlainText
is nullgetHtmlText(String, javax.jcr.Node)
String getEscapedHtmlText(String aPlainText, Node aFontNode, String aStyle)
aFontNode
. The html element in the returned result
will always be a paragraph (<p>
) with no class attribute if aFontNode
is null
or not of primary type sv:font
.
aStyle
will be ignored if it is null
.
Some examples:
Method call: getEscapedHtmlText("Hello world! one < two", myFontNode, "padding-left:0.7em")
will return any of the following:
<h1 class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</h1>
<h2 class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</h2>
<h3 class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</h3>
<h4 class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</h4>
<h5 class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</h5>
<h6 class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</h6>
<p class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</p>
<span class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</span>
<code class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</code>
<sub class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</sub>
<sup class="selectorTextOfMyFontNode" style="padding-left:0.7em">Hello world! one < two</sup>
Method call: getEscapedHtmlText("Hello world! one < two", null, "padding-left:0.7em")
will return this:
<p style="padding-left:0.7em">Hello world! one < two</p>
Method call: getEscapedHtmlText("Hello world! one < two", null, null)
will return this:
<p>Hello world! one < two</p>
Method call: getEscapedHtmlText("Hello world! one < two", myFontNode, null)
will return the same result as if the getEscapedHtmlText(String, Node)
method had been invoked.
aPlainText
- the text to be escaped and embedded in a html elementaFontNode
- a Node
of primary type sv:font
that determines the type of html element to use and the
class attribute value of the elementaStyle
- the style that should be inserted in the style attribute of the elementaPlainText
embedded in a html element, or empty String
if aPlainText
is null
getHtmlText(String, javax.jcr.Node, String)
String getHyperlinkedText(String aText, String aClass, String aStyle)
Inserts an hyperlink/anchor (<a href="...">...</a>
) with a title and optional class and style where the text seems
to indicate a hyperlink. Text blocks that starts with http://, https://, www. or contains an @ will be
considered for hyperlinking.
aText
- a text that might contain hyperlinkable partsaClass
- the class of the hyperlinks (the class
attribute of the a
element).
if aClass
is null
or empty, it will not be used in any hyperlinks.aStyle
- the style of the hyperlinks (the style
attribute of the a
element)
if aStyle
is null
or empty, it will not be used in any hyperlinks.aText
hyperlinkedgetHyperlinkedText(String)
String getHyperlinkedText(String aText)
Inserts an hyperlink/anchor (<a href="...">...</a>
) where the text seems to indicate a hyperlink.
Text blocks that starts with http://, https://, www. or contains an @ will be considered for hyperlinking.
aText
- a text that might contain hyperlinkable partsaText
hyperlinkedgetHyperlinkedText(String, String, String)
@Deprecated String getNodeAsText(Node aNode)
getNodeOutput(javax.jcr.Node, javax.jcr.Node, int)
aNode
- a text portlet nodeString
if aNode is null
or not a text portletgetNodeOutput(Node,Node,int)
String getNodeOutput(Node aPageNode, Node aPagePartNode, int aContentType)
Tip! Consider using TextModuleRenderer
instead if you want the output of a single Text module.
Note! Due to security reasons (potential never-ending loops) it is prohibited to get the output of anything from
the currently executing page (i.e. PortletContextUtil.getCurrentPage()
)!
aPageNode
- a page node (sv:page, sv:article, sv:sitePage) where current user has READ permission, must not be null or "current page".aPagePartNode
- a page part node that exist as content on aPageNode (or null if you want the complete output from aPageNode).aContentType
- a content-type marker, i.e.
CONTENT_TYPE_TEXT_PLAIN,
CONTENT_TYPE_TEXT_HTML or
CONTENT_TYPE_TEXT_XML.String getNodeInfoAsHTML(Node aNode) throws IllegalArgumentException, RepositoryException
Note! This method is intended for debugging purposes during development ONLY! Important: Only the types and properties that are officially specified on the Sitevision developer web can be relied upon and used in production. All other types and properties should be considered volatile. Output produced by this method is not indexed by the Sitevision indexer.
aNode
- the start node from where all properties should be retrievedString
in HTML or an empty String if it does not contain any properties and sub nodes.IllegalArgumentException
- if the given node aNode
is null.RepositoryException
- if something else goes wrong.getNodeInfoAsHTML(javax.jcr.Node, int)
String getNodeInfoAsHTML(Node aNode, int aDepth) throws IllegalArgumentException, RepositoryException
aDepth
is reached.
Note! This method is intended for debugging purposes during development ONLY! Important: Only the types and properties that are officially specified on the Sitevision developer web can be relied upon and used in production. All other types and properties should be considered volatile. Output produced by this method is not indexed by the Sitevision indexer.
aNode
- the start node from where all properties should be retrievedaDepth
- the number of sub levels from the start node to be retrievedString
in HTML or an empty String if it does not contain any properties and sub nodes.IllegalArgumentException
- if the given node aNode
is null or the given depth aDepth
is negative.RepositoryException
- if something else goes wrong.String renderWebPathNodes(Node aDescendantNode, LinkRenderer aLinkRenderer, String aSeparator)
---------------------------------------------------------
Example: You use Velocity and want to do a simple "path to this page" menu
with a pretty "double arrow" between the links
---------------------------------------------------------
A) The explicit way:
Use the getWebPathNodes
method of NodeTreeUtil
to get all nodes in the
path to the site page and render a link to each node using a LinkRenderer
.
Current page can be found via a PortletContextUtil
instance.
## Get all nodes from here to the site page
#set ($currentPage = $sitevisionUtils.portletContextUtil.currentPage)
#set ($nodeTreeUtil = $sitevisionUtils.nodeTreeUtil)
#set ($pathList = $nodeTreeUtil.getWebPathNodes($currentPage))
## Iterate the nodes in the list with a LinkRenderer
#if (!$pathList.isEmpty())
## Set up the link renderer
#set ($linkRenderer = $sitevisionUtils.getLinkRenderer())
## Render links to all nodes
<p class="normal">
#foreach ($node in $pathList)
$linkRenderer.update($node)
#if ($velocityCount > 0)
»
#end
$linkRenderer.render()
#end
</p>
#end
B) The convenient way:
Use the getWebPathNodes
method!
## Init
#set ($currentPage = $sitevisionUtils.portletContextUtil.currentPage)
#set ($outputUtil = $sitevisionUtils.outputUtil)
#set ($linkRenderer = $sitevisionUtils.getLinkRenderer())
## Render
#set ($result = $outputUtil.renderWebPathNodes($currentPage, $linkRenderer, ' » '))
#if ($result != '')
<p class="normal">$result</p>
#end
For a description of "web path", see NodeTreeUtil.getWebPathNodes(javax.jcr.Node)
aDescendantNode
- the node the web path should be rendered foraLinkRenderer
- the link renderer that determines how links are renderedaSeparator
- the separator that should be put between the links. Note! This is not encoded by this method.null
, aLinkRenderer
is null
,
aSeparator
is null
or no web path could be created.NodeTreeUtil.getWebPathNodes(javax.jcr.Node)
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.