Make nsExpatDriver and nsIExpatSink be on the same wavelength as far as passing

attributes to HandleStartElement.  Update callees as needed.  Bug 223470,
r=sicking, sr=peterv
This commit is contained in:
bzbarsky%mit.edu 2003-10-30 02:17:50 +00:00
Родитель 7d964c30f6
Коммит 38f1930059
11 изменённых файлов: 168 добавлений и 34 удалений

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

@ -230,7 +230,7 @@ NS_IMETHODIMP
nsXBLContentSink::HandleStartElement(const PRUnichar *aName, nsXBLContentSink::HandleStartElement(const PRUnichar *aName,
const PRUnichar **aAtts, const PRUnichar **aAtts,
PRUint32 aAttsCount, PRUint32 aAttsCount,
PRUint32 aIndex, PRInt32 aIndex,
PRUint32 aLineNumber) PRUint32 aLineNumber)
{ {
nsresult rv = nsXMLContentSink::HandleStartElement(aName,aAtts,aAttsCount,aIndex,aLineNumber); nsresult rv = nsXMLContentSink::HandleStartElement(aName,aAtts,aAttsCount,aIndex,aLineNumber);

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

@ -91,7 +91,7 @@ public:
NS_IMETHOD HandleStartElement(const PRUnichar *aName, NS_IMETHOD HandleStartElement(const PRUnichar *aName,
const PRUnichar **aAtts, const PRUnichar **aAtts,
PRUint32 aAttsCount, PRUint32 aAttsCount,
PRUint32 aIndex, PRInt32 aIndex,
PRUint32 aLineNumber); PRUint32 aLineNumber);
NS_IMETHOD HandleEndElement(const PRUnichar *aName); NS_IMETHOD HandleEndElement(const PRUnichar *aName);

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

@ -139,7 +139,7 @@ NS_IMETHODIMP
nsLoadSaveContentSink::HandleStartElement(const PRUnichar *aName, nsLoadSaveContentSink::HandleStartElement(const PRUnichar *aName,
const PRUnichar **aAtts, const PRUnichar **aAtts,
PRUint32 aAttsCount, PRUint32 aAttsCount,
PRUint32 aIndex, PRInt32 aIndex,
PRUint32 aLineNumber) PRUint32 aLineNumber)
{ {
return mExpatSink->HandleStartElement(aName, aAtts, aAttsCount, aIndex, return mExpatSink->HandleStartElement(aName, aAtts, aAttsCount, aIndex,

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

@ -1115,9 +1115,14 @@ NS_IMETHODIMP
nsXMLContentSink::HandleStartElement(const PRUnichar *aName, nsXMLContentSink::HandleStartElement(const PRUnichar *aName,
const PRUnichar **aAtts, const PRUnichar **aAtts,
PRUint32 aAttsCount, PRUint32 aAttsCount,
PRUint32 aIndex, PRInt32 aIndex,
PRUint32 aLineNumber) PRUint32 aLineNumber)
{ {
NS_PRECONDITION(aIndex >= -1, "Bogus aIndex");
NS_PRECONDITION(aAttsCount % 2 == 0, "incorrect aAttsCount");
// Adjust aAttsCount so it's the actual number of attributes
aAttsCount /= 2;
nsresult result = NS_OK; nsresult result = NS_OK;
PRBool appendContent = PR_TRUE; PRBool appendContent = PR_TRUE;
nsCOMPtr<nsIContent> content; nsCOMPtr<nsIContent> content;
@ -1193,7 +1198,7 @@ nsXMLContentSink::HandleStartElement(const PRUnichar *aName,
} }
// Set the ID attribute atom on the node info object for this node // Set the ID attribute atom on the node info object for this node
if ((aIndex != (PRUint32)-1) && NS_SUCCEEDED(result)) { if (aIndex != -1 && NS_SUCCEEDED(result)) {
nsCOMPtr<nsIAtom> IDAttr = do_GetAtom(aAtts[aIndex]); nsCOMPtr<nsIAtom> IDAttr = do_GetAtom(aAtts[aIndex]);
if (IDAttr) { if (IDAttr) {
@ -1472,7 +1477,7 @@ nsXMLContentSink::ReportError(const PRUnichar* aErrorText,
const PRUnichar* atts[] = {name.get(), value.get(), nsnull}; const PRUnichar* atts[] = {name.get(), value.get(), nsnull};
rv = HandleStartElement(NS_LITERAL_STRING("parsererror").get(), atts, 1, rv = HandleStartElement(NS_LITERAL_STRING("parsererror").get(), atts, 1,
(PRUint32)-1, (PRUint32)-1); -1, (PRUint32)-1);
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
rv = HandleCharacterData(aErrorText, nsCRT::strlen(aErrorText)); rv = HandleCharacterData(aErrorText, nsCRT::strlen(aErrorText));
@ -1480,7 +1485,7 @@ nsXMLContentSink::ReportError(const PRUnichar* aErrorText,
const PRUnichar* noAtts[] = {0, 0}; const PRUnichar* noAtts[] = {0, 0};
rv = HandleStartElement(NS_LITERAL_STRING("sourcetext").get(), noAtts, 0, rv = HandleStartElement(NS_LITERAL_STRING("sourcetext").get(), noAtts, 0,
(PRUint32)-1, (PRUint32)-1); -1, (PRUint32)-1);
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
rv = HandleCharacterData(aSourceText, nsCRT::strlen(aSourceText)); rv = HandleCharacterData(aSourceText, nsCRT::strlen(aSourceText));

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

@ -767,12 +767,17 @@ NS_IMETHODIMP
XULContentSinkImpl::HandleStartElement(const PRUnichar *aName, XULContentSinkImpl::HandleStartElement(const PRUnichar *aName,
const PRUnichar **aAtts, const PRUnichar **aAtts,
PRUint32 aAttsCount, PRUint32 aAttsCount,
PRUint32 aIndex, PRInt32 aIndex,
PRUint32 aLineNumber) PRUint32 aLineNumber)
{ {
// XXX Hopefully the parser will flag this before we get here. If // XXX Hopefully the parser will flag this before we get here. If
// we're in the epilog, there should be no new elements // we're in the epilog, there should be no new elements
NS_PRECONDITION(mState != eInEpilog, "tag in XUL doc epilog"); NS_PRECONDITION(mState != eInEpilog, "tag in XUL doc epilog");
NS_PRECONDITION(aIndex >= -1, "Bogus aIndex");
NS_PRECONDITION(aAttsCount % 2 == 0, "incorrect aAttsCount");
// Adjust aAttsCount so it's the actual number of attributes
aAttsCount /= 2;
if (mState == eInEpilog) if (mState == eInEpilog)
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
@ -813,7 +818,7 @@ XULContentSinkImpl::HandleStartElement(const PRUnichar *aName,
} }
// Set the ID attribute atom on the node info object for this node // Set the ID attribute atom on the node info object for this node
if ((aIndex != (PRUint32)-1) && NS_SUCCEEDED(rv)) { if (aIndex != -1 && NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIAtom> IDAttr = do_GetAtom(aAtts[aIndex]); nsCOMPtr<nsIAtom> IDAttr = do_GetAtom(aAtts[aIndex]);
if (IDAttr) { if (IDAttr) {
@ -1079,14 +1084,14 @@ XULContentSinkImpl::ReportError(const PRUnichar* aErrorText,
const PRUnichar* atts[] = {name.get(), value.get(), nsnull};; const PRUnichar* atts[] = {name.get(), value.get(), nsnull};;
rv = HandleStartElement(NS_LITERAL_STRING("parsererror").get(), atts, 1, 0, 0); rv = HandleStartElement(NS_LITERAL_STRING("parsererror").get(), atts, 1, -1, 0);
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
rv = HandleCharacterData(aErrorText, nsCRT::strlen(aErrorText)); rv = HandleCharacterData(aErrorText, nsCRT::strlen(aErrorText));
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
const PRUnichar* noAtts[] = {0, 0}; const PRUnichar* noAtts[] = {0, 0};
rv = HandleStartElement(NS_LITERAL_STRING("sourcetext").get(), noAtts, 0, 0, 0); rv = HandleStartElement(NS_LITERAL_STRING("sourcetext").get(), noAtts, 0, -1, 0);
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
rv = HandleCharacterData(aSourceText, nsCRT::strlen(aSourceText)); rv = HandleCharacterData(aSourceText, nsCRT::strlen(aSourceText));

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

@ -148,13 +148,13 @@ NS_IMETHODIMP
txStylesheetSink::HandleStartElement(const PRUnichar *aName, txStylesheetSink::HandleStartElement(const PRUnichar *aName,
const PRUnichar **aAtts, const PRUnichar **aAtts,
PRUint32 aAttsCount, PRUint32 aAttsCount,
PRUint32 aIndex, PRInt32 aIndex,
PRUint32 aLineNumber) PRUint32 aLineNumber)
{ {
// XXX aIndex should be a signed int, that's a bug in the NS_PRECONDITION(aAttsCount % 2 == 0, "incorrect aAttsCount");
// Mozilla content sink api.
nsresult rv = nsresult rv =
mCompiler->startElement(aName, aAtts, aAttsCount, (PRInt32)aIndex); mCompiler->startElement(aName, aAtts, aAttsCount / 2, aIndex);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
mCompiler->cancel(rv); mCompiler->cancel(rv);

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

@ -38,31 +38,82 @@
#include "nsISupports.idl" #include "nsISupports.idl"
/**
* This interface should be implemented by any content sink that wants
* to get output from expat and do something with it; in other words,
* by any sink that handles some sort of XML dialect.
*/
[scriptable, uuid(1DEEA160-C661-11d5-84CC-0010A4E0C706)] [scriptable, uuid(1DEEA160-C661-11d5-84CC-0010A4E0C706)]
interface nsIExpatSink : nsISupports interface nsIExpatSink : nsISupports
{ {
/**
* Called to handle the opening tag of an element.
* @param aName the fully qualified tagname of the element
* @param aAtts the array of attribute names and values. There are
* aAttsCount/2 names and aAttsCount/2 values, so the total number of
* elements in the array is aAttsCount. The names and values
* alternate. Thus, if we number attributes starting with 0,
* aAtts[2*k] is the name of the k-th attribute and aAtts[2*k+1] is
* the value of that attribute Both explicitly specified attributes
* and attributes that are defined to have default values in a DTD are
* present in aAtts.
* @param aAttsCount the number of elements in aAtts.
* @param aIndex If the element has an attribute of type ID, then
* aAtts[aIndex] is the name of that attribute. Otherwise, aIndex
* is -1
* @param aLineNumber the line number of the start tag in the data stream.
*/
void HandleStartElement(in wstring aName, void HandleStartElement(in wstring aName,
[array, size_is(aAttsCount)] in wstring aAtts, [array, size_is(aAttsCount)] in wstring aAtts,
in unsigned long aAttsCount, in unsigned long aAttsCount,
in unsigned long aIndex, in long aIndex,
in unsigned long aLineNumber); in unsigned long aLineNumber);
/**
* Called to handle the closing tag of an element.
* @param aName the fully qualified tagname of the element
*/
void HandleEndElement(in wstring aName); void HandleEndElement(in wstring aName);
void HandleComment(in wstring aName); /**
* Called to handle a comment
* @param aCommentText the text of the comment (not including the
* "<!--" and "-->")
*/
void HandleComment(in wstring aCommentText);
void HandleCDataSection(in wstring aData, /**
* Called to handle a CDATA section
* @param aData the text in the CDATA section. This is null-terminated.
* @param aLength the length of the aData string
*/
void HandleCDataSection([size_is(aLength)] in wstring aData,
in unsigned long aLength); in unsigned long aLength);
/**
* Called to handle the doctype declaration
*/
void HandleDoctypeDecl(in AString aSubset, void HandleDoctypeDecl(in AString aSubset,
in AString aName, in AString aName,
in AString aSystemId, in AString aSystemId,
in AString aPublicId, in AString aPublicId,
in nsISupports aCatalogData); in nsISupports aCatalogData);
void HandleCharacterData(in wstring aData, /**
* Called to handle character data. Note that this does NOT get
* called for the contents of CDATA sections.
* @param aData the data to handle. aData is NOT NULL-TERMINATED.
* @param aLength the length of the aData string
*/
void HandleCharacterData([size_is(aLength)] in wstring aData,
in unsigned long aLength); in unsigned long aLength);
/**
* Called to handle a processing instruction
* @param aTarget the PI target (e.g. xml-stylesheet)
* @param aData all the rest of the data in the PI
*/
void HandleProcessingInstruction(in wstring aTarget, void HandleProcessingInstruction(in wstring aTarget,
in wstring aData); in wstring aData);
@ -73,7 +124,7 @@ interface nsIExpatSink : nsISupports
* @param aLength The length of the declaration from * @param aLength The length of the declaration from
* opening '<' to closing '>'. * opening '<' to closing '>'.
**/ **/
void HandleXMLDeclaration(in wstring aData, void HandleXMLDeclaration([size_is(aLength)] in wstring aData,
in unsigned long aLength); in unsigned long aLength);
void ReportError(in wstring aErrorText, void ReportError(in wstring aErrorText,

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

@ -346,9 +346,20 @@ nsExpatDriver::HandleStartElement(const PRUnichar *aValue,
{ {
NS_ASSERTION(mSink, "content sink not found!"); NS_ASSERTION(mSink, "content sink not found!");
// Calculate the total number of elements in aAtts.
// XML_GetSpecifiedAttributeCount will only give us the number of specified
// attrs (twice that number, actually), so we have to check for default attrs
// ourselves.
PRUint32 attrArrayLength;
for (attrArrayLength = XML_GetSpecifiedAttributeCount(mExpatParser);
aAtts[attrArrayLength];
attrArrayLength += 2) {
// Just looping till we find out what the length is
}
if (mSink){ if (mSink){
mSink->HandleStartElement(aValue, aAtts, mSink->HandleStartElement(aValue, aAtts,
XML_GetSpecifiedAttributeCount(mExpatParser) / 2, attrArrayLength,
XML_GetIdAttributeIndex(mExpatParser), XML_GetIdAttributeIndex(mExpatParser),
XML_GetCurrentLineNumber(mExpatParser)); XML_GetCurrentLineNumber(mExpatParser));
} }

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

@ -38,31 +38,82 @@
#include "nsISupports.idl" #include "nsISupports.idl"
/**
* This interface should be implemented by any content sink that wants
* to get output from expat and do something with it; in other words,
* by any sink that handles some sort of XML dialect.
*/
[scriptable, uuid(1DEEA160-C661-11d5-84CC-0010A4E0C706)] [scriptable, uuid(1DEEA160-C661-11d5-84CC-0010A4E0C706)]
interface nsIExpatSink : nsISupports interface nsIExpatSink : nsISupports
{ {
/**
* Called to handle the opening tag of an element.
* @param aName the fully qualified tagname of the element
* @param aAtts the array of attribute names and values. There are
* aAttsCount/2 names and aAttsCount/2 values, so the total number of
* elements in the array is aAttsCount. The names and values
* alternate. Thus, if we number attributes starting with 0,
* aAtts[2*k] is the name of the k-th attribute and aAtts[2*k+1] is
* the value of that attribute Both explicitly specified attributes
* and attributes that are defined to have default values in a DTD are
* present in aAtts.
* @param aAttsCount the number of elements in aAtts.
* @param aIndex If the element has an attribute of type ID, then
* aAtts[aIndex] is the name of that attribute. Otherwise, aIndex
* is -1
* @param aLineNumber the line number of the start tag in the data stream.
*/
void HandleStartElement(in wstring aName, void HandleStartElement(in wstring aName,
[array, size_is(aAttsCount)] in wstring aAtts, [array, size_is(aAttsCount)] in wstring aAtts,
in unsigned long aAttsCount, in unsigned long aAttsCount,
in unsigned long aIndex, in long aIndex,
in unsigned long aLineNumber); in unsigned long aLineNumber);
/**
* Called to handle the closing tag of an element.
* @param aName the fully qualified tagname of the element
*/
void HandleEndElement(in wstring aName); void HandleEndElement(in wstring aName);
void HandleComment(in wstring aName); /**
* Called to handle a comment
* @param aCommentText the text of the comment (not including the
* "<!--" and "-->")
*/
void HandleComment(in wstring aCommentText);
void HandleCDataSection(in wstring aData, /**
* Called to handle a CDATA section
* @param aData the text in the CDATA section. This is null-terminated.
* @param aLength the length of the aData string
*/
void HandleCDataSection([size_is(aLength)] in wstring aData,
in unsigned long aLength); in unsigned long aLength);
/**
* Called to handle the doctype declaration
*/
void HandleDoctypeDecl(in AString aSubset, void HandleDoctypeDecl(in AString aSubset,
in AString aName, in AString aName,
in AString aSystemId, in AString aSystemId,
in AString aPublicId, in AString aPublicId,
in nsISupports aCatalogData); in nsISupports aCatalogData);
void HandleCharacterData(in wstring aData, /**
* Called to handle character data. Note that this does NOT get
* called for the contents of CDATA sections.
* @param aData the data to handle. aData is NOT NULL-TERMINATED.
* @param aLength the length of the aData string
*/
void HandleCharacterData([size_is(aLength)] in wstring aData,
in unsigned long aLength); in unsigned long aLength);
/**
* Called to handle a processing instruction
* @param aTarget the PI target (e.g. xml-stylesheet)
* @param aData all the rest of the data in the PI
*/
void HandleProcessingInstruction(in wstring aTarget, void HandleProcessingInstruction(in wstring aTarget,
in wstring aData); in wstring aData);
@ -73,7 +124,7 @@ interface nsIExpatSink : nsISupports
* @param aLength The length of the declaration from * @param aLength The length of the declaration from
* opening '<' to closing '>'. * opening '<' to closing '>'.
**/ **/
void HandleXMLDeclaration(in wstring aData, void HandleXMLDeclaration([size_is(aLength)] in wstring aData,
in unsigned long aLength); in unsigned long aLength);
void ReportError(in wstring aErrorText, void ReportError(in wstring aErrorText,

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

@ -346,9 +346,20 @@ nsExpatDriver::HandleStartElement(const PRUnichar *aValue,
{ {
NS_ASSERTION(mSink, "content sink not found!"); NS_ASSERTION(mSink, "content sink not found!");
// Calculate the total number of elements in aAtts.
// XML_GetSpecifiedAttributeCount will only give us the number of specified
// attrs (twice that number, actually), so we have to check for default attrs
// ourselves.
PRUint32 attrArrayLength;
for (attrArrayLength = XML_GetSpecifiedAttributeCount(mExpatParser);
aAtts[attrArrayLength];
attrArrayLength += 2) {
// Just looping till we find out what the length is
}
if (mSink){ if (mSink){
mSink->HandleStartElement(aValue, aAtts, mSink->HandleStartElement(aValue, aAtts,
XML_GetSpecifiedAttributeCount(mExpatParser) / 2, attrArrayLength,
XML_GetIdAttributeIndex(mExpatParser), XML_GetIdAttributeIndex(mExpatParser),
XML_GetCurrentLineNumber(mExpatParser)); XML_GetCurrentLineNumber(mExpatParser));
} }

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

@ -497,7 +497,7 @@ NS_IMETHODIMP
RDFContentSinkImpl::HandleStartElement(const PRUnichar *aName, RDFContentSinkImpl::HandleStartElement(const PRUnichar *aName,
const PRUnichar **aAtts, const PRUnichar **aAtts,
PRUint32 aAttsCount, PRUint32 aAttsCount,
PRUint32 aIndex, PRInt32 aIndex,
PRUint32 aLineNumber) PRUint32 aLineNumber)
{ {
FlushText(); FlushText();