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: package org.apache.roller.pojos;
019:
020: import java.io.File;
021: import java.lang.reflect.AccessibleObject;
022: import java.lang.reflect.Field;
023: import java.math.BigDecimal;
024: import java.util.Arrays;
025: import java.util.List;
026:
027: import org.apache.commons.lang.StringUtils;
028: import org.apache.roller.RollerException;
029: import org.apache.roller.business.Roller;
030: import org.apache.roller.business.RollerFactory;
031: import org.apache.roller.util.PojoUtil;
032:
033: /**
034: * Configuration object for Roller. Reads and writes roller-config.xml.
035: * RollerConfig extends Struts ActionForm so that it can be extended by
036: * RollerConfigForm in the administrator pages.
037: * <p />
038: * This is where you set default Roller configuration values.
039: *
040: * @ejb:bean name="RollerConfigData"
041: * @struts.form include-all="true"
042: * @hibernate.class lazy="false" table="rollerconfig"
043: */
044: public class RollerConfigData extends
045: org.apache.roller.pojos.PersistentObject implements
046: java.io.Serializable {
047: static final long serialVersionUID = -6354583200913127875L;
048:
049: protected java.lang.String id = null;
050:
051: /**
052: * Roller database version.
053: */
054: protected String mDatabaseVersion = "995"; // 1.0 will be '1000'
055:
056: /**
057: * Absolute URL for site, for cases where infered absolute URL doesn't work.
058: */
059: protected String mAbsoluteURL = null;
060:
061: /**
062: * Should Roller cache return RSS pages.
063: */
064: protected Boolean mRssUseCache = Boolean.FALSE;
065:
066: /**
067: * Duration to cache RSS pages (in seconds).
068: */
069: protected Integer mRssCacheTime = new Integer(3000);
070:
071: /**
072: * Does Roller allow the creation of new users.
073: */
074: protected Boolean mNewUserAllowed = Boolean.TRUE;
075:
076: /**
077: * @deprecated Admins now indicated by roles in userroles table.
078: */
079: protected String mAdminUsers = "admin";
080:
081: /**
082: * Where to get Themes presented to new users.
083: */
084: protected String mUserThemes = "/themes";
085:
086: /**
087: * List of "editor pages" for the Weblog entry editor
088: * seperated with commas.
089: */
090: protected String mEditorPages = "editor-text.jsp,editor-text-js.jsp,editor-rte.jsp,editor-dhtml.jsp,editor-ekit.jsp,editor-wiki-js.jsp";
091:
092: /**
093: * Dis/enble RSS aggregation capabilities.
094: */
095: protected Boolean mEnableAggregator = Boolean.FALSE;
096:
097: /**
098: * Are file uploads enabled.
099: */
100: protected Boolean mUploadEnabled = Boolean.TRUE;
101:
102: /**
103: * The maximum size of each user's upload directory.
104: */
105: protected BigDecimal mUploadMaxDirMB = new BigDecimal("2");
106:
107: /**
108: * The maximum size allowed per uploaded file.
109: */
110: protected BigDecimal mUploadMaxFileMB = new BigDecimal(".5");
111:
112: /**
113: * List of permitted file extensions (not including the "dot")
114: * seperated with commas.
115: * This attribute is mutually exclusive with uploadForbid.
116: */
117: protected String mUploadAllow = "";
118:
119: /**
120: * List of forbidden file extensions (not including the "dot")
121: * seperated with commas.
122: * This attribute is mutually exclusive with uploadAllow.
123: */
124: protected String mUploadForbid = "";
125:
126: /**
127: * Directory where uploaded files will be stored.
128: * May end with a slash. Optional, this value will
129: * default to RollerContext.USER_RESOURCES. If specified,
130: * should be a full path on the system harddrive or
131: * relative to the WebApp.
132: */
133: protected String mUploadDir = "";
134:
135: /**
136: * The path from which the webserver will serve upload files.
137: * This values must not end in a slash.
138: */
139: protected String uploadPath = "/resources";
140:
141: protected Boolean mMemDebug = Boolean.FALSE;
142:
143: /**
144: * Determines if the Comment page will "autoformat"
145: * comments. That is, replace carriage-returns with <br />.
146: */
147: protected Boolean mAutoformatComments = Boolean.FALSE;
148:
149: /**
150: * Determines if the Comment page will escape html in comments.
151: */
152: protected Boolean mEscapeCommentHtml = Boolean.FALSE;
153:
154: /**
155: * Determines if e-mailing comments is enabled.
156: */
157: protected Boolean mEmailComments = Boolean.FALSE;
158:
159: /**
160: * Enable linkback extraction.
161: */
162: protected Boolean mEnableLinkback = Boolean.FALSE;
163:
164: /**
165: * Name of this site
166: */
167: protected String mSiteName = "Roller-based Site";
168:
169: /**
170: * Description of this site
171: */
172: protected String mSiteDescription = "Roller-based Site";
173:
174: /**
175: * Site administrator's email address
176: */
177: protected String mEmailAddress = "";
178:
179: /**
180: * Lucene index directory
181: */
182: protected String mIndexDir = "${user.home}" + File.separator
183: + "roller-index";
184:
185: /**
186: * Flag for encrypting passwords
187: */
188: protected Boolean mEncryptPasswords = Boolean.FALSE;
189:
190: protected String mAlgorithm = "SHA";
191:
192: /**
193: * Comma-delimited list of "words" for filtering referrer spam.
194: */
195: protected String mRefererSpamWords = "";
196:
197: //-------------------------------------- begin requisite getters & setters
198:
199: /**
200: * Not remote since primary key may be extracted by other means.
201: *
202: * @struts.validator type="required" msgkey="errors.required"
203: * @ejb:persistent-field
204: * @hibernate.id column="id"
205: * generator-class="uuid.hex" unsaved-value="null"
206: */
207: public String getId() {
208: return this .id;
209: }
210:
211: /** @ejb:persistent-field */
212: public void setId(String id) {
213: this .id = id;
214: }
215:
216: /**
217: * @ejb:persistent-field
218: * @hibernate.property column="absoluteurl" non-null="false" unique="false"
219: */
220: public String getAbsoluteURL() {
221: return mAbsoluteURL;
222: }
223:
224: /** @ejb:persistent-field */
225: public void setAbsoluteURL(String string) {
226: mAbsoluteURL = string;
227: }
228:
229: /**
230: * @ejb:persistent-field
231: * @hibernate.property column="rssusecache" non-null="true" unique="false"
232: */
233: public Boolean getRssUseCache() {
234: return mRssUseCache;
235: }
236:
237: /** @ejb:persistent-field */
238: public void setRssUseCache(Boolean use) {
239: mRssUseCache = use;
240: }
241:
242: /**
243: * @ejb:persistent-field
244: * @hibernate.property column="rsscachetime" non-null="true" unique="false"
245: */
246: public Integer getRssCacheTime() {
247: return mRssCacheTime;
248: }
249:
250: /** @ejb:persistent-field */
251: public void setRssCacheTime(Integer cacheTime) {
252: mRssCacheTime = cacheTime;
253: }
254:
255: /**
256: * @ejb:persistent-field
257: * @hibernate.property column="newuserallowed" non-null="true" unique="false"
258: */
259: public Boolean getNewUserAllowed() {
260: return mNewUserAllowed;
261: }
262:
263: /** @ejb:persistent-field */
264: public void setNewUserAllowed(Boolean use) {
265: mNewUserAllowed = use;
266: }
267:
268: /**
269: * @deprecated Admins now indicated by roles in userroles table.
270: */
271: public String getAdminUsers() {
272: return mAdminUsers;
273: }
274:
275: /**
276: * @deprecated Admins now indicated by roles in userroles table.
277: */
278: public void setAdminUsers(String _adminUsers) {
279: mAdminUsers = _adminUsers;
280: }
281:
282: /**
283: * @ejb:persistent-field
284: * @hibernate.property column="userthemes" non-null="true" unique="false"
285: */
286: public String getUserThemes() {
287: return mUserThemes;
288: }
289:
290: /** @ejb:persistent-field */
291: public void setUserThemes(String str) {
292: mUserThemes = str;
293: }
294:
295: /**
296: * @ejb:persistent-field
297: * @hibernate.property column="editorpages" non-null="false" unique="false"
298: */
299: public String getEditorPages() {
300: return mEditorPages;
301: }
302:
303: /** @ejb:persistent-field */
304: public void setEditorPages(String _editorPages) {
305: mEditorPages = _editorPages;
306: }
307:
308: /**
309: * @ejb:persistent-field
310: * @hibernate.property column="enableaggregator" non-null="true" unique="false"
311: */
312: public Boolean getEnableAggregator() {
313: return mEnableAggregator;
314: }
315:
316: /** @ejb:persistent-field */
317: public void setEnableAggregator(Boolean use) {
318: mEnableAggregator = use;
319: }
320:
321: /**
322: * @ejb:persistent-field
323: * @hibernate.property column="uploadenabled" non-null="true" unique="false"
324: */
325: public Boolean getUploadEnabled() {
326: return mUploadEnabled;
327: }
328:
329: /** @ejb:persistent-field */
330: public void setUploadEnabled(Boolean use) {
331: mUploadEnabled = use;
332: }
333:
334: /**
335: * @ejb:persistent-field
336: * @hibernate.property column="uploadmaxdirmb"
337: * non-null="true" unique="false" type="big_decimal"
338: */
339: public BigDecimal getUploadMaxDirMB() {
340: return mUploadMaxDirMB;
341: }
342:
343: /** @ejb:persistent-field */
344: public void setUploadMaxDirMB(BigDecimal use) {
345: mUploadMaxDirMB = use;
346: }
347:
348: /**
349: * @ejb:persistent-field
350: * @hibernate.property column="uploadmaxfilemb"
351: * non-null="true" unique="false" type="big_decimal"
352: */
353: public BigDecimal getUploadMaxFileMB() {
354: return mUploadMaxFileMB;
355: }
356:
357: /** @ejb:persistent-field */
358: public void setUploadMaxFileMB(BigDecimal use) {
359: mUploadMaxFileMB = use;
360: }
361:
362: /**
363: * @ejb:persistent-field
364: * @hibernate.property column="uploadallow" non-null="true" unique="false"
365: */
366: public String getUploadAllow() {
367: return mUploadAllow;
368: }
369:
370: /** @ejb:persistent-field */
371: public void setUploadAllow(String _uploadAllow) {
372: mUploadAllow = _uploadAllow;
373: }
374:
375: /**
376: * @ejb:persistent-field
377: * @hibernate.property column="uploadforbid" non-null="true" unique="false"
378: */
379: public String getUploadForbid() {
380: return mUploadForbid;
381: }
382:
383: /** @ejb:persistent-field */
384: public void setUploadForbid(String _uploadForbid) {
385: mUploadForbid = _uploadForbid;
386: }
387:
388: /**
389: * @ejb:persistent-field
390: * @hibernate.property column="uploaddir" non-null="true" unique="false"
391: */
392: public String getUploadDir() {
393: return mUploadDir;
394: }
395:
396: /** @ejb:persistent-field */
397: public void setUploadDir(String str) {
398: mUploadDir = str;
399: }
400:
401: /**
402: * @ejb:persistent-field
403: * @hibernate.property column="uploadpath" non-null="true" unique="false"
404: */
405: public String getUploadPath() {
406: return uploadPath;
407: }
408:
409: /** @ejb:persistent-field */
410: public void setUploadPath(String str) {
411: uploadPath = str;
412: }
413:
414: /**
415: * @ejb:persistent-field
416: * @hibernate.property column="memdebug" non-null="true" unique="false"
417: */
418: public Boolean getMemDebug() {
419: return mMemDebug;
420: }
421:
422: /**
423: * Set memory debugging on or off.
424: * @param mMemDebug The mMemDebug to set
425: * @ejb:persistent-field
426: */
427: public void setMemDebug(Boolean memDebug) {
428: mMemDebug = memDebug;
429: }
430:
431: /**
432: * @ejb:persistent-field
433: * @hibernate.property column="autoformatcomments" non-null="true" unique="false"
434: */
435: public Boolean getAutoformatComments() {
436: return mAutoformatComments;
437: }
438:
439: /** @ejb:persistent-field */
440: public void setAutoformatComments(Boolean value) {
441: mAutoformatComments = value;
442: }
443:
444: /**
445: * @ejb:persistent-field
446: * @hibernate.property column="escapecommenthtml" non-null="true" unique="false"
447: */
448: public Boolean getEscapeCommentHtml() {
449: return mEscapeCommentHtml;
450: }
451:
452: /** @ejb:persistent-field */
453: public void setEscapeCommentHtml(Boolean value) {
454: mEscapeCommentHtml = value;
455: }
456:
457: /**
458: * Does website allow Should Comments be emailed to participants?
459: *
460: * @ejb:persistent-field
461: * @hibernate.property column="emailcomments" non-null="true" unique="false"
462: */
463: public Boolean getEmailComments() {
464: return mEmailComments;
465: }
466:
467: /**
468: * @ejb:persistent-field
469: */
470: public void setEmailComments(Boolean emailComments) {
471: this .mEmailComments = emailComments;
472: }
473:
474: /**
475: * Enable linkback.
476: * @ejb:persistent-field
477: * @hibernate.property column="enablelinkback" non-null="true" unique="false"
478: */
479: public Boolean getEnableLinkback() {
480: return mEnableLinkback;
481: }
482:
483: /**
484: * Enable linkback.
485: * @ejb:persistent-field
486: */
487: public void setEnableLinkback(Boolean b) {
488: mEnableLinkback = b;
489: }
490:
491: /**
492: * @ejb:persistent-field
493: * @hibernate.property column="sitedescription" non-null="false" unique="false"
494: */
495: public String getSiteDescription() {
496: return mSiteDescription;
497: }
498:
499: /**
500: * @param string
501: * @ejb:persistent-field
502: */
503: public void setSiteDescription(String string) {
504: mSiteDescription = string;
505: }
506:
507: /**
508: * @ejb:persistent-field
509: * @hibernate.property column="sitename" non-null="false" unique="false"
510: */
511: public String getSiteName() {
512: return mSiteName;
513: }
514:
515: /**
516: * @param string
517: * @ejb:persistent-field
518: */
519: public void setSiteName(String string) {
520: mSiteName = string;
521: }
522:
523: /**
524: * @ejb:persistent-field
525: * @hibernate.property column="emailaddress" non-null="false" unique="false"
526: */
527: public String getEmailAddress() {
528: return mEmailAddress;
529: }
530:
531: /**
532: * @param string
533: * @ejb:persistent-field
534: */
535: public void setEmailAddress(String emailAddress) {
536: mEmailAddress = emailAddress;
537: }
538:
539: /**
540: * @ejb:persistent-field
541: * @hibernate.property column="indexdir" non-null="false" unique="false"
542: */
543: public String getIndexDir() {
544:
545: return mIndexDir;
546: }
547:
548: /**
549: * @param the new index directory
550: * @ejb:persistent-field
551: */
552: public void setIndexDir(String indexDir) {
553: mIndexDir = indexDir;
554: }
555:
556: /**
557: * @ejb:persistent-field
558: * @hibernate.property column="encryptpasswords" non-null="true" unique="false"
559: */
560: public Boolean getEncryptPasswords() {
561: return mEncryptPasswords;
562: }
563:
564: /** @ejb:persistent-field */
565: public void setEncryptPasswords(Boolean value) {
566: mEncryptPasswords = value;
567: }
568:
569: /**
570: * @ejb:persistent-field
571: * @hibernate.property column="algorithm" non-null="false" unique="false"
572: */
573: public String getAlgorithm() {
574:
575: return mAlgorithm;
576: }
577:
578: /**
579: * @param the new algorithm for encrypting passwords
580: * @ejb:persistent-field
581: */
582: public void setAlgorithm(String algorithm) {
583: mAlgorithm = algorithm;
584: }
585:
586: /**
587: * @return Returns the mDatabaseVersion.
588: * @hibernate.property column="dbversion" non-null="false" unique="false"
589: */
590: public String getDatabaseVersion() {
591: return mDatabaseVersion;
592: }
593:
594: /**
595: * @param databaseVersion The mDatabaseVersion to set.
596: * @ejb:persistent-field
597: */
598: public void setDatabaseVersion(String databaseVersion) {
599: mDatabaseVersion = databaseVersion;
600: }
601:
602: /**
603: * @return Returns the mRefererSpamWords.
604: * @hibernate.property column="refspamwords" non-null="false" unique="false"
605: */
606: public String getRefererSpamWords() {
607: return this .mRefererSpamWords;
608: }
609:
610: /**
611: * @param refererSpamWords The mRefererSpamWords to set.
612: * @ejb:persistent-field
613: */
614: public void setRefererSpamWords(String refererSpamWords) {
615: this .mRefererSpamWords = refererSpamWords;
616: }
617:
618: //---------------------------------------- end requisite getters & setters
619:
620: /**
621: * Convenience method for getAdminUsers.
622: **/
623: public String[] adminUsersArray() {
624: return StringUtils.split(StringUtils
625: .deleteWhitespace(mAdminUsers), ",");
626: }
627:
628: /**
629: * Convenience method for getEditorPages.
630: **/
631: public List getEditorPagesList() {
632: return Arrays.asList(StringUtils.split(StringUtils
633: .deleteWhitespace(mEditorPages), ","));
634: }
635:
636: /**
637: * Convenience method for getUploadAllow.
638: **/
639: public String[] uploadAllowArray() {
640: return StringUtils.split(StringUtils
641: .deleteWhitespace(mUploadAllow), ",");
642: }
643:
644: /**
645: * Convenience method for getUploadForbid.
646: **/
647: public String[] uploadForbidArray() {
648: return StringUtils.split(StringUtils
649: .deleteWhitespace(mUploadForbid), ",");
650: }
651:
652: /**
653: * Convenience method for getRefererSpamWords.
654: **/
655: public String[] refererSpamWordsArray() {
656: return StringUtils.split(StringUtils
657: .deleteWhitespace(mRefererSpamWords), ",");
658: }
659:
660: public void updateValues(RollerConfigData child) {
661: this .mAbsoluteURL = child.getAbsoluteURL();
662: this .mRssUseCache = child.getRssUseCache();
663: this .mRssCacheTime = child.getRssCacheTime();
664: this .mNewUserAllowed = child.getNewUserAllowed();
665: this .mAdminUsers = child.getAdminUsers();
666: this .mDatabaseVersion = child.getDatabaseVersion();
667: this .mUserThemes = child.getUserThemes();
668: this .mEditorPages = child.getEditorPages();
669: this .mEnableAggregator = child.getEnableAggregator();
670: this .mUploadEnabled = child.getUploadEnabled();
671: this .mUploadMaxDirMB = child.getUploadMaxDirMB();
672: this .mUploadMaxFileMB = child.getUploadMaxFileMB();
673: this .mUploadAllow = child.getUploadAllow();
674: this .mUploadForbid = child.getUploadForbid();
675: this .mUploadDir = child.getUploadDir();
676: this .uploadPath = child.getUploadPath();
677: this .mMemDebug = child.getMemDebug();
678: this .mAutoformatComments = child.getAutoformatComments();
679: this .mEscapeCommentHtml = child.getEscapeCommentHtml();
680: this .mEmailComments = child.getEmailComments();
681: this .mEnableLinkback = child.getEnableLinkback();
682: this .mSiteName = child.getSiteName();
683: this .mSiteDescription = child.getSiteDescription();
684: this .mEmailAddress = child.getEmailAddress();
685: this .mIndexDir = child.getIndexDir();
686: this .mEncryptPasswords = child.getEncryptPasswords();
687: this .mAlgorithm = child.getAlgorithm();
688: this .mRefererSpamWords = child.getRefererSpamWords();
689: }
690:
691: /** nice output for debugging */
692: public String toString() {
693: StringBuffer buf = new StringBuffer();
694: buf.append("RollerConfig \n");
695: Class clazz = getClass();
696: Field[] fields = clazz.getDeclaredFields();
697:
698: try {
699: AccessibleObject.setAccessible(fields, true);
700: for (int i = 0; i < fields.length; i++) {
701: buf.append("\t[" + fields[i].getName() + "="
702: + fields[i].get(this ) + "], \n");
703: }
704: } catch (Exception e) {
705: // ignored!
706: }
707:
708: return buf.toString();
709: }
710:
711: public void setData(PersistentObject vo) {
712: if (vo instanceof RollerConfigData) {
713: this .id = ((RollerConfigData) vo).id;
714: updateValues((RollerConfigData) vo);
715: }
716: }
717:
718: public boolean equals(Object pOther) {
719: if (pOther instanceof WebsiteData) {
720: RollerConfigData lTest = (RollerConfigData) pOther;
721: boolean lEquals = true;
722:
723: lEquals = PojoUtil.equals(lEquals, this .id, lTest.id);
724: lEquals = PojoUtil.equals(lEquals, this .mAbsoluteURL, lTest
725: .getAbsoluteURL());
726: lEquals = PojoUtil.equals(lEquals, this .mRssUseCache, lTest
727: .getRssUseCache());
728: lEquals = PojoUtil.equals(lEquals, this .mRssCacheTime,
729: lTest.getRssCacheTime());
730: lEquals = PojoUtil.equals(lEquals, this .mNewUserAllowed,
731: lTest.getNewUserAllowed());
732: lEquals = PojoUtil.equals(lEquals, this .mAdminUsers, lTest
733: .getAdminUsers());
734: lEquals = PojoUtil.equals(lEquals, this .mUserThemes, lTest
735: .getUserThemes());
736: lEquals = PojoUtil.equals(lEquals, this .mEditorPages, lTest
737: .getEditorPages());
738: lEquals = PojoUtil.equals(lEquals, this .mEnableAggregator,
739: lTest.getEnableAggregator());
740: lEquals = PojoUtil.equals(lEquals, this .mUploadEnabled,
741: lTest.getUploadEnabled());
742: lEquals = PojoUtil.equals(lEquals, this .mUploadMaxDirMB,
743: lTest.getUploadMaxDirMB());
744: lEquals = PojoUtil.equals(lEquals, this .mUploadMaxFileMB,
745: lTest.getUploadMaxFileMB());
746: lEquals = PojoUtil.equals(lEquals, this .mUploadAllow, lTest
747: .getUploadAllow());
748: lEquals = PojoUtil.equals(lEquals, this .mUploadForbid,
749: lTest.getUploadForbid());
750: lEquals = PojoUtil.equals(lEquals, this .mUploadDir, lTest
751: .getUploadDir());
752: lEquals = PojoUtil.equals(lEquals, this .uploadPath, lTest
753: .getUploadPath());
754: lEquals = PojoUtil.equals(lEquals, this .mMemDebug, lTest
755: .getMemDebug());
756: lEquals = PojoUtil.equals(lEquals,
757: this .mAutoformatComments, lTest
758: .getAutoformatComments());
759: lEquals = PojoUtil.equals(lEquals, this .mEscapeCommentHtml,
760: lTest.getEscapeCommentHtml());
761: lEquals = PojoUtil.equals(lEquals, this .mEmailComments,
762: lTest.getEmailComments());
763: lEquals = PojoUtil.equals(lEquals, this .mEnableLinkback,
764: lTest.getEnableLinkback());
765: lEquals = PojoUtil.equals(lEquals, this .mSiteName, lTest
766: .getSiteName());
767: lEquals = PojoUtil.equals(lEquals, this .mSiteDescription,
768: lTest.getSiteDescription());
769: lEquals = PojoUtil.equals(lEquals, this .mEmailAddress,
770: lTest.getEmailAddress());
771: lEquals = PojoUtil.equals(lEquals, this .mIndexDir, lTest
772: .getIndexDir());
773: lEquals = PojoUtil.equals(lEquals, this .mEncryptPasswords,
774: lTest.getEncryptPasswords());
775: lEquals = PojoUtil.equals(lEquals, this .mAlgorithm, lTest
776: .getAlgorithm());
777: lEquals = PojoUtil.equals(lEquals, this .mRefererSpamWords,
778: lTest.getRefererSpamWords());
779:
780: return lEquals;
781: } else {
782: return false;
783: }
784: }
785:
786: public int hashCode() {
787: return super.hashCode();
788: }
789:
790: }
|