01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.components.template;
06:
07: import java.util.ArrayList;
08: import java.util.List;
09:
10: /**
11: * A template.
12: * <p/>
13: * A template is used as a model for rendering output.
14: * This object contains basic common template information
15: *
16: * @author plightbo
17: */
18: public class Template implements Cloneable {
19: String dir;
20: String theme;
21: String name;
22:
23: /**
24: * Constructor.
25: *
26: * @param dir base folder where the template is stored.
27: * @param theme the theme of the template
28: * @param name the name of the template.
29: */
30: public Template(String dir, String theme, String name) {
31: this .dir = dir;
32: this .theme = theme;
33: this .name = name;
34: }
35:
36: public String getDir() {
37: return dir;
38: }
39:
40: public String getTheme() {
41: return theme;
42: }
43:
44: public String getName() {
45: return name;
46: }
47:
48: public List getPossibleTemplates(TemplateEngine engine) {
49: List list = new ArrayList(3);
50: Template template = this ;
51: String parentTheme;
52: list.add(template);
53: while ((parentTheme = (String) engine.getThemeProps(template)
54: .get("parent")) != null) {
55: try {
56: template = (Template) template.clone();
57: template.theme = parentTheme;
58: list.add(template);
59: } catch (CloneNotSupportedException e) {
60: // do nothing
61: }
62: }
63:
64: return list;
65: }
66:
67: /**
68: * Constructs a string in the format <code>/dir/theme/name</code>.
69: * @return a string in the format <code>/dir/theme/name</code>.
70: */
71: public String toString() {
72: return "/" + dir + "/" + theme + "/" + name;
73: }
74:
75: protected Object clone() throws CloneNotSupportedException {
76: return super.clone();
77: }
78: }
|