01: /*
02: JSPWiki - a JSP-based WikiWiki clone.
03:
04: Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
05:
06: This program is free software; you can redistribute it and/or modify
07: it under the terms of the GNU Lesser General Public License as published by
08: the Free Software Foundation; either version 2.1 of the License, or
09: (at your option) any later version.
10:
11: This program is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU Lesser General Public License for more details.
15:
16: You should have received a copy of the GNU Lesser General Public License
17: along with this program; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package com.ecyrd.jspwiki.tags;
21:
22: import java.util.Date;
23: import java.text.SimpleDateFormat;
24: import java.io.IOException;
25:
26: import com.ecyrd.jspwiki.WikiEngine;
27: import com.ecyrd.jspwiki.WikiPage;
28:
29: /**
30: * Writes the modification date of the page, formatted
31: * as specified in the attribute "format".
32: *
33: * <UL>
34: * <LI>format = A string describing which format you want to use.
35: * This is exactly like in "java.text.SimpleDateFormat".
36: * </UL>
37: *
38: * @author Janne Jalkanen
39: * @since 2.0
40: */
41:
42: // FIXME: Should also take the current user TimeZone into account.
43: public class PageDateTag extends WikiTagBase {
44: public static final String DEFAULT_FORMAT = "dd-MMM-yyyy HH:mm:ss zzz";
45:
46: private String m_format = null;
47: private String m_id = null;
48:
49: public String getId() {
50: return m_id;
51: }
52:
53: public void setId(String id) {
54: m_id = id;
55: }
56:
57: public String getFormat() {
58: if (m_format == null)
59: return DEFAULT_FORMAT;
60:
61: return m_format;
62: }
63:
64: public void setFormat(String arg) {
65: m_format = arg;
66: }
67:
68: public final int doWikiStartTag() throws IOException {
69: WikiEngine engine = m_wikiContext.getEngine();
70: WikiPage page = m_wikiContext.getPage();
71:
72: if (page != null) {
73: Date d = page.getLastModified();
74: if (getId() != null) {
75: pageContext.setAttribute(getId(), d);
76: return SKIP_BODY;
77: }
78:
79: //
80: // Date may be null if the page does not exist.
81: //
82: if (d != null) {
83: SimpleDateFormat fmt = new SimpleDateFormat(getFormat());
84:
85: pageContext.getOut().write(fmt.format(d));
86: } else {
87: pageContext.getOut().write(
88: "<" + m_wikiContext.translate("date.never")
89: + ">");
90: }
91: }
92:
93: return SKIP_BODY;
94: }
95: }
|