KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dlog4j > tags > CalendarCellColorTag


1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package dlog4j.tags;
17
18 import java.io.IOException JavaDoc;
19 import java.util.Calendar JavaDoc;
20
21 import javax.servlet.jsp.JspException JavaDoc;
22 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
23
24 import dlog4j.util.StringUtils;
25
26 /**
27  * @author Liudong
28  * 日历单元格背景色
29  */

30 public class CalendarCellColorTag extends TagSupport JavaDoc {
31
32     protected String JavaDoc yearId = "year";
33     protected String JavaDoc monthId = "month";
34     protected String JavaDoc color=null;
35     protected int day;
36     
37     private boolean isToday = false;
38     
39     /* (non-Javadoc)
40      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
41      */

42     public int doStartTag() throws JspException JavaDoc {
43         Calendar JavaDoc cal = Calendar.getInstance();
44         int year = ((Integer JavaDoc)pageContext.getAttribute(yearId)).intValue();
45         int month = ((Integer JavaDoc)pageContext.getAttribute(monthId)).intValue()-1;
46         isToday = cal.get(Calendar.YEAR)==year && cal.get(Calendar.MONTH)==month && cal.get(Calendar.DATE)==day;
47         try{
48             if(isToday){
49                 if(StringUtils.isNotEmpty(color)){
50                     pageContext.getOut().print("<font color='");
51                     pageContext.getOut().print(color);
52                     pageContext.getOut().print("'>");
53                 }
54                 pageContext.getOut().print("<b>");
55             }
56         }catch(IOException JavaDoc e){}
57         return EVAL_BODY_INCLUDE;
58     }
59
60     public int doEndTag() throws JspException JavaDoc {
61         try{
62             if(isToday){
63                 pageContext.getOut().print("</b>");
64                 if(StringUtils.isNotEmpty(color)){
65                     pageContext.getOut().print("</font>");
66                 }
67             }
68         }catch(Exception JavaDoc e){}
69         return EVAL_PAGE;
70     }
71     /**
72      * @return
73      */

74     public String JavaDoc getMonthId() {
75         return monthId;
76     }
77
78     /**
79      * @return
80      */

81     public String JavaDoc getYearId() {
82         return yearId;
83     }
84
85     /**
86      * @param string
87      */

88     public void setMonthId(String JavaDoc string) {
89         monthId = string;
90     }
91
92     /**
93      * @param string
94      */

95     public void setYearId(String JavaDoc string) {
96         yearId = string;
97     }
98
99     /**
100      * @return
101      */

102     public String JavaDoc getColor() {
103         return color;
104     }
105
106     /**
107      * @param string
108      */

109     public void setColor(String JavaDoc string) {
110         color = string;
111     }
112
113     /**
114      * @return
115      */

116     public Object JavaDoc getDay() {
117         return new Integer JavaDoc(day);
118     }
119
120     /**
121      * @param i
122      */

123     public void setDay(Object JavaDoc i) {
124         if(i==null)
125             return;
126         if(i instanceof Integer JavaDoc)
127             day = ((Integer JavaDoc)i).intValue();
128         else if(i instanceof String JavaDoc)
129             day = Integer.parseInt((String JavaDoc)i);
130     }
131
132 }
133
Popular Tags