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.BlojsomConstants; 40 41 import javax.servlet.http.HttpServletRequest ; 42 import javax.servlet.http.HttpServletResponse ; 43 import java.util.Date ; 44 import java.util.Map ; 45 46 55 public class CalendarFilterPlugin extends AbstractCalendarPlugin { 56 57 private Log _logger = LogFactory.getLog(CalendarFilterPlugin.class); 58 59 70 public Entry[] process(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Blog blog, Map context, Entry[] entries) throws PluginException { 71 entries = super.process(httpServletRequest, httpServletResponse, blog, context, entries); 72 73 Date startDate = (Date ) context.get(BLOJSOM_FILTER_START_DATE); 74 Date endDate = (Date ) context.get(BLOJSOM_FILTER_END_DATE); 75 Date now = new Date (); 76 77 boolean isPermalinkRequest = context.containsKey(BlojsomConstants.BLOJSOM_PERMALINK); 78 79 if (startDate != null && endDate != null && !isPermalinkRequest) { 80 if (startDate.before(now)) { 81 if (endDate.after(now)) { 82 endDate = now; 83 } 84 85 try { 86 if (_logger.isDebugEnabled()) { 87 _logger.debug("Filtering entries betweeen: " + startDate.toString() + " and " + endDate.toString()); 88 } 89 90 entries = _fetcher.findEntriesBetweenDates(blog, startDate, endDate); 91 } catch (FetcherException e) { 92 if (_logger.isErrorEnabled()) { 93 _logger.error(e); 94 } 95 } 96 } 97 } 98 99 return entries; 100 } 101 } 102 | Popular Tags |