1
//========================================================================
2
//Copyright 2004-2008 Mort Bay Consulting Pty. Ltd.
3
//------------------------------------------------------------------------
4
//Licensed under the Apache License, Version 2.0 (the "License");
5
//you may not use this file except in compliance with the License.
6
//You may obtain a copy of the License at
7
//http://www.apache.org/licenses/LICENSE-2.0
8
//Unless required by applicable law or agreed to in writing, software
9
//distributed under the License is distributed on an "AS IS" BASIS,
10
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
//See the License for the specific language governing permissions and
12
//limitations under the License.
13
//========================================================================
17
import java.text.SimpleDateFormat;
18
import java.util.Date;
19
import java.util.TimeZone;
21
import javax.servlet.jsp.JspException;
22
import javax.servlet.jsp.JspTagException;
23
import javax.servlet.jsp.PageContext;
24
import javax.servlet.jsp.tagext.BodyContent;
25
import javax.servlet.jsp.tagext.BodyTagSupport;
26
import javax.servlet.jsp.tagext.Tag;
28
public class DateTag extends BodyTagSupport
34
public void setParent(Tag parent) {this.parent=parent;}
35
public Tag getParent() {return parent;}
36
public void setBodyContent(BodyContent content) {body=content;}
37
public void setPageContext(PageContext pageContext) {}
39
public void setTz(String value) {tz=value;}
41
public int doStartTag() throws JspException {return EVAL_BODY_TAG;}
43
public int doEndTag() throws JspException {return EVAL_PAGE;}
45
public void doInitBody() throws JspException {}
47
public int doAfterBody() throws JspException {
50
SimpleDateFormat format = new SimpleDateFormat(body.getString());
51
format.setTimeZone(TimeZone.getTimeZone(tz));
52
body.getEnclosingWriter().write(format.format(new Date()));
55
catch (Exception ex) {
57
throw new JspTagException(ex.toString());