1 25 26 package com.j2biz.blogunity.pojo; 27 28 import java.io.Serializable ; 29 import java.text.SimpleDateFormat ; 30 import java.util.Calendar ; 31 import java.util.Locale ; 32 33 import javax.servlet.http.HttpServletRequest ; 34 35 import com.j2biz.blogunity.BlogunityManager; 36 import com.j2biz.blogunity.IConstants; 37 38 public class CalendarArchive implements Serializable { 39 40 43 private static final long serialVersionUID = 3544388123799925557L; 44 45 48 private static final SimpleDateFormat linkformat = new SimpleDateFormat ("/yyyy/MM"); 49 50 private int month; 51 52 private int year; 53 54 private int numberOfMessages; 55 56 public CalendarArchive(int month, int year, int numberOfMessages) { 57 this.month = month; 58 this.year = year; 59 this.numberOfMessages = numberOfMessages; 60 } 61 62 65 public int getMonth() { 66 return month; 67 } 68 69 73 public void setMonth(int month) { 74 this.month = month; 75 } 76 77 80 public int getNumberOfMessages() { 81 return numberOfMessages; 82 } 83 84 88 public void setNumberOfMessages(int numberOfMessages) { 89 this.numberOfMessages = numberOfMessages; 90 } 91 92 95 public int getYear() { 96 return year; 97 } 98 99 103 public void setYear(int year) { 104 this.year = year; 105 } 106 107 public String toHtml(HttpServletRequest request, Blog b) { 108 SimpleDateFormat format = new SimpleDateFormat ("MMMM yyyy", getLocale(request)); 109 110 Calendar c = Calendar.getInstance(); 111 c.set(year, month - 1, 1); 112 String _year = String.valueOf(year); 113 String _month = (month < 10) ? "0" + month : String.valueOf(month); 114 115 return "<div class=\"monthTitle\"><a HREF=\"" + BlogunityManager.getBase() + "/blogs/" 116 + b.getUrlName() + linkformat.format(c.getTime()) + "\">" 117 + format.format(c.getTime()) + "</a></div>"; 118 } 119 120 public String asHtmlLink(HttpServletRequest request, Blog b) { 121 122 SimpleDateFormat format = new SimpleDateFormat ("MMMM yyyy", getLocale(request)); 123 124 Calendar c = Calendar.getInstance(); 125 c.set(year, month - 1, 1); 126 127 return "<a HREF=\"" + BlogunityManager.getBase() + "/blogs/" + b.getUrlName() 128 + linkformat.format(c.getTime()) + "\">" + format.format(c.getTime()) + "</a>"; 129 } 130 131 public String preformatedForText(HttpServletRequest request) { 132 SimpleDateFormat format = new SimpleDateFormat ("MMMM yyyy", getLocale(request)); 133 134 Calendar c = Calendar.getInstance(); 135 c.set(year, month - 1, 1); 136 return format.format(c.getTime()); 137 } 138 139 public String preformatedForLink(HttpServletRequest request) { 140 141 Calendar c = Calendar.getInstance(); 142 c.set(year, month - 1, 1); 143 return linkformat.format(c.getTime()); 144 } 145 146 private Locale getLocale(HttpServletRequest request) { 147 Locale locale = (Locale ) request.getAttribute(IConstants.Request.LOCALE); 148 149 return locale; 150 } 151 } | Popular Tags |