01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.wikitext.widgets;
04:
05: import java.util.Date;
06: import java.text.SimpleDateFormat;
07:
08: import fitnesse.wikitext.WikiWidget;
09: import fitnesse.wiki.*;
10: import fitnesse.html.HtmlUtil;
11:
12: //created by Jason Sypher
13:
14: public class LastModifiedWidget extends WikiWidget {
15: public static final String REGEXP = "^!lastmodified";
16:
17: private static SimpleDateFormat makeTimeFormat() {
18: // SimpleDateFormat is not thread safe, so we need to create each
19: // instance independently.
20: return new SimpleDateFormat("hh:mm:ss a");
21: }
22:
23: private static SimpleDateFormat makeDateFormat() {
24: // SimpleDateFormat is not thread safe, so we need to create each
25: // instance independently.
26: return new SimpleDateFormat("MMM dd, yyyy");
27: }
28:
29: public LastModifiedWidget(ParentWidget parent, String text)
30: throws Exception {
31: super (parent);
32: }
33:
34: public String render() throws Exception {
35: PageData data = getWikiPage().getData();
36: String formattedDate = formatDate(data
37: .getLastModificationTime());
38: String user = data.getAttribute(WikiPage.LAST_MODIFYING_USER);
39: if (user == null || "".equals(user))
40: return HtmlUtil.metaText("Last modified anonymously on "
41: + formattedDate);
42: else
43: return HtmlUtil.metaText("Last modified by " + user
44: + " on " + formattedDate);
45: }
46:
47: public static String formatDate(Date date) {
48: String formattedDate = makeDateFormat().format(date) + " at "
49: + makeTimeFormat().format(date);
50:
51: return formattedDate;
52: }
53:
54: }
|