1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.templating.jsp.cmsfn;
35
36 import info.magnolia.cms.util.SiblingsHelper;
37 import info.magnolia.jcr.util.ContentMap;
38 import info.magnolia.objectfactory.Components;
39 import info.magnolia.rendering.template.configured.ConfiguredInheritance;
40 import info.magnolia.templating.functions.TemplatingFunctions;
41
42 import java.util.Collection;
43 import java.util.List;
44
45 import javax.jcr.Node;
46 import javax.jcr.Property;
47 import javax.jcr.RepositoryException;
48
49 import org.apache.commons.lang3.StringUtils;
50 import org.tldgen.annotations.Function;
51
52
53
54
55
56 public class JspTemplatingFunction {
57
58 private static TemplatingFunctions templatingFunctions;
59
60
61
62
63
64
65
66
67 private static TemplatingFunctions getTemplatingFunctions() {
68 if (templatingFunctions == null) {
69 templatingFunctions = Components.getComponent(TemplatingFunctions.class);
70 }
71 return templatingFunctions;
72 }
73
74 @Function
75 public static Node asJCRNode(ContentMap contentMap) {
76 return getTemplatingFunctions().asJCRNode(contentMap);
77 }
78
79 @Function
80 public static ContentMap asContentMap(Node content) {
81 return getTemplatingFunctions().asContentMap(content);
82 }
83
84 @Function
85 public static List<ContentMap> children(ContentMap content, String nodeTypeName) throws RepositoryException {
86 if (!nodeTypeName.isEmpty()) {
87 return getTemplatingFunctions().children(content, nodeTypeName);
88 }
89 return getTemplatingFunctions().children(content);
90 }
91
92 @Function()
93 public static ContentMap root(ContentMap contentMap, String nodeTypeName) throws RepositoryException {
94 if (!nodeTypeName.isEmpty()) {
95 ContentMap root = getTemplatingFunctions().root(contentMap, nodeTypeName);
96 return root;
97 }
98 return getTemplatingFunctions().root(contentMap);
99 }
100
101 @Function
102 public static ContentMap parent(ContentMap contentMap, String nodeTypeName) throws RepositoryException {
103 if (!nodeTypeName.isEmpty()) {
104 return getTemplatingFunctions().parent(contentMap, nodeTypeName);
105 }
106 return getTemplatingFunctions().parent(contentMap);
107 }
108
109
110
111
112
113
114
115
116 @Function
117 public static ContentMap page(ContentMap content) throws RepositoryException {
118 return getTemplatingFunctions().page(content);
119 }
120
121 @Function
122 public static List<ContentMap> ancestors(ContentMap contentMap, String nodeTypeName) throws RepositoryException {
123 if (nodeTypeName.isEmpty()) {
124 return getTemplatingFunctions().ancestors(contentMap);
125 }
126 return getTemplatingFunctions().ancestors(contentMap, nodeTypeName);
127 }
128
129 @Function
130 public static ContentMap inherit(ContentMap content, String relPath) throws RepositoryException {
131 return JspTemplatingFunction.inherit(content, relPath, null, ConfiguredInheritance.COMPONENTS_FILTERED, ConfiguredInheritance.PROPERTIES_ALL);
132 }
133
134 @Function
135 public static ContentMap inherit(ContentMap content, String relPath, String nodeTypes, String nodeInheritance, String propertyInheritance) throws RepositoryException {
136 return getTemplatingFunctions().inherit(content, relPath, nodeTypes, nodeInheritance, propertyInheritance);
137 }
138
139 @Function
140 public static Property inheritProperty(ContentMap content, String relPath) throws RepositoryException {
141 return getTemplatingFunctions().inheritProperty(content, relPath);
142 }
143
144 @Function
145 public static List<ContentMap> inheritList(ContentMap content, String relPath) throws RepositoryException {
146 return getTemplatingFunctions().inheritList(content, relPath);
147 }
148
149 @Function
150 public static boolean isInherited(ContentMap content) {
151 return getTemplatingFunctions().isInherited(content);
152 }
153
154 @Function
155 public static boolean isFromCurrentPage(ContentMap content) {
156 return getTemplatingFunctions().isFromCurrentPage(content);
157 }
158
159
160
161
162 @Function
163 public static String linkForWorkspace(String workspace, String nodeIdentifier) {
164 return getTemplatingFunctions().link(workspace, nodeIdentifier);
165 }
166
167
168
169
170
171 @Function
172 public static String linkForProperty(Property property) {
173 return getTemplatingFunctions().link(property);
174 }
175
176 @Function
177 public static String link(ContentMap contentMap) throws RepositoryException {
178 return getTemplatingFunctions().link(contentMap);
179 }
180
181 @Function
182 public static String link(ContentMap contentMap, String propertyName) throws RepositoryException {
183 return getTemplatingFunctions().link(contentMap);
184 }
185
186
187
188
189
190
191 @Function
192 public static String language() {
193 return getTemplatingFunctions().language();
194 }
195
196
197
198
199
200
201
202
203
204 @Function
205 public static String externalLink(ContentMap content, String linkPropertyName) {
206 return getTemplatingFunctions().externalLink(content, linkPropertyName);
207 }
208
209
210
211
212
213
214
215
216
217
218 @Function
219 public static String externalLinkTitle(ContentMap content, String linkPropertyName, String linkTitlePropertyName) {
220 return getTemplatingFunctions().externalLinkTitle(content, linkPropertyName, linkTitlePropertyName);
221 }
222
223 @Function
224 public static boolean isEditMode() {
225 return getTemplatingFunctions().isEditMode();
226 }
227
228 @Function
229 public static boolean isPreviewMode() {
230 return getTemplatingFunctions().isPreviewMode();
231 }
232
233 @Function
234 public static boolean isAuthorInstance() {
235 return getTemplatingFunctions().isAuthorInstance();
236 }
237
238 @Function
239 public static boolean isPublicInstance() {
240 return getTemplatingFunctions().isPublicInstance();
241 }
242
243
244
245
246
247 @Function
248 public static String createHtmlAttribute(String name, String value) {
249 return getTemplatingFunctions().createHtmlAttribute(name, value);
250 }
251
252
253
254
255 @Function
256 public static SiblingsHelper siblings(ContentMap node) throws RepositoryException {
257 return getTemplatingFunctions().siblings(node);
258 }
259
260
261
262
263
264
265 @Function
266 public static Node content(String path, String repository) {
267 if (StringUtils.isBlank(repository)) {
268 return getTemplatingFunctions().content(path);
269 }
270 return getTemplatingFunctions().content(repository, path);
271 }
272
273
274
275
276
277
278 @Function
279 public static Node contentByIdentifier(String id, String repository) {
280 if (StringUtils.isBlank(repository)) {
281 return getTemplatingFunctions().contentByIdentifier(id);
282 }
283 return getTemplatingFunctions().contentByIdentifier(repository, id);
284 }
285
286 @Function
287 public static List<ContentMap> asContentMapList(Collection<Node> nodeList) {
288 return getTemplatingFunctions().asContentMapList(nodeList);
289 }
290
291 @Function
292 public static List<Node> asNodeList(Collection<ContentMap> contentMapList) {
293 return getTemplatingFunctions().asNodeList(contentMapList);
294 }
295
296
297
298
299 @Function
300 public static ContentMap decode(ContentMap content) {
301 return getTemplatingFunctions().decode(content);
302 }
303
304
305
306
307 @Function
308 public static String metaData(ContentMap content, String property) {
309 return getTemplatingFunctions().metaData(content, property);
310 }
311
312 @Function
313 public static Collection<Node> search(String workspace, String statement, String language, String returnItemType) {
314 return getTemplatingFunctions().search(workspace, statement, language, returnItemType);
315 }
316
317 @Function
318 public static Collection<Node> simpleSearch(String workspace, String statement, String returnItemType, String startPath) {
319 return getTemplatingFunctions().simpleSearch(workspace, statement, returnItemType, startPath);
320 }
321 }