KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > meshcms > taglib > LastModified


1 /*
2  * MeshCMS - A simple CMS based on SiteMesh
3  * Copyright (C) 2004-2007 Luciano Vernaschi
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * You can contact the author at http://www.cromoteca.com
20  * and at info@cromoteca.com
21  */

22
23 package org.meshcms.taglib;
24
25 import java.io.*;
26 import java.text.*;
27 import java.util.*;
28 import org.meshcms.core.*;
29 import org.meshcms.util.*;
30
31 /**
32  * Writes the date and time of last modification of the page.
33  */

34 public final class LastModified extends AbstractTag {
35   public static final String JavaDoc DATE_NORMAL = "normal";
36   public static final String JavaDoc DATE_FULL = "full";
37   public static final String JavaDoc MODE_STATIC = "static";
38   public static final String JavaDoc MODE_ALL = "all";
39   public static final String JavaDoc MODE_HIDDEN = "hidden";
40
41   private String JavaDoc date;
42   private String JavaDoc mode;
43   private String JavaDoc pre;
44   private String JavaDoc post;
45   private String JavaDoc update;
46
47   public void setDate(String JavaDoc date) {
48     this.date = date;
49   }
50
51   public void setMode(String JavaDoc mode) {
52     this.mode = mode;
53   }
54
55   public void setPre(String JavaDoc pre) {
56     this.pre = pre;
57   }
58
59   public void setPost(String JavaDoc post) {
60     this.post = post;
61   }
62
63   public void writeTag() throws IOException {
64     Writer w = getOut();
65     mode = Utils.noNull(mode);
66     long time = WebUtils.getLastModifiedTime(request);
67
68     if (mode.equals(MODE_ALL) || (!mode.equals(MODE_HIDDEN) &&
69         FileTypes.isLike(pagePath.getLastElement(), "html"))) {
70       Locale locale = WebUtils.getPageLocale(pageContext);
71       DateFormat df;
72
73       if (date != null && date.equals(DATE_FULL)) {
74         df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT,
75             locale);
76       } else {
77         df = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
78       }
79
80       if (pre != null) {
81        w.write(pre);
82       }
83
84       w.write(df.format(new Date(time)));
85
86       if (post != null) {
87         w.write(post);
88       }
89     } else {
90       w.write(" ");
91     }
92
93     if (Utils.isTrue(update)) {
94       webSite.getFile(pagePath).setLastModified(time);
95     }
96   }
97
98   public String JavaDoc getDate() {
99     return date;
100   }
101
102   public String JavaDoc getMode() {
103     return mode;
104   }
105
106   public String JavaDoc getPre() {
107     return pre;
108   }
109
110   public String JavaDoc getPost() {
111     return post;
112   }
113
114   public String JavaDoc getUpdate() {
115     return update;
116   }
117
118   public void setUpdate(String JavaDoc update) {
119     this.update = update;
120   }
121 }
122
Popular Tags