Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsAbDirectoryQuery Class Reference

#include <nsAbDirectoryQuery.h>

Inheritance diagram for nsAbDirectoryQuery:
Inheritance graph
[legend]
Collaboration diagram for nsAbDirectoryQuery:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIABDIRECTORYQUERY 
nsAbDirectoryQuery (nsIAbDirectory *aDirectory)
virtual ~nsAbDirectoryQuery ()
long doQuery (in nsIAbDirectoryQueryArguments arguments, in nsIAbDirectoryQueryResultListener listener, in long resultLimit, in long timeOut)
 Initiates a query on a directory and sub-directories for properties on cards.
void stopQuery (in long contextID)
 Stops an existing query operation if query operation is asynchronous.

Protected Member Functions

nsresult query (nsIAbDirectory *directory, nsIAbDirectoryQueryArguments *arguments, nsIAbDirectoryQueryResultListener *listener, PRInt32 *resultLimit)
nsresult queryChildren (nsIAbDirectory *directory, nsIAbDirectoryQueryArguments *arguments, nsIAbDirectoryQueryResultListener *listener, PRInt32 *resultLimit)
nsresult queryCards (nsIAbDirectory *directory, nsIAbDirectoryQueryArguments *arguments, nsIAbDirectoryQueryResultListener *listener, PRInt32 *resultLimit)
nsresult matchCard (nsIAbCard *card, nsIAbDirectoryQueryArguments *arguments, nsIAbDirectoryQueryResultListener *listener, PRInt32 *resultLimit)
nsresult matchCardExpression (nsIAbCard *card, nsIAbBooleanExpression *expression, PRBool *result)
nsresult matchCardCondition (nsIAbCard *card, nsIAbBooleanConditionString *condition, PRBool *matchFound)
nsresult queryMatch (nsIAbCard *card, nsIAbDirectoryQueryArguments *arguments, nsIAbDirectoryQueryResultListener *listener)
nsresult queryFinished (nsIAbDirectoryQueryArguments *arguments, nsIAbDirectoryQueryResultListener *listener)
nsresult queryError (nsIAbDirectoryQueryArguments *arguments, nsIAbDirectoryQueryResultListener *listener)

Protected Attributes

nsCOMPtr< nsIAbDirectorymDirectory

Detailed Description

Definition at line 125 of file nsAbDirectoryQuery.h.


Constructor & Destructor Documentation

Definition at line 350 of file nsAbDirectoryQuery.cpp.

{
  mDirectory = aDirectory;
}

Definition at line 355 of file nsAbDirectoryQuery.cpp.

{
}

Member Function Documentation

long nsIAbDirectoryQuery::doQuery ( in nsIAbDirectoryQueryArguments  arguments,
in nsIAbDirectoryQueryResultListener  listener,
in long  resultLimit,
in long  timeOut 
) [inherited]

Initiates a query on a directory and sub-directories for properties on cards.

Parameters:
argumentsThe properties and values to match Value could of type nsIAbDirectoryQueryMatchItem for matches other than ?contains?
listenerThe listener which will obtain individual query results
resultLimitLimits the results returned to a specifed maximum value
Returns:
Unique number representing the context ID of the query
nsresult nsAbDirectoryQuery::matchCard ( nsIAbCard card,
nsIAbDirectoryQueryArguments arguments,
nsIAbDirectoryQueryResultListener listener,
PRInt32 resultLimit 
) [protected]

Definition at line 475 of file nsAbDirectoryQuery.cpp.

{
    nsCOMPtr<nsISupports> supportsExpression;
    nsresult rv = arguments->GetExpression (getter_AddRefs (supportsExpression));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIAbBooleanExpression> expression(do_QueryInterface(supportsExpression, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    PRBool matchFound = PR_FALSE;
    rv = matchCardExpression (card, expression, &matchFound);
    NS_ENSURE_SUCCESS(rv, rv);

    if (matchFound)
    {
        (*resultLimit)--;
        rv = queryMatch (card, arguments, listener);
        NS_ENSURE_SUCCESS(rv, rv);
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbDirectoryQuery::matchCardCondition ( nsIAbCard card,
nsIAbBooleanConditionString condition,
PRBool matchFound 
) [protected]

Definition at line 559 of file nsAbDirectoryQuery.cpp.

{
    nsAbBooleanConditionType conditionType;
    nsresult rv = condition->GetCondition (&conditionType);
    NS_ENSURE_SUCCESS(rv, rv);

    nsXPIDLCString name;
    rv = condition->GetName (getter_Copies (name));
    NS_ENSURE_SUCCESS(rv, rv);

    if (name.Equals ("card:nsIAbCard"))
    {
      *matchFound = (conditionType == nsIAbBooleanConditionTypes::Exists);
      return NS_OK;
    }

    nsXPIDLString value;
    rv = card->GetCardValue (name.get (), getter_Copies (value));
    NS_ENSURE_SUCCESS(rv, rv);

    if (value.IsEmpty())
    {
      *matchFound = (conditionType == nsIAbBooleanConditionTypes::DoesNotExist) ?
          PR_TRUE : PR_FALSE;
      return NS_OK;
    }

    nsXPIDLString matchValue;
    rv = condition->GetValue (getter_Copies (matchValue));
    NS_ENSURE_SUCCESS(rv, rv);

    /* TODO
     * What about allowing choice between case insensitive
     * and case sensitive comparisons?
     *
     */
    switch (conditionType)
    {
        case nsIAbBooleanConditionTypes::Exists:
            *matchFound = PR_TRUE;
            break;
        case nsIAbBooleanConditionTypes::Contains:
            *matchFound = FindInReadable(matchValue, value, nsCaseInsensitiveStringComparator());
            break;
        case nsIAbBooleanConditionTypes::DoesNotContain:
            *matchFound = !FindInReadable(matchValue, value, nsCaseInsensitiveStringComparator());
            break;
        case nsIAbBooleanConditionTypes::Is:
            *matchFound = value.Equals(matchValue, nsCaseInsensitiveStringComparator());
            break;
        case nsIAbBooleanConditionTypes::IsNot:
            *matchFound = !value.Equals(matchValue, nsCaseInsensitiveStringComparator());
            break;
        case nsIAbBooleanConditionTypes::BeginsWith:
            *matchFound = StringBeginsWith(value, matchValue, nsCaseInsensitiveStringComparator());
            break;
        case nsIAbBooleanConditionTypes::LessThan:
            *matchFound = Compare(value, matchValue, nsCaseInsensitiveStringComparator()) < 0;
            break;
        case nsIAbBooleanConditionTypes::GreaterThan:
            *matchFound = Compare(value, matchValue, nsCaseInsensitiveStringComparator()) > 0;
            break;
        case nsIAbBooleanConditionTypes::EndsWith:
            *matchFound = StringEndsWith(value, matchValue, nsCaseInsensitiveStringComparator());
            break;
        case nsIAbBooleanConditionTypes::SoundsLike:
        case nsIAbBooleanConditionTypes::RegExp:
            *matchFound = PR_FALSE;
            break;
        default:
            *matchFound = PR_FALSE;
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbDirectoryQuery::matchCardExpression ( nsIAbCard card,
nsIAbBooleanExpression expression,
PRBool result 
) [protected]

Definition at line 501 of file nsAbDirectoryQuery.cpp.

{
    nsAbBooleanOperationType operation;
    nsresult rv = expression->GetOperation (&operation);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsISupportsArray> childExpressions;
    rv = expression->GetExpressions (getter_AddRefs (childExpressions));
    NS_ENSURE_SUCCESS(rv, rv);
    
    PRUint32 count;
    rv = childExpressions->Count (&count);
    NS_ENSURE_SUCCESS(rv, rv);

    if (operation == nsIAbBooleanOperationTypes::NOT &&
        count > 1)
        return NS_ERROR_FAILURE;

    PRBool value = *result = PR_FALSE;
    for (PRUint32 i = 0; i < count; i++)
    {
        nsCOMPtr<nsISupports> item;
        rv = childExpressions->GetElementAt (i, getter_AddRefs (item));
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsIAbBooleanConditionString>
            childCondition(do_QueryInterface(item, &rv));
        if (NS_SUCCEEDED(rv))
        {
            rv = matchCardCondition (card, childCondition, &value);
            NS_ENSURE_SUCCESS(rv, rv);
        }
        else
        {
            nsCOMPtr<nsIAbBooleanExpression>
                childExpression(do_QueryInterface(item, &rv));
            if (NS_SUCCEEDED(rv))
            {
                rv = matchCardExpression (card, childExpression, &value);
                NS_ENSURE_SUCCESS(rv, rv);
            }
            else
                return NS_ERROR_FAILURE;
        }
        if (operation == nsIAbBooleanOperationTypes::OR && value)
            break;
        else if (operation == nsIAbBooleanOperationTypes::AND && !value)
            break;
        else if (operation == nsIAbBooleanOperationTypes::NOT)
            value = !value;
    }
    *result = value;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbDirectoryQuery::query ( nsIAbDirectory directory,
nsIAbDirectoryQueryArguments arguments,
nsIAbDirectoryQueryResultListener listener,
PRInt32 resultLimit 
) [protected]

Definition at line 380 of file nsAbDirectoryQuery.cpp.

{
    if (*resultLimit == 0)
        return NS_OK;

    nsresult rv = queryCards (directory, arguments, listener, resultLimit);
    NS_ENSURE_SUCCESS(rv, rv);

    PRBool doSubDirectories;
    arguments->GetQuerySubDirectories (&doSubDirectories);
    if (doSubDirectories && *resultLimit != 0) {
        rv = queryChildren(directory, arguments, listener, resultLimit);
        NS_ENSURE_SUCCESS(rv, rv);
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbDirectoryQuery::queryCards ( nsIAbDirectory directory,
nsIAbDirectoryQueryArguments arguments,
nsIAbDirectoryQueryResultListener listener,
PRInt32 resultLimit 
) [protected]

Definition at line 429 of file nsAbDirectoryQuery.cpp.

{
    nsresult rv = NS_OK;

    nsCOMPtr<nsIEnumerator> cards;
    rv = directory->GetChildCards(getter_AddRefs(cards));
    if (NS_FAILED(rv))
    {
        if (rv != NS_ERROR_NOT_IMPLEMENTED)
            NS_ENSURE_SUCCESS(rv, rv);
        else
            return NS_OK;
    }

    if (!cards)
        return NS_OK;

    rv = cards->First();
    if (NS_FAILED(rv))
        return NS_OK;

    do
    {
        nsCOMPtr<nsISupports> item;
        rv = cards->CurrentItem(getter_AddRefs(item));
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsIAbCard> card(do_QueryInterface(item, &rv));
        NS_ENSURE_SUCCESS(rv, rv);
        
        rv = matchCard (card, arguments, listener, resultLimit);
        NS_ENSURE_SUCCESS(rv, rv);

        if (*resultLimit == 0)
            return NS_OK;

        rv = cards->Next ();
    }
    while (rv == NS_OK);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbDirectoryQuery::queryChildren ( nsIAbDirectory directory,
nsIAbDirectoryQueryArguments arguments,
nsIAbDirectoryQueryResultListener listener,
PRInt32 resultLimit 
) [protected]

Definition at line 401 of file nsAbDirectoryQuery.cpp.

{
    nsresult rv = NS_OK;

    nsCOMPtr<nsISimpleEnumerator> subDirectories;
    rv = directory->GetChildNodes(getter_AddRefs(subDirectories));
    NS_ENSURE_SUCCESS(rv, rv);

    PRBool hasMore;
    while (NS_SUCCEEDED(rv = subDirectories->HasMoreElements(&hasMore)) && hasMore)
    {
        nsCOMPtr<nsISupports> item;
        rv = subDirectories->GetNext (getter_AddRefs (item));
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsIAbDirectory> subDirectory(do_QueryInterface(item, &rv));
        NS_ENSURE_SUCCESS(rv, rv);
        
        rv = query (subDirectory, arguments, listener, resultLimit);
        NS_ENSURE_SUCCESS(rv, rv);

    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 725 of file nsAbDirectoryQuery.cpp.

{
    nsCOMPtr<nsIAbDirectoryQueryResult> queryResult;
    nsAbDirectoryQueryResult* _queryResult = new nsAbDirectoryQueryResult (0,
        arguments,
        nsIAbDirectoryQueryResult::queryResultError,
        0);
    if (!_queryResult)
        return NS_ERROR_OUT_OF_MEMORY;
    queryResult = _queryResult;

    return listener->OnQueryItem (queryResult);
}

Definition at line 710 of file nsAbDirectoryQuery.cpp.

{
    nsCOMPtr<nsIAbDirectoryQueryResult> queryResult;
    nsAbDirectoryQueryResult* _queryResult = new nsAbDirectoryQueryResult (0,
        arguments,
        nsIAbDirectoryQueryResult::queryResultComplete,
        0);
    if (!_queryResult)
        return NS_ERROR_OUT_OF_MEMORY;
    queryResult = _queryResult;

    return listener->OnQueryItem (queryResult);
}

Definition at line 637 of file nsAbDirectoryQuery.cpp.

{
    nsresult rv;
    nsCOMPtr<nsISupportsArray> propertyValues;

    CharPtrArrayGuard properties;
    rv = arguments->GetReturnProperties (properties.GetSizeAddr(), properties.GetArrayAddr());
    NS_ENSURE_SUCCESS(rv, rv);

    nsCAutoString n;
    for (PRUint32 i = 0; i < properties.GetSize(); i++)
    {
        n.Assign (properties[i]);

        nsAbDirectoryQueryPropertyValue* _propertyValue = 0;
        if (n.Equals("card:nsIAbCard"))
        {
            nsCOMPtr<nsISupports> supports(do_QueryInterface(card, &rv));
            NS_ENSURE_SUCCESS(rv, rv);

            _propertyValue = new nsAbDirectoryQueryPropertyValue(n.get (), supports);
            if (!_propertyValue)
                return NS_ERROR_OUT_OF_MEMORY;
        }
        else
        {
            nsXPIDLString value;
            rv = card->GetCardValue (n.get (), getter_Copies (value));
            NS_ENSURE_SUCCESS(rv, rv);

            if (!value.get () || value.Length () == 0)
                continue;

            _propertyValue = new nsAbDirectoryQueryPropertyValue(n.get (), value.get ());
            if (!_propertyValue)
                return NS_ERROR_OUT_OF_MEMORY;
        }

        if (_propertyValue)
        {
            nsCOMPtr<nsIAbDirectoryQueryPropertyValue> propertyValue;
            propertyValue = _propertyValue;

            if (!propertyValues)
            {
                NS_NewISupportsArray(getter_AddRefs(propertyValues));
            }

            nsCOMPtr<nsISupports> supports(do_QueryInterface(propertyValue, &rv));
            NS_ENSURE_SUCCESS(rv, rv);

            propertyValues->AppendElement (supports);
        }
    }

    
    if (!propertyValues)
        return NS_OK;

    nsCOMPtr<nsIAbDirectoryQueryResult> queryResult;
    nsAbDirectoryQueryResult* _queryResult = new nsAbDirectoryQueryResult (0,
        arguments,
        nsIAbDirectoryQueryResult::queryResultMatch,
        propertyValues);
    if (!_queryResult)
        return NS_ERROR_OUT_OF_MEMORY;
    queryResult = _queryResult;

    return listener->OnQueryItem (queryResult);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIAbDirectoryQuery::stopQuery ( in long  contextID) [inherited]

Stops an existing query operation if query operation is asynchronous.

The nsIAbDirectoryQueryResultListener will be notified when query has stopped

It is implementation specific if notification synchronous or asynchronous

Parameters:
contextIDThe unique number returned from the doQuery methods

Member Data Documentation

Definition at line 167 of file nsAbDirectoryQuery.h.


The documentation for this class was generated from the following files: