KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > mail > search > AddressStringTerm


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 /*
23  * @(#)AddressStringTerm.java 1.9 05/08/29
24  *
25  * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package javax.mail.search;
29
30 import javax.mail.Message JavaDoc;
31 import javax.mail.Address JavaDoc;
32 import javax.mail.internet.InternetAddress JavaDoc;
33
34 /**
35  * This abstract class implements string comparisons for Message
36  * addresses. <p>
37  *
38  * Note that this class differs from the <code>AddressTerm</code> class
39  * in that this class does comparisons on address strings rather than
40  * Address objects.
41  *
42  * @since JavaMail 1.1
43  */

44
45 public abstract class AddressStringTerm extends StringTerm JavaDoc {
46
47     private static final long serialVersionUID = 3086821234204980368L;
48
49     /**
50      * Constructor.
51      *
52      * @param pattern the address pattern to be compared.
53      */

54     protected AddressStringTerm(String JavaDoc pattern) {
55     super(pattern, true); // we need case-insensitive comparison.
56
}
57
58     /**
59      * Check whether the address pattern specified in the constructor is
60      * a substring of the string representation of the given Address
61      * object. <p>
62      *
63      * Note that if the string representation of the given Address object
64      * contains charset or transfer encodings, the encodings must be
65      * accounted for, during the match process. <p>
66      *
67      * @param a The comparison is applied to this Address object.
68      * @return true if the match succeeds, otherwise false.
69      */

70     protected boolean match(Address JavaDoc a) {
71     if (a instanceof InternetAddress JavaDoc) {
72         InternetAddress JavaDoc ia = (InternetAddress JavaDoc)a;
73         // We dont use toString() to get "a"'s String representation,
74
// because InternetAddress.toString() returns a RFC 2047
75
// encoded string, which isn't what we need here.
76

77         return super.match(ia.toUnicodeString());
78     } else
79         return super.match(a.toString());
80     }
81
82     /**
83      * Equality comparison.
84      */

85     public boolean equals(Object JavaDoc obj) {
86     if (!(obj instanceof AddressStringTerm JavaDoc))
87         return false;
88     return super.equals(obj);
89     }
90 }
91
Popular Tags