001: /**
002: * Copyright (c) 2003-2007, David A. Czarnecki
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * Redistributions of source code must retain the above copyright notice, this list of conditions and the
009: * following disclaimer.
010: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
011: * following disclaimer in the documentation and/or other materials provided with the distribution.
012: * Neither the name of "David A. Czarnecki" and "blojsom" nor the names of its contributors may be used to
013: * endorse or promote products derived from this software without specific prior written permission.
014: * Products derived from this software may not be called "blojsom", nor may "blojsom" appear in their name,
015: * without prior written permission of David A. Czarnecki.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
018: * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
019: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
020: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
021: * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
022: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
025: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
026: * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
027: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
028: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
029: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030: */package org.blojsom.blog.database;
031:
032: import org.blojsom.blog.Blog;
033: import org.blojsom.util.BlojsomConstants;
034: import org.blojsom.util.BlojsomUtils;
035:
036: import java.io.Serializable;
037: import java.util.Collections;
038: import java.util.Locale;
039: import java.util.Map;
040: import java.security.MessageDigest;
041: import java.security.NoSuchAlgorithmException;
042:
043: /**
044: * DatabaseBlog
045: *
046: * @author David Czarnecki
047: * @since blojsom 3.0
048: * @version $Id: DatabaseBlog.java,v 1.7 2007/01/17 02:35:16 czarneckid Exp $
049: */
050: public class DatabaseBlog implements Blog, Serializable {
051:
052: private Integer _id;
053: private String _blogId;
054: private Map _templates;
055: private Map _plugins;
056: private Map _properties;
057:
058: /**
059: * Create a new instance of the database blog
060: */
061: public DatabaseBlog() {
062: }
063:
064: /**
065: * Retrieve the unique id
066: *
067: * @return Unique ID
068: */
069: public Integer getId() {
070: return _id;
071: }
072:
073: /**
074: * Set the id
075: *
076: * @param id Unique ID
077: */
078: public void setId(Integer id) {
079: _id = id;
080: }
081:
082: /**
083: * Retrieve the blog ID
084: *
085: * @return Blog ID
086: */
087: public String getBlogId() {
088: return _blogId;
089: }
090:
091: /**
092: * Set the blog ID
093: *
094: * @param blogID Blog ID
095: */
096: public void setBlogId(String blogID) {
097: _blogId = blogID;
098: }
099:
100: /**
101: * Get a map of the templates
102: *
103: * @return Map of the templates
104: */
105: public Map getTemplates() {
106: return Collections.unmodifiableMap(_templates);
107: }
108:
109: /**
110: * Set the templates
111: *
112: * @param templates Map of the templates
113: */
114: public void setTemplates(Map templates) {
115: _templates = templates;
116: }
117:
118: /**
119: * Get a map of the plugins
120: *
121: * @return Map of the plugins
122: */
123: public Map getPlugins() {
124: return Collections.unmodifiableMap(_plugins);
125: }
126:
127: /**
128: * Set the plugins
129: *
130: * @param plugins Plugins
131: */
132: public void setPlugins(Map plugins) {
133: _plugins = plugins;
134: }
135:
136: /**
137: * Get the properties for the blog
138: *
139: * @return Properties for the blog
140: */
141: public Map getProperties() {
142: return _properties;
143: }
144:
145: /**
146: * Set the properties for the blog
147: *
148: * @param properties Blog properties
149: */
150: public void setProperties(Map properties) {
151: _properties = properties;
152: }
153:
154: /**
155: * Get a named property
156: *
157: * @param property Property name
158: * @return Value of property
159: */
160: public String getProperty(String property) {
161: return (String) _properties.get(property);
162: }
163:
164: /**
165: * Get a named property from the blog
166: *
167: * @param property Name
168: * @param fallback Fallback value
169: * @param allowNullBlank Use the fallback property if <code>allowNullBlank</code> is <code>false</code>
170: * @return Value of the property
171: */
172: public String getProperty(String property, String fallback,
173: boolean allowNullBlank) {
174: String value = (String) _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 getBlogName() {
189: return (String) _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 getEscapedBlogName() {
198: return BlojsomUtils.escapeString((String) _properties
199: .get(BlojsomConstants.BLOG_NAME_IP));
200:
201: }
202:
203: /**
204: * Description of the blog
205: *
206: * @return Blog description
207: */
208: public String getBlogDescription() {
209: return (String) _properties
210: .get(BlojsomConstants.BLOG_DESCRIPTION_IP);
211: }
212:
213: /**
214: * Returns the HTML escaped description of the blog
215: *
216: * @return Description of the blog that has been escaped
217: */
218: public String getEscapedBlogDescription() {
219: return BlojsomUtils.escapeString((String) _properties
220: .get(BlojsomConstants.BLOG_DESCRIPTION_IP));
221: }
222:
223: /**
224: * URL for the blog
225: *
226: * @return Blog URL
227: */
228: public String getBlogURL() {
229: return (String) _properties.get(BlojsomConstants.BLOG_URL_IP);
230: }
231:
232: /**
233: * Base admin URL for the blog
234: *
235: * @return Blog base admin URL
236: */
237: public String getBlogBaseAdminURL() {
238: return (String) _properties
239: .get(BlojsomConstants.BLOG_BASE_ADMIN_URL_IP);
240: }
241:
242: /**
243: * Admin URL for the blog
244: *
245: * @return Blog admin URL
246: */
247: public String getBlogAdminURL() {
248: return (String) _properties
249: .get(BlojsomConstants.BLOG_ADMIN_URL_IP);
250: }
251:
252: /**
253: * Base URL for the blog
254: *
255: * @return Blog base URL
256: */
257: public String getBlogBaseURL() {
258: return (String) _properties
259: .get(BlojsomConstants.BLOG_BASE_URL_IP);
260: }
261:
262: /**
263: * Language of the blog
264: *
265: * @return Blog language
266: */
267: public String getBlogLanguage() {
268: String language = BlojsomConstants.BLOG_LANGUAGE_DEFAULT;
269:
270: if (_properties.containsKey(BlojsomConstants.BLOG_LANGUAGE_IP)) {
271: language = (String) _properties
272: .get(BlojsomConstants.BLOG_LANGUAGE_IP);
273: }
274:
275: return language;
276: }
277:
278: /**
279: * Country of the blog
280: *
281: * @return Country for the blog
282: */
283: public String getBlogCountry() {
284: String country = BlojsomConstants.BLOG_COUNTRY_DEFAULT;
285:
286: if (_properties.containsKey(BlojsomConstants.BLOG_COUNTRY_IP)) {
287: country = (String) _properties
288: .get(BlojsomConstants.BLOG_COUNTRY_IP);
289: }
290:
291: return country;
292: }
293:
294: /**
295: * Return the number of blog entries to retrieve from the individual categories
296: *
297: * @return Blog entries to retrieve from the individual categories
298: */
299: public int getBlogDisplayEntries() {
300: int displayEntries;
301:
302: try {
303: displayEntries = Integer.parseInt((String) _properties
304: .get(BlojsomConstants.BLOG_ENTRIES_DISPLAY_IP));
305: } catch (NumberFormatException e) {
306: displayEntries = BlojsomConstants.BLOG_ENTRIES_DISPLAY_DEFAULT;
307: }
308:
309: return displayEntries;
310: }
311:
312: /**
313: * Return the blog owner's e-mail address
314: *
315: * @return Blog owner's e-mail
316: */
317: public String getBlogOwnerEmail() {
318: return (String) _properties
319: .get(BlojsomConstants.BLOG_OWNER_EMAIL);
320: }
321:
322: /**
323: * Return the blog owner's name
324: *
325: * @return Blog owner's name
326: */
327: public String getBlogOwner() {
328: return (String) _properties.get(BlojsomConstants.BLOG_OWNER);
329: }
330:
331: /**
332: * Return whether or not comments are enabled
333: *
334: * @return Whether or not comments are enabled
335: */
336: public Boolean getBlogCommentsEnabled() {
337: return Boolean.valueOf((String) _properties
338: .get(BlojsomConstants.BLOG_COMMENTS_ENABLED_IP));
339: }
340:
341: /**
342: * Return whether or not trackbacks are enabled
343: *
344: * @return <code>true</code> if trackbacks are enabled, <code>false</code> otherwise
345: */
346: public Boolean getBlogTrackbacksEnabled() {
347: return Boolean.valueOf((String) _properties
348: .get(BlojsomConstants.BLOG_TRACKBACKS_ENABLED_IP));
349: }
350:
351: /**
352: * Return whether or not pingbacks are enabled
353: *
354: * @return <code>true</code> if pingbacks are enabled, <code>false</code> otherwise
355: */
356: public Boolean getBlogPingbacksEnabled() {
357: return Boolean.valueOf((String) _properties
358: .get(BlojsomConstants.BLOG_PINGBACKS_ENABLED_IP));
359: }
360:
361: /**
362: * Get whether or not email is enabled
363: *
364: * @return Whether or not email is enabled
365: */
366: public Boolean getBlogEmailEnabled() {
367: return Boolean.valueOf((String) _properties
368: .get(BlojsomConstants.BLOG_EMAIL_ENABLED_IP));
369: }
370:
371: /**
372: * Get the default flavor for this blog
373: *
374: * @return Default blog flavor
375: */
376: public String getBlogDefaultFlavor() {
377: String defaultFlavor = BlojsomConstants.DEFAULT_FLAVOR_HTML;
378:
379: if (_properties
380: .containsKey(BlojsomConstants.BLOG_DEFAULT_FLAVOR_IP)) {
381: defaultFlavor = (String) _properties
382: .get(BlojsomConstants.BLOG_DEFAULT_FLAVOR_IP);
383: }
384:
385: return defaultFlavor;
386: }
387:
388: /**
389: * Is linear navigation enabled?
390: *
391: * @return <code>true</code> if linear navigation is enabled, <code>false</code> otherwise
392: */
393: public Boolean getLinearNavigationEnabled() {
394: return Boolean.valueOf((String) _properties
395: .get(BlojsomConstants.LINEAR_NAVIGATION_ENABLED_IP));
396: }
397:
398: /**
399: * Is XML-RPC enabled for this blog?
400: *
401: * @return <code>true</code> if XML-RPC is enabled, <code>false</code> otherwise
402: */
403: public Boolean getXmlrpcEnabled() {
404: return Boolean.valueOf((String) _properties
405: .get(BlojsomConstants.XMLRPC_ENABLED_IP));
406: }
407:
408: /**
409: * Retrieve the blog administration locale as a String
410: *
411: * @return String of blog administration locale
412: */
413: public String getBlogAdministrationLocaleAsString() {
414: return (String) _properties
415: .get(BlojsomConstants.BLOG_ADMINISTRATION_LOCALE_IP);
416: }
417:
418: /**
419: * Retrieve the blog administration locale as a {@link java.util.Locale} object
420: *
421: * @return {@link java.util.Locale} object for blog administration locale
422: */
423: public Locale getBlogAdministrationLocale() {
424: String administrationLocale = (String) _properties
425: .get(BlojsomConstants.BLOG_ADMINISTRATION_LOCALE_IP);
426: if (!BlojsomUtils.checkNullOrBlank(administrationLocale)) {
427: return BlojsomUtils
428: .getLocaleFromString(administrationLocale);
429: } else {
430: return new Locale("en");
431: }
432: }
433:
434: /**
435: * Retrive a {@link java.util.Locale} object from the blog's language and country settings
436: *
437: * @return {@link java.util.Locale} object from the blog's language and country settings
438: */
439: public Locale getBlogLocale() {
440: return new Locale(getBlogLanguage(), getBlogCountry());
441: }
442:
443: /**
444: * Retrieve whether or not MD5 encrypted passwords are used
445: *
446: * @return <code>true</code> if encrypted passwords are used, <code>false</code> otherwise
447: */
448: public Boolean getUseEncryptedPasswords() {
449: return Boolean.valueOf((String) _properties
450: .get(BlojsomConstants.USE_ENCRYPTED_PASSWORDS));
451: }
452:
453: /**
454: * Retrieve the in-use password digest algorithm
455: *
456: * @return Password digest algorithm
457: */
458: public String getDigestAlgorithm() {
459: String digestAlgorithm = BlojsomConstants.DEFAULT_DIGEST_ALGORITHM;
460:
461: if (_properties.containsKey(BlojsomConstants.DIGEST_ALGORITHM)) {
462: digestAlgorithm = (String) _properties
463: .get(BlojsomConstants.DIGEST_ALGORITHM);
464: }
465:
466: return digestAlgorithm;
467: }
468:
469: /**
470: * Set the new name for the blog
471: *
472: * @param blogName Blog name
473: */
474: public void setBlogName(String blogName) {
475: _properties.put(BlojsomConstants.BLOG_NAME_IP, blogName);
476: }
477:
478: /**
479: * Set the new description for the blog
480: *
481: * @param blogDescription Blog description
482: */
483: public void setBlogDescription(String blogDescription) {
484: _properties.put(BlojsomConstants.BLOG_DESCRIPTION_IP,
485: blogDescription);
486: }
487:
488: /**
489: * Set the new URL for the blog
490: *
491: * @param blogURL Blog URL
492: */
493: public void setBlogURL(String blogURL) {
494: _properties.put(BlojsomConstants.BLOG_URL_IP, blogURL);
495: }
496:
497: /**
498: * Set the new admin URL for the blog
499: *
500: * @param blogAdminURL Blog admin URL
501: */
502: public void setAdminBlogURL(String blogAdminURL) {
503: _properties.put(BlojsomConstants.BLOG_ADMIN_URL_IP,
504: blogAdminURL);
505: }
506:
507: /**
508: * Set the new base URL for the blog
509: *
510: * @param blogBaseURL Blog base URL
511: */
512: public void setBlogBaseURL(String blogBaseURL) {
513: _properties.put(BlojsomConstants.BLOG_BASE_URL_IP, blogBaseURL);
514: }
515:
516: /**
517: * Set the new 2 letter country code for the blog
518: *
519: * @param blogCountry Blog country code
520: */
521: public void setBlogCountry(String blogCountry) {
522: _properties.put(BlojsomConstants.BLOG_COUNTRY_IP, blogCountry);
523: }
524:
525: /**
526: * Set the new 2 letter language code for the blog
527: *
528: * @param blogLanguage Blog language code
529: */
530: public void setBlogLanguage(String blogLanguage) {
531: _properties
532: .put(BlojsomConstants.BLOG_LANGUAGE_IP, blogLanguage);
533: }
534:
535: /**
536: * Set the number of entries to display at one time, where -1 indicates to display all entries
537: *
538: * @param blogDisplayEntries Blog display entries
539: */
540: public void setBlogDisplayEntries(int blogDisplayEntries) {
541: _properties.put(BlojsomConstants.BLOG_ENTRIES_DISPLAY_IP,
542: Integer.toString(blogDisplayEntries));
543: }
544:
545: /**
546: * Set the new blog owner name
547: *
548: * @param blogOwner Blog owner
549: */
550: public void setBlogOwner(String blogOwner) {
551: _properties.put(BlojsomConstants.BLOG_OWNER, blogOwner);
552: }
553:
554: /**
555: * Set the new blog owner e-mail address
556: *
557: * @param blogOwnerEmail Blog owner e-mail
558: */
559: public void setBlogOwnerEmail(String blogOwnerEmail) {
560: _properties.put(BlojsomConstants.BLOG_OWNER_EMAIL,
561: blogOwnerEmail);
562: }
563:
564: /**
565: * Set whether blog comments are enabled
566: *
567: * @param blogCommentsEnabled <code>true</code> if comments are enabled, <code>false</code> otherwise
568: */
569: public void setBlogCommentsEnabled(Boolean blogCommentsEnabled) {
570: _properties.put(BlojsomConstants.BLOG_COMMENTS_ENABLED_IP,
571: blogCommentsEnabled.toString());
572: }
573:
574: /**
575: * Set whether emails are sent on blog comments and trackbacks
576: *
577: * @param blogEmailEnabled <code>true</code> if email of comments and trackbacks is enabled, <code>false</code> otherwise
578: */
579: public void setBlogEmailEnabled(Boolean blogEmailEnabled) {
580: _properties.put(BlojsomConstants.BLOG_EMAIL_ENABLED_IP,
581: blogEmailEnabled.toString());
582: }
583:
584: /**
585: * Set whether blog trackbacks are enabled
586: *
587: * @param blogTrackbacksEnabled <code>true</code> if trackbacks are enabled, <code>false</code> otherwise
588: */
589: public void setBlogTrackbacksEnabled(Boolean blogTrackbacksEnabled) {
590: _properties.put(BlojsomConstants.BLOG_TRACKBACKS_ENABLED_IP,
591: blogTrackbacksEnabled.toString());
592: }
593:
594: /**
595: * Set whether blog pingbacks are enabled
596: *
597: * @param blogPingbacksEnabled <code>true</code> if pingbacks are enabled, <code>false</code> otherwise
598: */
599: public void setBlogPingbacksEnabled(Boolean blogPingbacksEnabled) {
600: _properties.put(BlojsomConstants.BLOG_PINGBACKS_ENABLED_IP,
601: blogPingbacksEnabled.toString());
602: }
603:
604: /**
605: * Set the new default flavor for this blog
606: *
607: * @param blogDefaultFlavor New default blog flavor
608: */
609: public void setBlogDefaultFlavor(String blogDefaultFlavor) {
610: _properties.put(BlojsomConstants.BLOG_DEFAULT_FLAVOR_IP,
611: blogDefaultFlavor);
612: }
613:
614: /**
615: * Set whether or not linear navigation should be enabled
616: *
617: * @param linearNavigationEnabled <code>true</code> if linear navigation is enabled, <code>false</code> otherwise
618: */
619: public void setLinearNavigationEnabled(
620: Boolean linearNavigationEnabled) {
621: _properties.put(BlojsomConstants.LINEAR_NAVIGATION_ENABLED_IP,
622: linearNavigationEnabled.toString());
623: }
624:
625: /**
626: * Set whether or not XML-RPC is enabled
627: *
628: * @param xmlrpcEnabled <code>true</code> if XML-RPC is enabled, <code>false</code> otherwise
629: */
630: public void setXmlrpcEnabled(Boolean xmlrpcEnabled) {
631: _properties.put(BlojsomConstants.XMLRPC_ENABLED_IP,
632: xmlrpcEnabled.toString());
633: }
634:
635: /**
636: * Set the locale used in the administration console
637: *
638: * @param blogAdministrationLocale Locale string of form <code>language_country_variant</code>
639: */
640: public void setBlogAdministrationLocale(
641: String blogAdministrationLocale) {
642: _properties.put(BlojsomConstants.BLOG_ADMINISTRATION_LOCALE_IP,
643: blogAdministrationLocale);
644: }
645:
646: /**
647: * Set whether or not MD5 encrypted passwords are used
648: *
649: * @param useEncryptedPasswords <code>true</code> if MD5 passwords are used, <code>false</code> otherwise
650: */
651: public void setUseEncryptedPasswords(Boolean useEncryptedPasswords) {
652: _properties.put(BlojsomConstants.USE_ENCRYPTED_PASSWORDS,
653: useEncryptedPasswords.toString());
654: }
655:
656: /**
657: * Set the new admin URL for the blog
658: *
659: * @param blogAdminURL Blog admin URL
660: */
661: public void setBlogAdminURL(String blogAdminURL) {
662: _properties.put(BlojsomConstants.BLOG_ADMIN_URL_IP,
663: blogAdminURL);
664: }
665:
666: /**
667: * Set the new base admin URL for the blog
668: *
669: * @param blogBaseAdminURL Blog base admin URL
670: */
671: public void setBlogBaseAdminURL(String blogBaseAdminURL) {
672: _properties.put(BlojsomConstants.BLOG_BASE_ADMIN_URL_IP,
673: blogBaseAdminURL);
674: }
675:
676: /**
677: * Set the in-use password digest algorithm
678: *
679: * @param digestAlgorithm Digest algorithm
680: */
681: public void setDigestAlgorithm(String digestAlgorithm) {
682: if (BlojsomUtils.checkNullOrBlank(digestAlgorithm)) {
683: digestAlgorithm = BlojsomConstants.DEFAULT_DIGEST_ALGORITHM;
684: }
685:
686: try {
687: MessageDigest.getInstance(digestAlgorithm);
688: } catch (NoSuchAlgorithmException e) {
689: digestAlgorithm = BlojsomConstants.DEFAULT_DIGEST_ALGORITHM;
690: }
691:
692: _properties.put(BlojsomConstants.DIGEST_ALGORITHM,
693: digestAlgorithm);
694: }
695:
696: /**
697: * Set a property for the blog
698: *
699: * @param name Property name
700: * @param value Property value
701: */
702: public void setProperty(String name, String value) {
703: if (name != null && value != null) {
704: _properties.put(name, value);
705: }
706: }
707:
708: /**
709: * Remove a property from the blog
710: *
711: * @param name Property name
712: */
713: public void removeProperty(String name) {
714: if (!BlojsomUtils.checkNullOrBlank(name)) {
715: _properties.remove(name);
716: }
717: }
718: }
|