1 /*
2 * Copyright (C) 2003-2007 eXo Platform SAS.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Affero General Public License
6 * as published by the Free Software Foundation; either version 3
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see<http://www.gnu.org/licenses/>.
16 */
17 package org.exoplatform.services.cms.templates;
18
19 import java.io.InputStream;
20 import java.util.List;
21 import java.util.Set;
22
23 import javax.jcr.Node;
24 import javax.jcr.NodeIterator;
25 import javax.jcr.PathNotFoundException;
26 import javax.jcr.RepositoryException;
27 import javax.jcr.Session;
28
29 import org.exoplatform.services.cms.templates.impl.TemplatePlugin;
30 import org.exoplatform.services.jcr.ext.common.SessionProvider;
31
32
33 /**
34 * @author benjaminmestrallet
35 */
36 public interface TemplateService {
37
38 static final public String DIALOGS = "dialogs";
39 static final public String VIEWS = "views";
40 static final public String SKINS = "skins";
41 static final public String DEFAULT_DIALOG = "dialog1";
42 static final public String DEFAULT_VIEW = "view1";
43 static final public String DEFAULT_SKIN = "Stylesheet-lt";
44
45 static final String[] UNDELETABLE_TEMPLATES = {DEFAULT_DIALOG, DEFAULT_VIEW};
46
47 static final public String DEFAULT_DIALOGS_PATH = "/" + DIALOGS + "/" + DEFAULT_DIALOG;
48 static final public String DEFAULT_VIEWS_PATH = "/" + VIEWS + "/" + DEFAULT_VIEW;
49
50 static final public String NT_UNSTRUCTURED = "nt:unstructured" ;
51 static final public String DOCUMENT_TEMPLATE_PROP = "isDocumentTemplate" ;
52 static final public String TEMPLATE_LABEL = "label" ;
53
54 static final public String RTL = "rtl";
55 static final public String LTR = "ltr";
56
57 /**
58 * Return path of default template by giving the following parameters.
59 * @param isDialog boolean
60 * The boolean value which specify the type of template
61 * @param nodeTypeName String
62 * The name of NodeType
63 */
64 public String getDefaultTemplatePath(boolean isDialog, String nodeTypeName) ;
65
66 /**
67 * Return template home of current repository.
68 * @param provider SessionProvider
69 * The SessionProvider object is used to managed Sessions
70 * @see Node
71 * @throws Exception
72 */
73 public Node getTemplatesHome(SessionProvider provider) throws Exception ;
74
75 /**
76 * Return path template of the specified node.
77 * @param node Node
78 * The specified node
79 * @param isDialog boolean
80 * The boolean value which specify the type of template
81 * @see Node
82 * @throws Exception
83 */
84 public String getTemplatePath(Node node, boolean isDialog) throws Exception ;
85
86
87 /**
88 * Return the path public template.
89 * @param isDialog boolean
90 * The boolean value which specify the type of template
91 * @param nodeTypeName String
92 * The specify name of node type
93 * @throws Exception
94 */
95 public String getTemplatePathByAnonymous(boolean isDialog, String nodeTypeName) throws Exception;
96
97 /**
98 * Return the template by user.
99 * @param isDialog boolean
100 * The boolean value which specify the type of template
101 * @param nodeTypeName String
102 * The specify name of node type
103 * @param userName String
104 * The current user
105 * @see Node
106 * @see Session
107 * @throws RepositoryException
108 */
109 public String getTemplatePathByUser(boolean isDialog, String nodeTypeName, String userName) throws RepositoryException;
110
111 /**
112 * Return path template of the specified node.
113 * @param isDialog boolean
114 * The boolean value which specify the type of template
115 * @param nodeTypeName String
116 * The specify name of node type
117 * @param templateName String
118 * The name of template
119 * @see Session
120 * @see Node
121 * @throws Exception
122 */
123 public String getTemplatePath(boolean isDialog, String nodeTypeName, String templateName) throws Exception ;
124
125 /**
126 * Return template file of the specified node.
127 * @param templateType String
128 * The string value which specify the type of template
129 * @param nodeTypeName String
130 * The specify name of node type
131 * @param templateName String
132 * The name of template
133 * @see Session
134 * @see Node
135 * @throws Exception
136 */
137 public String getTemplate(String templateType, String nodeTypeName, String templateName) throws Exception ;
138
139 /**
140 * Insert a new template into NodeType by giving the following parameters.
141 * @param templateType The value which specify the type of template
142 * @param nodeTypeName The specify name of NodType
143 * @param label The label of the specified template
144 * @param isDocumentTemplate The boolean value which yes or no is DocumentTemplate
145 * @param templateName The name of template
146 * @param roles The roles of template
147 * @param templateFile The file of template
148 * @see Session
149 * @see Node
150 * @throws Exception
151 */
152 public String addTemplate(String templateType,
153 String nodeTypeName,
154 String label,
155 boolean isDocumentTemplate,
156 String templateName,
157 String[] roles,
158 InputStream templateFile) throws Exception;
159
160 /**
161 * Insert a new template into NodeType by giving the following parameters.
162 * @param templateType The value which specify the type of template
163 * @param nodeTypeName The specify name of NodType
164 * @param label The label of the specified template
165 * @param isDocumentTemplate The boolean value which yes or no is DocumentTemplate
166 * @param templateName The name of template
167 * @param roles The roles of template
168 * @param templateFile The file of template
169 * @param templatesHome Node
170 * @see Session
171 * @see Node
172 * @throws Exception
173 */
174 public String addTemplate(String templateType,
175 String nodeTypeName,
176 String label,
177 boolean isDocumentTemplate,
178 String templateName,
179 String[] roles,
180 InputStream templateFile,
181 Node templatesHome) throws Exception;
182
183 /**
184 * This method is used to filter types of NodeType which is added in folder.
185 * @param filterPlugin Content filer plugin
186 * @throws Exception
187 */
188 public void addContentTypeFilterPlugin(ContentTypeFilterPlugin filterPlugin) throws Exception;
189
190 /**
191 * Get set of folder type.
192 */
193 public Set<String> getAllowanceFolderType();
194
195 /**
196 * Remove a template of NodeType by giving the following parameters.
197 * @param templateType String
198 * The value which specify the type of template
199 * @param nodeTypeName String
200 * The specify name of NodType
201 * @param templateName String
202 * The name of template
203 * @see Session
204 * @see Node
205 * @throws Exception
206 */
207 public void removeTemplate(String templateType, String nodeTypeName, String templateName) throws Exception;
208
209 /**
210 * Return true if the given repository has document type named 'nodeTypeName'.
211 * @param nodeTypeName String
212 * The name of NodeType
213 * @see SessionProvider
214 * @see Session
215 * @see Node
216 * @throws RepositoryException
217 */
218 public boolean isManagedNodeType(String nodeTypeName) throws RepositoryException ;
219
220 /**
221 * Get all templates is document type of the specified repository.
222 * @see Session
223 * @see Node
224 * @throws RepositoryException
225 */
226 public List<String> getDocumentTemplates() throws RepositoryException ;
227
228 /**
229 * Return all teamplate of the specified NodeType.
230 *
231 * @param isDialog boolean The boolean value which specify the type of
232 * template
233 * @param nodeTypeName String The name of NodeType
234 * @param provider SessionProvider The SessionProvider object is used to
235 * managed Sessions
236 * @see SessionProvider
237 * @see Node
238 * @throws Exception
239 */
240 public NodeIterator getAllTemplatesOfNodeType(boolean isDialog,
241 String nodeTypeName,
242 SessionProvider provider) throws Exception;
243
244 /**
245 * Removes the NodeType by giving the name of NodeType.
246 * @param nodeTypeName String
247 * The name of NodeType
248 * @see Session
249 * @see Node
250 * @throws Exception
251 */
252 public void removeManagedNodeType(String nodeTypeName) throws Exception ;
253
254 /**
255 * Return the label of the specified template by giving the following parameters.
256 * @param nodeTypeName String
257 * The specified name of NodeType
258 * @see SessionProvider
259 * @see Node
260 * @throws Exception
261 */
262 public String getTemplateLabel(String nodeTypeName) throws Exception ;
263
264 /**
265 * Return template Node (Name of NodeType, Name of Template) by giving the following parameters.
266 * @param templateType String
267 * The value which specify the type of template
268 * @param nodeTypeName String
269 * The name of NodeType
270 * @param templateName String
271 * The name of template
272 * @param provider SessionProvider
273 * The SessionProvider object is used to managed Sessions
274 * @see SessionProvider
275 * @see Node
276 * @throws Exception
277 */
278 public Node getTemplateNode(String templateType,
279 String nodeTypeName,
280 String templateName,
281 SessionProvider provider) throws Exception;
282
283 /**
284 * Return CreationableContent Types to the given node.
285 * @param node The specified node
286 * @see Node
287 * @throws Exception
288 */
289 public List<String> getCreationableContentTypes(Node node) throws Exception;
290
291 /**
292 * Get all template that is configured in XML file of current repository.
293 * @see TemplatePlugin
294 * @throws Exception
295 */
296 public void init() throws Exception ;
297
298 /**
299 * Remove all templates cached.
300 *
301 */
302 public void removeAllTemplateCached();
303
304 /**
305 * Remove cache of template.
306 * @param templatePath String
307 * jcr path of template
308 * @throws Exception
309 */
310 public void removeCacheTemplate(String templatePath) throws Exception;
311
312
313 /**
314 * Get All Document NodeTypes of the current repository.
315 * @return all document nodetypes
316 */
317 public List<String> getAllDocumentNodeTypes() throws PathNotFoundException, RepositoryException;
318
319 /**
320 * Get path of css file which included in view template.
321 * @param nodeTypeName String
322 * The node type name
323 * @param skinName String
324 * The name of css file
325 * @param locale String
326 * The locale which specified by user
327 * @return String
328 * The path of css file
329 * @throws Exception
330 */
331 public String getSkinPath(String nodeTypeName, String skinName, String locale) throws Exception;
332
333 /**
334 * Build string of dialog form template base on properties of nodetype.
335 * @param nodeTypeName
336 * @return
337 */
338 public String buildDialogForm(String nodeTypeName) throws Exception;
339
340 /**
341 * Build string of view template form base on properties of nodetype.
342 * @param nodeTypeName
343 * @return
344 */
345 public String buildViewForm(String nodeTypeName) throws Exception;
346
347 /**
348 * Build string of view template form base on properties of nodetype.
349 * @param nodeTypeName
350 * @return
351 */
352 public String buildStyleSheet(String nodeTypeName) throws Exception;
353
354 /**
355 * Insert a template into JCR database as an nt:file node. This method should be used for all the template types.
356 * @param templateFolder The parent node which contains the template node
357 * @param name The template's name
358 * @param data The template's data
359 * @param roles The template's roles
360 */
361 @Deprecated
362 public String createTemplate(Node templateFolder, String name, InputStream data, String[] roles);
363
364 /**
365 * Insert a template into JCR database as an nt:file node. This method should be used for all the template types.
366 * @param templateFolder The parent node which contains the template node
367 * @param title The template title
368 * @param templateName The template's name
369 * @param data The template's data
370 * @param roles The template's roles
371 */
372 public String createTemplate(Node templateFolder, String title, String templateName, InputStream data, String[] roles);
373
374 /**
375 * Update a template inside JCR database. This method should be used for all the template types.
376 * @param template The template node
377 * @param data The template's data
378 * @param roles The template's roles
379 */
380 public String updateTemplate(Node template, InputStream data, String[] roles);
381
382 /**
383 * Get a template from JCR database. This method should be used for all the template types.
384 * @param template The template node
385 */
386 public String getTemplate(Node template);
387
388 /**
389 * Get roles from a template. This method should be used for all the template types.
390 * @param template The template node
391 */
392 public String getTemplateRoles(Node template);
393
394 /**
395 * gets all node types configured
396 * @return
397 */
398 public Set<String> getAllConfiguredNodeTypes();
399
400 /**
401 * Gets all node types configured whose templates were edited.
402 * @return list of String
403 */
404 public Set<String> getAllEditedConfiguredNodeTypes() throws Exception;
405
406 }