Check in search changes to add support for shopping.

This commit is contained in:
rjc%netscape.com 1999-12-23 11:56:24 +00:00
Родитель a342c44397
Коммит fbe93c2b98
11 изменённых файлов: 609 добавлений и 127 удалений

Просмотреть файл

@ -244,6 +244,10 @@ private:
static nsIRDFResource *kNC_RelevanceSort;
static nsIRDFResource *kNC_Engine;
static nsIRDFResource *kNC_Price;
static nsIRDFResource *kNC_PriceSort;
static nsIRDFResource *kNC_Availability;
protected:
static nsIRDFDataSource *mInner;
@ -268,6 +272,7 @@ static nsresult GetData(nsString &data, const char *sectionToFind, const char *a
nsresult GetInputs(const nsString &data, nsString &userVar, const nsString &text, nsString &input);
nsresult GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult);
nsresult ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRDFResource *engine, const nsString &htmlPage, PRBool useAllHREFsFlag, PRUint32 &numResults);
nsresult SetHint(nsIRDFResource *mParent, nsIRDFResource *hintRes);
InternetSearchDataSource(void);
virtual ~InternetSearchDataSource(void);
@ -319,7 +324,9 @@ nsIRDFResource *InternetSearchDataSource::kNC_Site;
nsIRDFResource *InternetSearchDataSource::kNC_Relevance;
nsIRDFResource *InternetSearchDataSource::kNC_RelevanceSort;
nsIRDFResource *InternetSearchDataSource::kNC_Engine;
nsIRDFResource *InternetSearchDataSource::kNC_Price;
nsIRDFResource *InternetSearchDataSource::kNC_PriceSort;
nsIRDFResource *InternetSearchDataSource::kNC_Availability;
static const char kEngineProtocol[] = "engine://";
@ -361,6 +368,9 @@ InternetSearchDataSource::InternetSearchDataSource(void)
gRDFService->GetResource(NC_NAMESPACE_URI "Relevance", &kNC_Relevance);
gRDFService->GetResource(NC_NAMESPACE_URI "Relevance?sort=true", &kNC_RelevanceSort);
gRDFService->GetResource(NC_NAMESPACE_URI "Engine", &kNC_Engine);
gRDFService->GetResource(NC_NAMESPACE_URI "Price", &kNC_Price);
gRDFService->GetResource(NC_NAMESPACE_URI "Price?sort=true", &kNC_PriceSort);
gRDFService->GetResource(NC_NAMESPACE_URI "Availability", &kNC_Availability);
}
}
@ -391,6 +401,9 @@ InternetSearchDataSource::~InternetSearchDataSource (void)
NS_IF_RELEASE(kNC_Relevance);
NS_IF_RELEASE(kNC_RelevanceSort);
NS_IF_RELEASE(kNC_Engine);
NS_IF_RELEASE(kNC_Price);
NS_IF_RELEASE(kNC_PriceSort);
NS_IF_RELEASE(kNC_Availability);
NS_IF_RELEASE(mInner);
@ -2302,25 +2315,6 @@ InternetSearchDataSource::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
rv = channel->GetURI(getter_AddRefs(aURL));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFLiteral> trueLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(nsAutoString("true").GetUnicode(), getter_AddRefs(trueLiteral))))
{
mInner->Unassert(mEngine, kNC_loading, trueLiteral);
if (mConnections)
{
PRUint32 count=0;
mConnections->Count(&count);
if (count <= 1)
{
if (mParent)
{
mInner->Unassert(mParent, kNC_loading, trueLiteral);
}
}
}
}
// copy the engine's icon reference (if it has one) onto the result node
nsCOMPtr<nsIRDFNode> engineIconStatusNode = nsnull;
mInner->GetTarget(mEngine, kNC_Icon, PR_TRUE, getter_AddRefs(engineIconStatusNode));
@ -2330,40 +2324,62 @@ InternetSearchDataSource::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
}
PRUnichar *uniBuf = nsnull;
if (NS_FAILED(rv = context->GetBuffer(&uniBuf))) return(rv);
if (!uniBuf) return(NS_ERROR_UNEXPECTED);
nsAutoString htmlResults(uniBuf);
if (htmlResults.Length() < 1)
if (NS_SUCCEEDED(rv = context->GetBuffer(&uniBuf)) && (uniBuf))
{
#ifdef DEBUG_SEARCH_OUTPUT
printf(" *** InternetSearchDataSourceCallback::OnStopRequest: no data.\n\n");
#endif
return(NS_OK);
}
// Note: don't free uniBuf, its really a const *
if (NS_FAILED(rv = context->Truncate())) return(rv);
if (mParent)
{
// save HTML result page for this engine
const PRUnichar *htmlUni = htmlResults.GetUnicode();
if (htmlUni)
nsAutoString htmlResults(uniBuf);
context->Truncate();
if (htmlResults.Length() > 0)
{
nsCOMPtr<nsIRDFLiteral> htmlLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(htmlUni, getter_AddRefs(htmlLiteral))))
if (mParent)
{
rv = mInner->Assert(mEngine, kNC_HTML, htmlLiteral, PR_TRUE);
// save HTML result page for this engine
const PRUnichar *htmlUni = htmlResults.GetUnicode();
if (htmlUni)
{
nsCOMPtr<nsIRDFLiteral> htmlLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(htmlUni, getter_AddRefs(htmlLiteral))))
{
rv = mInner->Assert(mEngine, kNC_HTML, htmlLiteral, PR_TRUE);
}
}
}
// parse up HTML results
PRUint32 numResults = 0;
rv = ParseHTML(aURL, mParent, mEngine, htmlResults, PR_FALSE, numResults);
if (NS_SUCCEEDED(rv) && (!mParent) && (numResults == 0))
{
rv = ParseHTML(aURL, mParent, mEngine, htmlResults, PR_TRUE, numResults);
}
}
else
{
#ifdef DEBUG_SEARCH_OUTPUT
printf(" *** InternetSearchDataSourceCallback::OnStopRequest: no data.\n\n");
#endif
}
}
PRUint32 numResults = 0;
rv = ParseHTML(aURL, mParent, mEngine, htmlResults, PR_FALSE, numResults);
if (NS_SUCCEEDED(rv) && (!mParent) && (numResults == 0))
// (do this last) potentially remove the loading attribute
nsCOMPtr<nsIRDFLiteral> trueLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(nsAutoString("true").GetUnicode(), getter_AddRefs(trueLiteral))))
{
rv = ParseHTML(aURL, mParent, mEngine, htmlResults, PR_TRUE, numResults);
mInner->Unassert(mEngine, kNC_loading, trueLiteral);
if (mConnections)
{
PRUint32 count=0;
mConnections->Count(&count);
if (count < 1)
{
if (mParent)
{
mInner->Unassert(mParent, kNC_loading, trueLiteral);
}
}
}
}
return(NS_OK);
@ -2381,6 +2397,7 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
nsAutoString resultItemStartStr, resultItemEndStr;
nsAutoString relevanceStartStr, relevanceEndStr;
nsAutoString bannerStartStr, bannerEndStr, skiplocalStr;
nsAutoString priceStartStr, priceEndStr, availStartStr, availEndStr;
PRBool skipLocalFlag = PR_FALSE;
nsresult rv;
@ -2425,6 +2442,11 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
GetData(data, "search", "name", engineStr);
GetData(data, "interpret", "priceStart", priceStartStr);
GetData(data, "interpret", "priceEnd", priceEndStr);
GetData(data, "interpret", "availStart", availStartStr);
GetData(data, "interpret", "availEnd", availEndStr);
#ifdef DEBUG_SEARCH_OUTPUT
char *cStr;
cStr = resultListStartStr.ToNewCString();
@ -2558,6 +2580,8 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
trimItemEnd = PR_FALSE;
}
PRBool hasPriceFlag = PR_FALSE, hasAvailabilityFlag = PR_FALSE, hasRelevanceFlag = PR_FALSE;
while(PR_TRUE)
{
PRInt32 resultItemStart;
@ -2679,10 +2703,7 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
}
}
char *href = hrefStr.ToNewCString();
if (!href) continue;
nsAutoString site(href);
nsAutoString site(hrefStr);
#ifdef DEBUG_SEARCH_OUTPUT
printf("HREF: '%s'\n", href);
@ -2692,7 +2713,7 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
// #define OLDWAY
#ifdef OLDWAY
rv = gRDFService->GetResource(href, getter_AddRefs(res));
rv = gRDFService->GetResource(nsCAutoString(hrefStr), getter_AddRefs(res));
#else
// save HREF attribute as URL
if (NS_SUCCEEDED(rv = gRDFService->GetAnonymousResource(getter_AddRefs(res))))
@ -2708,9 +2729,6 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
}
}
#endif
nsCRT::free(href);
href = nsnull;
if (NS_FAILED(rv)) continue;
// set HTML response chunk
@ -2873,6 +2891,106 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
}
}
// look for price
nsAutoString priceItem;
PRInt32 priceStart;
if ((priceStart = resultItem.Find(priceStartStr, PR_TRUE)) >= 0)
{
PRInt32 priceEnd = resultItem.Find(priceEndStr, PR_TRUE, priceStart + priceStartStr.Length());
if (priceEnd > priceStart)
{
resultItem.Mid(priceItem, priceStart + priceStartStr.Length(),
priceEnd - priceStart - priceStartStr.Length());
// munge out anything inside of HTML "<" / ">" tags
PRInt32 priceTagStartOffset;
while ((priceTagStartOffset = priceItem.FindCharInSet("<", 0)) >= 0)
{
PRInt32 priceTagEndOffset = priceItem.FindCharInSet(">", priceTagStartOffset);
if (priceTagEndOffset <= priceTagStartOffset) break;
priceItem.Cut(priceTagStartOffset, priceTagEndOffset - priceTagStartOffset + 1);
}
// cut out any CRs or LFs
PRInt32 priceEOLOffset;
while ((priceEOLOffset = priceItem.FindCharInSet("\n\r", 0)) >= 0)
{
priceItem.Cut(priceEOLOffset, 1);
}
}
}
if (priceItem.Length() > 0)
{
const PRUnichar *priceUni = priceItem.GetUnicode();
nsCOMPtr<nsIRDFLiteral> priceLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(priceUni, getter_AddRefs(priceLiteral))))
{
if (priceLiteral)
{
mInner->Assert(res, kNC_Price, priceLiteral, PR_TRUE);
hasPriceFlag = PR_TRUE;
}
}
PRInt32 priceCharStartOffset = priceItem.FindCharInSet("1234567890");
if (priceCharStartOffset >= 0)
{
priceItem.Cut(0, priceCharStartOffset);
PRInt32 priceErr;
float val = priceItem.ToFloat(&priceErr);
if (priceItem.FindChar(PRUnichar('.')) >= 0) val *= 100;
nsCOMPtr<nsIRDFInt> priceSortLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetIntLiteral((PRInt32)val, getter_AddRefs(priceSortLiteral))))
{
if (priceSortLiteral)
{
mInner->Assert(res, kNC_PriceSort, priceSortLiteral, PR_TRUE);
}
}
}
}
// look for availability
nsAutoString availItem;
PRInt32 availStart;
if ((availStart = resultItem.Find(availStartStr, PR_TRUE)) >= 0)
{
PRInt32 availEnd = resultItem.Find(availEndStr, PR_TRUE, availStart + availStartStr.Length());
if (availEnd > availStart)
{
resultItem.Mid(availItem, availStart + availStartStr.Length(),
availEnd - availStart - availStartStr.Length());
// munge out anything inside of HTML "<" / ">" tags
PRInt32 availTagStartOffset;
while ((availTagStartOffset = availItem.FindCharInSet("<", 0)) >= 0)
{
PRInt32 availTagEndOffset = availItem.FindCharInSet(">", availTagStartOffset);
if (availTagEndOffset <= availTagStartOffset) break;
availItem.Cut(availTagStartOffset, availTagEndOffset - availTagStartOffset + 1);
}
// cut out any CRs or LFs
PRInt32 availEOLOffset;
while ((availEOLOffset = availItem.FindCharInSet("\n\r", 0)) >= 0)
{
availItem.Cut(availEOLOffset, 1);
}
}
}
if (availItem.Length() > 0)
{
const PRUnichar *availUni = availItem.GetUnicode();
nsCOMPtr<nsIRDFLiteral> availLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(availUni, getter_AddRefs(availLiteral))))
{
if (availLiteral)
{
mInner->Assert(res, kNC_Availability, availLiteral, PR_TRUE);
hasAvailabilityFlag = PR_TRUE;
}
}
}
// look for relevance
nsAutoString relItem;
PRInt32 relStart;
@ -2923,6 +3041,7 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
relStr += PRUnichar('%');
}
relItem = relStr;
hasRelevanceFlag = PR_TRUE;
}
else
{
@ -3033,5 +3152,32 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
++numResults;
}
// set hints so that the appropriate columns can be displayed
if (hasPriceFlag == PR_TRUE) SetHint(mParent, kNC_Price);
if (hasAvailabilityFlag == PR_TRUE) SetHint(mParent, kNC_Availability);
if (hasRelevanceFlag == PR_TRUE) SetHint(mParent, kNC_Relevance);
return(NS_OK);
}
nsresult
InternetSearchDataSource::SetHint(nsIRDFResource *mParent, nsIRDFResource *hintRes)
{
if (!mInner) return(NS_OK);
nsresult rv;
nsCOMPtr<nsIRDFLiteral> trueLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(nsAutoString("true").GetUnicode(), getter_AddRefs(trueLiteral))))
{
PRBool hasAssertionFlag = PR_FALSE;
if (NS_SUCCEEDED(rv = mInner->HasAssertion(mParent, hintRes, trueLiteral, PR_TRUE, &hasAssertionFlag))
&& (hasAssertionFlag == PR_FALSE))
{
rv = mInner->Assert(mParent, hintRes, trueLiteral, PR_TRUE);
}
}
return(rv);
}

Просмотреть файл

@ -27,9 +27,17 @@
<treecol id="NameColumn" rdf:resource="http://home.netscape.com/NC-rdf#Name"/>
<treecol id="RelevanceColumn" rdf:resource="http://home.netscape.com/NC-rdf#Relevance"
rdf:resource2="http://home.netscape.com/NC-rdf#Name"
sortActive="true" sortDirection="descending" />
<treecol id="SiteColumn" rdf:resource="http://home.netscape.com/NC-rdf#Site"/>
<treecol id="EngineColumn" rdf:resource="http://home.netscape.com/NC-rdf#Engine"/>
style="width: 0; visibility: collapse;" />
<treecol id="PriceColumn" rdf:resource="http://home.netscape.com/NC-rdf#Price"
rdf:resource2="http://home.netscape.com/NC-rdf#Availability"
style="width: 0; visibility: collapse;" />
<treecol id="AvailabilityColumn" rdf:resource="http://home.netscape.com/NC-rdf#Availability"
rdf:resource2="http://home.netscape.com/NC-rdf#Price"
style="width: 0; visibility: collapse;" />
<treecol id="SiteColumn" rdf:resource="http://home.netscape.com/NC-rdf#Site"
rdf:resource2="http://home.netscape.com/NC-rdf#Name" />
<treecol id="EngineColumn" rdf:resource="http://home.netscape.com/NC-rdf#Engine"
rdf:resource2="http://home.netscape.com/NC-rdf#Name" />
<template>
<rule rdf:type="http://home.netscape.com/NC-rdf#BookmarkSeparator">
@ -53,6 +61,8 @@
<progressmeter value="rdf:http://home.netscape.com/NC-rdf#Relevance" align="horizontal" mode="normal" />
<titledbutton crop="right" value="rdf:http://home.netscape.com/NC-rdf#Relevance" align="left" style="list-style-image: none;" />
</treecell>
<treecell align="left" crop="right" value="rdf:http://home.netscape.com/NC-rdf#Price" />
<treecell align="left" crop="right" value="rdf:http://home.netscape.com/NC-rdf#Availability" />
<treecell align="left" crop="right" value="rdf:http://home.netscape.com/NC-rdf#Site" />
<treecell class="iconic" src="rdf:http://home.netscape.com/NC-rdf#Icon" align="left" crop="right" value="rdf:http://home.netscape.com/NC-rdf#Engine" />
</treerow>
@ -63,10 +73,31 @@
<treehead>
<treerow>
<treecell value="&name.column.label;" observes="NameColumn" resource="http://home.netscape.com/NC-rdf#Name" onclick="return doSort('NameColumn');" />
<treecell value="&relevance.column.label;" observes="RelevanceColumn" resource="http://home.netscape.com/NC-rdf#Relevance" onclick="return doSort('RelevanceColumn');" sortActive="true" sortDirection="descending" />
<treecell value="&site.column.label;" observes="SiteColumn" resource="http://home.netscape.com/NC-rdf#Site" onclick="return doSort('SiteColumn');" />
<treecell value="&engine.column.label;" observes="EngineColumn" resource="http://home.netscape.com/NC-rdf#Engine" onclick="return doSort('EngineColumn');" />
<treecell id="NameCell"
value="&name.column.label;" observes="NameColumn"
resource="http://home.netscape.com/NC-rdf#Name"
onclick="return doSort('NameColumn');" />
<treecell id="RelevanceCell"
value="&relevance.column.label;" observes="RelevanceColumn"
resource="http://home.netscape.com/NC-rdf#Relevance"
onclick="return doSort('RelevanceColumn');" />
<treecell id="PriceCell"
value="Price" observes="PriceColumn"
resource="http://home.netscape.com/NC-rdf#Price"
onclick="return doSort('PriceColumn');" />
<treecell id="AvailabilityCell"
value="Availability" observes="AvailabilityColumn"
resource="http://home.netscape.com/NC-rdf#Availability"
onclick="return doSort('AvailabilityColumn');" />
<treecell id="SiteCell"
value="&site.column.label;" observes="SiteColumn"
resource="http://home.netscape.com/NC-rdf#Site"
onclick="return doSort('SiteColumn');" />
<treecell id="EngineCell"
value="&engine.column.label;" observes="EngineColumn"
resource="http://home.netscape.com/NC-rdf#Engine"
onclick="return doSort('EngineColumn');" />
</treerow>
</treehead>
</tree>

Просмотреть файл

@ -1,6 +1,8 @@
category.rdf
AOLSearch.gif
AOLSearch.src
eBay.gif
eBay.src
Excite.gif
Excite.src
Google.gif

Просмотреть файл

@ -30,6 +30,8 @@ FILES = \
category.rdf \
AOLSearch.gif \
AOLSearch.src \
eBay.gif \
eBay.src \
Excite.gif \
Excite.src \
Google.gif \

Просмотреть файл

@ -38,10 +38,6 @@
<RDF:Description about="urn:search:category:2">
<NC:title>Shopping</NC:title>
</RDF:Description>
<RDF:Description about="urn:search:category:3">
<NC:title>People</NC:title>
</RDF:Description>
</RDF:li>
</RDF:Seq>
@ -62,9 +58,7 @@
</RDF:Seq>
<RDF:Seq about="NC:SearchCategory?category=urn:search:category:2">
</RDF:Seq>
<RDF:Seq about="NC:SearchCategory?category=urn:search:category:3">
<RDF:li resource="NC:SearchCategory?engine=urn:search:engine:10" />
</RDF:Seq>
@ -108,5 +102,9 @@
<NC:Name>Snap.com</NC:Name>
</RDF:Description>
<RDF:Description about="NC:SearchCategory?engine=urn:search:engine:10">
<NC:Name>eBay</NC:Name>
</RDF:Description>
</RDF:RDF>

Двоичные данные
xpfe/components/search/datasets/eBay.gif Executable file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1018 B

Просмотреть файл

@ -0,0 +1,24 @@
<search
name="eBay"
description="Your Personal Trading Community"
action="http://search.ebay.com/cgi-bin/texis/ebay/results.html"
method="GET"
>
<input name="query" user />
<input name="maxRecordsReturned" value="300" />
<input name="maxRecordsPerPage" value="50" />
<input name="SortProperty" value="MetaEndSort" />
<interpret
resultItemStart="<!--$minder-include$-->"
resultItemEnd="</table>"
priceStart='<font size="3"><b>'
priceEnd="</b></font>"
availStart='<td align="left" valign="top" width="13%"><font size="3">'
availEnd="</font></td>"
/>
<conversion prop="avail" name="min" value=".0167" scanfornumber />
</search>

Просмотреть файл

@ -27,6 +27,8 @@ FILES=\
category.rdf \
AOLSearch.gif \
AOLSearch.src \
eBay.gif \
eBay.src \
Excite.gif \
Excite.src \
Google.gif \

Просмотреть файл

@ -213,6 +213,98 @@ function doStop()
{
searchButtonNode.removeAttribute("style", "display: none;");
}
// get various services
var rdf = Components.classes["component://netscape/rdf/rdf-service"].getService();
if (rdf) rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
// var internetSearch = Components.classes["component://netscape/browser/internetsearch-service"].getService();
var internetSearch = Components.classes["component://netscape/rdf/datasource?name=internetsearch"].getService();
if (internetSearch) internetSearch = internetSearch.QueryInterface(Components.interfaces.nsIRDFDataSource);
var colNode;
var sortSetFlag = false;
// show appropriate column(s)
if ((rdf) && (internetSearch))
{
var resultsTree = parent.frames[1].document.getElementById("internetresultstree");
if (!resultsTree) return(false);
var searchURL = resultsTree.getAttribute("ref");
if (!searchURL || searchURL == "") return(false);
var searchResource = rdf.GetResource(searchURL, true);
var priceProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#Price", true);
var availabilityProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#Availability", true);
var relevanceProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#Relevance", true);
var trueProperty = rdf.GetLiteral("true");
var hasPriceFlag = internetSearch.HasAssertion(searchResource, priceProperty, trueProperty, true);
var hasAvailabilityFlag = internetSearch.HasAssertion(searchResource, availabilityProperty, trueProperty, true);
var hasRelevanceFlag = internetSearch.HasAssertion(searchResource, relevanceProperty, trueProperty, true);
if (hasPriceFlag == true)
{
colNode = parent.frames[1].document.getElementById("PriceColumn");
if (colNode)
{
colNode.removeAttribute("style", "width: 0; visibility: collapse;");
if (sortSetFlag == false)
{
setInitialSort(colNode, "ascending");
sortSetFlag = true;
}
}
}
if (hasAvailabilityFlag == true)
{
colNode = parent.frames[1].document.getElementById("AvailabilityColumn");
if (colNode)
{
colNode.removeAttribute("style", "width: 0; visibility: collapse;");
}
}
if (hasRelevanceFlag == true)
{
colNode = parent.frames[1].document.getElementById("RelevanceColumn");
if (colNode)
{
colNode.removeAttribute("style", "width: 0; visibility: collapse;");
if (sortSetFlag == false)
{
setInitialSort(colNode, "descending");
sortSetFlag = true;
}
}
}
}
if (sortSetFlag == false)
{
colNode = parent.frames[1].document.getElementById("NameColumn");
if (colNode)
{
setInitialSort(colNode, "ascending");
}
}
}
function setInitialSort(node, sortDirection)
{
// determine column resource to sort on
var sortResource = node.getAttribute('resource');
if (!sortResource) return(false);
var isupports = Components.classes["component://netscape/rdf/xul-sort-service"].getService();
if (!isupports) return(false);
var xulSortService = isupports.QueryInterface(Components.interfaces.nsIXULSortService);
if (!xulSortService) return(false);
xulSortService.Sort(node, sortResource, sortDirection);
return(true);
}
@ -280,6 +372,14 @@ function doSearch()
progressNode.removeAttribute("style", "display: none;");
}
// hide various columns
colNode = parent.frames[1].document.getElementById("RelevanceColumn");
if (colNode) colNode.setAttribute("style", "width: 0; visibility: collapse;");
colNode = parent.frames[1].document.getElementById("PriceColumn");
if (colNode) colNode.setAttribute("style", "width: 0; visibility: collapse;");
colNode = parent.frames[1].document.getElementById("AvailabilityColumn");
if (colNode) colNode.setAttribute("style", "width: 0; visibility: collapse;");
setTimeout("checkSearchProgress()", 1000);
gText = "";

Просмотреть файл

@ -27,9 +27,17 @@
<treecol id="NameColumn" rdf:resource="http://home.netscape.com/NC-rdf#Name"/>
<treecol id="RelevanceColumn" rdf:resource="http://home.netscape.com/NC-rdf#Relevance"
rdf:resource2="http://home.netscape.com/NC-rdf#Name"
sortActive="true" sortDirection="descending" />
<treecol id="SiteColumn" rdf:resource="http://home.netscape.com/NC-rdf#Site"/>
<treecol id="EngineColumn" rdf:resource="http://home.netscape.com/NC-rdf#Engine"/>
style="width: 0; visibility: collapse;" />
<treecol id="PriceColumn" rdf:resource="http://home.netscape.com/NC-rdf#Price"
rdf:resource2="http://home.netscape.com/NC-rdf#Availability"
style="width: 0; visibility: collapse;" />
<treecol id="AvailabilityColumn" rdf:resource="http://home.netscape.com/NC-rdf#Availability"
rdf:resource2="http://home.netscape.com/NC-rdf#Price"
style="width: 0; visibility: collapse;" />
<treecol id="SiteColumn" rdf:resource="http://home.netscape.com/NC-rdf#Site"
rdf:resource2="http://home.netscape.com/NC-rdf#Name" />
<treecol id="EngineColumn" rdf:resource="http://home.netscape.com/NC-rdf#Engine"
rdf:resource2="http://home.netscape.com/NC-rdf#Name" />
<template>
<rule rdf:type="http://home.netscape.com/NC-rdf#BookmarkSeparator">
@ -53,6 +61,8 @@
<progressmeter value="rdf:http://home.netscape.com/NC-rdf#Relevance" align="horizontal" mode="normal" />
<titledbutton crop="right" value="rdf:http://home.netscape.com/NC-rdf#Relevance" align="left" style="list-style-image: none;" />
</treecell>
<treecell align="left" crop="right" value="rdf:http://home.netscape.com/NC-rdf#Price" />
<treecell align="left" crop="right" value="rdf:http://home.netscape.com/NC-rdf#Availability" />
<treecell align="left" crop="right" value="rdf:http://home.netscape.com/NC-rdf#Site" />
<treecell class="iconic" src="rdf:http://home.netscape.com/NC-rdf#Icon" align="left" crop="right" value="rdf:http://home.netscape.com/NC-rdf#Engine" />
</treerow>
@ -63,10 +73,31 @@
<treehead>
<treerow>
<treecell value="&name.column.label;" observes="NameColumn" resource="http://home.netscape.com/NC-rdf#Name" onclick="return doSort('NameColumn');" />
<treecell value="&relevance.column.label;" observes="RelevanceColumn" resource="http://home.netscape.com/NC-rdf#Relevance" onclick="return doSort('RelevanceColumn');" sortActive="true" sortDirection="descending" />
<treecell value="&site.column.label;" observes="SiteColumn" resource="http://home.netscape.com/NC-rdf#Site" onclick="return doSort('SiteColumn');" />
<treecell value="&engine.column.label;" observes="EngineColumn" resource="http://home.netscape.com/NC-rdf#Engine" onclick="return doSort('EngineColumn');" />
<treecell id="NameCell"
value="&name.column.label;" observes="NameColumn"
resource="http://home.netscape.com/NC-rdf#Name"
onclick="return doSort('NameColumn');" />
<treecell id="RelevanceCell"
value="&relevance.column.label;" observes="RelevanceColumn"
resource="http://home.netscape.com/NC-rdf#Relevance"
onclick="return doSort('RelevanceColumn');" />
<treecell id="PriceCell"
value="Price" observes="PriceColumn"
resource="http://home.netscape.com/NC-rdf#Price"
onclick="return doSort('PriceColumn');" />
<treecell id="AvailabilityCell"
value="Availability" observes="AvailabilityColumn"
resource="http://home.netscape.com/NC-rdf#Availability"
onclick="return doSort('AvailabilityColumn');" />
<treecell id="SiteCell"
value="&site.column.label;" observes="SiteColumn"
resource="http://home.netscape.com/NC-rdf#Site"
onclick="return doSort('SiteColumn');" />
<treecell id="EngineCell"
value="&engine.column.label;" observes="EngineColumn"
resource="http://home.netscape.com/NC-rdf#Engine"
onclick="return doSort('EngineColumn');" />
</treerow>
</treehead>
</tree>

Просмотреть файл

@ -244,6 +244,10 @@ private:
static nsIRDFResource *kNC_RelevanceSort;
static nsIRDFResource *kNC_Engine;
static nsIRDFResource *kNC_Price;
static nsIRDFResource *kNC_PriceSort;
static nsIRDFResource *kNC_Availability;
protected:
static nsIRDFDataSource *mInner;
@ -268,6 +272,7 @@ static nsresult GetData(nsString &data, const char *sectionToFind, const char *a
nsresult GetInputs(const nsString &data, nsString &userVar, const nsString &text, nsString &input);
nsresult GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult);
nsresult ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRDFResource *engine, const nsString &htmlPage, PRBool useAllHREFsFlag, PRUint32 &numResults);
nsresult SetHint(nsIRDFResource *mParent, nsIRDFResource *hintRes);
InternetSearchDataSource(void);
virtual ~InternetSearchDataSource(void);
@ -319,7 +324,9 @@ nsIRDFResource *InternetSearchDataSource::kNC_Site;
nsIRDFResource *InternetSearchDataSource::kNC_Relevance;
nsIRDFResource *InternetSearchDataSource::kNC_RelevanceSort;
nsIRDFResource *InternetSearchDataSource::kNC_Engine;
nsIRDFResource *InternetSearchDataSource::kNC_Price;
nsIRDFResource *InternetSearchDataSource::kNC_PriceSort;
nsIRDFResource *InternetSearchDataSource::kNC_Availability;
static const char kEngineProtocol[] = "engine://";
@ -361,6 +368,9 @@ InternetSearchDataSource::InternetSearchDataSource(void)
gRDFService->GetResource(NC_NAMESPACE_URI "Relevance", &kNC_Relevance);
gRDFService->GetResource(NC_NAMESPACE_URI "Relevance?sort=true", &kNC_RelevanceSort);
gRDFService->GetResource(NC_NAMESPACE_URI "Engine", &kNC_Engine);
gRDFService->GetResource(NC_NAMESPACE_URI "Price", &kNC_Price);
gRDFService->GetResource(NC_NAMESPACE_URI "Price?sort=true", &kNC_PriceSort);
gRDFService->GetResource(NC_NAMESPACE_URI "Availability", &kNC_Availability);
}
}
@ -391,6 +401,9 @@ InternetSearchDataSource::~InternetSearchDataSource (void)
NS_IF_RELEASE(kNC_Relevance);
NS_IF_RELEASE(kNC_RelevanceSort);
NS_IF_RELEASE(kNC_Engine);
NS_IF_RELEASE(kNC_Price);
NS_IF_RELEASE(kNC_PriceSort);
NS_IF_RELEASE(kNC_Availability);
NS_IF_RELEASE(mInner);
@ -2302,25 +2315,6 @@ InternetSearchDataSource::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
rv = channel->GetURI(getter_AddRefs(aURL));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFLiteral> trueLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(nsAutoString("true").GetUnicode(), getter_AddRefs(trueLiteral))))
{
mInner->Unassert(mEngine, kNC_loading, trueLiteral);
if (mConnections)
{
PRUint32 count=0;
mConnections->Count(&count);
if (count <= 1)
{
if (mParent)
{
mInner->Unassert(mParent, kNC_loading, trueLiteral);
}
}
}
}
// copy the engine's icon reference (if it has one) onto the result node
nsCOMPtr<nsIRDFNode> engineIconStatusNode = nsnull;
mInner->GetTarget(mEngine, kNC_Icon, PR_TRUE, getter_AddRefs(engineIconStatusNode));
@ -2330,40 +2324,62 @@ InternetSearchDataSource::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
}
PRUnichar *uniBuf = nsnull;
if (NS_FAILED(rv = context->GetBuffer(&uniBuf))) return(rv);
if (!uniBuf) return(NS_ERROR_UNEXPECTED);
nsAutoString htmlResults(uniBuf);
if (htmlResults.Length() < 1)
if (NS_SUCCEEDED(rv = context->GetBuffer(&uniBuf)) && (uniBuf))
{
#ifdef DEBUG_SEARCH_OUTPUT
printf(" *** InternetSearchDataSourceCallback::OnStopRequest: no data.\n\n");
#endif
return(NS_OK);
}
// Note: don't free uniBuf, its really a const *
if (NS_FAILED(rv = context->Truncate())) return(rv);
if (mParent)
{
// save HTML result page for this engine
const PRUnichar *htmlUni = htmlResults.GetUnicode();
if (htmlUni)
nsAutoString htmlResults(uniBuf);
context->Truncate();
if (htmlResults.Length() > 0)
{
nsCOMPtr<nsIRDFLiteral> htmlLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(htmlUni, getter_AddRefs(htmlLiteral))))
if (mParent)
{
rv = mInner->Assert(mEngine, kNC_HTML, htmlLiteral, PR_TRUE);
// save HTML result page for this engine
const PRUnichar *htmlUni = htmlResults.GetUnicode();
if (htmlUni)
{
nsCOMPtr<nsIRDFLiteral> htmlLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(htmlUni, getter_AddRefs(htmlLiteral))))
{
rv = mInner->Assert(mEngine, kNC_HTML, htmlLiteral, PR_TRUE);
}
}
}
// parse up HTML results
PRUint32 numResults = 0;
rv = ParseHTML(aURL, mParent, mEngine, htmlResults, PR_FALSE, numResults);
if (NS_SUCCEEDED(rv) && (!mParent) && (numResults == 0))
{
rv = ParseHTML(aURL, mParent, mEngine, htmlResults, PR_TRUE, numResults);
}
}
else
{
#ifdef DEBUG_SEARCH_OUTPUT
printf(" *** InternetSearchDataSourceCallback::OnStopRequest: no data.\n\n");
#endif
}
}
PRUint32 numResults = 0;
rv = ParseHTML(aURL, mParent, mEngine, htmlResults, PR_FALSE, numResults);
if (NS_SUCCEEDED(rv) && (!mParent) && (numResults == 0))
// (do this last) potentially remove the loading attribute
nsCOMPtr<nsIRDFLiteral> trueLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(nsAutoString("true").GetUnicode(), getter_AddRefs(trueLiteral))))
{
rv = ParseHTML(aURL, mParent, mEngine, htmlResults, PR_TRUE, numResults);
mInner->Unassert(mEngine, kNC_loading, trueLiteral);
if (mConnections)
{
PRUint32 count=0;
mConnections->Count(&count);
if (count < 1)
{
if (mParent)
{
mInner->Unassert(mParent, kNC_loading, trueLiteral);
}
}
}
}
return(NS_OK);
@ -2381,6 +2397,7 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
nsAutoString resultItemStartStr, resultItemEndStr;
nsAutoString relevanceStartStr, relevanceEndStr;
nsAutoString bannerStartStr, bannerEndStr, skiplocalStr;
nsAutoString priceStartStr, priceEndStr, availStartStr, availEndStr;
PRBool skipLocalFlag = PR_FALSE;
nsresult rv;
@ -2425,6 +2442,11 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
GetData(data, "search", "name", engineStr);
GetData(data, "interpret", "priceStart", priceStartStr);
GetData(data, "interpret", "priceEnd", priceEndStr);
GetData(data, "interpret", "availStart", availStartStr);
GetData(data, "interpret", "availEnd", availEndStr);
#ifdef DEBUG_SEARCH_OUTPUT
char *cStr;
cStr = resultListStartStr.ToNewCString();
@ -2558,6 +2580,8 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
trimItemEnd = PR_FALSE;
}
PRBool hasPriceFlag = PR_FALSE, hasAvailabilityFlag = PR_FALSE, hasRelevanceFlag = PR_FALSE;
while(PR_TRUE)
{
PRInt32 resultItemStart;
@ -2679,10 +2703,7 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
}
}
char *href = hrefStr.ToNewCString();
if (!href) continue;
nsAutoString site(href);
nsAutoString site(hrefStr);
#ifdef DEBUG_SEARCH_OUTPUT
printf("HREF: '%s'\n", href);
@ -2692,7 +2713,7 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
// #define OLDWAY
#ifdef OLDWAY
rv = gRDFService->GetResource(href, getter_AddRefs(res));
rv = gRDFService->GetResource(nsCAutoString(hrefStr), getter_AddRefs(res));
#else
// save HREF attribute as URL
if (NS_SUCCEEDED(rv = gRDFService->GetAnonymousResource(getter_AddRefs(res))))
@ -2708,9 +2729,6 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
}
}
#endif
nsCRT::free(href);
href = nsnull;
if (NS_FAILED(rv)) continue;
// set HTML response chunk
@ -2873,6 +2891,106 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
}
}
// look for price
nsAutoString priceItem;
PRInt32 priceStart;
if ((priceStart = resultItem.Find(priceStartStr, PR_TRUE)) >= 0)
{
PRInt32 priceEnd = resultItem.Find(priceEndStr, PR_TRUE, priceStart + priceStartStr.Length());
if (priceEnd > priceStart)
{
resultItem.Mid(priceItem, priceStart + priceStartStr.Length(),
priceEnd - priceStart - priceStartStr.Length());
// munge out anything inside of HTML "<" / ">" tags
PRInt32 priceTagStartOffset;
while ((priceTagStartOffset = priceItem.FindCharInSet("<", 0)) >= 0)
{
PRInt32 priceTagEndOffset = priceItem.FindCharInSet(">", priceTagStartOffset);
if (priceTagEndOffset <= priceTagStartOffset) break;
priceItem.Cut(priceTagStartOffset, priceTagEndOffset - priceTagStartOffset + 1);
}
// cut out any CRs or LFs
PRInt32 priceEOLOffset;
while ((priceEOLOffset = priceItem.FindCharInSet("\n\r", 0)) >= 0)
{
priceItem.Cut(priceEOLOffset, 1);
}
}
}
if (priceItem.Length() > 0)
{
const PRUnichar *priceUni = priceItem.GetUnicode();
nsCOMPtr<nsIRDFLiteral> priceLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(priceUni, getter_AddRefs(priceLiteral))))
{
if (priceLiteral)
{
mInner->Assert(res, kNC_Price, priceLiteral, PR_TRUE);
hasPriceFlag = PR_TRUE;
}
}
PRInt32 priceCharStartOffset = priceItem.FindCharInSet("1234567890");
if (priceCharStartOffset >= 0)
{
priceItem.Cut(0, priceCharStartOffset);
PRInt32 priceErr;
float val = priceItem.ToFloat(&priceErr);
if (priceItem.FindChar(PRUnichar('.')) >= 0) val *= 100;
nsCOMPtr<nsIRDFInt> priceSortLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetIntLiteral((PRInt32)val, getter_AddRefs(priceSortLiteral))))
{
if (priceSortLiteral)
{
mInner->Assert(res, kNC_PriceSort, priceSortLiteral, PR_TRUE);
}
}
}
}
// look for availability
nsAutoString availItem;
PRInt32 availStart;
if ((availStart = resultItem.Find(availStartStr, PR_TRUE)) >= 0)
{
PRInt32 availEnd = resultItem.Find(availEndStr, PR_TRUE, availStart + availStartStr.Length());
if (availEnd > availStart)
{
resultItem.Mid(availItem, availStart + availStartStr.Length(),
availEnd - availStart - availStartStr.Length());
// munge out anything inside of HTML "<" / ">" tags
PRInt32 availTagStartOffset;
while ((availTagStartOffset = availItem.FindCharInSet("<", 0)) >= 0)
{
PRInt32 availTagEndOffset = availItem.FindCharInSet(">", availTagStartOffset);
if (availTagEndOffset <= availTagStartOffset) break;
availItem.Cut(availTagStartOffset, availTagEndOffset - availTagStartOffset + 1);
}
// cut out any CRs or LFs
PRInt32 availEOLOffset;
while ((availEOLOffset = availItem.FindCharInSet("\n\r", 0)) >= 0)
{
availItem.Cut(availEOLOffset, 1);
}
}
}
if (availItem.Length() > 0)
{
const PRUnichar *availUni = availItem.GetUnicode();
nsCOMPtr<nsIRDFLiteral> availLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(availUni, getter_AddRefs(availLiteral))))
{
if (availLiteral)
{
mInner->Assert(res, kNC_Availability, availLiteral, PR_TRUE);
hasAvailabilityFlag = PR_TRUE;
}
}
}
// look for relevance
nsAutoString relItem;
PRInt32 relStart;
@ -2923,6 +3041,7 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
relStr += PRUnichar('%');
}
relItem = relStr;
hasRelevanceFlag = PR_TRUE;
}
else
{
@ -3033,5 +3152,32 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
++numResults;
}
// set hints so that the appropriate columns can be displayed
if (hasPriceFlag == PR_TRUE) SetHint(mParent, kNC_Price);
if (hasAvailabilityFlag == PR_TRUE) SetHint(mParent, kNC_Availability);
if (hasRelevanceFlag == PR_TRUE) SetHint(mParent, kNC_Relevance);
return(NS_OK);
}
nsresult
InternetSearchDataSource::SetHint(nsIRDFResource *mParent, nsIRDFResource *hintRes)
{
if (!mInner) return(NS_OK);
nsresult rv;
nsCOMPtr<nsIRDFLiteral> trueLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(nsAutoString("true").GetUnicode(), getter_AddRefs(trueLiteral))))
{
PRBool hasAssertionFlag = PR_FALSE;
if (NS_SUCCEEDED(rv = mInner->HasAssertion(mParent, hintRes, trueLiteral, PR_TRUE, &hasAssertionFlag))
&& (hasAssertionFlag == PR_FALSE))
{
rv = mInner->Assert(mParent, hintRes, trueLiteral, PR_TRUE);
}
}
return(rv);
}