View Javadoc

1   /**
2    * This file Copyright (c) 2011-2012 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.templating.functions;
35  
36  import info.magnolia.cms.beans.config.ServerConfiguration;
37  import info.magnolia.cms.core.AggregationState;
38  import info.magnolia.cms.core.MgnlNodeType;
39  import info.magnolia.cms.core.NodeData;
40  import info.magnolia.cms.i18n.I18nContentSupportFactory;
41  import info.magnolia.cms.util.ContentUtil;
42  import info.magnolia.cms.util.QueryUtil;
43  import info.magnolia.cms.util.SiblingsHelper;
44  import info.magnolia.jcr.inheritance.InheritanceNodeWrapper;
45  import info.magnolia.jcr.util.ContentMap;
46  import info.magnolia.jcr.util.MetaDataUtil;
47  import info.magnolia.jcr.util.NodeTypes;
48  import info.magnolia.jcr.util.NodeUtil;
49  import info.magnolia.jcr.util.PropertyUtil;
50  import info.magnolia.jcr.util.SessionUtil;
51  import info.magnolia.jcr.wrapper.HTMLEscapingNodeWrapper;
52  import info.magnolia.link.LinkUtil;
53  import info.magnolia.objectfactory.Components;
54  import info.magnolia.rendering.template.configured.ConfiguredInheritance;
55  import info.magnolia.repository.RepositoryConstants;
56  import info.magnolia.templating.inheritance.DefaultInheritanceContentDecorator;
57  
58  import java.util.ArrayList;
59  import java.util.Calendar;
60  import java.util.Collection;
61  import java.util.List;
62  
63  import javax.inject.Inject;
64  import javax.inject.Provider;
65  import javax.jcr.Node;
66  import javax.jcr.PathNotFoundException;
67  import javax.jcr.Property;
68  import javax.jcr.PropertyType;
69  import javax.jcr.RepositoryException;
70  
71  import org.apache.commons.lang.StringUtils;
72  import org.apache.jackrabbit.util.ISO8601;
73  import org.slf4j.Logger;
74  import org.slf4j.LoggerFactory;
75  
76  /**
77   * An object exposing several methods useful for templates. It is exposed in templates as <code>cmsfn</code>.
78   *
79   * @version $Id$
80   */
81  public class TemplatingFunctions {
82  
83      private static final Logger log = LoggerFactory.getLogger(TemplatingFunctions.class);
84  
85      private final Provider<AggregationState> aggregationStateProvider;
86  
87      //TODO: To review with Philipp. Should not use Provider, but has deep impact on CategorizationSupportImpl PageSyndicator CategorySyndicator....
88      @Inject
89      public TemplatingFunctions(Provider<AggregationState> aggregationStateProvider) {
90          this.aggregationStateProvider = aggregationStateProvider;
91      }
92  
93  
94      public Node asJCRNode(ContentMap contentMap) {
95          return contentMap == null ? null : contentMap.getJCRNode();
96      }
97  
98      public ContentMap asContentMap(Node content) {
99          return content == null ? null : new ContentMap(content);
100     }
101 
102     public List<Node> children(Node content) throws RepositoryException {
103         return content == null ? null : asNodeList(NodeUtil.getNodes(content, NodeUtil.EXCLUDE_META_DATA_FILTER));
104     }
105 
106     public List<Node> children(Node content, String nodeTypeName) throws RepositoryException {
107         return content == null ? null : asNodeList(NodeUtil.getNodes(content, nodeTypeName));
108     }
109 
110     public List<ContentMap> children(ContentMap content) throws RepositoryException {
111         return content == null ? null : asContentMapList(NodeUtil.getNodes(asJCRNode(content), NodeUtil.EXCLUDE_META_DATA_FILTER));
112     }
113 
114     public List<ContentMap> children(ContentMap content, String nodeTypeName) throws RepositoryException {
115         return content == null ? null : asContentMapList(NodeUtil.getNodes(asJCRNode(content), nodeTypeName));
116     }
117 
118     public ContentMap root(ContentMap contentMap) throws RepositoryException {
119         return contentMap == null ? null : asContentMap(this.root(contentMap.getJCRNode()));
120     }
121 
122     public ContentMap root(ContentMap contentMap, String nodeTypeName) throws RepositoryException {
123         return contentMap == null ? null : asContentMap(this.root(contentMap.getJCRNode(), nodeTypeName));
124     }
125 
126     public Node root(Node content) throws RepositoryException {
127         return this.root(content, null);
128     }
129 
130     public Node root(Node content, String nodeTypeName) throws RepositoryException {
131         if (content == null) {
132             return null;
133         }
134         if (nodeTypeName == null) {
135             return (Node) content.getAncestor(0);
136         }
137         if (isRoot(content) && content.isNodeType(nodeTypeName)) {
138             return content;
139         }
140 
141         Node parentNode = this.parent(content, nodeTypeName);
142         while (parent(parentNode, nodeTypeName) != null) {
143             parentNode = this.parent(parentNode, nodeTypeName);
144         }
145         return parentNode;
146     }
147 
148     public ContentMap parent(ContentMap contentMap) throws RepositoryException {
149         return contentMap == null ? null : asContentMap(this.parent(contentMap.getJCRNode()));
150     }
151 
152     public ContentMap parent(ContentMap contentMap, String nodeTypeName) throws RepositoryException {
153         return contentMap == null ? null : asContentMap(this.parent(contentMap.getJCRNode(), nodeTypeName));
154     }
155 
156     public Node parent(Node content) throws RepositoryException {
157         return this.parent(content, null);
158     }
159 
160     public Node parent(Node content, String nodeTypeName) throws RepositoryException {
161         if (content == null) {
162             return null;
163         }
164         if (isRoot(content)) {
165             return null;
166         }
167         if (nodeTypeName == null) {
168             return content.getParent();
169         }
170         Node parent = content.getParent();
171         while (!parent.isNodeType(nodeTypeName)) {
172             if (isRoot(parent)) {
173                 return null;
174             }
175             parent = parent.getParent();
176         }
177         return parent;
178     }
179 
180     /**
181      * Returns the page's {@link ContentMap} of the passed {@link ContentMap}. If the passed {@link ContentMap} represents a page, the passed {@link ContentMap} will be returned.
182      * If the passed {@link ContentMap} has no parent page at all, null is returned.
183      *
184      * @param content the {@link ContentMap} to get the page's {@link ContentMap} from.
185      * @return returns the page {@link ContentMap} of the passed content {@link ContentMap}.
186      * @throws RepositoryException
187      */
188     public ContentMap page(ContentMap content) throws RepositoryException {
189         return content == null ? null : asContentMap(page(content.getJCRNode()));
190     }
191 
192     /**
193      * Returns the page {@link Node} of the passed node. If the passed {@link Node} is a page, the passed {@link Node} will be returned.
194      * If the passed Node has no parent page at all, null is returned.
195      *
196      * @param content the {@link Node} to get the page from.
197      * @return returns the page {@link Node} of the passed content {@link Node}.
198      * @throws RepositoryException
199      */
200     public Node page(Node content) throws RepositoryException {
201         if (content == null) {
202             return null;
203         }
204         if (content.isNodeType(MgnlNodeType.NT_PAGE)) {
205             return content;
206         }
207         return parent(content, MgnlNodeType.NT_PAGE);
208     }
209 
210     public List<ContentMap> ancestors(ContentMap contentMap) throws RepositoryException {
211         return ancestors(contentMap, null);
212     }
213 
214     public List<ContentMap> ancestors(ContentMap contentMap, String nodeTypeName) throws RepositoryException {
215         List<Node> ancestorsAsNodes = this.ancestors(contentMap.getJCRNode(), nodeTypeName);
216         return asContentMapList(ancestorsAsNodes);
217     }
218 
219     public List<Node> ancestors(Node content) throws RepositoryException {
220         return content == null ? null : this.ancestors(content, null);
221     }
222 
223     public List<Node> ancestors(Node content, String nodeTypeName) throws RepositoryException {
224         if (content == null) {
225             return null;
226         }
227         List<Node> ancestors = new ArrayList<Node>();
228         int depth = content.getDepth();
229         for (int i = 1; i < depth; ++i) {
230             Node possibleAncestor = (Node) content.getAncestor(i);
231             if (nodeTypeName == null) {
232                 ancestors.add(possibleAncestor);
233             } else {
234                 if (possibleAncestor.isNodeType(nodeTypeName)) {
235                     ancestors.add(possibleAncestor);
236                 }
237             }
238         }
239         return ancestors;
240     }
241 
242     public Node inherit(Node content) throws RepositoryException {
243         return inherit(content, null);
244     }
245 
246     public Node inherit(Node content, String relPath) throws RepositoryException {
247         if (content == null) {
248             return null;
249         }
250         Node inheritedNode = wrapForInheritance(content);
251 
252         if (StringUtils.isBlank(relPath)) {
253             return inheritedNode;
254         }
255 
256         try {
257             Node subNode = inheritedNode.getNode(relPath);
258             return NodeUtil.unwrap(subNode);
259         } catch (PathNotFoundException e) {
260             // TODO fgrilli: rethrow exception?
261         }
262         return null;
263     }
264 
265     public ContentMap inherit(ContentMap content) throws RepositoryException {
266         return inherit(content, null);
267     }
268 
269     public ContentMap inherit(ContentMap content, String relPath) throws RepositoryException {
270         if (content == null) {
271             return null;
272         }
273         Node node = inherit(content.getJCRNode(), relPath);
274         return node == null ? null : new ContentMap(node);
275     }
276 
277 
278     public Property inheritProperty(Node content, String relPath) throws RepositoryException {
279         if (content == null) {
280             return null;
281         }
282         if (StringUtils.isBlank(relPath)) {
283             throw new IllegalArgumentException("relative path cannot be null or empty");
284         }
285         try {
286             Node inheritedNode = wrapForInheritance(content);
287             return inheritedNode.getProperty(relPath);
288 
289         } catch (PathNotFoundException e) {
290             // TODO fgrilli: rethrow exception?
291         } catch (RepositoryException e) {
292             // TODO fgrilli:rethrow exception?
293         }
294 
295         return null;
296     }
297 
298     public Property inheritProperty(ContentMap content, String relPath) throws RepositoryException {
299         if (content == null) {
300             return null;
301         }
302         return inheritProperty(content.getJCRNode(), relPath);
303     }
304 
305     public List<Node> inheritList(Node content, String relPath) throws RepositoryException {
306         if (content == null) {
307             return null;
308         }
309         if (StringUtils.isBlank(relPath)) {
310             throw new IllegalArgumentException("relative path cannot be null or empty");
311         }
312         Node inheritedNode = wrapForInheritance(content);
313         Node subNode = inheritedNode.getNode(relPath);
314         return children(subNode);
315     }
316 
317     public List<ContentMap> inheritList(ContentMap content, String relPath) throws RepositoryException {
318         if (content == null) {
319             return null;
320         }
321         if (StringUtils.isBlank(relPath)) {
322             throw new IllegalArgumentException("relative path cannot be null or empty");
323         }
324         Node node = asJCRNode(content);
325         Node inheritedNode = wrapForInheritance(node);
326         Node subNode = inheritedNode.getNode(relPath);
327         return children(new ContentMap(subNode));
328     }
329 
330     public boolean isInherited(Node content) {
331         if (content instanceof InheritanceNodeWrapper) {
332             return ((InheritanceNodeWrapper) content).isInherited();
333         }
334         return false;
335     }
336 
337     public boolean isInherited(ContentMap content) {
338         return isInherited(asJCRNode(content));
339     }
340 
341     public boolean isFromCurrentPage(Node content) {
342         return !isInherited(content);
343     }
344 
345     public boolean isFromCurrentPage(ContentMap content) {
346         return isFromCurrentPage(asJCRNode(content));
347     }
348 
349     /**
350      * Create link for the Node identified by nodeIdentifier in the specified workspace.
351      */
352     public String link(String workspace, String nodeIdentifier) {
353         try {
354             return LinkUtil.createLink(workspace, nodeIdentifier);
355         } catch (RepositoryException e) {
356             return null;
357         }
358     }
359 
360     /**
361      * 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 #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.
362      * 
363      * @deprecated since 4.5.4. There is no valid use case for this method.
364      */
365     @Deprecated
366     public String link(Property property) {
367         try {
368             Node parentNode = null;
369             String propertyName = null;
370             if (property.getType() == PropertyType.BINARY) {
371                 parentNode = property.getParent().getParent();
372                 propertyName = property.getParent().getName();
373             } else {
374                 parentNode = property.getParent();
375                 propertyName = property.getName();
376             }
377             NodeData equivNodeData = ContentUtil.asContent(parentNode).getNodeData(propertyName);
378             return LinkUtil.createLink(equivNodeData);
379         } catch (Exception e) {
380             return null;
381         }
382     }
383 
384     // TODO fgrilli: LinkUtil needs to be Node capable and not only Content. Switch to node based impl when SCRUM-242
385     // will be done.
386     public String link(Node content) {
387         return content == null ? null : LinkUtil.createLink(ContentUtil.asContent(content));
388     }
389 
390     public String link(ContentMap contentMap) throws RepositoryException {
391         return contentMap == null ? null : this.link(asJCRNode(contentMap));
392     }
393 
394     /**
395      * Get the language used currently.
396      * @return The language as a String.
397      */
398     public String language(){
399         return I18nContentSupportFactory.getI18nSupport().getLocale().toString();
400     }
401     /**
402      * Returns an external link prepended with <code>http://</code> in case the protocol is missing or an empty String
403      * if the link does not exist.
404      *
405      * @param content The node where the link property is stored on.
406      * @param linkPropertyName The property where the link value is stored in.
407      * @return The link prepended with <code>http://</code>
408      */
409     public String externalLink(Node content, String linkPropertyName) {
410         String externalLink = PropertyUtil.getString(content, linkPropertyName);
411         if (StringUtils.isBlank(externalLink)) {
412             return StringUtils.EMPTY;
413         }
414         if (!hasProtocol(externalLink)) {
415             externalLink = "http://" + externalLink;
416         }
417         return externalLink;
418     }
419 
420     /**
421      * Returns an external link prepended with <code>http://</code> in case the protocol is missing or an empty String
422      * if the link does not exist.
423      *
424      * @param content The node's map representation where the link property is stored on.
425      * @param linkPropertyName The property where the link value is stored in.
426      * @return The link prepended with <code>http://</code>
427      */
428     public String externalLink(ContentMap content, String linkPropertyName) {
429         return externalLink(asJCRNode(content), linkPropertyName);
430     }
431 
432     /**
433      * Return a link title based on the @param linkTitlePropertyName. When property @param linkTitlePropertyName is
434      * empty or null, the link itself is provided as the linkTitle (prepended with <code>http://</code>).
435      *
436      * @param content The node where the link property is stored on.
437      * @param linkPropertyName The property where the link value is stored in.
438      * @param linkTitlePropertyName The property where the link title value is stored
439      * @return the resolved link title value
440      */
441     public String externalLinkTitle(Node content, String linkPropertyName, String linkTitlePropertyName) {
442         String linkTitle = PropertyUtil.getString(content, linkTitlePropertyName);
443         if (StringUtils.isNotEmpty(linkTitle)) {
444             return linkTitle;
445         }
446         return externalLink(content, linkPropertyName);
447     }
448 
449     /**
450      * Return a link title based on the @param linkTitlePropertyName. When property @param linkTitlePropertyName is
451      * empty or null, the link itself is provided as the linkTitle (prepended with <code>http://</code>).
452      *
453      * @param content The node where the link property is stored on.
454      * @param linkPropertyName The property where the link value is stored in.
455      * @param linkTitlePropertyName The property where the link title value is stored
456      * @return the resolved link title value
457      */
458     public String externalLinkTitle(ContentMap content, String linkPropertyName, String linkTitlePropertyName) {
459         return externalLinkTitle(asJCRNode(content), linkPropertyName, linkTitlePropertyName);
460     }
461 
462     public boolean isEditMode() {
463         // TODO : see CmsFunctions.isEditMode, which checks a couple of other properties.
464         return isAuthorInstance() && !isPreviewMode();
465     }
466 
467     public boolean isPreviewMode() {
468         return this.aggregationStateProvider.get().isPreviewMode();
469     }
470 
471     public boolean isAuthorInstance() {
472         return Components.getComponent(ServerConfiguration.class).isAdmin();
473     }
474 
475     public boolean isPublicInstance() {
476         return !isAuthorInstance();
477     }
478 
479     /**
480      * Util method to create html attributes <code>name="value"</code>. If the value is empty an empty string will be returned.
481      * This is mainly helpful to avoid empty attributes.
482      */
483     public String createHtmlAttribute(String name, String value) {
484         value = StringUtils.trim(value);
485         if (StringUtils.isNotEmpty(value)) {
486             return new StringBuffer().append(name).append("=\"").append(value).append("\"").toString();
487         }
488         return StringUtils.EMPTY;
489     }
490 
491     /**
492      * Returns an instance of SiblingsHelper for the given node.
493      */
494     public SiblingsHelper siblings(Node node) throws RepositoryException {
495         return SiblingsHelper.of(ContentUtil.asContent(node));
496     }
497 
498     public SiblingsHelper siblings(ContentMap node) throws RepositoryException {
499         return siblings(asJCRNode(node));
500     }
501 
502     /**
503      * Return the Node for the Given Path
504      * from the website repository.
505      */
506     public Node content(String path){
507         return content(RepositoryConstants.WEBSITE, path);
508     }
509 
510     /**
511      * Return the Node for the Given Path
512      * from the given repository.
513      */
514     public Node content(String repository, String path){
515         return SessionUtil.getNode(repository, path);
516     }
517 
518     /**
519      * Return the Node by the given identifier
520      * from the website repository.
521      */
522     public Node contentByIdentifier(String id){
523         return contentByIdentifier(RepositoryConstants.WEBSITE, id);
524     }
525 
526     /**
527     * Return the Node by the given identifier
528     * from the given repository.
529     */
530     public Node contentByIdentifier(String repository, String id){
531         return SessionUtil.getNodeByIdentifier(repository, id);
532     }
533 
534     public List<ContentMap> asContentMapList(Collection<Node> nodeList) {
535         if (nodeList != null) {
536             List<ContentMap> contentMapList = new ArrayList<ContentMap>();
537             for (Node node : nodeList) {
538                 contentMapList.add(asContentMap(node));
539             }
540             return contentMapList;
541         }
542         return null;
543     }
544 
545     public List<Node> asNodeList(Collection<ContentMap> contentMapList) {
546         if (contentMapList != null) {
547             List<Node> nodeList = new ArrayList<Node>();
548             for (ContentMap node : contentMapList) {
549                 nodeList.add(node.getJCRNode());
550             }
551             return nodeList;
552         }
553         return null;
554     }
555 
556     // TODO fgrilli: should we unwrap children?
557     protected List<Node> asNodeList(Iterable<Node> nodes) {
558         List<Node> childList = new ArrayList<Node>();
559         for (Node child : nodes) {
560             childList.add(child);
561         }
562         return childList;
563     }
564 
565     // TODO fgrilli: should we unwrap children?
566     protected List<ContentMap> asContentMapList(Iterable<Node> nodes) {
567         List<ContentMap> childList = new ArrayList<ContentMap>();
568         for (Node child : nodes) {
569             childList.add(new ContentMap(child));
570         }
571         return childList;
572     }
573 
574     /**
575      * Checks if passed string has a <code>http://</code> protocol.
576      *
577      * @param link The link to check
578      * @return If @param link contains a <code>http://</code> protocol
579      */
580     private boolean hasProtocol(String link) {
581         return link != null && link.contains("://");
582     }
583 
584     /**
585      * Checks if the passed {@link Node} is the jcr root '/' of the workspace.
586      * @param content {@link Node} to check if its root.
587      * @return if @param content is the jcr workspace root.
588      * @throws RepositoryException
589      */
590     private boolean isRoot(Node content) throws RepositoryException {
591         return content.getDepth() == 0;
592     }
593 
594     /**
595      * Removes escaping of HTML on properties.
596      */
597     public ContentMap decode(ContentMap content){
598         return asContentMap(decode(content.getJCRNode()));
599     }
600 
601     /**
602      * Removes escaping of HTML on properties.
603      */
604     public Node decode(Node content){
605         return NodeUtil.deepUnwrap(content, HTMLEscapingNodeWrapper.class);
606     }
607 
608     /**
609      * Adds escaping of HTML on properties as well as changing line breaks into &lt;br/&gt; tags.
610      */
611     public Node encode(Node content){
612         return content != null ? new HTMLEscapingNodeWrapper(content, true) : null;
613     }
614 
615     private Node wrapForInheritance(Node destination) throws RepositoryException {
616         ConfiguredInheritance inheritanceConfiguration = new ConfiguredInheritance();
617         inheritanceConfiguration.setEnabled(true);
618         return new DefaultInheritanceContentDecorator(destination, inheritanceConfiguration).wrapNode(destination);
619     }
620 
621     /**
622      * Returns the string representation of a property from the metaData of the node or <code>null</code> if the node has no Magnolia metaData or if no matching property is found.
623      */
624     public String metaData(Node content, String property){
625 
626         Object returnValue;
627         try {
628             if (property.equals(NodeTypes.Created.CREATED)) {
629                 returnValue = NodeTypes.Created.getCreated(content);
630             } else if (property.equals(NodeTypes.Created.CREATED_BY)) {
631                 returnValue = NodeTypes.Created.getCreatedBy(content);
632             } else if (property.equals(NodeTypes.LastModified.LAST_MODIFIED)) {
633                 returnValue = NodeTypes.LastModified.getLastModified(content);
634             } else if (property.equals(NodeTypes.LastModified.LAST_MODIFIED_BY)) {
635                 returnValue = NodeTypes.LastModified.getLastModifiedBy(content);
636             } else if (property.equals(NodeTypes.Renderable.TEMPLATE)) {
637                 returnValue = NodeTypes.Renderable.getTemplate(content);
638             } else if (property.equals(NodeTypes.Activatable.LAST_ACTIVATED)) {
639                 returnValue = NodeTypes.Activatable.getLastActivated(content);
640             } else if (property.equals(NodeTypes.Activatable.LAST_ACTIVATED_BY)) {
641                 returnValue = NodeTypes.Activatable.getLastActivatedBy(content);
642             } else if (property.equals(NodeTypes.Activatable.ACTIVATION_STATUS)) {
643                 returnValue = NodeTypes.Activatable.getActivationStatus(content);
644             } else if (property.equals(NodeTypes.Deleted.DELETED)) {
645                 returnValue = NodeTypes.Deleted.getDeleted(content);
646             } else if (property.equals(NodeTypes.Deleted.DELETED_BY)) {
647                 returnValue = NodeTypes.Deleted.getDeletedBy(content);
648             } else if (property.equals(NodeTypes.Deleted.COMMENT)) {
649                 // Since NodeTypes.Deleted.COMMENT and NodeTypes.Versionable.COMMENT have identical names this will work for both
650                 returnValue = NodeTypes.Deleted.getComment(content);
651             } else {
652 
653                 // Try to get the value using one of the deprecated names in MetaData.
654                 // This throws an IllegalArgumentException if its not one of those constants
655                 returnValue = MetaDataUtil.getMetaData(content).getStringProperty(property);
656 
657                 // If no exception was thrown then warn that a legacy constant was used
658                 log.warn("Deprecated constant [" + property+"] used to query for meta data property on node [" + NodeUtil.getPathIfPossible(content) + "]");
659             }
660         } catch (RepositoryException e) {
661             return "";
662         }
663 
664         return returnValue instanceof Calendar ? ISO8601.format((Calendar) returnValue) : returnValue.toString();
665     }
666 
667     /**
668      * @see {@link TemplatingFunctions#metaData(Node, String)}.
669      */
670     public String metaData(ContentMap content, String property){
671         return metaData(content.getJCRNode(), property);
672     }
673     
674     /**
675      * Executes query and returns result as Collection of Nodes.
676      * 
677      * @param workspace
678      * @param statement has to be in formal form for chosen language
679      * @param language
680      * @param returnItemType
681      */
682     public Collection<Node> search(String workspace, String statement, String language, String returnItemType){
683         try {
684             return NodeUtil.getCollectionFromNodeIterator(QueryUtil.search(workspace, statement, language, returnItemType));
685         } catch (Exception e) {
686             log.error(e.getMessage(), e);
687         }
688         return null;
689     }
690     
691     /**
692      * Executes simple SQL2 query and returns result as Collection of Nodes.
693      * 
694      * @param workspace
695      * @param statement should be set of labels target has to contain inserted as one string each separated by comma
696      * @param returnItemType
697      * @param startPath can be inserted, for results without limitation set it to slash
698      */
699     public Collection<Node> simpleSearch(String workspace, String statement, String returnItemType, String startPath){
700         if(StringUtils.isEmpty(statement)){
701             log.error("Cannot search with empty statement.");
702             return null;
703         }
704         String query = QueryUtil.buildQuery(statement, startPath);
705         try {
706             return NodeUtil.getCollectionFromNodeIterator(QueryUtil.search(workspace, query, "JCR-SQL2", returnItemType));
707         } catch (Exception e) {
708             log.error(e.getMessage(), e);
709         }
710         return null;
711     }
712 }