001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListDateMacroFormatter.java,v $
003: * Date : $Date: 2008-02-27 12:05:28 $
004: * Version: $Revision: 1.8 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.list;
033:
034: import org.opencms.i18n.CmsMessageContainer;
035:
036: import java.util.Date;
037: import java.util.Locale;
038:
039: /**
040: * Formatter for dates.<p>
041: *
042: * The 'never' message will be displayed if the date is null or <code>{@link Date#getTime()}==0</code>.<p>
043: *
044: * @author Michael Moossen
045: *
046: * @version $Revision: 1.8 $
047: *
048: * @since 6.0.0
049: */
050: public class CmsListDateMacroFormatter extends CmsListMacroFormatter {
051:
052: /** Constant for never message. */
053: private final CmsMessageContainer m_never;
054:
055: /** Constant for never time. */
056: private final long m_neverTime;
057:
058: /**
059: * Default constructor that sets the mask to use.<p>
060: *
061: * @param mask pattern for <code>{@link java.text.MessageFormat}</code>
062: * @param never message (without args) for the 'never' message
063: */
064: public CmsListDateMacroFormatter(CmsMessageContainer mask,
065: CmsMessageContainer never) {
066:
067: this (mask, never, 0);
068: }
069:
070: /**
071: * Default constructor that sets the mask to use.<p>
072: *
073: * @param mask pattern for <code>{@link java.text.MessageFormat}</code>
074: * @param never message (without args) for the 'never' message
075: * @param neverTime the time considered as 'never', default is <code>0</code>
076: */
077: public CmsListDateMacroFormatter(CmsMessageContainer mask,
078: CmsMessageContainer never, long neverTime) {
079:
080: super (mask);
081: m_never = never;
082: m_neverTime = neverTime;
083: }
084:
085: /**
086: * Returns a default date formatter object.<p>
087: *
088: * @return a default date formatter object
089: */
090: public static I_CmsListFormatter getDefaultDateFormatter() {
091:
092: return new CmsListDateMacroFormatter(Messages.get().container(
093: Messages.GUI_LIST_DATE_FORMAT_1), Messages.get()
094: .container(Messages.GUI_LIST_DATE_FORMAT_NEVER_0));
095: }
096:
097: /**
098: * Returns a default date formatter object.<p>
099: *
100: * @param never time considered as never
101: *
102: * @return a default date formatter object
103: */
104: public static I_CmsListFormatter getDefaultDateFormatter(long never) {
105:
106: return new CmsListDateMacroFormatter(Messages.get().container(
107: Messages.GUI_LIST_DATE_FORMAT_1), Messages.get()
108: .container(Messages.GUI_LIST_DATE_FORMAT_NEVER_0),
109: never);
110: }
111:
112: /**
113: * @see org.opencms.workplace.list.CmsListMacroFormatter#format(java.lang.Object, java.util.Locale)
114: */
115: public String format(Object data, Locale locale) {
116:
117: if (data == null) {
118: return m_never.key(locale);
119: }
120: if (data instanceof Date) {
121: if (((Date) data).getTime() == m_neverTime) {
122: return m_never.key(locale);
123: }
124: }
125: return super.format(data, locale);
126: }
127: }
|