KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > pojos > Theme


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. For additional information regarding
15  * copyright in this work, please see the NOTICE file in the top level
16  * directory of this distribution.
17  */

18
19 package org.apache.roller.pojos;
20
21 import java.io.Serializable JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Date JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27
28
29 /**
30  * The Theme object encapsulates all elements of a single weblog theme. It
31  * is used mostly to contain all the templates for a theme, but does contain
32  * other theme related attributes such as name, last modifed date, etc.
33  */

34 public class Theme implements Serializable JavaDoc {
35     
36     // this is the name that will be used to identify a user customized theme
37
public static final String JavaDoc CUSTOM = "custom";
38     
39     private String JavaDoc id;
40     private String JavaDoc name;
41     private String JavaDoc description;
42     private String JavaDoc author;
43     private String JavaDoc lastEditor; // user id value of last editor
44
private Date JavaDoc lastModified;
45     private boolean enabled;
46     
47     // we keep templates in a Map for faster lookups by name
48
// the Map contains ... (template name, ThemeTemplate)
49
private Map JavaDoc templates;
50     
51     
52     public Theme() {
53         this.id = null;
54         this.name = null;
55         this.description = null;
56         this.author = null;
57         this.lastEditor = null;
58         this.lastModified = null;
59         this.enabled = false;
60         this.templates = new HashMap JavaDoc();
61     }
62
63     
64     /**
65      * Get the collection of all templates associated with this Theme.
66      */

67     public Collection JavaDoc getTemplates() {
68         return this.templates.values();
69     }
70     
71     
72     /**
73      * Lookup the specified template by name.
74      * Returns null if the template cannot be found.
75      */

76     public ThemeTemplate getTemplate(String JavaDoc name) {
77         return (ThemeTemplate) this.templates.get(name);
78     }
79     
80     
81     /**
82      * Lookup the specified template by link.
83      * Returns null if the template cannot be found.
84      *
85      * NOTE: for themes we enforce the rule that
86      * Theme.link == Theme.name
87      *
88      * So this lookup is basically the same as lookup by name.
89      */

90     public ThemeTemplate getTemplateByLink(String JavaDoc link) {
91         return (ThemeTemplate) this.templates.get(link);
92     }
93     
94     
95     /**
96      * Set the value for a given template name.
97      */

98     public void setTemplate(String JavaDoc name, ThemeTemplate template) {
99         this.templates.put(name, template);
100     }
101     
102     
103     /**
104      * Check if this Theme contains the named template.
105      * Returns true if the template exists, false otherwise.
106      */

107     public boolean hasTemplate(String JavaDoc name) {
108         return this.templates.containsKey(name);
109     }
110     
111     
112     public String JavaDoc getId() {
113         return id;
114     }
115
116     public void setId(String JavaDoc id) {
117         this.id = id;
118     }
119     
120     public String JavaDoc getName() {
121         return name;
122     }
123
124     public void setName(String JavaDoc name) {
125         this.name = name;
126     }
127
128     public String JavaDoc getDescription() {
129         return description;
130     }
131
132     public void setDescription(String JavaDoc description) {
133         this.description = description;
134     }
135
136     public String JavaDoc getAuthor() {
137         return author;
138     }
139
140     public void setAuthor(String JavaDoc author) {
141         this.author = author;
142     }
143
144     public String JavaDoc getLastEditor() {
145         return lastEditor;
146     }
147
148     public void setLastEditor(String JavaDoc lastEditor) {
149         this.lastEditor = lastEditor;
150     }
151
152     public Date JavaDoc getLastModified() {
153         return lastModified;
154     }
155
156     public void setLastModified(Date JavaDoc lastModified) {
157         this.lastModified = lastModified;
158     }
159     
160     public boolean isEnabled() {
161         return enabled;
162     }
163
164     public void setEnabled(boolean enabled) {
165         this.enabled = enabled;
166     }
167     
168     public String JavaDoc toString() {
169         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
170         sb.append(name);
171         sb.append("\n");
172         
173         Iterator JavaDoc it = this.templates.values().iterator();
174         while(it.hasNext()) {
175             sb.append(it.next());
176             sb.append("\n");
177         }
178         
179         return sb.toString();
180         
181     }
182
183 }
184
Popular Tags