View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.geronimo.javamail.store.imap.connection;
19  
20  import java.text.FieldPosition;
21  import java.text.NumberFormat;
22  import java.text.ParsePosition;
23  import java.text.SimpleDateFormat;
24  import java.util.Calendar;
25  import java.util.Date;
26  import java.util.Locale;
27  
28  /**
29   * Formats ths date in the form used by the javamail IMAP SEARCH command, 
30   * <p/>
31   * The format used is <code>d MMM yyyy</code> and  locale is always US-ASCII.
32   *
33   * @version $Rev: 594520 $ $Date: 2007-11-13 07:57:39 -0500 (Tue, 13 Nov 2007) $
34   */
35  public class IMAPSearchDateFormat extends SimpleDateFormat {
36      public IMAPSearchDateFormat() {
37          super("dd-MMM-yyyy", Locale.US);
38      }
39      public StringBuffer format(Date date, StringBuffer buffer, FieldPosition position) {
40          StringBuffer result = super.format(date, buffer, position);
41          // The RFC 2060 requires that the day in the date be formatted with either 2 digits
42          // or one digit.  Our format specifies 2 digits, which pads with leading
43          // zeros.  We need to check for this and whack it if it's there
44          if (result.charAt(0) == '0') {
45              result.deleteCharAt(0); 
46          }
47          return result;
48      }
49  
50      /**
51       * The calendar cannot be set
52       * @param calendar
53       * @throws UnsupportedOperationException
54       */
55      public void setCalendar(Calendar calendar) {
56          throw new UnsupportedOperationException();
57      }
58  
59      /**
60       * The format cannot be set
61       * @param format
62       * @throws UnsupportedOperationException
63       */
64      public void setNumberFormat(NumberFormat format) {
65          throw new UnsupportedOperationException();
66      }
67  }
68  
69