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