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:
019: package org.apache.roller.ui.rendering.velocity.deprecated;
020:
021: import java.util.ArrayList;
022: import java.util.Calendar;
023: import java.util.Collection;
024: import java.util.Date;
025: import java.util.HashMap;
026: import java.util.Iterator;
027: import java.util.List;
028: import java.util.Map;
029: import java.util.TimeZone;
030: import javax.servlet.http.HttpServletRequest;
031: import org.apache.commons.logging.Log;
032: import org.apache.commons.logging.LogFactory;
033: import org.apache.roller.RollerException;
034: import org.apache.roller.config.RollerRuntimeConfig;
035: import org.apache.roller.business.BookmarkManager;
036: import org.apache.roller.business.referrers.RefererManager;
037: import org.apache.roller.business.RollerFactory;
038: import org.apache.roller.pojos.Template;
039: import org.apache.roller.business.UserManager;
040: import org.apache.roller.business.WeblogManager;
041: import org.apache.roller.pojos.CommentData;
042: import org.apache.roller.pojos.FolderData;
043: import org.apache.roller.pojos.RefererData;
044: import org.apache.roller.pojos.WeblogCategoryData;
045: import org.apache.roller.pojos.WeblogEntryData;
046: import org.apache.roller.pojos.WebsiteData;
047: import org.apache.roller.pojos.wrapper.CommentDataWrapper;
048: import org.apache.roller.pojos.wrapper.FolderDataWrapper;
049: import org.apache.roller.pojos.wrapper.RefererDataWrapper;
050: import org.apache.roller.pojos.wrapper.TemplateWrapper;
051: import org.apache.roller.pojos.wrapper.WeblogCategoryDataWrapper;
052: import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
053: import org.apache.roller.pojos.wrapper.WebsiteDataWrapper;
054: import org.apache.roller.ui.core.RollerSession;
055: import org.apache.roller.util.DateUtil;
056: import org.apache.commons.lang.StringUtils;
057: import org.apache.roller.pojos.HitCountData;
058:
059: /**
060: * Provides Roller page templates with access to Roller domain model objects.
061: */
062: public class OldWeblogPageModel {
063: public final static String VELOCITY_NULL = "nil";
064:
065: protected static Log mLogger = LogFactory.getFactory().getInstance(
066: OldWeblogPageModel.class);
067:
068: private BookmarkManager mBookmarkMgr = null;
069: private WeblogManager mWeblogMgr = null;
070: private UserManager mUserMgr = null;
071: private RefererManager mRefererMgr = null;
072:
073: private Map mCategories = new HashMap();
074: private HashMap mPageMap = new HashMap();
075: private HttpServletRequest mRequest = null;
076: private WebsiteData mWebsite = null;
077: private WeblogEntryData mEntry = null;
078: private WeblogCategoryData mCategory = null;
079: private Date mDate = null;
080: private boolean mIsDaySpecified = false;
081: private boolean mIsMonthSpecified = false;
082: private String mLocale = null;
083: private WeblogEntryDataWrapper mNextEntry = null;
084: private WeblogEntryDataWrapper mPreviousEntry = null;
085: private WeblogEntryDataWrapper mLastEntry = null;
086: private WeblogEntryDataWrapper mFirstEntry = null;
087:
088: //------------------------------------------------------------------------
089:
090: /** init() must be called to complete construction */
091: public OldWeblogPageModel() {
092: }
093:
094: public String getModelName() {
095: return "pageModel";
096: }
097:
098: /**
099: * Initialize PageModel and allow PageModel to initialized VelocityContext.
100: */
101: public void init(HttpServletRequest request, WebsiteData website,
102: WeblogEntryData entry, WeblogCategoryData category,
103: Date date, boolean isDay, boolean isMonth, String locale) {
104:
105: mRequest = request;
106:
107: // data we'll need in the methods
108: mWebsite = website;
109: mEntry = entry;
110: mCategory = category;
111: mDate = date;
112: mIsDaySpecified = isDay;
113: mIsMonthSpecified = isMonth;
114: mLocale = locale;
115:
116: try {
117: mBookmarkMgr = RollerFactory.getRoller()
118: .getBookmarkManager();
119: mRefererMgr = RollerFactory.getRoller().getRefererManager();
120: mUserMgr = RollerFactory.getRoller().getUserManager();
121: mWeblogMgr = RollerFactory.getRoller().getWeblogManager();
122:
123: // Preload what we can for encapsulation. What we cannot preload we
124: // will use the Managers later to fetch.
125:
126: // Get the pages, put into context & load map
127: if (mWebsite != null) {
128:
129: // Get the pages, put into context & load map
130: List pages = mWebsite.getPages();
131: Iterator pageIter = pages.iterator();
132: while (pageIter.hasNext()) {
133: Template page = (Template) pageIter.next();
134: mPageMap.put(page.getName(), TemplateWrapper
135: .wrap(page));
136: }
137: }
138:
139: } catch (RollerException e) {
140: mLogger.error("PageModel Roller get*Manager Exception", e);
141: }
142: }
143:
144: //------------------------------------------------------------------------
145:
146: /** Encapsulates folder.getBookmarks() & sorting */
147: public Collection getBookmarks(FolderDataWrapper folder) {
148: Collection bookmarks = null;
149: if (folder != null) {
150: mLogger.debug("Getting bookmarks for folder : "
151: + folder.getName());
152:
153: // since we already have a wrapped pojo we know the output
154: // will be wrapped as well :)
155: bookmarks = folder.getBookmarks();
156:
157: // TODO: need to setup new BookmarkWrapperComparator
158: //List mBookmarks = new ArrayList(bookmarks);
159: //Collections.sort( mBookmarks, new BookmarkComparator() );
160: }
161: return bookmarks;
162: }
163:
164: //------------------------------------------------------------------------
165:
166: /** Get top level bookmark folders. */
167: public Collection getTopLevelFolders() {
168: List tops = null;
169: try {
170: Collection mTops = mBookmarkMgr.getRootFolder(
171: mUserMgr.getWebsiteByHandle(mWebsite.getHandle()))
172: .getFolders();
173:
174: // wrap pojos
175: tops = new ArrayList(mTops.size());
176: Iterator it = mTops.iterator();
177: int i = 0;
178: while (it.hasNext()) {
179: tops.add(i, FolderDataWrapper.wrap((FolderData) it
180: .next()));
181: i++;
182: }
183: } catch (RollerException e) {
184: tops = new ArrayList();
185: }
186: return tops;
187: }
188:
189: //------------------------------------------------------------------------
190:
191: /** Get number of approved non-spam comments for entry */
192: public int getCommentCount(String entryId) {
193: return getCommentCount(entryId, true, true);
194: }
195:
196: /** Get number of approved non-spam comments for entry */
197: public int getCommentCount(String entryId, boolean noSpam,
198: boolean approvedOnly) {
199: try {
200: WeblogEntryData entry = mWeblogMgr.getWeblogEntry(entryId);
201: return entry.getComments(noSpam, approvedOnly).size();
202: } catch (RollerException alreadyLogged) {
203: }
204: return 0;
205: }
206:
207: //------------------------------------------------------------------------
208:
209: /** Get comments for weblog entry specified by request */
210: public List getComments(WeblogEntryDataWrapper entry) {
211: return getComments(entry, true, true);
212: }
213:
214: /** Get comments for weblog entry specified by request */
215: public List getComments(WeblogEntryDataWrapper wrapper,
216: boolean noSpam, boolean approvedOnly) {
217: WeblogEntryData entry = wrapper.getPojo();
218: List comments = new ArrayList();
219: List unwrappped = entry.getComments(noSpam, approvedOnly);
220: comments = new ArrayList(unwrappped.size());
221: Iterator it = unwrappped.iterator();
222: while (it.hasNext()) {
223: comments.add(CommentDataWrapper.wrap((CommentData) it
224: .next()));
225: }
226: return comments;
227: }
228:
229: //------------------------------------------------------------------------
230:
231: /** Encapsulates RefererManager */
232: public int getDayHits() {
233: try {
234: HitCountData hitCount = mWeblogMgr
235: .getHitCountByWeblog(mWebsite);
236:
237: return (hitCount != null) ? hitCount.getDailyHits() : 0;
238:
239: } catch (RollerException e) {
240: mLogger.error("PageModel getDayHits()", e);
241: }
242: return 0;
243: }
244:
245: //------------------------------------------------------------------------
246:
247: /** Encapsulates BookmarkManager.getFolder() */
248: public FolderDataWrapper getFolder(String folderPath) {
249: try {
250: return FolderDataWrapper.wrap(mBookmarkMgr.getFolder(
251: mUserMgr.getWebsiteByHandle(mWebsite.getHandle()),
252: folderPath));
253: } catch (RollerException e) {
254: mLogger.error("PageModel getFolder()", e);
255: }
256: return null;
257: }
258:
259: //------------------------------------------------------------------------
260:
261: /** Encapsulates UserManager.getPageByName() */
262: public TemplateWrapper getUsersPageByName(
263: WebsiteDataWrapper wrapper, String pageName) {
264: WebsiteData website = wrapper.getPojo();
265: TemplateWrapper page = null;
266: try {
267: if (website == null)
268: throw new NullPointerException("website is null");
269:
270: if (pageName == null)
271: throw new NullPointerException("pageName is null");
272:
273: page = TemplateWrapper
274: .wrap(website.getPageByName(pageName));
275: } catch (NullPointerException npe) {
276: mLogger.warn(npe.getMessage());
277: } catch (RollerException e) {
278: mLogger.error("ERROR getting user's page by name: "
279: + e.getMessage(), e);
280: }
281: return page;
282: }
283:
284: //------------------------------------------------------------------------
285:
286: /** Encapsulates UserManager.getPageByName() */
287: public TemplateWrapper getPageByName(String pageName) {
288: return (TemplateWrapper) mPageMap.get(pageName);
289: }
290:
291: //------------------------------------------------------------------------
292:
293: /** Encapsulates UserManager.getPageByName() */
294: public String getPageIdByName(String pageName) {
295: mLogger.debug("looking up page [" + pageName + "]");
296:
297: String template_id = null;
298:
299: try {
300: Template pd = mWebsite.getPageByName(pageName);
301: if (pd != null) {
302: template_id = pd.getId();
303: }
304: } catch (Exception e) {
305: mLogger.error(e);
306: }
307:
308: mLogger.debug("returning template id [" + template_id + "]");
309:
310: return template_id;
311: }
312:
313: //------------------------------------------------------------------------
314:
315: /**
316: * Get collection of user pages.
317: * @return
318: */
319: public Object getPages() {
320: return mPageMap.values();
321: }
322:
323: //------------------------------------------------------------------------
324:
325: /**
326: * Returns a map of up to 100 recent weblog entries for the user and day
327: * specified in the request, filtered by the category specified by the
328: * request, limited by the 'maxEntries' argument, and sorted by reverse
329: * chronological order.
330: *
331: * <p>This method will look for a category name in the following places
332: * and in the following order:</p>
333: * <ul>
334: * <li>The request via RollerRequest.getWeblogCategory().</li>
335: * <li>The categoryName argument to this method.</li>
336: * <li>The default category for the website specified by the request via
337: * RollerRequest.getWebsite().getDefaultCategory().</li>
338: * <li></li>
339: * </ul>
340: *
341: * @param maxEntries Maximum number of entries to be returned (only applies
342: * if specific day not specified).
343: * @param catName Only return entries from this category and it's
344: * subcategories. If null, returns all categories of entry
345: * @return Map of Lists of WeblogEntryData, keyed by 8-char date
346: * strings.
347: */
348: public Map getRecentWeblogEntries(int maxEntries, String catName) {
349: if (VELOCITY_NULL.equals(catName))
350: catName = null;
351: Map ret = new HashMap();
352: try {
353: // If request specifies a category, then use that
354: String catParam = null;
355: if (mCategory != null) {
356: catParam = mCategory.getPath();
357: } else if (catName != null) {
358: // use category argument instead
359: catParam = catName;
360: } else if (mWebsite != null) // MAIN
361: {
362: catParam = mWebsite.getDefaultCategory().getPath();
363: if (catParam.equals("/")) {
364: catParam = null;
365: }
366: }
367:
368: Calendar cal = null;
369: if (mWebsite != null) {
370: TimeZone tz = mWebsite.getTimeZoneInstance();
371: cal = Calendar.getInstance(tz);
372: } else {
373: cal = Calendar.getInstance();
374: }
375: int limit = mWebsite.getEntryDisplayCount();
376: Date startDate = null;
377: Date endDate = mDate;
378: if (endDate == null)
379: endDate = new Date();
380: if (mIsDaySpecified) {
381: // URL specified a specific day
382: // so get entries for that day
383: endDate = DateUtil.getEndOfDay(endDate, cal);
384: startDate = DateUtil.getStartOfDay(endDate, cal);
385: // and get them ALL, no limit
386: limit = -1;
387: } else if (mIsMonthSpecified) {
388: endDate = DateUtil.getEndOfMonth(endDate, cal);
389: }
390: Map mRet = RollerFactory.getRoller().getWeblogManager()
391: .getWeblogEntryObjectMap(mWebsite, startDate, // startDate
392: endDate, // endDate
393: catParam, // catName
394: null, // tags
395: WeblogEntryData.PUBLISHED, // status
396: mLocale, 0, limit);
397:
398: // need to wrap pojos
399: java.util.Date key = null;
400: Iterator days = mRet.keySet().iterator();
401: while (days.hasNext()) {
402: key = (java.util.Date) days.next();
403:
404: // now we need to go through each entry in a day and wrap
405: List wrappedEntries = new ArrayList();
406: List entries = (List) mRet.get(key);
407: for (int i = 0; i < entries.size(); i++) {
408: wrappedEntries.add(i, WeblogEntryDataWrapper
409: .wrap((WeblogEntryData) entries.get(i)));
410: }
411: mRet.put(key, wrappedEntries);
412: }
413:
414: ret = mRet;
415:
416: setFirstAndLastEntries(ret);
417: } catch (Exception e) {
418: mLogger.error("PageModel getRecentWeblogEntries()", e);
419: }
420: return ret;
421: }
422:
423: //------------------------------------------------------------------------
424:
425: /**
426: * Pull the last WeblogEntryData out of the Map.
427: * @param ret
428: */
429: private void setFirstAndLastEntries(Map days) {
430: int numDays = days.keySet().size();
431: if (numDays > 0) // there is at least one day
432: {
433: // get first entry in map
434: Object[] keys = days.keySet().toArray(new Object[numDays]);
435: List vals = (List) days.get(keys[0]);
436: int valSize = vals.size();
437: if (valSize > 0) {
438: mFirstEntry = (WeblogEntryDataWrapper) vals.get(0);
439: }
440:
441: // get last entry in map
442: vals = (List) days.get(keys[--numDays]);
443: valSize = vals.size();
444: if (valSize > 0) {
445: mLastEntry = (WeblogEntryDataWrapper) vals
446: .get(--valSize);
447: }
448: }
449: }
450:
451: //------------------------------------------------------------------------
452:
453: /**
454: * Returns list of recent weblog entries for the user and day specified in
455: * the request, filtered by the category specified by the request, limited
456: * by the 'maxEntries' argument, and sorted by reverse chronological order.
457: *
458: * <p>This method will look for a category name in the same places and
459: * same order as does the getRecentWeblogEntries() method.</p>
460: *
461: * @param maxEntries Maximum number of entries to be returned.
462: * @param categoryName Only return entries from this category and it's
463: * subcategories. If null, returns all categories of entry.
464: * @return List of WeblogEntryData objects in revese chronological order.
465: */
466: public List getRecentWeblogEntriesArray(int maxEntries,
467: String categoryName) {
468: if (VELOCITY_NULL.equals(categoryName))
469: categoryName = null;
470: List ret = new ArrayList();
471: try {
472: Date day = mDate;
473: if (day == null)
474: day = new Date();
475:
476: // If request specifies a category, then use that
477: String catParam = null;
478: if (mCategory != null) {
479: catParam = mCategory.getPath();
480: } else if (categoryName != null) {
481: // use category argument instead
482: catParam = categoryName;
483: } else if (mWebsite != null) // MAIN
484: {
485: catParam = mWebsite.getDefaultCategory().getPath();
486: if (catParam.equals("/")) {
487: catParam = null;
488: }
489: }
490: WeblogManager mgr = RollerFactory.getRoller()
491: .getWeblogManager();
492:
493: //ret = mgr.getRecentWeblogEntriesArray(
494: //name, day, catParam, maxEntries, true );
495:
496: List mEntries = mgr.getWeblogEntries(mWebsite, null, null, // startDate
497: day, // endDate
498: catParam, // catName
499: null, // tags
500: WeblogEntryData.PUBLISHED, // status
501: null, // sortby (null for pubTime)
502: mLocale, 0, mWebsite.getEntryDisplayCount());
503:
504: // wrap pojos
505: ret = new ArrayList(mEntries.size());
506: Iterator it = mEntries.iterator();
507: int i = 0;
508: while (it.hasNext()) {
509: ret.add(i, WeblogEntryDataWrapper
510: .wrap((WeblogEntryData) it.next()));
511: i++;
512: }
513: } catch (Exception e) {
514: mLogger.error("PageModel getRecentWeblogEntries()", e);
515: }
516: return ret;
517: }
518:
519: //------------------------------------------------------------------------
520:
521: /** Encapsulates RefererManager **/
522: public List getReferers(String date) {
523: date = date.trim();
524: ArrayList referers = new ArrayList();
525: try {
526: List refs = mRefererMgr.getReferersToDate(mWebsite, date);
527: RollerSession rses = RollerSession
528: .getRollerSession(mRequest);
529:
530: for (Iterator rdItr = refs.iterator(); rdItr.hasNext();) {
531: RefererData referer = (RefererData) rdItr.next();
532: String title = referer.getTitle();
533: String excerpt = referer.getExcerpt();
534: if (StringUtils.isNotEmpty(title)
535: && StringUtils.isNotEmpty(excerpt)) {
536: if (referer.getVisible().booleanValue()
537: || rses.isUserAuthorizedToAdmin(referer
538: .getWebsite())) {
539: referers.add(RefererDataWrapper.wrap(referer));
540: }
541: }
542: }
543:
544: } catch (Exception e) {
545: mLogger.error(
546: "PageModel getReferersToDate() fails with URL"
547: + mRequest.getRequestURL(), e);
548: }
549: return referers;
550: }
551:
552: /** Encapsulates RefererManager **/
553: public List getEntryReferers(WeblogEntryDataWrapper entry) {
554: ArrayList referers = new ArrayList();
555: try {
556: List refs = mRefererMgr.getReferersToEntry(entry.getId());
557: RollerSession rses = RollerSession
558: .getRollerSession(mRequest);
559:
560: for (Iterator rdItr = refs.iterator(); rdItr.hasNext();) {
561: RefererData referer = (RefererData) rdItr.next();
562: String title = referer.getTitle();
563: String excerpt = referer.getExcerpt();
564: if (StringUtils.isNotEmpty(title)
565: && StringUtils.isNotEmpty(excerpt)) {
566: if (referer.getVisible().booleanValue()
567: || rses.isUserAuthorizedToAdmin(referer
568: .getWebsite())) {
569: referers.add(RefererDataWrapper.wrap(referer));
570: }
571: }
572: }
573:
574: } catch (Exception e) {
575: mLogger.error(
576: "PageModel getReferersToDate() fails with URL"
577: + mRequest.getRequestURL(), e);
578: }
579: return referers;
580: }
581:
582: //------------------------------------------------------------------------
583:
584: /** Encapsulates RefererManager */
585: public List getTodaysReferers() {
586: return mWebsite.getTodaysReferrers();
587: }
588:
589: //------------------------------------------------------------------------
590:
591: /** Encapsulates RefererManager */
592: public int getTotalHits() {
593: return mWebsite.getTodaysHits();
594: }
595:
596: //------------------------------------------------------------------------
597: /**
598: * Returns most recent update time of collection of weblog entries.
599: * @param weblogEntries Collection of weblog entries.
600: * @return Most recent update time.
601: */
602: public static Date getUpdateTime(ArrayList weblogEntries) {
603: Date updateTime = null;
604: Iterator iter = weblogEntries.iterator();
605: while (iter.hasNext()) {
606: // NOTE: this will need to be WeblogEntryDataWrapper
607: WeblogEntryData wd = (WeblogEntryData) iter.next();
608: if (updateTime == null) {
609: updateTime = wd.getUpdateTime();
610: }
611: //else if ( updateTime.compareTo(wd.getUpdateTime()) < 0 )
612: else if (updateTime.before(wd.getUpdateTime())) {
613: updateTime = wd.getUpdateTime();
614: }
615: }
616: return updateTime;
617: }
618:
619: //------------------------------------------------------------------------
620:
621: /** Encapsulates WeblogManager.getWeblogCategories() */
622: public List getWeblogCategories(String categoryName) {
623: List ret = null;
624: if (VELOCITY_NULL.equals(categoryName))
625: categoryName = null;
626:
627: // Make sure we have not already fetched this category.
628: if (categoryName != null) {
629: ret = (List) mCategories.get(categoryName);
630: } else {
631: ret = (List) mCategories.get("zzz_null_zzz");
632: }
633:
634: if (null == ret) {
635: try {
636: WeblogCategoryData category = null;
637: if (categoryName != null) {
638: category = mWeblogMgr.getWeblogCategoryByPath(
639: mWebsite, null, categoryName);
640: } else {
641: category = mWebsite.getDefaultCategory();
642: }
643:
644: List mRet = category.getWeblogCategories();
645:
646: // wrap pojos
647: ret = new ArrayList(mRet.size());
648: Iterator it = mRet.iterator();
649: int i = 0;
650: while (it.hasNext()) {
651: ret.add(i, WeblogCategoryDataWrapper
652: .wrap((WeblogCategoryData) it.next()));
653: i++;
654: }
655: if (categoryName != null) {
656: mCategories.put(categoryName, ret);
657: } else {
658: mCategories.put("zzz_null_zzz", ret);
659: }
660: } catch (RollerException e) {
661: mLogger.error(e);
662: }
663: }
664: return ret;
665: }
666:
667: //------------------------------------------------------------------------
668:
669: /** Encapsulates RollerRequest.getWeblogEntry() */
670: public WeblogEntryDataWrapper getWeblogEntry() {
671:
672: if (mEntry != null
673: && mEntry.getStatus().equals(WeblogEntryData.PUBLISHED))
674: return WeblogEntryDataWrapper.wrap(mEntry);
675: else
676: return null;
677: }
678:
679: //------------------------------------------------------------------------
680:
681: /**
682: * Get the next occurring Entry.
683: */
684: public WeblogEntryDataWrapper getNextEntry() {
685: WeblogEntryDataWrapper currentEntry = getWeblogEntry();
686: if (mFirstEntry != null)
687: currentEntry = mFirstEntry;
688: if (mNextEntry == null && currentEntry != null) {
689: String catName = null;
690: if (mCategory != null) {
691: catName = mCategory.getName();
692: }
693: try {
694: WeblogEntryData nextEntry = mWeblogMgr.getNextEntry(
695: currentEntry.getPojo(), catName, mLocale);
696:
697: if (nextEntry != null)
698: mNextEntry = WeblogEntryDataWrapper.wrap(nextEntry);
699:
700: // make sure that mNextEntry is not published to future
701: if (mNextEntry != null
702: && mNextEntry.getPubTime().after(new Date())) {
703: mNextEntry = null;
704: }
705: } catch (RollerException e) {
706: mLogger.error("PageModel.getNextEntry)", e);
707: }
708: }
709: return mNextEntry;
710: }
711:
712: //------------------------------------------------------------------------
713:
714: /**
715: * Get the previous occurring Entry.
716: */
717: public WeblogEntryDataWrapper getPreviousEntry() {
718: WeblogEntryDataWrapper currentEntry = getWeblogEntry();
719: if (mLastEntry != null)
720: currentEntry = mLastEntry;
721: if (mPreviousEntry == null && currentEntry != null) {
722: String catName = null;
723: if (mCategory != null) {
724: catName = mCategory.getName();
725: }
726: try {
727: WeblogEntryData prevEntry = mWeblogMgr
728: .getPreviousEntry(currentEntry.getPojo(),
729: catName, mLocale);
730:
731: if (prevEntry != null)
732: mPreviousEntry = WeblogEntryDataWrapper
733: .wrap(prevEntry);
734: } catch (RollerException e) {
735: mLogger.error("PageModel.getPreviousEntry)", e);
736: }
737: }
738: return mPreviousEntry;
739: }
740:
741: //------------------------------------------------------------------------
742:
743: public boolean isUserAuthorizedToEdit() {
744: try {
745: RollerSession rses = RollerSession
746: .getRollerSession(mRequest);
747: if (rses != null && rses.getAuthenticatedUser() != null
748: && mWebsite != null) {
749: return rses.isUserAuthorizedToAuthor(mWebsite);
750: }
751: } catch (Exception e) {
752: mLogger.warn("PageModel.isUserAuthorizedToEdit()", e);
753: }
754: return false;
755: }
756:
757: //------------------------------------------------------------------------
758:
759: public boolean isUserAuthorizedToAdmin() {
760: try {
761: RollerSession rses = RollerSession
762: .getRollerSession(mRequest);
763: if (rses != null && rses.getAuthenticatedUser() != null
764: && mWebsite != null) {
765: return rses.isUserAuthorizedToAdmin(mWebsite);
766: }
767: } catch (Exception e) {
768: mLogger.warn("PageModel.isUserAuthorizedToAdmin()", e);
769: }
770: return false;
771: }
772:
773: //------------------------------------------------------------------------
774:
775: public boolean isUserAuthenticated() {
776: return (mRequest.getUserPrincipal() != null);
777: }
778:
779: //------------------------------------------------------------------------
780:
781: public String getRequestParameter(String key) {
782: return mRequest.getParameter(key);
783: }
784:
785: public int getIntRequestParameter(String key) {
786: return Integer.parseInt(mRequest.getParameter(key));
787: }
788:
789: //------------------------------------------------------------------------
790:
791: public FolderDataWrapper getFolderByPath(String path) {
792: try {
793: FolderData folder = mBookmarkMgr.getFolderByPath(mWebsite,
794: null, path);
795:
796: if (folder != null)
797: return FolderDataWrapper.wrap(folder);
798: } catch (RollerException e) {
799: mLogger.error(e);
800: }
801:
802: return null;
803: }
804:
805: /**
806: * Facade for WeblogManager.getRecentComments().
807: * Get the most recent (chronologically) posted Comments
808: * for this website, limited to maxCount.
809: * @return List of Comments.
810: */
811: public List getRecentComments(int maxCount) {
812: List recentComments = new ArrayList();
813: try {
814: WeblogManager wmgr = RollerFactory.getRoller()
815: .getWeblogManager();
816: List recent = wmgr.getComments(mWebsite, null, // weblog entry
817: null, // search String
818: null, // startDate
819: null, // endDate
820: null, // pending
821: Boolean.TRUE, // approved only
822: Boolean.FALSE, // no spam
823: true, // we want reverse chrono order
824: 0, // offset
825: maxCount); // no limit
826:
827: // wrap pojos
828: recentComments = new ArrayList(recent.size());
829: Iterator it = recent.iterator();
830: while (it.hasNext()) {
831: recentComments.add(CommentDataWrapper
832: .wrap((CommentData) it.next()));
833: }
834: } catch (RollerException e) {
835: mLogger.error(e);
836: }
837: return recentComments;
838: }
839:
840: public boolean getEmailComments() {
841: if (mWebsite != null) {
842: boolean emailComments = RollerRuntimeConfig
843: .getBooleanProperty("users.comments.emailnotify");
844: return (mWebsite.getEmailComments().booleanValue() && emailComments);
845: }
846: return false;
847: }
848: }
|