KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > list > CmsListDateMacroFormatter


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListDateMacroFormatter.java,v $
3  * Date : $Date: 2006/03/27 14:52:28 $
4  * Version: $Revision: 1.6 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.list;
33
34 import org.opencms.i18n.CmsMessageContainer;
35
36 import java.util.Date JavaDoc;
37 import java.util.Locale JavaDoc;
38
39 /**
40  * Formatter for dates.<p>
41  *
42  * The 'never' message will be displayed if the date is null or <code>{@link Date#getTime()}==0</code>.<p>
43  *
44  * @author Michael Moossen
45  *
46  * @version $Revision: 1.6 $
47  *
48  * @since 6.0.0
49  */

50 public class CmsListDateMacroFormatter extends CmsListMacroFormatter {
51
52     /** Constant for never message. */
53     private final CmsMessageContainer m_never;
54
55     /** Constant for never time. */
56     private final long m_neverTime;
57
58     /**
59      * Default constructor that sets the mask to use.<p>
60      *
61      * @param mask pattern for <code>{@link java.text.MessageFormat}</code>
62      * @param never message (without args) for the 'never' message
63      */

64     public CmsListDateMacroFormatter(CmsMessageContainer mask, CmsMessageContainer never) {
65
66         this(mask, never, 0);
67     }
68
69     /**
70      * Default constructor that sets the mask to use.<p>
71      *
72      * @param mask pattern for <code>{@link java.text.MessageFormat}</code>
73      * @param never message (without args) for the 'never' message
74      * @param neverTime the time considered as 'never', default is <code>0</code>
75      */

76     public CmsListDateMacroFormatter(CmsMessageContainer mask, CmsMessageContainer never, long neverTime) {
77
78         super(mask);
79         m_never = never;
80         m_neverTime = neverTime;
81     }
82
83     /**
84      * Returns a default date formatter object.<p>
85      *
86      * @return a default date formatter object
87      */

88     public static I_CmsListFormatter getDefaultDateFormatter() {
89
90         return new CmsListDateMacroFormatter(
91             Messages.get().container(Messages.GUI_LIST_DATE_FORMAT_1),
92             Messages.get().container(Messages.GUI_LIST_DATE_FORMAT_NEVER_0));
93     }
94
95     /**
96      * Returns a default date formatter object.<p>
97      *
98      * @param never time considered as never
99      *
100      * @return a default date formatter object
101      */

102     public static I_CmsListFormatter getDefaultDateFormatter(long never) {
103
104         return new CmsListDateMacroFormatter(
105             Messages.get().container(Messages.GUI_LIST_DATE_FORMAT_1),
106             Messages.get().container(Messages.GUI_LIST_DATE_FORMAT_NEVER_0),
107             never);
108     }
109
110     /**
111      * @see org.opencms.workplace.list.CmsListMacroFormatter#format(java.lang.Object, java.util.Locale)
112      */

113     public String JavaDoc format(Object JavaDoc data, Locale JavaDoc locale) {
114
115         if (data == null) {
116             return m_never.key(locale);
117         }
118         if (data instanceof Date JavaDoc) {
119             if (((Date JavaDoc)data).getTime() == m_neverTime) {
120                 return m_never.key(locale);
121             }
122         }
123         return super.format(data, locale);
124     }
125 }
126
Popular Tags