01: /*
02: * $Id: Template.java 560894 2007-07-30 09:05:32Z rgielen $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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)
68: .get("parent")) != null) {
69: try {
70: template = (Template) template.clone();
71: template.theme = parentTheme;
72: list.add(template);
73: } catch (CloneNotSupportedException e) {
74: // do nothing
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: }
|