1 18 19 package org.apache.roller.ui.rendering.model; 20 21 import java.util.Map ; 22 import javax.servlet.jsp.PageContext ; 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 import org.apache.roller.RollerException; 26 import org.apache.roller.pojos.wrapper.WebsiteDataWrapper; 27 import org.apache.roller.ui.core.tags.calendar.BigWeblogCalendarModel; 28 import org.apache.roller.ui.core.tags.calendar.CalendarTag; 29 import org.apache.roller.ui.core.tags.calendar.WeblogCalendarModel; 30 import org.apache.roller.ui.rendering.util.WeblogPageRequest; 31 import org.apache.roller.ui.rendering.util.WeblogRequest; 32 33 34 39 public class CalendarModel implements Model { 40 41 private static Log log = LogFactory.getLog(CalendarModel.class); 42 43 private PageContext pageContext = null; 44 private WeblogPageRequest pageRequest = null; 45 46 47 48 public String getModelName() { 49 return "calendarModel"; 50 } 51 52 53 54 public void init(Map initData) throws RollerException { 55 56 this.pageContext = (PageContext ) initData.get("pageContext"); 58 59 WeblogRequest weblogRequest = (WeblogRequest) initData.get("weblogRequest"); 61 if(weblogRequest == null) { 62 throw new RollerException("expected weblogRequest from init data"); 63 } 64 65 if(weblogRequest instanceof WeblogPageRequest) { 68 this.pageRequest = (WeblogPageRequest) weblogRequest; 69 } else { 70 throw new RollerException("weblogRequest is not a WeblogPageRequest."+ 71 " CalendarModel only supports page requests."); 72 } 73 } 74 75 76 public String showWeblogEntryCalendar(WebsiteDataWrapper websiteWrapper, String catArgument) { 77 return showWeblogEntryCalendar(websiteWrapper, catArgument, false); 78 } 79 80 81 public String showWeblogEntryCalendarBig(WebsiteDataWrapper websiteWrapper, String catArgument) { 82 return showWeblogEntryCalendar(websiteWrapper, catArgument, true); 83 } 84 85 86 private String showWeblogEntryCalendar(WebsiteDataWrapper websiteWrapper, String catArgument, boolean big) { 87 88 if ("nil".equals(catArgument)) catArgument = null; 89 String ret = null; 90 try { 91 org.apache.roller.ui.core.tags.calendar.CalendarModel model = null; 92 if (big) { 93 model = new BigWeblogCalendarModel(pageRequest, catArgument); 94 } else { 95 model = new WeblogCalendarModel(pageRequest, catArgument); 96 } 97 98 pageContext.setAttribute("calendarModel", model); 100 101 CalendarTag calTag = new CalendarTag(); 102 calTag.setPageContext(pageContext); 103 calTag.setName("calendar"); 104 calTag.setModel("calendarModel"); 105 calTag.setLocale(pageRequest.getLocaleInstance()); 106 if (big) { 107 calTag.setClassSuffix("Big"); 108 } 109 ret = calTag.emit(); 110 } catch (Exception e) { 111 log.error("ERROR: initializing calendar tag",e); 112 } 113 return ret; 114 } 115 116 } 117 | Popular Tags |