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