We've decided to do away with the notion of an nsExpatDTD. The expat tokenizer which encapsulates the expat parser will be driven by nsWellFormedDTD. So, nsExpatTokenizer has changed accordingly. nsWellFormedDTD() creates an nsExpatTokenizer if EXPAT is #define'd; otherwise it creates the old nsXMLTokenizer. nsParser no longer registers and createsthe nsExpatDTD.

git-svn-id: svn://10.0.0.236/trunk@22679 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
nisheeth%netscape.com
1999-03-03 02:34:18 +00:00
parent 787945c1bd
commit 8ce7dc3e65
10 changed files with 348 additions and 42 deletions

View File

@@ -307,7 +307,7 @@ void nsExpatDTD::SetupExpatCallbacks(void) {
*/
nsITokenizer* nsExpatDTD::GetTokenizer(void) {
if(!mTokenizer) {
mTokenizer=new nsExpatTokenizer(this);
mTokenizer=new nsExpatTokenizer();
mExpatParser = XML_ParserCreate(NULL);
if (mExpatParser) {
SetupExpatCallbacks();

View File

@@ -95,6 +95,25 @@ NS_HTMLPARS nsresult NS_New_Expat_Tokenizer(nsIDTD** aInstancePtrResult) {
NS_IMPL_ADDREF(nsExpatTokenizer)
NS_IMPL_RELEASE(nsExpatTokenizer)
/**
* Sets up the callbacks for the expat parser
* @update nra 2/24/99
* @param none
* @return none
*/
void nsExpatTokenizer::SetupExpatCallbacks(void) {
if (mExpatParser) {
XML_SetElementHandler(mExpatParser, HandleStartElement, HandleEndElement);
XML_SetCharacterDataHandler(mExpatParser, HandleCharacterData);
XML_SetProcessingInstructionHandler(mExpatParser, HandleProcessingInstruction);
// XML_SetDefaultHandler(mExpatParser, NULL);
// XML_SetUnparsedEntityDeclHandler(mExpatParser, NULL);
XML_SetNotationDeclHandler(mExpatParser, HandleNotationDecl);
// XML_SetExternalEntityRefHandler(mExpatParser, NULL);
// XML_SetUnknownEncodingHandler(mExpatParser, NULL, NULL);
}
}
/**
* Default constructor
@@ -103,9 +122,12 @@ NS_IMPL_RELEASE(nsExpatTokenizer)
* @param
* @return
*/
nsExpatTokenizer::nsExpatTokenizer(nsExpatDTD *aDTD) : nsHTMLTokenizer() {
nsExpatTokenizer::nsExpatTokenizer() : nsHTMLTokenizer() {
NS_INIT_REFCNT();
mExpatDTD = aDTD;
mExpatParser = XML_ParserCreate(NULL);
if (mExpatParser) {
SetupExpatCallbacks();
}
}
/**
@@ -116,7 +138,8 @@ nsExpatTokenizer::nsExpatTokenizer(nsExpatDTD *aDTD) : nsHTMLTokenizer() {
* @return
*/
nsExpatTokenizer::~nsExpatTokenizer(){
if (mExpatParser)
XML_ParserFree(mExpatParser);
}
@@ -124,6 +147,23 @@ nsExpatTokenizer::~nsExpatTokenizer(){
Here begins the real working methods for the tokenizer.
*******************************************************************/
nsresult nsExpatTokenizer::ParseXMLBuffer(const char *buffer){
nsresult result=NS_OK;
if (mExpatParser) {
if (!XML_Parse(mExpatParser, buffer, strlen(buffer), PR_FALSE)) {
// XXX Add code here to implement error propagation to the
// content sink.
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::ParseXMLBuffer(): \
Error propogation from expat not yet implemented.");
result = NS_ERROR_FAILURE;
}
}
else {
result = NS_ERROR_FAILURE;
}
return result;
}
/**
* This method repeatedly called by the tokenizer.
* Each time, we determine the kind of token were about to
@@ -149,16 +189,81 @@ nsresult nsExpatTokenizer::ConsumeToken(nsScanner& aScanner) {
// XXX Rick should add a method to the scanner that gives me the
// entire contents of the scanner's buffer without calling
// GetChar() repeatedly.
result = aScanner.ReadUntil(buffer, '\0', PR_FALSE);
if (aScanner.Eof() == result || NS_OK == result) {
buffer = aScanner.GetBuffer();
if (buffer) {
expatBuffer = buffer.ToNewCString();
if (expatBuffer && mExpatDTD) {
// XXX Who takes ownership of expatBuffer?
result = mExpatDTD->ParseXMLBuffer(expatBuffer);
if (expatBuffer) {
result = ParseXMLBuffer(expatBuffer);
delete [] expatBuffer;
}
}
return result;
}
/***************************************/
/* Expat Callback Functions start here */
/***************************************/
void nsExpatTokenizer::HandleStartElement(void *userData, const XML_Char *name, const XML_Char **atts)
{
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleStartElement() not yet implemented.");
}
void nsExpatTokenizer::HandleEndElement(void *userData, const XML_Char *name)
{
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleEndElement() not yet implemented.");
}
void nsExpatTokenizer::HandleCharacterData(void *userData, const XML_Char *s, int len)
{
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleCharacterData() not yet implemented.");
}
void nsExpatTokenizer::HandleProcessingInstruction(void *userData,
const XML_Char *target,
const XML_Char *data)
{
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleProcessingInstruction() not yet implemented.");
}
void nsExpatTokenizer::HandleDefault(void *userData, const XML_Char *s, int len)
{
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleDefault() not yet implemented.");
}
void nsExpatTokenizer::HandleUnparsedEntityDecl(void *userData,
const XML_Char *entityName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId,
const XML_Char *notationName)
{
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleUnparsedEntityDecl() not yet implemented.");
}
void nsExpatTokenizer::HandleNotationDecl(void *userData,
const XML_Char *notationName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId)
{
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleNotationDecl() not yet implemented.");
}
void nsExpatTokenizer::HandleExternalEntityRef(XML_Parser parser,
const XML_Char *openEntityNames,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId)
{
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleExternalEntityRef() not yet implemented.");
}
void nsExpatTokenizer::HandleUnknownEncoding(void *encodingHandlerData,
const XML_Char *name,
XML_Encoding *info)
{
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleUnknownEncoding() not yet implemented.");
}

View File

@@ -29,7 +29,7 @@
#include "nsISupports.h"
#include "nsHTMLTokenizer.h"
#include "prtypes.h"
#include "nsExpatDTD.h"
#include "xmlparse.h"
#define NS_EXPATTOKENIZER_IID \
{0x483836aa, 0xcabe, 0x11d2, { 0xab, 0xcb, 0x0, 0x10, 0x4b, 0x98, 0x3f, 0xd4 }}
@@ -45,7 +45,7 @@
CLASS_EXPORT_HTMLPARS nsExpatTokenizer : public nsHTMLTokenizer {
public:
nsExpatTokenizer(nsExpatDTD *aDTD=0);
nsExpatTokenizer();
virtual ~nsExpatTokenizer();
NS_DECL_ISUPPORTS
@@ -54,7 +54,51 @@ public:
virtual nsresult ConsumeToken(nsScanner& aScanner);
protected:
nsExpatDTD *mExpatDTD;
/**
* Parse an XML buffer using expat
* @update nra 2/29/99
* @return NS_ERROR_FAILURE if expat encounters an error, else NS_OK
*/
nsresult ParseXMLBuffer(const char *buffer);
/**
* Sets up the callbacks for the expat parser
* @update nra 2/24/99
* @param none
* @return none
*/
void SetupExpatCallbacks(void);
/* The callback handlers that get called from the expat parser */
static void HandleStartElement(void *userData, const XML_Char *name, const XML_Char **atts);
static void HandleEndElement(void *userData, const XML_Char *name);
static void HandleCharacterData(void *userData, const XML_Char *s, int len);
static void HandleProcessingInstruction(void *userData,
const XML_Char *target,
const XML_Char *data);
static void HandleDefault(void *userData, const XML_Char *s, int len);
static void HandleUnparsedEntityDecl(void *userData,
const XML_Char *entityName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId,
const XML_Char *notationName);
static void HandleNotationDecl(void *userData,
const XML_Char *notationName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
static void HandleExternalEntityRef(XML_Parser parser,
const XML_Char *openEntityNames,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
static void HandleUnknownEncoding(void *encodingHandlerData,
const XML_Char *name,
XML_Encoding *info);
XML_Parser mExpatParser;
};
extern NS_HTMLPARS nsresult NS_Expat_Tokenizer(nsIDTD** aInstancePtrResult);

View File

@@ -31,9 +31,6 @@
#include "CNavDTD.h"
#include "nsWellFormedDTD.h"
#include "nsViewSourceHTML.h" //uncomment this to partially enable viewsource...
#ifdef EXPAT
#include "nsExpatDTD.h"
#endif
#undef rickgdebug
#ifdef rickgdebug
@@ -93,12 +90,7 @@ public:
nsIDTD* theDTD;
#ifndef EXPAT
NS_NewWellFormed_DTD(&theDTD);
#else
NS_New_Expat_DTD(&theDTD);
#endif
RegisterDTD(theDTD);
NS_NewNavHTMLDTD(&theDTD); //do this as the default HTML DTD...

View File

@@ -35,6 +35,9 @@
#include "nsIContentSink.h"
#include "nsIHTMLContentSink.h"
#include "nsXMLTokenizer.h"
#ifdef EXPAT
#include "nsExpatTokenizer.h"
#endif
#include "prenv.h" //this is here for debug reasons...
#include "prtypes.h" //this is here for debug reasons...
@@ -136,6 +139,10 @@ CWellFormedDTD::CWellFormedDTD() : nsIDTD() {
*/
CWellFormedDTD::~CWellFormedDTD(){
mParser=0; //just to prove we destructed...
#ifdef EXPAT
if (mTokenizer)
delete (nsExpatTokenizer *) mTokenizer;
#endif
}
/**
@@ -322,8 +329,13 @@ nsITokenRecycler* CWellFormedDTD::GetTokenRecycler(void){
* @return ptr to tokenizer
*/
nsITokenizer* CWellFormedDTD::GetTokenizer(void) {
if(!mTokenizer)
if(!mTokenizer) {
#ifndef EXPAT
mTokenizer=new nsXMLTokenizer();
#else
mTokenizer = new nsExpatTokenizer();
#endif
}
return mTokenizer;
}