1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.components.template;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27 /***
28 * A template.
29 * <p/>
30 * A template is used as a model for rendering output.
31 * This object contains basic common template information
32 */
33 public class Template implements Cloneable {
34 String dir;
35 String theme;
36 String name;
37
38 /***
39 * Constructor.
40 *
41 * @param dir base folder where the template is stored.
42 * @param theme the theme of the template
43 * @param name the name of the template.
44 */
45 public Template(String dir, String theme, String name) {
46 this.dir = dir;
47 this.theme = theme;
48 this.name = name;
49 }
50
51 public String getDir() {
52 return dir;
53 }
54
55 public String getTheme() {
56 return theme;
57 }
58
59 public String getName() {
60 return name;
61 }
62
63 public List<Template> getPossibleTemplates(TemplateEngine engine) {
64 List<Template> list = new ArrayList<Template>(3);
65 Template template = this;
66 String parentTheme;
67 list.add(template);
68 while ((parentTheme = (String) engine.getThemeProps(template).get("parent")) != null) {
69 try {
70 template = (Template) template.clone();
71 template.theme = parentTheme;
72 list.add(template);
73 } catch (CloneNotSupportedException e) {
74
75 }
76 }
77
78 return list;
79 }
80
81 /***
82 * Constructs a string in the format <code>/dir/theme/name</code>.
83 * @return a string in the format <code>/dir/theme/name</code>.
84 */
85 public String toString() {
86 return "/" + dir + "/" + theme + "/" + name;
87 }
88
89 protected Object clone() throws CloneNotSupportedException {
90 return super.clone();
91 }
92 }