KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > common > PageTool


1
2  /*
3  -- GeiNuke --
4 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
5  http://www.hostingjava.it/-geinuke/
6
7 This file is part of GeiNuke.
8
9     GeiNuke is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13
14     GeiNuke is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with GeiNuke; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */

23 package com.geinuke.common;
24
25 import java.util.Date JavaDoc;
26 import java.util.GregorianCalendar JavaDoc;
27 import java.util.Locale JavaDoc;
28
29 import org.apache.velocity.tools.generic.DateTool;
30
31
32 public class PageTool {
33     protected Locale JavaDoc locale=null;
34     protected DateTool dt=null;
35     
36     public PageTool(){
37         dt=new DateTool();
38     }
39     
40     public PageTool(Locale JavaDoc lo){
41         dt=new DateTool();
42         this.locale=lo;
43     }
44     
45     public String JavaDoc formatDate(GregorianCalendar JavaDoc gc){
46         String JavaDoc text=null;
47         if(this.locale!=null)
48             text=this.dt.format(dt.getFormat(),gc,this.locale);
49         else
50             text=this.dt.format(dt.getFormat(),gc);
51         return text;
52     }
53     
54     public String JavaDoc formatDate(long time){
55         GregorianCalendar JavaDoc gc=null;
56         Date JavaDoc d=new Date JavaDoc(time);
57         gc=new GregorianCalendar JavaDoc();
58         gc.setTime(d);
59         String JavaDoc text=null;
60         if(this.locale!=null)
61             text=this.dt.format(dt.getFormat(),gc,this.locale);
62         else
63             text=this.dt.format(dt.getFormat(),gc);
64         return text;
65     }
66     
67     public String JavaDoc formatDate(String JavaDoc s,GregorianCalendar JavaDoc gc){
68         String JavaDoc text=null;
69         if(this.locale!=null)
70             text=this.dt.format(s,gc,this.locale);
71         else
72             text=this.dt.format(s,gc);
73         return text;
74     }
75     
76     public Locale JavaDoc getLocale() {
77         return locale;
78     }
79     public void setLocale(Locale JavaDoc locale) {
80         this.locale = locale;
81     }
82 }
83
Popular Tags