001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.pojos;
020:
021: import java.io.File;
022: import java.io.Serializable;
023: import java.util.ArrayList;
024: import java.util.Collection;
025: import java.util.Collections;
026: import java.util.Date;
027: import java.util.HashMap;
028: import java.util.Iterator;
029: import java.util.List;
030: import java.util.Map;
031:
032: /**
033: * The Theme object encapsulates all elements of a single weblog theme. It
034: * is used mostly to contain all the templates for a theme, but does contain
035: * other theme related attributes such as name, last modifed date, etc.
036: */
037: public class Theme implements Serializable {
038:
039: // this is the name that will be used to identify a user customized theme
040: public static final String CUSTOM = "custom";
041:
042: private String id;
043: private String name;
044: private String description;
045: private String author;
046: private String lastEditor; // user id value of last editor
047: private Date lastModified;
048: private boolean enabled;
049:
050: // we keep templates in a Map for faster lookups by name
051: // the Map contains ... (template name, ThemeTemplate)
052: private Map templates;
053:
054: // we keep resources in a Map for faster lookups by path
055: // the Map contains ... (resource path, File)
056: private Map resources;
057:
058: public Theme() {
059: this .id = null;
060: this .name = null;
061: this .description = null;
062: this .author = null;
063: this .lastEditor = null;
064: this .lastModified = null;
065: this .enabled = false;
066: this .templates = new HashMap();
067: this .resources = new HashMap();
068: }
069:
070: /**
071: * Get the collection of all templates associated with this Theme.
072: */
073: public Collection getTemplates() {
074: return this .templates.values();
075: }
076:
077: /**
078: * Lookup the specified template by name.
079: * Returns null if the template cannot be found.
080: */
081: public ThemeTemplate getTemplate(String name) {
082: return (ThemeTemplate) this .templates.get(name);
083: }
084:
085: /**
086: * Lookup the specified template by link.
087: * Returns null if the template cannot be found.
088: *
089: * NOTE: for themes we enforce the rule that
090: * Theme.link == Theme.name
091: *
092: * So this lookup is basically the same as lookup by name.
093: */
094: public ThemeTemplate getTemplateByLink(String link) {
095: return (ThemeTemplate) this .templates.get(link);
096: }
097:
098: /**
099: * Set the value for a given template name.
100: */
101: public void setTemplate(String name, ThemeTemplate template) {
102: this .templates.put(name, template);
103: }
104:
105: /**
106: * Check if this Theme contains the named template.
107: * Returns true if the template exists, false otherwise.
108: */
109: public boolean hasTemplate(String name) {
110: return this .templates.containsKey(name);
111: }
112:
113: /**
114: * Get the collection of all resources associated with this Theme.
115: *
116: * It is assured that the resources are returned sorted by pathname.
117: */
118: public List getResources() {
119:
120: // make sure resources are sorted.
121: List myResources = new ArrayList(this .resources.values());
122: Collections.sort(myResources);
123:
124: return myResources;
125: }
126:
127: /**
128: * Lookup the specified resource by path.
129: * Returns null if the resource cannot be found.
130: */
131: public File getResource(String path) {
132: return (File) this .resources.get(path);
133: }
134:
135: /**
136: * Set the value for a given resource path.
137: */
138: public void setResource(String path, File resource) {
139: this .resources.put(path, resource);
140: }
141:
142: /**
143: * Check if this Theme contains the named resource.
144: * Returns true if the resource exists, false otherwise.
145: */
146: public boolean hasResource(String path) {
147: return this .resources.containsKey(path);
148: }
149:
150: public String getId() {
151: return id;
152: }
153:
154: public void setId(String id) {
155: this .id = id;
156: }
157:
158: public String getName() {
159: return name;
160: }
161:
162: public void setName(String name) {
163: this .name = name;
164: }
165:
166: public String getDescription() {
167: return description;
168: }
169:
170: public void setDescription(String description) {
171: this .description = description;
172: }
173:
174: public String getAuthor() {
175: return author;
176: }
177:
178: public void setAuthor(String author) {
179: this .author = author;
180: }
181:
182: public String getLastEditor() {
183: return lastEditor;
184: }
185:
186: public void setLastEditor(String lastEditor) {
187: this .lastEditor = lastEditor;
188: }
189:
190: public Date getLastModified() {
191: return lastModified;
192: }
193:
194: public void setLastModified(Date lastModified) {
195: this .lastModified = lastModified;
196: }
197:
198: public boolean isEnabled() {
199: return enabled;
200: }
201:
202: public void setEnabled(boolean enabled) {
203: this .enabled = enabled;
204: }
205:
206: public String toString() {
207: StringBuffer sb = new StringBuffer();
208: sb.append(name);
209: sb.append("\n");
210:
211: Iterator it = this .templates.values().iterator();
212: while (it.hasNext()) {
213: sb.append(it.next());
214: sb.append("\n");
215: }
216:
217: return sb.toString();
218:
219: }
220:
221: }
|