01: /*
02: JSPWiki - a JSP-based WikiWiki clone.
03:
04: Copyright (C) 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.plugin;
21:
22: import org.apache.log4j.Logger;
23: import com.ecyrd.jspwiki.*;
24: import java.util.*;
25: import java.text.SimpleDateFormat;
26:
27: /**
28: * Just displays the current date and time.
29: * The time format is exactly like in the java.text.SimpleDateFormat class.
30: *
31: * @since 1.7.8
32: * @see java.text.SimpleDateFormat
33: * @author Janne Jalkanen
34: */
35: public class CurrentTimePlugin implements WikiPlugin {
36: private static Logger log = Logger
37: .getLogger(CurrentTimePlugin.class);
38:
39: public static final String DEFAULT_FORMAT = "HH:mm:ss dd-MMM-yyyy zzzz";
40:
41: public String execute(WikiContext context, Map params)
42: throws PluginException {
43: String formatString = (String) params.get("format");
44:
45: if (formatString == null) {
46: formatString = DEFAULT_FORMAT;
47: }
48:
49: log.debug("Date format string is: " + formatString);
50:
51: try {
52: SimpleDateFormat fmt = new SimpleDateFormat(formatString);
53:
54: Date d = new Date(); // Now.
55:
56: return fmt.format(d);
57: } catch (IllegalArgumentException e) {
58: ResourceBundle rb = context
59: .getBundle(WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
60:
61: throw new PluginException(rb
62: .getString("currenttimeplugin.badformat")
63: + e.getMessage());
64: }
65: }
66:
67: }
|