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 in the form used by the javamail IMAP SEARCH command, 
030     * <p/>
031     * The format used is <code>d MMM yyyy</code> and  locale is always US-ASCII.
032     *
033     * @version $Rev: 594520 $ $Date: 2007-11-13 07:57:39 -0500 (Tue, 13 Nov 2007) $
034     */
035    public class IMAPSearchDateFormat extends SimpleDateFormat {
036        public IMAPSearchDateFormat() {
037            super("dd-MMM-yyyy", Locale.US);
038        }
039        public StringBuffer format(Date date, StringBuffer buffer, FieldPosition position) {
040            StringBuffer result = super.format(date, buffer, position);
041            // The RFC 2060 requires that the day in the date be formatted with either 2 digits
042            // or one digit.  Our format specifies 2 digits, which pads with leading
043            // zeros.  We need to check for this and whack it if it's there
044            if (result.charAt(0) == '0') {
045                result.deleteCharAt(0); 
046            }
047            return result;
048        }
049    
050        /**
051         * The calendar cannot be set
052         * @param calendar
053         * @throws UnsupportedOperationException
054         */
055        public void setCalendar(Calendar calendar) {
056            throw new UnsupportedOperationException();
057        }
058    
059        /**
060         * The format cannot be set
061         * @param format
062         * @throws UnsupportedOperationException
063         */
064        public void setNumberFormat(NumberFormat format) {
065            throw new UnsupportedOperationException();
066        }
067    }
068    
069