htmlResults.Cut(0, resultItemEnd + resultItemEndStr.Length());
if (trimItemEnd == PR_TRUE) { htmlResults.Cut(0, resultItemEnd + resultItemEndStr.Length()); } else { htmlResults.Cut(0, resultItemEnd); }
SearchDataSourceCallback::OnStopRequest(nsIURI* aURL, nsresult aStatus, const PRUnichar* aMsg) #endif{	nsAutoString		trueStr("true");	nsIRDFLiteral		*literal = nsnull;	nsresult		rv;#ifdef NECKO	nsCOMPtr<nsIURI> aURL;	rv = channel->GetURI(getter_AddRefs(aURL));	if (NS_FAILED(rv)) return rv;#endif	if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(trueStr.GetUnicode(), &literal)))	{		mDataSource->Unassert(mParent, kNC_loading, literal);		NS_RELEASE(literal);	}	if (!mLine)	{#ifdef	DEBUG		printf(" *** SearchDataSourceCallback::OnStopRequest:  no data.\n\n");#endif		return(NS_OK);	}#if	0	printf("\n\n%s\n\n", mLine);#endif	nsAutoString	htmlResults(mLine);	delete [] mLine;	mLine = nsnull;	// get data out of graph	nsAutoString		data("");	nsCOMPtr<nsIRDFNode>	dataNode;	if (NS_FAILED(rv = mDataSource->GetTarget(mEngine, kNC_Data, PR_TRUE, getter_AddRefs(dataNode))))	{		return(rv);	}	nsCOMPtr<nsIRDFLiteral>	dataLiteral = do_QueryInterface(dataNode);	if (!dataLiteral)	return(NS_ERROR_NULL_POINTER);	PRUnichar	*dataUni = nsnull;	if (NS_FAILED(rv = dataLiteral->GetValue(&dataUni)))		return(rv);	if (!dataUni)	return(NS_ERROR_NULL_POINTER);	data = dataUni;	if (data.Length() < 1)		return(rv);	nsAutoString	resultListStartStr(""), resultListEndStr("");	nsAutoString	resultItemStartStr(""), resultItemEndStr("");	nsAutoString	relevanceStartStr(""), relevanceEndStr("");	SearchDataSource::GetData(data, "interpret", "resultListStart", resultListStartStr);	SearchDataSource::GetData(data, "interpret", "resultListEnd", resultListEndStr);	SearchDataSource::GetData(data, "interpret", "resultItemStart", resultItemStartStr);	SearchDataSource::GetData(data, "interpret", "resultItemEnd", resultItemEndStr);	SearchDataSource::GetData(data, "interpret", "relevanceStart", relevanceStartStr);	SearchDataSource::GetData(data, "interpret", "relevanceEnd", relevanceEndStr);#if 1	char *cStr;	cStr = resultListStartStr.ToNewCString();	if (cStr)	{		printf("resultListStart: '%s'\n", cStr);		delete [] cStr;		cStr = nsnull;	}	cStr = resultListEndStr.ToNewCString();	if (cStr)	{		printf("resultListEnd: '%s'\n", cStr);		delete [] cStr;		cStr = nsnull;	}	cStr = resultItemStartStr.ToNewCString();	if (cStr)	{		printf("resultItemStart: '%s'\n", cStr);		delete [] cStr;		cStr = nsnull;	}	cStr = resultItemEndStr.ToNewCString();	if (cStr)	{		printf("resultItemEnd: '%s'\n", cStr);		delete [] cStr;		cStr = nsnull;	}	cStr = relevanceStartStr.ToNewCString();	if (cStr)	{		printf("relevanceStart: '%s'\n", cStr);		delete [] cStr;		cStr = nsnull;	}	cStr = relevanceEndStr.ToNewCString();	if (cStr)	{		printf("relevanceEnd: '%s'\n", cStr);		delete [] cStr;		cStr = nsnull;	}#endif	if (resultListStartStr.Length() > 0)	{		PRInt32	resultListStart = htmlResults.Find(resultListStartStr, PR_TRUE);		if (resultListStart >= 0)		{			htmlResults.Cut(0, resultListStart + resultListStartStr.Length());		}	}	if (resultListEndStr.Length() > 0)	{		PRInt32	resultListEnd = htmlResults.Find(resultListEndStr, PR_TRUE);		if (resultListEnd >= 0)		{			htmlResults.Truncate(resultListEnd);		}	}	// if resultItemEndStr is not specified, try making it the same as resultItemStartStr	if (resultItemEndStr.Length() < 1)	{		resultItemEndStr = resultItemStartStr;	}	while(PR_TRUE)	{		PRInt32	resultItemStart;		resultItemStart = htmlResults.Find(resultItemStartStr, PR_TRUE);		if (resultItemStart < 0)	break;		htmlResults.Cut(0, resultItemStart + resultItemStartStr.Length());		PRInt32	resultItemEnd = htmlResults.Find(resultItemEndStr, PR_TRUE );		if (resultItemEnd < 0)		{			resultItemEnd = htmlResults.Length()-1;		}		nsAutoString	resultItem("");		htmlResults.Left(resultItem, resultItemEnd);		if (resultItem.Length() < 1)	break;		htmlResults.Cut(0, resultItemEnd + resultItemEndStr.Length());#if DEBUG		char	*results = resultItem.ToNewCString();		if (results)		{			printf("----- Search result: '%s'\n", results);			delete [] results;			results = nsnull;		}#endif		// look for href		PRInt32	hrefOffset = resultItem.Find("<A HREF=", PR_TRUE);		if (hrefOffset < 0)		{			continue;		}		nsAutoString	hrefStr("");		PRInt32 quoteStartOffset = resultItem.FindCharInSet("\"\'>", hrefOffset);		if (quoteStartOffset < hrefOffset)	continue;		PRInt32		quoteEndOffset;		if (resultItem[quoteStartOffset] == PRUnichar('>'))		{			// handle case where HREF isn't quoted			quoteEndOffset = quoteStartOffset;			quoteStartOffset = hrefOffset + strlen("<A HREF=") -1;		}		else		{			quoteEndOffset = resultItem.FindCharInSet("\"\'", quoteStartOffset + 1);			if (quoteEndOffset < hrefOffset)	continue;		}		resultItem.Mid(hrefStr, quoteStartOffset + 1, quoteEndOffset - quoteStartOffset - 1);		if (hrefStr.Length() < 1)	continue;		// check to see if this needs to be an absolute URL		if (hrefStr[0] == PRUnichar('/'))		{#ifdef NECKO			char *host = nsnull, *protocol = nsnull;#else			const char	*host = nsnull, *protocol = nsnull;#endif			aURL->GetHost(&host);#ifdef NECKO			aURL->GetScheme(&protocol);#else			aURL->GetProtocol(&protocol);#endif			if (host && protocol)			{				nsAutoString	temp;				temp += protocol;				temp += "://";				temp += host;				temp += hrefStr;				hrefStr = temp;			}#ifdef NECKO			if (host) nsCRT::free(host);			if (protocol) nsCRT::free(protocol);#endif		}				char	*href = hrefStr.ToNewCString();		if (!href)	continue;		nsAutoString	site(href);#ifdef	DEBUG		printf("HREF: '%s'\n", href);#endif		nsCOMPtr<nsIRDFResource>	res;#define	OLDWAY#ifdef	OLDWAY		rv = gRDFService->GetResource(href, getter_AddRefs(res));#else		const char			*parentURI = nsnull;		mParent->GetValueConst(&parentURI);		if (!parentURI)	break;		rv = rdf_CreateAnonymousResource(parentURI, getter_AddRefs(res));		// XXX must save HREF attribute#endif		delete [] href;		href = nsnull;		if (NS_FAILED(rv))	continue;		// look for Site (if it isn't already set)		nsCOMPtr<nsIRDFNode>		oldSiteRes = nsnull;		mDataSource->GetTarget(res, kNC_Site, PR_TRUE, getter_AddRefs(oldSiteRes));		if (!oldSiteRes)		{			PRInt32	protocolOffset = site.FindCharInSet(":", 0);			if (protocolOffset >= 0)			{				site.Cut(0, protocolOffset+1);				while (site[0] == PRUnichar('/'))				{					site.Cut(0, 1);				}				PRInt32	slashOffset = site.FindCharInSet("/", 0);				if (slashOffset >= 0)				{					site.Truncate(slashOffset);				}				if (site.Length() > 0)				{					const PRUnichar	*siteUni = site.GetUnicode();					if (siteUni)					{						nsCOMPtr<nsIRDFLiteral>	siteLiteral;						if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(siteUni, getter_AddRefs(siteLiteral))))						{							if (siteLiteral)							{								mDataSource->Assert(res, kNC_Site, siteLiteral, PR_TRUE);							}						}					}				}			}		}		// look for name		PRInt32	anchorEnd = resultItem.FindCharInSet(">", quoteEndOffset);		if (anchorEnd < quoteEndOffset)	continue;		PRInt32	anchorStop = resultItem.Find("</A>", PR_TRUE);		if (anchorStop < anchorEnd)	continue;				nsAutoString	nameStr;		resultItem.Mid(nameStr, anchorEnd + 1, anchorStop - anchorEnd - 1);		// munge any "&quot;" in name		PRInt32	quotOffset;		while ((quotOffset = nameStr.Find("&quot;", PR_TRUE)) >= 0)		{			nameStr.Cut(quotOffset, strlen("&quot;"));			nameStr.Insert(PRUnichar('\"'), quotOffset);		}				// munge any "&amp;" in name		PRInt32	ampOffset;		while ((ampOffset = nameStr.Find("&amp;", PR_TRUE)) >= 0)		{			nameStr.Cut(ampOffset, strlen("&amp;"));			nameStr.Insert(PRUnichar('&'), ampOffset);		}				// munge any "&nbsp;" in name		PRInt32	nbspOffset;		while ((nbspOffset = nameStr.Find("&nbsp;", PR_TRUE)) >= 0)		{			nameStr.Cut(nbspOffset, strlen("&nbsp;"));			nameStr.Insert(PRUnichar(' '), nbspOffset);		}		// munge any "&lt;" in name		PRInt32	ltOffset;		while ((ltOffset = nameStr.Find("&lt;", PR_TRUE)) >= 0)		{			nameStr.Cut(ltOffset, strlen("&lt;"));			nameStr.Insert(PRUnichar('<'), ltOffset);		}		// munge any "&gt;" in name		PRInt32	gtOffset;		while ((gtOffset = nameStr.Find("&gt;", PR_TRUE)) >= 0)		{			nameStr.Cut(gtOffset, strlen("&gt;"));			nameStr.Insert(PRUnichar('>'), gtOffset);		}				// munge out anything inside of HTML "<" / ">" tags		PRInt32 tagStartOffset;		while ((tagStartOffset = nameStr.FindCharInSet("<", 0)) >= 0)		{			PRInt32	tagEndOffset = nameStr.FindCharInSet(">", tagStartOffset);			if (tagEndOffset <= tagStartOffset)	break;			nameStr.Cut(tagStartOffset, tagEndOffset - tagStartOffset + 1);		}		// cut out any CRs or LFs		PRInt32	eolOffset;		while ((eolOffset = nameStr.FindCharInSet("\n\r", 0)) >= 0)		{			nameStr.Cut(eolOffset, 1);		}		// and trim name		nameStr = nameStr.Trim(" \t");		// look for Name (if it isn't already set)		nsCOMPtr<nsIRDFNode>		oldNameRes = nsnull;		mDataSource->GetTarget(res, kNC_Name, PR_TRUE, getter_AddRefs(oldNameRes));		if (!oldNameRes)		{			if (nameStr.Length() > 0)			{				const PRUnichar	*nameUni = nameStr.GetUnicode();				if (nameUni)				{					nsCOMPtr<nsIRDFLiteral>	nameLiteral;					if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(nameUni, getter_AddRefs(nameLiteral))))					{						if (nameLiteral)						{							mDataSource->Assert(res, kNC_Name, nameLiteral, PR_TRUE);						}					}				}			}		}		// look for relevance		nsAutoString	relItem("-");		PRInt32		relStart;		if ((relStart = resultItem.Find(relevanceStartStr /* , PR_TRUE */)) >= 0)		{			PRInt32	relEnd = resultItem.Find(relevanceEndStr /* , PR_TRUE */);			if (relEnd > relStart)			{				resultItem.Mid(relItem, relStart + relevanceStartStr.Length(),					relEnd - relStart - relevanceStartStr.Length());			}		}		// look for Relevance (if it isn't already set)		nsCOMPtr<nsIRDFNode>		oldRelRes = nsnull;		mDataSource->GetTarget(res, kNC_Relevance, PR_TRUE, getter_AddRefs(oldRelRes));		if (!oldRelRes)		{			if (relItem.Length() > 0)			{				// save real relevance				const PRUnichar	*relUni = relItem.GetUnicode();				if (relUni)				{					nsCOMPtr<nsIRDFLiteral>	relLiteral;					if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(relUni, getter_AddRefs(relLiteral))))					{						if (relLiteral)						{							mDataSource->Assert(res, kNC_Relevance, relLiteral, PR_TRUE);						}					}				}				// If its a percentage, remove "%", left-pad with "0"s and set special sorting value				if (relItem[relItem.Length()-1] == PRUnichar('%'))				{					relItem.Cut(relItem.Length()-1, 1);					nsAutoString	zero("000");					if (relItem.Length() < 3)					{						relItem.Insert(zero, 0, 3-relItem.Length()); 					}					const PRUnichar	*relSortUni = relItem.GetUnicode();					if (relSortUni)					{						nsCOMPtr<nsIRDFLiteral>	relSortLiteral;						if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(relSortUni, getter_AddRefs(relSortLiteral))))						{							if (relSortLiteral)							{								mDataSource->Assert(res, kNC_RelevanceSort, relSortLiteral, PR_TRUE);							}						}					}				}			}		}		// set reference to engine this came from (if it isn't already set)		nsCOMPtr<nsIRDFNode>		oldEngineRes = nsnull;		mDataSource->GetTarget(res, kNC_Engine, PR_TRUE, getter_AddRefs(oldEngineRes));		if (!oldEngineRes)		{			nsAutoString	engineStr;			if (NS_SUCCEEDED(rv = SearchDataSource::GetData(data, "search", "name", engineStr)))			{				const PRUnichar		*engineUni = engineStr.GetUnicode();				nsCOMPtr<nsIRDFLiteral>	engineLiteral;				if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(engineUni, getter_AddRefs(engineLiteral))))				{					if (engineLiteral)					{						mDataSource->Assert(res, kNC_Engine, engineLiteral, PR_TRUE);					}				}			}		}#ifdef	OLDWAY		// Note: always add in parent-child relationship last!  (if it isn't already set)		PRBool		parentHasChildFlag = PR_FALSE;		mDataSource->HasAssertion(mParent, kNC_Child, res, PR_TRUE, &parentHasChildFlag);		if (parentHasChildFlag == PR_FALSE)#endif		{			rv = mDataSource->Assert(mParent, kNC_Child, res, PR_TRUE);		}	}	return(NS_OK);}