View Javadoc
1 /***
2 *
3 * $Id$
4 *
5 * Copyright (c) 2002-2003 JLCP.org
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 */
27
28 package com.gotjava.web.taglibs.calendar;
29
30 import java.util.Date;
31 import java.io.IOException;
32
33 import javax.servlet.jsp.tagext.TagSupport;
34 import javax.servlet.jsp.tagext.BodyTagSupport;
35 import javax.servlet.jsp.tagext.BodyContent;
36 import javax.servlet.jsp.JspTagException;
37 import javax.servlet.jsp.JspWriter;
38
39 import com.gotjava.model.signon.JLCPUser;
40
41 import com.gotjava.model.calendar.CalendarSpan;
42 import com.gotjava.system.calendar.CalendarManager;
43
44 import com.gotjava.web.taglibs.signon.UserLookupTag;
45 import com.gotjava.web.taglibs.signon.UserLookupByIdTag;
46 import com.gotjava.web.taglibs.signon.UserLookupByUsernameTag;
47 import com.gotjava.system.calendar.exceptions.*;
48
49
50 /***
51 * <p>Description: </p>
52 * <p>Created: Mar 15, 2003</p>
53 * @author farra
54 */
55 public class CalendarTag extends BodyTagSupport {
56
57
58 private int m_span = CalendarSpan.MONTH;
59 private String m_spanString = "month";
60 private Date m_date = new Date();
61
62 public int doStartTag()
63 throws JspTagException
64 {
65 UserLookupTag lookupTag = (UserLookupTag) findAncestorWithClass(this,
66 UserLookupByIdTag.class);
67 if (lookupTag == null)
68 lookupTag = (UserLookupTag) findAncestorWithClass(this,
69 UserLookupByUsernameTag.class);
70
71 CalendarSpan cspan = null;
72
73 if (lookupTag == null){
74
75 cspan = CalendarManager.getInstance().getCalendarSpan(m_span, m_date);
76
77 }
78 else{
79 JLCPUser user = (JLCPUser) pageContext.getAttribute("currentUser");
80
81 if(cspan == null){
82 try {
83 cspan = CalendarManager.getInstance().getCalendarForUser(user,
84 m_span, m_date);
85 }
86 catch (CalendarException ex) {
87 ex.printStackTrace();
88 }
89 }
90 }
91
92 pageContext.setAttribute("currentSpan",cspan);
93 pageContext.setAttribute("currentDate",cspan.getStartDate());
94
95 return EVAL_BODY_BUFFERED;
96
97 }
98
99 public int doAfterBody()
100 {
101 try
102 {
103 BodyContent body = getBodyContent();
104 JspWriter out = body.getEnclosingWriter();
105 out.println(body.getString());
106 body.clearBody();
107
108 pageContext.removeAttribute("rootSpan");
109 pageContext.removeAttribute("currentCalendar");
110
111 }
112 catch (IOException ex)
113 {
114 }
115 return SKIP_BODY;
116 }
117
118
119 public void release(){
120 m_span = CalendarSpan.MONTH;
121 m_spanString = "month";
122 m_date = new Date();
123 }
124
125 public void setDate(Date m_date) {
126 this.m_date = m_date;
127 }
128 public void setSpan(String span) {
129 m_spanString = span;
130 if(span.equalsIgnoreCase("month")){
131 m_span = CalendarSpan.MONTH;
132 }
133 else if(span.equalsIgnoreCase("week")){
134 m_span = CalendarSpan.WEEK;
135 }
136 else if(span.equalsIgnoreCase("day")){
137 m_span = CalendarSpan.DAY;
138 }
139 else if(span.equalsIgnoreCase("year")){
140 m_span = CalendarSpan.YEAR;
141 }
142 }
143 public Date getDate() {
144 return m_date;
145 }
146 public String getSpan() {
147 return m_spanString;
148 }
149
150 }
This page was automatically generated by Maven