1 18 19 package org.apache.roller.ui.core.tags.calendar; 20 21 import java.text.SimpleDateFormat ; 22 import java.util.Date ; 23 import java.util.HashMap ; 24 import java.util.List ; 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.roller.RollerException; 28 import org.apache.roller.model.RollerFactory; 29 import org.apache.roller.model.WeblogManager; 30 import org.apache.roller.pojos.WeblogEntryData; 31 import org.apache.roller.ui.core.RollerContext; 32 import org.apache.roller.ui.rendering.util.WeblogPageRequest; 33 import org.apache.roller.util.DateUtil; 34 import org.apache.roller.util.URLUtilities; 35 36 37 40 public class BigWeblogCalendarModel extends WeblogCalendarModel { 41 42 private static Log mLogger = LogFactory.getLog(BigWeblogCalendarModel.class); 43 44 protected static final SimpleDateFormat mStarDateFormat = 45 DateUtil.get8charDateFormat(); 46 47 protected static final SimpleDateFormat mSingleDayFormat = 48 new SimpleDateFormat ("dd"); 49 50 51 public BigWeblogCalendarModel(WeblogPageRequest pRequest, String cat) { 52 super(pRequest, cat); 53 } 54 55 56 protected void loadWeblogEntries(Date startDate, Date endDate, String catName) { 57 try { 58 WeblogManager mgr = RollerFactory.getRoller().getWeblogManager(); 59 monthMap = mgr.getWeblogEntryObjectMap( 60 weblog, startDate, endDate, catName, WeblogEntryData.PUBLISHED, locale, 66 0, -1); 67 } catch (RollerException e) { 68 mLogger.error(e); 69 monthMap = new HashMap (); 70 } 71 } 72 73 74 public String getContent(Date day) { 75 String content = null; 76 try { 77 RollerContext rctx = RollerContext.getRollerContext(); 78 StringBuffer sb = new StringBuffer (); 79 80 String dateString = null; 83 List entries = (List )monthMap.get(day); 84 if ( entries != null ) { 85 dateString = mStarDateFormat.format( 86 ((WeblogEntryData)entries.get(0)).getPubTime()); 87 88 String dayUrl = URLUtilities.getWeblogCollectionURL(weblog, locale, cat, dateString, -1, false); 90 91 sb.append("<div class=\"hCalendarDayTitleBig\">"); 92 sb.append("<a HREF=\""); 93 sb.append( dayUrl ); 94 sb.append("\">"); 95 sb.append( mSingleDayFormat.format( day ) ); 96 sb.append("</a></div>"); 97 98 for ( int i=0; i<entries.size(); i++ ) { 99 sb.append("<div class=\"bCalendarDayContentBig\">"); 100 sb.append("<a HREF=\""); 101 sb.append(((WeblogEntryData)entries.get(i)).getPermalink()); 102 sb.append("\">"); 103 104 String title = ((WeblogEntryData)entries.get(i)).getTitle().trim(); 105 if ( title.length()==0 ) { 106 title = ((WeblogEntryData)entries.get(i)).getAnchor(); 107 } 108 if ( title.length() > 20 ) { 109 title = title.substring(0,20)+"..."; 110 } 111 112 sb.append( title ); 113 sb.append("</a></div>"); 114 } 115 116 } else { 117 sb.append("<div class=\"hCalendarDayTitleBig\">"); 118 sb.append( mSingleDayFormat.format( day ) ); 119 sb.append("</div>"); 120 sb.append("<div class=\"bCalendarDayContentBig\"/>"); 121 } 122 content = sb.toString(); 123 } catch (Exception e) { 124 mLogger.error("ERROR: creating URL", e); 125 } 126 return content; 127 } 128 129 136 public String computeUrl(Date day, boolean nextPrevMonthURL, boolean alwaysURL) { 137 String url = null; 138 String dateString = null; 141 List entries = (List )monthMap.get( day ); 142 if ( entries != null && day != null ) { 143 WeblogEntryData entry = (WeblogEntryData)entries.get(0); 144 dateString = mStarDateFormat.format(entry.getPubTime()); 145 } 146 if (dateString == null && !alwaysURL) return null; 147 else if (dateString == null && !nextPrevMonthURL) { 148 dateString = DateUtil.format8chars(day); 149 } else if (dateString == null && nextPrevMonthURL) { 150 dateString = DateUtil.format6chars(day); 151 } 152 try { 153 if (nextPrevMonthURL && pageLink != null) { 154 url = URLUtilities.getWeblogPageURL(weblog, locale, pageLink, null, cat, dateString, -1, false); 156 } else { 157 url = URLUtilities.getWeblogCollectionURL(weblog, locale, cat, dateString, -1, false); 159 } 160 } catch (Exception e) { 161 mLogger.error("ERROR: creating URL",e); 162 } 163 return url; 164 } 165 } 166 | Popular Tags |