KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > pojo > CalendarArchive


1 /*
2  * $Id: CalendarArchive.java,v 1.5 2005/01/13 19:27:20 michelson Exp $
3  *
4  * Copyright (c) 2004 j2biz Group, http://www.j2biz.com Koeln / Duesseldorf ,
5  * Germany
6  *
7  * @author Max Kalina
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License as published by the Free Software
12  * Foundation; either version 2 of the License, or (at your option) any later
13  * version.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License along with
21  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  * Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */

25
26 package com.j2biz.blogunity.pojo;
27
28 import java.io.Serializable JavaDoc;
29 import java.text.SimpleDateFormat JavaDoc;
30 import java.util.Calendar JavaDoc;
31 import java.util.Locale JavaDoc;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34
35 import com.j2biz.blogunity.BlogunityManager;
36 import com.j2biz.blogunity.IConstants;
37
38 public class CalendarArchive implements Serializable JavaDoc {
39
40     /**
41      * Comment for <code>serialVersionUID</code>
42      */

43     private static final long serialVersionUID = 3544388123799925557L;
44
45     // private static final SimpleDateFormat format = new SimpleDateFormat("MMMM
46
// yyyy");
47

48     private static final SimpleDateFormat JavaDoc linkformat = new SimpleDateFormat JavaDoc("/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     /**
63      * @return Returns the month.
64      */

65     public int getMonth() {
66         return month;
67     }
68
69     /**
70      * @param month
71      * The month to set.
72      */

73     public void setMonth(int month) {
74         this.month = month;
75     }
76
77     /**
78      * @return Returns the numberOfMessages.
79      */

80     public int getNumberOfMessages() {
81         return numberOfMessages;
82     }
83
84     /**
85      * @param numberOfMessages
86      * The numberOfMessages to set.
87      */

88     public void setNumberOfMessages(int numberOfMessages) {
89         this.numberOfMessages = numberOfMessages;
90     }
91
92     /**
93      * @return Returns the year.
94      */

95     public int getYear() {
96         return year;
97     }
98
99     /**
100      * @param year
101      * The year to set.
102      */

103     public void setYear(int year) {
104         this.year = year;
105     }
106
107     public String JavaDoc toHtml(HttpServletRequest JavaDoc request, Blog b) {
108         SimpleDateFormat JavaDoc format = new SimpleDateFormat JavaDoc("MMMM yyyy", getLocale(request));
109
110         Calendar JavaDoc c = Calendar.getInstance();
111         c.set(year, month - 1, 1);
112         String JavaDoc _year = String.valueOf(year);
113         String JavaDoc _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 JavaDoc asHtmlLink(HttpServletRequest JavaDoc request, Blog b) {
121
122         SimpleDateFormat JavaDoc format = new SimpleDateFormat JavaDoc("MMMM yyyy", getLocale(request));
123
124         Calendar JavaDoc 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 JavaDoc preformatedForText(HttpServletRequest JavaDoc request) {
132         SimpleDateFormat JavaDoc format = new SimpleDateFormat JavaDoc("MMMM yyyy", getLocale(request));
133
134         Calendar JavaDoc c = Calendar.getInstance();
135         c.set(year, month - 1, 1);
136         return format.format(c.getTime());
137     }
138
139     public String JavaDoc preformatedForLink(HttpServletRequest JavaDoc request) {
140
141         Calendar JavaDoc c = Calendar.getInstance();
142         c.set(year, month - 1, 1);
143         return linkformat.format(c.getTime());
144     }
145
146     private Locale JavaDoc getLocale(HttpServletRequest JavaDoc request) {
147         Locale JavaDoc locale = (Locale JavaDoc) request.getAttribute(IConstants.Request.LOCALE);
148
149         return locale;
150     }
151 }
Popular Tags