Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Private Attributes | Static Private Attributes
LocalSearchDataSource Class Reference

#include <nsLocalSearchService.h>

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

List of all members.

Public Member Functions

 LocalSearchDataSource (void)
virtual ~LocalSearchDataSource (void)
nsresult Init ()
nsIRDFResource GetSource (in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue)
 Find an RDF resource that points to a given node over the specified arc & truth value.
nsISimpleEnumerator GetSources (in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue)
 Find all RDF resources that point to a given node over the specified arc & truth value.
nsIRDFNode GetTarget (in nsIRDFResource aSource, in nsIRDFResource aProperty, in boolean aTruthValue)
 Find a child of that is related to the source by the given arc arc and truth value.
nsISimpleEnumerator GetTargets (in nsIRDFResource aSource, in nsIRDFResource aProperty, in boolean aTruthValue)
 Find all children of that are related to the source by the given arc arc and truth value.
void Assert (in nsIRDFResource aSource, in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue)
 Add an assertion to the graph.
void Unassert (in nsIRDFResource aSource, in nsIRDFResource aProperty, in nsIRDFNode aTarget)
 Remove an assertion from the graph.
void Change (in nsIRDFResource aSource, in nsIRDFResource aProperty, in nsIRDFNode aOldTarget, in nsIRDFNode aNewTarget)
 Change an assertion from.
void Move (in nsIRDFResource aOldSource, in nsIRDFResource aNewSource, in nsIRDFResource aProperty, in nsIRDFNode aTarget)
 'Move' an assertion from
boolean HasAssertion (in nsIRDFResource aSource, in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue)
 Query whether an assertion exists in this graph.
void AddObserver (in nsIRDFObserver aObserver)
 Add an observer to this data source.
void RemoveObserver (in nsIRDFObserver aObserver)
 Remove an observer from this data source.
nsISimpleEnumerator ArcLabelsIn (in nsIRDFNode aNode)
 Get a cursor to iterate over all the arcs that point into a node.
nsISimpleEnumerator ArcLabelsOut (in nsIRDFResource aSource)
 Get a cursor to iterate over all the arcs that originate in a resource.
nsISimpleEnumerator GetAllResources ()
 Retrieve all of the resources that the data source currently refers to.
boolean IsCommandEnabled (in nsISupportsArray aSources, in nsIRDFResource aCommand, in nsISupportsArray aArguments)
 Returns whether a given command is enabled for a set of sources.
void DoCommand (in nsISupportsArray aSources, in nsIRDFResource aCommand, in nsISupportsArray aArguments)
 Perform the specified command on set of sources.
nsISimpleEnumerator GetAllCmds (in nsIRDFResource aSource)
 Returns the set of all commands defined for a given source.
boolean hasArcIn (in nsIRDFNode aNode, in nsIRDFResource aArc)
 Returns true if the specified node is pointed to by the specified arc.
boolean hasArcOut (in nsIRDFResource aSource, in nsIRDFResource aArc)
 Returns true if the specified node has the specified outward arc.
void beginUpdateBatch ()
 Notify observers that the datasource is about to send several notifications at once.
void endUpdateBatch ()
 Notify observers that the datasource has completed issuing a notification group.

Public Attributes

readonly attribute string URI
 The "URI" of the data source.

Protected Member Functions

NS_METHOD getFindResults (nsIRDFResource *source, nsISimpleEnumerator **aResult)
NS_METHOD getFindName (nsIRDFResource *source, nsIRDFLiteral **aResult)
NS_METHOD parseResourceIntoFindTokens (nsIRDFResource *u, findTokenPtr tokens)
PRBool doMatch (nsIRDFLiteral *literal, const nsAString &matchMethod, const nsString &matchText)
PRBool matchNode (nsIRDFNode *aNode, const nsAString &matchMethod, const nsString &matchText)
PRBool doDateMatch (nsIRDFDate *literal, const nsAString &matchMethod, const nsAString &matchText)
PRBool doIntMatch (nsIRDFInt *literal, const nsAString &matchMethod, const nsString &matchText)
PRBool dateMatches (nsIRDFDate *literal, const nsAString &method, const PRInt64 &matchDate)
NS_METHOD parseDate (const nsAString &aDate, PRInt64 *aResult)
NS_METHOD parseFindURL (nsIRDFResource *u, nsISupportsArray *array)

Private Attributes

nsCOMPtr< nsISupportsArraymObservers

Static Private Attributes

static PRInt32 gRefCnt
static nsIRDFResourcekNC_Child
static nsIRDFResourcekNC_Name
static nsIRDFResourcekNC_URL
static nsIRDFResourcekNC_FindObject
static nsIRDFResourcekNC_pulse
static nsIRDFResourcekRDF_InstanceOf
static nsIRDFResourcekRDF_type

Detailed Description

Definition at line 56 of file nsLocalSearchService.h.


Constructor & Destructor Documentation


Member Function Documentation

Add an observer to this data source.

If the datasource supports observers, the datasource source should hold a strong reference to the observer.

Here is the caller graph for this function:

Get a cursor to iterate over all the arcs that point into a node.

Returns:
NS_OK unless a catastrophic error occurs. If the method returns NS_OK, you may assume that labels points to a valid (but possible empty) nsISimpleEnumerator object.

Here is the caller graph for this function:

Get a cursor to iterate over all the arcs that originate in a resource.

Returns:
NS_OK unless a catastrophic error occurs. If the method returns NS_OK, you may assume that labels points to a valid (but possible empty) nsISimpleEnumerator object.

Here is the caller graph for this function:

void nsIRDFDataSource::Assert ( in nsIRDFResource  aSource,
in nsIRDFResource  aProperty,
in nsIRDFNode  aTarget,
in boolean  aTruthValue 
) [inherited]

Add an assertion to the graph.

Here is the caller graph for this function:

Notify observers that the datasource is about to send several notifications at once.

This must be followed by calling endUpdateBatch(), otherwise viewers will get out of sync.

void nsIRDFDataSource::Change ( in nsIRDFResource  aSource,
in nsIRDFResource  aProperty,
in nsIRDFNode  aOldTarget,
in nsIRDFNode  aNewTarget 
) [inherited]

Change an assertion from.

[aSource]--[aProperty]-->[aOldTarget]

to

[aSource]--[aProperty]-->[aNewTarget]

Here is the caller graph for this function:

PRBool LocalSearchDataSource::dateMatches ( nsIRDFDate literal,
const nsAString &  method,
const PRInt64 matchDate 
) [protected]

Definition at line 483 of file nsLocalSearchService.cpp.

{
    PRInt64 date;
    aDate->GetValue(&date);
    PRBool matches = PR_FALSE;
    
    if (method.EqualsLiteral("isbefore"))
        matches = LL_CMP(date, <, matchDate);
    
    else if (method.EqualsLiteral("isafter"))
        matches = LL_CMP(date, >, matchDate);

    else if (method.EqualsLiteral("is"))
        matches = LL_EQ(date, matchDate);

    return matches;
}

Here is the caller graph for this function:

void nsIRDFDataSource::DoCommand ( in nsISupportsArray  aSources,
in nsIRDFResource  aCommand,
in nsISupportsArray  aArguments 
) [inherited]

Perform the specified command on set of sources.

Here is the caller graph for this function:

PRBool LocalSearchDataSource::doDateMatch ( nsIRDFDate literal,
const nsAString &  matchMethod,
const nsAString &  matchText 
) [protected]

Definition at line 421 of file nsLocalSearchService.cpp.

{
    PRBool found = PR_FALSE;
    
    if (matchMethod.EqualsLiteral("isbefore") ||
        matchMethod.EqualsLiteral("isafter"))
    {
        PRInt64 matchDate;
        nsresult rv = parseDate(matchText, &matchDate);
        if (NS_SUCCEEDED(rv))
            found = dateMatches(aDate, matchMethod, matchDate);
    }

    return found;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool LocalSearchDataSource::doIntMatch ( nsIRDFInt literal,
const nsAString &  matchMethod,
const nsString matchText 
) [protected]

Definition at line 440 of file nsLocalSearchService.cpp.

{
    nsresult rv;
    PRBool found = PR_FALSE;
    
    PRInt32 val;
    rv = aInt->GetValue(&val);
    if (NS_FAILED(rv)) return PR_FALSE;
    
    PRInt32 error=0;
    PRInt32 matchVal = matchText.ToInteger(&error);
    if (error != 0) return PR_FALSE;
    
    if (matchMethod.EqualsLiteral("is"))
        found = (val == matchVal);
    else if (matchMethod.EqualsLiteral("isgreater"))
        found = (val > matchVal);
    else if (matchMethod.EqualsLiteral("isless"))
        found = (val < matchVal);

    return found;
}

Here is the caller graph for this function:

PRBool LocalSearchDataSource::doMatch ( nsIRDFLiteral literal,
const nsAString &  matchMethod,
const nsString matchText 
) [protected]

Definition at line 353 of file nsLocalSearchService.cpp.

{
       PRBool        found = PR_FALSE;

       if ((nsnull == literal) ||
            matchMethod.IsEmpty() ||
            matchText.IsEmpty())
              return(found);

       const  PRUnichar     *str = nsnull;
       literal->GetValueConst( &str );
       if (! str)    return(found);
       nsAutoString  value(str);

        if (matchMethod.EqualsLiteral("contains"))
       {
            if (FindInReadable(matchText, value,
                               nsCaseInsensitiveStringComparator()))
                found = PR_TRUE;
       }
        else if (matchMethod.EqualsLiteral("startswith"))
       {
            nsAString::const_iterator start, realstart, end;
            value.BeginReading(start);
            value.EndReading(end);
            realstart = start;
            
            if (FindInReadable(matchText, start, end,
                               nsCaseInsensitiveStringComparator()) &&
                start == realstart)
                
                found = PR_TRUE;
       }
        else if (matchMethod.EqualsLiteral("endswith"))
       {
            nsAString::const_iterator start, end, realend;
            value.BeginReading(start);
            value.EndReading(end);
            realend = end;

            if (RFindInReadable(matchText, start, end,
                                nsCaseInsensitiveStringComparator()) &&
                end == realend)
                
                found = PR_TRUE;
       }
        else if (matchMethod.EqualsLiteral("is"))
       {
            if (value.Equals(matchText, nsCaseInsensitiveStringComparator()))
                found = PR_TRUE;
       }
        else if (matchMethod.EqualsLiteral("isnot"))
       {
            if (!value.Equals(matchText, nsCaseInsensitiveStringComparator()))
                found = PR_TRUE;
       }
        else if (matchMethod.EqualsLiteral("doesntcontain"))
       {
            if (!FindInReadable(matchText, value,
                                nsCaseInsensitiveStringComparator()))
                found = PR_TRUE;
       }
        return(found);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Notify observers that the datasource has completed issuing a notification group.

Returns the set of all commands defined for a given source.

Here is the caller graph for this function:

Retrieve all of the resources that the data source currently refers to.

Here is the caller graph for this function:

NS_METHOD LocalSearchDataSource::getFindName ( nsIRDFResource source,
nsIRDFLiteral **  aResult 
) [protected]

Definition at line 652 of file nsLocalSearchService.cpp.

{
       // XXX construct find URI human-readable name
       *aResult = nsnull;
       return(NS_OK);
}

Definition at line 629 of file nsLocalSearchService.cpp.

{
       nsresult                    rv;
       nsCOMPtr<nsISupportsArray>  nameArray;
       rv = NS_NewISupportsArray( getter_AddRefs(nameArray) );
       if (NS_FAILED(rv)) return rv;

       rv = parseFindURL(source, nameArray);
       if (NS_FAILED(rv)) return rv;

       nsISimpleEnumerator* result = new nsArrayEnumerator(nameArray);
       if (! result)
              return(NS_ERROR_OUT_OF_MEMORY);

       NS_ADDREF(result);
       *aResult = result;

       return NS_OK;
}

Here is the call graph for this function:

nsIRDFResource nsIRDFDataSource::GetSource ( in nsIRDFResource  aProperty,
in nsIRDFNode  aTarget,
in boolean  aTruthValue 
) [inherited]

Find an RDF resource that points to a given node over the specified arc & truth value.

Returns:
NS_RDF_NO_VALUE if there is no source that leads to the target with the specified property.

Here is the caller graph for this function:

nsISimpleEnumerator nsIRDFDataSource::GetSources ( in nsIRDFResource  aProperty,
in nsIRDFNode  aTarget,
in boolean  aTruthValue 
) [inherited]

Find all RDF resources that point to a given node over the specified arc & truth value.

Returns:
NS_OK unless a catastrophic error occurs. If the method returns NS_OK, you may assume that nsISimpleEnumerator points to a valid (but possibly empty) cursor.

Here is the caller graph for this function:

nsIRDFNode nsIRDFDataSource::GetTarget ( in nsIRDFResource  aSource,
in nsIRDFResource  aProperty,
in boolean  aTruthValue 
) [inherited]

Find a child of that is related to the source by the given arc arc and truth value.

Returns:
NS_RDF_NO_VALUE if there is no target accessable from the source via the specified property.

Here is the caller graph for this function:

nsISimpleEnumerator nsIRDFDataSource::GetTargets ( in nsIRDFResource  aSource,
in nsIRDFResource  aProperty,
in boolean  aTruthValue 
) [inherited]

Find all children of that are related to the source by the given arc arc and truth value.

Returns:
NS_OK unless a catastrophic error occurs. If the method returns NS_OK, you may assume that nsISimpleEnumerator points to a valid (but possibly empty) cursor.

Here is the caller graph for this function:

boolean nsIRDFDataSource::hasArcIn ( in nsIRDFNode  aNode,
in nsIRDFResource  aArc 
) [inherited]

Returns true if the specified node is pointed to by the specified arc.

Equivalent to enumerating ArcLabelsIn and comparing for the specified arc.

Returns true if the specified node has the specified outward arc.

Equivalent to enumerating ArcLabelsOut and comparing for the specified arc.

boolean nsIRDFDataSource::HasAssertion ( in nsIRDFResource  aSource,
in nsIRDFResource  aProperty,
in nsIRDFNode  aTarget,
in boolean  aTruthValue 
) [inherited]

Query whether an assertion exists in this graph.

Here is the caller graph for this function:

Definition at line 145 of file nsLocalSearchService.cpp.

{
       nsresult      rv = NS_ERROR_OUT_OF_MEMORY;

       // register this as a named data source with the service manager
       if (NS_FAILED(rv = gRDFService->RegisterDataSource(this, PR_FALSE)))
              return(rv);

       return(rv);
}

Here is the call graph for this function:

boolean nsIRDFDataSource::IsCommandEnabled ( in nsISupportsArray  aSources,
in nsIRDFResource  aCommand,
in nsISupportsArray  aArguments 
) [inherited]

Returns whether a given command is enabled for a set of sources.

Here is the caller graph for this function:

PRBool LocalSearchDataSource::matchNode ( nsIRDFNode aNode,
const nsAString &  matchMethod,
const nsString matchText 
) [protected]

Definition at line 609 of file nsLocalSearchService.cpp.

{
    nsCOMPtr<nsIRDFLiteral> literal(do_QueryInterface(aValue));
    if (literal)
        return doMatch(literal, matchMethod, matchText);

    nsCOMPtr<nsIRDFDate> dateLiteral(do_QueryInterface(aValue));
    if (dateLiteral)
        return doDateMatch(dateLiteral, matchMethod, matchText);
    
    nsCOMPtr<nsIRDFInt> intLiteral(do_QueryInterface(aValue));
    if (intLiteral)
        return doIntMatch(intLiteral, matchMethod, matchText);

    return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIRDFDataSource::Move ( in nsIRDFResource  aOldSource,
in nsIRDFResource  aNewSource,
in nsIRDFResource  aProperty,
in nsIRDFNode  aTarget 
) [inherited]

'Move' an assertion from

[aOldSource]--[aProperty]-->[aTarget]

to

[aNewSource]--[aProperty]-->[aTarget]

Here is the caller graph for this function:

NS_METHOD LocalSearchDataSource::parseDate ( const nsAString &  aDate,
PRInt64 aResult 
) [protected]

Definition at line 466 of file nsLocalSearchService.cpp.

{
    // date is in the form of msec since epoch, but use NSPR to
    // parse the time
    PRTime *outTime = NS_STATIC_CAST(PRTime*,aResult);
    PRStatus err;
    err = PR_ParseTimeString(NS_ConvertUCS2toUTF8(aDate).get(),
                             PR_FALSE, // PR_FALSE == use current timezone
                             outTime);
    NS_ENSURE_TRUE(err == 0, NS_ERROR_FAILURE);
    
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 505 of file nsLocalSearchService.cpp.

{
  findTokenStruct           tokens[5];
  nsresult rv;

  // build up a token list
  tokens[0].token = "datasource";
  tokens[1].token = "match";
  tokens[2].token = "method";
  tokens[3].token = "text";
  tokens[4].token = NULL;

  // parse find URI, get parameters, search in appropriate
  // datasource(s), return results
  rv = parseResourceIntoFindTokens(u, tokens);
  if (NS_FAILED(rv)) 
    return rv;

  nsCAutoString dsName;
  dsName.AssignWithConversion(tokens[0].value);

  nsCOMPtr<nsIRDFDataSource> datasource;
  rv = gRDFService->GetDataSource(dsName.get(), getter_AddRefs(datasource));
  if (NS_FAILED(rv)) 
    return rv;

  nsCOMPtr<nsISimpleEnumerator> cursor;
  rv = datasource->GetAllResources(getter_AddRefs(cursor));
  if (NS_FAILED(rv)) 
    return rv;
        
  while (PR_TRUE) {
    PRBool hasMore;
    rv = cursor->HasMoreElements(&hasMore);
    if (NS_FAILED(rv)) 
      break;

    if (!hasMore) 
      break;

    nsCOMPtr<nsISupports> isupports;
    rv = cursor->GetNext(getter_AddRefs(isupports));
    if (NS_FAILED(rv)) 
      continue;

    nsCOMPtr<nsIRDFResource> source(do_QueryInterface(isupports));
    if (!source) 
      continue;

    const char       *uri = nsnull;
    source->GetValueConst(&uri);

    if (!uri) 
      continue;
            
    // never match against a "find:" URI
    if (PL_strncmp(uri, kFindProtocol, sizeof(kFindProtocol)-1) == 0)
      continue;

    // never match against a container. Searching for folders just isn't
    // much of a utility, and this fixes an infinite recursion crash. (65063)
    PRBool isContainer = PR_FALSE;

    // Check to see if this source is an RDF container
    nsCOMPtr<nsIRDFContainerUtils> cUtils(do_GetService("@mozilla.org/rdf/container-utils;1"));
    if (cUtils)
      cUtils->IsContainer(datasource, source, &isContainer);
    // Check to see if this source is a pseudo-container
    if (!isContainer)
      datasource->HasArcOut(source, kNC_Child, &isContainer);

    if (isContainer) 
      continue;

    nsCOMPtr<nsIRDFResource> property;
    rv = gRDFService->GetUnicodeResource(tokens[1].value,
    getter_AddRefs(property));

    if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE) || !property)
      continue;

    nsCOMPtr<nsIRDFNode>    value;
    rv = datasource->GetTarget(source, property,
    PR_TRUE, getter_AddRefs(value));
    if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE) || !value)
      continue;

    PRBool found = PR_FALSE;
    found = matchNode(value, tokens[2].value, tokens[3].value);

    if (found)
      array->AppendElement(source);
   }

  if (rv == NS_RDF_CURSOR_EMPTY)
    rv = NS_OK;

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 291 of file nsLocalSearchService.cpp.

{
       const char           *uri = nsnull;
       char                 *id, *token, *value, *newstr;
       int                  loop;
       nsresult             rv;

       if (NS_FAILED(rv = u->GetValueConst(&uri)))      return(rv);

#ifdef DEBUG
       printf("Find: %s\n", (const char*) uri);
#endif

       if (!(id = PL_strdup(uri + sizeof(kFindProtocol) - 1)))
              return(NS_ERROR_OUT_OF_MEMORY);

       /* parse ID, build up token list */
       if ((token = nsCRT::strtok(id, "&", &newstr)) != NULL)
       {
              while (token != NULL)
              {
                     if ((value = strstr(token, "=")) != NULL)
                     {
                            *value++ = '\0';
                     }
                     for (loop=0; tokens[loop].token != NULL; loop++)
                     {
                            if (!strcmp(token, tokens[loop].token))
                            {
                                if (!strcmp(token, "text"))
                                {
                            nsCOMPtr<nsITextToSubURI> textToSubURI = 
                                     do_GetService(kTextToSubURICID, &rv);
                            if (NS_SUCCEEDED(rv) && (textToSubURI))
                            {
                                   PRUnichar     *uni = nsnull;
                                   if (NS_SUCCEEDED(rv = textToSubURI->UnEscapeAndConvert("UTF-8", value, &uni)) && (uni))
                                   {
                                           tokens[loop].value = uni;
                                           Recycle(uni);
                                       }
                                   }
                                }
                                else
                                {
                                    nsAutoString    valueStr;
                                    valueStr.AssignWithConversion(value);
                                    tokens[loop].value = valueStr;
                         }
                                   break;
                            }
                     }
                     token = nsCRT::strtok(newstr, "&", &newstr);
              }
       }
       PL_strfree(id);
       return(NS_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Remove an observer from this data source.

Here is the caller graph for this function:

void nsIRDFDataSource::Unassert ( in nsIRDFResource  aSource,
in nsIRDFResource  aProperty,
in nsIRDFNode  aTarget 
) [inherited]

Remove an assertion from the graph.

Here is the caller graph for this function:


Member Data Documentation

Definition at line 61 of file nsLocalSearchService.h.

Definition at line 64 of file nsLocalSearchService.h.

Definition at line 67 of file nsLocalSearchService.h.

Definition at line 65 of file nsLocalSearchService.h.

Definition at line 68 of file nsLocalSearchService.h.

Definition at line 66 of file nsLocalSearchService.h.

Definition at line 69 of file nsLocalSearchService.h.

Definition at line 70 of file nsLocalSearchService.h.

Definition at line 59 of file nsLocalSearchService.h.

readonly attribute string nsIRDFDataSource::URI [inherited]

The "URI" of the data source.

This used by the RDF service's |GetDataSource()| method to cache datasources.

Definition at line 56 of file nsIRDFDataSource.idl.


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