info.magnolia.templating.functions
Class TemplatingFunctions

java.lang.Object
  extended by info.magnolia.templating.functions.TemplatingFunctions

public class TemplatingFunctions
extends Object

An object exposing several methods useful for templates. It is exposed in templates as cmsfn.

Version:
$Id$

Constructor Summary
TemplatingFunctions(javax.inject.Provider<info.magnolia.cms.core.AggregationState> aggregationStateProvider)
           
 
Method Summary
 List<info.magnolia.jcr.util.ContentMap> ancestors(info.magnolia.jcr.util.ContentMap contentMap)
           
 List<info.magnolia.jcr.util.ContentMap> ancestors(info.magnolia.jcr.util.ContentMap contentMap, String nodeTypeName)
           
 List<javax.jcr.Node> ancestors(javax.jcr.Node content)
           
 List<javax.jcr.Node> ancestors(javax.jcr.Node content, String nodeTypeName)
           
 info.magnolia.jcr.util.ContentMap asContentMap(javax.jcr.Node content)
           
 List<info.magnolia.jcr.util.ContentMap> asContentMapList(Collection<javax.jcr.Node> nodeList)
           
protected  List<info.magnolia.jcr.util.ContentMap> asContentMapList(Iterable<javax.jcr.Node> nodes)
           
 javax.jcr.Node asJCRNode(info.magnolia.jcr.util.ContentMap contentMap)
           
 List<javax.jcr.Node> asNodeList(Collection<info.magnolia.jcr.util.ContentMap> contentMapList)
           
protected  List<javax.jcr.Node> asNodeList(Iterable<javax.jcr.Node> nodes)
           
 List<info.magnolia.jcr.util.ContentMap> children(info.magnolia.jcr.util.ContentMap content)
           
 List<info.magnolia.jcr.util.ContentMap> children(info.magnolia.jcr.util.ContentMap content, String nodeTypeName)
           
 List<javax.jcr.Node> children(javax.jcr.Node content)
           
 List<javax.jcr.Node> children(javax.jcr.Node content, String nodeTypeName)
           
 javax.jcr.Node content(String path)
          Deprecated. use contentByPath(String path) or nodeByPath(String path)
 javax.jcr.Node content(String repository, String path)
          Deprecated. use contentByPath(String path, String workspace) or nodeByPath(String path, String workspace)
 info.magnolia.jcr.util.ContentMap contentById(String id)
          Return the ContentMap by the given identifier from the website repository.
 info.magnolia.jcr.util.ContentMap contentById(String id, String workspace)
          Return the ContentMap by the given identifier from the given repository.
 javax.jcr.Node contentByIdentifier(String id)
          Deprecated. use contentById(String id) or {@link #nodeById(String id)
 javax.jcr.Node contentByIdentifier(String repository, String id)
          Deprecated. use contentById(String id, String workspace) or #contentByPath(String id, String workspace)}
 info.magnolia.jcr.util.ContentMap contentByPath(String path)
          Return the ContentMap for the Given Path from the website repository.
 info.magnolia.jcr.util.ContentMap contentByPath(String path, String workspace)
          Return the ContentMap for the Given Path from the given repository.
 String createHtmlAttribute(String name, String value)
          Util method to create html attributes name="value".
 info.magnolia.jcr.util.ContentMap decode(info.magnolia.jcr.util.ContentMap content)
          Removes escaping of HTML on properties.
 javax.jcr.Node decode(javax.jcr.Node content)
          Removes escaping of HTML on properties.
 info.magnolia.jcr.util.ContentMap encode(info.magnolia.jcr.util.ContentMap content)
          Adds escaping of HTML on properties as well as changing line breaks into <br/> tags.
 javax.jcr.Node encode(javax.jcr.Node content)
          Adds escaping of HTML on properties as well as changing line breaks into <br/> tags.
 String externalLink(info.magnolia.jcr.util.ContentMap content, String linkPropertyName)
          Returns an external link prepended with http:// in case the protocol is missing or an empty String if the link does not exist.
 String externalLink(javax.jcr.Node content, String linkPropertyName)
          Returns an external link prepended with http:// in case the protocol is missing or an empty String if the link does not exist.
 String externalLinkTitle(info.magnolia.jcr.util.ContentMap content, String linkPropertyName, String linkTitlePropertyName)
          Return a link title based on the @param linkTitlePropertyName.
 String externalLinkTitle(javax.jcr.Node content, String linkPropertyName, String linkTitlePropertyName)
          Return a link title based on the @param linkTitlePropertyName.
 info.magnolia.jcr.util.ContentMap inherit(info.magnolia.jcr.util.ContentMap content)
           
 info.magnolia.jcr.util.ContentMap inherit(info.magnolia.jcr.util.ContentMap content, String relPath)
           
 javax.jcr.Node inherit(javax.jcr.Node content)
           
 javax.jcr.Node inherit(javax.jcr.Node content, String relPath)
           
 List<info.magnolia.jcr.util.ContentMap> inheritList(info.magnolia.jcr.util.ContentMap content, String relPath)
           
 List<javax.jcr.Node> inheritList(javax.jcr.Node content, String relPath)
           
 javax.jcr.Property inheritProperty(info.magnolia.jcr.util.ContentMap content, String relPath)
           
 javax.jcr.Property inheritProperty(javax.jcr.Node content, String relPath)
           
 boolean isAuthorInstance()
           
 boolean isEditMode()
           
 boolean isFromCurrentPage(info.magnolia.jcr.util.ContentMap content)
           
 boolean isFromCurrentPage(javax.jcr.Node content)
           
 boolean isInherited(info.magnolia.jcr.util.ContentMap content)
           
 boolean isInherited(javax.jcr.Node content)
           
 boolean isPreviewMode()
           
 boolean isPublicInstance()
           
 String language()
          Get the language used currently.
 String link(info.magnolia.jcr.util.ContentMap contentMap)
           
 String link(javax.jcr.Node content)
           
 String link(javax.jcr.Property property)
          Deprecated. since 4.5.4. There is no valid use case for this method.
 String link(String workspace, String nodeIdentifier)
          Create link for the Node identified by nodeIdentifier in the specified workspace.
 String metaData(info.magnolia.jcr.util.ContentMap content, String property)
           
 String metaData(javax.jcr.Node content, String property)
          Returns the string representation of a property from the metaData of the node or null if the node has no Magnolia metaData or if no matching property is found.
 javax.jcr.Node nodeById(String id)
          Return the Node by the given identifier from the website repository.
 javax.jcr.Node nodeById(String id, String workspace)
          Return the Node by the given identifier from the given repository.
 javax.jcr.Node nodeByPath(String path)
          Return the Node for the Given Path from the website repository.
 javax.jcr.Node nodeByPath(String path, String workspace)
          Return the Node for the Given Path from the given repository.
 info.magnolia.jcr.util.ContentMap page(info.magnolia.jcr.util.ContentMap content)
          Returns the page's ContentMap of the passed ContentMap.
 javax.jcr.Node page(javax.jcr.Node content)
          Returns the page Node of the passed node.
 info.magnolia.jcr.util.ContentMap parent(info.magnolia.jcr.util.ContentMap contentMap)
           
 info.magnolia.jcr.util.ContentMap parent(info.magnolia.jcr.util.ContentMap contentMap, String nodeTypeName)
           
 javax.jcr.Node parent(javax.jcr.Node content)
           
 javax.jcr.Node parent(javax.jcr.Node content, String nodeTypeName)
           
 info.magnolia.jcr.util.ContentMap root(info.magnolia.jcr.util.ContentMap contentMap)
           
 info.magnolia.jcr.util.ContentMap root(info.magnolia.jcr.util.ContentMap contentMap, String nodeTypeName)
           
 javax.jcr.Node root(javax.jcr.Node content)
           
 javax.jcr.Node root(javax.jcr.Node content, String nodeTypeName)
           
 Collection<javax.jcr.Node> search(String workspace, String statement, String language, String returnItemType)
          Executes query and returns result as Collection of Nodes.
 info.magnolia.cms.util.SiblingsHelper siblings(info.magnolia.jcr.util.ContentMap node)
           
 info.magnolia.cms.util.SiblingsHelper siblings(javax.jcr.Node node)
          Returns an instance of SiblingsHelper for the given node.
 Collection<javax.jcr.Node> simpleSearch(String workspace, String statement, String returnItemType, String startPath)
          Executes simple SQL2 query and returns result as Collection of Nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TemplatingFunctions

@Inject
public TemplatingFunctions(javax.inject.Provider<info.magnolia.cms.core.AggregationState> aggregationStateProvider)
Method Detail

asJCRNode

public javax.jcr.Node asJCRNode(info.magnolia.jcr.util.ContentMap contentMap)

asContentMap

public info.magnolia.jcr.util.ContentMap asContentMap(javax.jcr.Node content)

children

public List<javax.jcr.Node> children(javax.jcr.Node content)
                              throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

children

public List<javax.jcr.Node> children(javax.jcr.Node content,
                                     String nodeTypeName)
                              throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

children

public List<info.magnolia.jcr.util.ContentMap> children(info.magnolia.jcr.util.ContentMap content)
                                                 throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

children

public List<info.magnolia.jcr.util.ContentMap> children(info.magnolia.jcr.util.ContentMap content,
                                                        String nodeTypeName)
                                                 throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

root

public info.magnolia.jcr.util.ContentMap root(info.magnolia.jcr.util.ContentMap contentMap)
                                       throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

root

public info.magnolia.jcr.util.ContentMap root(info.magnolia.jcr.util.ContentMap contentMap,
                                              String nodeTypeName)
                                       throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

root

public javax.jcr.Node root(javax.jcr.Node content)
                    throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

root

public javax.jcr.Node root(javax.jcr.Node content,
                           String nodeTypeName)
                    throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

parent

public info.magnolia.jcr.util.ContentMap parent(info.magnolia.jcr.util.ContentMap contentMap)
                                         throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

parent

public info.magnolia.jcr.util.ContentMap parent(info.magnolia.jcr.util.ContentMap contentMap,
                                                String nodeTypeName)
                                         throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

parent

public javax.jcr.Node parent(javax.jcr.Node content)
                      throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

parent

public javax.jcr.Node parent(javax.jcr.Node content,
                             String nodeTypeName)
                      throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

page

public info.magnolia.jcr.util.ContentMap page(info.magnolia.jcr.util.ContentMap content)
                                       throws javax.jcr.RepositoryException
Returns the page's ContentMap of the passed ContentMap. If the passed ContentMap represents a page, the passed ContentMap will be returned. If the passed ContentMap has no parent page at all, null is returned.

Parameters:
content - the ContentMap to get the page's ContentMap from.
Returns:
returns the page ContentMap of the passed content ContentMap.
Throws:
javax.jcr.RepositoryException

page

public javax.jcr.Node page(javax.jcr.Node content)
                    throws javax.jcr.RepositoryException
Returns the page Node of the passed node. If the passed Node is a page, the passed Node will be returned. If the passed Node has no parent page at all, null is returned.

Parameters:
content - the Node to get the page from.
Returns:
returns the page Node of the passed content Node.
Throws:
javax.jcr.RepositoryException

ancestors

public List<info.magnolia.jcr.util.ContentMap> ancestors(info.magnolia.jcr.util.ContentMap contentMap)
                                                  throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

ancestors

public List<info.magnolia.jcr.util.ContentMap> ancestors(info.magnolia.jcr.util.ContentMap contentMap,
                                                         String nodeTypeName)
                                                  throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

ancestors

public List<javax.jcr.Node> ancestors(javax.jcr.Node content)
                               throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

ancestors

public List<javax.jcr.Node> ancestors(javax.jcr.Node content,
                                      String nodeTypeName)
                               throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

inherit

public javax.jcr.Node inherit(javax.jcr.Node content)
                       throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

inherit

public javax.jcr.Node inherit(javax.jcr.Node content,
                              String relPath)
                       throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

inherit

public info.magnolia.jcr.util.ContentMap inherit(info.magnolia.jcr.util.ContentMap content)
                                          throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

inherit

public info.magnolia.jcr.util.ContentMap inherit(info.magnolia.jcr.util.ContentMap content,
                                                 String relPath)
                                          throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

inheritProperty

public javax.jcr.Property inheritProperty(javax.jcr.Node content,
                                          String relPath)
                                   throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

inheritProperty

public javax.jcr.Property inheritProperty(info.magnolia.jcr.util.ContentMap content,
                                          String relPath)
                                   throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

inheritList

public List<javax.jcr.Node> inheritList(javax.jcr.Node content,
                                        String relPath)
                                 throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

inheritList

public List<info.magnolia.jcr.util.ContentMap> inheritList(info.magnolia.jcr.util.ContentMap content,
                                                           String relPath)
                                                    throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

isInherited

public boolean isInherited(javax.jcr.Node content)

isInherited

public boolean isInherited(info.magnolia.jcr.util.ContentMap content)

isFromCurrentPage

public boolean isFromCurrentPage(javax.jcr.Node content)

isFromCurrentPage

public boolean isFromCurrentPage(info.magnolia.jcr.util.ContentMap content)

link

public String link(String workspace,
                   String nodeIdentifier)
Create link for the Node identified by nodeIdentifier in the specified workspace.


link

@Deprecated
public String link(javax.jcr.Property property)
Deprecated. since 4.5.4. There is no valid use case for this method.

There should be no real reason to use this method except to produce link to binary content stored in jcr:data property in which case one should call link(Node) while passing parent node as a parameter. In case you find other valid reason to use this method, please raise it in a forum discussion or create issue. Otherwise this method will be removed in the future.


link

public String link(javax.jcr.Node content)

link

public String link(info.magnolia.jcr.util.ContentMap contentMap)
            throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

language

public String language()
Get the language used currently.

Returns:
The language as a String.

externalLink

public String externalLink(javax.jcr.Node content,
                           String linkPropertyName)
Returns an external link prepended with http:// in case the protocol is missing or an empty String if the link does not exist.

Parameters:
content - The node where the link property is stored on.
linkPropertyName - The property where the link value is stored in.
Returns:
The link prepended with http://

externalLink

public String externalLink(info.magnolia.jcr.util.ContentMap content,
                           String linkPropertyName)
Returns an external link prepended with http:// in case the protocol is missing or an empty String if the link does not exist.

Parameters:
content - The node's map representation where the link property is stored on.
linkPropertyName - The property where the link value is stored in.
Returns:
The link prepended with http://

externalLinkTitle

public String externalLinkTitle(javax.jcr.Node content,
                                String linkPropertyName,
                                String linkTitlePropertyName)
Return a link title based on the @param linkTitlePropertyName. When property @param linkTitlePropertyName is empty or null, the link itself is provided as the linkTitle (prepended with http://).

Parameters:
content - The node where the link property is stored on.
linkPropertyName - The property where the link value is stored in.
linkTitlePropertyName - The property where the link title value is stored
Returns:
the resolved link title value

externalLinkTitle

public String externalLinkTitle(info.magnolia.jcr.util.ContentMap content,
                                String linkPropertyName,
                                String linkTitlePropertyName)
Return a link title based on the @param linkTitlePropertyName. When property @param linkTitlePropertyName is empty or null, the link itself is provided as the linkTitle (prepended with http://).

Parameters:
content - The node where the link property is stored on.
linkPropertyName - The property where the link value is stored in.
linkTitlePropertyName - The property where the link title value is stored
Returns:
the resolved link title value

isEditMode

public boolean isEditMode()

isPreviewMode

public boolean isPreviewMode()

isAuthorInstance

public boolean isAuthorInstance()

isPublicInstance

public boolean isPublicInstance()

createHtmlAttribute

public String createHtmlAttribute(String name,
                                  String value)
Util method to create html attributes name="value". If the value is empty an empty string will be returned. This is mainly helpful to avoid empty attributes.


siblings

public info.magnolia.cms.util.SiblingsHelper siblings(javax.jcr.Node node)
                                               throws javax.jcr.RepositoryException
Returns an instance of SiblingsHelper for the given node.

Throws:
javax.jcr.RepositoryException

siblings

public info.magnolia.cms.util.SiblingsHelper siblings(info.magnolia.jcr.util.ContentMap node)
                                               throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

content

public javax.jcr.Node content(String path)
Deprecated. use contentByPath(String path) or nodeByPath(String path)

Return the Node for the Given Path from the website repository.


content

public javax.jcr.Node content(String repository,
                              String path)
Deprecated. use contentByPath(String path, String workspace) or nodeByPath(String path, String workspace)

Return the Node for the Given Path from the given repository.


contentByIdentifier

public javax.jcr.Node contentByIdentifier(String id)
Deprecated. use contentById(String id) or {@link #nodeById(String id)

Return the Node by the given identifier from the website repository.


contentByIdentifier

public javax.jcr.Node contentByIdentifier(String repository,
                                          String id)
Deprecated. use contentById(String id, String workspace) or #contentByPath(String id, String workspace)}

Return the Node by the given identifier from the given repository.


contentByPath

public info.magnolia.jcr.util.ContentMap contentByPath(String path)
Return the ContentMap for the Given Path from the website repository.


contentByPath

public info.magnolia.jcr.util.ContentMap contentByPath(String path,
                                                       String workspace)
Return the ContentMap for the Given Path from the given repository.


contentById

public info.magnolia.jcr.util.ContentMap contentById(String id)
Return the ContentMap by the given identifier from the website repository.


contentById

public info.magnolia.jcr.util.ContentMap contentById(String id,
                                                     String workspace)
Return the ContentMap by the given identifier from the given repository.


nodeByPath

public javax.jcr.Node nodeByPath(String path)
Return the Node for the Given Path from the website repository.


nodeByPath

public javax.jcr.Node nodeByPath(String path,
                                 String workspace)
Return the Node for the Given Path from the given repository.


nodeById

public javax.jcr.Node nodeById(String id)
Return the Node by the given identifier from the website repository.


nodeById

public javax.jcr.Node nodeById(String id,
                               String workspace)
Return the Node by the given identifier from the given repository.


asContentMapList

public List<info.magnolia.jcr.util.ContentMap> asContentMapList(Collection<javax.jcr.Node> nodeList)

asNodeList

public List<javax.jcr.Node> asNodeList(Collection<info.magnolia.jcr.util.ContentMap> contentMapList)

asNodeList

protected List<javax.jcr.Node> asNodeList(Iterable<javax.jcr.Node> nodes)

asContentMapList

protected List<info.magnolia.jcr.util.ContentMap> asContentMapList(Iterable<javax.jcr.Node> nodes)

decode

public info.magnolia.jcr.util.ContentMap decode(info.magnolia.jcr.util.ContentMap content)
Removes escaping of HTML on properties.


decode

public javax.jcr.Node decode(javax.jcr.Node content)
Removes escaping of HTML on properties.


encode

public javax.jcr.Node encode(javax.jcr.Node content)
Adds escaping of HTML on properties as well as changing line breaks into <br/> tags.


encode

public info.magnolia.jcr.util.ContentMap encode(info.magnolia.jcr.util.ContentMap content)
Adds escaping of HTML on properties as well as changing line breaks into <br/> tags.


metaData

public String metaData(javax.jcr.Node content,
                       String property)
Returns the string representation of a property from the metaData of the node or null if the node has no Magnolia metaData or if no matching property is found.


metaData

public String metaData(info.magnolia.jcr.util.ContentMap content,
                       String property)
See Also:
TemplatingFunctions#metaData(Node, String)}.

search

public Collection<javax.jcr.Node> search(String workspace,
                                         String statement,
                                         String language,
                                         String returnItemType)
Executes query and returns result as Collection of Nodes.

Parameters:
workspace -
statement - has to be in formal form for chosen language
language -
returnItemType -

simpleSearch

public Collection<javax.jcr.Node> simpleSearch(String workspace,
                                               String statement,
                                               String returnItemType,
                                               String startPath)
Executes simple SQL2 query and returns result as Collection of Nodes.

Parameters:
workspace -
statement - should be set of labels target has to contain inserted as one string each separated by comma
returnItemType -
startPath - can be inserted, for results without limitation set it to slash


Copyright © 2003-2014 Magnolia International Ltd.. All Rights Reserved.