KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > blojsom > blog > database > DatabaseBlog


1 /**
2  * Copyright (c) 2003-2006, David A. Czarnecki
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the
9  * following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11  * following disclaimer in the documentation and/or other materials provided with the distribution.
12  * Neither the name of "David A. Czarnecki" and "blojsom" nor the names of its contributors may be used to
13  * endorse or promote products derived from this software without specific prior written permission.
14  * Products derived from this software may not be called "blojsom", nor may "blojsom" appear in their name,
15  * without prior written permission of David A. Czarnecki.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
18  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
21  * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */

31 package org.blojsom.blog.database;
32
33 import org.blojsom.blog.Blog;
34 import org.blojsom.util.BlojsomConstants;
35 import org.blojsom.util.BlojsomUtils;
36
37 import java.io.Serializable JavaDoc;
38 import java.util.Collections JavaDoc;
39 import java.util.Locale JavaDoc;
40 import java.util.Map JavaDoc;
41 import java.security.MessageDigest JavaDoc;
42 import java.security.NoSuchAlgorithmException JavaDoc;
43
44 /**
45  * DatabaseBlog
46  *
47  * @author David Czarnecki
48  * @since blojsom 3.0
49  * @version $Id: DatabaseBlog.java,v 1.5 2006/09/26 02:55:21 czarneckid Exp $
50  */

51 public class DatabaseBlog implements Blog, Serializable JavaDoc {
52
53     private Integer JavaDoc _id;
54     private String JavaDoc _blogId;
55     private Map JavaDoc _templates;
56     private Map JavaDoc _plugins;
57     private Map JavaDoc _properties;
58
59     /**
60      * Create a new instance of the database blog
61      */

62     public DatabaseBlog() {
63     }
64
65     /**
66      * Retrieve the unique id
67      *
68      * @return Unique ID
69      */

70     public Integer JavaDoc getId() {
71         return _id;
72     }
73
74     /**
75      * Set the id
76      *
77      * @param id Unique ID
78      */

79     public void setId(Integer JavaDoc id) {
80         _id = id;
81     }
82
83     /**
84      * Retrieve the blog ID
85      *
86      * @return Blog ID
87      */

88     public String JavaDoc getBlogId() {
89         return _blogId;
90     }
91
92     /**
93      * Set the blog ID
94      *
95      * @param blogID Blog ID
96      */

97     public void setBlogId(String JavaDoc blogID) {
98         _blogId = blogID;
99     }
100
101     /**
102      * Get a map of the templates
103      *
104      * @return Map of the templates
105      */

106     public Map JavaDoc getTemplates() {
107         return Collections.unmodifiableMap(_templates);
108     }
109
110     /**
111      * Set the templates
112      *
113      * @param templates Map of the templates
114      */

115     public void setTemplates(Map JavaDoc templates) {
116         _templates = templates;
117     }
118
119     /**
120      * Get a map of the plugins
121      *
122      * @return Map of the plugins
123      */

124     public Map JavaDoc getPlugins() {
125         return Collections.unmodifiableMap(_plugins);
126     }
127
128     /**
129      * Set the plugins
130      *
131      * @param plugins Plugins
132      */

133     public void setPlugins(Map JavaDoc plugins) {
134         _plugins = plugins;
135     }
136
137     /**
138      * Get the properties for the blog
139      *
140      * @return Properties for the blog
141      */

142     public Map JavaDoc getProperties() {
143         return _properties;
144     }
145
146     /**
147      * Set the properties for the blog
148      *
149      * @param properties Blog properties
150      */

151     public void setProperties(Map JavaDoc properties) {
152         _properties = properties;
153     }
154
155     /**
156      * Get a named property
157      *
158      * @param property Property name
159      * @return Value of property
160      */

161     public String JavaDoc getProperty(String JavaDoc property) {
162         return (String JavaDoc) _properties.get(property);
163     }
164
165     /**
166      * Get a named property from the blog
167      *
168      * @param property Name
169      * @param fallback Fallback value
170      * @param allowNullBlank Use the fallback property if <code>allowNullBlank</code> is <code>false</code>
171      * @return Value of the property
172      */

173     public String JavaDoc getProperty(String JavaDoc property, String JavaDoc fallback, boolean allowNullBlank) {
174         String JavaDoc value = (String JavaDoc) _properties.get(property);
175
176         if (!allowNullBlank && BlojsomUtils.checkNullOrBlank(value)) {
177             return fallback;
178         }
179
180         return value;
181     }
182
183     /**
184      * Name of the blog
185      *
186      * @return Blog name
187      */

188     public String JavaDoc getBlogName() {
189         return (String JavaDoc) _properties.get(BlojsomConstants.BLOG_NAME_IP);
190     }
191
192     /**
193      * Returns the HTML escaped name of the blog
194      *
195      * @return Name of the blog that has been escaped
196      */

197     public String JavaDoc getEscapedBlogName() {
198         return BlojsomUtils.escapeString((String JavaDoc) _properties.get(BlojsomConstants.BLOG_NAME_IP));
199
200     }
201
202     /**
203      * Description of the blog
204      *
205      * @return Blog description
206      */

207     public String JavaDoc getBlogDescription() {
208         return (String JavaDoc) _properties.get(BlojsomConstants.BLOG_DESCRIPTION_IP);
209     }
210
211     /**
212      * Returns the HTML escaped description of the blog
213      *
214      * @return Description of the blog that has been escaped
215      */

216     public String JavaDoc getEscapedBlogDescription() {
217         return BlojsomUtils.escapeString((String JavaDoc) _properties.get(BlojsomConstants.BLOG_DESCRIPTION_IP));
218     }
219
220     /**
221      * URL for the blog
222      *
223      * @return Blog URL
224      */

225     public String JavaDoc getBlogURL() {
226         return (String JavaDoc) _properties.get(BlojsomConstants.BLOG_URL_IP);
227     }
228
229     /**
230      * Base admin URL for the blog
231      *
232      * @return Blog base admin URL
233      */

234     public String JavaDoc getBlogBaseAdminURL() {
235         return (String JavaDoc) _properties.get(BlojsomConstants.BLOG_BASE_ADMIN_URL_IP);
236     }
237
238     /**
239      * Admin URL for the blog
240      *
241      * @return Blog admin URL
242      */

243     public String JavaDoc getBlogAdminURL() {
244         return (String JavaDoc) _properties.get(BlojsomConstants.BLOG_ADMIN_URL_IP);
245     }
246
247     /**
248      * Base URL for the blog
249      *
250      * @return Blog base URL
251      */

252     public String JavaDoc getBlogBaseURL() {
253         return (String JavaDoc) _properties.get(BlojsomConstants.BLOG_BASE_URL_IP);
254     }
255
256     /**
257      * Language of the blog
258      *
259      * @return Blog language
260      */

261     public String JavaDoc getBlogLanguage() {
262         String JavaDoc language = BlojsomConstants.BLOG_LANGUAGE_DEFAULT;
263
264         if (_properties.containsKey(BlojsomConstants.BLOG_LANGUAGE_IP)) {
265             language = (String JavaDoc) _properties.get(BlojsomConstants.BLOG_LANGUAGE_IP);
266         }
267
268         return language;
269     }
270
271     /**
272      * Country of the blog
273      *
274      * @return Country for the blog
275      */

276     public String JavaDoc getBlogCountry() {
277         String JavaDoc country = BlojsomConstants.BLOG_COUNTRY_DEFAULT;
278
279         if (_properties.containsKey(BlojsomConstants.BLOG_COUNTRY_IP)) {
280             country = (String JavaDoc) _properties.get(BlojsomConstants.BLOG_COUNTRY_IP);
281         }
282
283         return country;
284     }
285
286     /**
287      * Return the number of blog entries to retrieve from the individual categories
288      *
289      * @return Blog entries to retrieve from the individual categories
290      */

291     public int getBlogDisplayEntries() {
292         int displayEntries;
293
294         try {
295             displayEntries = Integer.parseInt((String JavaDoc) _properties.get(BlojsomConstants.BLOG_ENTRIES_DISPLAY_IP));
296         } catch (NumberFormatException JavaDoc e) {
297             displayEntries = BlojsomConstants.BLOG_ENTRIES_DISPLAY_DEFAULT;
298         }
299
300         return displayEntries;
301     }
302
303     /**
304      * Return the blog owner's e-mail address
305      *
306      * @return Blog owner's e-mail
307      */

308     public String JavaDoc getBlogOwnerEmail() {
309         return (String JavaDoc) _properties.get(BlojsomConstants.BLOG_OWNER_EMAIL);
310     }
311
312     /**
313      * Return the blog owner's name
314      *
315      * @return Blog owner's name
316      */

317     public String JavaDoc getBlogOwner() {
318         return (String JavaDoc) _properties.get(BlojsomConstants.BLOG_OWNER);
319     }
320
321     /**
322      * Return whether or not comments are enabled
323      *
324      * @return Whether or not comments are enabled
325      */

326     public Boolean JavaDoc getBlogCommentsEnabled() {
327         return Boolean.valueOf((String JavaDoc) _properties.get(BlojsomConstants.BLOG_COMMENTS_ENABLED_IP));
328     }
329
330     /**
331      * Return whether or not trackbacks are enabled
332      *
333      * @return <code>true</code> if trackbacks are enabled, <code>false</code> otherwise
334      */

335     public Boolean JavaDoc getBlogTrackbacksEnabled() {
336         return Boolean.valueOf((String JavaDoc) _properties.get(BlojsomConstants.BLOG_TRACKBACKS_ENABLED_IP));
337     }
338
339     /**
340      * Return whether or not pingbacks are enabled
341      *
342      * @return <code>true</code> if pingbacks are enabled, <code>false</code> otherwise
343      */

344     public Boolean JavaDoc getBlogPingbacksEnabled() {
345         return Boolean.valueOf((String JavaDoc) _properties.get(BlojsomConstants.BLOG_PINGBACKS_ENABLED_IP));
346     }
347
348     /**
349      * Get whether or not email is enabled
350      *
351      * @return Whether or not email is enabled
352      */

353     public Boolean JavaDoc getBlogEmailEnabled() {
354         return Boolean.valueOf((String JavaDoc) _properties.get(BlojsomConstants.BLOG_EMAIL_ENABLED_IP));
355     }
356
357     /**
358      * Get the default flavor for this blog
359      *
360      * @return Default blog flavor
361      */

362     public String JavaDoc getBlogDefaultFlavor() {
363         String JavaDoc defaultFlavor = BlojsomConstants.DEFAULT_FLAVOR_HTML;
364
365         if (_properties.containsKey(BlojsomConstants.BLOG_DEFAULT_FLAVOR_IP)) {
366             defaultFlavor = (String JavaDoc) _properties.get(BlojsomConstants.BLOG_DEFAULT_FLAVOR_IP);
367         }
368
369         return defaultFlavor;
370     }
371
372     /**
373      * Is linear navigation enabled?
374      *
375      * @return <code>true</code> if linear navigation is enabled, <code>false</code> otherwise
376      */

377     public Boolean JavaDoc getLinearNavigationEnabled() {
378         return Boolean.valueOf((String JavaDoc) _properties.get(BlojsomConstants.LINEAR_NAVIGATION_ENABLED_IP));
379     }
380
381     /**
382      * Is XML-RPC enabled for this blog?
383      *
384      * @return <code>true</code> if XML-RPC is enabled, <code>false</code> otherwise
385      */

386     public Boolean JavaDoc getXmlrpcEnabled() {
387         return Boolean.valueOf((String JavaDoc) _properties.get(BlojsomConstants.XMLRPC_ENABLED_IP));
388     }
389
390     /**
391      * Retrieve the blog administration locale as a String
392      *
393      * @return String of blog administration locale
394      */

395     public String JavaDoc getBlogAdministrationLocaleAsString() {
396         return (String JavaDoc) _properties.get(BlojsomConstants.BLOG_ADMINISTRATION_LOCALE_IP);
397     }
398
399     /**
400      * Retrieve the blog administration locale as a {@link java.util.Locale} object
401      *
402      * @return {@link java.util.Locale} object for blog administration locale
403      */

404     public Locale JavaDoc getBlogAdministrationLocale() {
405         String JavaDoc administrationLocale = (String JavaDoc) _properties.get(BlojsomConstants.BLOG_ADMINISTRATION_LOCALE_IP);
406         if (!BlojsomUtils.checkNullOrBlank(administrationLocale)) {
407             return BlojsomUtils.getLocaleFromString(administrationLocale);
408         } else {
409             return new Locale JavaDoc("en");
410         }
411     }
412
413     /**
414      * Retrive a {@link java.util.Locale} object from the blog's language and country settings
415      *
416      * @return {@link java.util.Locale} object from the blog's language and country settings
417      */

418     public Locale JavaDoc getBlogLocale() {
419         return new Locale JavaDoc(getBlogLanguage(), getBlogCountry());
420     }
421
422     /**
423      * Retrieve whether or not MD5 encrypted passwords are used
424      *
425      * @return <code>true</code> if encrypted passwords are used, <code>false</code> otherwise
426      */

427     public Boolean JavaDoc getUseEncryptedPasswords() {
428         return Boolean.valueOf((String JavaDoc) _properties.get(BlojsomConstants.USE_ENCRYPTED_PASSWORDS));
429     }
430
431     /**
432      * Retrieve the in-use password digest algorithm
433      *
434      * @return Password digest algorithm
435      */

436     public String JavaDoc getDigestAlgorithm() {
437         String JavaDoc digestAlgorithm = BlojsomConstants.DEFAULT_DIGEST_ALGORITHM;
438
439         if (_properties.containsKey(BlojsomConstants.DIGEST_ALGORITHM)) {
440             digestAlgorithm = (String JavaDoc) _properties.get(BlojsomConstants.DIGEST_ALGORITHM);
441         }
442
443         return digestAlgorithm;
444     }
445
446     /**
447      * Set the new name for the blog
448      *
449      * @param blogName Blog name
450      */

451     public void setBlogName(String JavaDoc blogName) {
452         _properties.put(BlojsomConstants.BLOG_NAME_IP, blogName);
453     }
454
455     /**
456      * Set the new description for the blog
457      *
458      * @param blogDescription Blog description
459      */

460     public void setBlogDescription(String JavaDoc blogDescription) {
461         _properties.put(BlojsomConstants.BLOG_DESCRIPTION_IP, blogDescription);
462     }
463
464     /**
465      * Set the new URL for the blog
466      *
467      * @param blogURL Blog URL
468      */

469     public void setBlogURL(String JavaDoc blogURL) {
470         _properties.put(BlojsomConstants.BLOG_URL_IP, blogURL);
471     }
472
473     /**
474      * Set the new admin URL for the blog
475      *
476      * @param blogAdminURL Blog admin URL
477      */

478     public void setAdminBlogURL(String JavaDoc blogAdminURL) {
479         _properties.put(BlojsomConstants.BLOG_ADMIN_URL_IP, blogAdminURL);
480     }
481
482     /**
483      * Set the new base URL for the blog
484      *
485      * @param blogBaseURL Blog base URL
486      */

487     public void setBlogBaseURL(String JavaDoc blogBaseURL) {
488         _properties.put(BlojsomConstants.BLOG_BASE_URL_IP, blogBaseURL);
489     }
490
491     /**
492      * Set the new 2 letter country code for the blog
493      *
494      * @param blogCountry Blog country code
495      */

496     public void setBlogCountry(String JavaDoc blogCountry) {
497         _properties.put(BlojsomConstants.BLOG_COUNTRY_IP, blogCountry);
498     }
499
500     /**
501      * Set the new 2 letter language code for the blog
502      *
503      * @param blogLanguage Blog language code
504      */

505     public void setBlogLanguage(String JavaDoc blogLanguage) {
506         _properties.put(BlojsomConstants.BLOG_LANGUAGE_IP, blogLanguage);
507     }
508
509     /**
510      * Set the number of entries to display at one time, where -1 indicates to display all entries
511      *
512      * @param blogDisplayEntries Blog display entries
513      */

514     public void setBlogDisplayEntries(int blogDisplayEntries) {
515         _properties.put(BlojsomConstants.BLOG_ENTRIES_DISPLAY_IP, Integer.toString(blogDisplayEntries));
516     }
517
518     /**
519      * Set the new blog owner name
520      *
521      * @param blogOwner Blog owner
522      */

523     public void setBlogOwner(String JavaDoc blogOwner) {
524         _properties.put(BlojsomConstants.BLOG_OWNER, blogOwner);
525     }
526
527     /**
528      * Set the new blog owner e-mail address
529      *
530      * @param blogOwnerEmail Blog owner e-mail
531      */

532     public void setBlogOwnerEmail(String JavaDoc blogOwnerEmail) {
533         _properties.put(BlojsomConstants.BLOG_OWNER_EMAIL, blogOwnerEmail);
534     }
535
536     /**
537      * Set whether blog comments are enabled
538      *
539      * @param blogCommentsEnabled <code>true</code> if comments are enabled, <code>false</code> otherwise
540      */

541     public void setBlogCommentsEnabled(Boolean JavaDoc blogCommentsEnabled) {
542         _properties.put(BlojsomConstants.BLOG_COMMENTS_ENABLED_IP, blogCommentsEnabled.toString());
543     }
544
545     /**
546      * Set whether emails are sent on blog comments and trackbacks
547      *
548      * @param blogEmailEnabled <code>true</code> if email of comments and trackbacks is enabled, <code>false</code> otherwise
549      */

550     public void setBlogEmailEnabled(Boolean JavaDoc blogEmailEnabled) {
551         _properties.put(BlojsomConstants.BLOG_EMAIL_ENABLED_IP, blogEmailEnabled.toString());
552     }
553
554     /**
555      * Set whether blog trackbacks are enabled
556      *
557      * @param blogTrackbacksEnabled <code>true</code> if trackbacks are enabled, <code>false</code> otherwise
558      */

559     public void setBlogTrackbacksEnabled(Boolean JavaDoc blogTrackbacksEnabled) {
560         _properties.put(BlojsomConstants.BLOG_TRACKBACKS_ENABLED_IP, blogTrackbacksEnabled.toString());
561     }
562
563     /**
564      * Set whether blog pingbacks are enabled
565      *
566      * @param blogPingbacksEnabled <code>true</code> if pingbacks are enabled, <code>false</code> otherwise
567      */

568     public void setBlogPingbacksEnabled(Boolean JavaDoc blogPingbacksEnabled) {
569         _properties.put(BlojsomConstants.BLOG_PINGBACKS_ENABLED_IP, blogPingbacksEnabled.toString());
570     }
571
572     /**
573      * Set the new default flavor for this blog
574      *
575      * @param blogDefaultFlavor New default blog flavor
576      */

577     public void setBlogDefaultFlavor(String JavaDoc blogDefaultFlavor) {
578         _properties.put(BlojsomConstants.BLOG_DEFAULT_FLAVOR_IP, blogDefaultFlavor);
579     }
580
581     /**
582      * Set whether or not linear navigation should be enabled
583      *
584      * @param linearNavigationEnabled <code>true</code> if linear navigation is enabled, <code>false</code> otherwise
585      */

586     public void setLinearNavigationEnabled(Boolean JavaDoc linearNavigationEnabled) {
587         _properties.put(BlojsomConstants.LINEAR_NAVIGATION_ENABLED_IP, linearNavigationEnabled.toString());
588     }
589
590     /**
591      * Set whether or not XML-RPC is enabled
592      *
593      * @param xmlrpcEnabled <code>true</code> if XML-RPC is enabled, <code>false</code> otherwise
594      */

595     public void setXmlrpcEnabled(Boolean JavaDoc xmlrpcEnabled) {
596         _properties.put(BlojsomConstants.XMLRPC_ENABLED_IP, xmlrpcEnabled.toString());
597     }
598
599     /**
600      * Set the locale used in the administration console
601      *
602      * @param blogAdministrationLocale Locale string of form <code>language_country_variant</code>
603      */

604     public void setBlogAdministrationLocale(String JavaDoc blogAdministrationLocale) {
605         _properties.put(BlojsomConstants.BLOG_ADMINISTRATION_LOCALE_IP, blogAdministrationLocale);
606     }
607
608     /**
609      * Set whether or not MD5 encrypted passwords are used
610      *
611      * @param useEncryptedPasswords <code>true</code> if MD5 passwords are used, <code>false</code> otherwise
612      */

613     public void setUseEncryptedPasswords(Boolean JavaDoc useEncryptedPasswords) {
614         _properties.put(BlojsomConstants.USE_ENCRYPTED_PASSWORDS, useEncryptedPasswords.toString());
615     }
616
617     /**
618      * Set the new admin URL for the blog
619      *
620      * @param blogAdminURL Blog admin URL
621      */

622     public void setBlogAdminURL(String JavaDoc blogAdminURL) {
623         _properties.put(BlojsomConstants.BLOG_ADMIN_URL_IP, blogAdminURL);
624     }
625
626     /**
627      * Set the new base admin URL for the blog
628      *
629      * @param blogBaseAdminURL Blog base admin URL
630      */

631     public void setBlogBaseAdminURL(String JavaDoc blogBaseAdminURL) {
632         _properties.put(BlojsomConstants.BLOG_BASE_ADMIN_URL_IP, blogBaseAdminURL);
633     }
634
635     /**
636      * Set the in-use password digest algorithm
637      *
638      * @param digestAlgorithm Digest algorithm
639      */

640     public void setDigestAlgorithm(String JavaDoc digestAlgorithm) {
641         if (BlojsomUtils.checkNullOrBlank(digestAlgorithm)) {
642             digestAlgorithm = BlojsomConstants.DEFAULT_DIGEST_ALGORITHM;
643         }
644
645         try {
646             MessageDigest.getInstance(digestAlgorithm);
647         } catch (NoSuchAlgorithmException JavaDoc e) {
648             digestAlgorithm = BlojsomConstants.DEFAULT_DIGEST_ALGORITHM;
649         }
650
651         _properties.put(BlojsomConstants.DIGEST_ALGORITHM, digestAlgorithm);
652     }
653
654     /**
655      * Set a property for the blog
656      *
657      * @param name Property name
658      * @param value Property value
659      */

660     public void setProperty(String JavaDoc name, String JavaDoc value) {
661         if (name != null && value != null) {
662             _properties.put(name, value);
663         }
664     }
665 }
666
Popular Tags