001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.geronimo.javamail.store.imap.connection;
019    
020    import java.text.FieldPosition;
021    import java.text.NumberFormat;
022    import java.text.ParsePosition;
023    import java.text.SimpleDateFormat;
024    import java.util.Calendar;
025    import java.util.Date;
026    import java.util.Locale;
027    
028    /**
029     * Formats ths date as specified by
030     * draft-ietf-drums-msg-fmt-08 dated January 26, 2000
031     * which supercedes RFC822.
032     * <p/>
033     * <p/>
034     * The format used is <code>EEE, d MMM yyyy HH:mm:ss Z</code> and
035     * locale is always US-ASCII.
036     *
037     * @version $Rev: 594520 $ $Date: 2007-11-13 07:57:39 -0500 (Tue, 13 Nov 2007) $
038     */
039    public class IMAPDateFormat extends SimpleDateFormat {
040        public IMAPDateFormat() {
041            super("dd-MMM-yyyy HH:mm:ss Z", Locale.US);
042        }
043        public StringBuffer format(Date date, StringBuffer buffer, FieldPosition position) {
044            StringBuffer result = super.format(date, buffer, position);
045            // The RFC 2060 requires that the day in the date be formatted with either 2 digits
046            // or one digit.  Our format specifies 2 digits, which pads with leading
047            // zeros.  We need to check for this and whack it if it's there
048            if (result.charAt(0) == '0') {
049                result.deleteCharAt(0); 
050            }
051            return result;
052        }
053    
054        /**
055         * The calendar cannot be set
056         * @param calendar
057         * @throws UnsupportedOperationException
058         */
059        public void setCalendar(Calendar calendar) {
060            throw new UnsupportedOperationException();
061        }
062    
063        /**
064         * The format cannot be set
065         * @param format
066         * @throws UnsupportedOperationException
067         */
068        public void setNumberFormat(NumberFormat format) {
069            throw new UnsupportedOperationException();
070        }
071    }
072