1 31 package org.blojsom.plugin.calendar; 32 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 import org.blojsom.blog.Blog; 36 import org.blojsom.blog.Entry; 37 import org.blojsom.fetcher.FetcherException; 38 import org.blojsom.plugin.PluginException; 39 import org.blojsom.util.BlojsomUtils; 40 41 import javax.servlet.http.HttpServletRequest ; 42 import javax.servlet.http.HttpServletResponse ; 43 import java.util.Calendar ; 44 import java.util.Date ; 45 import java.util.Locale ; 46 import java.util.Map ; 47 48 56 public abstract class AbstractVisualCalendarPlugin extends AbstractCalendarPlugin { 57 58 private Log _logger = LogFactory.getLog(AbstractVisualCalendarPlugin.class); 59 60 protected BlogCalendar _blogCalendar; 61 62 73 public Entry[] process(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Blog blog, Map context, Entry[] entries) throws PluginException { 74 entries = super.process(httpServletRequest, httpServletResponse, blog, context, entries); 75 76 Locale locale = (Locale ) context.get(BLOJSOM_CALENDAR_LOCALE); 77 BlogCalendar blogCalendar = (BlogCalendar) context.get(BLOJSOM_CALENDAR); 78 Calendar entrycalendar = Calendar.getInstance(locale); 79 80 Date startDate = BlojsomUtils.getFirstDateOfYearMonth(locale, blogCalendar.getCurrentYear(), blogCalendar.getCurrentMonth()); 81 Date endDate = BlojsomUtils.getLastDateOfYearMonth(locale, blogCalendar.getCurrentYear(), blogCalendar.getCurrentMonth()); 82 Date now = new Date (); 83 84 if (startDate.before(now)) { 85 if (endDate.after(now)) { 86 endDate = now; 87 } 88 89 try { 90 Entry[] entriesForMonth = _fetcher.findEntriesBetweenDates(blog, startDate, endDate); 91 for (int i = 0; i < entriesForMonth.length; i++) { 92 Entry entry = entriesForMonth[i]; 93 entrycalendar.setTime(entry.getDate()); 94 int entrymonth = entrycalendar.get(Calendar.MONTH); 95 int entryyear = entrycalendar.get(Calendar.YEAR); 96 97 if ((entrymonth == blogCalendar.getCurrentMonth()) && (entryyear == blogCalendar.getCurrentYear())) { 99 blogCalendar.setEntryForDOM(entrycalendar.get(Calendar.DAY_OF_MONTH)); 100 } 101 } 102 } catch (FetcherException e) { 103 if (_logger.isErrorEnabled()) { 104 _logger.error(e); 105 } 106 } 107 } 108 109 context.put(BLOJSOM_CALENDAR, blogCalendar); 110 111 return entries; 112 } 113 } 114 | Popular Tags |