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.jcr.util.ContentMap;
37 import info.magnolia.objectfactory.Components;
38 import info.magnolia.rendering.template.configured.ConfiguredInheritance;
39 import info.magnolia.templating.functions.SiblingsHelper;
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 @Function
168 public static String link(ContentMap contentMap) throws RepositoryException {
169 return getTemplatingFunctions().link(contentMap);
170 }
171
172 @Function
173 public static String link(ContentMap contentMap, String propertyName) throws RepositoryException {
174 return getTemplatingFunctions().link(contentMap);
175 }
176
177
178
179
180
181
182 @Function
183 public static String language() {
184 return getTemplatingFunctions().language();
185 }
186
187
188
189
190
191
192
193
194
195 @Function
196 public static String externalLink(ContentMap content, String linkPropertyName) {
197 return getTemplatingFunctions().externalLink(content, linkPropertyName);
198 }
199
200
201
202
203
204
205
206
207
208
209 @Function
210 public static String externalLinkTitle(ContentMap content, String linkPropertyName, String linkTitlePropertyName) {
211 return getTemplatingFunctions().externalLinkTitle(content, linkPropertyName, linkTitlePropertyName);
212 }
213
214 @Function
215 public static boolean isEditMode() {
216 return getTemplatingFunctions().isEditMode();
217 }
218
219 @Function
220 public static boolean isPreviewMode() {
221 return getTemplatingFunctions().isPreviewMode();
222 }
223
224 @Function
225 public static boolean isAuthorInstance() {
226 return getTemplatingFunctions().isAuthorInstance();
227 }
228
229 @Function
230 public static boolean isPublicInstance() {
231 return getTemplatingFunctions().isPublicInstance();
232 }
233
234
235
236
237
238 @Function
239 public static String createHtmlAttribute(String name, String value) {
240 return getTemplatingFunctions().createHtmlAttribute(name, value);
241 }
242
243
244
245
246 @Function
247 public static SiblingsHelper siblings(ContentMap node) throws RepositoryException {
248 return getTemplatingFunctions().siblings(node);
249 }
250
251
252
253
254
255
256 @Function
257 public static Node content(String path, String repository) {
258 if (StringUtils.isBlank(repository)) {
259 return getTemplatingFunctions().content(path);
260 }
261 return getTemplatingFunctions().content(repository, path);
262 }
263
264
265
266
267
268
269 @Function
270 public static Node contentByIdentifier(String id, String repository) {
271 if (StringUtils.isBlank(repository)) {
272 return getTemplatingFunctions().contentByIdentifier(id);
273 }
274 return getTemplatingFunctions().contentByIdentifier(repository, id);
275 }
276
277 @Function
278 public static List<ContentMap> asContentMapList(Collection<Node> nodeList) {
279 return getTemplatingFunctions().asContentMapList(nodeList);
280 }
281
282 @Function
283 public static List<Node> asNodeList(Collection<ContentMap> contentMapList) {
284 return getTemplatingFunctions().asNodeList(contentMapList);
285 }
286
287
288
289
290 @Function
291 public static ContentMap decode(ContentMap content) {
292 return getTemplatingFunctions().decode(content);
293 }
294
295
296
297
298 @Function
299 public static String metaData(ContentMap content, String property) {
300 return getTemplatingFunctions().metaData(content, property);
301 }
302
303 @Function
304 public static Collection<Node> search(String workspace, String statement, String language, String returnItemType) {
305 return getTemplatingFunctions().search(workspace, statement, language, returnItemType);
306 }
307
308 @Function
309 public static Collection<Node> simpleSearch(String workspace, String statement, String returnItemType, String startPath) {
310 return getTemplatingFunctions().simpleSearch(workspace, statement, returnItemType, startPath);
311 }
312 }