1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.wiki.mow.core.api.wiki;
18
19 import java.util.Iterator;
20 import java.util.Map;
21 import java.util.Map.Entry;
22
23 import org.chromattic.api.annotations.Create;
24 import org.chromattic.api.annotations.OneToMany;
25 import org.chromattic.api.annotations.Path;
26 import org.chromattic.api.annotations.PrimaryType;
27 import org.exoplatform.services.log.ExoLogger;
28 import org.exoplatform.services.log.Log;
29 import org.exoplatform.wiki.WikiException;
30
31 @PrimaryType(name = WikiNodeType.WIKI_TEMPLATE_CONTAINER)
32 public abstract class TemplateContainer {
33
34 @Create
35 public abstract TemplateImpl createTemplatePage();
36
37 @Path
38 public abstract String getPath();
39
40 @OneToMany
41 public abstract Map<String, TemplateImpl> getTemplates();
42 public abstract void setTemplates(Map<String,TemplateImpl> templates);
43
44 public TemplateImpl addPage(String templateName, TemplateImpl template) {
45 if (templateName == null) {
46 throw new IllegalArgumentException("Template name cannot be null");
47 }
48 if (template == null) {
49 throw new IllegalArgumentException("Template cannot be null");
50 }
51 Map<String, TemplateImpl> children = getTemplates();
52 if (children.containsKey(templateName)) {
53 return template;
54 }
55 children.put(templateName, template);
56
57 return template;
58 }
59
60 public TemplateImpl getTemplate(String name) {
61 Iterator<Entry<String, TemplateImpl>> iter = getTemplates().entrySet().iterator();
62 while (iter.hasNext()) {
63 Entry<String, TemplateImpl> entry = iter.next();
64 TemplateImpl template = entry.getValue();
65 if (template.getName().equals(name)) {
66 return template;
67 }
68 }
69 return null;
70 };
71
72 }