KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > config > functions > FmtFunctions


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source 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  * Resin Open Source 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, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Sam
27  */

28
29 package com.caucho.config.functions;
30
31 import com.caucho.log.Log;
32 import com.caucho.server.util.CauchoSystem;
33 import com.caucho.util.Alarm;
34 import com.caucho.util.L10N;
35 import com.caucho.util.QDate;
36 import com.caucho.util.Sprintf;
37
38 import java.util.Calendar JavaDoc;
39 import java.util.Date JavaDoc;
40 import java.util.logging.Logger JavaDoc;
41
42 /**
43  * An object to store in an EL Environment to provide utility methods.
44  */

45 public class FmtFunctions {
46   static protected final Logger JavaDoc log = Log.open(FmtFunctions.class);
47   static final L10N L = new L10N(FmtFunctions.class);
48
49   static private QDate _calendar = new QDate(true);
50
51   public FmtFunctions()
52   {
53   }
54
55   /**
56    * Make a timestamp for current date and time.
57    */

58   static public String JavaDoc timestamp(String JavaDoc format)
59   {
60     long now;
61
62     if (CauchoSystem.isTesting())
63       now = Alarm.getCurrentTime();
64     else
65       now = System.currentTimeMillis();
66
67     return timestamp(format,now);
68   }
69
70   static protected String JavaDoc timestamp(String JavaDoc format, long t)
71   {
72     return _calendar.formatLocal(t, format);
73   }
74
75   public static String JavaDoc timestamp(String JavaDoc format, Date date)
76   {
77     return timestamp(format,date.getTime());
78   }
79
80   public static String JavaDoc timestamp(String JavaDoc format, Calendar JavaDoc date)
81   {
82     return timestamp(format,date.getTimeInMillis());
83   }
84
85   public static String JavaDoc timestamp(String JavaDoc format, QDate date)
86   {
87     return date.format(format);
88   }
89
90   public static String JavaDoc sprintf(String JavaDoc format, Object JavaDoc arg0, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3, Object JavaDoc arg4, Object JavaDoc arg5, Object JavaDoc arg6, Object JavaDoc arg7, Object JavaDoc arg8, Object JavaDoc arg9)
91   {
92     return Sprintf.sprintf(format, new Object JavaDoc[] { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 } );
93   }
94
95   public static String JavaDoc sprintf(String JavaDoc format, Object JavaDoc arg0, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3, Object JavaDoc arg4, Object JavaDoc arg5, Object JavaDoc arg6, Object JavaDoc arg7, Object JavaDoc arg8)
96   {
97     return Sprintf.sprintf(format, new Object JavaDoc[] { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 } );
98   }
99
100   public static String JavaDoc sprintf(String JavaDoc format, Object JavaDoc arg0, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3, Object JavaDoc arg4, Object JavaDoc arg5, Object JavaDoc arg6, Object JavaDoc arg7)
101   {
102     return Sprintf.sprintf(format, new Object JavaDoc[] { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 } );
103   }
104
105   public static String JavaDoc sprintf(String JavaDoc format, Object JavaDoc arg0, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3, Object JavaDoc arg4, Object JavaDoc arg5, Object JavaDoc arg6)
106   {
107     return Sprintf.sprintf(format, new Object JavaDoc[] { arg0, arg1, arg2, arg3, arg4, arg5, arg6 } );
108   }
109
110   public static String JavaDoc sprintf(String JavaDoc format, Object JavaDoc arg0, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3, Object JavaDoc arg4, Object JavaDoc arg5)
111   {
112     return Sprintf.sprintf(format, new Object JavaDoc[] { arg0, arg1, arg2, arg3, arg4, arg5 } );
113   }
114
115   public static String JavaDoc sprintf(String JavaDoc format, Object JavaDoc arg0, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3, Object JavaDoc arg4)
116   {
117     return Sprintf.sprintf(format, new Object JavaDoc[] { arg0, arg1, arg2, arg3, arg4 } );
118   }
119
120   public static String JavaDoc sprintf(String JavaDoc format, Object JavaDoc arg0, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3)
121   {
122     return Sprintf.sprintf(format, new Object JavaDoc[] { arg0, arg1, arg2, arg3 } );
123   }
124
125   public static String JavaDoc sprintf(String JavaDoc format, Object JavaDoc arg0, Object JavaDoc arg1, Object JavaDoc arg2)
126   {
127     return Sprintf.sprintf(format, new Object JavaDoc[] { arg0, arg1, arg2 } );
128   }
129
130   public static String JavaDoc sprintf(String JavaDoc format, Object JavaDoc arg0, Object JavaDoc arg1)
131   {
132     return Sprintf.sprintf(format, new Object JavaDoc[] { arg0, arg1 } );
133   }
134
135   public static String JavaDoc sprintf(String JavaDoc format, Object JavaDoc arg0)
136   {
137     return Sprintf.sprintf(format, new Object JavaDoc[] { arg0 } );
138   }
139 }
140
141
Popular Tags