org.apache.james.mailboxmanager
Class SearchQuery

java.lang.Object
  extended by org.apache.james.mailboxmanager.SearchQuery

public class SearchQuery
extends java.lang.Object

Models a query used to search for messages. A query is the logical AND of the contained criteria.

Each Criterion is composed of an Operator (combining value and operation) together with field information (optional since the criteria type may imply a particular field). Factory methods are provided for criteria.


Nested Class Summary
static class SearchQuery.AllCriterion
          Any message.
static class SearchQuery.BooleanOperator
          Boolean value search.
static class SearchQuery.ConjunctionCriterion
          Conjuction applying to the contained criteria.
static class SearchQuery.ContainsOperator
          Contained value search.
static class SearchQuery.Criterion
          Marker superclass for criteria.
static class SearchQuery.CustomFlagCriterion
          Filters on a custom flag valuation.
static class SearchQuery.DateOperator
          Operates on a date.
static class SearchQuery.ExistsOperator
          Existance search.
static class SearchQuery.FlagCriterion
          Filters on a standard flag.
static class SearchQuery.HeaderCriterion
          Header value content search.
static interface SearchQuery.HeaderOperator
          Marks operator as suitable for header value searching.
static class SearchQuery.InOperator
          Search for numbers within set of ranges.
static class SearchQuery.InternalDateCriterion
          Filters on the internal date.
static class SearchQuery.NumericOperator
          Searches numberic values.
static class SearchQuery.NumericRange
          Numbers within a particular range.
static interface SearchQuery.Operator
          Search operator.
static class SearchQuery.SizeCriterion
          Filters on the size of the message in octets.
static class SearchQuery.TextCriterion
          Message text.
static class SearchQuery.UidCriterion
          Filters on message identity.
 
Constructor Summary
SearchQuery()
           
 
Method Summary
static SearchQuery.Criterion all()
          Creates a filter matching all messages.
static SearchQuery.Criterion and(java.util.List criteria)
          Creates a filter composing the listed criteria.
static SearchQuery.Criterion and(SearchQuery.Criterion one, SearchQuery.Criterion two)
          Creates a filter composing the two different criteria.
 void andCriteria(SearchQuery.Criterion crit)
           
static SearchQuery.Criterion bodyContains(java.lang.String value)
          Creates a filter matching messages which contains the given text within the body.
 boolean equals(java.lang.Object obj)
           
static SearchQuery.Criterion flagIsSet(javax.mail.Flags.Flag flag)
          Creates a filter on the given flag selecting messages where the given flag is selected.
static SearchQuery.Criterion flagIsSet(java.lang.String flag)
          Creates a filter on the given flag selecting messages where the given flag is selected.
static SearchQuery.Criterion flagIsUnSet(javax.mail.Flags.Flag flag)
          Creates a filter on the given flag selecting messages where the given flag is not selected.
static SearchQuery.Criterion flagIsUnSet(java.lang.String flag)
          Creates a filter on the given flag selecting messages where the given flag is not selected.
static SearchQuery.Criterion flagSet(javax.mail.Flags.Flag flag, boolean isSet)
          Creates a filter on the given flag.
static SearchQuery.Criterion flagSet(java.lang.String flag, boolean isSet)
          Creates a filter on the given flag.
 java.util.List getCriterias()
           
 java.util.Set getRecentMessageUids()
          Gets the UIDS of messages which are recent for this client session.
 int hashCode()
           
static SearchQuery.Criterion headerContains(java.lang.String headerName, java.lang.String value)
          Creates a filter matching messages whose header value contains the given value.
static SearchQuery.Criterion headerDateAfter(java.lang.String headerName, int day, int month, int year)
          Creates a filter matching messages with the date of the given header after the given date.
static SearchQuery.Criterion headerDateBefore(java.lang.String headerName, int day, int month, int year)
          Creates a filter matching messages with the date of the given header before the given date.
static SearchQuery.Criterion headerDateOn(java.lang.String headerName, int day, int month, int year)
          Creates a filter matching messages with the date of the given header on the given date.
static SearchQuery.Criterion headerExists(java.lang.String headerName)
          Creates a filter matching messages with a header matching the given name.
static SearchQuery.Criterion internalDateAfter(int day, int month, int year)
          Creates a filter matching messages with internal date after the given date.
static SearchQuery.Criterion internalDateBefore(int day, int month, int year)
          Creates a filter matching messages with internal date before the given date.
static SearchQuery.Criterion internalDateOn(int day, int month, int year)
          Creates a filter matching messages with internal date on the given date.
static SearchQuery.Criterion mailContains(java.lang.String value)
          Creates a filter matching messages which contains the given text either within the body or in the headers.
static SearchQuery.Criterion not(SearchQuery.Criterion criterion)
          Creates a filter inverting the given criteria.
static SearchQuery.Criterion or(SearchQuery.Criterion one, SearchQuery.Criterion two)
          Creates a filter composing the two different criteria.
static SearchQuery.Criterion sizeEquals(long value)
          Creates a filter for message size equal to the given value
static SearchQuery.Criterion sizeGreaterThan(long value)
          Creates a filter for message size greater than the given value
static SearchQuery.Criterion sizeLessThan(long value)
          Creates a filter for message size less than the given value
 java.lang.String toString()
           
static SearchQuery.Criterion uid(SearchQuery.NumericRange[] range)
          Creates a filter matching messages within any of the given ranges.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SearchQuery

public SearchQuery()
Method Detail

sizeLessThan

public static final SearchQuery.Criterion sizeLessThan(long value)
Creates a filter for message size less than the given value

Parameters:
value - messages with size less than this value will be selected by the returned criterion
Returns:
Criterion, not null

sizeGreaterThan

public static final SearchQuery.Criterion sizeGreaterThan(long value)
Creates a filter for message size greater than the given value

Parameters:
value - messages with size greater than this value will be selected by the returned criterion
Returns:
Criterion, not null

sizeEquals

public static final SearchQuery.Criterion sizeEquals(long value)
Creates a filter for message size equal to the given value

Parameters:
value - messages with size equal to this value will be selected by the returned criterion
Returns:
Criterion, not null

internalDateAfter

public static final SearchQuery.Criterion internalDateAfter(int day,
                                                            int month,
                                                            int year)
Creates a filter matching messages with internal date after the given date.

Parameters:
day - one based day of the month
month - one based month of the year
year - year
Returns:
Criterion, not null

internalDateOn

public static final SearchQuery.Criterion internalDateOn(int day,
                                                         int month,
                                                         int year)
Creates a filter matching messages with internal date on the given date.

Parameters:
day - one based day of the month
month - one based month of the year
year - year
Returns:
Criterion, not null

internalDateBefore

public static final SearchQuery.Criterion internalDateBefore(int day,
                                                             int month,
                                                             int year)
Creates a filter matching messages with internal date before the given date.

Parameters:
day - one based day of the month
month - one based month of the year
year - year
Returns:
Criterion, not null

headerDateAfter

public static final SearchQuery.Criterion headerDateAfter(java.lang.String headerName,
                                                          int day,
                                                          int month,
                                                          int year)
Creates a filter matching messages with the date of the given header after the given date. If the header's value is not a date then it will not be included.

Parameters:
headerName - name of the header whose value will be compared, not null
day - one based day of the month
month - one based month of the year
year - year
Returns:
Criterion, not null

headerDateOn

public static final SearchQuery.Criterion headerDateOn(java.lang.String headerName,
                                                       int day,
                                                       int month,
                                                       int year)
Creates a filter matching messages with the date of the given header on the given date. If the header's value is not a date then it will not be included.

Parameters:
headerName - name of the header whose value will be compared, not null
day - one based day of the month
month - one based month of the year
year - year
Returns:
Criterion, not null

headerDateBefore

public static final SearchQuery.Criterion headerDateBefore(java.lang.String headerName,
                                                           int day,
                                                           int month,
                                                           int year)
Creates a filter matching messages with the date of the given header before the given date. If the header's value is not a date then it will not be included.

Parameters:
headerName - name of the header whose value will be compared, not null
day - one based day of the month
month - one based month of the year
year - year
Returns:
Criterion, not null

headerContains

public static final SearchQuery.Criterion headerContains(java.lang.String headerName,
                                                         java.lang.String value)
Creates a filter matching messages whose header value contains the given value.

Parameters:
headerName - name of the header whose value will be compared, not null
value - when null or empty the existance of the header will be checked, otherwise contained value
Returns:
Criterion, not null

headerExists

public static final SearchQuery.Criterion headerExists(java.lang.String headerName)
Creates a filter matching messages with a header matching the given name.

Parameters:
headerName - name of the header whose value will be compared, not null
Returns:
Criterion, not null

mailContains

public static final SearchQuery.Criterion mailContains(java.lang.String value)
Creates a filter matching messages which contains the given text either within the body or in the headers. Implementations may choose to ignore mime parts which cannot be decoded to text.

Parameters:
value - search value
Returns:
Criterion, not null

bodyContains

public static final SearchQuery.Criterion bodyContains(java.lang.String value)
Creates a filter matching messages which contains the given text within the body. Implementations may choose to ignore mime parts which cannot be decoded to text.

Parameters:
value - search value
Returns:
Criterion, not null

uid

public static final SearchQuery.Criterion uid(SearchQuery.NumericRange[] range)
Creates a filter matching messages within any of the given ranges.

Parameters:
range - NumericRange's, not null
Returns:
Criterion, not null

or

public static final SearchQuery.Criterion or(SearchQuery.Criterion one,
                                             SearchQuery.Criterion two)
Creates a filter composing the two different criteria.

Parameters:
one - Criterion, not null
two - Criterion, not null
Returns:
Criterion, not null

and

public static final SearchQuery.Criterion and(SearchQuery.Criterion one,
                                              SearchQuery.Criterion two)
Creates a filter composing the two different criteria.

Parameters:
one - Criterion, not null
two - Criterion, not null
Returns:
Criterion, not null

and

public static final SearchQuery.Criterion and(java.util.List criteria)
Creates a filter composing the listed criteria.

Parameters:
criteria - List of SearchQuery.Criterion
Returns:
Criterion, not null

not

public static final SearchQuery.Criterion not(SearchQuery.Criterion criterion)
Creates a filter inverting the given criteria.

Parameters:
criterion - Criterion, not null
Returns:
Criterion, not null

flagSet

public static final SearchQuery.Criterion flagSet(javax.mail.Flags.Flag flag,
                                                  boolean isSet)
Creates a filter on the given flag.

Parameters:
flag - Flag, not null
isSet - true if the messages with the flag set should be matched, false otherwise
Returns:
Criterion, not null

flagIsSet

public static final SearchQuery.Criterion flagIsSet(javax.mail.Flags.Flag flag)
Creates a filter on the given flag selecting messages where the given flag is selected.

Parameters:
flag - Flag, not null
Returns:
Criterion, not null

flagIsUnSet

public static final SearchQuery.Criterion flagIsUnSet(javax.mail.Flags.Flag flag)
Creates a filter on the given flag selecting messages where the given flag is not selected.

Parameters:
flag - Flag, not null
Returns:
Criterion, not null

flagSet

public static final SearchQuery.Criterion flagSet(java.lang.String flag,
                                                  boolean isSet)
Creates a filter on the given flag.

Parameters:
flag - Flag, not null
isSet - true if the messages with the flag set should be matched, false otherwise
Returns:
Criterion, not null

flagIsSet

public static final SearchQuery.Criterion flagIsSet(java.lang.String flag)
Creates a filter on the given flag selecting messages where the given flag is selected.

Parameters:
flag - Flag, not null
Returns:
Criterion, not null

flagIsUnSet

public static final SearchQuery.Criterion flagIsUnSet(java.lang.String flag)
Creates a filter on the given flag selecting messages where the given flag is not selected.

Parameters:
flag - Flag, not null
Returns:
Criterion, not null

all

public static final SearchQuery.Criterion all()
Creates a filter matching all messages.

Returns:
Criterion, not null

andCriteria

public void andCriteria(SearchQuery.Criterion crit)

getCriterias

public java.util.List getCriterias()

getRecentMessageUids

public java.util.Set getRecentMessageUids()
Gets the UIDS of messages which are recent for this client session. The list of recent mail is maintained in the protocol layer since the mechanics are protocol specific.

Returns:
mutable Set of Long UIDS

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)


Copyright © 2002-2008 The Apache Software Foundation. All Rights Reserved.