Copyright© 2008-2022 Sitevision AB, all rights reserved.
public interface TextModuleRenderer
This rendering utility is a Text module-specific sibling to OutputUtil.getNodeOutput(Node, Node, int)
but it has some nifty advantages:
OutputUtil
for subsequent Text module rendering.
Using the TextModuleRenderer is pretty straightforward, if you remember that it is stateful.
Conceptually you would typically use it like this:
When you have rendered once, you can re-use the TextModuleRenderer until you are done. Something like:
Example of how this renderer could be used:
E.g. You want to get all output types (html, plain html, text) from two Text modules on a specific page.
var textRendererBuilder = require('TextModuleRendererBuilder'),
textRenderer,
page,
htmlData = { "type": "HTML" },
plainHtmlData = { "type": "Plain HTML" },
textData = { "type": "Text" };
// Get the page where the Text modules are located...
page = ...
// Create a TextModuleRenderer for given page
textRenderer = textRendererBuilder.setPage(page).build();
// Update the TextModuleRenderer with a Text module and render (if possible)
textRenderer.updateByName('Rubrik');
if (textRenderer.isLoaded()) {
htmlData.heading = textRenderer.renderHtml();
plainHtmlData.heading = textRenderer.renderPlainHtml();
textData.heading = textRenderer.renderText();
}
// Update the TextModuleRenderer with another Text module and render (if possible)
textRenderer.updateByName('Text');
if (textRenderer.isLoaded()) {
htmlData.content = textRenderer.renderHtml();
plainHtmlData.content = textRenderer.renderPlainHtml();
textData.content = textRenderer.renderText();
}
The JSON result of the Javascript objects in the example script above could be something like this:
// htmlData
{
"type": "HTML",
"heading": "<div class=\"sv-text-portlet-content\"><h1 class=\"heading\" id=\"h-Heading\">Heading</h1></div>",
"content": "<div class=\"sv-text-portlet-content\"><p class=\"normal\">Some content</p></div>"
}
// plainHtmlData
{
"type": "Plain HTML",
"heading": "<h1>Heading</h1>",
"content": "<p>Some content</p>"
}
// textData
{
"type": "Text",
"heading": "Heading",
"content": "Some content"
}
HTML output
Please note that the HTML of a Text module will differ in versions (i.e.
VersionUtil.OFFLINE_VERSION
and
VersionUtil.ONLINE_VERSION
).
The OFFLINE_VERSION typically contains more elements and attributes.
Legacy Text modules
This renderer does NOT support legacy Text modules that was created before Sitevision 3!
Such Text modules must be converted before they can be used by this renderer
(to convert - open the page in the Sitevision editor, simply click on the legacy Text module and re-publish the page).
An instance of the Sitevision class implementing this interface can be obtained via
TextModuleRendererBuilder.build()
.
See TextModuleRendererBuilder
for how to obtain an instance of the TextModuleRendererBuilder
interface.
Modifier and Type | Method and Description |
---|---|
boolean |
isLoaded()
Whether or not this renderer has been updated with a renderable text module.
|
String |
renderHtml()
Renders full HTML for the loaded Text module.
|
String |
renderPlainHtml()
Renders the plain HTML for the loaded Text module.
|
String |
renderText()
Renders the text for the loaded Text module.
|
void |
update(Node aTextModuleNode)
Updates the state of this renderer (potentially "loads" a Text module for rendering) using a Text module Node.
|
void |
updateByIdentifier(String aTextModuleIdentifier)
Updates the state of this renderer (potentially "loads" a Text module for rendering) using the identifier of a Text module Node.
|
void |
updateByName(String aTextModuleName)
Updates the state of this renderer (potentially "loads" a Text module for rendering) using the name of a Text module Node.
|
void update(Node aTextModuleNode)
Note! If this state update fails (i.e. argument was null or not specifying a supported Text module that exists on the page
this renderer was created for) there will be nothing to render. The state can always be checked via the
isLoaded()
method.
aTextModuleNode
- the Text modulevoid updateByName(String aTextModuleName)
Note! If this state update fails (i.e. argument was null or not specifying a supported Text module that exists on the page
this renderer was created for) there will be nothing to render. The state can always be checked via the
isLoaded()
method.
aTextModuleName
- the name of the Text modulevoid updateByIdentifier(String aTextModuleIdentifier)
Note! If this state update fails (i.e. argument was null or not specifying a supported Text module that exists on the page
this renderer was created for) there will be nothing to render. The state can always be checked via the
isLoaded()
method.
aTextModuleIdentifier
- the identifier of the Text moduleboolean isLoaded()
String renderHtml()
Note! The returned value will always be empty string if the isLoaded()
state is false
when invoking this render method (i.e. you would typically always check the loaded state before calling this method).
This method is conceptually equivalent with
OutputUtil.getNodeOutput(ThePageOfThisRenderer, TheLoadedTextModule, OutputUtil.CONTENT_TYPE_TEXT_HTML)
renderPlainHtml()
String renderText()
Note! The returned value will always be empty string if the isLoaded()
state is false
when invoking this render method (i.e. you would typically always check the loaded state before calling this method).
This method is conceptually equivalent with
OutputUtil.getNodeOutput(ThePageOfThisRenderer, TheLoadedTextModule, OutputUtil.CONTENT_TYPE_TEXT_PLAIN)
but this method does not html encode/escape any chars, this method provides the "raw" text.
Important security note!
The result text of this method is not HTML encoded/escaped!
Hence if you should output the text as part of a HTML page, you must escape/encode the text!
Such escaping/encoding is provided by EndecUtil.escapeXML(String)
.
String renderPlainHtml()
Note! The returned value will always be empty string if the isLoaded()
state is false
when invoking this render method (i.e. you would typically always check the loaded state before calling this method).
The plain HTML is a minimal and generic variant of the full Text module HTML (as of renderHtml()
).
renderHtml()
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.