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<AggregationState> aggregationStateProvider)
           
 
Method Summary
 List<ContentMap> ancestors(ContentMap contentMap)
           
 List<ContentMap> ancestors(ContentMap contentMap, String nodeTypeName)
           
 List<javax.jcr.Node> ancestors(javax.jcr.Node content)
           
 List<javax.jcr.Node> ancestors(javax.jcr.Node content, String nodeTypeName)
           
 ContentMap asContentMap(javax.jcr.Node content)
           
 List<ContentMap> asContentMapList(Collection<javax.jcr.Node> nodeList)
           
protected  List<ContentMap> asContentMapList(Iterable<javax.jcr.Node> nodes)
           
 javax.jcr.Node asJCRNode(ContentMap contentMap)
           
 List<javax.jcr.Node> asNodeList(Collection<ContentMap> contentMapList)
           
protected  List<javax.jcr.Node> asNodeList(Iterable<javax.jcr.Node> nodes)
           
 List<ContentMap> children(ContentMap content)
           
 List<ContentMap> children(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)
 ContentMap contentById(String id)
          Return the ContentMap by the given identifier from the website repository.
 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)}
 ContentMap contentByPath(String path)
          Return the ContentMap for the Given Path from the website repository.
 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".
 ContentMap decode(ContentMap content)
          Removes escaping of HTML on properties.
 javax.jcr.Node decode(javax.jcr.Node content)
          Removes escaping of HTML on properties.
 ContentMap encode(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(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(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.
 ContentMap inherit(ContentMap content)
           
 ContentMap inherit(ContentMap content, String relPath)
           
 javax.jcr.Node inherit(javax.jcr.Node content)
           
 javax.jcr.Node inherit(javax.jcr.Node content, String relPath)
           
 List<ContentMap> inheritList(ContentMap content, String relPath)
           
 List<javax.jcr.Node> inheritList(javax.jcr.Node content, String relPath)
           
 javax.jcr.Property inheritProperty(ContentMap content, String relPath)
           
 javax.jcr.Property inheritProperty(javax.jcr.Node content, String relPath)
           
 boolean isAuthorInstance()
           
 boolean isEditMode()
           
 boolean isFromCurrentPage(ContentMap content)
           
 boolean isFromCurrentPage(javax.jcr.Node content)
           
 boolean isInherited(ContentMap content)
           
 boolean isInherited(javax.jcr.Node content)
           
 boolean isPreviewMode()
           
 boolean isPublicInstance()
           
 String language()
          Get the language used currently.
 String link(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(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.
 ContentMap page(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.
 ContentMap parent(ContentMap contentMap)
           
 ContentMap parent(ContentMap contentMap, String nodeTypeName)
           
 javax.jcr.Node parent(javax.jcr.Node content)
           
 javax.jcr.Node parent(javax.jcr.Node content, String nodeTypeName)
           
 ContentMap root(ContentMap contentMap)
           
 ContentMap root(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.
 SiblingsHelper siblings(ContentMap node)
           
 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<AggregationState> aggregationStateProvider)
Method Detail

asJCRNode

public javax.jcr.Node asJCRNode(ContentMap contentMap)

asContentMap

public 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<ContentMap> children(ContentMap content)
                          throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

children

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

root

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

root

public ContentMap root(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 ContentMap parent(ContentMap contentMap)
                  throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

parent

public ContentMap parent(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 ContentMap page(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<ContentMap> ancestors(ContentMap contentMap)
                           throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

ancestors

public List<ContentMap> ancestors(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 ContentMap inherit(ContentMap content)
                   throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

inherit

public ContentMap inherit(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(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<ContentMap> inheritList(ContentMap content,
                                    String relPath)
                             throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

isInherited

public boolean isInherited(javax.jcr.Node content)

isInherited

public boolean isInherited(ContentMap content)

isFromCurrentPage

public boolean isFromCurrentPage(javax.jcr.Node content)

isFromCurrentPage

public boolean isFromCurrentPage(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(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(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(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 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 SiblingsHelper siblings(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 ContentMap contentByPath(String path)
Return the ContentMap for the Given Path from the website repository.


contentByPath

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


contentById

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


contentById

public 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<ContentMap> asContentMapList(Collection<javax.jcr.Node> nodeList)

asNodeList

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

asNodeList

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

asContentMapList

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

decode

public ContentMap decode(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 ContentMap encode(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(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.