Fix for bug 8607. DOCTYPE decls are now propagated from the XML tokenizer to the XML content sink.

This commit is contained in:
nisheeth%netscape.com 1999-08-07 06:26:01 +00:00
Родитель 10bf2abb17
Коммит f271357886
12 изменённых файлов: 52 добавлений и 140 удалений

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

@ -501,7 +501,6 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag,
case eToken_cdatasection: result=new CCDATASectionToken(); break;
case eToken_error: result=new CErrorToken(); break;
case eToken_doctypeDecl: result=new CDoctypeDeclToken(); break;
case eToken_xmlDecl: result=new CXMLDeclToken(); break;
default:
break;
}
@ -543,7 +542,6 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag)
case eToken_cdatasection: result=new CCDATASectionToken(); break;
case eToken_error: result=new CErrorToken(); break;
case eToken_doctypeDecl: result=new CDoctypeDeclToken(); break;
case eToken_xmlDecl: result=new CXMLDeclToken(); break;
default:
break;
}

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

@ -132,7 +132,8 @@ void nsExpatTokenizer::SetupExpatCallbacks(void) {
XML_SetNotationDeclHandler(mExpatParser, HandleNotationDecl);
XML_SetExternalEntityRefHandler(mExpatParser, HandleExternalEntityRef);
XML_SetCommentHandler(mExpatParser, HandleComment);
XML_SetUnknownEncodingHandler(mExpatParser, HandleUnknownEncoding, NULL);
XML_SetUnknownEncodingHandler(mExpatParser, HandleUnknownEncoding, NULL);
XML_SetDoctypeDeclHandler(mExpatParser, HandleStartDoctypeDecl, HandleEndDoctypeDecl);
}
}
@ -475,37 +476,7 @@ void nsExpatTokenizer::HandleProcessingInstruction(void *userData, const XML_Cha
}
void nsExpatTokenizer::HandleDefault(void *userData, const XML_Char *s, int len) {
nsString str = (PRUnichar*) s;
CToken* token = (CToken*) userData;
PRBool ProcessingDocTypeDecl = (token != nsnull);
str.Truncate(len);
if (ProcessingDocTypeDecl) {
nsString& tokenStr = token->GetStringValueXXX();
tokenStr.Append(str);
if (str == "]") {
tokenStr.Append(">");
AddToken(token, NS_OK, *gTokenDeque, gTokenRecycler);
XML_SetUserData(gExpatParser, nsnull);
}
}
else if (0 == str.Find(kXMLDeclPrefix)) {
str.CompressWhitespace(PR_TRUE, PR_TRUE);
if (nsString::IsSpace(str[nsCRT::strlen(kXMLDeclPrefix)])) {
// Create the XML decl token
token = gTokenRecycler->CreateTokenOfType(eToken_xmlDecl, eHTMLTag_unknown);
nsString& tokenStr = token->GetStringValueXXX();
tokenStr.Append(str);
AddToken(token, NS_OK, *gTokenDeque, gTokenRecycler);
}
}
else if (0 == str.Find(kDocTypeDeclPrefix)) {
// Create the DOCTYPE decl token
token = gTokenRecycler->CreateTokenOfType(eToken_doctypeDecl, eHTMLTag_unknown);
nsString& tokenStr = token->GetStringValueXXX();
tokenStr.Append(str);
XML_SetUserData(gExpatParser, (void*) token);
}
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleDefault() not yet implemented.");
}
void nsExpatTokenizer::HandleUnparsedEntityDecl(void *userData,
@ -660,3 +631,21 @@ int nsExpatTokenizer::HandleUnknownEncoding(void *encodingHandlerData,
return result;
}
void nsExpatTokenizer::HandleStartDoctypeDecl(void *userData,
const XML_Char *doctypeName)
{
CToken* token=gTokenRecycler->CreateTokenOfType(eToken_doctypeDecl,eHTMLTag_unknown);
if (token) {
nsString& str = token->GetStringValueXXX();
str.Append(kDocTypeDeclPrefix);
str.Append(" ");
str.Append((PRUnichar*) doctypeName);
str.Append(">");
AddToken(token,NS_OK,*gTokenDeque,gTokenRecycler);
}
}
void nsExpatTokenizer::HandleEndDoctypeDecl(void *userData)
{
// Do nothing
}

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

@ -120,6 +120,9 @@ protected:
static int HandleUnknownEncoding(void *encodingHandlerData,
const XML_Char *name,
XML_Encoding *info);
static void HandleStartDoctypeDecl(void *userData,
const XML_Char *doctypeName);
static void HandleEndDoctypeDecl(void *userData);
XML_Parser mExpatParser;
PRUint32 mBytesParsed;

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

@ -1920,17 +1920,4 @@ const char* CDoctypeDeclToken::GetClassName(void) {
PRInt32 CDoctypeDeclToken::GetTokenType(void) {
return eToken_doctypeDecl;
}
// XML decl token
CXMLDeclToken::CXMLDeclToken() : CHTMLToken(eHTMLTag_unknown) {
}
const char* CXMLDeclToken::GetClassName(void) {
return "xmldecl";
}
PRInt32 CXMLDeclToken::GetTokenType(void) {
return eToken_xmlDecl;
}
}

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

@ -56,7 +56,7 @@ enum eHTMLTokenTypes {
eToken_start=1, eToken_end, eToken_comment, eToken_entity,
eToken_whitespace, eToken_newline, eToken_text, eToken_attribute,
eToken_script, eToken_style, eToken_skippedcontent, eToken_instruction,
eToken_cdatasection, eToken_error, eToken_doctypeDecl, eToken_xmlDecl,
eToken_cdatasection, eToken_error, eToken_doctypeDecl,
eToken_last //make sure this stays the last token...
};
@ -393,18 +393,4 @@ public:
virtual PRInt32 GetTokenType(void);
};
/**
* XXX This token is in here temporarily. It will be removed
* once generic tokens are implemented. It is generated by the
* expat tokenizer when it sees an XML declaration ("<?xml ... ?>).
*
*/
class CXMLDeclToken: public CHTMLToken {
public:
CXMLDeclToken();
virtual const char* GetClassName(void);
virtual PRInt32 GetTokenType(void);
};
#endif

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

@ -566,13 +566,6 @@ NS_IMETHODIMP CWellFormedDTD::HandleToken(CToken* aToken,nsIParser* aParser) {
result = mSink->NotifyError(errTok->GetError());
}
break;
case eToken_xmlDecl:
{
nsCOMPtr<nsIXMLContentSink> xmlSink(do_QueryInterface(mSink, &result));
if (NS_SUCCEEDED(result))
result = xmlSink->AddXMLDecl(theNode);
}
break;
case eToken_doctypeDecl:
result = mSink->AddDocTypeDecl(theNode, 0);
break;

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

@ -501,7 +501,6 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag,
case eToken_cdatasection: result=new CCDATASectionToken(); break;
case eToken_error: result=new CErrorToken(); break;
case eToken_doctypeDecl: result=new CDoctypeDeclToken(); break;
case eToken_xmlDecl: result=new CXMLDeclToken(); break;
default:
break;
}
@ -543,7 +542,6 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag)
case eToken_cdatasection: result=new CCDATASectionToken(); break;
case eToken_error: result=new CErrorToken(); break;
case eToken_doctypeDecl: result=new CDoctypeDeclToken(); break;
case eToken_xmlDecl: result=new CXMLDeclToken(); break;
default:
break;
}

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

@ -132,7 +132,8 @@ void nsExpatTokenizer::SetupExpatCallbacks(void) {
XML_SetNotationDeclHandler(mExpatParser, HandleNotationDecl);
XML_SetExternalEntityRefHandler(mExpatParser, HandleExternalEntityRef);
XML_SetCommentHandler(mExpatParser, HandleComment);
XML_SetUnknownEncodingHandler(mExpatParser, HandleUnknownEncoding, NULL);
XML_SetUnknownEncodingHandler(mExpatParser, HandleUnknownEncoding, NULL);
XML_SetDoctypeDeclHandler(mExpatParser, HandleStartDoctypeDecl, HandleEndDoctypeDecl);
}
}
@ -475,37 +476,7 @@ void nsExpatTokenizer::HandleProcessingInstruction(void *userData, const XML_Cha
}
void nsExpatTokenizer::HandleDefault(void *userData, const XML_Char *s, int len) {
nsString str = (PRUnichar*) s;
CToken* token = (CToken*) userData;
PRBool ProcessingDocTypeDecl = (token != nsnull);
str.Truncate(len);
if (ProcessingDocTypeDecl) {
nsString& tokenStr = token->GetStringValueXXX();
tokenStr.Append(str);
if (str == "]") {
tokenStr.Append(">");
AddToken(token, NS_OK, *gTokenDeque, gTokenRecycler);
XML_SetUserData(gExpatParser, nsnull);
}
}
else if (0 == str.Find(kXMLDeclPrefix)) {
str.CompressWhitespace(PR_TRUE, PR_TRUE);
if (nsString::IsSpace(str[nsCRT::strlen(kXMLDeclPrefix)])) {
// Create the XML decl token
token = gTokenRecycler->CreateTokenOfType(eToken_xmlDecl, eHTMLTag_unknown);
nsString& tokenStr = token->GetStringValueXXX();
tokenStr.Append(str);
AddToken(token, NS_OK, *gTokenDeque, gTokenRecycler);
}
}
else if (0 == str.Find(kDocTypeDeclPrefix)) {
// Create the DOCTYPE decl token
token = gTokenRecycler->CreateTokenOfType(eToken_doctypeDecl, eHTMLTag_unknown);
nsString& tokenStr = token->GetStringValueXXX();
tokenStr.Append(str);
XML_SetUserData(gExpatParser, (void*) token);
}
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleDefault() not yet implemented.");
}
void nsExpatTokenizer::HandleUnparsedEntityDecl(void *userData,
@ -660,3 +631,21 @@ int nsExpatTokenizer::HandleUnknownEncoding(void *encodingHandlerData,
return result;
}
void nsExpatTokenizer::HandleStartDoctypeDecl(void *userData,
const XML_Char *doctypeName)
{
CToken* token=gTokenRecycler->CreateTokenOfType(eToken_doctypeDecl,eHTMLTag_unknown);
if (token) {
nsString& str = token->GetStringValueXXX();
str.Append(kDocTypeDeclPrefix);
str.Append(" ");
str.Append((PRUnichar*) doctypeName);
str.Append(">");
AddToken(token,NS_OK,*gTokenDeque,gTokenRecycler);
}
}
void nsExpatTokenizer::HandleEndDoctypeDecl(void *userData)
{
// Do nothing
}

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

@ -120,6 +120,9 @@ protected:
static int HandleUnknownEncoding(void *encodingHandlerData,
const XML_Char *name,
XML_Encoding *info);
static void HandleStartDoctypeDecl(void *userData,
const XML_Char *doctypeName);
static void HandleEndDoctypeDecl(void *userData);
XML_Parser mExpatParser;
PRUint32 mBytesParsed;

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

@ -1920,17 +1920,4 @@ const char* CDoctypeDeclToken::GetClassName(void) {
PRInt32 CDoctypeDeclToken::GetTokenType(void) {
return eToken_doctypeDecl;
}
// XML decl token
CXMLDeclToken::CXMLDeclToken() : CHTMLToken(eHTMLTag_unknown) {
}
const char* CXMLDeclToken::GetClassName(void) {
return "xmldecl";
}
PRInt32 CXMLDeclToken::GetTokenType(void) {
return eToken_xmlDecl;
}
}

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

@ -56,7 +56,7 @@ enum eHTMLTokenTypes {
eToken_start=1, eToken_end, eToken_comment, eToken_entity,
eToken_whitespace, eToken_newline, eToken_text, eToken_attribute,
eToken_script, eToken_style, eToken_skippedcontent, eToken_instruction,
eToken_cdatasection, eToken_error, eToken_doctypeDecl, eToken_xmlDecl,
eToken_cdatasection, eToken_error, eToken_doctypeDecl,
eToken_last //make sure this stays the last token...
};
@ -393,18 +393,4 @@ public:
virtual PRInt32 GetTokenType(void);
};
/**
* XXX This token is in here temporarily. It will be removed
* once generic tokens are implemented. It is generated by the
* expat tokenizer when it sees an XML declaration ("<?xml ... ?>).
*
*/
class CXMLDeclToken: public CHTMLToken {
public:
CXMLDeclToken();
virtual const char* GetClassName(void);
virtual PRInt32 GetTokenType(void);
};
#endif

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

@ -566,13 +566,6 @@ NS_IMETHODIMP CWellFormedDTD::HandleToken(CToken* aToken,nsIParser* aParser) {
result = mSink->NotifyError(errTok->GetError());
}
break;
case eToken_xmlDecl:
{
nsCOMPtr<nsIXMLContentSink> xmlSink(do_QueryInterface(mSink, &result));
if (NS_SUCCEEDED(result))
result = xmlSink->AddXMLDecl(theNode);
}
break;
case eToken_doctypeDecl:
result = mSink->AddDocTypeDecl(theNode, 0);
break;