1 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 ; 38 import java.util.Collections ; 39 import java.util.Locale ; 40 import java.util.Map ; 41 import java.security.MessageDigest ; 42 import java.security.NoSuchAlgorithmException ; 43 44 51 public class DatabaseBlog implements Blog, Serializable { 52 53 private Integer _id; 54 private String _blogId; 55 private Map _templates; 56 private Map _plugins; 57 private Map _properties; 58 59 62 public DatabaseBlog() { 63 } 64 65 70 public Integer getId() { 71 return _id; 72 } 73 74 79 public void setId(Integer id) { 80 _id = id; 81 } 82 83 88 public String getBlogId() { 89 return _blogId; 90 } 91 92 97 public void setBlogId(String blogID) { 98 _blogId = blogID; 99 } 100 101 106 public Map getTemplates() { 107 return Collections.unmodifiableMap(_templates); 108 } 109 110 115 public void setTemplates(Map templates) { 116 _templates = templates; 117 } 118 119 124 public Map getPlugins() { 125 return Collections.unmodifiableMap(_plugins); 126 } 127 128 133 public void setPlugins(Map plugins) { 134 _plugins = plugins; 135 } 136 137 142 public Map getProperties() { 143 return _properties; 144 } 145 146 151 public void setProperties(Map properties) { 152 _properties = properties; 153 } 154 155 161 public String getProperty(String property) { 162 return (String ) _properties.get(property); 163 } 164 165 173 public String getProperty(String property, String fallback, 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 188 public String getBlogName() { 189 return (String ) _properties.get(BlojsomConstants.BLOG_NAME_IP); 190 } 191 192 197 public String getEscapedBlogName() { 198 return BlojsomUtils.escapeString((String ) _properties.get(BlojsomConstants.BLOG_NAME_IP)); 199 200 } 201 202 207 public String getBlogDescription() { 208 return (String ) _properties.get(BlojsomConstants.BLOG_DESCRIPTION_IP); 209 } 210 211 216 public String getEscapedBlogDescription() { 217 return BlojsomUtils.escapeString((String ) _properties.get(BlojsomConstants.BLOG_DESCRIPTION_IP)); 218 } 219 220 225 public String getBlogURL() { 226 return (String ) _properties.get(BlojsomConstants.BLOG_URL_IP); 227 } 228 229 234 public String getBlogBaseAdminURL() { 235 return (String ) _properties.get(BlojsomConstants.BLOG_BASE_ADMIN_URL_IP); 236 } 237 238 243 public String getBlogAdminURL() { 244 return (String ) _properties.get(BlojsomConstants.BLOG_ADMIN_URL_IP); 245 } 246 247 252 public String getBlogBaseURL() { 253 return (String ) _properties.get(BlojsomConstants.BLOG_BASE_URL_IP); 254 } 255 256 261 public String getBlogLanguage() { 262 String language = BlojsomConstants.BLOG_LANGUAGE_DEFAULT; 263 264 if (_properties.containsKey(BlojsomConstants.BLOG_LANGUAGE_IP)) { 265 language = (String ) _properties.get(BlojsomConstants.BLOG_LANGUAGE_IP); 266 } 267 268 return language; 269 } 270 271 276 public String getBlogCountry() { 277 String country = BlojsomConstants.BLOG_COUNTRY_DEFAULT; 278 279 if (_properties.containsKey(BlojsomConstants.BLOG_COUNTRY_IP)) { 280 country = (String ) _properties.get(BlojsomConstants.BLOG_COUNTRY_IP); 281 } 282 283 return country; 284 } 285 286 291 public int getBlogDisplayEntries() { 292 int displayEntries; 293 294 try { 295 displayEntries = Integer.parseInt((String ) _properties.get(BlojsomConstants.BLOG_ENTRIES_DISPLAY_IP)); 296 } catch (NumberFormatException e) { 297 displayEntries = BlojsomConstants.BLOG_ENTRIES_DISPLAY_DEFAULT; 298 } 299 300 return displayEntries; 301 } 302 303 308 public String getBlogOwnerEmail() { 309 return (String ) _properties.get(BlojsomConstants.BLOG_OWNER_EMAIL); 310 } 311 312 317 public String getBlogOwner() { 318 return (String ) _properties.get(BlojsomConstants.BLOG_OWNER); 319 } 320 321 326 public Boolean getBlogCommentsEnabled() { 327 return Boolean.valueOf((String ) _properties.get(BlojsomConstants.BLOG_COMMENTS_ENABLED_IP)); 328 } 329 330 335 public Boolean getBlogTrackbacksEnabled() { 336 return Boolean.valueOf((String ) _properties.get(BlojsomConstants.BLOG_TRACKBACKS_ENABLED_IP)); 337 } 338 339 344 public Boolean getBlogPingbacksEnabled() { 345 return Boolean.valueOf((String ) _properties.get(BlojsomConstants.BLOG_PINGBACKS_ENABLED_IP)); 346 } 347 348 353 public Boolean getBlogEmailEnabled() { 354 return Boolean.valueOf((String ) _properties.get(BlojsomConstants.BLOG_EMAIL_ENABLED_IP)); 355 } 356 357 362 public String getBlogDefaultFlavor() { 363 String defaultFlavor = BlojsomConstants.DEFAULT_FLAVOR_HTML; 364 365 if (_properties.containsKey(BlojsomConstants.BLOG_DEFAULT_FLAVOR_IP)) { 366 defaultFlavor = (String ) _properties.get(BlojsomConstants.BLOG_DEFAULT_FLAVOR_IP); 367 } 368 369 return defaultFlavor; 370 } 371 372 377 public Boolean getLinearNavigationEnabled() { 378 return Boolean.valueOf((String ) _properties.get(BlojsomConstants.LINEAR_NAVIGATION_ENABLED_IP)); 379 } 380 381 386 public Boolean getXmlrpcEnabled() { 387 return Boolean.valueOf((String ) _properties.get(BlojsomConstants.XMLRPC_ENABLED_IP)); 388 } 389 390 395 public String getBlogAdministrationLocaleAsString() { 396 return (String ) _properties.get(BlojsomConstants.BLOG_ADMINISTRATION_LOCALE_IP); 397 } 398 399 404 public Locale getBlogAdministrationLocale() { 405 String administrationLocale = (String ) _properties.get(BlojsomConstants.BLOG_ADMINISTRATION_LOCALE_IP); 406 if (!BlojsomUtils.checkNullOrBlank(administrationLocale)) { 407 return BlojsomUtils.getLocaleFromString(administrationLocale); 408 } else { 409 return new Locale ("en"); 410 } 411 } 412 413 418 public Locale getBlogLocale() { 419 return new Locale (getBlogLanguage(), getBlogCountry()); 420 } 421 422 427 public Boolean getUseEncryptedPasswords() { 428 return Boolean.valueOf((String ) _properties.get(BlojsomConstants.USE_ENCRYPTED_PASSWORDS)); 429 } 430 431 436 public String getDigestAlgorithm() { 437 String digestAlgorithm = BlojsomConstants.DEFAULT_DIGEST_ALGORITHM; 438 439 if (_properties.containsKey(BlojsomConstants.DIGEST_ALGORITHM)) { 440 digestAlgorithm = (String ) _properties.get(BlojsomConstants.DIGEST_ALGORITHM); 441 } 442 443 return digestAlgorithm; 444 } 445 446 451 public void setBlogName(String blogName) { 452 _properties.put(BlojsomConstants.BLOG_NAME_IP, blogName); 453 } 454 455 460 public void setBlogDescription(String blogDescription) { 461 _properties.put(BlojsomConstants.BLOG_DESCRIPTION_IP, blogDescription); 462 } 463 464 469 public void setBlogURL(String blogURL) { 470 _properties.put(BlojsomConstants.BLOG_URL_IP, blogURL); 471 } 472 473 478 public void setAdminBlogURL(String blogAdminURL) { 479 _properties.put(BlojsomConstants.BLOG_ADMIN_URL_IP, blogAdminURL); 480 } 481 482 487 public void setBlogBaseURL(String blogBaseURL) { 488 _properties.put(BlojsomConstants.BLOG_BASE_URL_IP, blogBaseURL); 489 } 490 491 496 public void setBlogCountry(String blogCountry) { 497 _properties.put(BlojsomConstants.BLOG_COUNTRY_IP, blogCountry); 498 } 499 500 505 public void setBlogLanguage(String blogLanguage) { 506 _properties.put(BlojsomConstants.BLOG_LANGUAGE_IP, blogLanguage); 507 } 508 509 514 public void setBlogDisplayEntries(int blogDisplayEntries) { 515 _properties.put(BlojsomConstants.BLOG_ENTRIES_DISPLAY_IP, Integer.toString(blogDisplayEntries)); 516 } 517 518 523 public void setBlogOwner(String blogOwner) { 524 _properties.put(BlojsomConstants.BLOG_OWNER, blogOwner); 525 } 526 527 532 public void setBlogOwnerEmail(String blogOwnerEmail) { 533 _properties.put(BlojsomConstants.BLOG_OWNER_EMAIL, blogOwnerEmail); 534 } 535 536 541 public void setBlogCommentsEnabled(Boolean blogCommentsEnabled) { 542 _properties.put(BlojsomConstants.BLOG_COMMENTS_ENABLED_IP, blogCommentsEnabled.toString()); 543 } 544 545 550 public void setBlogEmailEnabled(Boolean blogEmailEnabled) { 551 _properties.put(BlojsomConstants.BLOG_EMAIL_ENABLED_IP, blogEmailEnabled.toString()); 552 } 553 554 559 public void setBlogTrackbacksEnabled(Boolean blogTrackbacksEnabled) { 560 _properties.put(BlojsomConstants.BLOG_TRACKBACKS_ENABLED_IP, blogTrackbacksEnabled.toString()); 561 } 562 563 568 public void setBlogPingbacksEnabled(Boolean blogPingbacksEnabled) { 569 _properties.put(BlojsomConstants.BLOG_PINGBACKS_ENABLED_IP, blogPingbacksEnabled.toString()); 570 } 571 572 577 public void setBlogDefaultFlavor(String blogDefaultFlavor) { 578 _properties.put(BlojsomConstants.BLOG_DEFAULT_FLAVOR_IP, blogDefaultFlavor); 579 } 580 581 586 public void setLinearNavigationEnabled(Boolean linearNavigationEnabled) { 587 _properties.put(BlojsomConstants.LINEAR_NAVIGATION_ENABLED_IP, linearNavigationEnabled.toString()); 588 } 589 590 595 public void setXmlrpcEnabled(Boolean xmlrpcEnabled) { 596 _properties.put(BlojsomConstants.XMLRPC_ENABLED_IP, xmlrpcEnabled.toString()); 597 } 598 599 604 public void setBlogAdministrationLocale(String blogAdministrationLocale) { 605 _properties.put(BlojsomConstants.BLOG_ADMINISTRATION_LOCALE_IP, blogAdministrationLocale); 606 } 607 608 613 public void setUseEncryptedPasswords(Boolean useEncryptedPasswords) { 614 _properties.put(BlojsomConstants.USE_ENCRYPTED_PASSWORDS, useEncryptedPasswords.toString()); 615 } 616 617 622 public void setBlogAdminURL(String blogAdminURL) { 623 _properties.put(BlojsomConstants.BLOG_ADMIN_URL_IP, blogAdminURL); 624 } 625 626 631 public void setBlogBaseAdminURL(String blogBaseAdminURL) { 632 _properties.put(BlojsomConstants.BLOG_BASE_ADMIN_URL_IP, blogBaseAdminURL); 633 } 634 635 640 public void setDigestAlgorithm(String digestAlgorithm) { 641 if (BlojsomUtils.checkNullOrBlank(digestAlgorithm)) { 642 digestAlgorithm = BlojsomConstants.DEFAULT_DIGEST_ALGORITHM; 643 } 644 645 try { 646 MessageDigest.getInstance(digestAlgorithm); 647 } catch (NoSuchAlgorithmException e) { 648 digestAlgorithm = BlojsomConstants.DEFAULT_DIGEST_ALGORITHM; 649 } 650 651 _properties.put(BlojsomConstants.DIGEST_ALGORITHM, digestAlgorithm); 652 } 653 654 660 public void setProperty(String name, String value) { 661 if (name != null && value != null) { 662 _properties.put(name, value); 663 } 664 } 665 } 666 | Popular Tags |