зеркало из https://github.com/mozilla/pjs.git
Bug 374862 Port xpfe/components/search/src to frozen linkage. Original patch by Mook, one minor fixup by me,r=Neil,sr=biesi
This commit is contained in:
Родитель
553dac9928
Коммит
6107b7c50d
|
@ -1,129 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Robert John Churchill <rjc@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
|
||||
The Browser Search service
|
||||
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIRDFDataSource.idl"
|
||||
|
||||
interface nsIUnicodeDecoder;
|
||||
|
||||
[scriptable, uuid(1222e6f0-a5e3-11d2-8b7c-00805f8a7db6)]
|
||||
interface nsILocalSearchService : nsISupports
|
||||
{
|
||||
};
|
||||
|
||||
[scriptable, uuid(6bd1d803-1c67-11d3-9820-ed1b357eb3c4)]
|
||||
interface nsIInternetSearchService : nsISupports
|
||||
{
|
||||
// constants set in the whichButtons out param of GetInternetSearchURL()
|
||||
const unsigned short kHaveNext = 1;
|
||||
const unsigned short kHavePrev = 2;
|
||||
|
||||
string GetInternetSearchURL(in string searchEngineURI, in wstring searchStr, in short direction, in unsigned short pageNumber, out unsigned short whichButtons);
|
||||
void RememberLastSearchText(in wstring escapedSearchStr);
|
||||
boolean FindInternetSearchResults(in string url);
|
||||
void Stop();
|
||||
void ClearResults(in boolean flushLastSearchRef);
|
||||
void ClearResultSearchSites();
|
||||
nsIRDFDataSource GetCategoryDataSource();
|
||||
void AddSearchEngine(in string engineURL, in string iconURL,
|
||||
in wstring suggestedTitle, in wstring suggestedCategory);
|
||||
};
|
||||
|
||||
[noscript, uuid(7b171610-80ca-4d33-b16c-4186cd7b7e73)]
|
||||
interface nsIInternetSearchContext : nsISupports
|
||||
{
|
||||
const unsigned long WEB_SEARCH_CONTEXT = 1;
|
||||
|
||||
// The download of the .src file for a *new* engine.
|
||||
const unsigned long ENGINE_DOWNLOAD_NEW_CONTEXT = 2;
|
||||
|
||||
// The download of the icon file for a new engine.
|
||||
const unsigned long ICON_DOWNLOAD_NEW_CONTEXT = 3;
|
||||
|
||||
// The head request to see if we need to update the engine.
|
||||
const unsigned long ENGINE_UPDATE_HEAD_CONTEXT = 4;
|
||||
|
||||
// The download of the .src file for an engine update.
|
||||
const unsigned long ENGINE_DOWNLOAD_UPDATE_CONTEXT = 5;
|
||||
|
||||
// The download of the icon file for an engine update.
|
||||
const unsigned long ICON_DOWNLOAD_UPDATE_CONTEXT = 6;
|
||||
|
||||
// attributes
|
||||
readonly attribute unsigned long ContextType;
|
||||
|
||||
// methods
|
||||
nsIUnicodeDecoder GetUnicodeDecoder();
|
||||
nsIRDFResource GetParent();
|
||||
nsIRDFResource GetEngine();
|
||||
void GetHintConst([shared] out wstring buffer);
|
||||
void AppendBytes(in string buffer, in long numBytes);
|
||||
void AppendUnicodeBytes(in wstring buffer, in long numUniBytes);
|
||||
long GetBufferLength();
|
||||
void GetBufferConst([shared] out wstring buffer);
|
||||
void Truncate();
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
#define NS_IINTERNETSEARCHDATASOURCECALLBACK_IID \
|
||||
{ 0x88774583, 0x1edd, 0x11d3, { 0x98, 0x20, 0xbf, 0x1b, 0xe7, 0x7e, 0x61, 0xc4 } }
|
||||
|
||||
#define NS_IINTERNETSEARCHDATAOURCE_IID \
|
||||
{ 0x6bd1d803, 0x1c67, 0x11d3, { 0x98, 0x20, 0xed, 0x1b, 0x35, 0x7e, 0xb3, 0xc4 } }
|
||||
|
||||
#define NS_ILOCALSEARCHDATASOURCE_IID \
|
||||
{ 0x1222e6f0, 0xa5e3, 0x11d2, { 0x8b, 0x7c, 0x00, 0x80, 0x5f, 0x8a, 0x7d, 0xb6 } }
|
||||
|
||||
#define NS_LOCALSEARCH_SERVICE_CONTRACTID \
|
||||
"@mozilla.org/browser/localsearch-service;1"
|
||||
#define NS_LOCALSEARCH_DATASOURCE_CONTRACTID \
|
||||
"@mozilla.org/rdf/datasource;1?name=localsearch"
|
||||
|
||||
#define NS_INTERNETSEARCH_SERVICE_CONTRACTID \
|
||||
"@mozilla.org/browser/internetsearch-service;1"
|
||||
#define NS_INTERNETSEARCH_DATASOURCE_CONTRACTID \
|
||||
"@mozilla.org/rdf/datasource;1?name=internetsearch"
|
||||
|
||||
%}
|
|
@ -1,78 +0,0 @@
|
|||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1998
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = appcomps
|
||||
LIBRARY_NAME = searchservice
|
||||
SHORT_LIBNAME = srchsvc
|
||||
IS_COMPONENT = 1
|
||||
EXPORT_LIBRARY = 1
|
||||
MODULE_NAME = SearchServiceModule
|
||||
MOZILLA_INTERNAL_API = 1
|
||||
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
rdf \
|
||||
necko \
|
||||
pref \
|
||||
uconv \
|
||||
intl \
|
||||
unicharutil \
|
||||
bookmarks \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsLocalSearchService.cpp \
|
||||
nsSearchModule.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifndef MOZ_PHOENIX
|
||||
CPPSRCS += nsInternetSearchService.cpp
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
$(MOZ_UNICHARUTIL_LIBS) \
|
||||
$(MOZ_COMPONENT_LIBS) \
|
||||
$(NULL)
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,214 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsinternetsearchdatasource__h____
|
||||
#define nsinternetsearchdatasource__h____
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsISearchService.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIRDFContainerUtils.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
|
||||
class InternetSearchDataSource : public nsIInternetSearchService,
|
||||
public nsIRDFDataSource,
|
||||
public nsIStreamListener,
|
||||
public nsIObserver,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
private:
|
||||
PRInt32 mBrowserSearchMode;
|
||||
PRBool mEngineListBuilt;
|
||||
|
||||
#ifdef MOZ_PHOENIX
|
||||
PRBool mReorderedEngineList;
|
||||
#endif
|
||||
|
||||
// pseudo-constants
|
||||
nsCOMPtr<nsIRDFResource> mNC_SearchResult;
|
||||
nsCOMPtr<nsIRDFResource> mNC_SearchEngineRoot;
|
||||
nsCOMPtr<nsIRDFResource> mNC_LastSearchRoot;
|
||||
nsCOMPtr<nsIRDFResource> mNC_LastSearchMode;
|
||||
nsCOMPtr<nsIRDFResource> mNC_SearchCategoryRoot;
|
||||
nsCOMPtr<nsIRDFResource> mNC_SearchResultsSitesRoot;
|
||||
nsCOMPtr<nsIRDFResource> mNC_FilterSearchURLsRoot;
|
||||
nsCOMPtr<nsIRDFResource> mNC_FilterSearchSitesRoot;
|
||||
nsCOMPtr<nsIRDFResource> mNC_SearchType;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Ref;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Child;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Title;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Data;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Name;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Description;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Version;
|
||||
nsCOMPtr<nsIRDFResource> mNC_actionButton;
|
||||
nsCOMPtr<nsIRDFResource> mNC_actionBar;
|
||||
nsCOMPtr<nsIRDFResource> mNC_searchForm;
|
||||
nsCOMPtr<nsIRDFResource> mNC_LastText;
|
||||
nsCOMPtr<nsIRDFResource> mNC_URL;
|
||||
nsCOMPtr<nsIRDFResource> mRDF_InstanceOf;
|
||||
nsCOMPtr<nsIRDFResource> mRDF_type;
|
||||
nsCOMPtr<nsIRDFResource> mNC_loading;
|
||||
nsCOMPtr<nsIRDFResource> mNC_HTML;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Icon;
|
||||
nsCOMPtr<nsIRDFResource> mNC_StatusIcon;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Banner;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Site;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Relevance;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Date;
|
||||
nsCOMPtr<nsIRDFResource> mNC_RelevanceSort;
|
||||
nsCOMPtr<nsIRDFResource> mNC_PageRank;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Engine;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Price;
|
||||
nsCOMPtr<nsIRDFResource> mNC_PriceSort;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Availability;
|
||||
nsCOMPtr<nsIRDFResource> mNC_BookmarkSeparator;
|
||||
nsCOMPtr<nsIRDFResource> mNC_Update;
|
||||
nsCOMPtr<nsIRDFResource> mNC_UpdateIcon;
|
||||
nsCOMPtr<nsIRDFResource> mNC_UpdateCheckDays;
|
||||
nsCOMPtr<nsIRDFResource> mWEB_LastPingDate;
|
||||
nsCOMPtr<nsIRDFResource> mWEB_LastPingModDate;
|
||||
nsCOMPtr<nsIRDFResource> mWEB_LastPingContentLen;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> mNC_SearchCommand_AddToBookmarks;
|
||||
nsCOMPtr<nsIRDFResource> mNC_SearchCommand_AddQueryToBookmarks;
|
||||
nsCOMPtr<nsIRDFResource> mNC_SearchCommand_FilterResult;
|
||||
nsCOMPtr<nsIRDFResource> mNC_SearchCommand_FilterSite;
|
||||
nsCOMPtr<nsIRDFResource> mNC_SearchCommand_ClearFilters;
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> mTrueLiteral;
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIRDFService> mRDFService;
|
||||
nsCOMPtr<nsIRDFContainerUtils> mRDFC;
|
||||
nsCOMPtr<nsIRDFDataSource> mInner;
|
||||
nsCOMPtr<nsIRDFDataSource> mLocalstore;
|
||||
nsCOMPtr<nsISupportsArray> mUpdateArray;
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
nsCOMPtr<nsILoadGroup> mBackgroundLoadGroup;
|
||||
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
||||
nsCOMPtr<nsIRDFDataSource> categoryDataSource;
|
||||
PRBool busySchedule;
|
||||
nsCOMPtr<nsIRDFResource> busyResource;
|
||||
nsString mQueryEncodingStr;
|
||||
|
||||
friend int PR_CALLBACK searchModePrefCallback(const char *pref, void *aClosure);
|
||||
|
||||
// helper methods
|
||||
nsresult GetSearchEngineToPing(nsIRDFResource **theResource, nsCString &updateURL);
|
||||
PRBool isEngineURI(nsIRDFResource* aResource);
|
||||
PRBool isSearchURI(nsIRDFResource* aResource);
|
||||
PRBool isSearchCategoryURI(nsIRDFResource* aResource);
|
||||
PRBool isSearchCategoryEngineURI(nsIRDFResource* aResource);
|
||||
PRBool isSearchCategoryEngineBasenameURI(nsIRDFNode *aResource);
|
||||
PRBool isSearchCommand(nsIRDFResource* aResource);
|
||||
nsresult resolveSearchCategoryEngineURI(nsIRDFResource *source, nsIRDFResource **trueEngine);
|
||||
nsresult BeginSearchRequest(nsIRDFResource *source, PRBool doNetworkRequest);
|
||||
nsresult FindData(nsIRDFResource *engine, nsIRDFLiteral **data);
|
||||
nsresult EngineFileFromResource(nsIRDFResource *aEngineResource,
|
||||
nsILocalFile **aResult);
|
||||
nsresult updateDataHintsInGraph(nsIRDFResource *engine, const PRUnichar *data);
|
||||
nsresult updateAtom(nsIRDFDataSource *db, nsIRDFResource *src, nsIRDFResource *prop, nsIRDFNode *newValue, PRBool *dirtyFlag);
|
||||
nsresult validateEngine(nsIRDFResource *engine);
|
||||
nsresult DoSearch(nsIRDFResource *source, nsIRDFResource *engine, const nsString &fullURL, const nsString &text);
|
||||
nsresult MapEncoding(const nsString &numericEncoding,
|
||||
nsString &stringEncoding);
|
||||
const char * const MapScriptCodeToCharsetName(PRUint32 aScriptCode);
|
||||
nsresult SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon, const PRUnichar *hint, const PRUnichar *data, PRBool isSystemSearchFile);
|
||||
nsresult GetSearchEngineList(nsIFile *spec, PRBool isSystemSearchFile);
|
||||
nsresult GetCategoryList();
|
||||
nsresult ReadFileContents(nsILocalFile *baseFilename, nsString & sourceContents);
|
||||
nsresult DecodeData(const char *aCharset, const PRUnichar *aInString, PRUnichar **aOutString);
|
||||
nsresult GetData(const PRUnichar *data, const char *sectionToFind, PRUint32 sectionNum, const char *attribToFind, nsString &value);
|
||||
nsresult GetNumInterpretSections(const PRUnichar *data, PRUint32 &numInterpretSections);
|
||||
nsresult GetInputs(const PRUnichar *data, nsString &engineName, nsString &userVar, const nsString &text, nsString &input, PRInt16 direction, PRUint16 pageNumber, PRUint16 *whichButtons);
|
||||
PRInt32 computeIndex(nsAutoString &factor, PRUint16 page, PRInt16 direction);
|
||||
nsresult GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult);
|
||||
nsresult validateEngineNow(nsIRDFResource *engine);
|
||||
nsresult webSearchFinalize(nsIChannel *channel, nsIInternetSearchContext *context);
|
||||
nsresult ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRDFResource *engine, const PRUnichar *htmlPage, PRInt32 htmlPageSize);
|
||||
nsresult SetHint(nsIRDFResource *mParent, nsIRDFResource *hintRes);
|
||||
nsresult ConvertEntities(nsString &str, PRBool removeHTMLFlag = PR_TRUE, PRBool removeCRLFsFlag = PR_TRUE, PRBool trimWhiteSpaceFlag = PR_TRUE);
|
||||
nsresult saveContents(nsIChannel* channel, nsIInternetSearchContext *context, PRUint32 contextType);
|
||||
PRBool getSearchURI(nsIRDFResource *src, nsAString &_retval); // returns true on success
|
||||
nsresult addToBookmarks(nsIRDFResource *src);
|
||||
nsresult addQueryToBookmarks(nsIRDFResource *src);
|
||||
nsresult filterResult(nsIRDFResource *src);
|
||||
nsresult filterSite(nsIRDFResource *src);
|
||||
nsresult clearFilters(void);
|
||||
PRBool isSearchResultFiltered(const nsString &href);
|
||||
#ifdef MOZ_PHOENIX
|
||||
void ReorderEngineList();
|
||||
#endif
|
||||
|
||||
static void FireTimer(nsITimer* aTimer, void* aClosure);
|
||||
|
||||
// Just like AddSearchEngine, but with an extra parameter to include the
|
||||
// nsIRDFResource of an existing engines. If this is a new search engine
|
||||
// aOldEngineResource should be null.
|
||||
nsresult AddSearchEngineInternal(const char *engineURL,
|
||||
const char *iconURL,
|
||||
const PRUnichar *suggestedTitle,
|
||||
const PRUnichar *suggestedCategory,
|
||||
nsIRDFResource *aOldEngineResource);
|
||||
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(InternetSearchDataSource,
|
||||
nsIInternetSearchService)
|
||||
NS_DECL_NSIINTERNETSEARCHSERVICE
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
NS_DECL_NSIRDFDATASOURCE
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
InternetSearchDataSource(void);
|
||||
virtual ~InternetSearchDataSource(void);
|
||||
NS_METHOD Init();
|
||||
void DeferredInit();
|
||||
};
|
||||
|
||||
#endif // nsinternetsearchdatasource__h____
|
|
@ -1,937 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8; c-file-style: "stroustrup" -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Robert John Churchill <rjc@netscape.com>
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
Implementation for a find RDF data store.
|
||||
*/
|
||||
|
||||
#include "nsLocalSearchService.h"
|
||||
#include "nscore.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIRDFContainerUtils.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "plhash.h"
|
||||
#include "plstr.h"
|
||||
#include "prmem.h"
|
||||
#include "prprf.h"
|
||||
#include "prio.h"
|
||||
#include "prlog.h"
|
||||
#include "nsITextToSubURI.h"
|
||||
#include "nsIRDFObserver.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "rdf.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kTextToSubURICID, NS_TEXTTOSUBURI_CID);
|
||||
|
||||
static nsIRDFService *gRDFService = nsnull;
|
||||
static LocalSearchDataSource *gLocalSearchDataSource = nsnull;
|
||||
static const char kFindProtocol[] = "find:";
|
||||
|
||||
static PRBool
|
||||
isFindURI(nsIRDFResource *r)
|
||||
{
|
||||
PRBool isFindURIFlag = PR_FALSE;
|
||||
const char *uri = nsnull;
|
||||
|
||||
r->GetValueConst(&uri);
|
||||
if ((uri) && (!strncmp(uri, kFindProtocol, sizeof(kFindProtocol) - 1)))
|
||||
{
|
||||
isFindURIFlag = PR_TRUE;
|
||||
}
|
||||
return(isFindURIFlag);
|
||||
}
|
||||
|
||||
|
||||
PRInt32 LocalSearchDataSource::gRefCnt;
|
||||
nsIRDFResource *LocalSearchDataSource::kNC_Child;
|
||||
nsIRDFResource *LocalSearchDataSource::kNC_Name;
|
||||
nsIRDFResource *LocalSearchDataSource::kNC_URL;
|
||||
nsIRDFResource *LocalSearchDataSource::kNC_FindObject;
|
||||
nsIRDFResource *LocalSearchDataSource::kNC_pulse;
|
||||
nsIRDFResource *LocalSearchDataSource::kRDF_InstanceOf;
|
||||
nsIRDFResource *LocalSearchDataSource::kRDF_type;
|
||||
|
||||
LocalSearchDataSource::LocalSearchDataSource(void)
|
||||
{
|
||||
if (gRefCnt++ == 0)
|
||||
{
|
||||
nsresult rv = CallGetService(kRDFServiceCID, &gRDFService);
|
||||
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "child"),
|
||||
&kNC_Child);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Name"),
|
||||
&kNC_Name);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "URL"),
|
||||
&kNC_URL);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "FindObject"),
|
||||
&kNC_FindObject);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "pulse"),
|
||||
&kNC_pulse);
|
||||
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "instanceOf"),
|
||||
&kRDF_InstanceOf);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "type"),
|
||||
&kRDF_type);
|
||||
|
||||
gLocalSearchDataSource = this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
LocalSearchDataSource::~LocalSearchDataSource (void)
|
||||
{
|
||||
if (--gRefCnt == 0)
|
||||
{
|
||||
NS_RELEASE(kNC_Child);
|
||||
NS_RELEASE(kNC_Name);
|
||||
NS_RELEASE(kNC_URL);
|
||||
NS_RELEASE(kNC_FindObject);
|
||||
NS_RELEASE(kNC_pulse);
|
||||
NS_RELEASE(kRDF_InstanceOf);
|
||||
NS_RELEASE(kRDF_type);
|
||||
|
||||
gLocalSearchDataSource = nsnull;
|
||||
NS_RELEASE(gRDFService);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
LocalSearchDataSource::Init()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS1(LocalSearchDataSource, nsIRDFDataSource)
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::GetURI(char **uri)
|
||||
{
|
||||
NS_PRECONDITION(uri != nsnull, "null ptr");
|
||||
if (! uri)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if ((*uri = nsCRT::strdup("rdf:localsearch")) == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::GetSource(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFResource** source /* out */)
|
||||
{
|
||||
NS_PRECONDITION(property != nsnull, "null ptr");
|
||||
if (! property)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(target != nsnull, "null ptr");
|
||||
if (! target)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(source != nsnull, "null ptr");
|
||||
if (! source)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*source = nsnull;
|
||||
return NS_RDF_NO_VALUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::GetSources(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsISimpleEnumerator **sources /* out */)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("write me");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::GetTarget(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFNode **target /* out */)
|
||||
{
|
||||
NS_PRECONDITION(source != nsnull, "null ptr");
|
||||
if (! source)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(property != nsnull, "null ptr");
|
||||
if (! property)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(target != nsnull, "null ptr");
|
||||
if (! target)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv = NS_RDF_NO_VALUE;
|
||||
|
||||
// we only have positive assertions in the find data source.
|
||||
if (! tv)
|
||||
return rv;
|
||||
|
||||
if (isFindURI(source))
|
||||
{
|
||||
if (property == kNC_Name)
|
||||
{
|
||||
// rv = GetName(source, &array);
|
||||
}
|
||||
else if (property == kNC_URL)
|
||||
{
|
||||
// note: lie and say there is no URL
|
||||
// rv = GetURL(source, &array);
|
||||
nsAutoString url;
|
||||
nsIRDFLiteral *literal;
|
||||
rv = gRDFService->GetLiteral(url.get(), &literal);
|
||||
*target = literal;
|
||||
return rv;
|
||||
}
|
||||
else if (property == kRDF_type)
|
||||
{
|
||||
const char *uri = nsnull;
|
||||
rv = kNC_FindObject->GetValueConst(&uri);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ConvertUTF8toUTF16 url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
rv = gRDFService->GetLiteral(url.get(), &literal);
|
||||
|
||||
*target = literal;
|
||||
return rv;
|
||||
}
|
||||
else if (property == kNC_pulse)
|
||||
{
|
||||
nsAutoString pulse(NS_LITERAL_STRING("15"));
|
||||
nsIRDFLiteral *pulseLiteral;
|
||||
rv = gRDFService->GetLiteral(pulse.get(), &pulseLiteral);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*target = pulseLiteral;
|
||||
return NS_OK;
|
||||
}
|
||||
else if (property == kNC_Child)
|
||||
{
|
||||
// fake out the generic builder (i.e. return anything in this case)
|
||||
// so that search containers never appear to be empty
|
||||
*target = source;
|
||||
NS_ADDREF(*target);
|
||||
return(NS_OK);
|
||||
}
|
||||
}
|
||||
return NS_RDF_NO_VALUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_METHOD
|
||||
LocalSearchDataSource::parseResourceIntoFindTokens(nsIRDFResource *u, findTokenPtr tokens)
|
||||
{
|
||||
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.Adopt(uni);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CopyASCIItoUTF16(value, tokens[loop].value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
token = nsCRT::strtok(newstr, "&", &newstr);
|
||||
}
|
||||
}
|
||||
PL_strfree(id);
|
||||
return(NS_OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRBool
|
||||
LocalSearchDataSource::doMatch(nsIRDFLiteral *literal,
|
||||
const nsAString &matchMethod,
|
||||
const nsString &matchText)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
PRBool
|
||||
LocalSearchDataSource::doDateMatch(nsIRDFDate *aDate,
|
||||
const nsAString& matchMethod,
|
||||
const nsAString& matchText)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
PRBool
|
||||
LocalSearchDataSource::doIntMatch(nsIRDFInt *aInt,
|
||||
const nsAString& matchMethod,
|
||||
const nsString& matchText)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
LocalSearchDataSource::parseDate(const nsAString& aDate,
|
||||
PRInt64 *aResult)
|
||||
{
|
||||
// date is in the form of msec since epoch, but use NSPR to
|
||||
// parse the time
|
||||
PRTime *outTime = static_cast<PRTime*>(aResult);
|
||||
PRStatus err;
|
||||
err = PR_ParseTimeString(NS_ConvertUTF16toUTF8(aDate).get(),
|
||||
PR_FALSE, // PR_FALSE == use current timezone
|
||||
outTime);
|
||||
NS_ENSURE_TRUE(err == 0, NS_ERROR_FAILURE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
LocalSearchDataSource::dateMatches(nsIRDFDate *aDate,
|
||||
const nsAString& method,
|
||||
const PRInt64& matchDate)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
NS_METHOD
|
||||
LocalSearchDataSource::parseFindURL(nsIRDFResource *u, nsISupportsArray *array)
|
||||
{
|
||||
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.Assign(NS_LossyConvertUTF16toASCII(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;
|
||||
}
|
||||
|
||||
// could speed up date/integer matching signifigantly by caching the
|
||||
// last successful match data type (i.e. string, date, int) and trying
|
||||
// to QI against that first
|
||||
PRBool
|
||||
LocalSearchDataSource::matchNode(nsIRDFNode *aValue,
|
||||
const nsAString& matchMethod,
|
||||
const nsString& matchText)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
LocalSearchDataSource::getFindResults(nsIRDFResource *source, nsISimpleEnumerator** aResult)
|
||||
{
|
||||
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;
|
||||
|
||||
return NS_NewArrayEnumerator(aResult, nameArray);
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_METHOD
|
||||
LocalSearchDataSource::getFindName(nsIRDFResource *source, nsIRDFLiteral** aResult)
|
||||
{
|
||||
// XXX construct find URI human-readable name
|
||||
*aResult = nsnull;
|
||||
return(NS_OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::GetTargets(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsISimpleEnumerator **targets /* out */)
|
||||
{
|
||||
NS_PRECONDITION(source != nsnull, "null ptr");
|
||||
if (! source)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(property != nsnull, "null ptr");
|
||||
if (! property)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(targets != nsnull, "null ptr");
|
||||
if (! targets)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
// we only have positive assertions in the find data source.
|
||||
if (! tv)
|
||||
return rv;
|
||||
|
||||
if (isFindURI(source))
|
||||
{
|
||||
if (property == kNC_Child)
|
||||
{
|
||||
return getFindResults(source, targets);
|
||||
}
|
||||
else if (property == kNC_Name)
|
||||
{
|
||||
nsCOMPtr<nsIRDFLiteral> name;
|
||||
rv = getFindName(source, getter_AddRefs(name));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_NewSingletonEnumerator(targets, name);
|
||||
}
|
||||
else if (property == kRDF_type)
|
||||
{
|
||||
const char *uri = nsnull;
|
||||
rv = kNC_FindObject->GetValueConst( &uri );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> literal;
|
||||
rv = gRDFService->GetLiteral(NS_ConvertUTF8toUTF16(uri).get(),
|
||||
getter_AddRefs(literal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_NewSingletonEnumerator(targets, literal);
|
||||
}
|
||||
else if (property == kNC_pulse)
|
||||
{
|
||||
nsAutoString pulse(NS_LITERAL_STRING("15"));
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> pulseLiteral;
|
||||
rv = gRDFService->GetLiteral(pulse.get(),
|
||||
getter_AddRefs(pulseLiteral));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_NewSingletonEnumerator(targets, pulseLiteral);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_NewEmptyEnumerator(targets);
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::Assert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv)
|
||||
{
|
||||
return NS_RDF_ASSERTION_REJECTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::Unassert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target)
|
||||
{
|
||||
return NS_RDF_ASSERTION_REJECTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::Change(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aOldTarget,
|
||||
nsIRDFNode* aNewTarget)
|
||||
{
|
||||
return NS_RDF_ASSERTION_REJECTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::Move(nsIRDFResource* aOldSource,
|
||||
nsIRDFResource* aNewSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget)
|
||||
{
|
||||
return NS_RDF_ASSERTION_REJECTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::HasAssertion(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
PRBool *hasAssertion /* out */)
|
||||
{
|
||||
NS_PRECONDITION(source != nsnull, "null ptr");
|
||||
if (! source)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(property != nsnull, "null ptr");
|
||||
if (! property)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(target != nsnull, "null ptr");
|
||||
if (! target)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(hasAssertion != nsnull, "null ptr");
|
||||
if (! hasAssertion)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
*hasAssertion = PR_FALSE;
|
||||
|
||||
// we only have positive assertions in the find data source.
|
||||
if (! tv)
|
||||
return rv;
|
||||
|
||||
if (isFindURI(source))
|
||||
{
|
||||
if (property == kRDF_type)
|
||||
{
|
||||
if ((nsIRDFResource *)target == kRDF_type)
|
||||
{
|
||||
*hasAssertion = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (rv);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, PRBool *result)
|
||||
{
|
||||
*result = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::HasArcOut(nsIRDFResource *source, nsIRDFResource *aArc, PRBool *result)
|
||||
{
|
||||
NS_PRECONDITION(source != nsnull, "null ptr");
|
||||
if (! source)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if ((aArc == kNC_Child ||
|
||||
aArc == kNC_pulse)) {
|
||||
*result = isFindURI(source);
|
||||
}
|
||||
else {
|
||||
*result = PR_FALSE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::ArcLabelsIn(nsIRDFNode *node,
|
||||
nsISimpleEnumerator ** labels /* out */)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("write me");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::ArcLabelsOut(nsIRDFResource *source,
|
||||
nsISimpleEnumerator **labels /* out */)
|
||||
{
|
||||
NS_PRECONDITION(source != nsnull, "null ptr");
|
||||
if (! source)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(labels != nsnull, "null ptr");
|
||||
if (! labels)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
if (isFindURI(source))
|
||||
{
|
||||
nsCOMPtr<nsISupportsArray> array;
|
||||
rv = NS_NewISupportsArray( getter_AddRefs(array) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
array->AppendElement(kNC_Child);
|
||||
array->AppendElement(kNC_pulse);
|
||||
|
||||
return NS_NewArrayEnumerator(labels, array);
|
||||
}
|
||||
return(NS_NewEmptyEnumerator(labels));
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::GetAllResources(nsISimpleEnumerator** aCursor)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("sorry!");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::AddObserver(nsIRDFObserver *n)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::RemoveObserver(nsIRDFObserver *n)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::GetAllCmds(nsIRDFResource* source, nsISimpleEnumerator/*<nsIRDFResource>*/** commands)
|
||||
{
|
||||
return(NS_NewEmptyEnumerator(commands));
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments,
|
||||
PRBool* aResult)
|
||||
{
|
||||
return(NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments)
|
||||
{
|
||||
return(NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::BeginUpdateBatch()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocalSearchDataSource::EndUpdateBatch()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef localsearchdb___h_____
|
||||
#define localsearchdb___h_____
|
||||
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsISearchService.h"
|
||||
|
||||
typedef struct _findTokenStruct
|
||||
{
|
||||
const char *token;
|
||||
nsString value;
|
||||
} findTokenStruct, *findTokenPtr;
|
||||
|
||||
|
||||
class LocalSearchDataSource : public nsIRDFDataSource
|
||||
{
|
||||
private:
|
||||
static PRInt32 gRefCnt;
|
||||
|
||||
// pseudo-constants
|
||||
static nsIRDFResource *kNC_Child;
|
||||
static nsIRDFResource *kNC_Name;
|
||||
static nsIRDFResource *kNC_URL;
|
||||
static nsIRDFResource *kNC_FindObject;
|
||||
static nsIRDFResource *kNC_pulse;
|
||||
static nsIRDFResource *kRDF_InstanceOf;
|
||||
static nsIRDFResource *kRDF_type;
|
||||
|
||||
protected:
|
||||
|
||||
NS_METHOD getFindResults(nsIRDFResource *source, nsISimpleEnumerator** aResult);
|
||||
NS_METHOD getFindName(nsIRDFResource *source, nsIRDFLiteral** aResult);
|
||||
NS_METHOD parseResourceIntoFindTokens(nsIRDFResource *u, findTokenPtr tokens);
|
||||
|
||||
// matching functions, based on type
|
||||
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);
|
||||
|
||||
public:
|
||||
LocalSearchDataSource(void);
|
||||
virtual ~LocalSearchDataSource(void);
|
||||
nsresult Init();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSILOCALSEARCHSERVICE
|
||||
NS_DECL_NSIRDFDATASOURCE
|
||||
};
|
||||
|
||||
#endif // localsearchdb___h_____
|
Загрузка…
Ссылка в новой задаче