Bug 334302. Adjust SAXLocator reports in ReportError. Patch by Alex Vincent <ajvincent@gmail.com>. r=sayrer, sr=bz

This commit is contained in:
sayrer%gmail.com 2006-09-13 18:20:05 +00:00
Родитель 5ed2cd6ba4
Коммит 9f0cf6c3db
6 изменённых файлов: 45 добавлений и 45 удалений

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

@ -79,7 +79,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(CViewSourceHTML)
#endif
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSAXAttributes)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSAXLocator)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSAXXMLReader)
static const nsModuleComponentInfo gComponents[] = {
@ -99,18 +98,13 @@ static const nsModuleComponentInfo gComponents[] = {
NS_PARSERSERVICE_CONTRACTID,
nsParserServiceConstructor
},
{
NS_SAXATTRIBUTES_CLASSNAME,
NS_SAXATTRIBUTES_CID,
NS_SAXATTRIBUTES_CONTRACTID,
nsSAXAttributesConstructor
},
{
NS_SAXLOCATOR_CLASSNAME,
NS_SAXLOCATOR_CID,
NS_SAXLOCATOR_CONTRACTID,
nsSAXLocatorConstructor
},
{
NS_SAXXMLREADER_CLASSNAME,

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

@ -54,6 +54,7 @@ REQUIRES = \
htmlparser \
content \
uconv \
xpconnect \
$(NULL)
CPPSRCS = \

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

@ -39,7 +39,14 @@
NS_IMPL_ISUPPORTS1(nsSAXLocator, nsISAXLocator)
nsSAXLocator::nsSAXLocator() : mLineNumber(0), mColumnNumber(0)
nsSAXLocator::nsSAXLocator(nsString& aPublicId,
nsString& aSystemId,
PRInt32 aLineNumber,
PRInt32 aColumnNumber) :
mPublicId(aPublicId),
mSystemId(aSystemId),
mLineNumber(aLineNumber),
mColumnNumber(aColumnNumber)
{
}
@ -70,31 +77,3 @@ nsSAXLocator::GetSystemId(nsAString &aSystemId)
aSystemId = mSystemId;
return NS_OK;
}
NS_IMETHODIMP
nsSAXLocator::SetColumnNumber(PRInt32 aColumnNumber)
{
mColumnNumber = aColumnNumber;
return NS_OK;
}
NS_IMETHODIMP
nsSAXLocator::SetLineNumber(PRInt32 aLineNumber)
{
mLineNumber = aLineNumber;
return NS_OK;
}
NS_IMETHODIMP
nsSAXLocator::SetSystemId(const nsAString &aSystemId)
{
mSystemId = aSystemId;
return NS_OK;
}
NS_IMETHODIMP
nsSAXLocator::SetPublicId(const nsAString &aPublicId)
{
mPublicId = aPublicId;
return NS_OK;
}

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

@ -54,12 +54,10 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSISAXLOCATOR
nsSAXLocator();
NS_IMETHOD SetColumnNumber(PRInt32 aColumnNumber);
NS_IMETHOD SetLineNumber(PRInt32 aLineNumber);
NS_IMETHOD SetSystemId(const nsAString & aSystemId);
NS_IMETHOD SetPublicId(const nsAString & aPublicId);
nsSAXLocator(nsString& aPublicId,
nsString& aSystemId,
PRInt32 aLineNumber,
PRInt32 aColumnNumber);
private:
nsString mPublicId;

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

@ -43,7 +43,9 @@
#include "nsParserCIID.h"
#include "nsStreamUtils.h"
#include "nsStringStream.h"
#include "nsIScriptError.h"
#include "nsSAXAttributes.h"
#include "nsSAXLocator.h"
#include "nsSAXXMLReader.h"
#define XMLNS_URI "http://www.w3.org/2000/xmlns/"
@ -163,6 +165,8 @@ nsSAXXMLReader::HandleStartDTD(const PRUnichar *aName,
const PRUnichar *aSystemId,
const PRUnichar *aPublicId)
{
mSystemId = aSystemId;
mPublicId = aPublicId;
if (mLexicalHandler) {
return mLexicalHandler->StartDTD(nsDependentString(aName),
nsDependentString(aSystemId),
@ -298,10 +302,23 @@ nsSAXXMLReader::ReportError(const PRUnichar* aErrorText,
// Normally, the expat driver should report the error.
*_retval = PR_TRUE;
/// XXX need to settle what to do about the input setup, so I have
/// coherent values for the nsISAXLocator here. nsnull for now.
if (mErrorHandler) {
nsresult rv = mErrorHandler->FatalError(nsnull, nsDependentString(aErrorText));
PRUint32 lineNumber;
nsresult rv = aError->GetLineNumber(&lineNumber);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 columnNumber;
rv = aError->GetColumnNumber(&columnNumber);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISAXLocator> locator = new nsSAXLocator(mPublicId,
mSystemId,
lineNumber,
columnNumber);
if (!locator)
return NS_ERROR_OUT_OF_MEMORY;
rv = mErrorHandler->FatalError(locator, nsDependentString(aErrorText));
if (NS_SUCCEEDED(rv)) {
// The error handler has handled the script error. Don't log to console.
*_retval = PR_FALSE;
@ -464,6 +481,15 @@ nsSAXXMLReader::ParseFromStream(nsIInputStream *aStream,
rv = mListener->OnStartRequest(parserChannel, nsnull);
if (NS_FAILED(rv))
parserChannel->Cancel(rv);
/* When parsing a new document, we need to clear the XML identifiers.
HandleStartDTD will set these values from the DTD declaration tag.
We won't have them, of course, if there's a well-formedness error
before the DTD tag (such as a space before an XML declaration).
*/
mSystemId.Truncate();
mPublicId.Truncate();
nsresult status;
parserChannel->GetStatus(&status);

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

@ -116,6 +116,8 @@ private:
nsString &aURI,
nsString &aLocalName,
nsString &aQName);
nsString mPublicId;
nsString mSystemId;
};
#endif // nsSAXXMLReader_h__