/** * This file is auto generated from JavaDoc. Do not modify it manually. */ import type { Node } from "../../types/javax/jcr/Node"; import type { String } from "../../types/java/lang/String"; /** * LinkRenderer is a stateful utility interface that can be used to build valid html text links that uses link icons according to the * website settings. * *
* An instance of the Sitevision class implementing this interface can be obtained via {@link senselogic.sitevision.api.Utils#getLinkRenderer()}.
* See {@link senselogic.sitevision.api.Utils} for how to obtain an instance of the Utils interface.
*
* LinkRenderer is very suitable when rendering more than one link (for instance when rendering a menu) or if you don't want to bother whether or not * the site prescribes your link(s) should use link icons or file icons. *
* ** LinkRenderer attributes comes in different flavors: *
*String or a {@link #isRenderableTarget(javax.jcr.Node) renderable Node}.<a class="xyz" href="xyz" title="xyz">Linked text</a>
* <a class="xyz" href="xyz" title="xyz">Linked text</a>
* <a class="xyz" href="xyz" title="xyz">Linked text</a>
* <a class="xyz" href="xyz" title="xyz">Linked text</a>null
* <a class="xyz" href="xyz" title="xyz" style="xyz">Linked text</a>null
* <a class="xyz" href="xyz" title="xyz" onclick="xyz"
* onkeypress="xyz>Linked text</a>null
* <a class="xyz" href="xyz" title="xyz" id="xyz">Linked text</a>null
* <a class="xyz" href="xyz?a=b&c=d" title="xyz">Linked text</a><a class="xyz" href="xyz" title="xyz" rel="xyz">Linked text</a>null
* <a class="xyz" href="xyz" title="xyz" accesskey="xyz">Linked text</a>null
* false
* false
* <a class="xyz" href="xyz" title="xyz" lang="en">Linked text</a>null
* <a class="xyz" href="xyz" title="xyz" hreflang="en">Linked text</a>null
* false.
* true.
* true.
* true.
* true.
* false.
* * ---------------------------------------------------------------------------------------------------- *
* *
* Using the LinkRenderer 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 LinkRenderer until you are done. Something like: *
*
* Example of how this strategy could be implemented in Velocity:
* (You want to do a simple menu, i.e. iterate the nodes in a collection/iterator "$pages", and use LinkRenderer to render links to them
* as a html list)
*
* ## Get PropertyUtil to ease Node property fetching
* #set ($propertyUtil = $sitevisionUtils.propertyUtil)
*
* ## Use font class 'normal' for all links
* #set ($font = 'normal')
*
* ## Get LinkRenderer
* #set ($linkRenderer = $sitevisionUtils.linkRenderer)
*
* ## Iterate through pages and render links to them
* <ul style="list-style:none">
* #foreach ($page in $pages)
* ## Fetch the name of the node
* #set ($pageName = $propertyUtil.getString($page, 'displayName', $page.toString()))
*
* ## Update the renderer and render
* $linkRenderer.update($page, $font, $pageName)
* <li>
* $linkRenderer.render()
* </li>
* #end
* </ul>
*
*
* * ---------------------------------------------------------------------------------------------------- *
* ** Since LinkRenderer is stateful and likely will be used in Velocity frequently, there are some "shortcuts" that might be useful: *
*update(...) methods.
* If you at the same time want to clear all optional attributes, use one of the updateClean(...) methods instead.
* clearAllOptional() method
* forceOpenNewWindow() results in an execution of setOpenNewWindow(true) clearOpenNewWindow() results in an execution of setOpenNewWindow(false)
* null.
* For example: clearAccessKey() results in an execution of setAccessKey(null)
*
*
* Thread Note! The render method is NOT thread safe! If two threads simultaneously executes
* the render method on the SAME LinkRenderer instance, the rendered result is undeterminable. This is in almost
* all cases nothing you need to worry about, unless your portlet or servlet actually creates a separate Thread
* and starts it. If so - ensure all your created threads creates and uses their own LinkRenderer instance!
*
* Note/Tip! This interface helps rendering textual links. If you want to render image links, you would typically * use the {@link senselogic.sitevision.api.render.ImageLinkRenderer} instead. *
* @author Magnus Lövgren */ export interface LinkRenderer { /** * Updates current state. * @param aTarget the target of the link (href attribute for the a element) * @param aFontClass the class name the link should use (class attribute for the a element) * @param aText the link text * @param aTitle the title of the link (title attribute for the a element) * @see #isValidTarget(javax.jcr.Node) */ update( aTarget: Node, aFontClass: String | string, aText: String | string, aTitle: String | string ): void; /** * Updates current state and removes previous title. * @param aTarget the target of the link (href attribute for the a element) * @param aFontClass the class name the link should use (class attribute for the a element) * @param aText the link text * @see #isValidTarget(javax.jcr.Node) */ update( aTarget: Node, aFontClass: String | string, aText: String | string ): void; /** * Updates current state and removes previous title. * @param aTarget the target of the link (href attribute for the a element) * @param aText the link text * @see #isValidTarget(javax.jcr.Node) */ update(aTarget: Node, aText: String | string): void; /** * Updates current state and removes previous title and text. * ** Note. If no text exists when rendering, the target Node will be used to determine an appropriate text * (e.g. the display name if the node is a page). *
* @param aTarget the target of the link (href attribute for the a element) * @see #isValidTarget(javax.jcr.Node) */ update(aTarget: Node): void; /** * Updates current state and removes all optional attributes. * @param aTarget the target of the link (href attribute for the a element) * @param aFontClass the class name the link should use (class attribute for the a element) * @param aText the link text * @param aTitle the title of the link (title attribute for the a element) * @see #clearAllOptional() * @see #isValidTarget(javax.jcr.Node) */ updateClean( aTarget: Node, aFontClass: String | string, aText: String | string, aTitle: String | string ): void; /** * Updates current state and removes all optional attributes and title. * @param aTarget the target of the link (href attribute for the a element) * @param aFontClass the class name the link should use (class attribute for the a element) * @param aText the link text * @see #clearAllOptional() * @see #isValidTarget(javax.jcr.Node) */ updateClean( aTarget: Node, aFontClass: String | string, aText: String | string ): void; /** * Updates current state and removes all optional attributes and title. * @param aTarget the target of the link (href attribute for the a element) * @param aText the link text * @see #clearAllOptional() * @see #isValidTarget(javax.jcr.Node) */ updateClean(aTarget: Node, aText: String | string): void; /** * Updates current state and removes all optional attributes, title and text. * ** Note. If no text exists when rendering, the target Node will be used to determine an appropriate text * (e.g. the display name if the node is a page). *
* @param aTarget the target of the link (href attribute for the a element) * @see #clearAllOptional() * @see #isValidTarget(javax.jcr.Node) */ updateClean(aTarget: Node): void; /** * Removes all optional settings. * In other words - executing this method has the same effect as executing: *clearStyle()clearOnclick()clearId()clearTargetParameters()clearRel()clearAccessKey()clearOpenNewWindow()clearDataAttributes()clearAriaAttributes()clearUseDownload()clearLang()clearHrefLang()* Note! The render method is not thread safe, see thread note above. *
* @return a html link, ready to print out on a page */ render(): string; /** * Sets what the link target is, i.e "what the link links to" (href attribute on the a element). * The target attribute is mandatory when the result is rendered. * @param aTarget a Node identifying the target * @see #isValidTarget(javax.jcr.Node) */ setTarget(aTarget: Node): void; /** * Sets what the link target is, i.e "what the link links to" (href attribute on the a element). * The target attribute is mandatory when the result is rendered. * @param aTarget a String identifying the target (i.e "http://xyz.com", "?name=a&value=b", "/images/a.gif", "#anchor") */ setStringTarget(aTarget: String | string): void; /** * Checks if a Node is a renderable target or not (node type accepted). * ** This method can be used to avoid updating this renderer with nodes that can't be rendered. Since nodes that aren't * renderable will be ignored, updating the renderer with such nodes will result in rendering of previous target. *
* *
* LinkRenderer will accept nodes with the following primary node type as targets
* (i.e. this method will return true for such nodes):
*
sv:articlesv:collaborationGroupsv:collaborationGroupPagesv:collaborationGroupTemplatesv:filesv:imagesv:link (the actual target of the link must also be a valid target)sv:pagesv:sitePagesv:structureLink (the actual target of the structure link must also be a valid target)sv:structurePagesv:systemUser (the system user must have a mail address)sv:templatesv:user (the user must have a mail address)sv:userIdentity (the site must have a profile page, or backing user must have a mail address)* Always use this method if you are not sure all nodes you are rendering will be accepted as targets. *
* *
* Example:
* Velocity code like this:
*
<ul style="list-style:none">
* #foreach ($node in $myNodes)
* ## Update the renderer and render
* $linkRenderer.update($node)
* <li>$linkRenderer.render()</li>
* #end
* </ul>
* could be replaced with Velocity code like this:<ul style="list-style:none">
* #foreach ($node in $myNodes)
* ## Ensure node actually can be rendered
* #if ($linkRenderer.isRenderableTarget($node))
* ## Update the renderer and render
* $linkRenderer.update($node)
* <li>$linkRenderer.render()</li>
* #end
* #end
* </ul>
*
*
* Performance note! Calling this method prior to calling an update method (or the setTarget method)
* will not have any noticeable negative performance impact. The result of this method is internally cached and the update
* methods (and the setTarget method) will re-use that cached data.
*
true if aNode is a target that can be rendered, false if not
* @since Sitevision 3.0
* @see #isValidTarget(javax.jcr.Node)
*/
isRenderableTarget(aNode: Node): boolean;
/**
* Checks if a Node is a valid target or not (node type accepted and target is valid).
*
* * This method is similar to the {@link senselogic.sitevision.api.render.LinkRenderer#isRenderableTarget(javax.jcr.Node)} method, * but this method does more extensive checking to ensure rendered links will be ok. Note! "External" link targets (e.g. * a link to "www.whatever.com") of a sv:link Node will NOT be checked. *
** This method can be used to avoid updating this renderer with nodes that can't be rendered or nodes that have invalid targets. * An invalid target is typically an existing link that has an empty or trashed target (i.e. target is in trashcan). *
* *
* Example:
* Velocity code like this:
*
<ul style="list-style:none">
* #foreach ($node in $myNodes)
* ## Update the renderer and render
* $linkRenderer.update($node)
* <li>$linkRenderer.render()</li>
* #end
* </ul>
* could be replaced with Velocity code like this:<ul style="list-style:none">
* #foreach ($node in $myNodes)
* ## Ensure node actually can be rendered
* #if ($linkRenderer.isValidTarget($node))
* ## Update the renderer and render
* $linkRenderer.update($node)
* <li>$linkRenderer.render()</li>
* #end
* #end
* </ul>
*
*
* Performance note! Avoid subsequent calls to this method for same Node. If performance is a top
* priority, consider using {@link senselogic.sitevision.api.render.LinkRenderer#isRenderableTarget(javax.jcr.Node)} instead.
*
true if aNode is a target that can be rendered as a functional link, false if not
* @since Sitevision 2.6.2
* @see #isRenderableTarget(javax.jcr.Node)
*/
isValidTarget(aNode: Node): boolean;
/**
* Sets the class name the link should use (class attribute on the a element).
* The fontClass attribute is mandatory when the result is rendered.
* @param aFontClass the class name of the font to use
*/
setFontClass(aFontClass: String | string): void;
/**
* Sets the class name the link should use (class attribute on an a element) based on a given font node.
*
*
* The actual font class is extracted from aFontNode and if aFontNode is null or not a valid font node the
* font class will not be set.
*
* When subsequently setting the font class, use the {@link #setFontClass(String)} method instead for best performance. *
* @param aFontNode the font node that has a font class that can be extracted * @see #setFontClass(String) */ setFont(aFontNode: Node): void; /** * Sets the text that the link should display, i.e. "the text the user clicks on". * The text attribute is mandatory when the result is rendered. * @param aText a link text */ setText(aText: String | string): void; /** * Sets the title the link should have (title attribute on the a element). * *
* If there are no title (i.e. it is null) when the result is rendered, it will get the same
* value as text attribute if autoTitle is activated, otherwise it will be empty. Default is null.
*
setTitle(null)
* @see #setTitle(String)
*/
removeTitle(): void;
/**
* Sets the css style the link should have (style attribute on the a element).
* The style attribute is optional when the result is rendered. Default is null.
* @param aStyle the style of the link
*/
setStyle(aStyle: String | string): void;
/**
* Removes the style, i.e executes setStyle(null)
* @see #setStyle(String)
*/
clearStyle(): void;
/**
* Sets the lang attribute on the a element (defines the language of the element).
* @param aLang a single language code
* @since Sitevision 2022.10.1
*/
setLang(aLang: String | string): void;
/**
* Removes the lang, i.e executes setLang(null)
* @see #setLang(String)
* @since Sitevision 2022.10.1
*/
clearLang(): void;
/**
* Sets the hreflang attribute on the a element (hints at the language of the linked resource).
* @param aHrefLang a single language code
* @since Sitevision 2022.10.1
*/
setHrefLang(aHrefLang: String | string): void;
/**
* Removes the hreflang, i.e executes setHrefLang(null)
* @see #setHrefLang(String)
* @since Sitevision 2022.10.1
*/
clearHrefLang(): void;
/**
* Adds target parameters (key=value) to the link target (href attribute on the a element).
*
* * Target parameters is optional when the result is rendered. Default is no target parameters. *
** There can only be one target parameter per key (i.e. when a target parameter is added it will always replace the possibly existing * target parameter that already use that key). *
* @param key the key of the target parameter * @param value the value of the target parameter */ addTargetParameter(key: String | string, value: String | string): void; /** * Removes all existing target parameters */ clearTargetParameters(): void; /** * Should target parameters be URL encoded or not? * Default istrue.
* @param performParameterEncoding whether parameters should be URL encoded or not.
* @see senselogic.sitevision.api.text.EndecUtil#encodeURL(String)
* @since Sitevision 3.0
*/
setUseParameterEncoding(performParameterEncoding: boolean): void;
/**
* Utility method for executing setUseParameterEncoding(true)
* @see #setUseParameterEncoding(boolean)
* @since Sitevision 3.0
*/
forceUseParameterEncoding(): void;
/**
* Utility method for executing setUseParameterEncoding(false)
* @see #setUseParameterEncoding(boolean)
* @since Sitevision 3.0
*/
clearUseParameterEncoding(): void;
/**
* Adds a data-* attribute to the link element.
* Data attributes is optional when the result is rendered. Default is no data attributes.
* * There can only be one data attribute per name (i.e. when a data attribute is added it will always replace the possibly existing * data attribute that already use that name). *
* ** Notes about names and values: *
*null, whitespace-only or prefix-only will be completely ignored,
* i.e. no data attribute will be rendered.
* null or whitespace-only will be rendered as a data attribute without value.
* * There can only be one aria attribute per name (i.e. when an aria attribute is added it will always replace the possibly existing * aria attribute that already use that name). *
* ** Notes about names and values: *
*null, whitespace-only or prefix-only will be completely ignored,
* i.e. no aria attribute will be rendered.
* null or whitespace-only will be rendered as an aria attribute without value.
* null.
* @param anAccessKey the access key that should be used
*/
setAccessKey(anAccessKey: String | string): void;
/**
* Removes the accesskey, i.e. executes setAccessKey(null)
* @see #setAccessKey(String)
*/
clearAccessKey(): void;
/**
* Sets the rel that should be used (rel attribute on the a element)
* The rel attribute is optional when the result is rendered. Default is null.
* @param aRel the rel that should be used. Note! If "external" is used, the rendered link will be opened in a new window via JavaScript
*/
setRel(aRel: String | string): void;
/**
* Removes the rel value, i.e executes setRel(null)
* @see #setRel(String)
*/
clearRel(): void;
/**
* Sets the onclick value (onclick attribute and onkeypress attribute on the a element), typically some kind of Javascript
* The onclick attribute is optional when the result is rendered. Default is null.
*
* Note! The events (onclick, onkeypress) will be added with non-obtrusive javascript when render() is called.
* @param anOnclick the onClick value that should be used */ setOnclick(anOnclick: String | string): void; /** * Removes the onclick value, i.e executessetOnclick(null)
* @see #setOnclick(String)
*/
clearOnclick(): void;
/**
* Sets the id value (id attribute on the a element), most likely only needed if some kind of javascript/ajax code needs to access the
* rendered link via its id.
*
*
* The id attribute is optional when the result is rendered. Default is null.
*
* This method does not perform any checks of the id. All values will be accepted. * (Note! A valid id should be unique - i.e. should not appear more than once in a html/xhtml document - and not all characters are allowed. * See W3C 3.3.1 Attribute types.) *
* @param anId the id value that should be used * @since Sitevision 3.0 */ setId(anId: String | string): void; /** * Removes the id value, i.e executessetId(null)
* @see #setId(String)
* @since Sitevision 3.0
*/
clearId(): void;
/**
* Use icons for "external", "new window" and "new window, external" according to Site's settings or not.
* Default is true.
* @param useLinkDecorationSettings whether or not Site's settings for link type icons should be used
*/
setUseLinkDecorationSettings(useLinkDecorationSettings: boolean): void;
/**
* Utility method for executing setUseLinkDecorationSettings(true)
* @see #setUseLinkDecorationSettings(boolean)
*/
forceUseLinkDecorationSettings(): void;
/**
* Utility method for executing setUseLinkDecorationSettings(false)
* @see #setUseLinkDecorationSettings(boolean)
*/
clearUseLinkDecorationSettings(): void;
/**
* Use icons/descriptions for known file types according to Site's settings or not.
* Default is true.
* @param useResourceDecorationSettings whether or not Site's settings for icons/descriptions for known file types should be used
*/
setUseResourceDecorationSettings(
useResourceDecorationSettings: boolean
): void;
/**
* Utility method for executing setUseResourceDecorationSettings(true)
* @see #setUseResourceDecorationSettings(boolean)
*/
forceUseResourceDecorationSettings(): void;
/**
* Utility method for executing setUseResourceDecorationSettings(false)
* @see #setUseResourceDecorationSettings(boolean)
*/
clearUseResourceDecorationSettings(): void;
/**
* Should the link target be opened in a new window or not?
* Default is false.
* @param openNewWindow whether or not the link target should be opened in a new window
*/
setOpenNewWindow(openNewWindow: boolean): void;
/**
* Utility method for executing setOpenNewWindow(true)
* @see #setOpenNewWindow(boolean)
*/
forceOpenNewWindow(): void;
/**
* Utility method for executing setOpenNewWindow(false)
* @see #setOpenNewWindow(boolean)
*/
clearOpenNewWindow(): void;
/**
* Should the browser download the link target instead of navigating to it?
* Default is false.
* @param useDownload whether a browser is suggested to download the link target directly
* @since Sitevision 5.2
*/
setUseDownload(useDownload: boolean): void;
/**
* Utility method for executing setUseDownload(true)
* @see #setUseDownload(boolean)
* @since Sitevision 5.2
*/
forceUseDownload(): void;
/**
* Utility method for executing setUseDownload(false)
* @see #setUseDownload(boolean)
* @since Sitevision 5.2
*/
clearUseDownload(): void;
/**
* Should text and attributes be properly encoded or not?
* Default is true.
* @param performEncoding whether text should be encoded or not.
*/
setUseEncoding(performEncoding: boolean): void;
/**
* Utility method for executing setUseEncoding(true)
* @see #setUseEncoding(boolean)
*/
forceUseEncoding(): void;
/**
* Utility method for executing setUseEncoding(false)
* @see #setUseEncoding(boolean)
*/
clearUseEncoding(): void;
/**
* Ensures title always will have a value. If non-existing, the title will be set to the title of the target target (or
* the same as the linked text if the target isn't a page or the title of the page is lacking)
* Default is false.
* @param useAutoTitle whether or not the link always should get the title automatically if title is missing
*/
setUseAutoTitle(useAutoTitle: boolean): void;
/**
* Utility method for executing setUseAutoTitle(true)
* @see #setUseAutoTitle(boolean)
*/
forceUseAutoTitle(): void;
/**
* Utility method for executing setUseAutoTitle(false)
* @see #setUseAutoTitle(boolean)
*/
clearUseAutoTitle(): void;
/**
* Should cross-site internal Node links be handled or not?
*
*
* Default is false.
*
* Note! For best performance: enable only if your site actually contains internal links to * pages on other sites (e.g. The System user creates an internal link and selects a page * on another site in the target browse tree). *
* @param useCrossSiteTargetChecking whether or not to check for cross-site Node targets * @since Sitevision 3.0.2 */ setUseCrossSiteTargetChecking(useCrossSiteTargetChecking: boolean): void; /** * Utility method for executingsetUseCrossSiteTargetChecking(true)
* @see #setUseCrossSiteTargetChecking(boolean)
* @since Sitevision 3.0.2
*/
forceUseCrossSiteTargetChecking(): void;
/**
* Utility method for executing seUseCrossSiteTargetChecking(false)
* @see #setUseCrossSiteTargetChecking(boolean)
* @since Sitevision 3.0.2
*/
clearUseCrossSiteTargetChecking(): void;
}
declare namespace LinkRenderer {}
declare var linkRenderer: LinkRenderer;
export default linkRenderer;