KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > meshcms > core > Configuration


1 /*
2  * MeshCMS - A simple CMS based on SiteMesh
3  * Copyright (C) 2004-2007 Luciano Vernaschi
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * You can contact the author at http://www.cromoteca.com
20  * and at info@cromoteca.com
21  */

22
23 package org.meshcms.core;
24
25 import java.io.*;
26
27 /**
28  * Manages the configuration parameters of a website.
29  */

30 public class Configuration implements Serializable {
31   /**
32    * The length of a hour in milliseconds.
33    */

34   public static final long LENGTH_OF_HOUR = 60 * 60 * 1000;
35
36   /**
37    * The length of a day in milliseconds.
38    */

39   public static final long LENGTH_OF_DAY = 24 * LENGTH_OF_HOUR;
40
41   /**
42    * Contains the extensions of files that are visually editable by default.
43    */

44   public static final String JavaDoc[] DEFAULT_VISUAL_EXTENSIONS = {"html", "htm"};
45
46   /**
47    * Value used to disable page caching.
48    */

49   public static final int NO_CACHE = 0;
50
51   /**
52    * Value used to cache pages in memory.
53    */

54   public static final int IN_MEMORY_CACHE = 1;
55
56   /**
57    * Value used to cache pages on disk.
58    */

59   public static final int ON_DISK_CACHE = 2;
60
61   private boolean useAdminTheme;
62   private boolean preventHotlinking;
63   private boolean alwaysRedirectWelcomes;
64   private boolean alwaysDenyDirectoryListings;
65   private boolean hideExceptions;
66   private boolean editorModulesCollapsed;
67   private boolean highQualityThumbnails;
68   private boolean exportCheckDates;
69   private boolean searchMovedPages;
70   private int backupLife;
71   private int statsLength;
72   private int updateInterval;
73   private int cacheType;
74   private String JavaDoc mailServer;
75   private String JavaDoc smtpUsername;
76   private String JavaDoc smtpPassword;
77   private String JavaDoc siteName;
78   private String JavaDoc siteHost;
79   private String JavaDoc siteDescription;
80   private String JavaDoc siteKeywords;
81   private String JavaDoc siteAuthor;
82   private String JavaDoc siteAuthorURL;
83   private String JavaDoc exportBaseURL;
84   private String JavaDoc exportDir;
85   private String JavaDoc exportCommand;
86   private String JavaDoc[] visualExtensions;
87
88   private Configuration() {
89     setUseAdminTheme(true);
90     setPreventHotlinking(false);
91     setAlwaysRedirectWelcomes(true);
92     setAlwaysDenyDirectoryListings(true);
93     setHideExceptions(true);
94     setEditorModulesCollapsed(false);
95     setHighQualityThumbnails(false);
96     setExportCheckDates(true);
97     setSearchMovedPages(false);
98
99     setBackupLife(90);
100     setStatsLength(3);
101     setUpdateInterval(4);
102     setCacheType(ON_DISK_CACHE);
103
104     setMailServer("localhost");
105     setSmtpUsername("");
106     setSmtpPassword("");
107     setSiteAuthor("Luciano Vernaschi");
108     setSiteAuthorURL("http://www.cromoteca.com/");
109     setSiteDescription("MeshCMS is a Content Management System designed to be" +
110         " easy to use. It doesn't require a database and offers easy" +
111         " deployment, management of multiple sites, wysiwyg editing, file" +
112         " manager, themes, modules and a custom tag library.");
113     setSiteHost("www.meshcms.org");
114     setSiteKeywords("meshcms, cms, java, jsp, servlet, content management system");
115     setSiteName("MeshCMS - Open Source Content Management System");
116     setExportBaseURL("");
117     setExportDir("");
118     setExportCommand("");
119
120     setVisualExtensions(DEFAULT_VISUAL_EXTENSIONS);
121   }
122
123   /**
124    * @return true if the default MeshCMS theme is always used for the pages
125    * of the control panel.
126    */

127   public boolean isUseAdminTheme() {
128     return useAdminTheme;
129   }
130
131   /**
132    * Sets if the default MeshCMS theme is always used for the pages
133    * of the control panel.
134    */

135   public void setUseAdminTheme(boolean useAdminTheme) {
136     this.useAdminTheme = useAdminTheme;
137   }
138
139   /**
140    * @return true if the option to prevent hotlinking is enabled.
141    */

142   public boolean isPreventHotlinking() {
143     return preventHotlinking;
144   }
145
146   /**
147    * Enables or disables hotlinking prevention.
148    */

149   public void setPreventHotlinking(boolean preventHotlinking) {
150     this.preventHotlinking = preventHotlinking;
151   }
152
153   /**
154    * @return the minimum time before deleting a backup file,
155    * measured in days.
156    */

157   public int getBackupLife() {
158     return backupLife;
159   }
160
161   /**
162    * Sets the minimum time before deleting a backup file,
163    * measured in days.
164    */

165   public void setBackupLife(int backupLife) {
166     this.backupLife = Math.max(backupLife, 0);
167   }
168
169   /**
170    * @return the length of stats (hit counts) measured in days.
171    */

172   public int getStatsLength() {
173     return statsLength;
174   }
175
176   /**
177    * Sets the length of stats (hit counts) measured in days. Please note that
178    * this value is fixed when the web application is initialized, so if the
179    * value is changed, the new value won't be used until the next restart of the
180    * web application.
181    */

182   public void setStatsLength(int statsLength) {
183     this.statsLength = Math.max(statsLength, 1);
184   }
185
186   /**
187    * @return the minimum interval between two updates of the site map,
188    * measured in hours.
189    */

190   public int getUpdateInterval() {
191     return updateInterval;
192   }
193
194   /**
195    * Sets the minimum interval between two updates of the site map,
196    * measured in hours.
197    */

198   public void setUpdateInterval(int updateInterval) {
199     this.updateInterval = Math.max(updateInterval, 1);
200   }
201
202   /**
203    * @return the type of cache to be used for pages.
204    *
205    * @see #setCacheType
206    */

207   public int getCacheType() {
208     return cacheType;
209   }
210
211   /**
212    * Sets the type of cache to be used for pages. Possible values are
213    * {@link #NO_CACHE}, {@link #IN_MEMORY_CACHE} and {@link #ON_DISK_CACHE}.
214    */

215   public void setCacheType(int cacheType) {
216     this.cacheType = cacheType;
217   }
218
219   /**
220    * @return the name of the mail server (SMTP).
221    */

222   public String JavaDoc getMailServer() {
223     return mailServer;
224   }
225
226   /**
227    * Sets the name of the mail server (SMTP).
228    */

229   public void setMailServer(String JavaDoc mailServer) {
230     this.mailServer = mailServer;
231   }
232
233   /**
234    * @return the SMTP username.
235    */

236   public String JavaDoc getSmtpUsername() {
237     return smtpUsername;
238   }
239
240   /**
241    * Sets the SMTP username.
242    */

243   public void setSmtpUsername(String JavaDoc smtpUsername) {
244     this.smtpUsername = smtpUsername;
245   }
246
247   /**
248    * @return the SMTP password.
249    */

250   public String JavaDoc getSmtpPassword() {
251     return smtpPassword;
252   }
253
254   /**
255    * Sets the SMTP password.
256    */

257   public void setSmtpPassword(String JavaDoc smtpPassword) {
258     this.smtpPassword = smtpPassword;
259   }
260
261   /**
262    * Loads the configuration from file or creates a new configuration with
263    * default values if the file doesn't exist.
264    */

265   public static Configuration load(WebSite webSite) {
266     Configuration c = null;
267
268     try {
269       c = (Configuration) webSite.loadFromXML(webSite.getConfigFilePath());
270     } catch (Exception JavaDoc ex) {}
271
272     if (c == null) {
273       c = new Configuration();
274     }
275
276     return c;
277   }
278
279   /**
280    * Saves the current configuration to file.
281    */

282   public boolean store(WebSite webSite) {
283     return webSite.storeToXML(this, webSite.getConfigFilePath());
284   }
285
286   /**
287    * @return the minimum interval between two updates of the site map,
288    * measured in milliseconds.
289    */

290   public long getUpdateIntervalMillis() {
291     return getUpdateInterval() * LENGTH_OF_HOUR;
292   }
293
294   /**
295    * @return the minimum time before deleting a backup file,
296    * measured in milliseconds.
297    */

298   public long getBackupLifeMillis() {
299     return getBackupLife() * LENGTH_OF_DAY;
300   }
301
302   /**
303    * @return the extensions that denote file types that can be edited
304    * using the wysiwyg editor.
305    */

306   public String JavaDoc[] getVisualExtensions() {
307     return visualExtensions;
308   }
309
310   /**
311    * Sets the extensions that denote file types that can be edited
312    * using the wysiwyg editor.
313    */

314   public void setVisualExtensions(String JavaDoc[] visualExtensions) {
315     this.visualExtensions = visualExtensions;
316   }
317
318   /**
319    * @return the state of the automatic redirection to welcome files.
320    */

321   public boolean isAlwaysRedirectWelcomes() {
322     return alwaysRedirectWelcomes;
323   }
324
325   /**
326    * Enables or disables automatic redirection to welcome files.
327    */

328   public void setAlwaysRedirectWelcomes(boolean alwaysRedirectWelcomes) {
329     this.alwaysRedirectWelcomes = alwaysRedirectWelcomes;
330   }
331
332   /**
333    * @return the state of directory list blocking.
334    */

335   public boolean isAlwaysDenyDirectoryListings() {
336     return alwaysDenyDirectoryListings;
337   }
338
339   /**
340    * Enables or disables blocking of directory listings.
341    */

342   public void setAlwaysDenyDirectoryListings(boolean alwaysDenyDirectoryListings) {
343     this.alwaysDenyDirectoryListings = alwaysDenyDirectoryListings;
344   }
345
346   /**
347    * @return the main host name of this website.
348    */

349   public String JavaDoc getSiteHost() {
350     return siteHost;
351   }
352
353   /**
354    * Sets the main host name of this website.
355    */

356   public void setSiteHost(String JavaDoc siteHost) {
357     this.siteHost = siteHost;
358   }
359
360   /**
361    * @return the website description.
362    */

363   public String JavaDoc getSiteDescription() {
364     return siteDescription;
365   }
366
367   /**
368    * Sets the website description.
369    */

370   public void setSiteDescription(String JavaDoc siteDescription) {
371     this.siteDescription = siteDescription;
372   }
373
374   /**
375    * @return the keywords related to the website.
376    */

377   public String JavaDoc getSiteKeywords() {
378     return siteKeywords;
379   }
380
381   /**
382    * Sets the keywords related to the website.
383    */

384   public void setSiteKeywords(String JavaDoc siteKeywords) {
385     this.siteKeywords = siteKeywords;
386   }
387
388   /**
389    * @return the author name.
390    */

391   public String JavaDoc getSiteAuthor() {
392     return siteAuthor;
393   }
394
395   /**
396    * Sets the author name.
397    */

398   public void setSiteAuthor(String JavaDoc siteAuthor) {
399     this.siteAuthor = siteAuthor;
400   }
401
402   /**
403    * @return the site name.
404    */

405   public String JavaDoc getSiteName() {
406     return siteName;
407   }
408
409   /**
410    * Sets the site name.
411    */

412   public void setSiteName(String JavaDoc siteName) {
413     this.siteName = siteName;
414   }
415
416   /**
417    * @return the author's URL.
418    */

419   public String JavaDoc getSiteAuthorURL() {
420     return siteAuthorURL;
421   }
422
423   /**
424    * Sets the author's URL. Can be a website URL or a mailto. It is expected
425    * to be a full URL.
426    */

427   public void setSiteAuthorURL(String JavaDoc siteAuthorURL) {
428     this.siteAuthorURL = siteAuthorURL;
429   }
430
431   /**
432    * @return the state of exception hiding.
433    */

434   public boolean isHideExceptions() {
435     return hideExceptions;
436   }
437
438   /**
439    * Enables or disables hiding of Java exceptions. If enabled, exception will
440    * be catched and not rethrown.
441    */

442   public void setHideExceptions(boolean hideExceptions) {
443     this.hideExceptions = hideExceptions;
444   }
445
446   /**
447    * @return the state of whether modules are collapsed in the editor.
448    */

449   public boolean isEditorModulesCollapsed() {
450     return editorModulesCollapsed;
451   }
452
453   /**
454    * Sets whether modules are collapsed in the editor or not.
455    */

456   public void setEditorModulesCollapsed(boolean editorModulesCollapsed) {
457     this.editorModulesCollapsed = editorModulesCollapsed;
458   }
459
460   public boolean isHighQualityThumbnails() {
461     return highQualityThumbnails;
462   }
463
464   public void setHighQualityThumbnails(boolean highQualityThumbnails) {
465     this.highQualityThumbnails = highQualityThumbnails;
466   }
467
468   public boolean isExportCheckDates() {
469     return exportCheckDates;
470   }
471
472   public void setExportCheckDates(boolean exportCheckDates) {
473     this.exportCheckDates = exportCheckDates;
474   }
475
476   public String JavaDoc getExportBaseURL() {
477     return exportBaseURL;
478   }
479
480   public void setExportBaseURL(String JavaDoc exportBaseURL) {
481     this.exportBaseURL = exportBaseURL;
482   }
483
484   public String JavaDoc getExportDir() {
485     return exportDir;
486   }
487
488   public void setExportDir(String JavaDoc exportDir) {
489     this.exportDir = exportDir;
490   }
491
492   public String JavaDoc getExportCommand() {
493     return exportCommand;
494   }
495
496   public void setExportCommand(String JavaDoc exportCommand) {
497     this.exportCommand = exportCommand;
498   }
499
500   public boolean isSearchMovedPages() {
501     return searchMovedPages;
502   }
503
504   public void setSearchMovedPages(boolean searchMovedPages) {
505     this.searchMovedPages = searchMovedPages;
506   }
507 }
508
Popular Tags