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