зеркало из https://github.com/mozilla/pjs.git
105137 - Eliminate nsTokens, nsParserNode usage for xml/xbl/xul/rdf documents. r=heikki, sr=jst
This commit is contained in:
Родитель
9fc8a911cb
Коммит
fd33e7c446
|
@ -759,7 +759,8 @@ sub BuildClientDist()
|
|||
|
||||
#HTMLPARSER
|
||||
InstallFromManifest(":mozilla:htmlparser:public:MANIFEST", "$distdirectory:htmlparser:");
|
||||
|
||||
InstallFromManifest(":mozilla:htmlparser:public:MANIFEST_IDL", "$distdirectory:idl:");
|
||||
|
||||
#EXPAT
|
||||
InstallFromManifest(":mozilla:expat:xmlparse:MANIFEST", "$distdirectory:expat:");
|
||||
|
||||
|
|
|
@ -94,7 +94,6 @@ public:
|
|||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError) { return NS_OK; }
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode) { return NS_OK; }
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode) { return NS_OK; }
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0) { return NS_OK; }
|
||||
|
|
|
@ -232,12 +232,15 @@ public:
|
|||
NS_IMETHOD WillInterrupt(void);
|
||||
NS_IMETHOD WillResume(void);
|
||||
NS_IMETHOD SetParser(nsIParser* aParser);
|
||||
NS_IMETHOD FlushPendingNotifications();
|
||||
NS_IMETHOD SetDocumentCharset(nsAWritableString& aCharset);
|
||||
|
||||
|
||||
|
||||
// nsIHTMLContentSink
|
||||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError);
|
||||
NS_IMETHOD FlushPendingNotifications();
|
||||
NS_IMETHOD SetDocumentCharset(nsAWritableString& aCharset);
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0);
|
||||
|
@ -246,9 +249,6 @@ public:
|
|||
NS_IMETHOD WillProcessAToken(void);
|
||||
NS_IMETHOD DidProcessAToken(void);
|
||||
NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode);
|
||||
|
||||
|
||||
// nsIHTMLContentSink
|
||||
NS_IMETHOD BeginContext(PRInt32 aID);
|
||||
NS_IMETHOD EndContext(PRInt32 aID);
|
||||
NS_IMETHOD SetTitle(const nsString& aValue);
|
||||
|
@ -5231,14 +5231,6 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode)
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLContentSink::NotifyError(const nsParserError* aError)
|
||||
{
|
||||
// Errors in HTML? Who would have thought!
|
||||
// Why are you telling us, parser. Deal with it yourself.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLContentSink::FlushPendingNotifications()
|
||||
{
|
||||
|
|
|
@ -87,7 +87,6 @@ public:
|
|||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError);
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0);
|
||||
|
@ -663,12 +662,6 @@ nsHTMLFragmentContentSink::AddLeaf(const nsIParserNode& aNode)
|
|||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLFragmentContentSink::NotifyError(const nsParserError* aError)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLFragmentContentSink::AddComment(const nsIParserNode& aNode)
|
||||
{
|
||||
|
|
|
@ -96,6 +96,7 @@ XBL_ATOM(content, "content")
|
|||
XBL_ATOM(constructor, "constructor")
|
||||
XBL_ATOM(destructor, "destructor")
|
||||
XBL_ATOM(inheritstyle, "inheritstyle")
|
||||
XBL_ATOM(button, "button")
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -96,6 +96,7 @@ XBL_ATOM(content, "content")
|
|||
XBL_ATOM(constructor, "constructor")
|
||||
XBL_ATOM(destructor, "destructor")
|
||||
XBL_ATOM(inheritstyle, "inheritstyle")
|
||||
XBL_ATOM(button, "button")
|
||||
|
||||
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -88,33 +88,52 @@ public:
|
|||
nsIWebShell* aContainer);
|
||||
|
||||
// nsIContentSink overrides
|
||||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddCDATASection(const nsIParserNode& aNode);
|
||||
NS_IMETHOD HandleStartElement(const PRUnichar *aName,
|
||||
const PRUnichar **aAtts,
|
||||
const PRUint32 aAttsCount,
|
||||
const PRUint32 aIndex,
|
||||
const PRUint32 aLineNumber);
|
||||
|
||||
NS_IMETHOD HandleEndElement(const PRUnichar *aName);
|
||||
|
||||
NS_IMETHOD HandleCDataSection(const PRUnichar *aData,
|
||||
const PRUint32 aLength);
|
||||
|
||||
protected:
|
||||
// nsXMLContentSink overrides
|
||||
PRBool OnOpenContainer(const PRUnichar **aAtts,
|
||||
PRUint32 aAttsCount,
|
||||
PRInt32 aNameSpaceID,
|
||||
nsIAtom* aTagName);
|
||||
|
||||
nsresult CreateElement(const PRUnichar** aAtts,
|
||||
PRUint32 aAttsCount,
|
||||
PRInt32 aNameSpaceID,
|
||||
nsINodeInfo* aNodeInfo,
|
||||
nsIContent** aResult);
|
||||
|
||||
nsresult AddAttributes(const PRUnichar** aAtts,
|
||||
nsIContent* aContent,
|
||||
PRBool aIsHTML);
|
||||
|
||||
nsresult AddAttributesToXULPrototype(const PRUnichar **aAtts,
|
||||
PRUint32 aAttsCount,
|
||||
nsXULPrototypeElement* aElement);
|
||||
|
||||
// Our own helpers for constructing XBL prototype objects.
|
||||
void ConstructBinding();
|
||||
void ConstructHandler(const PRUnichar **aAtts);
|
||||
void ConstructResource(const PRUnichar **aAtts, nsIAtom* aResourceType);
|
||||
void ConstructImplementation(const PRUnichar **aAtts);
|
||||
void ConstructProperty(const PRUnichar **aAtts);
|
||||
void ConstructMethod(const PRUnichar **aAtts);
|
||||
void ConstructParameter(const PRUnichar **aAtts);
|
||||
void ConstructField(const PRUnichar **aAtts);
|
||||
|
||||
|
||||
// nsXMLContentSink overrides
|
||||
PRBool OnOpenContainer(const nsIParserNode& aNode, PRInt32 aNameSpaceID, nsIAtom* aTagName);
|
||||
nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
|
||||
PRBool* aDidFlush=nsnull);
|
||||
nsresult CreateElement(const nsIParserNode& aNode, PRInt32 aNameSpaceID,
|
||||
nsINodeInfo* aNodeInfo, nsIContent** aResult);
|
||||
nsresult AddAttributes(const nsIParserNode& aNode,
|
||||
nsIContent* aContent,
|
||||
PRBool aIsHTML);
|
||||
|
||||
// Our own helpers for constructing XBL prototype objects.
|
||||
void ConstructBinding();
|
||||
void ConstructHandler(const nsIParserNode& aNode);
|
||||
void ConstructResource(const nsIParserNode& aNode, nsIAtom* aResourceType);
|
||||
void ConstructImplementation(const nsIParserNode& aNode);
|
||||
void ConstructProperty(const nsIParserNode& aNode);
|
||||
void ConstructMethod(const nsIParserNode& aNode);
|
||||
void ConstructParameter(const nsIParserNode& aNode);
|
||||
void ConstructField(const nsIParserNode& aNode);
|
||||
|
||||
nsresult AddAttributesToXULPrototype(const nsIParserNode& aNode, nsXULPrototypeElement* aElement);
|
||||
|
||||
protected:
|
||||
XBLPrimaryState mState;
|
||||
XBLSecondaryState mSecondaryState;
|
||||
|
|
|
@ -90,7 +90,7 @@ NS_NewXBLProtoImpl(nsIXBLPrototypeBinding* aBinding,
|
|||
nsXBLProtoImpl* impl = new nsXBLProtoImpl();
|
||||
if (!impl)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
if (aClassName)
|
||||
if (aClassName && !aClassName->IsEmpty())
|
||||
impl->mClassName.AssignWithConversion(*aClassName);
|
||||
else
|
||||
aBinding->GetBindingURI(impl->mClassName);
|
||||
|
|
|
@ -78,52 +78,6 @@ public:
|
|||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXMLCONTENT_SINK_IID)
|
||||
|
||||
/**
|
||||
* This method is called by the parser when it encounters
|
||||
* the XML declaration for a document.
|
||||
*
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddXMLDecl(const nsIParserNode& aNode)=0;
|
||||
|
||||
/**
|
||||
* This method is called by the parser when it encounters
|
||||
* character data - either regular CDATA or a marked CDATA
|
||||
* section.
|
||||
*
|
||||
* XXX Could be removed in favor of nsIContentSink::AddLeaf
|
||||
*
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddCharacterData(const nsIParserNode& aNode)=0;
|
||||
|
||||
/**
|
||||
* This method is called by the parser when it encounters
|
||||
* an unparsed entity (i.e. NDATA)
|
||||
*
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddUnparsedEntity(const nsIParserNode& aNode)=0;
|
||||
|
||||
/**
|
||||
* This method is called by the parser when it encounters
|
||||
* a notation.
|
||||
*
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddNotation(const nsIParserNode& aNode)=0;
|
||||
|
||||
/**
|
||||
* This method is called by the parser when it encounters
|
||||
* an entity reference. Note that the expectation is that
|
||||
* the content sink itself will expand the entity reference
|
||||
* in the content model.
|
||||
*
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddEntityReference(const nsIParserNode& aNode)=0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
extern nsresult NS_NewXMLContentSink(nsIXMLContentSink** aInstancePtrResult,
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -57,6 +57,7 @@ class nsICSSStyleSheet;
|
|||
#include "nsIScriptLoader.h"
|
||||
#include "nsIScriptLoaderObserver.h"
|
||||
#include "nsSupportsArray.h"
|
||||
#include "nsIExpatSink.h"
|
||||
|
||||
class nsIDocument;
|
||||
class nsIURI;
|
||||
|
@ -83,7 +84,8 @@ class nsXMLContentSink : public nsIXMLContentSink,
|
|||
public nsIObserver,
|
||||
public nsSupportsWeakReference,
|
||||
public nsIScriptLoaderObserver,
|
||||
public nsICSSLoaderObserver
|
||||
public nsICSSLoaderObserver,
|
||||
public nsIExpatSink
|
||||
{
|
||||
public:
|
||||
nsXMLContentSink();
|
||||
|
@ -97,30 +99,16 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISCRIPTLOADEROBSERVER
|
||||
|
||||
NS_DECL_NSIEXPATSINK
|
||||
|
||||
// nsIContentSink
|
||||
NS_IMETHOD WillBuildModel(void);
|
||||
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel);
|
||||
NS_IMETHOD WillInterrupt(void);
|
||||
NS_IMETHOD WillResume(void);
|
||||
NS_IMETHOD SetParser(nsIParser* aParser);
|
||||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddCDATASection(const nsIParserNode& aNode);
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError);
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0);
|
||||
NS_IMETHOD FlushPendingNotifications() { return NS_OK; }
|
||||
NS_IMETHOD SetDocumentCharset(nsAWritableString& aCharset);
|
||||
NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode) { return NS_OK; }
|
||||
|
||||
// nsIXMLContentSink
|
||||
NS_IMETHOD AddXMLDecl(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddCharacterData(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddUnparsedEntity(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddNotation(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddEntityReference(const nsIParserNode& aNode);
|
||||
|
||||
// nsICSSLoaderObserver
|
||||
NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet*aSheet, PRBool aNotify);
|
||||
|
@ -133,15 +121,28 @@ public:
|
|||
protected:
|
||||
void StartLayout();
|
||||
|
||||
nsresult PushNameSpacesFrom(const PRUnichar** aAttributes);
|
||||
nsresult AddAttributes(const PRUnichar** aNode, nsIContent* aContent,PRBool aIsHTML);
|
||||
nsresult AddText(const PRUnichar* aString, PRInt32 aLength);
|
||||
nsresult ProcessStartSCRIPTTag(PRUint32 aLineNo);
|
||||
nsresult ProcessSTYLETag();
|
||||
nsresult ProcessEndSCRIPTTag();
|
||||
|
||||
virtual PRBool OnOpenContainer(const PRUnichar **aAtts,
|
||||
PRUint32 aAttsCount,
|
||||
PRInt32 aNameSpaceID,
|
||||
nsIAtom* aTagName) { return PR_TRUE; }
|
||||
virtual nsresult CreateElement(const PRUnichar** aAtts,
|
||||
PRUint32 aAttsCount,
|
||||
PRInt32 aNameSpaceID,
|
||||
nsINodeInfo* aNodeInfo,
|
||||
nsIContent** aResult);
|
||||
|
||||
virtual nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
|
||||
PRBool* aDidFlush=nsnull);
|
||||
virtual nsresult AddAttributes(const nsIParserNode& aNode,
|
||||
nsIContent* aContent,
|
||||
PRBool aIsHTML);
|
||||
|
||||
nsresult AddContentAsLeaf(nsIContent *aContent);
|
||||
virtual nsresult CreateElement(const nsIParserNode& aNode, PRInt32 aNameSpaceID,
|
||||
nsINodeInfo* aNodeInfo, nsIContent** aResult);
|
||||
nsresult PushNameSpacesFrom(const nsIParserNode& aNode);
|
||||
|
||||
static void SplitXMLName(nsAReadableString& aString, nsIAtom **aPrefix,
|
||||
nsIAtom **aTagName);
|
||||
PRInt32 GetNameSpaceId(nsIAtom* aPrefix);
|
||||
|
@ -152,9 +153,6 @@ protected:
|
|||
PRInt32 PushContent(nsIContent *aContent);
|
||||
nsIContent* PopContent();
|
||||
|
||||
nsresult ProcessEndSCRIPTTag(const nsIParserNode& aNode);
|
||||
nsresult ProcessStartSCRIPTTag(const nsIParserNode& aNode);
|
||||
nsresult ProcessSTYLETag(const nsIParserNode& aNode);
|
||||
|
||||
nsresult ProcessBASETag();
|
||||
nsresult ProcessMETATag();
|
||||
|
@ -173,55 +171,49 @@ protected:
|
|||
nsresult LoadXSLStyleSheet(nsIURI* aUrl);
|
||||
nsresult SetupTransformMediator();
|
||||
|
||||
nsresult AddText(const nsAReadableString& aString);
|
||||
|
||||
static void
|
||||
GetElementFactory(PRInt32 aNameSpaceID, nsIElementFactory** aResult);
|
||||
|
||||
void ScrollToRef();
|
||||
|
||||
virtual PRBool OnOpenContainer(const nsIParserNode& aNode, PRInt32 aNameSpaceID, nsIAtom* aTagName) { return PR_TRUE; };
|
||||
|
||||
|
||||
static nsINameSpaceManager* gNameSpaceManager;
|
||||
static PRUint32 gRefCnt;
|
||||
|
||||
nsIDocument* mDocument;
|
||||
nsIURI* mDocumentURL;
|
||||
nsIURI* mDocumentBaseURL; // can be set via HTTP headers
|
||||
nsIWebShell* mWebShell;
|
||||
nsIParser* mParser;
|
||||
nsIDocument* mDocument;
|
||||
nsIURI* mDocumentURL;
|
||||
nsIURI* mDocumentBaseURL; // can be set via HTTP headers
|
||||
nsIWebShell* mWebShell;
|
||||
nsIParser* mParser;
|
||||
nsIContent* mRootElement;
|
||||
nsIContent* mDocElement;
|
||||
nsAutoVoidArray* mNameSpaceStack;
|
||||
PRUnichar* mText;
|
||||
nsICSSLoader* mCSSLoader;
|
||||
|
||||
nsIContent* mRootElement;
|
||||
nsIContent* mDocElement;
|
||||
nsSupportsArray mScriptElements;
|
||||
XMLContentSinkState mState;
|
||||
|
||||
nsCOMPtr<nsISupportsArray> mContentStack;
|
||||
nsAutoVoidArray* mNameSpaceStack;
|
||||
|
||||
PRUnichar* mText;
|
||||
PRInt32 mTextLength;
|
||||
PRInt32 mTextSize;
|
||||
PRPackedBool mConstrainSize;
|
||||
PRPackedBool mInTitle;
|
||||
|
||||
PRPackedBool mNeedToBlockParser;
|
||||
PRUint32 mScriptLineNo;
|
||||
nsSupportsArray mScriptElements;
|
||||
|
||||
nsString mStyleText;
|
||||
nsString mPreferredStyle;
|
||||
PRInt32 mStyleSheetCount;
|
||||
nsICSSLoader* mCSSLoader;
|
||||
nsCOMPtr<nsINodeInfoManager> mNodeInfoManager;
|
||||
nsCOMPtr<nsITransformMediator> mXSLTransformMediator;
|
||||
|
||||
nsString mPreferredStyle;
|
||||
nsString mRef; // ScrollTo #ref
|
||||
nsString mTitleText;
|
||||
|
||||
PRInt32 mStyleSheetCount;
|
||||
PRInt32 mTextLength;
|
||||
PRInt32 mTextSize;
|
||||
PRUint32 mScriptLineNo;
|
||||
|
||||
PRPackedBool mConstrainSize;
|
||||
PRPackedBool mInTitle;
|
||||
PRPackedBool mNeedToBlockParser;
|
||||
|
||||
nsCOMPtr<nsIHTMLContent> mStyleElement;
|
||||
nsCOMPtr<nsIHTMLContent> mBaseElement;
|
||||
nsCOMPtr<nsIHTMLContent> mMetaElement;
|
||||
nsCOMPtr<nsIHTMLContent> mLinkElement;
|
||||
nsCOMPtr<nsISupportsArray> mContentStack;
|
||||
nsCOMPtr<nsINodeInfoManager> mNodeInfoManager;
|
||||
nsCOMPtr<nsITransformMediator> mXSLTransformMediator;
|
||||
nsCOMPtr<nsIHTMLContent> mStyleElement;
|
||||
nsCOMPtr<nsIHTMLContent> mBaseElement;
|
||||
nsCOMPtr<nsIHTMLContent> mMetaElement;
|
||||
nsCOMPtr<nsIHTMLContent> mLinkElement;
|
||||
};
|
||||
|
||||
#endif // nsXMLContentSink_h__
|
||||
|
|
|
@ -24,32 +24,32 @@ DEPTH=..\..\..\..
|
|||
LIBRARY_NAME=contentxuldocument_s
|
||||
MODULE=content_xul
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
exthandler \
|
||||
mimetype \
|
||||
widget \
|
||||
dom \
|
||||
rdf \
|
||||
js \
|
||||
xpconnect \
|
||||
caps \
|
||||
locale \
|
||||
view \
|
||||
necko \
|
||||
uriloader \
|
||||
htmlparser \
|
||||
lwbrk \
|
||||
chrome \
|
||||
docshell \
|
||||
pref \
|
||||
layout \
|
||||
gfx \
|
||||
layout_xul \
|
||||
content \
|
||||
webshell \
|
||||
webBrowser_core \
|
||||
unicharutil \
|
||||
$(NULL)
|
||||
string \
|
||||
exthandler \
|
||||
mimetype \
|
||||
widget \
|
||||
dom \
|
||||
rdf \
|
||||
js \
|
||||
xpconnect \
|
||||
caps \
|
||||
locale \
|
||||
view \
|
||||
necko \
|
||||
uriloader \
|
||||
htmlparser \
|
||||
lwbrk \
|
||||
chrome \
|
||||
docshell \
|
||||
pref \
|
||||
layout \
|
||||
gfx \
|
||||
layout_xul \
|
||||
content \
|
||||
webshell \
|
||||
webBrowser_core \
|
||||
unicharutil \
|
||||
$(NULL)
|
||||
|
||||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -189,7 +189,6 @@ static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
|||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
|
||||
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
|
||||
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
|
||||
static NS_DEFINE_CID(kXMLElementFactoryCID, NS_XML_ELEMENT_FACTORY_CID);
|
||||
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
|
||||
static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID);
|
||||
|
|
|
@ -285,6 +285,7 @@ typedef struct {
|
|||
const char *m_bufferPtr;
|
||||
/* past last character to be parsed */
|
||||
char *m_bufferEnd;
|
||||
|
||||
/* allocated end of buffer */
|
||||
const char *m_bufferLim;
|
||||
long m_parseEndByteIndex;
|
||||
|
@ -345,6 +346,7 @@ typedef struct {
|
|||
int m_attsSize;
|
||||
int m_nSpecifiedAtts;
|
||||
int m_idAttIndex;
|
||||
int m_blocked;
|
||||
ATTRIBUTE *m_atts;
|
||||
POSITION m_position;
|
||||
STRING_POOL m_tempPool;
|
||||
|
@ -357,6 +359,7 @@ typedef struct {
|
|||
enum XML_ParamEntityParsing m_paramEntityParsing;
|
||||
XML_Parser m_parentParser;
|
||||
#endif
|
||||
const XML_Char* m_mismatch;
|
||||
} Parser;
|
||||
|
||||
#define userData (((Parser *)parser)->m_userData)
|
||||
|
@ -426,12 +429,14 @@ typedef struct {
|
|||
#define attsSize (((Parser *)parser)->m_attsSize)
|
||||
#define nSpecifiedAtts (((Parser *)parser)->m_nSpecifiedAtts)
|
||||
#define idAttIndex (((Parser *)parser)->m_idAttIndex)
|
||||
#define blocked (((Parser *)parser)->m_blocked)
|
||||
#define tempPool (((Parser *)parser)->m_tempPool)
|
||||
#define temp2Pool (((Parser *)parser)->m_temp2Pool)
|
||||
#define groupConnector (((Parser *)parser)->m_groupConnector)
|
||||
#define groupSize (((Parser *)parser)->m_groupSize)
|
||||
#define hadExternalDoctype (((Parser *)parser)->m_hadExternalDoctype)
|
||||
#define namespaceSeparator (((Parser *)parser)->m_namespaceSeparator)
|
||||
#define mismatch (((Parser *)parser)->m_mismatch)
|
||||
#ifdef XML_DTD
|
||||
#define parentParser (((Parser *)parser)->m_parentParser)
|
||||
#define paramEntityParsing (((Parser *)parser)->m_paramEntityParsing)
|
||||
|
@ -526,6 +531,7 @@ XML_Parser XML_ParserCreate(const XML_Char *encodingName)
|
|||
dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE;
|
||||
XmlInitEncoding(&initEncoding, &encoding, 0);
|
||||
internalEncoding = XmlGetInternalEncoding();
|
||||
blocked = 0;
|
||||
return parser;
|
||||
}
|
||||
|
||||
|
@ -737,6 +743,22 @@ int XML_GetIdAttributeIndex(XML_Parser parser)
|
|||
return idAttIndex;
|
||||
}
|
||||
|
||||
void XML_BlockParser(XML_Parser parser)
|
||||
{
|
||||
blocked = 1;
|
||||
}
|
||||
|
||||
void XML_UnblockParser(XML_Parser parser)
|
||||
{
|
||||
blocked = 0;
|
||||
}
|
||||
|
||||
const
|
||||
XML_Char* XML_GetMismatchedTag(XML_Parser parser)
|
||||
{
|
||||
return mismatch;
|
||||
}
|
||||
|
||||
void XML_SetElementHandler(XML_Parser parser,
|
||||
XML_StartElementHandler start,
|
||||
XML_EndElementHandler end)
|
||||
|
@ -866,6 +888,11 @@ int XML_SetParamEntityParsing(XML_Parser parser,
|
|||
|
||||
int XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
|
||||
{
|
||||
if (blocked) {
|
||||
// First unblock parser
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
if (!isFinal)
|
||||
return 1;
|
||||
|
@ -893,7 +920,11 @@ int XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
|
|||
errorCode = processor(parser, s, parseEndPtr = s + len, &end);
|
||||
if (errorCode != XML_ERROR_NONE) {
|
||||
eventEndPtr = eventPtr;
|
||||
processor = errorProcessor;
|
||||
if (blocked) {
|
||||
parseEndPtr = eventEndPtr;
|
||||
parseEndByteIndex -= len - (eventPtr - s); // This is how much we've red thus far
|
||||
XmlUpdatePosition(encoding, positionPtr, eventEndPtr, &position);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
XmlUpdatePosition(encoding, positionPtr, end, &position);
|
||||
|
@ -1372,12 +1403,15 @@ doContent(XML_Parser parser,
|
|||
if (nextPtr)
|
||||
tag->rawName = tag->buf;
|
||||
}
|
||||
*toPtr = XML_T('\0');
|
||||
*toPtr = XML_T('\0');
|
||||
result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings));
|
||||
if (result)
|
||||
return result;
|
||||
startElementHandler(handlerArg, tag->name.str, (const XML_Char **)atts);
|
||||
poolClear(&tempPool);
|
||||
if (blocked) {
|
||||
return XML_ERROR_PARSER_BLOCKED;
|
||||
}
|
||||
}
|
||||
else {
|
||||
tag->name.str = 0;
|
||||
|
@ -1408,12 +1442,19 @@ doContent(XML_Parser parser,
|
|||
if (result)
|
||||
return result;
|
||||
poolFinish(&tempPool);
|
||||
if (startElementHandler)
|
||||
if (startElementHandler) {
|
||||
startElementHandler(handlerArg, name.str, (const XML_Char **)atts);
|
||||
if (blocked) {
|
||||
return XML_ERROR_PARSER_BLOCKED;
|
||||
}
|
||||
}
|
||||
if (endElementHandler) {
|
||||
if (startElementHandler)
|
||||
*eventPP = *eventEndPP;
|
||||
endElementHandler(handlerArg, name.str);
|
||||
if (blocked) {
|
||||
return XML_ERROR_PARSER_BLOCKED;
|
||||
}
|
||||
}
|
||||
poolClear(&tempPool);
|
||||
while (bindings) {
|
||||
|
@ -1446,6 +1487,7 @@ doContent(XML_Parser parser,
|
|||
if (len != tag->rawNameLength
|
||||
|| memcmp(tag->rawName, rawName, len) != 0) {
|
||||
*eventPP = rawName;
|
||||
mismatch = tag->name.str;
|
||||
return XML_ERROR_TAG_MISMATCH;
|
||||
}
|
||||
--tagLevel;
|
||||
|
@ -1457,6 +1499,9 @@ doContent(XML_Parser parser,
|
|||
;
|
||||
}
|
||||
endElementHandler(handlerArg, tag->name.str);
|
||||
if (blocked) {
|
||||
return XML_ERROR_PARSER_BLOCKED;
|
||||
}
|
||||
}
|
||||
else if (defaultHandler)
|
||||
reportDefault(parser, enc, s, next);
|
||||
|
@ -2684,8 +2729,13 @@ doProlog(XML_Parser parser,
|
|||
case XML_ROLE_NONE:
|
||||
switch (tok) {
|
||||
case XML_TOK_PI:
|
||||
if (!reportProcessingInstruction(parser, enc, s, next))
|
||||
return XML_ERROR_NO_MEMORY;
|
||||
if (!reportProcessingInstruction(parser, enc, s, next)) {
|
||||
if (blocked) {
|
||||
eventPtr = next;
|
||||
return XML_ERROR_PARSER_BLOCKED;
|
||||
}
|
||||
return XML_ERROR_NO_MEMORY;
|
||||
}
|
||||
break;
|
||||
case XML_TOK_COMMENT:
|
||||
if (!reportComment(parser, enc, s, next))
|
||||
|
@ -3103,6 +3153,9 @@ reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, const char *
|
|||
normalizeLines(data);
|
||||
processingInstructionHandler(handlerArg, target, data);
|
||||
poolClear(&tempPool);
|
||||
if (blocked) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,11 +72,11 @@ XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
|
|||
/* atts is array of name/value pairs, terminated by 0;
|
||||
names and values are 0 terminated. */
|
||||
|
||||
typedef void (*XML_StartElementHandler)(void *userData,
|
||||
typedef int (*XML_StartElementHandler)(void *userData,
|
||||
const XML_Char *name,
|
||||
const XML_Char **atts);
|
||||
|
||||
typedef void (*XML_EndElementHandler)(void *userData,
|
||||
typedef int (*XML_EndElementHandler)(void *userData,
|
||||
const XML_Char *name);
|
||||
|
||||
/* s is not 0 terminated. */
|
||||
|
@ -85,7 +85,7 @@ typedef void (*XML_CharacterDataHandler)(void *userData,
|
|||
int len);
|
||||
|
||||
/* target and data are 0 terminated */
|
||||
typedef void (*XML_ProcessingInstructionHandler)(void *userData,
|
||||
typedef int (*XML_ProcessingInstructionHandler)(void *userData,
|
||||
const XML_Char *target,
|
||||
const XML_Char *data);
|
||||
|
||||
|
@ -401,6 +401,10 @@ attribute/value pair counts as 2; thus this correspondds to an index
|
|||
into the atts array passed to the XML_StartElementHandler. */
|
||||
int XMLPARSEAPI XML_GetIdAttributeIndex(XML_Parser parser);
|
||||
|
||||
void XMLPARSEAPI XML_BlockParser(XML_Parser parser);
|
||||
void XMLPARSEAPI XML_UnblockParser(XML_Parser parser);
|
||||
|
||||
const XML_Char* XMLPARSEAPI XML_GetMismatchedTag(XML_Parser parser);
|
||||
/* Parses some input. Returns 0 if a fatal error is detected.
|
||||
The last call to XML_Parse must have isFinal true;
|
||||
len may be zero for this call (or any other). */
|
||||
|
@ -483,7 +487,8 @@ enum XML_Error {
|
|||
XML_ERROR_INCORRECT_ENCODING,
|
||||
XML_ERROR_UNCLOSED_CDATA_SECTION,
|
||||
XML_ERROR_EXTERNAL_ENTITY_HANDLING,
|
||||
XML_ERROR_NOT_STANDALONE
|
||||
XML_ERROR_NOT_STANDALONE,
|
||||
XML_ERROR_PARSER_BLOCKED
|
||||
};
|
||||
|
||||
/* If XML_Parse or XML_ParseBuffer have returned 0, then XML_GetErrorCode
|
||||
|
|
|
@ -990,13 +990,6 @@
|
|||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsWellFormedDTD.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsDebugRobot.cpp</PATH>
|
||||
|
@ -1090,7 +1083,7 @@
|
|||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsExpatTokenizer.cpp</PATH>
|
||||
<PATH>nsExpatDriver.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
|
@ -1201,11 +1194,6 @@
|
|||
<PATH>nsHTMLTags.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsWellFormedDTD.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsDebugRobot.cpp</PATH>
|
||||
|
@ -1248,7 +1236,7 @@
|
|||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsExpatTokenizer.cpp</PATH>
|
||||
<PATH>nsExpatDriver.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
|
@ -2238,13 +2226,6 @@
|
|||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsWellFormedDTD.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsDebugRobot.cpp</PATH>
|
||||
|
@ -2331,7 +2312,7 @@
|
|||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsExpatTokenizer.cpp</PATH>
|
||||
<PATH>nsExpatDriver.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
|
@ -2437,11 +2418,6 @@
|
|||
<PATH>nsHTMLTags.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsWellFormedDTD.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsDebugRobot.cpp</PATH>
|
||||
|
@ -2479,7 +2455,7 @@
|
|||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsExpatTokenizer.cpp</PATH>
|
||||
<PATH>nsExpatDriver.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
|
@ -2625,7 +2601,7 @@
|
|||
<FILEREF>
|
||||
<TARGETNAME>htmlparserDebug.shlb</TARGETNAME>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsExpatTokenizer.cpp</PATH>
|
||||
<PATH>nsExpatDriver.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
|
@ -2664,12 +2640,6 @@
|
|||
<PATH>nsHTMLEntities.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<TARGETNAME>htmlparserDebug.shlb</TARGETNAME>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsWellFormedDTD.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<TARGETNAME>htmlparserDebug.shlb</TARGETNAME>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
|
|
|
@ -28,10 +28,13 @@ include $(DEPTH)/config/autoconf.mk
|
|||
|
||||
MODULE = htmlparser
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIExpatSink.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsIContentSink.h \
|
||||
nsITokenizer.h \
|
||||
nsIExpatTokenizer.h \
|
||||
nsIHTMLContentSink.h \
|
||||
nsIHTMLFragmentContentSink.h\
|
||||
nsIParserNode.h \
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..
|
||||
|
||||
MODULE = htmlparser
|
||||
|
||||
EXPORTS = \
|
||||
nsITokenizer.h \
|
||||
nsIExpatTokenizer.h \
|
||||
nsIContentSink.h \
|
||||
nsIHTMLContentSink.h \
|
||||
nsIHTMLFragmentContentSink.h\
|
||||
nsIParserNode.h \
|
||||
nsIParser.h \
|
||||
nsIParserFilter.h \
|
||||
nsIDTD.h \
|
||||
nsIElementObserver.h \
|
||||
nsIParserService.h \
|
||||
nsHTMLTagList.h \
|
||||
nsHTMLTags.h \
|
||||
nsHTMLTokens.h \
|
||||
nsParserError.h \
|
||||
nsParserCIID.h \
|
||||
nsToken.h \
|
||||
!ifdef MOZ_DEBUG
|
||||
nsILoggingSink.h \
|
||||
!endif
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -49,10 +49,8 @@
|
|||
* content-sink model building process. There is another one that you may care
|
||||
* about more, which is the IHTMLContentSink interface. (See that file for details).
|
||||
*/
|
||||
|
||||
#include "nsIParserNode.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsParserError.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIParser;
|
||||
|
||||
|
@ -113,79 +111,6 @@ public:
|
|||
*/
|
||||
NS_IMETHOD SetParser(nsIParser* aParser)=0;
|
||||
|
||||
/**
|
||||
* This method is used to open a generic container in the sink.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a close
|
||||
* container tag has been consumed and needs to be closed.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This method is called by the parser when it encounters
|
||||
* a document type declaration.
|
||||
*
|
||||
* XXX Should the parser also part the internal subset?
|
||||
*
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode)=0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser if it hits an unrecoverable
|
||||
* error (in XML, if the document is not well-formed or valid).
|
||||
*
|
||||
* @param aErrorResult the error code
|
||||
*/
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError)=0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser to notify observers of
|
||||
* the tag
|
||||
*
|
||||
* @param aErrorResult the error code
|
||||
*/
|
||||
NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode)=0;
|
||||
|
||||
/**
|
||||
* Flush all pending notifications so that the content model
|
||||
* is in sync with the state of the sink.
|
||||
|
|
|
@ -89,6 +89,7 @@ public:
|
|||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDTD_IID)
|
||||
|
||||
|
||||
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const = 0;
|
||||
|
||||
/**
|
||||
|
@ -113,13 +114,6 @@ public:
|
|||
const nsString& aBuffer,
|
||||
PRInt32 aVersion) = 0;
|
||||
|
||||
/**
|
||||
* Called by the parser just before the parsing process begins
|
||||
* @update gess5/18/98
|
||||
* @param aFilename--string that contains name of file being parsed
|
||||
* (if applicable)
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext,
|
||||
nsIContentSink* aSink=0) = 0;
|
||||
|
||||
|
@ -156,14 +150,12 @@ public:
|
|||
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser) = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 12/20/99
|
||||
*
|
||||
* @update gess 12/20/99
|
||||
* @param ptr-ref to (out) tokenizer
|
||||
* @return nsresult
|
||||
*/
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer) = 0;
|
||||
|
||||
NS_IMETHOD_(nsTokenAllocator *) GetTokenAllocator(void) = 0;
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer) = 0;
|
||||
|
||||
/**
|
||||
* If the parse process gets interrupted midway, this method is
|
||||
|
@ -171,7 +163,7 @@ public:
|
|||
* @update gess5/18/98
|
||||
* @return ignored
|
||||
*/
|
||||
NS_IMETHOD WillResumeParse(void) = 0;
|
||||
NS_IMETHOD WillResumeParse(nsIContentSink* aSink = 0) = 0;
|
||||
|
||||
/**
|
||||
* If the parse process gets interrupted, this method is called by
|
||||
|
@ -179,7 +171,7 @@ public:
|
|||
* @update gess5/18/98
|
||||
* @return ignored
|
||||
*/
|
||||
NS_IMETHOD WillInterruptParse(void) = 0;
|
||||
NS_IMETHOD WillInterruptParse(nsIContentSink* aSink = 0) = 0;
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag of one
|
||||
|
@ -226,16 +218,36 @@ public:
|
|||
*/
|
||||
NS_IMETHOD StringTagToIntTag(const nsAReadableString &aTag,
|
||||
PRInt32* aIntTag) const = 0;
|
||||
|
||||
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const = 0;
|
||||
|
||||
|
||||
NS_IMETHOD ConvertEntityToUnicode(const nsAReadableString& aEntity,
|
||||
PRInt32* aUnicode) const = 0;
|
||||
|
||||
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const = 0;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const = 0;
|
||||
};
|
||||
|
||||
#define NS_DECL_NSIDTD \
|
||||
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const;\
|
||||
NS_IMETHOD CreateNewInstance(nsIDTD** aInstancePtrResult);\
|
||||
NS_IMETHOD_(eAutoDetectResult) CanParse(CParserContext& aParserContext, const nsString& aBuffer, PRInt32 aVersion);\
|
||||
NS_IMETHOD WillBuildModel( const CParserContext& aParserContext,nsIContentSink* aSink=0);\
|
||||
NS_IMETHOD DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParser* aParser,nsIContentSink* aSink=0);\
|
||||
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITokenObserver* anObserver=0,nsIContentSink* aSink=0);\
|
||||
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser);\
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer);\
|
||||
NS_IMETHOD WillResumeParse(nsIContentSink* aSink = 0);\
|
||||
NS_IMETHOD WillInterruptParse(nsIContentSink* aSink = 0);\
|
||||
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent,PRInt32 aChild) const;\
|
||||
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const;\
|
||||
NS_IMETHOD_(nsresult) Terminate(nsIParser* aParser=nsnull);\
|
||||
NS_IMETHOD StringTagToIntTag(const nsAReadableString &aTag, PRInt32* aIntTag) const ;\
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const ;\
|
||||
NS_IMETHOD ConvertEntityToUnicode(const nsAReadableString& aEntity, PRInt32* aUnicode) const ;\
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,PRInt32 aParentID) const;\
|
||||
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,PRInt32 aParentID) const;
|
||||
#endif /* nsIDTD_h___ */
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(1DEEA160-C661-11d5-84CC-0010A4E0C706)]
|
||||
interface nsIExpatSink : nsISupports
|
||||
{
|
||||
void HandleStartElement([const] in wstring aName,
|
||||
[array, size_is (aAttsCount)] in wstring aAtts,
|
||||
[const] in unsigned long aAttsCount,
|
||||
[const] in unsigned long aIndex,
|
||||
[const] in unsigned long aLineNumber);
|
||||
|
||||
void HandleEndElement([const] in wstring aName);
|
||||
|
||||
void HandleComment([const] in wstring aName);
|
||||
|
||||
void HandleCDataSection([const] in wstring aData,
|
||||
[const] in unsigned long aLength);
|
||||
|
||||
void HandleDoctypeDecl([const] in wstring aDoctype);
|
||||
|
||||
void HandleCharacterData([const] in wstring aData,
|
||||
[const] in unsigned long aLength);
|
||||
|
||||
void HandleProcessingInstruction([const] in wstring aTarget,
|
||||
[const] in wstring aData);
|
||||
|
||||
void ReportError([const] in wstring aErrorText,
|
||||
[const] in wstring aSourceText);
|
||||
};
|
|
@ -271,6 +271,71 @@ public:
|
|||
*/
|
||||
NS_IMETHOD DidProcessAToken(void)=0;
|
||||
|
||||
/**
|
||||
* This method is used to open a generic container in the sink.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a close
|
||||
* container tag has been consumed and needs to be closed.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This method is called by the parser when it encounters
|
||||
* a document type declaration.
|
||||
*
|
||||
* XXX Should the parser also part the internal subset?
|
||||
*
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode)=0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser to notify observers of
|
||||
* the tag
|
||||
*
|
||||
* @param aErrorResult the error code
|
||||
*/
|
||||
NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode)=0;
|
||||
|
||||
};
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
|
|
|
@ -70,26 +70,38 @@ public:
|
|||
Notes:
|
||||
***************************************************************/
|
||||
|
||||
|
||||
class nsITokenizer : public nsISupports {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITOKENIZER_IID)
|
||||
|
||||
virtual nsresult WillTokenize(PRBool aIsFinalChunk,nsTokenAllocator* aTokenAllocator)=0;
|
||||
virtual nsresult ConsumeToken(nsScanner& aScanner,PRBool& aFlushTokens)=0;
|
||||
virtual nsresult DidTokenize(PRBool aIsFinalChunk)=0;
|
||||
virtual nsTokenAllocator* GetTokenAllocator(void)=0;
|
||||
|
||||
virtual CToken* PushTokenFront(CToken* aToken)=0;
|
||||
virtual CToken* PushToken(CToken* aToken)=0;
|
||||
virtual CToken* PopToken(void)=0;
|
||||
virtual CToken* PeekToken(void)=0;
|
||||
virtual PRInt32 GetCount(void)=0;
|
||||
virtual CToken* GetTokenAt(PRInt32 anIndex)=0;
|
||||
|
||||
virtual void PrependTokens(nsDeque& aDeque)=0;
|
||||
NS_IMETHOD WillTokenize(PRBool aIsFinalChunk,nsTokenAllocator* aTokenAllocator)=0;
|
||||
NS_IMETHOD ConsumeToken(nsScanner& aScanner,PRBool& aFlushTokens)=0;
|
||||
NS_IMETHOD DidTokenize(PRBool aIsFinalChunk)=0;
|
||||
|
||||
NS_IMETHOD_(CToken*) PushTokenFront(CToken* aToken)=0;
|
||||
NS_IMETHOD_(CToken*) PushToken(CToken* aToken)=0;
|
||||
NS_IMETHOD_(CToken*) PopToken(void)=0;
|
||||
NS_IMETHOD_(CToken*) PeekToken(void)=0;
|
||||
NS_IMETHOD_(CToken*) GetTokenAt(PRInt32 anIndex)=0;
|
||||
NS_IMETHOD_(PRInt32) GetCount(void)=0;
|
||||
NS_IMETHOD_(nsTokenAllocator*) GetTokenAllocator(void)=0;
|
||||
NS_IMETHOD_(void) PrependTokens(nsDeque& aDeque)=0;
|
||||
|
||||
};
|
||||
|
||||
#define NS_DECL_NSITOKENIZER \
|
||||
NS_IMETHOD WillTokenize(PRBool aIsFinalChunk,nsTokenAllocator* aTokenAllocator);\
|
||||
NS_IMETHOD ConsumeToken(nsScanner& aScanner,PRBool& aFlushTokens);\
|
||||
NS_IMETHOD DidTokenize(PRBool aIsFinalChunk);\
|
||||
NS_IMETHOD_(CToken*) PushTokenFront(CToken* aToken);\
|
||||
NS_IMETHOD_(CToken*) PushToken(CToken* aToken);\
|
||||
NS_IMETHOD_(CToken*) PopToken(void);\
|
||||
NS_IMETHOD_(CToken*) PeekToken(void);\
|
||||
NS_IMETHOD_(CToken*) GetTokenAt(PRInt32 anIndex);\
|
||||
NS_IMETHOD_(PRInt32) GetCount(void);\
|
||||
NS_IMETHOD_(nsTokenAllocator*) GetTokenAllocator(void);\
|
||||
NS_IMETHOD_(void) PrependTokens(nsDeque& aDeque);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -53,10 +53,6 @@
|
|||
{0x9039c670, 0x2717, 0x11d2, \
|
||||
{0x92, 0x46, 0x00, 0x80, 0x5f, 0x8a, 0x7a, 0xb6}}
|
||||
|
||||
// {E6FD9941-899D-11d2-8EAE-00805F29F370}
|
||||
#define NS_WELLFORMEDDTD_CID \
|
||||
{ 0xe6fd9941, 0x899d, 0x11d2, { 0x8e, 0xae, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
// {a6cf9107-15b3-11d2-932e-00805f8add32}
|
||||
#define NS_CNAVDTD_CID \
|
||||
{ 0xa6cf9107, 0x15b3, 0x11d2, { 0x93, 0x2e, 0x0, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
|
||||
|
@ -81,7 +77,9 @@
|
|||
#define NS_VIEWSOURCE_DTD_CID \
|
||||
{ 0x8323fad0, 0x2102, 0x11d4, { 0x81, 0x42, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
|
||||
|
||||
// {FFF4FBE9-528A-4b37-819D-FC18F3A401A7}
|
||||
#define NS_EXPAT_DRIVER_CID \
|
||||
{ 0xfff4fbe9, 0x528a, 0x4b37, { 0x81, 0x9d, 0xfc, 0x18, 0xf3, 0xa4, 0x1, 0xa7 } }
|
||||
|
||||
// {a6cf910f-15b3-11d2-932e-00805f8add32}
|
||||
#define NS_HTMLCONTENTSINKSTREAM_CID \
|
||||
|
|
|
@ -92,7 +92,6 @@ public:
|
|||
NS_IMETHOD GetPref(PRInt32 aTag,PRBool& aPref) { return NS_OK; }
|
||||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError);
|
||||
NS_IMETHOD CloseTopmostContainer();
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
||||
|
@ -291,11 +290,6 @@ NS_IMETHODIMP RobotSink::AddLeaf(const nsIParserNode& aNode)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP RobotSink::NotifyError(const nsParserError* aError)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets called by the parsing system when we find a comment
|
||||
* @update gess11/9/98
|
||||
|
|
|
@ -674,6 +674,12 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse
|
|||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
CNavDTD::Terminate(nsIParser* aParser)
|
||||
{
|
||||
return mDTDState=NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
}
|
||||
|
||||
/**
|
||||
* --- Backwards compatibility ---
|
||||
* Use this method to determine if the tag in question needs a BODY.
|
||||
|
@ -3921,7 +3927,8 @@ nsresult CNavDTD::CreateContextStackFor(eHTMLTags aChildTag){
|
|||
* @param none
|
||||
* @return ptr to tokenizer
|
||||
*/
|
||||
nsresult CNavDTD::GetTokenizer(nsITokenizer*& aTokenizer) {
|
||||
NS_IMETHODIMP
|
||||
CNavDTD::GetTokenizer(nsITokenizer*& aTokenizer) {
|
||||
nsresult result=NS_OK;
|
||||
if(!mTokenizer) {
|
||||
result=NS_NewHTMLTokenizer(&mTokenizer,mDTDMode,mDocType,mParserCommand);
|
||||
|
@ -3930,37 +3937,18 @@ nsresult CNavDTD::GetTokenizer(nsITokenizer*& aTokenizer) {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess8/4/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHODIMP_(nsTokenAllocator *)
|
||||
CNavDTD::GetTokenAllocator(void)
|
||||
{
|
||||
if(!mTokenAllocator) {
|
||||
nsresult result=GetTokenizer(mTokenizer);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
mTokenAllocator=mTokenizer->GetTokenAllocator();
|
||||
}
|
||||
}
|
||||
return mTokenAllocator;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult CNavDTD::WillResumeParse(void){
|
||||
nsresult CNavDTD::WillResumeParse(nsIContentSink* aSink){
|
||||
|
||||
STOP_TIMER();
|
||||
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillResumeParse(), this=%p\n", this));
|
||||
|
||||
nsresult result=(mSink) ? mSink->WillResume() : NS_OK;
|
||||
nsresult result=(aSink) ? aSink->WillResume() : NS_OK;
|
||||
|
||||
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::WillResumeParse(), this=%p\n", this));
|
||||
START_TIMER();
|
||||
|
@ -3974,12 +3962,12 @@ nsresult CNavDTD::WillResumeParse(void){
|
|||
* @update gess5/18/98
|
||||
* @return error code
|
||||
*/
|
||||
nsresult CNavDTD::WillInterruptParse(void){
|
||||
nsresult CNavDTD::WillInterruptParse(nsIContentSink* aSink){
|
||||
|
||||
STOP_TIMER();
|
||||
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillInterruptParse(), this=%p\n", this));
|
||||
|
||||
nsresult result=(mSink) ? mSink->WillInterrupt() : NS_OK;
|
||||
nsresult result=(aSink) ? aSink->WillInterrupt() : NS_OK;
|
||||
|
||||
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::WillInterruptParse(), this=%p\n", this));
|
||||
START_TIMER();
|
||||
|
|
|
@ -126,7 +126,8 @@ class CNavDTD : public nsIDTD
|
|||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIDTD
|
||||
|
||||
/**
|
||||
* Common constructor for navdtd. You probably want to call
|
||||
* NS_NewNavHTMLDTD().
|
||||
|
@ -134,115 +135,8 @@ public:
|
|||
* @update gess 7/9/98
|
||||
*/
|
||||
CNavDTD();
|
||||
|
||||
/**
|
||||
* Virtual destructor -- you know what to do
|
||||
* @update gess 7/9/98
|
||||
*/
|
||||
virtual ~CNavDTD();
|
||||
|
||||
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const;
|
||||
|
||||
/**
|
||||
* Call this method if you want the DTD to construct a clone of itself.
|
||||
* @update gess7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD CreateNewInstance(nsIDTD** aInstancePtrResult);
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can parse
|
||||
* a document of a given source-type.
|
||||
* Note that parsing assumes that the end result will always be stored
|
||||
* in the main content model. Of course, it's up to you which content-
|
||||
* model you pass in to the parser, so you can always control the process.
|
||||
*
|
||||
* @update gess 7/15/98
|
||||
* @param aContentType contains the name of a filetype that you are
|
||||
* being asked to parse).
|
||||
* @return TRUE if this DTD parse the given type; FALSE otherwise.
|
||||
*/
|
||||
NS_IMETHOD_(eAutoDetectResult) CanParse(CParserContext& aParserContext,
|
||||
const nsString& aBuffer,
|
||||
PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update rickg 03.20.2000
|
||||
* @param aParserContext
|
||||
* @param aSink
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext,
|
||||
nsIContentSink* aSink);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param aFilename is the name of the file being parsed.
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer,
|
||||
nsITokenObserver* anObserver = nsnull,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param anErrorCode contans the last error that occured
|
||||
* @return error code
|
||||
*/
|
||||
NS_IMETHOD DidBuildModel(nsresult anErrorCode, PRBool aNotifySink,
|
||||
nsIParser* aParser,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
* This method is called by the parser, once for each token
|
||||
* that has been constructed during the tokenization phase.
|
||||
* @update gess 3/25/98
|
||||
* @param aToken -- token object to be put into content model
|
||||
* @return 0 if all is well; non-zero is an error
|
||||
*/
|
||||
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/28/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/28/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD_(nsTokenAllocator *) GetTokenAllocator(void);
|
||||
|
||||
/**
|
||||
* If the parse process gets interrupted, this method gets called
|
||||
* prior to the process resuming.
|
||||
* @update gess5/18/98
|
||||
* @return error code -- usually NS_OK (0)
|
||||
*/
|
||||
NS_IMETHOD WillResumeParse(void);
|
||||
|
||||
/**
|
||||
* If the parse process is about to be interrupted, this method
|
||||
* will be called just prior.
|
||||
* @update gess5/18/98
|
||||
* @return error code -- usually NS_OK (0)
|
||||
*/
|
||||
NS_IMETHOD WillInterruptParse(void);
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
|
@ -253,19 +147,9 @@ public:
|
|||
* @param aChild -- int tag of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent,PRInt32 aChild) const;
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- int tag of parent container
|
||||
* @param aChild -- int tag of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) CanPropagate(eHTMLTags aParent, eHTMLTags aChild,
|
||||
PRBool aParentContains) ;
|
||||
virtual PRBool CanPropagate(eHTMLTags aParent,
|
||||
eHTMLTags aChild,
|
||||
PRBool aParentContains) ;
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
|
@ -277,18 +161,9 @@ public:
|
|||
* @param aParentContains -- can be 0,1,-1 (false,true, unknown)
|
||||
* @return PR_TRUE if given tag can be omitted
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) CanOmit(eHTMLTags aParent, eHTMLTags aChild,
|
||||
PRBool& aParentContains);
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag is itself a container
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aTag -- tag to test for containership
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const;
|
||||
virtual PRBool CanOmit(eHTMLTags aParent,
|
||||
eHTMLTags aChild,
|
||||
PRBool& aParentContains);
|
||||
|
||||
/**
|
||||
* This method tries to design a context map (without actually
|
||||
|
@ -300,9 +175,9 @@ public:
|
|||
* @param aChild -- tag type of child
|
||||
* @return True if closure was achieved -- other false
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) ForwardPropagate(nsString& aSequence,
|
||||
eHTMLTags aParentTag,
|
||||
eHTMLTags aChildTag);
|
||||
virtual PRBool ForwardPropagate(nsString& aSequence,
|
||||
eHTMLTags aParentTag,
|
||||
eHTMLTags aChildTag);
|
||||
|
||||
/**
|
||||
* This method tries to design a context map (without actually
|
||||
|
@ -313,9 +188,9 @@ public:
|
|||
* @param aChild -- tag type of child
|
||||
* @return True if closure was achieved -- other false
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) BackwardPropagate(nsString& aSequence,
|
||||
eHTMLTags aParentTag,
|
||||
eHTMLTags aChildTag) const;
|
||||
virtual PRBool BackwardPropagate(nsString& aSequence,
|
||||
eHTMLTags aParentTag,
|
||||
eHTMLTags aChildTag) const;
|
||||
|
||||
/**
|
||||
* Attempt forward and/or backward propagation for the given
|
||||
|
@ -367,40 +242,6 @@ public:
|
|||
*/
|
||||
virtual PRInt32 LastOf(eHTMLTags aTagSet[],PRInt32 aCount) const;
|
||||
|
||||
/**
|
||||
* Use this id you want to stop the building content model
|
||||
* --------------[ Sets DTD to STOP mode ]----------------
|
||||
* It's recommended to use this method in accordance with
|
||||
* the parser's terminate() method.
|
||||
*
|
||||
* @update harishd 07/22/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD Terminate(nsIParser* aParser = nsnull)
|
||||
{
|
||||
mDTDState = NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
|
||||
return mDTDState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give rest of world access to our tag enums, so that CanContain(), etc,
|
||||
* become useful.
|
||||
*/
|
||||
NS_IMETHOD StringTagToIntTag(const nsAReadableString &aTag,
|
||||
PRInt32* aIntTag) const;
|
||||
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const;
|
||||
|
||||
NS_IMETHOD ConvertEntityToUnicode(const nsAReadableString& aEntity,
|
||||
PRInt32* aUnicode) const;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const;
|
||||
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const;
|
||||
|
||||
/**
|
||||
* The following set of methods are used to partially construct
|
||||
* the content model (via the sink) according to the type of token.
|
||||
|
@ -489,7 +330,6 @@ public:
|
|||
|
||||
nsresult DoFragment(PRBool aFlag);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
nsresult CollectAttributes(nsIParserNode& aNode,eHTMLTags aTag,PRInt32 aCount);
|
||||
|
@ -502,27 +342,32 @@ protected:
|
|||
|
||||
nsDeque mMisplacedContent;
|
||||
nsDeque mSkippedContent;
|
||||
|
||||
nsIHTMLContentSink* mSink;
|
||||
nsTokenAllocator* mTokenAllocator;
|
||||
nsDTDContext* mBodyContext;
|
||||
nsDTDContext* mTempContext;
|
||||
PRInt32 mOpenHeadCount;
|
||||
PRInt32 mOpenMapCount;
|
||||
PRInt32 mOpenFormCount;
|
||||
nsParser* mParser;
|
||||
nsITokenizer* mTokenizer;
|
||||
|
||||
nsString mFilename;
|
||||
nsString mScratch; //used for various purposes; non-persistent
|
||||
nsAutoString mMimeType; //ok as an autostring; these are short.
|
||||
|
||||
nsNodeAllocator mNodeAllocator;
|
||||
nsDTDMode mDTDMode;
|
||||
eParserDocType mDocType;
|
||||
eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors...
|
||||
|
||||
eHTMLTags mSkipTarget;
|
||||
nsresult mDTDState;
|
||||
PRUint16 mFlags;
|
||||
PRInt32 mLineNumber;
|
||||
nsString mScratch; //used for various purposes; non-persistent
|
||||
nsAutoString mMimeType; //ok as an autostring; these are short.
|
||||
nsNodeAllocator mNodeAllocator;
|
||||
nsString mFilename;
|
||||
|
||||
PRInt32 mOpenHeadCount;
|
||||
PRInt32 mOpenMapCount;
|
||||
PRInt32 mOpenFormCount;
|
||||
|
||||
PRUint16 mFlags;
|
||||
|
||||
#ifdef ENABLE_CRC
|
||||
PRUint32 mComputedCRC32;
|
||||
PRUint32 mExpectedCRC32;
|
||||
|
@ -533,7 +378,7 @@ inline nsresult NS_NewNavHTMLDTD(nsIDTD** aInstancePtrResult)
|
|||
{
|
||||
NS_DEFINE_CID(kNavDTDCID, NS_CNAVDTD_CID);
|
||||
return nsComponentManager::CreateInstance(kNavDTDCID,
|
||||
nsnull,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIDTD),
|
||||
(void**)aInstancePtrResult);
|
||||
}
|
||||
|
|
|
@ -485,6 +485,12 @@ nsresult COtherDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIPar
|
|||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
COtherDTD::Terminate(nsIParser* aParser)
|
||||
{
|
||||
return mDTDState=NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
}
|
||||
|
||||
/**
|
||||
* This big dispatch method is used to route token handler calls to the right place.
|
||||
* What's wrong with it? This table, and the dispatch methods themselves need to be
|
||||
|
@ -995,12 +1001,12 @@ nsresult COtherDTD::GetTokenizer(nsITokenizer*& aTokenizer) {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult COtherDTD::WillResumeParse(void) {
|
||||
nsresult COtherDTD::WillResumeParse(nsIContentSink* aSink) {
|
||||
|
||||
STOP_TIMER();
|
||||
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: COtherDTD::WillResumeParse(), this=%p\n", this));
|
||||
|
||||
nsresult result=(mSink) ? mSink->WillResume() : NS_OK;
|
||||
nsresult result=(aSink) ? aSink->WillResume() : NS_OK;
|
||||
|
||||
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: COtherDTD::WillResumeParse(), this=%p\n", this));
|
||||
START_TIMER();
|
||||
|
@ -1014,12 +1020,12 @@ nsresult COtherDTD::WillResumeParse(void) {
|
|||
* @update gess5/18/98
|
||||
* @return error code
|
||||
*/
|
||||
nsresult COtherDTD::WillInterruptParse(void){
|
||||
nsresult COtherDTD::WillInterruptParse(nsIContentSink* aSink){
|
||||
|
||||
STOP_TIMER();
|
||||
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: COtherDTD::WillInterruptParse(), this=%p\n", this));
|
||||
|
||||
nsresult result=(mSink) ? mSink->WillInterrupt() : NS_OK;
|
||||
nsresult result=(aSink) ? aSink->WillInterrupt() : NS_OK;
|
||||
|
||||
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: COtherDTD::WillInterruptParse(), this=%p\n", this));
|
||||
START_TIMER();
|
||||
|
|
|
@ -122,7 +122,10 @@ class COtherDTD : public nsIDTD
|
|||
#pragma warning( default : 4275 )
|
||||
#endif
|
||||
|
||||
public:
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDTD
|
||||
|
||||
/**
|
||||
* Common constructor for navdtd. You probably want to call
|
||||
* NS_NewNavHTMLDTD().
|
||||
|
@ -137,171 +140,6 @@ public:
|
|||
*/
|
||||
virtual ~COtherDTD();
|
||||
|
||||
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const;
|
||||
|
||||
/**
|
||||
* Call this method if you want the DTD to construct a clone of itself.
|
||||
* @update gess7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD CreateNewInstance(nsIDTD** aInstancePtrResult);
|
||||
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can parse
|
||||
* a document of a given source-type.
|
||||
* Note that parsing assumes that the end result will always be stored
|
||||
* in the main content model. Of course, it's up to you which content-
|
||||
* model you pass in to the parser, so you can always control the process.
|
||||
*
|
||||
* @update gess 7/15/98
|
||||
* @param aContentType contains the name of a filetype that you are
|
||||
* being asked to parse).
|
||||
* @return TRUE if this DTD parse the given type; FALSE otherwise.
|
||||
*/
|
||||
NS_IMETHOD_(eAutoDetectResult) CanParse(CParserContext& aParserContext,
|
||||
const nsString& aBuffer,
|
||||
PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update rickg 03.20.2000
|
||||
* @param aParserContext
|
||||
* @param aSink
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext,
|
||||
nsIContentSink* aSink);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param aFilename is the name of the file being parsed.
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer,
|
||||
nsITokenObserver* anObserver = nsnull,
|
||||
nsIContentSink* aSink=nsnull);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param anErrorCode contans the last error that occured
|
||||
* @return error code
|
||||
*/
|
||||
NS_IMETHOD DidBuildModel(nsresult anErrorCode, PRBool aNotifySink,
|
||||
nsIParser* aParser,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
* This method is called by the parser, once for each token
|
||||
* that has been constructed during the tokenization phase.
|
||||
* @update gess 3/25/98
|
||||
* @param aToken -- token object to be put into content model
|
||||
* @return 0 if all is well; non-zero is an error
|
||||
*/
|
||||
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/28/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer);
|
||||
|
||||
/**
|
||||
* Note that the otherDTD get's it's recycler from
|
||||
* the body context.
|
||||
*
|
||||
* @update rickg 16June2000
|
||||
* @return always 0
|
||||
*/
|
||||
NS_IMETHOD_(nsTokenAllocator *) GetTokenAllocator(void)
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the parse process gets interrupted, this method gets called
|
||||
* prior to the process resuming.
|
||||
* @update gess5/18/98
|
||||
* @return error code -- usually NS_OK (0)
|
||||
*/
|
||||
NS_IMETHOD WillResumeParse(void);
|
||||
|
||||
/**
|
||||
* If the parse process is about to be interrupted, this method
|
||||
* will be called just prior.
|
||||
* @update gess5/18/98
|
||||
* @return error code -- usually NS_OK (0)
|
||||
*/
|
||||
NS_IMETHOD WillInterruptParse(void);
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- int tag of parent container
|
||||
* @param aChild -- int tag of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent,PRInt32 aChild) const;
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag is itself a container
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aTag -- tag to test for containership
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const;
|
||||
|
||||
/**
|
||||
* Use this id you want to stop the building content model
|
||||
* --------------[ Sets DTD to STOP mode ]----------------
|
||||
* It's recommended to use this method in accordance with
|
||||
* the parser's terminate() method.
|
||||
*
|
||||
* @update harishd 07/22/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD Terminate(nsIParser* aParser = nsnull)
|
||||
{
|
||||
mDTDState=NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
|
||||
return mDTDState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give rest of world access to our tag enums, so that CanContain(), etc,
|
||||
* become useful.
|
||||
*/
|
||||
NS_IMETHOD StringTagToIntTag(const nsAReadableString &aTag,
|
||||
PRInt32* aIntTag) const;
|
||||
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const;
|
||||
|
||||
NS_IMETHOD ConvertEntityToUnicode(const nsAReadableString& aEntity,
|
||||
PRInt32* aUnicode) const;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const;
|
||||
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const;
|
||||
|
||||
/**
|
||||
* The following set of methods are used to partially construct
|
||||
* the content model (via the sink) according to the type of token.
|
||||
|
|
|
@ -84,11 +84,11 @@ public:
|
|||
nsIDTD* mDTD;
|
||||
nsIDTD* mValidator;
|
||||
nsIRequestObserver* mListener;
|
||||
|
||||
char* mTransferBuffer;
|
||||
void* mKey;
|
||||
CParserContext* mPrevContext;
|
||||
nsScanner* mScanner;
|
||||
|
||||
nsAutoString mMimeType;
|
||||
nsDTDMode mDTDMode;
|
||||
|
||||
|
|
|
@ -58,8 +58,8 @@ endif
|
|||
CPPSRCS = \
|
||||
nsDTDUtils.cpp \
|
||||
nsHTMLTokenizer.cpp \
|
||||
nsExpatTokenizer.cpp\
|
||||
nsElementTable.cpp \
|
||||
nsExpatDriver.cpp \
|
||||
CNavDTD.cpp \
|
||||
COtherDTD.cpp \
|
||||
nsHTMLEntities.cpp \
|
||||
|
@ -72,7 +72,6 @@ CPPSRCS = \
|
|||
nsParserNode.cpp \
|
||||
nsScanner.cpp \
|
||||
nsToken.cpp \
|
||||
nsWellFormedDTD.cpp \
|
||||
nsViewSourceHTML.cpp\
|
||||
nsParserMsgUtils.cpp\
|
||||
$(NULL)
|
||||
|
|
|
@ -40,13 +40,13 @@ include <$(DEPTH)\config\config.mak>
|
|||
LIBRARY_NAME=raptorhtmlpars
|
||||
DEFINES=-D_IMPL_NS_HTMLPARS -DWIN32_LEAN_AND_MEAN -DXML_DTD
|
||||
|
||||
LIBRARY_NAME = gkparser
|
||||
MODULE_NAME = nsParserModule
|
||||
LIBRARY_NAME = gkparser
|
||||
MODULE_NAME = nsParserModule
|
||||
|
||||
CPP_OBJS = \
|
||||
CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsDTDUtils.obj \
|
||||
.\$(OBJDIR)\nsHTMLTokenizer.obj \
|
||||
.\$(OBJDIR)\nsExpatTokenizer.obj\
|
||||
.\$(OBJDIR)\nsExpatDriver.obj \
|
||||
.\$(OBJDIR)\nsElementTable.obj \
|
||||
.\$(OBJDIR)\CNavDTD.obj \
|
||||
.\$(OBJDIR)\COtherDTD.obj \
|
||||
|
@ -58,11 +58,10 @@ CPP_OBJS = \
|
|||
.\$(OBJDIR)\nsParserNode.obj \
|
||||
.\$(OBJDIR)\nsScanner.obj \
|
||||
.\$(OBJDIR)\nsToken.obj \
|
||||
.\$(OBJDIR)\nsWellFormedDTD.obj \
|
||||
.\$(OBJDIR)\nsViewSourceHTML.obj\
|
||||
.\$(OBJDIR)\nsParserService.obj \
|
||||
.\$(OBJDIR)\nsParserService.obj \
|
||||
.\$(OBJDIR)\nsParserModule.obj \
|
||||
.\$(OBJDIR)\nsParserMsgUtils.obj \
|
||||
.\$(OBJDIR)\nsParserMsgUtils.obj\
|
||||
!ifdef MOZ_DEBUG
|
||||
.\$(OBJDIR)\nsLoggingSink.obj \
|
||||
.\$(OBJDIR)\nsHTMLNullSink.obj \
|
||||
|
|
|
@ -0,0 +1,947 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsExpatDriver.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "CParserContext.h"
|
||||
#include "nsIExpatSink.h"
|
||||
#include "nsIContentSink.h"
|
||||
#include "nsParserMsgUtils.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIUnicharInputStream.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "prprf.h"
|
||||
#include "prmem.h"
|
||||
#include "nsTextFormatter.h"
|
||||
|
||||
static const char* kDTDDirectory = "dtd/";
|
||||
|
||||
/***************************** EXPAT CALL BACKS *******************************/
|
||||
|
||||
// The callback handlers that get called from the expat parser
|
||||
static int
|
||||
Driver_HandleStartElement(void *aUserData,
|
||||
const XML_Char *aName,
|
||||
const XML_Char **aAtts)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
return NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleStartElement((const PRUnichar*)aName,
|
||||
(const PRUnichar**)aAtts);
|
||||
}
|
||||
return XML_ERROR_NONE;
|
||||
}
|
||||
|
||||
static int
|
||||
Driver_HandleEndElement(void *aUserData,
|
||||
const XML_Char *aName)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
return NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleEndElement((const PRUnichar*)aName);
|
||||
}
|
||||
return XML_ERROR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleCharacterData(void *aUserData,
|
||||
const XML_Char *aData,
|
||||
int aLength)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleCharacterData((PRUnichar*)aData,
|
||||
PRUint32(aLength));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleComment(void *aUserData,
|
||||
const XML_Char *aName)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if(aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleComment((const PRUnichar*)aName);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
Driver_HandleProcessingInstruction(void *aUserData,
|
||||
const XML_Char *aTarget,
|
||||
const XML_Char *aData)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
return NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleProcessingInstruction((const PRUnichar*)aTarget,
|
||||
(const PRUnichar*)aData);
|
||||
}
|
||||
return XML_ERROR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleDefault(void *aUserData,
|
||||
const XML_Char *aData,
|
||||
int aLength)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleDefault((const PRUnichar*)aData,
|
||||
PRUint32(aLength));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleStartCdataSection(void *aUserData)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleStartCdataSection();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleEndCdataSection(void *aUserData)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleEndCdataSection();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleStartDoctypeDecl(void *aUserData,
|
||||
const XML_Char *aDoctypeName)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleStartDoctypeDecl();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleEndDoctypeDecl(void *aUserData)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleEndDoctypeDecl();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
Driver_HandleExternalEntityRef(XML_Parser parser,
|
||||
const XML_Char *openEntityNames,
|
||||
const XML_Char *base,
|
||||
const XML_Char *systemId,
|
||||
const XML_Char *publicId)
|
||||
{
|
||||
int result = PR_TRUE;
|
||||
|
||||
#ifdef XML_DTD
|
||||
|
||||
// Load the external entity into a buffer
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
nsAutoString absURL;
|
||||
|
||||
nsresult rv = nsExpatDriver::OpenInputStream(systemId, base, getter_AddRefs(in), absURL);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIUnicharInputStream> uniIn;
|
||||
|
||||
NS_NewUTF8ConverterStream(getter_AddRefs(uniIn), in, 1024);
|
||||
|
||||
if (uniIn) {
|
||||
XML_Parser entParser =
|
||||
XML_ExternalEntityParserCreate(parser, 0, (const XML_Char*) NS_LITERAL_STRING("UTF-16").get());
|
||||
|
||||
if (entParser) {
|
||||
PRUint32 readCount = 0;
|
||||
PRUnichar tmpBuff[1024] = {0};
|
||||
PRUnichar *uniBuf = tmpBuff;
|
||||
|
||||
XML_SetBase(entParser, (const XML_Char*) absURL.get());
|
||||
|
||||
while (NS_SUCCEEDED(uniIn->Read(uniBuf, 0, 1024, &readCount))) {
|
||||
if (readCount) {
|
||||
// Pass the buffer to expat for parsing
|
||||
result = XML_Parse(entParser, (char *)uniBuf, readCount * sizeof(PRUnichar), 0);
|
||||
}
|
||||
else {
|
||||
// done reading
|
||||
result = XML_Parse(entParser, nsnull, 0, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
XML_ParserFree(entParser);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* ! XML_DTD */
|
||||
NS_NOTYETIMPLEMENTED("Error: Tokenizer_HandleExternalEntityRef() not yet implemented.");
|
||||
#endif /* XML_DTD */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/***************************** END CALL BACKS *********************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsExpatDriver,
|
||||
nsITokenizer,
|
||||
nsIDTD);
|
||||
|
||||
nsresult
|
||||
NS_NewExpatDriver(nsIDTD** aResult) {
|
||||
nsExpatDriver* driver = nsnull;
|
||||
NS_NEWXPCOM(driver, nsExpatDriver);
|
||||
NS_ENSURE_TRUE(driver,NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
return driver->QueryInterface(NS_GET_IID(nsIDTD), (void**)aResult);
|
||||
}
|
||||
|
||||
nsExpatDriver::nsExpatDriver()
|
||||
:mExpatParser(0),
|
||||
mSink(0),
|
||||
mInDoctype(0),
|
||||
mInCData(0),
|
||||
mBytesParsed(0),
|
||||
mBytePosition(0),
|
||||
mInternalState(NS_OK)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsExpatDriver::~nsExpatDriver()
|
||||
{
|
||||
NS_IF_RELEASE(mSink);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleStartElement(const PRUnichar *aValue,
|
||||
const PRUnichar **aAtts)
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
if (mSink){
|
||||
nsresult result = mSink->HandleStartElement(aValue, aAtts,
|
||||
XML_GetSpecifiedAttributeCount(mExpatParser) / 2,
|
||||
XML_GetIdAttributeIndex(mExpatParser),
|
||||
XML_GetCurrentLineNumber(mExpatParser));
|
||||
|
||||
if (result == NS_ERROR_HTMLPARSER_BLOCK) {
|
||||
mInternalState = NS_ERROR_HTMLPARSER_BLOCK;
|
||||
XML_BlockParser(mExpatParser);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleEndElement(const PRUnichar *aValue)
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
if (mSink){
|
||||
nsresult result = mSink->HandleEndElement(aValue);
|
||||
if (result == NS_ERROR_HTMLPARSER_BLOCK) {
|
||||
mInternalState = NS_ERROR_HTMLPARSER_BLOCK;
|
||||
XML_BlockParser(mExpatParser);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleCharacterData(const PRUnichar *aValue,
|
||||
const PRUint32 aLength)
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
if (mInCData) {
|
||||
mCDataText.Append(aValue,aLength);
|
||||
}
|
||||
else if (mSink){
|
||||
mInternalState = mSink->HandleCharacterData(aValue, aLength);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleComment(const PRUnichar *aValue)
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
if (mInDoctype) {
|
||||
// We do not want comments popping out of the doctype...
|
||||
mDoctypeText.Append(NS_LITERAL_STRING("<!--"));
|
||||
mDoctypeText.Append(aValue);
|
||||
mDoctypeText.Append(NS_LITERAL_STRING("-->"));
|
||||
}
|
||||
else if (mSink){
|
||||
mInternalState = mSink->HandleComment(aValue);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleProcessingInstruction(const PRUnichar *aTarget,
|
||||
const PRUnichar *aData)
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
if (mSink){
|
||||
nsresult result = mSink->HandleProcessingInstruction(aTarget, aData);
|
||||
if (result == NS_ERROR_HTMLPARSER_BLOCK) {
|
||||
mInternalState = NS_ERROR_HTMLPARSER_BLOCK;
|
||||
XML_BlockParser(mExpatParser);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleDefault(const PRUnichar *aValue,
|
||||
const PRUint32 aLength)
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
if (mInDoctype) {
|
||||
mDoctypeText.Append(aValue, aLength);
|
||||
}
|
||||
else if (mSink) {
|
||||
static const PRUnichar newline[] = {'\n','\0'};
|
||||
for (PRUint32 i = 0; i < aLength && NS_SUCCEEDED(mInternalState); i++) {
|
||||
if (aValue[i] == '\n' || aValue[i] == '\r') {
|
||||
mInternalState = mSink->HandleCharacterData(newline, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleStartCdataSection()
|
||||
{
|
||||
mInCData = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleEndCdataSection()
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
mInCData = PR_FALSE;
|
||||
if (mSink) {
|
||||
mInternalState = mSink->HandleCDataSection(mCDataText.get(),mCDataText.Length());
|
||||
}
|
||||
mCDataText.Truncate();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleStartDoctypeDecl()
|
||||
{
|
||||
mInDoctype = PR_TRUE;
|
||||
mDoctypeText.Assign(NS_LITERAL_STRING("<!DOCTYPE "));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleEndDoctypeDecl()
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
mInDoctype = PR_FALSE;
|
||||
mDoctypeText.Append(PRUnichar('>'));
|
||||
|
||||
if(mSink) {
|
||||
mInternalState = mSink->HandleDoctypeDecl(mDoctypeText.get());
|
||||
}
|
||||
|
||||
mDoctypeText.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// aDTD is an in/out parameter. Returns true if the aDTD is a chrome url or if the
|
||||
// filename contained within the url exists in the special DTD directory ("dtd"
|
||||
// relative to the current process directory). For the latter case, aDTD is set
|
||||
// to the file: url that points to the DTD file found in the local DTD directory
|
||||
// AND the old URI is relased.
|
||||
static PRBool
|
||||
IsLoadableDTD(nsCOMPtr<nsIURI>* aDTD)
|
||||
{
|
||||
PRBool isLoadable = PR_FALSE;
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (!aDTD || !*aDTD) {
|
||||
NS_ASSERTION(0, "Null parameter.");
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// Return true if the url is a chrome url
|
||||
res = (*aDTD)->SchemeIs("chrome", &isLoadable);
|
||||
|
||||
// If the url is not a chrome url, check to see if a DTD file of the same name
|
||||
// exists in the special DTD directory
|
||||
if (!isLoadable) {
|
||||
nsCOMPtr<nsIURL> dtdURL;
|
||||
dtdURL = do_QueryInterface(*aDTD, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsXPIDLCString fileName;
|
||||
res = dtdURL->GetFileName(getter_Copies(fileName));
|
||||
if (NS_SUCCEEDED(res) && fileName) {
|
||||
nsSpecialSystemDirectory dtdPath(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
||||
dtdPath += NS_ConvertASCIItoUCS2(nsDependentCString(kDTDDirectory) + fileName);
|
||||
if (dtdPath.Exists()) {
|
||||
// The DTD was found in the local DTD directory.
|
||||
// Set aDTD to a file: url pointing to the local DTD
|
||||
nsFileURL dtdFile(dtdPath);
|
||||
nsCOMPtr<nsIURI> dtdURI;
|
||||
res = NS_NewURI(getter_AddRefs(dtdURI), dtdFile.GetURLString());
|
||||
if (NS_SUCCEEDED(res) && dtdURI) {
|
||||
*aDTD = dtdURI;
|
||||
isLoadable = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isLoadable;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::OpenInputStream(const XML_Char* aURLStr,
|
||||
const XML_Char* aBaseURL,
|
||||
nsIInputStream** in,
|
||||
nsAString& aAbsURL)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> baseURI;
|
||||
rv = NS_NewURI(getter_AddRefs(baseURI), NS_ConvertUCS2toUTF8((const PRUnichar*)aBaseURL).get());
|
||||
if (NS_SUCCEEDED(rv) && baseURI) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), NS_ConvertUCS2toUTF8((const PRUnichar*)aURLStr).get(), baseURI);
|
||||
if (NS_SUCCEEDED(rv) && uri) {
|
||||
if (IsLoadableDTD(address_of(uri))) {
|
||||
rv = NS_OpenURI(in, uri);
|
||||
nsXPIDLCString absURL;
|
||||
uri->GetSpec(getter_Copies(absURL));
|
||||
CopyASCIItoUCS2(absURL, aAbsURL);
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
CreateErrorText(const PRUnichar* aDescription,
|
||||
const PRUnichar* aSourceURL,
|
||||
const PRInt32 aLineNumber,
|
||||
const PRInt32 aColNumber,
|
||||
nsString& aErrorString)
|
||||
{
|
||||
aErrorString.Truncate();
|
||||
|
||||
nsAutoString msg;
|
||||
nsresult rv = nsParserMsgUtils::GetLocalizedStringByName(XMLPARSER_PROPERTIES,"XMLParsingError",msg);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// XML Parsing Error: %1$S\nLocation: %2$S\nLine Number %3$d, Column %4$d:
|
||||
PRUnichar *message = nsTextFormatter::smprintf(msg.get(),aDescription,aSourceURL,aLineNumber,aColNumber);
|
||||
if (!message) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
aErrorString.Assign(message);
|
||||
nsTextFormatter::smprintf_free(message);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
CreateSourceText(const PRInt32 aColNumber,
|
||||
const PRUnichar* aSourceLine,
|
||||
nsString& aSourceString)
|
||||
{
|
||||
PRInt32 errorPosition = aColNumber;
|
||||
|
||||
aSourceString.Append(aSourceLine);
|
||||
aSourceString.Append(PRUnichar('\n'));
|
||||
for (PRInt32 i = 0; i < errorPosition - 1; i++) {
|
||||
aSourceString.Append(PRUnichar('-'));
|
||||
}
|
||||
aSourceString.Append(PRUnichar('^'));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleError(const char *aBuffer,
|
||||
PRUint32 aLength,
|
||||
PRBool aIsFinal)
|
||||
{
|
||||
|
||||
PRInt32 code = XML_GetErrorCode(mExpatParser);
|
||||
NS_WARN_IF_FALSE(code >= 1, "unexpected XML error code");
|
||||
|
||||
// Map Expat error code to an error string
|
||||
// XXX Deal with error returns.
|
||||
nsAutoString description;
|
||||
nsParserMsgUtils::GetLocalizedStringByID(XMLPARSER_PROPERTIES, code, description);
|
||||
|
||||
if (code == XML_ERROR_TAG_MISMATCH) {
|
||||
description.Append(NS_LITERAL_STRING(". Expected: "));
|
||||
description.Append(NS_LITERAL_STRING("</"));
|
||||
description.Append((const PRUnichar*)XML_GetMismatchedTag(mExpatParser));
|
||||
description.Append(NS_LITERAL_STRING(">."));
|
||||
}
|
||||
|
||||
nsAutoString sourceLine;
|
||||
if (!aIsFinal) {
|
||||
GetLine(aBuffer, aLength, (XML_GetCurrentByteIndex(mExpatParser) - mBytesParsed), sourceLine);
|
||||
}
|
||||
else {
|
||||
sourceLine.Append(mLastLine);
|
||||
}
|
||||
|
||||
// Adjust the column number so that it is one based rather than zero based.
|
||||
PRInt32 colNumber = XML_GetCurrentColumnNumber(mExpatParser) + 1;
|
||||
|
||||
nsAutoString errorText;
|
||||
CreateErrorText(description.get(),
|
||||
(PRUnichar*)XML_GetBase(mExpatParser),
|
||||
XML_GetCurrentLineNumber(mExpatParser),
|
||||
colNumber, errorText);
|
||||
|
||||
nsAutoString sourceText;
|
||||
CreateSourceText(colNumber, sourceLine.get(), sourceText);
|
||||
|
||||
NS_ASSERTION(mSink,"no sink?");
|
||||
if (mSink) {
|
||||
mSink->ReportError(errorText.get(), sourceText.get());
|
||||
}
|
||||
|
||||
return NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::ParseBuffer(const char* aBuffer,
|
||||
PRUint32 aLength,
|
||||
PRBool aIsFinal)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
NS_ASSERTION((aBuffer && aLength) || (aBuffer == nsnull && aLength == 0), "?");
|
||||
|
||||
if (mExpatParser && mInternalState == NS_OK) {
|
||||
if (!XML_Parse(mExpatParser, aBuffer, aLength, aIsFinal)) {
|
||||
if (mInternalState == NS_ERROR_HTMLPARSER_BLOCK ||
|
||||
mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING) {
|
||||
mBytePosition = (XML_GetCurrentByteIndex(mExpatParser) - mBytesParsed);
|
||||
mBytesParsed += mBytePosition;
|
||||
}
|
||||
else {
|
||||
HandleError(aBuffer,aLength,aIsFinal);
|
||||
mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
}
|
||||
return mInternalState;
|
||||
}
|
||||
else if (aBuffer && aLength) {
|
||||
// Cache the last line in the buffer
|
||||
GetLine(aBuffer, aLength, aLength - sizeof(PRUnichar), mLastLine);
|
||||
}
|
||||
mBytesParsed += aLength;
|
||||
mBytePosition = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
nsExpatDriver::GetLine(const char* aSourceBuffer,
|
||||
PRUint32 aLength,
|
||||
PRUint32 aOffset,
|
||||
nsString& aLine)
|
||||
{
|
||||
/* Figure out the line inside aSourceBuffer that contains character specified by aOffset.
|
||||
Copy it into aLine. */
|
||||
NS_ASSERTION(aOffset >= 0 && aOffset < aLength, "?");
|
||||
/* Assert that the byteIndex and the length of the buffer is even */
|
||||
NS_ASSERTION(aOffset % 2 == 0 && aLength % 2 == 0, "?");
|
||||
PRUnichar* start = (PRUnichar* ) &aSourceBuffer[aOffset]; /* Will try to find the start of the line */
|
||||
PRUnichar* end = (PRUnichar* ) &aSourceBuffer[aOffset]; /* Will try to find the end of the line */
|
||||
PRUint32 startIndex = aOffset / sizeof(PRUnichar); /* Track the position of the 'start' pointer into the buffer */
|
||||
PRUint32 endIndex = aOffset / sizeof(PRUnichar); /* Track the position of the 'end' pointer into the buffer */
|
||||
PRUint32 numCharsInBuffer = aLength / sizeof(PRUnichar);
|
||||
PRBool reachedStart;
|
||||
PRBool reachedEnd;
|
||||
|
||||
|
||||
/* Use start to find the first new line before the error position and
|
||||
end to find the first new line after the error position */
|
||||
reachedStart = (startIndex <= 0 || '\n' == *start || '\r' == *start);
|
||||
reachedEnd = (endIndex >= numCharsInBuffer || '\n' == *end || '\r' == *end);
|
||||
while (!reachedStart || !reachedEnd) {
|
||||
if (!reachedStart) {
|
||||
--start;
|
||||
--startIndex;
|
||||
reachedStart = (startIndex <= 0 || '\n' == *start || '\r' == *start);
|
||||
}
|
||||
if (!reachedEnd) {
|
||||
++end;
|
||||
++endIndex;
|
||||
reachedEnd = (endIndex >= numCharsInBuffer || '\n' == *end || '\r' == *end);
|
||||
}
|
||||
}
|
||||
|
||||
aLine.Truncate(0);
|
||||
if (startIndex == endIndex) {
|
||||
// Special case if the error is on a line where the only character is a newline.
|
||||
// Do nothing
|
||||
}
|
||||
else {
|
||||
NS_ASSERTION(endIndex - startIndex >= sizeof(PRUnichar), "?");
|
||||
/* At this point, there are two cases. Either the error is on the first line or
|
||||
on subsequent lines. If the error is on the first line, startIndex will decrement
|
||||
all the way to zero. If not, startIndex will decrement to the position of the
|
||||
newline character on the previous line. So, in the first case, the start position
|
||||
of the error line = startIndex (== 0). In the second case, the start position of the
|
||||
error line = startIndex + 1. In both cases, the end position of the error line will be
|
||||
(endIndex - 1). */
|
||||
PRUint32 startPosn = (startIndex <= 0) ? startIndex : startIndex + 1;
|
||||
|
||||
/* At this point, the substring starting at startPosn and ending at (endIndex - 1),
|
||||
is the line on which the error occurred. Copy that substring into the error structure. */
|
||||
const PRUnichar* unicodeBuffer = (const PRUnichar*) aSourceBuffer;
|
||||
aLine.Append(&unicodeBuffer[startPosn], endIndex - startPosn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::CreateNewInstance(nsIDTD** aInstancePtrResult)
|
||||
{
|
||||
return NS_NewExpatDriver(aInstancePtrResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::ConsumeToken(nsScanner& aScanner,
|
||||
PRBool& aFlushTokens)
|
||||
{
|
||||
|
||||
// Ask the scanner to send us all the data it has
|
||||
// scanned and pass that data to expat.
|
||||
|
||||
mInternalState = NS_OK; // Resume in case we're blocked.
|
||||
XML_UnblockParser(mExpatParser);
|
||||
|
||||
nsReadingIterator<PRUnichar> start, end;
|
||||
aScanner.CurrentPosition(start);
|
||||
aScanner.EndReading(end);
|
||||
|
||||
while (start != end) {
|
||||
PRUint32 fragLength = PRUint32(start.size_forward());
|
||||
const PRUnichar* expatBuffer = start.get();
|
||||
|
||||
mInternalState = ParseBuffer((const char *)expatBuffer,
|
||||
fragLength * sizeof(PRUnichar),
|
||||
aFlushTokens);
|
||||
|
||||
if (NS_FAILED(mInternalState)) {
|
||||
if (mInternalState == NS_ERROR_HTMLPARSER_BLOCK) {
|
||||
// mBytePosition / 2 => character position. Since one char = two bytes.
|
||||
aScanner.SetPosition(start.advance(mBytePosition / 2), PR_TRUE);
|
||||
aScanner.Mark();
|
||||
}
|
||||
return mInternalState;
|
||||
}
|
||||
|
||||
start.advance(fragLength);
|
||||
}
|
||||
|
||||
aScanner.SetPosition(end, PR_TRUE);
|
||||
|
||||
if(NS_SUCCEEDED(mInternalState)) {
|
||||
return aScanner.Eof();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(eAutoDetectResult)
|
||||
nsExpatDriver::CanParse(CParserContext& aParserContext,
|
||||
const nsString& aBuffer,
|
||||
PRInt32 aVersion)
|
||||
{
|
||||
eAutoDetectResult result = eUnknownDetect;
|
||||
|
||||
if (eViewSource != aParserContext.mParserCommand) {
|
||||
if (aParserContext.mMimeType.EqualsWithConversion(kXMLTextContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kXMLApplicationContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kXHTMLApplicationContentType)||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kRDFTextContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kXULTextContentType)) {
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
else {
|
||||
if (0 == aParserContext.mMimeType.Length() &&
|
||||
kNotFound != aBuffer.Find("<?xml ")) {
|
||||
aParserContext.SetMimeType(NS_LITERAL_STRING(kXMLTextContentType));
|
||||
result=eValidDetect;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
|
||||
nsIContentSink* aSink)
|
||||
{
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aSink);
|
||||
|
||||
aSink->QueryInterface(NS_GET_IID(nsIExpatSink),(void**)&(mSink));
|
||||
NS_ENSURE_TRUE(mSink,NS_ERROR_FAILURE);
|
||||
|
||||
mExpatParser = XML_ParserCreate((const XML_Char*) NS_LITERAL_STRING("UTF-16").get());
|
||||
NS_ENSURE_TRUE(mExpatParser, NS_ERROR_FAILURE);
|
||||
|
||||
#ifdef XML_DTD
|
||||
XML_SetParamEntityParsing(mExpatParser, XML_PARAM_ENTITY_PARSING_ALWAYS);
|
||||
#endif
|
||||
|
||||
XML_SetBase(mExpatParser, (const XML_Char*) (aParserContext.mScanner->GetFilename()).get());
|
||||
|
||||
// Set up the callbacks
|
||||
XML_SetElementHandler(mExpatParser, Driver_HandleStartElement, Driver_HandleEndElement);
|
||||
XML_SetCharacterDataHandler(mExpatParser, Driver_HandleCharacterData);
|
||||
XML_SetProcessingInstructionHandler(mExpatParser, Driver_HandleProcessingInstruction);
|
||||
XML_SetDefaultHandlerExpand(mExpatParser, Driver_HandleDefault);
|
||||
XML_SetExternalEntityRefHandler(mExpatParser, Driver_HandleExternalEntityRef);
|
||||
XML_SetCommentHandler(mExpatParser, Driver_HandleComment);
|
||||
XML_SetCdataSectionHandler(mExpatParser, Driver_HandleStartCdataSection,
|
||||
Driver_HandleEndCdataSection);
|
||||
|
||||
XML_SetDoctypeDeclHandler(mExpatParser, Driver_HandleStartDoctypeDecl, Driver_HandleEndDoctypeDecl);
|
||||
|
||||
// Set up the user data.
|
||||
XML_SetUserData(mExpatParser, this);
|
||||
|
||||
return aSink->WillBuildModel();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::BuildModel(nsIParser* aParser,
|
||||
nsITokenizer* aTokenizer,
|
||||
nsITokenObserver* anObserver,
|
||||
nsIContentSink* aSink)
|
||||
{
|
||||
return mInternalState;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::DidBuildModel(nsresult anErrorCode,
|
||||
PRBool aNotifySink,
|
||||
nsIParser* aParser,
|
||||
nsIContentSink* aSink)
|
||||
{
|
||||
// Check for mSink is intentional. This would make sure
|
||||
// that DidBuildModel() is called only once on the sink.
|
||||
nsresult result = (mSink)? aSink->DidBuildModel(0) : NS_OK;
|
||||
NS_IF_RELEASE(mSink);
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsExpatDriver::GetTokenizer(nsITokenizer*& aTokenizer)
|
||||
{
|
||||
aTokenizer = this;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::WillTokenize(PRBool aIsFinalChunk,
|
||||
nsTokenAllocator* aTokenAllocator)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::WillResumeParse(nsIContentSink* aSink)
|
||||
{
|
||||
return (aSink)? aSink->WillResume():NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::WillInterruptParse(nsIContentSink* aSink)
|
||||
{
|
||||
return (aSink)? aSink->WillInterrupt():NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::DidTokenize(PRBool aIsFinalChunk)
|
||||
{
|
||||
return ParseBuffer(nsnull, 0, aIsFinalChunk);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(const nsIID&)
|
||||
nsExpatDriver::GetMostDerivedIID(void) const
|
||||
{
|
||||
return NS_GET_IID(nsIDTD);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsExpatDriver::Terminate(nsIParser* aParser)
|
||||
{
|
||||
XML_BlockParser(mExpatParser); // XXX - not sure what happens to the unparsed data.
|
||||
return mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
}
|
||||
|
||||
/*************************** Unused methods ***************************************/
|
||||
|
||||
NS_IMETHODIMP_(CToken*)
|
||||
nsExpatDriver::PushTokenFront(CToken* aToken)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(CToken*)
|
||||
nsExpatDriver::PushToken(CToken* aToken)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(CToken*)
|
||||
nsExpatDriver::PopToken(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(CToken*)
|
||||
nsExpatDriver::PeekToken(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(CToken*)
|
||||
nsExpatDriver::GetTokenAt(PRInt32 anIndex)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRInt32)
|
||||
nsExpatDriver::GetCount(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsTokenAllocator*)
|
||||
nsExpatDriver::GetTokenAllocator(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
nsExpatDriver::PrependTokens(nsDeque& aDeque)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::HandleToken(CToken* aToken,nsIParser* aParser)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsExpatDriver::IsBlockElement(PRInt32 aTagID,PRInt32 aParentID) const
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsExpatDriver::IsInlineElement(PRInt32 aTagID,PRInt32 aParentID) const
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsExpatDriver::IsContainer(PRInt32 aTag) const
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsExpatDriver::CanContain(PRInt32 aParent,PRInt32 aChild) const
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::StringTagToIntTag(const nsAReadableString &aTag, PRInt32* aIntTag) const
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(const PRUnichar *)
|
||||
nsExpatDriver::IntTagToStringTag(PRInt32 aIntTag) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::ConvertEntityToUnicode(const nsAReadableString& aEntity, PRInt32* aUnicode) const
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
/******************************************************************************/
|
|
@ -0,0 +1,94 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef NS_EXPAT_DRIVER__
|
||||
#define NS_EXPAT_DRIVER__
|
||||
|
||||
#include "xmlparse.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIDTD.h"
|
||||
#include "nsITokenizer.h"
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
class nsIExpatSink;
|
||||
|
||||
class nsExpatDriver : public nsIDTD,
|
||||
public nsITokenizer
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDTD
|
||||
NS_DECL_NSITOKENIZER
|
||||
|
||||
nsExpatDriver();
|
||||
virtual ~nsExpatDriver();
|
||||
|
||||
// Load up an external stream to get external entity information
|
||||
static nsresult OpenInputStream(const XML_Char* aURLStr, const XML_Char* aBaseURL, nsIInputStream** in, nsAString& aAbsURL);
|
||||
|
||||
nsresult HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts);
|
||||
nsresult HandleEndElement(const PRUnichar *aName);
|
||||
nsresult HandleCharacterData(const PRUnichar *aCData, const PRUint32 aLength);
|
||||
nsresult HandleComment(const PRUnichar *aName);
|
||||
nsresult HandleProcessingInstruction(const PRUnichar *aTarget, const PRUnichar *aData);
|
||||
nsresult HandleDefault(const PRUnichar *aData, const PRUint32 aLength);
|
||||
nsresult HandleStartCdataSection();
|
||||
nsresult HandleEndCdataSection();
|
||||
nsresult HandleStartDoctypeDecl();
|
||||
nsresult HandleEndDoctypeDecl();
|
||||
|
||||
protected:
|
||||
|
||||
nsresult ParseBuffer(const char* aBuffer, PRUint32 aLength, PRBool aIsFinal);
|
||||
nsresult HandleError(const char *aBuffer, PRUint32 aLength, PRBool aIsFinal);
|
||||
void GetLine(const char* aSourceBuffer, PRUint32 aLength, PRUint32 aOffset, nsString& aLine);
|
||||
|
||||
XML_Parser mExpatParser;
|
||||
nsIExpatSink* mSink;
|
||||
nsString mLastLine;
|
||||
nsString mDoctypeText;
|
||||
nsString mCDataText;
|
||||
PRPackedBool mInDoctype;
|
||||
PRPackedBool mInCData;
|
||||
PRUint32 mBytesParsed;
|
||||
PRInt32 mBytePosition;
|
||||
nsresult mInternalState;
|
||||
};
|
||||
nsresult NS_NewExpatDriver(nsIDTD** aDriver);
|
||||
|
||||
#endif
|
|
@ -66,7 +66,6 @@ public:
|
|||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError);
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0);
|
||||
|
@ -624,12 +623,6 @@ nsHTMLNullSink::SetParser(nsIParser* aParser)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLNullSink::NotifyError(const nsParserError* aError)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gpk03/14/99
|
||||
|
|
|
@ -70,27 +70,14 @@
|
|||
|
||||
class nsHTMLTokenizer : public nsITokenizer {
|
||||
public:
|
||||
nsHTMLTokenizer( PRInt32 aParseMode=eDTDMode_quirks,
|
||||
eParserDocType aDocType=eHTML3_Quirks,
|
||||
eParserCommands aCommand=eViewNormal);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSITOKENIZER
|
||||
nsHTMLTokenizer(PRInt32 aParseMode=eDTDMode_quirks,
|
||||
eParserDocType aDocType=eHTML3_Quirks,
|
||||
eParserCommands aCommand=eViewNormal);
|
||||
virtual ~nsHTMLTokenizer();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult WillTokenize(PRBool aIsFinalChunk,nsTokenAllocator* aTokenAllocator);
|
||||
virtual nsresult ConsumeToken(nsScanner& aScanner,PRBool& aFlushTokens);
|
||||
virtual nsresult DidTokenize(PRBool aIsFinalChunk);
|
||||
virtual nsTokenAllocator* GetTokenAllocator(void);
|
||||
|
||||
virtual CToken* PushTokenFront(CToken* theToken);
|
||||
virtual CToken* PushToken(CToken* theToken);
|
||||
virtual CToken* PopToken(void);
|
||||
virtual CToken* PeekToken(void);
|
||||
virtual CToken* GetTokenAt(PRInt32 anIndex);
|
||||
virtual PRInt32 GetCount(void);
|
||||
|
||||
virtual void PrependTokens(nsDeque& aDeque);
|
||||
|
||||
protected:
|
||||
|
||||
virtual nsresult ConsumeScriptContent(nsScanner& aScanner,CToken*& aToken);
|
||||
|
|
|
@ -253,20 +253,6 @@ nsLoggingSink::AddLeaf(const nsIParserNode& aNode) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLoggingSink::NotifyError(const nsParserError* aError) {
|
||||
nsresult theResult=NS_OK;
|
||||
|
||||
//then proxy the call to the real sink if you have one.
|
||||
if(mSink) {
|
||||
theResult=mSink->NotifyError(aError);
|
||||
}
|
||||
|
||||
return theResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a PI node to the current container in the content
|
||||
|
|
|
@ -68,7 +68,6 @@ public:
|
|||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError);
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0);
|
||||
|
|
|
@ -49,7 +49,6 @@
|
|||
#include "nsScanner.h"
|
||||
#include "plstr.h"
|
||||
#include "nsIParserFilter.h"
|
||||
#include "nsWellFormedDTD.h"
|
||||
#include "nsViewSourceHTML.h"
|
||||
#include "nsIStringStream.h"
|
||||
#include "nsIChannel.h"
|
||||
|
@ -65,13 +64,14 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsExpatDriver.h"
|
||||
//#define rickgdebug
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
|
||||
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
|
||||
|
||||
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
|
||||
static NS_DEFINE_IID(kExpatDriverCID, NS_EXPAT_DRIVER_CID);
|
||||
static NS_DEFINE_CID(kNavDTDCID, NS_CNAVDTD_CID);
|
||||
static NS_DEFINE_CID(kCOtherDTDCID, NS_COTHER_DTD_CID);
|
||||
static NS_DEFINE_CID(kViewSourceDTDCID, NS_VIEWSOURCE_DTD_CID);
|
||||
|
@ -1159,7 +1159,7 @@ PRBool FindSuitableDTD( CParserContext& aParserContext,nsString& aBuffer) {
|
|||
}
|
||||
if((theDTDIndex==gSharedObjects.mDTDDeque.GetSize()) && (!thePrimaryFound)) {
|
||||
if(!gSharedObjects.mHasXMLDTD) {
|
||||
NS_NewWellFormed_DTD(&theDTD); //do this to view XML files...
|
||||
NS_NewExpatDriver(&theDTD); //do this to view XML files...
|
||||
gSharedObjects.mDTDDeque.Push(theDTD);
|
||||
gSharedObjects.mHasXMLDTD=PR_TRUE;
|
||||
}
|
||||
|
@ -1261,7 +1261,7 @@ NS_IMETHODIMP nsParser::CreateCompatibleDTD(nsIDTD** aDTD,
|
|||
theDTDClassID=&kNavDTDCID;
|
||||
break;
|
||||
case eXML:
|
||||
theDTDClassID=&kWellFormedDTDCID;
|
||||
theDTDClassID=&kExpatDriverCID;
|
||||
break;
|
||||
default:
|
||||
theDTDClassID=&kNavDTDCID;
|
||||
|
@ -1288,7 +1288,7 @@ NS_IMETHODIMP nsParser::CreateCompatibleDTD(nsIDTD** aDTD,
|
|||
aMimeType->EqualsWithConversion(kXHTMLApplicationContentType) ||
|
||||
aMimeType->EqualsWithConversion(kXULTextContentType) ||
|
||||
aMimeType->EqualsWithConversion(kRDFTextContentType)) {
|
||||
theDTDClassID=&kWellFormedDTDCID;
|
||||
theDTDClassID=&kExpatDriverCID;
|
||||
}
|
||||
else {
|
||||
theDTDClassID=&kNavDTDCID;
|
||||
|
@ -1836,7 +1836,7 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo
|
|||
// as if it was read from the input stream.
|
||||
// Adding UngetReadable() per vidur!!
|
||||
mParserContext->mScanner->UngetReadable(mUnusedInput);
|
||||
mUnusedInput.Truncate(0);
|
||||
mUnusedInput.Truncate(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1853,7 +1853,7 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo
|
|||
SetCanInterrupt(PR_FALSE);
|
||||
|
||||
theIterationIsOk=PRBool((kEOF!=theTokenizerResult) && (result!=NS_ERROR_HTMLPARSER_INTERRUPTED));
|
||||
|
||||
|
||||
// Make sure not to stop parsing too early. Therefore, before shutting down the
|
||||
// parser, it's important to check whether the input buffer has been scanned to
|
||||
// completion ( theTokenizerResult should be kEOF ). kEOF -> End of buffer.
|
||||
|
@ -1864,7 +1864,7 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo
|
|||
if(NS_ERROR_HTMLPARSER_BLOCK==result) {
|
||||
//BLOCK == 2152596464
|
||||
if (mParserContext->mDTD) {
|
||||
mParserContext->mDTD->WillInterruptParse();
|
||||
mParserContext->mDTD->WillInterruptParse(mSink);
|
||||
}
|
||||
|
||||
BlockParser();
|
||||
|
|
|
@ -162,10 +162,10 @@ class nsParser : public nsIParser,
|
|||
*/
|
||||
virtual void SetDocumentCharset(nsString& aCharset, PRInt32 aSource);
|
||||
|
||||
void GetDocumentCharset(nsString& oCharset, PRInt32& oSource)
|
||||
void GetDocumentCharset(nsString& aCharset, PRInt32& aSource)
|
||||
{
|
||||
oCharset = mCharset;
|
||||
oSource = mCharsetSource;
|
||||
aCharset = mCharset;
|
||||
aSource = mCharsetSource;
|
||||
}
|
||||
|
||||
|
||||
|
@ -453,29 +453,30 @@ protected:
|
|||
// And now, some data members...
|
||||
//*********************************************
|
||||
|
||||
|
||||
CParserContext* mParserContext;
|
||||
PRInt32 mMajorIteration;
|
||||
PRInt32 mMinorIteration;
|
||||
|
||||
nsIRequestObserver* mObserver;
|
||||
nsIContentSink* mSink;
|
||||
|
||||
nsCOMPtr<nsIEventQueue> mEventQueue;
|
||||
CParserContext* mParserContext;
|
||||
nsIRequestObserver* mObserver;
|
||||
nsIContentSink* mSink;
|
||||
|
||||
nsIParserFilter* mParserFilter;
|
||||
PRBool mDTDVerification;
|
||||
eParserCommands mCommand;
|
||||
PRInt32 mStreamStatus;
|
||||
nsITokenObserver* mTokenObserver;
|
||||
nsTokenAllocator mTokenAllocator;
|
||||
|
||||
eParserCommands mCommand;
|
||||
nsresult mInternalState;
|
||||
PRInt32 mStreamStatus;
|
||||
PRInt32 mMajorIteration;
|
||||
PRInt32 mMinorIteration;
|
||||
PRInt32 mCharsetSource;
|
||||
|
||||
nsString mUnusedInput;
|
||||
nsString mCharset;
|
||||
PRInt32 mCharsetSource;
|
||||
nsresult mInternalState;
|
||||
PRBool mObserversEnabled;
|
||||
nsString mCommandStr;
|
||||
PRBool mParserEnabled;
|
||||
nsTokenAllocator mTokenAllocator;
|
||||
|
||||
nsCOMPtr<nsIEventQueue> mEventQueue;
|
||||
|
||||
PRPackedBool mDTDVerification;
|
||||
PRPackedBool mParserEnabled;
|
||||
PRPackedBool mObserversEnabled;
|
||||
PRPackedBool mPendingContinueEvent;
|
||||
PRPackedBool mCanInterrupt;
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "nsILoggingSink.h"
|
||||
#include "nsParser.h"
|
||||
#include "nsParserNode.h"
|
||||
#include "nsWellFormedDTD.h"
|
||||
#include "CNavDTD.h"
|
||||
|
||||
#include "nsHTMLTags.h"
|
||||
|
@ -52,12 +51,12 @@
|
|||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_IID(kCParserNode, NS_PARSER_NODE_IID);
|
||||
|
||||
static NS_DEFINE_CID(kCParserCID NS_PARSER_CID);
|
||||
static NS_DEFINE_IID(kCParserNode, NS_PARSER_NODE_IID);
|
||||
static NS_DEFINE_IID(kLoggingSinkCID, NS_LOGGING_SINK_CID);
|
||||
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
|
||||
static NS_DEFINE_CID(kCNavDTDCID, NS_CNAVDTD_CID);
|
||||
static NS_DEFINE_CID(kCParserCID NS_PARSER_CID);
|
||||
static NS_DEFINE_CID(kLoggingSinkCID, NS_LOGGING_SINK_CID);
|
||||
static NS_DEFINE_CID(kExpatDriverCID, NS_EXPAT_DRIVER_CID);
|
||||
static NS_DEFINE_CID(kCNavDTDCID, NS_CNAVDTD_CID);
|
||||
|
||||
class nsParserFactory : public nsIFactory
|
||||
{
|
||||
|
@ -144,8 +143,8 @@ nsresult nsParserFactory::CreateInstance(nsISupports *aOuter,
|
|||
*aResult = cs;
|
||||
return rv;
|
||||
}
|
||||
else if (mClassID.Equals(kWellFormedDTDCID)) {
|
||||
nsresult rv = NS_NewWellFormed_DTD((nsIDTD**) &inst);
|
||||
else if (mClassID.Equals(kExpatDriverCID)) {
|
||||
nsresult rv = NS_NewExpatDriver((nsIDTD**) &inst);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "nsIModule.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "nsParser.h"
|
||||
#include "nsWellFormedDTD.h"
|
||||
#include "CNavDTD.h"
|
||||
#include "COtherDTD.h"
|
||||
#include "COtherDTD.h"
|
||||
|
@ -52,22 +51,22 @@
|
|||
#include "nsHTMLEntities.h"
|
||||
#include "nsHTMLTokenizer.h"
|
||||
//#include "nsTextTokenizer.h"
|
||||
#include "nsExpatTokenizer.h"
|
||||
#include "nsElementTable.h"
|
||||
#include "nsParserService.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
#include "nsLoggingSink.h"
|
||||
#include "nsExpatDriver.h"
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLoggingSink)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsExpatDriver)
|
||||
#endif
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsParser)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(CWellFormedDTD)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(CNavDTD)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(COtherDTD)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(CTransitionalDTD)
|
||||
|
@ -78,10 +77,10 @@ static nsModuleComponentInfo gComponents[] = {
|
|||
|
||||
#ifdef NS_DEBUG
|
||||
{ "Logging sink", NS_LOGGING_SINK_CID, NULL, nsLoggingSinkConstructor },
|
||||
{ "Expat Driver", NS_EXPAT_DRIVER_CID, NULL, nsExpatDriverConstructor },
|
||||
#endif
|
||||
|
||||
{ "Parser", NS_PARSER_CID, NULL, nsParserConstructor },
|
||||
{ "Well formed DTD", NS_WELLFORMEDDTD_CID, NULL, CWellFormedDTDConstructor },
|
||||
{ "Navigator HTML DTD", NS_CNAVDTD_CID, NULL, CNavDTDConstructor },
|
||||
{ "OTHER DTD", NS_COTHER_DTD_CID, NULL, COtherDTDConstructor },
|
||||
{ "Transitional DTD", NS_CTRANSITIONAL_DTD_CID, NULL,
|
||||
|
|
|
@ -713,22 +713,6 @@ NS_IMETHODIMP CViewSourceHTML::DidBuildModel(nsresult anErrorCode,PRBool aNotify
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess8/4/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsTokenAllocator* CViewSourceHTML::GetTokenAllocator(void){
|
||||
nsITokenizer* theTokenizer=0;
|
||||
nsresult result=GetTokenizer(theTokenizer);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
return theTokenizer->GetTokenAllocator();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this id you want to stop the building content model
|
||||
* --------------[ Sets DTD to STOP mode ]----------------
|
||||
|
@ -767,7 +751,7 @@ nsresult CViewSourceHTML::GetTokenizer(nsITokenizer*& aTokenizer) {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHODIMP CViewSourceHTML::WillResumeParse(void){
|
||||
NS_IMETHODIMP CViewSourceHTML::WillResumeParse(nsIContentSink* aSink){
|
||||
nsresult result = NS_OK;
|
||||
if(mSink) {
|
||||
result = mSink->WillResume();
|
||||
|
@ -781,7 +765,7 @@ NS_IMETHODIMP CViewSourceHTML::WillResumeParse(void){
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHODIMP CViewSourceHTML::WillInterruptParse(void){
|
||||
NS_IMETHODIMP CViewSourceHTML::WillInterruptParse(nsIContentSink* aSink){
|
||||
nsresult result = NS_OK;
|
||||
if(mSink) {
|
||||
result = mSink->WillInterrupt();
|
||||
|
|
|
@ -53,127 +53,10 @@ class CViewSourceHTML: public nsIDTD
|
|||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 4/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
CViewSourceHTML();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 4/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual ~CViewSourceHTML();
|
||||
|
||||
|
||||
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const;
|
||||
|
||||
/**
|
||||
* Call this method if you want the DTD to construct a clone of itself.
|
||||
* @update gess7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD CreateNewInstance(nsIDTD** aInstancePtrResult);
|
||||
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can parse
|
||||
* a document in a given source-type.
|
||||
* NOTE: Parsing always assumes that the end result will involve
|
||||
* storing the result in the main content model.
|
||||
* @update gess6/24/98
|
||||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
NS_IMETHOD_(eAutoDetectResult) CanParse(CParserContext& aParserContext,
|
||||
const nsString& aBuffer,
|
||||
PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update rickg 03.20.2000
|
||||
* @param aParserContext
|
||||
* @param aSink
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext,
|
||||
nsIContentSink* aSink);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param aFilename is the name of the file being parsed.
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer,
|
||||
nsITokenObserver* anObserver = nsnull,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param anErrorCode contans the last error that occured
|
||||
* @return error code
|
||||
*/
|
||||
NS_IMETHOD DidBuildModel(nsresult anErrorCode, PRBool aNotifySink,
|
||||
nsIParser* aParser,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aToken -- token object to be put into content model
|
||||
* @return 0 if all is well; non-zero is an error
|
||||
*/
|
||||
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 12/20/99
|
||||
* @param ptr-ref to (out) tokenizer
|
||||
* @return nsresult
|
||||
*/
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer);
|
||||
|
||||
NS_DECL_NSIDTD
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/28/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD_(nsTokenAllocator *) GetTokenAllocator(void);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD WillResumeParse(void);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD WillInterruptParse(void);
|
||||
CViewSourceHTML();
|
||||
virtual ~CViewSourceHTML();
|
||||
|
||||
/**
|
||||
* Set this to TRUE if you want the DTD to verify its
|
||||
|
@ -184,61 +67,20 @@ public:
|
|||
*/
|
||||
virtual void SetVerification(PRBool aEnable);
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- int tag of parent container
|
||||
* @param aChild -- int tag of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent,PRInt32 aChild) const;
|
||||
|
||||
/**
|
||||
* Use this id you want to stop the building content model
|
||||
* --------------[ Sets DTD to STOP mode ]----------------
|
||||
* It's recommended to use this method in accordance with
|
||||
* the parser's terminate() method.
|
||||
*
|
||||
* @update harishd 07/22/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD Terminate(nsIParser* aParser = nsnull);
|
||||
|
||||
/**
|
||||
* Give rest of world access to our tag enums, so that CanContain(), etc,
|
||||
* become useful.
|
||||
*/
|
||||
NS_IMETHOD StringTagToIntTag(const nsAReadableString &aTag,
|
||||
PRInt32* aIntTag) const;
|
||||
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const;
|
||||
|
||||
NS_IMETHOD ConvertEntityToUnicode(const nsAReadableString& aEntity,
|
||||
PRInt32* aUnicode) const;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const;
|
||||
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const;
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag is itself a container
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aTag -- tag to test for containership
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const;
|
||||
|
||||
|
||||
private:
|
||||
nsresult WriteTag(PRInt32 tagType,const nsAReadableString &aText,PRInt32 attrCount,PRBool aNewlineRequired);
|
||||
nsresult WriteTagWithError(PRInt32 tagType,const nsAReadableString& aToken,PRInt32 attrCount,PRBool aNewlineRequired);
|
||||
void AddContainmentError(eHTMLTags aChild,eHTMLTags aParent,PRInt32 aLineNumber);
|
||||
nsresult WriteTag(PRInt32 tagType,
|
||||
const nsAReadableString &aText,
|
||||
PRInt32 attrCount,
|
||||
PRBool aNewlineRequired);
|
||||
|
||||
nsresult WriteTagWithError(PRInt32 tagType,
|
||||
const nsAReadableString& aToken,
|
||||
PRInt32 attrCount,
|
||||
PRBool aNewlineRequired);
|
||||
|
||||
void AddContainmentError(eHTMLTags aChild,
|
||||
eHTMLTags aParent,
|
||||
PRInt32 aLineNumber);
|
||||
|
||||
nsresult WriteAttributes(PRInt32 attrCount);
|
||||
nsresult GenerateSummary();
|
||||
|
|
|
@ -1,788 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* MODULE NOTES:
|
||||
* @update gess 4/8/98
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsWellFormedDTD.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsParser.h"
|
||||
#include "nsScanner.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsDTDUtils.h"
|
||||
#include "nsIContentSink.h"
|
||||
#include "nsIHTMLContentSink.h"
|
||||
#include "nsHTMLTokenizer.h"
|
||||
#include "nsExpatTokenizer.h"
|
||||
|
||||
#include "prenv.h" //this is here for debug reasons...
|
||||
#include "prtypes.h" //this is here for debug reasons...
|
||||
#include "prio.h"
|
||||
#include "plstr.h"
|
||||
#include "prprf.h"
|
||||
|
||||
#include "prmem.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
|
||||
#include <ctype.h> // toupper()
|
||||
#include "nsString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
|
||||
static NS_DEFINE_IID(kClassIID, NS_WELLFORMED_DTD_IID);
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called as part of our COM-like interfaces.
|
||||
* Its purpose is to create an interface to parser object
|
||||
* of some type.
|
||||
*
|
||||
* @update gess 4/8/98
|
||||
* @param nsIID id of object to discover
|
||||
* @param aInstancePtr ptr to newly discovered interface
|
||||
* @return NS_xxx result code
|
||||
*/
|
||||
nsresult CWellFormedDTD::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if(aIID.Equals(kISupportsIID)) { //do IUnknown...
|
||||
*aInstancePtr = (nsIDTD*)(this);
|
||||
}
|
||||
else if(aIID.Equals(kIDTDIID)) { //do IParser base class...
|
||||
*aInstancePtr = (nsIDTD*)(this);
|
||||
}
|
||||
else if(aIID.Equals(kClassIID)) { //do this class...
|
||||
*aInstancePtr = (CWellFormedDTD*)(this);
|
||||
}
|
||||
else {
|
||||
*aInstancePtr=0;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is defined in nsIParser. It is used to
|
||||
* cause the COM-like construction of an nsParser.
|
||||
*
|
||||
* @update gess 4/8/98
|
||||
* @param nsIParser** ptr to newly instantiated parser
|
||||
* @return NS_xxx error result
|
||||
*/
|
||||
nsresult NS_NewWellFormed_DTD(nsIDTD** aInstancePtrResult)
|
||||
{
|
||||
CWellFormedDTD* it = new CWellFormedDTD();
|
||||
|
||||
if (it == 0) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kClassIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(CWellFormedDTD)
|
||||
NS_IMPL_RELEASE(CWellFormedDTD)
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @update gess 4/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
CWellFormedDTD::CWellFormedDTD() : nsIDTD() {
|
||||
NS_INIT_REFCNT();
|
||||
mParser=0;
|
||||
mSink=0;
|
||||
mLineNumber=1;
|
||||
mTokenizer=0;
|
||||
mDTDState=NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default destructor
|
||||
*
|
||||
* @update gess 4/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
CWellFormedDTD::~CWellFormedDTD(){
|
||||
mParser=0; //just to prove we destructed...
|
||||
NS_IF_RELEASE(mTokenizer);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/8/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
const nsIID& CWellFormedDTD::GetMostDerivedIID(void) const{
|
||||
return kClassIID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method if you want the DTD to construct a fresh
|
||||
* instance of itself.
|
||||
* @update gess7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult CWellFormedDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
||||
return NS_NewWellFormed_DTD(aInstancePtrResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can parse
|
||||
* a document in a given source-type.
|
||||
* NOTE: Parsing always assumes that the end result will involve
|
||||
* storing the result in the main content model.
|
||||
* @update gess6/24/98
|
||||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
NS_IMETHODIMP_(eAutoDetectResult)
|
||||
CWellFormedDTD::CanParse(CParserContext& aParserContext,
|
||||
const nsString& aBuffer, PRInt32 aVersion)
|
||||
{
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
|
||||
if(eViewSource!=aParserContext.mParserCommand) {
|
||||
if(aParserContext.mMimeType.EqualsWithConversion(kXMLTextContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kXMLApplicationContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kXHTMLApplicationContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kRDFTextContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kXULTextContentType)
|
||||
#ifdef MOZ_SVG
|
||||
|| aParserContext.mMimeType.Equals(NS_LITERAL_STRING(kSVGTextContentType))
|
||||
#endif
|
||||
) {
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
else if (aParserContext.mMimeType.IsEmpty()) {
|
||||
nsAReadableString::const_iterator iter, end;
|
||||
aBuffer.BeginReading(iter);
|
||||
aBuffer.EndReading(end);
|
||||
|
||||
if (FindInReadable(NS_LITERAL_STRING("<?xml "), iter, end)) {
|
||||
aParserContext.SetMimeType(NS_ConvertASCIItoUCS2(kXMLTextContentType));
|
||||
result=eValidDetect;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update rickg 03.20.2000
|
||||
* @param aParserContext
|
||||
* @param aSink
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
nsresult CWellFormedDTD::WillBuildModel( const CParserContext& aParserContext,nsIContentSink* aSink){
|
||||
|
||||
nsresult result=NS_OK;
|
||||
mFilename=aParserContext.mScanner->GetFilename();
|
||||
|
||||
mSink=aSink;
|
||||
if((!aParserContext.mPrevContext) && (mSink)) {
|
||||
mLineNumber=1;
|
||||
result = mSink->WillBuildModel();
|
||||
|
||||
#if 0
|
||||
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
|
||||
{
|
||||
|
||||
//now let's automatically open the html...
|
||||
CStartToken theHTMLToken(eHTMLTag_html);
|
||||
nsCParserNode theHTMLNode(&theHTMLToken,0);
|
||||
mSink->OpenHTML(theHTMLNode);
|
||||
|
||||
//now let's automatically open the body...
|
||||
CStartToken theBodyToken(eHTMLTag_body);
|
||||
nsCParserNode theBodyNode(&theBodyToken,0);
|
||||
mSink->OpenBody(theBodyNode);
|
||||
}
|
||||
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
|
||||
#endif
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess 1/4/99
|
||||
* @param aFilename is the name of the file being parsed.
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHODIMP CWellFormedDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITokenObserver* anObserver,nsIContentSink* aSink) {
|
||||
nsresult result=NS_OK;
|
||||
|
||||
if(aTokenizer) {
|
||||
nsHTMLTokenizer* oldTokenizer=mTokenizer;
|
||||
mTokenizer=(nsHTMLTokenizer*)aTokenizer;
|
||||
|
||||
while(NS_SUCCEEDED(result)){
|
||||
if(mDTDState!=NS_ERROR_HTMLPARSER_STOPPARSING) {
|
||||
CToken* theToken=mTokenizer->PopToken();
|
||||
if(theToken) {
|
||||
result=HandleToken(theToken,aParser);
|
||||
if(NS_SUCCEEDED(result) || (NS_ERROR_HTMLPARSER_BLOCK==result)) {
|
||||
IF_FREE(theToken, mTokenizer->GetTokenAllocator());
|
||||
}
|
||||
else {
|
||||
// if(NS_ERROR_HTMLPARSER_BLOCK!=result){
|
||||
mTokenizer->PushTokenFront(theToken);
|
||||
}
|
||||
}
|
||||
else break;
|
||||
}
|
||||
else result=mDTDState;
|
||||
}//while
|
||||
mTokenizer=oldTokenizer;
|
||||
}
|
||||
else result=NS_ERROR_HTMLPARSER_BADTOKENIZER;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHODIMP CWellFormedDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParser* aParser,nsIContentSink* aSink){
|
||||
nsresult result= NS_OK;
|
||||
|
||||
//ADD CODE HERE TO CLOSE OPEN CONTAINERS...
|
||||
|
||||
if(aParser){
|
||||
mSink=aParser->GetContentSink();
|
||||
if((aNotifySink) && (mSink)) {
|
||||
result = mSink->DidBuildModel(1);
|
||||
|
||||
#if 0
|
||||
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
|
||||
{
|
||||
nsIHTMLContentSink* mSink=(nsIHTMLContentSink*)mSink;
|
||||
|
||||
//now let's automatically open the body...
|
||||
CEndToken theBodyToken(eHTMLTag_body);
|
||||
nsCParserNode theBodyNode(&theBodyToken,0);
|
||||
mSink->CloseBody(theBodyNode);
|
||||
|
||||
//now let's automatically open the html...
|
||||
CEndToken theHTMLToken(eHTMLTag_html);
|
||||
nsCParserNode theHTMLNode(&theBodyToken,0);
|
||||
mSink->CloseHTML(theBodyNode);
|
||||
|
||||
}
|
||||
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess8/4/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsTokenAllocator* CWellFormedDTD::GetTokenAllocator(void){
|
||||
nsITokenizer* theTokenizer=0;
|
||||
|
||||
nsresult result=GetTokenizer(theTokenizer);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
return theTokenizer->GetTokenAllocator();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this id you want to stop the building content model
|
||||
* --------------[ Sets DTD to STOP mode ]----------------
|
||||
* It's recommended to use this method in accordance with
|
||||
* the parser's terminate() method. Here we process only
|
||||
* the "error" token.
|
||||
*
|
||||
* @update harishd 07/22/99
|
||||
* @param aParser - Parser that exists.
|
||||
* @return NS_ERROR_HTMLPARSER_STOPPARSING or the appropriate error.
|
||||
*/
|
||||
nsresult CWellFormedDTD::Terminate(nsIParser* aParser)
|
||||
{
|
||||
nsresult result=NS_OK;
|
||||
|
||||
if(mTokenizer) {
|
||||
nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();
|
||||
if(theAllocator) {
|
||||
eHTMLTokenTypes theType=eToken_unknown;
|
||||
|
||||
mDTDState=NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
|
||||
while(result==NS_OK){
|
||||
CToken* theToken=mTokenizer->PopToken();
|
||||
if(theToken) {
|
||||
theType=(eHTMLTokenTypes)theToken->GetTokenType();
|
||||
if(theType==eToken_error) {
|
||||
result=HandleToken(theToken,aParser);
|
||||
}
|
||||
IF_FREE(theToken, mTokenizer->GetTokenAllocator());
|
||||
}
|
||||
else break;
|
||||
}//while
|
||||
}//if
|
||||
}//if
|
||||
result=(NS_SUCCEEDED(result))? mDTDState:result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the preferred tokenizer for use by this DTD.
|
||||
* @update gess12/28/98
|
||||
* @param none
|
||||
* @return ptr to tokenizer
|
||||
*/
|
||||
nsresult CWellFormedDTD::GetTokenizer(nsITokenizer*& aTokenizer) {
|
||||
nsresult result=NS_OK;
|
||||
if(!mTokenizer) {
|
||||
mTokenizer=(nsHTMLTokenizer*)new nsExpatTokenizer(&mFilename);
|
||||
NS_IF_ADDREF(mTokenizer);
|
||||
}
|
||||
aTokenizer=mTokenizer;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHODIMP CWellFormedDTD::WillResumeParse(void){
|
||||
nsresult result = NS_OK;
|
||||
if(mSink) {
|
||||
result = mSink->WillResume();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHODIMP CWellFormedDTD::WillInterruptParse(void){
|
||||
nsresult result = NS_OK;
|
||||
if(mSink) {
|
||||
result = mSink->WillInterrupt();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the parser to enable/disable dtd verification of the
|
||||
* internal context stack.
|
||||
* @update gess 7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void CWellFormedDTD::SetVerification(PRBool aEnabled){
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- int tag of parent container
|
||||
* @param aChild -- int tag of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
PRBool CWellFormedDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const{
|
||||
PRBool result=PR_TRUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give rest of world access to our tag enums, so that CanContain(), etc,
|
||||
* become useful.
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
CWellFormedDTD::StringTagToIntTag(const nsAReadableString &aTag,
|
||||
PRInt32* aIntTag) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(const PRUnichar *)
|
||||
CWellFormedDTD::IntTagToStringTag(PRInt32 aIntTag) const
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CWellFormedDTD::ConvertEntityToUnicode(const nsAReadableString& aEntity,
|
||||
PRInt32* aUnicode) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag is itself a container
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aTag -- tag to test for containership
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
PRBool CWellFormedDTD::IsContainer(PRInt32 aTag) const{
|
||||
PRBool result=PR_TRUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update vidur 11/12/98
|
||||
* @param aToken -- token object to be put into content model
|
||||
* @return 0 if all is well; non-zero is an error
|
||||
*/
|
||||
NS_IMETHODIMP CWellFormedDTD::HandleToken(CToken* aToken,nsIParser* aParser) {
|
||||
nsresult result=NS_OK;
|
||||
CHTMLToken* theToken= (CHTMLToken*)(aToken);
|
||||
eHTMLTokenTypes theType= (eHTMLTokenTypes)theToken->GetTokenType();
|
||||
|
||||
mParser=(nsParser*)aParser;
|
||||
mSink=aParser->GetContentSink();
|
||||
|
||||
switch(theType) {
|
||||
|
||||
case eToken_newline:
|
||||
mLineNumber++; //now fall through
|
||||
case eToken_entity:
|
||||
case eToken_whitespace:
|
||||
case eToken_text:
|
||||
case eToken_cdatasection:
|
||||
case eToken_markupDecl:
|
||||
result=HandleLeafToken(aToken);
|
||||
break;
|
||||
case eToken_comment:
|
||||
result=HandleCommentToken(aToken);
|
||||
break;
|
||||
case eToken_instruction:
|
||||
result=HandleProcessingInstructionToken(aToken);
|
||||
break;
|
||||
case eToken_start:
|
||||
result=HandleStartToken(aToken);
|
||||
break;
|
||||
case eToken_end:
|
||||
result=HandleEndToken(aToken);
|
||||
break;
|
||||
case eToken_error:
|
||||
result=HandleErrorToken(aToken);
|
||||
break;
|
||||
case eToken_doctypeDecl:
|
||||
result=HandleDocTypeDeclToken(aToken);
|
||||
break;
|
||||
case eToken_style:
|
||||
case eToken_skippedcontent:
|
||||
default:
|
||||
result=NS_OK;
|
||||
}//switch
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a leaf token has been
|
||||
* encountered in the parse process.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleLeafToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenizer->GetTokenAllocator());
|
||||
result= (mSink)? mSink->AddLeaf(theNode):NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a comment token has been
|
||||
* encountered in the parse process. Here we also make sure
|
||||
* to count the newlines in the comment.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleCommentToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
CCommentToken* theToken = (CCommentToken*)aToken;
|
||||
mLineNumber += CountCharInReadable(theToken->GetStringValue(),
|
||||
PRUnichar(kNewLine));
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenizer->GetTokenAllocator());
|
||||
result=(mSink)? mSink->AddComment(theNode):NS_OK;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a prcessing instruction
|
||||
* has been encountered in the parse process.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleProcessingInstructionToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenizer->GetTokenAllocator());
|
||||
result=(mSink)? mSink->AddProcessingInstruction(theNode):NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a start token has been
|
||||
* encountered in the parse process.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next (start) token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleStartToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenizer->GetTokenAllocator());
|
||||
PRInt16 attrCount=aToken->GetAttributeCount();
|
||||
|
||||
if(0<attrCount){ //go collect the attributes...
|
||||
int attr=0;
|
||||
for(attr=0;attr<attrCount;attr++){
|
||||
CToken* theInnerToken= (mTokenizer)? mTokenizer->PeekToken():nsnull;
|
||||
if(theInnerToken) {
|
||||
eHTMLTokenTypes theInnerType=eHTMLTokenTypes(theInnerToken->GetTokenType());
|
||||
if(eToken_attribute==theInnerType){
|
||||
mTokenizer->PopToken(); //pop it for real...
|
||||
theNode.AddAttribute(theInnerToken);
|
||||
}
|
||||
}
|
||||
else return kEOF;
|
||||
}
|
||||
}
|
||||
|
||||
// Pass the ID Attribute atom from the start token to the parser node
|
||||
CStartToken* startToken = NS_STATIC_CAST(CStartToken *, aToken);
|
||||
nsCOMPtr<nsIAtom> IDAttr=nsnull;
|
||||
result = startToken->GetIDAttributeAtom(getter_AddRefs(IDAttr));
|
||||
if (IDAttr && NS_SUCCEEDED(result))
|
||||
result = theNode.SetIDAttributeAtom(IDAttr);
|
||||
|
||||
if(NS_OK==result){
|
||||
if(mSink) {
|
||||
result=mSink->OpenContainer(theNode);
|
||||
if(((CStartToken*)aToken)->IsEmpty()){
|
||||
result=mSink->CloseContainer(theNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when an end token has been
|
||||
* encountered in the parse process.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next (end) token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleEndToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenizer->GetTokenAllocator());
|
||||
result=(mSink)? mSink->CloseContainer(theNode):NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when an error token has been
|
||||
* encountered in the parse process.
|
||||
* FYI: when the document is malformed this is the only
|
||||
* token that will get reported to the content sink.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleErrorToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
nsresult result=NS_OK;
|
||||
|
||||
if(mTokenizer) {
|
||||
// Cycle through the remaining tokens in the token stream and handle them
|
||||
// These tokens were added so that content objects for the error message
|
||||
// are generated by the content sink
|
||||
while (PR_TRUE) {
|
||||
CToken* token = mTokenizer->PopToken();
|
||||
if(token) {
|
||||
eHTMLTokenTypes type = (eHTMLTokenTypes) token->GetTokenType();
|
||||
switch(type) {
|
||||
case eToken_newline:
|
||||
mLineNumber++; //now fall through
|
||||
case eToken_whitespace:
|
||||
case eToken_text:
|
||||
HandleLeafToken(token);
|
||||
break;
|
||||
case eToken_start:
|
||||
HandleStartToken(token);
|
||||
break;
|
||||
case eToken_end:
|
||||
HandleEndToken(token);
|
||||
break;
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
IF_FREE(token, mTokenizer->GetTokenAllocator());
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Propagate the error onto the content sink.
|
||||
CErrorToken *errTok = (CErrorToken *)aToken;
|
||||
const nsParserError* error = errTok->GetError();
|
||||
result=(mSink)? mSink->NotifyError(error):NS_OK;
|
||||
|
||||
// Output the error to the console
|
||||
if (error) {
|
||||
nsCAutoString temp;
|
||||
|
||||
temp.AssignWithConversion(mFilename);
|
||||
|
||||
PR_fprintf(PR_STDOUT, "XML Error in file '%s', ", temp.get());
|
||||
|
||||
PR_fprintf(PR_STDOUT, "Line Number: %d, ", error->lineNumber);
|
||||
PR_fprintf(PR_STDOUT, "Col Number: %d, ", error->colNumber);
|
||||
|
||||
temp.AssignWithConversion(error->description);
|
||||
|
||||
PR_fprintf(PR_STDOUT, "Description: %s\n", temp.get());
|
||||
|
||||
temp.AssignWithConversion(error->sourceLine);
|
||||
|
||||
PR_fprintf(PR_STDOUT, "Source Line: %s\n", temp.get());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a doc. type token has been
|
||||
* encountered in the parse process.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleDocTypeDeclToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenizer->GetTokenAllocator());
|
||||
result = (mSink)? mSink->AddDocTypeDecl(theNode, 0):NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1,271 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
/**
|
||||
* MODULE NOTES:
|
||||
* @update gess 4/8/98
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __NS_WELLFORMED_DTD
|
||||
#define __NS_WELLFORMED_DTD
|
||||
|
||||
#include "nsIDTD.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsHTMLTokens.h"
|
||||
#include "nsIContentSink.h"
|
||||
|
||||
#define NS_WELLFORMED_DTD_IID \
|
||||
{0xa39c6bfd, 0x15f0, 0x11d2, \
|
||||
{0x80, 0x41, 0x0, 0x10, 0x4b, 0x98, 0x3f, 0xd4}}
|
||||
|
||||
|
||||
class nsIDTDDebug;
|
||||
class nsIParserNode;
|
||||
class nsParser;
|
||||
class nsHTMLTokenizer;
|
||||
|
||||
|
||||
class CWellFormedDTD : public nsIDTD
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 4/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
CWellFormedDTD();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 4/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual ~CWellFormedDTD();
|
||||
|
||||
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const;
|
||||
|
||||
/**
|
||||
* Call this method if you want the DTD to construct a clone of itself.
|
||||
* @update gess7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD CreateNewInstance(nsIDTD** aInstancePtrResult);
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can parse
|
||||
* a document in a given source-type.
|
||||
* NOTE: Parsing always assumes that the end result will involve
|
||||
* storing the result in the main content model.
|
||||
* @update gess6/24/98
|
||||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
NS_IMETHOD_(eAutoDetectResult) CanParse(CParserContext& aParserContext,
|
||||
const nsString& aBuffer,
|
||||
PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update rickg 03.20.2000
|
||||
* @param aParserContext
|
||||
* @param aSink
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext,
|
||||
nsIContentSink* aSink);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param aFilename is the name of the file being parsed.
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer,
|
||||
nsITokenObserver* anObserver = nsnull,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param anErrorCode contans the last error that occured
|
||||
* @return error code
|
||||
*/
|
||||
NS_IMETHOD DidBuildModel(nsresult anErrorCode, PRBool aNotifySink,
|
||||
nsIParser* aParser,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aToken -- token object to be put into content model
|
||||
* @return 0 if all is well; non-zero is an error
|
||||
*/
|
||||
NS_IMETHOD HandleToken(CToken* aToken, nsIParser* aParser);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 12/20/99
|
||||
* @param ptr-ref to (out) tokenizer
|
||||
* @return nsresult
|
||||
*/
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD WillResumeParse(void);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD WillInterruptParse(void);
|
||||
|
||||
/**
|
||||
* Set this to TRUE if you want the DTD to verify its
|
||||
* context stack.
|
||||
* @update gess 7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual void SetVerification(PRBool aEnable);
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- int tag of parent container
|
||||
* @param aChild -- int tag of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent, PRInt32 aChild) const;
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag is itself a container
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aTag -- tag to test for containership
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const;
|
||||
|
||||
/**
|
||||
* Retrieve a ptr to the global token recycler...
|
||||
* @update gess8/4/98
|
||||
* @return ptr to recycler (or null)
|
||||
*/
|
||||
NS_IMETHOD_(nsTokenAllocator *) GetTokenAllocator(void);
|
||||
|
||||
/**
|
||||
* Use this id you want to stop the building content model
|
||||
* --------------[ Sets DTD to STOP mode ]----------------
|
||||
* It's recommended to use this method in accordance with
|
||||
* the parser's terminate() method.
|
||||
*
|
||||
* @update harishd 07/22/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD Terminate(nsIParser* aParser = nsnull);
|
||||
|
||||
/**
|
||||
* Give rest of world access to our tag enums, so that CanContain(), etc,
|
||||
* become useful.
|
||||
*/
|
||||
NS_IMETHOD StringTagToIntTag(const nsAReadableString &aTag,
|
||||
PRInt32* aIntTag) const;
|
||||
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const;
|
||||
|
||||
NS_IMETHOD ConvertEntityToUnicode(const nsAReadableString& aEntity,
|
||||
PRInt32* aUnicode) const;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
protected:
|
||||
/*
|
||||
NS_IMETHODIMP ConsumeTag(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeStartTag(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeText(const nsString& aString,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeNewline(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeWhitespace(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeEscapedContent(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeComment(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeEntity(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeAttributes(PRUnichar aChar,nsScanner& aScanner,CStartToken* aToken);
|
||||
*/
|
||||
nsresult HandleStartToken(CToken* aToken);
|
||||
nsresult HandleEndToken(CToken* aToken);
|
||||
nsresult HandleCommentToken(CToken* aToken);
|
||||
nsresult HandleErrorToken(CToken* aToken);
|
||||
nsresult HandleDocTypeDeclToken(CToken* aToken);
|
||||
nsresult HandleLeafToken(CToken* aToken);
|
||||
nsresult HandleProcessingInstructionToken(CToken* aToken);
|
||||
|
||||
nsParser* mParser;
|
||||
nsIContentSink* mSink;
|
||||
nsString mFilename;
|
||||
PRInt32 mLineNumber;
|
||||
nsHTMLTokenizer* mTokenizer;
|
||||
nsresult mDTDState;
|
||||
};
|
||||
|
||||
extern nsresult NS_NewWellFormed_DTD(nsIDTD** aInstancePtrResult);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -285,6 +285,7 @@ typedef struct {
|
|||
const char *m_bufferPtr;
|
||||
/* past last character to be parsed */
|
||||
char *m_bufferEnd;
|
||||
|
||||
/* allocated end of buffer */
|
||||
const char *m_bufferLim;
|
||||
long m_parseEndByteIndex;
|
||||
|
@ -345,6 +346,7 @@ typedef struct {
|
|||
int m_attsSize;
|
||||
int m_nSpecifiedAtts;
|
||||
int m_idAttIndex;
|
||||
int m_blocked;
|
||||
ATTRIBUTE *m_atts;
|
||||
POSITION m_position;
|
||||
STRING_POOL m_tempPool;
|
||||
|
@ -357,6 +359,7 @@ typedef struct {
|
|||
enum XML_ParamEntityParsing m_paramEntityParsing;
|
||||
XML_Parser m_parentParser;
|
||||
#endif
|
||||
const XML_Char* m_mismatch;
|
||||
} Parser;
|
||||
|
||||
#define userData (((Parser *)parser)->m_userData)
|
||||
|
@ -426,12 +429,14 @@ typedef struct {
|
|||
#define attsSize (((Parser *)parser)->m_attsSize)
|
||||
#define nSpecifiedAtts (((Parser *)parser)->m_nSpecifiedAtts)
|
||||
#define idAttIndex (((Parser *)parser)->m_idAttIndex)
|
||||
#define blocked (((Parser *)parser)->m_blocked)
|
||||
#define tempPool (((Parser *)parser)->m_tempPool)
|
||||
#define temp2Pool (((Parser *)parser)->m_temp2Pool)
|
||||
#define groupConnector (((Parser *)parser)->m_groupConnector)
|
||||
#define groupSize (((Parser *)parser)->m_groupSize)
|
||||
#define hadExternalDoctype (((Parser *)parser)->m_hadExternalDoctype)
|
||||
#define namespaceSeparator (((Parser *)parser)->m_namespaceSeparator)
|
||||
#define mismatch (((Parser *)parser)->m_mismatch)
|
||||
#ifdef XML_DTD
|
||||
#define parentParser (((Parser *)parser)->m_parentParser)
|
||||
#define paramEntityParsing (((Parser *)parser)->m_paramEntityParsing)
|
||||
|
@ -526,6 +531,7 @@ XML_Parser XML_ParserCreate(const XML_Char *encodingName)
|
|||
dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE;
|
||||
XmlInitEncoding(&initEncoding, &encoding, 0);
|
||||
internalEncoding = XmlGetInternalEncoding();
|
||||
blocked = 0;
|
||||
return parser;
|
||||
}
|
||||
|
||||
|
@ -737,6 +743,22 @@ int XML_GetIdAttributeIndex(XML_Parser parser)
|
|||
return idAttIndex;
|
||||
}
|
||||
|
||||
void XML_BlockParser(XML_Parser parser)
|
||||
{
|
||||
blocked = 1;
|
||||
}
|
||||
|
||||
void XML_UnblockParser(XML_Parser parser)
|
||||
{
|
||||
blocked = 0;
|
||||
}
|
||||
|
||||
const
|
||||
XML_Char* XML_GetMismatchedTag(XML_Parser parser)
|
||||
{
|
||||
return mismatch;
|
||||
}
|
||||
|
||||
void XML_SetElementHandler(XML_Parser parser,
|
||||
XML_StartElementHandler start,
|
||||
XML_EndElementHandler end)
|
||||
|
@ -866,6 +888,11 @@ int XML_SetParamEntityParsing(XML_Parser parser,
|
|||
|
||||
int XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
|
||||
{
|
||||
if (blocked) {
|
||||
// First unblock parser
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
if (!isFinal)
|
||||
return 1;
|
||||
|
@ -893,7 +920,11 @@ int XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
|
|||
errorCode = processor(parser, s, parseEndPtr = s + len, &end);
|
||||
if (errorCode != XML_ERROR_NONE) {
|
||||
eventEndPtr = eventPtr;
|
||||
processor = errorProcessor;
|
||||
if (blocked) {
|
||||
parseEndPtr = eventEndPtr;
|
||||
parseEndByteIndex -= len - (eventPtr - s); // This is how much we've red thus far
|
||||
XmlUpdatePosition(encoding, positionPtr, eventEndPtr, &position);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
XmlUpdatePosition(encoding, positionPtr, end, &position);
|
||||
|
@ -1372,12 +1403,15 @@ doContent(XML_Parser parser,
|
|||
if (nextPtr)
|
||||
tag->rawName = tag->buf;
|
||||
}
|
||||
*toPtr = XML_T('\0');
|
||||
*toPtr = XML_T('\0');
|
||||
result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings));
|
||||
if (result)
|
||||
return result;
|
||||
startElementHandler(handlerArg, tag->name.str, (const XML_Char **)atts);
|
||||
poolClear(&tempPool);
|
||||
if (blocked) {
|
||||
return XML_ERROR_PARSER_BLOCKED;
|
||||
}
|
||||
}
|
||||
else {
|
||||
tag->name.str = 0;
|
||||
|
@ -1408,12 +1442,19 @@ doContent(XML_Parser parser,
|
|||
if (result)
|
||||
return result;
|
||||
poolFinish(&tempPool);
|
||||
if (startElementHandler)
|
||||
if (startElementHandler) {
|
||||
startElementHandler(handlerArg, name.str, (const XML_Char **)atts);
|
||||
if (blocked) {
|
||||
return XML_ERROR_PARSER_BLOCKED;
|
||||
}
|
||||
}
|
||||
if (endElementHandler) {
|
||||
if (startElementHandler)
|
||||
*eventPP = *eventEndPP;
|
||||
endElementHandler(handlerArg, name.str);
|
||||
if (blocked) {
|
||||
return XML_ERROR_PARSER_BLOCKED;
|
||||
}
|
||||
}
|
||||
poolClear(&tempPool);
|
||||
while (bindings) {
|
||||
|
@ -1446,6 +1487,7 @@ doContent(XML_Parser parser,
|
|||
if (len != tag->rawNameLength
|
||||
|| memcmp(tag->rawName, rawName, len) != 0) {
|
||||
*eventPP = rawName;
|
||||
mismatch = tag->name.str;
|
||||
return XML_ERROR_TAG_MISMATCH;
|
||||
}
|
||||
--tagLevel;
|
||||
|
@ -1457,6 +1499,9 @@ doContent(XML_Parser parser,
|
|||
;
|
||||
}
|
||||
endElementHandler(handlerArg, tag->name.str);
|
||||
if (blocked) {
|
||||
return XML_ERROR_PARSER_BLOCKED;
|
||||
}
|
||||
}
|
||||
else if (defaultHandler)
|
||||
reportDefault(parser, enc, s, next);
|
||||
|
@ -2684,8 +2729,13 @@ doProlog(XML_Parser parser,
|
|||
case XML_ROLE_NONE:
|
||||
switch (tok) {
|
||||
case XML_TOK_PI:
|
||||
if (!reportProcessingInstruction(parser, enc, s, next))
|
||||
return XML_ERROR_NO_MEMORY;
|
||||
if (!reportProcessingInstruction(parser, enc, s, next)) {
|
||||
if (blocked) {
|
||||
eventPtr = next;
|
||||
return XML_ERROR_PARSER_BLOCKED;
|
||||
}
|
||||
return XML_ERROR_NO_MEMORY;
|
||||
}
|
||||
break;
|
||||
case XML_TOK_COMMENT:
|
||||
if (!reportComment(parser, enc, s, next))
|
||||
|
@ -3103,6 +3153,9 @@ reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, const char *
|
|||
normalizeLines(data);
|
||||
processingInstructionHandler(handlerArg, target, data);
|
||||
poolClear(&tempPool);
|
||||
if (blocked) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,11 +72,11 @@ XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
|
|||
/* atts is array of name/value pairs, terminated by 0;
|
||||
names and values are 0 terminated. */
|
||||
|
||||
typedef void (*XML_StartElementHandler)(void *userData,
|
||||
typedef int (*XML_StartElementHandler)(void *userData,
|
||||
const XML_Char *name,
|
||||
const XML_Char **atts);
|
||||
|
||||
typedef void (*XML_EndElementHandler)(void *userData,
|
||||
typedef int (*XML_EndElementHandler)(void *userData,
|
||||
const XML_Char *name);
|
||||
|
||||
/* s is not 0 terminated. */
|
||||
|
@ -85,7 +85,7 @@ typedef void (*XML_CharacterDataHandler)(void *userData,
|
|||
int len);
|
||||
|
||||
/* target and data are 0 terminated */
|
||||
typedef void (*XML_ProcessingInstructionHandler)(void *userData,
|
||||
typedef int (*XML_ProcessingInstructionHandler)(void *userData,
|
||||
const XML_Char *target,
|
||||
const XML_Char *data);
|
||||
|
||||
|
@ -401,6 +401,10 @@ attribute/value pair counts as 2; thus this correspondds to an index
|
|||
into the atts array passed to the XML_StartElementHandler. */
|
||||
int XMLPARSEAPI XML_GetIdAttributeIndex(XML_Parser parser);
|
||||
|
||||
void XMLPARSEAPI XML_BlockParser(XML_Parser parser);
|
||||
void XMLPARSEAPI XML_UnblockParser(XML_Parser parser);
|
||||
|
||||
const XML_Char* XMLPARSEAPI XML_GetMismatchedTag(XML_Parser parser);
|
||||
/* Parses some input. Returns 0 if a fatal error is detected.
|
||||
The last call to XML_Parse must have isFinal true;
|
||||
len may be zero for this call (or any other). */
|
||||
|
@ -483,7 +487,8 @@ enum XML_Error {
|
|||
XML_ERROR_INCORRECT_ENCODING,
|
||||
XML_ERROR_UNCLOSED_CDATA_SECTION,
|
||||
XML_ERROR_EXTERNAL_ENTITY_HANDLING,
|
||||
XML_ERROR_NOT_STANDALONE
|
||||
XML_ERROR_NOT_STANDALONE,
|
||||
XML_ERROR_PARSER_BLOCKED
|
||||
};
|
||||
|
||||
/* If XML_Parse or XML_ParseBuffer have returned 0, then XML_GetErrorCode
|
||||
|
|
|
@ -990,13 +990,6 @@
|
|||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsWellFormedDTD.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsDebugRobot.cpp</PATH>
|
||||
|
@ -1090,7 +1083,7 @@
|
|||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsExpatTokenizer.cpp</PATH>
|
||||
<PATH>nsExpatDriver.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
|
@ -1201,11 +1194,6 @@
|
|||
<PATH>nsHTMLTags.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsWellFormedDTD.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsDebugRobot.cpp</PATH>
|
||||
|
@ -1248,7 +1236,7 @@
|
|||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsExpatTokenizer.cpp</PATH>
|
||||
<PATH>nsExpatDriver.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
|
@ -2238,13 +2226,6 @@
|
|||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsWellFormedDTD.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsDebugRobot.cpp</PATH>
|
||||
|
@ -2331,7 +2312,7 @@
|
|||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsExpatTokenizer.cpp</PATH>
|
||||
<PATH>nsExpatDriver.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
|
@ -2437,11 +2418,6 @@
|
|||
<PATH>nsHTMLTags.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsWellFormedDTD.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsDebugRobot.cpp</PATH>
|
||||
|
@ -2479,7 +2455,7 @@
|
|||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsExpatTokenizer.cpp</PATH>
|
||||
<PATH>nsExpatDriver.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
|
@ -2625,7 +2601,7 @@
|
|||
<FILEREF>
|
||||
<TARGETNAME>htmlparserDebug.shlb</TARGETNAME>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsExpatTokenizer.cpp</PATH>
|
||||
<PATH>nsExpatDriver.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
|
@ -2664,12 +2640,6 @@
|
|||
<PATH>nsHTMLEntities.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<TARGETNAME>htmlparserDebug.shlb</TARGETNAME>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsWellFormedDTD.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<TARGETNAME>htmlparserDebug.shlb</TARGETNAME>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
|
|
|
@ -28,10 +28,13 @@ include $(DEPTH)/config/autoconf.mk
|
|||
|
||||
MODULE = htmlparser
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIExpatSink.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsIContentSink.h \
|
||||
nsITokenizer.h \
|
||||
nsIExpatTokenizer.h \
|
||||
nsIHTMLContentSink.h \
|
||||
nsIHTMLFragmentContentSink.h\
|
||||
nsIParserNode.h \
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..
|
||||
|
||||
MODULE = htmlparser
|
||||
|
||||
EXPORTS = \
|
||||
nsITokenizer.h \
|
||||
nsIExpatTokenizer.h \
|
||||
nsIContentSink.h \
|
||||
nsIHTMLContentSink.h \
|
||||
nsIHTMLFragmentContentSink.h\
|
||||
nsIParserNode.h \
|
||||
nsIParser.h \
|
||||
nsIParserFilter.h \
|
||||
nsIDTD.h \
|
||||
nsIElementObserver.h \
|
||||
nsIParserService.h \
|
||||
nsHTMLTagList.h \
|
||||
nsHTMLTags.h \
|
||||
nsHTMLTokens.h \
|
||||
nsParserError.h \
|
||||
nsParserCIID.h \
|
||||
nsToken.h \
|
||||
!ifdef MOZ_DEBUG
|
||||
nsILoggingSink.h \
|
||||
!endif
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -49,10 +49,8 @@
|
|||
* content-sink model building process. There is another one that you may care
|
||||
* about more, which is the IHTMLContentSink interface. (See that file for details).
|
||||
*/
|
||||
|
||||
#include "nsIParserNode.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsParserError.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIParser;
|
||||
|
||||
|
@ -113,79 +111,6 @@ public:
|
|||
*/
|
||||
NS_IMETHOD SetParser(nsIParser* aParser)=0;
|
||||
|
||||
/**
|
||||
* This method is used to open a generic container in the sink.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a close
|
||||
* container tag has been consumed and needs to be closed.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This method is called by the parser when it encounters
|
||||
* a document type declaration.
|
||||
*
|
||||
* XXX Should the parser also part the internal subset?
|
||||
*
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode)=0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser if it hits an unrecoverable
|
||||
* error (in XML, if the document is not well-formed or valid).
|
||||
*
|
||||
* @param aErrorResult the error code
|
||||
*/
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError)=0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser to notify observers of
|
||||
* the tag
|
||||
*
|
||||
* @param aErrorResult the error code
|
||||
*/
|
||||
NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode)=0;
|
||||
|
||||
/**
|
||||
* Flush all pending notifications so that the content model
|
||||
* is in sync with the state of the sink.
|
||||
|
|
|
@ -89,6 +89,7 @@ public:
|
|||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDTD_IID)
|
||||
|
||||
|
||||
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const = 0;
|
||||
|
||||
/**
|
||||
|
@ -113,13 +114,6 @@ public:
|
|||
const nsString& aBuffer,
|
||||
PRInt32 aVersion) = 0;
|
||||
|
||||
/**
|
||||
* Called by the parser just before the parsing process begins
|
||||
* @update gess5/18/98
|
||||
* @param aFilename--string that contains name of file being parsed
|
||||
* (if applicable)
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext,
|
||||
nsIContentSink* aSink=0) = 0;
|
||||
|
||||
|
@ -156,14 +150,12 @@ public:
|
|||
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser) = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 12/20/99
|
||||
*
|
||||
* @update gess 12/20/99
|
||||
* @param ptr-ref to (out) tokenizer
|
||||
* @return nsresult
|
||||
*/
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer) = 0;
|
||||
|
||||
NS_IMETHOD_(nsTokenAllocator *) GetTokenAllocator(void) = 0;
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer) = 0;
|
||||
|
||||
/**
|
||||
* If the parse process gets interrupted midway, this method is
|
||||
|
@ -171,7 +163,7 @@ public:
|
|||
* @update gess5/18/98
|
||||
* @return ignored
|
||||
*/
|
||||
NS_IMETHOD WillResumeParse(void) = 0;
|
||||
NS_IMETHOD WillResumeParse(nsIContentSink* aSink = 0) = 0;
|
||||
|
||||
/**
|
||||
* If the parse process gets interrupted, this method is called by
|
||||
|
@ -179,7 +171,7 @@ public:
|
|||
* @update gess5/18/98
|
||||
* @return ignored
|
||||
*/
|
||||
NS_IMETHOD WillInterruptParse(void) = 0;
|
||||
NS_IMETHOD WillInterruptParse(nsIContentSink* aSink = 0) = 0;
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag of one
|
||||
|
@ -226,16 +218,36 @@ public:
|
|||
*/
|
||||
NS_IMETHOD StringTagToIntTag(const nsAReadableString &aTag,
|
||||
PRInt32* aIntTag) const = 0;
|
||||
|
||||
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const = 0;
|
||||
|
||||
|
||||
NS_IMETHOD ConvertEntityToUnicode(const nsAReadableString& aEntity,
|
||||
PRInt32* aUnicode) const = 0;
|
||||
|
||||
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const = 0;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const = 0;
|
||||
};
|
||||
|
||||
#define NS_DECL_NSIDTD \
|
||||
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const;\
|
||||
NS_IMETHOD CreateNewInstance(nsIDTD** aInstancePtrResult);\
|
||||
NS_IMETHOD_(eAutoDetectResult) CanParse(CParserContext& aParserContext, const nsString& aBuffer, PRInt32 aVersion);\
|
||||
NS_IMETHOD WillBuildModel( const CParserContext& aParserContext,nsIContentSink* aSink=0);\
|
||||
NS_IMETHOD DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParser* aParser,nsIContentSink* aSink=0);\
|
||||
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITokenObserver* anObserver=0,nsIContentSink* aSink=0);\
|
||||
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser);\
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer);\
|
||||
NS_IMETHOD WillResumeParse(nsIContentSink* aSink = 0);\
|
||||
NS_IMETHOD WillInterruptParse(nsIContentSink* aSink = 0);\
|
||||
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent,PRInt32 aChild) const;\
|
||||
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const;\
|
||||
NS_IMETHOD_(nsresult) Terminate(nsIParser* aParser=nsnull);\
|
||||
NS_IMETHOD StringTagToIntTag(const nsAReadableString &aTag, PRInt32* aIntTag) const ;\
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const ;\
|
||||
NS_IMETHOD ConvertEntityToUnicode(const nsAReadableString& aEntity, PRInt32* aUnicode) const ;\
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,PRInt32 aParentID) const;\
|
||||
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,PRInt32 aParentID) const;
|
||||
#endif /* nsIDTD_h___ */
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(1DEEA160-C661-11d5-84CC-0010A4E0C706)]
|
||||
interface nsIExpatSink : nsISupports
|
||||
{
|
||||
void HandleStartElement([const] in wstring aName,
|
||||
[array, size_is (aAttsCount)] in wstring aAtts,
|
||||
[const] in unsigned long aAttsCount,
|
||||
[const] in unsigned long aIndex,
|
||||
[const] in unsigned long aLineNumber);
|
||||
|
||||
void HandleEndElement([const] in wstring aName);
|
||||
|
||||
void HandleComment([const] in wstring aName);
|
||||
|
||||
void HandleCDataSection([const] in wstring aData,
|
||||
[const] in unsigned long aLength);
|
||||
|
||||
void HandleDoctypeDecl([const] in wstring aDoctype);
|
||||
|
||||
void HandleCharacterData([const] in wstring aData,
|
||||
[const] in unsigned long aLength);
|
||||
|
||||
void HandleProcessingInstruction([const] in wstring aTarget,
|
||||
[const] in wstring aData);
|
||||
|
||||
void ReportError([const] in wstring aErrorText,
|
||||
[const] in wstring aSourceText);
|
||||
};
|
|
@ -271,6 +271,71 @@ public:
|
|||
*/
|
||||
NS_IMETHOD DidProcessAToken(void)=0;
|
||||
|
||||
/**
|
||||
* This method is used to open a generic container in the sink.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a close
|
||||
* container tag has been consumed and needs to be closed.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @update 4/1/98 gess
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode) = 0;
|
||||
|
||||
/**
|
||||
* This method is called by the parser when it encounters
|
||||
* a document type declaration.
|
||||
*
|
||||
* XXX Should the parser also part the internal subset?
|
||||
*
|
||||
* @param nsIParserNode reference to parser node interface
|
||||
*/
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode)=0;
|
||||
|
||||
/**
|
||||
* This gets called by the parser to notify observers of
|
||||
* the tag
|
||||
*
|
||||
* @param aErrorResult the error code
|
||||
*/
|
||||
NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode)=0;
|
||||
|
||||
};
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
|
|
|
@ -70,26 +70,38 @@ public:
|
|||
Notes:
|
||||
***************************************************************/
|
||||
|
||||
|
||||
class nsITokenizer : public nsISupports {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITOKENIZER_IID)
|
||||
|
||||
virtual nsresult WillTokenize(PRBool aIsFinalChunk,nsTokenAllocator* aTokenAllocator)=0;
|
||||
virtual nsresult ConsumeToken(nsScanner& aScanner,PRBool& aFlushTokens)=0;
|
||||
virtual nsresult DidTokenize(PRBool aIsFinalChunk)=0;
|
||||
virtual nsTokenAllocator* GetTokenAllocator(void)=0;
|
||||
|
||||
virtual CToken* PushTokenFront(CToken* aToken)=0;
|
||||
virtual CToken* PushToken(CToken* aToken)=0;
|
||||
virtual CToken* PopToken(void)=0;
|
||||
virtual CToken* PeekToken(void)=0;
|
||||
virtual PRInt32 GetCount(void)=0;
|
||||
virtual CToken* GetTokenAt(PRInt32 anIndex)=0;
|
||||
|
||||
virtual void PrependTokens(nsDeque& aDeque)=0;
|
||||
NS_IMETHOD WillTokenize(PRBool aIsFinalChunk,nsTokenAllocator* aTokenAllocator)=0;
|
||||
NS_IMETHOD ConsumeToken(nsScanner& aScanner,PRBool& aFlushTokens)=0;
|
||||
NS_IMETHOD DidTokenize(PRBool aIsFinalChunk)=0;
|
||||
|
||||
NS_IMETHOD_(CToken*) PushTokenFront(CToken* aToken)=0;
|
||||
NS_IMETHOD_(CToken*) PushToken(CToken* aToken)=0;
|
||||
NS_IMETHOD_(CToken*) PopToken(void)=0;
|
||||
NS_IMETHOD_(CToken*) PeekToken(void)=0;
|
||||
NS_IMETHOD_(CToken*) GetTokenAt(PRInt32 anIndex)=0;
|
||||
NS_IMETHOD_(PRInt32) GetCount(void)=0;
|
||||
NS_IMETHOD_(nsTokenAllocator*) GetTokenAllocator(void)=0;
|
||||
NS_IMETHOD_(void) PrependTokens(nsDeque& aDeque)=0;
|
||||
|
||||
};
|
||||
|
||||
#define NS_DECL_NSITOKENIZER \
|
||||
NS_IMETHOD WillTokenize(PRBool aIsFinalChunk,nsTokenAllocator* aTokenAllocator);\
|
||||
NS_IMETHOD ConsumeToken(nsScanner& aScanner,PRBool& aFlushTokens);\
|
||||
NS_IMETHOD DidTokenize(PRBool aIsFinalChunk);\
|
||||
NS_IMETHOD_(CToken*) PushTokenFront(CToken* aToken);\
|
||||
NS_IMETHOD_(CToken*) PushToken(CToken* aToken);\
|
||||
NS_IMETHOD_(CToken*) PopToken(void);\
|
||||
NS_IMETHOD_(CToken*) PeekToken(void);\
|
||||
NS_IMETHOD_(CToken*) GetTokenAt(PRInt32 anIndex);\
|
||||
NS_IMETHOD_(PRInt32) GetCount(void);\
|
||||
NS_IMETHOD_(nsTokenAllocator*) GetTokenAllocator(void);\
|
||||
NS_IMETHOD_(void) PrependTokens(nsDeque& aDeque);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -53,10 +53,6 @@
|
|||
{0x9039c670, 0x2717, 0x11d2, \
|
||||
{0x92, 0x46, 0x00, 0x80, 0x5f, 0x8a, 0x7a, 0xb6}}
|
||||
|
||||
// {E6FD9941-899D-11d2-8EAE-00805F29F370}
|
||||
#define NS_WELLFORMEDDTD_CID \
|
||||
{ 0xe6fd9941, 0x899d, 0x11d2, { 0x8e, 0xae, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
// {a6cf9107-15b3-11d2-932e-00805f8add32}
|
||||
#define NS_CNAVDTD_CID \
|
||||
{ 0xa6cf9107, 0x15b3, 0x11d2, { 0x93, 0x2e, 0x0, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
|
||||
|
@ -81,7 +77,9 @@
|
|||
#define NS_VIEWSOURCE_DTD_CID \
|
||||
{ 0x8323fad0, 0x2102, 0x11d4, { 0x81, 0x42, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
|
||||
|
||||
// {FFF4FBE9-528A-4b37-819D-FC18F3A401A7}
|
||||
#define NS_EXPAT_DRIVER_CID \
|
||||
{ 0xfff4fbe9, 0x528a, 0x4b37, { 0x81, 0x9d, 0xfc, 0x18, 0xf3, 0xa4, 0x1, 0xa7 } }
|
||||
|
||||
// {a6cf910f-15b3-11d2-932e-00805f8add32}
|
||||
#define NS_HTMLCONTENTSINKSTREAM_CID \
|
||||
|
|
|
@ -92,7 +92,6 @@ public:
|
|||
NS_IMETHOD GetPref(PRInt32 aTag,PRBool& aPref) { return NS_OK; }
|
||||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError);
|
||||
NS_IMETHOD CloseTopmostContainer();
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
||||
|
@ -291,11 +290,6 @@ NS_IMETHODIMP RobotSink::AddLeaf(const nsIParserNode& aNode)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP RobotSink::NotifyError(const nsParserError* aError)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets called by the parsing system when we find a comment
|
||||
* @update gess11/9/98
|
||||
|
|
|
@ -674,6 +674,12 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse
|
|||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
CNavDTD::Terminate(nsIParser* aParser)
|
||||
{
|
||||
return mDTDState=NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
}
|
||||
|
||||
/**
|
||||
* --- Backwards compatibility ---
|
||||
* Use this method to determine if the tag in question needs a BODY.
|
||||
|
@ -3921,7 +3927,8 @@ nsresult CNavDTD::CreateContextStackFor(eHTMLTags aChildTag){
|
|||
* @param none
|
||||
* @return ptr to tokenizer
|
||||
*/
|
||||
nsresult CNavDTD::GetTokenizer(nsITokenizer*& aTokenizer) {
|
||||
NS_IMETHODIMP
|
||||
CNavDTD::GetTokenizer(nsITokenizer*& aTokenizer) {
|
||||
nsresult result=NS_OK;
|
||||
if(!mTokenizer) {
|
||||
result=NS_NewHTMLTokenizer(&mTokenizer,mDTDMode,mDocType,mParserCommand);
|
||||
|
@ -3930,37 +3937,18 @@ nsresult CNavDTD::GetTokenizer(nsITokenizer*& aTokenizer) {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess8/4/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHODIMP_(nsTokenAllocator *)
|
||||
CNavDTD::GetTokenAllocator(void)
|
||||
{
|
||||
if(!mTokenAllocator) {
|
||||
nsresult result=GetTokenizer(mTokenizer);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
mTokenAllocator=mTokenizer->GetTokenAllocator();
|
||||
}
|
||||
}
|
||||
return mTokenAllocator;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult CNavDTD::WillResumeParse(void){
|
||||
nsresult CNavDTD::WillResumeParse(nsIContentSink* aSink){
|
||||
|
||||
STOP_TIMER();
|
||||
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillResumeParse(), this=%p\n", this));
|
||||
|
||||
nsresult result=(mSink) ? mSink->WillResume() : NS_OK;
|
||||
nsresult result=(aSink) ? aSink->WillResume() : NS_OK;
|
||||
|
||||
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::WillResumeParse(), this=%p\n", this));
|
||||
START_TIMER();
|
||||
|
@ -3974,12 +3962,12 @@ nsresult CNavDTD::WillResumeParse(void){
|
|||
* @update gess5/18/98
|
||||
* @return error code
|
||||
*/
|
||||
nsresult CNavDTD::WillInterruptParse(void){
|
||||
nsresult CNavDTD::WillInterruptParse(nsIContentSink* aSink){
|
||||
|
||||
STOP_TIMER();
|
||||
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillInterruptParse(), this=%p\n", this));
|
||||
|
||||
nsresult result=(mSink) ? mSink->WillInterrupt() : NS_OK;
|
||||
nsresult result=(aSink) ? aSink->WillInterrupt() : NS_OK;
|
||||
|
||||
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::WillInterruptParse(), this=%p\n", this));
|
||||
START_TIMER();
|
||||
|
|
|
@ -126,7 +126,8 @@ class CNavDTD : public nsIDTD
|
|||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIDTD
|
||||
|
||||
/**
|
||||
* Common constructor for navdtd. You probably want to call
|
||||
* NS_NewNavHTMLDTD().
|
||||
|
@ -134,115 +135,8 @@ public:
|
|||
* @update gess 7/9/98
|
||||
*/
|
||||
CNavDTD();
|
||||
|
||||
/**
|
||||
* Virtual destructor -- you know what to do
|
||||
* @update gess 7/9/98
|
||||
*/
|
||||
virtual ~CNavDTD();
|
||||
|
||||
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const;
|
||||
|
||||
/**
|
||||
* Call this method if you want the DTD to construct a clone of itself.
|
||||
* @update gess7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD CreateNewInstance(nsIDTD** aInstancePtrResult);
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can parse
|
||||
* a document of a given source-type.
|
||||
* Note that parsing assumes that the end result will always be stored
|
||||
* in the main content model. Of course, it's up to you which content-
|
||||
* model you pass in to the parser, so you can always control the process.
|
||||
*
|
||||
* @update gess 7/15/98
|
||||
* @param aContentType contains the name of a filetype that you are
|
||||
* being asked to parse).
|
||||
* @return TRUE if this DTD parse the given type; FALSE otherwise.
|
||||
*/
|
||||
NS_IMETHOD_(eAutoDetectResult) CanParse(CParserContext& aParserContext,
|
||||
const nsString& aBuffer,
|
||||
PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update rickg 03.20.2000
|
||||
* @param aParserContext
|
||||
* @param aSink
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext,
|
||||
nsIContentSink* aSink);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param aFilename is the name of the file being parsed.
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer,
|
||||
nsITokenObserver* anObserver = nsnull,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param anErrorCode contans the last error that occured
|
||||
* @return error code
|
||||
*/
|
||||
NS_IMETHOD DidBuildModel(nsresult anErrorCode, PRBool aNotifySink,
|
||||
nsIParser* aParser,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
* This method is called by the parser, once for each token
|
||||
* that has been constructed during the tokenization phase.
|
||||
* @update gess 3/25/98
|
||||
* @param aToken -- token object to be put into content model
|
||||
* @return 0 if all is well; non-zero is an error
|
||||
*/
|
||||
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/28/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/28/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD_(nsTokenAllocator *) GetTokenAllocator(void);
|
||||
|
||||
/**
|
||||
* If the parse process gets interrupted, this method gets called
|
||||
* prior to the process resuming.
|
||||
* @update gess5/18/98
|
||||
* @return error code -- usually NS_OK (0)
|
||||
*/
|
||||
NS_IMETHOD WillResumeParse(void);
|
||||
|
||||
/**
|
||||
* If the parse process is about to be interrupted, this method
|
||||
* will be called just prior.
|
||||
* @update gess5/18/98
|
||||
* @return error code -- usually NS_OK (0)
|
||||
*/
|
||||
NS_IMETHOD WillInterruptParse(void);
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
|
@ -253,19 +147,9 @@ public:
|
|||
* @param aChild -- int tag of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent,PRInt32 aChild) const;
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- int tag of parent container
|
||||
* @param aChild -- int tag of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) CanPropagate(eHTMLTags aParent, eHTMLTags aChild,
|
||||
PRBool aParentContains) ;
|
||||
virtual PRBool CanPropagate(eHTMLTags aParent,
|
||||
eHTMLTags aChild,
|
||||
PRBool aParentContains) ;
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
|
@ -277,18 +161,9 @@ public:
|
|||
* @param aParentContains -- can be 0,1,-1 (false,true, unknown)
|
||||
* @return PR_TRUE if given tag can be omitted
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) CanOmit(eHTMLTags aParent, eHTMLTags aChild,
|
||||
PRBool& aParentContains);
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag is itself a container
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aTag -- tag to test for containership
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const;
|
||||
virtual PRBool CanOmit(eHTMLTags aParent,
|
||||
eHTMLTags aChild,
|
||||
PRBool& aParentContains);
|
||||
|
||||
/**
|
||||
* This method tries to design a context map (without actually
|
||||
|
@ -300,9 +175,9 @@ public:
|
|||
* @param aChild -- tag type of child
|
||||
* @return True if closure was achieved -- other false
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) ForwardPropagate(nsString& aSequence,
|
||||
eHTMLTags aParentTag,
|
||||
eHTMLTags aChildTag);
|
||||
virtual PRBool ForwardPropagate(nsString& aSequence,
|
||||
eHTMLTags aParentTag,
|
||||
eHTMLTags aChildTag);
|
||||
|
||||
/**
|
||||
* This method tries to design a context map (without actually
|
||||
|
@ -313,9 +188,9 @@ public:
|
|||
* @param aChild -- tag type of child
|
||||
* @return True if closure was achieved -- other false
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) BackwardPropagate(nsString& aSequence,
|
||||
eHTMLTags aParentTag,
|
||||
eHTMLTags aChildTag) const;
|
||||
virtual PRBool BackwardPropagate(nsString& aSequence,
|
||||
eHTMLTags aParentTag,
|
||||
eHTMLTags aChildTag) const;
|
||||
|
||||
/**
|
||||
* Attempt forward and/or backward propagation for the given
|
||||
|
@ -367,40 +242,6 @@ public:
|
|||
*/
|
||||
virtual PRInt32 LastOf(eHTMLTags aTagSet[],PRInt32 aCount) const;
|
||||
|
||||
/**
|
||||
* Use this id you want to stop the building content model
|
||||
* --------------[ Sets DTD to STOP mode ]----------------
|
||||
* It's recommended to use this method in accordance with
|
||||
* the parser's terminate() method.
|
||||
*
|
||||
* @update harishd 07/22/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD Terminate(nsIParser* aParser = nsnull)
|
||||
{
|
||||
mDTDState = NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
|
||||
return mDTDState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give rest of world access to our tag enums, so that CanContain(), etc,
|
||||
* become useful.
|
||||
*/
|
||||
NS_IMETHOD StringTagToIntTag(const nsAReadableString &aTag,
|
||||
PRInt32* aIntTag) const;
|
||||
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const;
|
||||
|
||||
NS_IMETHOD ConvertEntityToUnicode(const nsAReadableString& aEntity,
|
||||
PRInt32* aUnicode) const;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const;
|
||||
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const;
|
||||
|
||||
/**
|
||||
* The following set of methods are used to partially construct
|
||||
* the content model (via the sink) according to the type of token.
|
||||
|
@ -489,7 +330,6 @@ public:
|
|||
|
||||
nsresult DoFragment(PRBool aFlag);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
nsresult CollectAttributes(nsIParserNode& aNode,eHTMLTags aTag,PRInt32 aCount);
|
||||
|
@ -502,27 +342,32 @@ protected:
|
|||
|
||||
nsDeque mMisplacedContent;
|
||||
nsDeque mSkippedContent;
|
||||
|
||||
nsIHTMLContentSink* mSink;
|
||||
nsTokenAllocator* mTokenAllocator;
|
||||
nsDTDContext* mBodyContext;
|
||||
nsDTDContext* mTempContext;
|
||||
PRInt32 mOpenHeadCount;
|
||||
PRInt32 mOpenMapCount;
|
||||
PRInt32 mOpenFormCount;
|
||||
nsParser* mParser;
|
||||
nsITokenizer* mTokenizer;
|
||||
|
||||
nsString mFilename;
|
||||
nsString mScratch; //used for various purposes; non-persistent
|
||||
nsAutoString mMimeType; //ok as an autostring; these are short.
|
||||
|
||||
nsNodeAllocator mNodeAllocator;
|
||||
nsDTDMode mDTDMode;
|
||||
eParserDocType mDocType;
|
||||
eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors...
|
||||
|
||||
eHTMLTags mSkipTarget;
|
||||
nsresult mDTDState;
|
||||
PRUint16 mFlags;
|
||||
PRInt32 mLineNumber;
|
||||
nsString mScratch; //used for various purposes; non-persistent
|
||||
nsAutoString mMimeType; //ok as an autostring; these are short.
|
||||
nsNodeAllocator mNodeAllocator;
|
||||
nsString mFilename;
|
||||
|
||||
PRInt32 mOpenHeadCount;
|
||||
PRInt32 mOpenMapCount;
|
||||
PRInt32 mOpenFormCount;
|
||||
|
||||
PRUint16 mFlags;
|
||||
|
||||
#ifdef ENABLE_CRC
|
||||
PRUint32 mComputedCRC32;
|
||||
PRUint32 mExpectedCRC32;
|
||||
|
@ -533,7 +378,7 @@ inline nsresult NS_NewNavHTMLDTD(nsIDTD** aInstancePtrResult)
|
|||
{
|
||||
NS_DEFINE_CID(kNavDTDCID, NS_CNAVDTD_CID);
|
||||
return nsComponentManager::CreateInstance(kNavDTDCID,
|
||||
nsnull,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIDTD),
|
||||
(void**)aInstancePtrResult);
|
||||
}
|
||||
|
|
|
@ -485,6 +485,12 @@ nsresult COtherDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIPar
|
|||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
COtherDTD::Terminate(nsIParser* aParser)
|
||||
{
|
||||
return mDTDState=NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
}
|
||||
|
||||
/**
|
||||
* This big dispatch method is used to route token handler calls to the right place.
|
||||
* What's wrong with it? This table, and the dispatch methods themselves need to be
|
||||
|
@ -995,12 +1001,12 @@ nsresult COtherDTD::GetTokenizer(nsITokenizer*& aTokenizer) {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult COtherDTD::WillResumeParse(void) {
|
||||
nsresult COtherDTD::WillResumeParse(nsIContentSink* aSink) {
|
||||
|
||||
STOP_TIMER();
|
||||
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: COtherDTD::WillResumeParse(), this=%p\n", this));
|
||||
|
||||
nsresult result=(mSink) ? mSink->WillResume() : NS_OK;
|
||||
nsresult result=(aSink) ? aSink->WillResume() : NS_OK;
|
||||
|
||||
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: COtherDTD::WillResumeParse(), this=%p\n", this));
|
||||
START_TIMER();
|
||||
|
@ -1014,12 +1020,12 @@ nsresult COtherDTD::WillResumeParse(void) {
|
|||
* @update gess5/18/98
|
||||
* @return error code
|
||||
*/
|
||||
nsresult COtherDTD::WillInterruptParse(void){
|
||||
nsresult COtherDTD::WillInterruptParse(nsIContentSink* aSink){
|
||||
|
||||
STOP_TIMER();
|
||||
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: COtherDTD::WillInterruptParse(), this=%p\n", this));
|
||||
|
||||
nsresult result=(mSink) ? mSink->WillInterrupt() : NS_OK;
|
||||
nsresult result=(aSink) ? aSink->WillInterrupt() : NS_OK;
|
||||
|
||||
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: COtherDTD::WillInterruptParse(), this=%p\n", this));
|
||||
START_TIMER();
|
||||
|
|
|
@ -122,7 +122,10 @@ class COtherDTD : public nsIDTD
|
|||
#pragma warning( default : 4275 )
|
||||
#endif
|
||||
|
||||
public:
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDTD
|
||||
|
||||
/**
|
||||
* Common constructor for navdtd. You probably want to call
|
||||
* NS_NewNavHTMLDTD().
|
||||
|
@ -137,171 +140,6 @@ public:
|
|||
*/
|
||||
virtual ~COtherDTD();
|
||||
|
||||
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const;
|
||||
|
||||
/**
|
||||
* Call this method if you want the DTD to construct a clone of itself.
|
||||
* @update gess7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD CreateNewInstance(nsIDTD** aInstancePtrResult);
|
||||
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can parse
|
||||
* a document of a given source-type.
|
||||
* Note that parsing assumes that the end result will always be stored
|
||||
* in the main content model. Of course, it's up to you which content-
|
||||
* model you pass in to the parser, so you can always control the process.
|
||||
*
|
||||
* @update gess 7/15/98
|
||||
* @param aContentType contains the name of a filetype that you are
|
||||
* being asked to parse).
|
||||
* @return TRUE if this DTD parse the given type; FALSE otherwise.
|
||||
*/
|
||||
NS_IMETHOD_(eAutoDetectResult) CanParse(CParserContext& aParserContext,
|
||||
const nsString& aBuffer,
|
||||
PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update rickg 03.20.2000
|
||||
* @param aParserContext
|
||||
* @param aSink
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext,
|
||||
nsIContentSink* aSink);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param aFilename is the name of the file being parsed.
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer,
|
||||
nsITokenObserver* anObserver = nsnull,
|
||||
nsIContentSink* aSink=nsnull);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param anErrorCode contans the last error that occured
|
||||
* @return error code
|
||||
*/
|
||||
NS_IMETHOD DidBuildModel(nsresult anErrorCode, PRBool aNotifySink,
|
||||
nsIParser* aParser,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
* This method is called by the parser, once for each token
|
||||
* that has been constructed during the tokenization phase.
|
||||
* @update gess 3/25/98
|
||||
* @param aToken -- token object to be put into content model
|
||||
* @return 0 if all is well; non-zero is an error
|
||||
*/
|
||||
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/28/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer);
|
||||
|
||||
/**
|
||||
* Note that the otherDTD get's it's recycler from
|
||||
* the body context.
|
||||
*
|
||||
* @update rickg 16June2000
|
||||
* @return always 0
|
||||
*/
|
||||
NS_IMETHOD_(nsTokenAllocator *) GetTokenAllocator(void)
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the parse process gets interrupted, this method gets called
|
||||
* prior to the process resuming.
|
||||
* @update gess5/18/98
|
||||
* @return error code -- usually NS_OK (0)
|
||||
*/
|
||||
NS_IMETHOD WillResumeParse(void);
|
||||
|
||||
/**
|
||||
* If the parse process is about to be interrupted, this method
|
||||
* will be called just prior.
|
||||
* @update gess5/18/98
|
||||
* @return error code -- usually NS_OK (0)
|
||||
*/
|
||||
NS_IMETHOD WillInterruptParse(void);
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- int tag of parent container
|
||||
* @param aChild -- int tag of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent,PRInt32 aChild) const;
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag is itself a container
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aTag -- tag to test for containership
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const;
|
||||
|
||||
/**
|
||||
* Use this id you want to stop the building content model
|
||||
* --------------[ Sets DTD to STOP mode ]----------------
|
||||
* It's recommended to use this method in accordance with
|
||||
* the parser's terminate() method.
|
||||
*
|
||||
* @update harishd 07/22/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD Terminate(nsIParser* aParser = nsnull)
|
||||
{
|
||||
mDTDState=NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
|
||||
return mDTDState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give rest of world access to our tag enums, so that CanContain(), etc,
|
||||
* become useful.
|
||||
*/
|
||||
NS_IMETHOD StringTagToIntTag(const nsAReadableString &aTag,
|
||||
PRInt32* aIntTag) const;
|
||||
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const;
|
||||
|
||||
NS_IMETHOD ConvertEntityToUnicode(const nsAReadableString& aEntity,
|
||||
PRInt32* aUnicode) const;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const;
|
||||
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const;
|
||||
|
||||
/**
|
||||
* The following set of methods are used to partially construct
|
||||
* the content model (via the sink) according to the type of token.
|
||||
|
|
|
@ -84,11 +84,11 @@ public:
|
|||
nsIDTD* mDTD;
|
||||
nsIDTD* mValidator;
|
||||
nsIRequestObserver* mListener;
|
||||
|
||||
char* mTransferBuffer;
|
||||
void* mKey;
|
||||
CParserContext* mPrevContext;
|
||||
nsScanner* mScanner;
|
||||
|
||||
nsAutoString mMimeType;
|
||||
nsDTDMode mDTDMode;
|
||||
|
||||
|
|
|
@ -58,8 +58,8 @@ endif
|
|||
CPPSRCS = \
|
||||
nsDTDUtils.cpp \
|
||||
nsHTMLTokenizer.cpp \
|
||||
nsExpatTokenizer.cpp\
|
||||
nsElementTable.cpp \
|
||||
nsExpatDriver.cpp \
|
||||
CNavDTD.cpp \
|
||||
COtherDTD.cpp \
|
||||
nsHTMLEntities.cpp \
|
||||
|
@ -72,7 +72,6 @@ CPPSRCS = \
|
|||
nsParserNode.cpp \
|
||||
nsScanner.cpp \
|
||||
nsToken.cpp \
|
||||
nsWellFormedDTD.cpp \
|
||||
nsViewSourceHTML.cpp\
|
||||
nsParserMsgUtils.cpp\
|
||||
$(NULL)
|
||||
|
|
|
@ -40,13 +40,13 @@ include <$(DEPTH)\config\config.mak>
|
|||
LIBRARY_NAME=raptorhtmlpars
|
||||
DEFINES=-D_IMPL_NS_HTMLPARS -DWIN32_LEAN_AND_MEAN -DXML_DTD
|
||||
|
||||
LIBRARY_NAME = gkparser
|
||||
MODULE_NAME = nsParserModule
|
||||
LIBRARY_NAME = gkparser
|
||||
MODULE_NAME = nsParserModule
|
||||
|
||||
CPP_OBJS = \
|
||||
CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsDTDUtils.obj \
|
||||
.\$(OBJDIR)\nsHTMLTokenizer.obj \
|
||||
.\$(OBJDIR)\nsExpatTokenizer.obj\
|
||||
.\$(OBJDIR)\nsExpatDriver.obj \
|
||||
.\$(OBJDIR)\nsElementTable.obj \
|
||||
.\$(OBJDIR)\CNavDTD.obj \
|
||||
.\$(OBJDIR)\COtherDTD.obj \
|
||||
|
@ -58,11 +58,10 @@ CPP_OBJS = \
|
|||
.\$(OBJDIR)\nsParserNode.obj \
|
||||
.\$(OBJDIR)\nsScanner.obj \
|
||||
.\$(OBJDIR)\nsToken.obj \
|
||||
.\$(OBJDIR)\nsWellFormedDTD.obj \
|
||||
.\$(OBJDIR)\nsViewSourceHTML.obj\
|
||||
.\$(OBJDIR)\nsParserService.obj \
|
||||
.\$(OBJDIR)\nsParserService.obj \
|
||||
.\$(OBJDIR)\nsParserModule.obj \
|
||||
.\$(OBJDIR)\nsParserMsgUtils.obj \
|
||||
.\$(OBJDIR)\nsParserMsgUtils.obj\
|
||||
!ifdef MOZ_DEBUG
|
||||
.\$(OBJDIR)\nsLoggingSink.obj \
|
||||
.\$(OBJDIR)\nsHTMLNullSink.obj \
|
||||
|
|
|
@ -0,0 +1,947 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsExpatDriver.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "CParserContext.h"
|
||||
#include "nsIExpatSink.h"
|
||||
#include "nsIContentSink.h"
|
||||
#include "nsParserMsgUtils.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIUnicharInputStream.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "prprf.h"
|
||||
#include "prmem.h"
|
||||
#include "nsTextFormatter.h"
|
||||
|
||||
static const char* kDTDDirectory = "dtd/";
|
||||
|
||||
/***************************** EXPAT CALL BACKS *******************************/
|
||||
|
||||
// The callback handlers that get called from the expat parser
|
||||
static int
|
||||
Driver_HandleStartElement(void *aUserData,
|
||||
const XML_Char *aName,
|
||||
const XML_Char **aAtts)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
return NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleStartElement((const PRUnichar*)aName,
|
||||
(const PRUnichar**)aAtts);
|
||||
}
|
||||
return XML_ERROR_NONE;
|
||||
}
|
||||
|
||||
static int
|
||||
Driver_HandleEndElement(void *aUserData,
|
||||
const XML_Char *aName)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
return NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleEndElement((const PRUnichar*)aName);
|
||||
}
|
||||
return XML_ERROR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleCharacterData(void *aUserData,
|
||||
const XML_Char *aData,
|
||||
int aLength)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleCharacterData((PRUnichar*)aData,
|
||||
PRUint32(aLength));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleComment(void *aUserData,
|
||||
const XML_Char *aName)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if(aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleComment((const PRUnichar*)aName);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
Driver_HandleProcessingInstruction(void *aUserData,
|
||||
const XML_Char *aTarget,
|
||||
const XML_Char *aData)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
return NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleProcessingInstruction((const PRUnichar*)aTarget,
|
||||
(const PRUnichar*)aData);
|
||||
}
|
||||
return XML_ERROR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleDefault(void *aUserData,
|
||||
const XML_Char *aData,
|
||||
int aLength)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleDefault((const PRUnichar*)aData,
|
||||
PRUint32(aLength));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleStartCdataSection(void *aUserData)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleStartCdataSection();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleEndCdataSection(void *aUserData)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleEndCdataSection();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleStartDoctypeDecl(void *aUserData,
|
||||
const XML_Char *aDoctypeName)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleStartDoctypeDecl();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Driver_HandleEndDoctypeDecl(void *aUserData)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
NS_STATIC_CAST(nsExpatDriver*,aUserData)->HandleEndDoctypeDecl();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
Driver_HandleExternalEntityRef(XML_Parser parser,
|
||||
const XML_Char *openEntityNames,
|
||||
const XML_Char *base,
|
||||
const XML_Char *systemId,
|
||||
const XML_Char *publicId)
|
||||
{
|
||||
int result = PR_TRUE;
|
||||
|
||||
#ifdef XML_DTD
|
||||
|
||||
// Load the external entity into a buffer
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
nsAutoString absURL;
|
||||
|
||||
nsresult rv = nsExpatDriver::OpenInputStream(systemId, base, getter_AddRefs(in), absURL);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIUnicharInputStream> uniIn;
|
||||
|
||||
NS_NewUTF8ConverterStream(getter_AddRefs(uniIn), in, 1024);
|
||||
|
||||
if (uniIn) {
|
||||
XML_Parser entParser =
|
||||
XML_ExternalEntityParserCreate(parser, 0, (const XML_Char*) NS_LITERAL_STRING("UTF-16").get());
|
||||
|
||||
if (entParser) {
|
||||
PRUint32 readCount = 0;
|
||||
PRUnichar tmpBuff[1024] = {0};
|
||||
PRUnichar *uniBuf = tmpBuff;
|
||||
|
||||
XML_SetBase(entParser, (const XML_Char*) absURL.get());
|
||||
|
||||
while (NS_SUCCEEDED(uniIn->Read(uniBuf, 0, 1024, &readCount))) {
|
||||
if (readCount) {
|
||||
// Pass the buffer to expat for parsing
|
||||
result = XML_Parse(entParser, (char *)uniBuf, readCount * sizeof(PRUnichar), 0);
|
||||
}
|
||||
else {
|
||||
// done reading
|
||||
result = XML_Parse(entParser, nsnull, 0, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
XML_ParserFree(entParser);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* ! XML_DTD */
|
||||
NS_NOTYETIMPLEMENTED("Error: Tokenizer_HandleExternalEntityRef() not yet implemented.");
|
||||
#endif /* XML_DTD */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/***************************** END CALL BACKS *********************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsExpatDriver,
|
||||
nsITokenizer,
|
||||
nsIDTD);
|
||||
|
||||
nsresult
|
||||
NS_NewExpatDriver(nsIDTD** aResult) {
|
||||
nsExpatDriver* driver = nsnull;
|
||||
NS_NEWXPCOM(driver, nsExpatDriver);
|
||||
NS_ENSURE_TRUE(driver,NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
return driver->QueryInterface(NS_GET_IID(nsIDTD), (void**)aResult);
|
||||
}
|
||||
|
||||
nsExpatDriver::nsExpatDriver()
|
||||
:mExpatParser(0),
|
||||
mSink(0),
|
||||
mInDoctype(0),
|
||||
mInCData(0),
|
||||
mBytesParsed(0),
|
||||
mBytePosition(0),
|
||||
mInternalState(NS_OK)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsExpatDriver::~nsExpatDriver()
|
||||
{
|
||||
NS_IF_RELEASE(mSink);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleStartElement(const PRUnichar *aValue,
|
||||
const PRUnichar **aAtts)
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
if (mSink){
|
||||
nsresult result = mSink->HandleStartElement(aValue, aAtts,
|
||||
XML_GetSpecifiedAttributeCount(mExpatParser) / 2,
|
||||
XML_GetIdAttributeIndex(mExpatParser),
|
||||
XML_GetCurrentLineNumber(mExpatParser));
|
||||
|
||||
if (result == NS_ERROR_HTMLPARSER_BLOCK) {
|
||||
mInternalState = NS_ERROR_HTMLPARSER_BLOCK;
|
||||
XML_BlockParser(mExpatParser);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleEndElement(const PRUnichar *aValue)
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
if (mSink){
|
||||
nsresult result = mSink->HandleEndElement(aValue);
|
||||
if (result == NS_ERROR_HTMLPARSER_BLOCK) {
|
||||
mInternalState = NS_ERROR_HTMLPARSER_BLOCK;
|
||||
XML_BlockParser(mExpatParser);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleCharacterData(const PRUnichar *aValue,
|
||||
const PRUint32 aLength)
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
if (mInCData) {
|
||||
mCDataText.Append(aValue,aLength);
|
||||
}
|
||||
else if (mSink){
|
||||
mInternalState = mSink->HandleCharacterData(aValue, aLength);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleComment(const PRUnichar *aValue)
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
if (mInDoctype) {
|
||||
// We do not want comments popping out of the doctype...
|
||||
mDoctypeText.Append(NS_LITERAL_STRING("<!--"));
|
||||
mDoctypeText.Append(aValue);
|
||||
mDoctypeText.Append(NS_LITERAL_STRING("-->"));
|
||||
}
|
||||
else if (mSink){
|
||||
mInternalState = mSink->HandleComment(aValue);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleProcessingInstruction(const PRUnichar *aTarget,
|
||||
const PRUnichar *aData)
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
if (mSink){
|
||||
nsresult result = mSink->HandleProcessingInstruction(aTarget, aData);
|
||||
if (result == NS_ERROR_HTMLPARSER_BLOCK) {
|
||||
mInternalState = NS_ERROR_HTMLPARSER_BLOCK;
|
||||
XML_BlockParser(mExpatParser);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleDefault(const PRUnichar *aValue,
|
||||
const PRUint32 aLength)
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
if (mInDoctype) {
|
||||
mDoctypeText.Append(aValue, aLength);
|
||||
}
|
||||
else if (mSink) {
|
||||
static const PRUnichar newline[] = {'\n','\0'};
|
||||
for (PRUint32 i = 0; i < aLength && NS_SUCCEEDED(mInternalState); i++) {
|
||||
if (aValue[i] == '\n' || aValue[i] == '\r') {
|
||||
mInternalState = mSink->HandleCharacterData(newline, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleStartCdataSection()
|
||||
{
|
||||
mInCData = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleEndCdataSection()
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
mInCData = PR_FALSE;
|
||||
if (mSink) {
|
||||
mInternalState = mSink->HandleCDataSection(mCDataText.get(),mCDataText.Length());
|
||||
}
|
||||
mCDataText.Truncate();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleStartDoctypeDecl()
|
||||
{
|
||||
mInDoctype = PR_TRUE;
|
||||
mDoctypeText.Assign(NS_LITERAL_STRING("<!DOCTYPE "));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleEndDoctypeDecl()
|
||||
{
|
||||
NS_ASSERTION(mSink, "content sink not found!");
|
||||
|
||||
mInDoctype = PR_FALSE;
|
||||
mDoctypeText.Append(PRUnichar('>'));
|
||||
|
||||
if(mSink) {
|
||||
mInternalState = mSink->HandleDoctypeDecl(mDoctypeText.get());
|
||||
}
|
||||
|
||||
mDoctypeText.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// aDTD is an in/out parameter. Returns true if the aDTD is a chrome url or if the
|
||||
// filename contained within the url exists in the special DTD directory ("dtd"
|
||||
// relative to the current process directory). For the latter case, aDTD is set
|
||||
// to the file: url that points to the DTD file found in the local DTD directory
|
||||
// AND the old URI is relased.
|
||||
static PRBool
|
||||
IsLoadableDTD(nsCOMPtr<nsIURI>* aDTD)
|
||||
{
|
||||
PRBool isLoadable = PR_FALSE;
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (!aDTD || !*aDTD) {
|
||||
NS_ASSERTION(0, "Null parameter.");
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// Return true if the url is a chrome url
|
||||
res = (*aDTD)->SchemeIs("chrome", &isLoadable);
|
||||
|
||||
// If the url is not a chrome url, check to see if a DTD file of the same name
|
||||
// exists in the special DTD directory
|
||||
if (!isLoadable) {
|
||||
nsCOMPtr<nsIURL> dtdURL;
|
||||
dtdURL = do_QueryInterface(*aDTD, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsXPIDLCString fileName;
|
||||
res = dtdURL->GetFileName(getter_Copies(fileName));
|
||||
if (NS_SUCCEEDED(res) && fileName) {
|
||||
nsSpecialSystemDirectory dtdPath(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
||||
dtdPath += NS_ConvertASCIItoUCS2(nsDependentCString(kDTDDirectory) + fileName);
|
||||
if (dtdPath.Exists()) {
|
||||
// The DTD was found in the local DTD directory.
|
||||
// Set aDTD to a file: url pointing to the local DTD
|
||||
nsFileURL dtdFile(dtdPath);
|
||||
nsCOMPtr<nsIURI> dtdURI;
|
||||
res = NS_NewURI(getter_AddRefs(dtdURI), dtdFile.GetURLString());
|
||||
if (NS_SUCCEEDED(res) && dtdURI) {
|
||||
*aDTD = dtdURI;
|
||||
isLoadable = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isLoadable;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::OpenInputStream(const XML_Char* aURLStr,
|
||||
const XML_Char* aBaseURL,
|
||||
nsIInputStream** in,
|
||||
nsAString& aAbsURL)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> baseURI;
|
||||
rv = NS_NewURI(getter_AddRefs(baseURI), NS_ConvertUCS2toUTF8((const PRUnichar*)aBaseURL).get());
|
||||
if (NS_SUCCEEDED(rv) && baseURI) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), NS_ConvertUCS2toUTF8((const PRUnichar*)aURLStr).get(), baseURI);
|
||||
if (NS_SUCCEEDED(rv) && uri) {
|
||||
if (IsLoadableDTD(address_of(uri))) {
|
||||
rv = NS_OpenURI(in, uri);
|
||||
nsXPIDLCString absURL;
|
||||
uri->GetSpec(getter_Copies(absURL));
|
||||
CopyASCIItoUCS2(absURL, aAbsURL);
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
CreateErrorText(const PRUnichar* aDescription,
|
||||
const PRUnichar* aSourceURL,
|
||||
const PRInt32 aLineNumber,
|
||||
const PRInt32 aColNumber,
|
||||
nsString& aErrorString)
|
||||
{
|
||||
aErrorString.Truncate();
|
||||
|
||||
nsAutoString msg;
|
||||
nsresult rv = nsParserMsgUtils::GetLocalizedStringByName(XMLPARSER_PROPERTIES,"XMLParsingError",msg);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// XML Parsing Error: %1$S\nLocation: %2$S\nLine Number %3$d, Column %4$d:
|
||||
PRUnichar *message = nsTextFormatter::smprintf(msg.get(),aDescription,aSourceURL,aLineNumber,aColNumber);
|
||||
if (!message) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
aErrorString.Assign(message);
|
||||
nsTextFormatter::smprintf_free(message);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
CreateSourceText(const PRInt32 aColNumber,
|
||||
const PRUnichar* aSourceLine,
|
||||
nsString& aSourceString)
|
||||
{
|
||||
PRInt32 errorPosition = aColNumber;
|
||||
|
||||
aSourceString.Append(aSourceLine);
|
||||
aSourceString.Append(PRUnichar('\n'));
|
||||
for (PRInt32 i = 0; i < errorPosition - 1; i++) {
|
||||
aSourceString.Append(PRUnichar('-'));
|
||||
}
|
||||
aSourceString.Append(PRUnichar('^'));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleError(const char *aBuffer,
|
||||
PRUint32 aLength,
|
||||
PRBool aIsFinal)
|
||||
{
|
||||
|
||||
PRInt32 code = XML_GetErrorCode(mExpatParser);
|
||||
NS_WARN_IF_FALSE(code >= 1, "unexpected XML error code");
|
||||
|
||||
// Map Expat error code to an error string
|
||||
// XXX Deal with error returns.
|
||||
nsAutoString description;
|
||||
nsParserMsgUtils::GetLocalizedStringByID(XMLPARSER_PROPERTIES, code, description);
|
||||
|
||||
if (code == XML_ERROR_TAG_MISMATCH) {
|
||||
description.Append(NS_LITERAL_STRING(". Expected: "));
|
||||
description.Append(NS_LITERAL_STRING("</"));
|
||||
description.Append((const PRUnichar*)XML_GetMismatchedTag(mExpatParser));
|
||||
description.Append(NS_LITERAL_STRING(">."));
|
||||
}
|
||||
|
||||
nsAutoString sourceLine;
|
||||
if (!aIsFinal) {
|
||||
GetLine(aBuffer, aLength, (XML_GetCurrentByteIndex(mExpatParser) - mBytesParsed), sourceLine);
|
||||
}
|
||||
else {
|
||||
sourceLine.Append(mLastLine);
|
||||
}
|
||||
|
||||
// Adjust the column number so that it is one based rather than zero based.
|
||||
PRInt32 colNumber = XML_GetCurrentColumnNumber(mExpatParser) + 1;
|
||||
|
||||
nsAutoString errorText;
|
||||
CreateErrorText(description.get(),
|
||||
(PRUnichar*)XML_GetBase(mExpatParser),
|
||||
XML_GetCurrentLineNumber(mExpatParser),
|
||||
colNumber, errorText);
|
||||
|
||||
nsAutoString sourceText;
|
||||
CreateSourceText(colNumber, sourceLine.get(), sourceText);
|
||||
|
||||
NS_ASSERTION(mSink,"no sink?");
|
||||
if (mSink) {
|
||||
mSink->ReportError(errorText.get(), sourceText.get());
|
||||
}
|
||||
|
||||
return NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::ParseBuffer(const char* aBuffer,
|
||||
PRUint32 aLength,
|
||||
PRBool aIsFinal)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
NS_ASSERTION((aBuffer && aLength) || (aBuffer == nsnull && aLength == 0), "?");
|
||||
|
||||
if (mExpatParser && mInternalState == NS_OK) {
|
||||
if (!XML_Parse(mExpatParser, aBuffer, aLength, aIsFinal)) {
|
||||
if (mInternalState == NS_ERROR_HTMLPARSER_BLOCK ||
|
||||
mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING) {
|
||||
mBytePosition = (XML_GetCurrentByteIndex(mExpatParser) - mBytesParsed);
|
||||
mBytesParsed += mBytePosition;
|
||||
}
|
||||
else {
|
||||
HandleError(aBuffer,aLength,aIsFinal);
|
||||
mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
}
|
||||
return mInternalState;
|
||||
}
|
||||
else if (aBuffer && aLength) {
|
||||
// Cache the last line in the buffer
|
||||
GetLine(aBuffer, aLength, aLength - sizeof(PRUnichar), mLastLine);
|
||||
}
|
||||
mBytesParsed += aLength;
|
||||
mBytePosition = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
nsExpatDriver::GetLine(const char* aSourceBuffer,
|
||||
PRUint32 aLength,
|
||||
PRUint32 aOffset,
|
||||
nsString& aLine)
|
||||
{
|
||||
/* Figure out the line inside aSourceBuffer that contains character specified by aOffset.
|
||||
Copy it into aLine. */
|
||||
NS_ASSERTION(aOffset >= 0 && aOffset < aLength, "?");
|
||||
/* Assert that the byteIndex and the length of the buffer is even */
|
||||
NS_ASSERTION(aOffset % 2 == 0 && aLength % 2 == 0, "?");
|
||||
PRUnichar* start = (PRUnichar* ) &aSourceBuffer[aOffset]; /* Will try to find the start of the line */
|
||||
PRUnichar* end = (PRUnichar* ) &aSourceBuffer[aOffset]; /* Will try to find the end of the line */
|
||||
PRUint32 startIndex = aOffset / sizeof(PRUnichar); /* Track the position of the 'start' pointer into the buffer */
|
||||
PRUint32 endIndex = aOffset / sizeof(PRUnichar); /* Track the position of the 'end' pointer into the buffer */
|
||||
PRUint32 numCharsInBuffer = aLength / sizeof(PRUnichar);
|
||||
PRBool reachedStart;
|
||||
PRBool reachedEnd;
|
||||
|
||||
|
||||
/* Use start to find the first new line before the error position and
|
||||
end to find the first new line after the error position */
|
||||
reachedStart = (startIndex <= 0 || '\n' == *start || '\r' == *start);
|
||||
reachedEnd = (endIndex >= numCharsInBuffer || '\n' == *end || '\r' == *end);
|
||||
while (!reachedStart || !reachedEnd) {
|
||||
if (!reachedStart) {
|
||||
--start;
|
||||
--startIndex;
|
||||
reachedStart = (startIndex <= 0 || '\n' == *start || '\r' == *start);
|
||||
}
|
||||
if (!reachedEnd) {
|
||||
++end;
|
||||
++endIndex;
|
||||
reachedEnd = (endIndex >= numCharsInBuffer || '\n' == *end || '\r' == *end);
|
||||
}
|
||||
}
|
||||
|
||||
aLine.Truncate(0);
|
||||
if (startIndex == endIndex) {
|
||||
// Special case if the error is on a line where the only character is a newline.
|
||||
// Do nothing
|
||||
}
|
||||
else {
|
||||
NS_ASSERTION(endIndex - startIndex >= sizeof(PRUnichar), "?");
|
||||
/* At this point, there are two cases. Either the error is on the first line or
|
||||
on subsequent lines. If the error is on the first line, startIndex will decrement
|
||||
all the way to zero. If not, startIndex will decrement to the position of the
|
||||
newline character on the previous line. So, in the first case, the start position
|
||||
of the error line = startIndex (== 0). In the second case, the start position of the
|
||||
error line = startIndex + 1. In both cases, the end position of the error line will be
|
||||
(endIndex - 1). */
|
||||
PRUint32 startPosn = (startIndex <= 0) ? startIndex : startIndex + 1;
|
||||
|
||||
/* At this point, the substring starting at startPosn and ending at (endIndex - 1),
|
||||
is the line on which the error occurred. Copy that substring into the error structure. */
|
||||
const PRUnichar* unicodeBuffer = (const PRUnichar*) aSourceBuffer;
|
||||
aLine.Append(&unicodeBuffer[startPosn], endIndex - startPosn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::CreateNewInstance(nsIDTD** aInstancePtrResult)
|
||||
{
|
||||
return NS_NewExpatDriver(aInstancePtrResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::ConsumeToken(nsScanner& aScanner,
|
||||
PRBool& aFlushTokens)
|
||||
{
|
||||
|
||||
// Ask the scanner to send us all the data it has
|
||||
// scanned and pass that data to expat.
|
||||
|
||||
mInternalState = NS_OK; // Resume in case we're blocked.
|
||||
XML_UnblockParser(mExpatParser);
|
||||
|
||||
nsReadingIterator<PRUnichar> start, end;
|
||||
aScanner.CurrentPosition(start);
|
||||
aScanner.EndReading(end);
|
||||
|
||||
while (start != end) {
|
||||
PRUint32 fragLength = PRUint32(start.size_forward());
|
||||
const PRUnichar* expatBuffer = start.get();
|
||||
|
||||
mInternalState = ParseBuffer((const char *)expatBuffer,
|
||||
fragLength * sizeof(PRUnichar),
|
||||
aFlushTokens);
|
||||
|
||||
if (NS_FAILED(mInternalState)) {
|
||||
if (mInternalState == NS_ERROR_HTMLPARSER_BLOCK) {
|
||||
// mBytePosition / 2 => character position. Since one char = two bytes.
|
||||
aScanner.SetPosition(start.advance(mBytePosition / 2), PR_TRUE);
|
||||
aScanner.Mark();
|
||||
}
|
||||
return mInternalState;
|
||||
}
|
||||
|
||||
start.advance(fragLength);
|
||||
}
|
||||
|
||||
aScanner.SetPosition(end, PR_TRUE);
|
||||
|
||||
if(NS_SUCCEEDED(mInternalState)) {
|
||||
return aScanner.Eof();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(eAutoDetectResult)
|
||||
nsExpatDriver::CanParse(CParserContext& aParserContext,
|
||||
const nsString& aBuffer,
|
||||
PRInt32 aVersion)
|
||||
{
|
||||
eAutoDetectResult result = eUnknownDetect;
|
||||
|
||||
if (eViewSource != aParserContext.mParserCommand) {
|
||||
if (aParserContext.mMimeType.EqualsWithConversion(kXMLTextContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kXMLApplicationContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kXHTMLApplicationContentType)||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kRDFTextContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kXULTextContentType)) {
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
else {
|
||||
if (0 == aParserContext.mMimeType.Length() &&
|
||||
kNotFound != aBuffer.Find("<?xml ")) {
|
||||
aParserContext.SetMimeType(NS_LITERAL_STRING(kXMLTextContentType));
|
||||
result=eValidDetect;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
|
||||
nsIContentSink* aSink)
|
||||
{
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aSink);
|
||||
|
||||
aSink->QueryInterface(NS_GET_IID(nsIExpatSink),(void**)&(mSink));
|
||||
NS_ENSURE_TRUE(mSink,NS_ERROR_FAILURE);
|
||||
|
||||
mExpatParser = XML_ParserCreate((const XML_Char*) NS_LITERAL_STRING("UTF-16").get());
|
||||
NS_ENSURE_TRUE(mExpatParser, NS_ERROR_FAILURE);
|
||||
|
||||
#ifdef XML_DTD
|
||||
XML_SetParamEntityParsing(mExpatParser, XML_PARAM_ENTITY_PARSING_ALWAYS);
|
||||
#endif
|
||||
|
||||
XML_SetBase(mExpatParser, (const XML_Char*) (aParserContext.mScanner->GetFilename()).get());
|
||||
|
||||
// Set up the callbacks
|
||||
XML_SetElementHandler(mExpatParser, Driver_HandleStartElement, Driver_HandleEndElement);
|
||||
XML_SetCharacterDataHandler(mExpatParser, Driver_HandleCharacterData);
|
||||
XML_SetProcessingInstructionHandler(mExpatParser, Driver_HandleProcessingInstruction);
|
||||
XML_SetDefaultHandlerExpand(mExpatParser, Driver_HandleDefault);
|
||||
XML_SetExternalEntityRefHandler(mExpatParser, Driver_HandleExternalEntityRef);
|
||||
XML_SetCommentHandler(mExpatParser, Driver_HandleComment);
|
||||
XML_SetCdataSectionHandler(mExpatParser, Driver_HandleStartCdataSection,
|
||||
Driver_HandleEndCdataSection);
|
||||
|
||||
XML_SetDoctypeDeclHandler(mExpatParser, Driver_HandleStartDoctypeDecl, Driver_HandleEndDoctypeDecl);
|
||||
|
||||
// Set up the user data.
|
||||
XML_SetUserData(mExpatParser, this);
|
||||
|
||||
return aSink->WillBuildModel();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::BuildModel(nsIParser* aParser,
|
||||
nsITokenizer* aTokenizer,
|
||||
nsITokenObserver* anObserver,
|
||||
nsIContentSink* aSink)
|
||||
{
|
||||
return mInternalState;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::DidBuildModel(nsresult anErrorCode,
|
||||
PRBool aNotifySink,
|
||||
nsIParser* aParser,
|
||||
nsIContentSink* aSink)
|
||||
{
|
||||
// Check for mSink is intentional. This would make sure
|
||||
// that DidBuildModel() is called only once on the sink.
|
||||
nsresult result = (mSink)? aSink->DidBuildModel(0) : NS_OK;
|
||||
NS_IF_RELEASE(mSink);
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsExpatDriver::GetTokenizer(nsITokenizer*& aTokenizer)
|
||||
{
|
||||
aTokenizer = this;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::WillTokenize(PRBool aIsFinalChunk,
|
||||
nsTokenAllocator* aTokenAllocator)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::WillResumeParse(nsIContentSink* aSink)
|
||||
{
|
||||
return (aSink)? aSink->WillResume():NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::WillInterruptParse(nsIContentSink* aSink)
|
||||
{
|
||||
return (aSink)? aSink->WillInterrupt():NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::DidTokenize(PRBool aIsFinalChunk)
|
||||
{
|
||||
return ParseBuffer(nsnull, 0, aIsFinalChunk);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(const nsIID&)
|
||||
nsExpatDriver::GetMostDerivedIID(void) const
|
||||
{
|
||||
return NS_GET_IID(nsIDTD);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsExpatDriver::Terminate(nsIParser* aParser)
|
||||
{
|
||||
XML_BlockParser(mExpatParser); // XXX - not sure what happens to the unparsed data.
|
||||
return mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
}
|
||||
|
||||
/*************************** Unused methods ***************************************/
|
||||
|
||||
NS_IMETHODIMP_(CToken*)
|
||||
nsExpatDriver::PushTokenFront(CToken* aToken)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(CToken*)
|
||||
nsExpatDriver::PushToken(CToken* aToken)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(CToken*)
|
||||
nsExpatDriver::PopToken(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(CToken*)
|
||||
nsExpatDriver::PeekToken(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(CToken*)
|
||||
nsExpatDriver::GetTokenAt(PRInt32 anIndex)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRInt32)
|
||||
nsExpatDriver::GetCount(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsTokenAllocator*)
|
||||
nsExpatDriver::GetTokenAllocator(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
nsExpatDriver::PrependTokens(nsDeque& aDeque)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::HandleToken(CToken* aToken,nsIParser* aParser)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsExpatDriver::IsBlockElement(PRInt32 aTagID,PRInt32 aParentID) const
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsExpatDriver::IsInlineElement(PRInt32 aTagID,PRInt32 aParentID) const
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsExpatDriver::IsContainer(PRInt32 aTag) const
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsExpatDriver::CanContain(PRInt32 aParent,PRInt32 aChild) const
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::StringTagToIntTag(const nsAReadableString &aTag, PRInt32* aIntTag) const
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(const PRUnichar *)
|
||||
nsExpatDriver::IntTagToStringTag(PRInt32 aIntTag) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpatDriver::ConvertEntityToUnicode(const nsAReadableString& aEntity, PRInt32* aUnicode) const
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
/******************************************************************************/
|
|
@ -0,0 +1,94 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef NS_EXPAT_DRIVER__
|
||||
#define NS_EXPAT_DRIVER__
|
||||
|
||||
#include "xmlparse.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIDTD.h"
|
||||
#include "nsITokenizer.h"
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
class nsIExpatSink;
|
||||
|
||||
class nsExpatDriver : public nsIDTD,
|
||||
public nsITokenizer
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDTD
|
||||
NS_DECL_NSITOKENIZER
|
||||
|
||||
nsExpatDriver();
|
||||
virtual ~nsExpatDriver();
|
||||
|
||||
// Load up an external stream to get external entity information
|
||||
static nsresult OpenInputStream(const XML_Char* aURLStr, const XML_Char* aBaseURL, nsIInputStream** in, nsAString& aAbsURL);
|
||||
|
||||
nsresult HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts);
|
||||
nsresult HandleEndElement(const PRUnichar *aName);
|
||||
nsresult HandleCharacterData(const PRUnichar *aCData, const PRUint32 aLength);
|
||||
nsresult HandleComment(const PRUnichar *aName);
|
||||
nsresult HandleProcessingInstruction(const PRUnichar *aTarget, const PRUnichar *aData);
|
||||
nsresult HandleDefault(const PRUnichar *aData, const PRUint32 aLength);
|
||||
nsresult HandleStartCdataSection();
|
||||
nsresult HandleEndCdataSection();
|
||||
nsresult HandleStartDoctypeDecl();
|
||||
nsresult HandleEndDoctypeDecl();
|
||||
|
||||
protected:
|
||||
|
||||
nsresult ParseBuffer(const char* aBuffer, PRUint32 aLength, PRBool aIsFinal);
|
||||
nsresult HandleError(const char *aBuffer, PRUint32 aLength, PRBool aIsFinal);
|
||||
void GetLine(const char* aSourceBuffer, PRUint32 aLength, PRUint32 aOffset, nsString& aLine);
|
||||
|
||||
XML_Parser mExpatParser;
|
||||
nsIExpatSink* mSink;
|
||||
nsString mLastLine;
|
||||
nsString mDoctypeText;
|
||||
nsString mCDataText;
|
||||
PRPackedBool mInDoctype;
|
||||
PRPackedBool mInCData;
|
||||
PRUint32 mBytesParsed;
|
||||
PRInt32 mBytePosition;
|
||||
nsresult mInternalState;
|
||||
};
|
||||
nsresult NS_NewExpatDriver(nsIDTD** aDriver);
|
||||
|
||||
#endif
|
|
@ -66,7 +66,6 @@ public:
|
|||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError);
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0);
|
||||
|
@ -624,12 +623,6 @@ nsHTMLNullSink::SetParser(nsIParser* aParser)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLNullSink::NotifyError(const nsParserError* aError)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gpk03/14/99
|
||||
|
|
|
@ -70,27 +70,14 @@
|
|||
|
||||
class nsHTMLTokenizer : public nsITokenizer {
|
||||
public:
|
||||
nsHTMLTokenizer( PRInt32 aParseMode=eDTDMode_quirks,
|
||||
eParserDocType aDocType=eHTML3_Quirks,
|
||||
eParserCommands aCommand=eViewNormal);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSITOKENIZER
|
||||
nsHTMLTokenizer(PRInt32 aParseMode=eDTDMode_quirks,
|
||||
eParserDocType aDocType=eHTML3_Quirks,
|
||||
eParserCommands aCommand=eViewNormal);
|
||||
virtual ~nsHTMLTokenizer();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult WillTokenize(PRBool aIsFinalChunk,nsTokenAllocator* aTokenAllocator);
|
||||
virtual nsresult ConsumeToken(nsScanner& aScanner,PRBool& aFlushTokens);
|
||||
virtual nsresult DidTokenize(PRBool aIsFinalChunk);
|
||||
virtual nsTokenAllocator* GetTokenAllocator(void);
|
||||
|
||||
virtual CToken* PushTokenFront(CToken* theToken);
|
||||
virtual CToken* PushToken(CToken* theToken);
|
||||
virtual CToken* PopToken(void);
|
||||
virtual CToken* PeekToken(void);
|
||||
virtual CToken* GetTokenAt(PRInt32 anIndex);
|
||||
virtual PRInt32 GetCount(void);
|
||||
|
||||
virtual void PrependTokens(nsDeque& aDeque);
|
||||
|
||||
protected:
|
||||
|
||||
virtual nsresult ConsumeScriptContent(nsScanner& aScanner,CToken*& aToken);
|
||||
|
|
|
@ -253,20 +253,6 @@ nsLoggingSink::AddLeaf(const nsIParserNode& aNode) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLoggingSink::NotifyError(const nsParserError* aError) {
|
||||
nsresult theResult=NS_OK;
|
||||
|
||||
//then proxy the call to the real sink if you have one.
|
||||
if(mSink) {
|
||||
theResult=mSink->NotifyError(aError);
|
||||
}
|
||||
|
||||
return theResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a PI node to the current container in the content
|
||||
|
|
|
@ -68,7 +68,6 @@ public:
|
|||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError);
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0);
|
||||
|
|
|
@ -49,7 +49,6 @@
|
|||
#include "nsScanner.h"
|
||||
#include "plstr.h"
|
||||
#include "nsIParserFilter.h"
|
||||
#include "nsWellFormedDTD.h"
|
||||
#include "nsViewSourceHTML.h"
|
||||
#include "nsIStringStream.h"
|
||||
#include "nsIChannel.h"
|
||||
|
@ -65,13 +64,14 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsExpatDriver.h"
|
||||
//#define rickgdebug
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
|
||||
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
|
||||
|
||||
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
|
||||
static NS_DEFINE_IID(kExpatDriverCID, NS_EXPAT_DRIVER_CID);
|
||||
static NS_DEFINE_CID(kNavDTDCID, NS_CNAVDTD_CID);
|
||||
static NS_DEFINE_CID(kCOtherDTDCID, NS_COTHER_DTD_CID);
|
||||
static NS_DEFINE_CID(kViewSourceDTDCID, NS_VIEWSOURCE_DTD_CID);
|
||||
|
@ -1159,7 +1159,7 @@ PRBool FindSuitableDTD( CParserContext& aParserContext,nsString& aBuffer) {
|
|||
}
|
||||
if((theDTDIndex==gSharedObjects.mDTDDeque.GetSize()) && (!thePrimaryFound)) {
|
||||
if(!gSharedObjects.mHasXMLDTD) {
|
||||
NS_NewWellFormed_DTD(&theDTD); //do this to view XML files...
|
||||
NS_NewExpatDriver(&theDTD); //do this to view XML files...
|
||||
gSharedObjects.mDTDDeque.Push(theDTD);
|
||||
gSharedObjects.mHasXMLDTD=PR_TRUE;
|
||||
}
|
||||
|
@ -1261,7 +1261,7 @@ NS_IMETHODIMP nsParser::CreateCompatibleDTD(nsIDTD** aDTD,
|
|||
theDTDClassID=&kNavDTDCID;
|
||||
break;
|
||||
case eXML:
|
||||
theDTDClassID=&kWellFormedDTDCID;
|
||||
theDTDClassID=&kExpatDriverCID;
|
||||
break;
|
||||
default:
|
||||
theDTDClassID=&kNavDTDCID;
|
||||
|
@ -1288,7 +1288,7 @@ NS_IMETHODIMP nsParser::CreateCompatibleDTD(nsIDTD** aDTD,
|
|||
aMimeType->EqualsWithConversion(kXHTMLApplicationContentType) ||
|
||||
aMimeType->EqualsWithConversion(kXULTextContentType) ||
|
||||
aMimeType->EqualsWithConversion(kRDFTextContentType)) {
|
||||
theDTDClassID=&kWellFormedDTDCID;
|
||||
theDTDClassID=&kExpatDriverCID;
|
||||
}
|
||||
else {
|
||||
theDTDClassID=&kNavDTDCID;
|
||||
|
@ -1836,7 +1836,7 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo
|
|||
// as if it was read from the input stream.
|
||||
// Adding UngetReadable() per vidur!!
|
||||
mParserContext->mScanner->UngetReadable(mUnusedInput);
|
||||
mUnusedInput.Truncate(0);
|
||||
mUnusedInput.Truncate(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1853,7 +1853,7 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo
|
|||
SetCanInterrupt(PR_FALSE);
|
||||
|
||||
theIterationIsOk=PRBool((kEOF!=theTokenizerResult) && (result!=NS_ERROR_HTMLPARSER_INTERRUPTED));
|
||||
|
||||
|
||||
// Make sure not to stop parsing too early. Therefore, before shutting down the
|
||||
// parser, it's important to check whether the input buffer has been scanned to
|
||||
// completion ( theTokenizerResult should be kEOF ). kEOF -> End of buffer.
|
||||
|
@ -1864,7 +1864,7 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo
|
|||
if(NS_ERROR_HTMLPARSER_BLOCK==result) {
|
||||
//BLOCK == 2152596464
|
||||
if (mParserContext->mDTD) {
|
||||
mParserContext->mDTD->WillInterruptParse();
|
||||
mParserContext->mDTD->WillInterruptParse(mSink);
|
||||
}
|
||||
|
||||
BlockParser();
|
||||
|
|
|
@ -162,10 +162,10 @@ class nsParser : public nsIParser,
|
|||
*/
|
||||
virtual void SetDocumentCharset(nsString& aCharset, PRInt32 aSource);
|
||||
|
||||
void GetDocumentCharset(nsString& oCharset, PRInt32& oSource)
|
||||
void GetDocumentCharset(nsString& aCharset, PRInt32& aSource)
|
||||
{
|
||||
oCharset = mCharset;
|
||||
oSource = mCharsetSource;
|
||||
aCharset = mCharset;
|
||||
aSource = mCharsetSource;
|
||||
}
|
||||
|
||||
|
||||
|
@ -453,29 +453,30 @@ protected:
|
|||
// And now, some data members...
|
||||
//*********************************************
|
||||
|
||||
|
||||
CParserContext* mParserContext;
|
||||
PRInt32 mMajorIteration;
|
||||
PRInt32 mMinorIteration;
|
||||
|
||||
nsIRequestObserver* mObserver;
|
||||
nsIContentSink* mSink;
|
||||
|
||||
nsCOMPtr<nsIEventQueue> mEventQueue;
|
||||
CParserContext* mParserContext;
|
||||
nsIRequestObserver* mObserver;
|
||||
nsIContentSink* mSink;
|
||||
|
||||
nsIParserFilter* mParserFilter;
|
||||
PRBool mDTDVerification;
|
||||
eParserCommands mCommand;
|
||||
PRInt32 mStreamStatus;
|
||||
nsITokenObserver* mTokenObserver;
|
||||
nsTokenAllocator mTokenAllocator;
|
||||
|
||||
eParserCommands mCommand;
|
||||
nsresult mInternalState;
|
||||
PRInt32 mStreamStatus;
|
||||
PRInt32 mMajorIteration;
|
||||
PRInt32 mMinorIteration;
|
||||
PRInt32 mCharsetSource;
|
||||
|
||||
nsString mUnusedInput;
|
||||
nsString mCharset;
|
||||
PRInt32 mCharsetSource;
|
||||
nsresult mInternalState;
|
||||
PRBool mObserversEnabled;
|
||||
nsString mCommandStr;
|
||||
PRBool mParserEnabled;
|
||||
nsTokenAllocator mTokenAllocator;
|
||||
|
||||
nsCOMPtr<nsIEventQueue> mEventQueue;
|
||||
|
||||
PRPackedBool mDTDVerification;
|
||||
PRPackedBool mParserEnabled;
|
||||
PRPackedBool mObserversEnabled;
|
||||
PRPackedBool mPendingContinueEvent;
|
||||
PRPackedBool mCanInterrupt;
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "nsILoggingSink.h"
|
||||
#include "nsParser.h"
|
||||
#include "nsParserNode.h"
|
||||
#include "nsWellFormedDTD.h"
|
||||
#include "CNavDTD.h"
|
||||
|
||||
#include "nsHTMLTags.h"
|
||||
|
@ -52,12 +51,12 @@
|
|||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_IID(kCParserNode, NS_PARSER_NODE_IID);
|
||||
|
||||
static NS_DEFINE_CID(kCParserCID NS_PARSER_CID);
|
||||
static NS_DEFINE_IID(kCParserNode, NS_PARSER_NODE_IID);
|
||||
static NS_DEFINE_IID(kLoggingSinkCID, NS_LOGGING_SINK_CID);
|
||||
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
|
||||
static NS_DEFINE_CID(kCNavDTDCID, NS_CNAVDTD_CID);
|
||||
static NS_DEFINE_CID(kCParserCID NS_PARSER_CID);
|
||||
static NS_DEFINE_CID(kLoggingSinkCID, NS_LOGGING_SINK_CID);
|
||||
static NS_DEFINE_CID(kExpatDriverCID, NS_EXPAT_DRIVER_CID);
|
||||
static NS_DEFINE_CID(kCNavDTDCID, NS_CNAVDTD_CID);
|
||||
|
||||
class nsParserFactory : public nsIFactory
|
||||
{
|
||||
|
@ -144,8 +143,8 @@ nsresult nsParserFactory::CreateInstance(nsISupports *aOuter,
|
|||
*aResult = cs;
|
||||
return rv;
|
||||
}
|
||||
else if (mClassID.Equals(kWellFormedDTDCID)) {
|
||||
nsresult rv = NS_NewWellFormed_DTD((nsIDTD**) &inst);
|
||||
else if (mClassID.Equals(kExpatDriverCID)) {
|
||||
nsresult rv = NS_NewExpatDriver((nsIDTD**) &inst);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "nsIModule.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "nsParser.h"
|
||||
#include "nsWellFormedDTD.h"
|
||||
#include "CNavDTD.h"
|
||||
#include "COtherDTD.h"
|
||||
#include "COtherDTD.h"
|
||||
|
@ -52,22 +51,22 @@
|
|||
#include "nsHTMLEntities.h"
|
||||
#include "nsHTMLTokenizer.h"
|
||||
//#include "nsTextTokenizer.h"
|
||||
#include "nsExpatTokenizer.h"
|
||||
#include "nsElementTable.h"
|
||||
#include "nsParserService.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
#include "nsLoggingSink.h"
|
||||
#include "nsExpatDriver.h"
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLoggingSink)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsExpatDriver)
|
||||
#endif
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsParser)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(CWellFormedDTD)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(CNavDTD)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(COtherDTD)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(CTransitionalDTD)
|
||||
|
@ -78,10 +77,10 @@ static nsModuleComponentInfo gComponents[] = {
|
|||
|
||||
#ifdef NS_DEBUG
|
||||
{ "Logging sink", NS_LOGGING_SINK_CID, NULL, nsLoggingSinkConstructor },
|
||||
{ "Expat Driver", NS_EXPAT_DRIVER_CID, NULL, nsExpatDriverConstructor },
|
||||
#endif
|
||||
|
||||
{ "Parser", NS_PARSER_CID, NULL, nsParserConstructor },
|
||||
{ "Well formed DTD", NS_WELLFORMEDDTD_CID, NULL, CWellFormedDTDConstructor },
|
||||
{ "Navigator HTML DTD", NS_CNAVDTD_CID, NULL, CNavDTDConstructor },
|
||||
{ "OTHER DTD", NS_COTHER_DTD_CID, NULL, COtherDTDConstructor },
|
||||
{ "Transitional DTD", NS_CTRANSITIONAL_DTD_CID, NULL,
|
||||
|
|
|
@ -713,22 +713,6 @@ NS_IMETHODIMP CViewSourceHTML::DidBuildModel(nsresult anErrorCode,PRBool aNotify
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess8/4/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsTokenAllocator* CViewSourceHTML::GetTokenAllocator(void){
|
||||
nsITokenizer* theTokenizer=0;
|
||||
nsresult result=GetTokenizer(theTokenizer);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
return theTokenizer->GetTokenAllocator();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this id you want to stop the building content model
|
||||
* --------------[ Sets DTD to STOP mode ]----------------
|
||||
|
@ -767,7 +751,7 @@ nsresult CViewSourceHTML::GetTokenizer(nsITokenizer*& aTokenizer) {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHODIMP CViewSourceHTML::WillResumeParse(void){
|
||||
NS_IMETHODIMP CViewSourceHTML::WillResumeParse(nsIContentSink* aSink){
|
||||
nsresult result = NS_OK;
|
||||
if(mSink) {
|
||||
result = mSink->WillResume();
|
||||
|
@ -781,7 +765,7 @@ NS_IMETHODIMP CViewSourceHTML::WillResumeParse(void){
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHODIMP CViewSourceHTML::WillInterruptParse(void){
|
||||
NS_IMETHODIMP CViewSourceHTML::WillInterruptParse(nsIContentSink* aSink){
|
||||
nsresult result = NS_OK;
|
||||
if(mSink) {
|
||||
result = mSink->WillInterrupt();
|
||||
|
|
|
@ -53,127 +53,10 @@ class CViewSourceHTML: public nsIDTD
|
|||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 4/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
CViewSourceHTML();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 4/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual ~CViewSourceHTML();
|
||||
|
||||
|
||||
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const;
|
||||
|
||||
/**
|
||||
* Call this method if you want the DTD to construct a clone of itself.
|
||||
* @update gess7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD CreateNewInstance(nsIDTD** aInstancePtrResult);
|
||||
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can parse
|
||||
* a document in a given source-type.
|
||||
* NOTE: Parsing always assumes that the end result will involve
|
||||
* storing the result in the main content model.
|
||||
* @update gess6/24/98
|
||||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
NS_IMETHOD_(eAutoDetectResult) CanParse(CParserContext& aParserContext,
|
||||
const nsString& aBuffer,
|
||||
PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update rickg 03.20.2000
|
||||
* @param aParserContext
|
||||
* @param aSink
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext,
|
||||
nsIContentSink* aSink);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param aFilename is the name of the file being parsed.
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer,
|
||||
nsITokenObserver* anObserver = nsnull,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param anErrorCode contans the last error that occured
|
||||
* @return error code
|
||||
*/
|
||||
NS_IMETHOD DidBuildModel(nsresult anErrorCode, PRBool aNotifySink,
|
||||
nsIParser* aParser,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aToken -- token object to be put into content model
|
||||
* @return 0 if all is well; non-zero is an error
|
||||
*/
|
||||
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 12/20/99
|
||||
* @param ptr-ref to (out) tokenizer
|
||||
* @return nsresult
|
||||
*/
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer);
|
||||
|
||||
NS_DECL_NSIDTD
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/28/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD_(nsTokenAllocator *) GetTokenAllocator(void);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD WillResumeParse(void);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD WillInterruptParse(void);
|
||||
CViewSourceHTML();
|
||||
virtual ~CViewSourceHTML();
|
||||
|
||||
/**
|
||||
* Set this to TRUE if you want the DTD to verify its
|
||||
|
@ -184,61 +67,20 @@ public:
|
|||
*/
|
||||
virtual void SetVerification(PRBool aEnable);
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- int tag of parent container
|
||||
* @param aChild -- int tag of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent,PRInt32 aChild) const;
|
||||
|
||||
/**
|
||||
* Use this id you want to stop the building content model
|
||||
* --------------[ Sets DTD to STOP mode ]----------------
|
||||
* It's recommended to use this method in accordance with
|
||||
* the parser's terminate() method.
|
||||
*
|
||||
* @update harishd 07/22/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD Terminate(nsIParser* aParser = nsnull);
|
||||
|
||||
/**
|
||||
* Give rest of world access to our tag enums, so that CanContain(), etc,
|
||||
* become useful.
|
||||
*/
|
||||
NS_IMETHOD StringTagToIntTag(const nsAReadableString &aTag,
|
||||
PRInt32* aIntTag) const;
|
||||
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const;
|
||||
|
||||
NS_IMETHOD ConvertEntityToUnicode(const nsAReadableString& aEntity,
|
||||
PRInt32* aUnicode) const;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const;
|
||||
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const;
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag is itself a container
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aTag -- tag to test for containership
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const;
|
||||
|
||||
|
||||
private:
|
||||
nsresult WriteTag(PRInt32 tagType,const nsAReadableString &aText,PRInt32 attrCount,PRBool aNewlineRequired);
|
||||
nsresult WriteTagWithError(PRInt32 tagType,const nsAReadableString& aToken,PRInt32 attrCount,PRBool aNewlineRequired);
|
||||
void AddContainmentError(eHTMLTags aChild,eHTMLTags aParent,PRInt32 aLineNumber);
|
||||
nsresult WriteTag(PRInt32 tagType,
|
||||
const nsAReadableString &aText,
|
||||
PRInt32 attrCount,
|
||||
PRBool aNewlineRequired);
|
||||
|
||||
nsresult WriteTagWithError(PRInt32 tagType,
|
||||
const nsAReadableString& aToken,
|
||||
PRInt32 attrCount,
|
||||
PRBool aNewlineRequired);
|
||||
|
||||
void AddContainmentError(eHTMLTags aChild,
|
||||
eHTMLTags aParent,
|
||||
PRInt32 aLineNumber);
|
||||
|
||||
nsresult WriteAttributes(PRInt32 attrCount);
|
||||
nsresult GenerateSummary();
|
||||
|
|
|
@ -1,788 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* MODULE NOTES:
|
||||
* @update gess 4/8/98
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsWellFormedDTD.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsParser.h"
|
||||
#include "nsScanner.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsDTDUtils.h"
|
||||
#include "nsIContentSink.h"
|
||||
#include "nsIHTMLContentSink.h"
|
||||
#include "nsHTMLTokenizer.h"
|
||||
#include "nsExpatTokenizer.h"
|
||||
|
||||
#include "prenv.h" //this is here for debug reasons...
|
||||
#include "prtypes.h" //this is here for debug reasons...
|
||||
#include "prio.h"
|
||||
#include "plstr.h"
|
||||
#include "prprf.h"
|
||||
|
||||
#include "prmem.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
|
||||
#include <ctype.h> // toupper()
|
||||
#include "nsString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
|
||||
static NS_DEFINE_IID(kClassIID, NS_WELLFORMED_DTD_IID);
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called as part of our COM-like interfaces.
|
||||
* Its purpose is to create an interface to parser object
|
||||
* of some type.
|
||||
*
|
||||
* @update gess 4/8/98
|
||||
* @param nsIID id of object to discover
|
||||
* @param aInstancePtr ptr to newly discovered interface
|
||||
* @return NS_xxx result code
|
||||
*/
|
||||
nsresult CWellFormedDTD::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if(aIID.Equals(kISupportsIID)) { //do IUnknown...
|
||||
*aInstancePtr = (nsIDTD*)(this);
|
||||
}
|
||||
else if(aIID.Equals(kIDTDIID)) { //do IParser base class...
|
||||
*aInstancePtr = (nsIDTD*)(this);
|
||||
}
|
||||
else if(aIID.Equals(kClassIID)) { //do this class...
|
||||
*aInstancePtr = (CWellFormedDTD*)(this);
|
||||
}
|
||||
else {
|
||||
*aInstancePtr=0;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is defined in nsIParser. It is used to
|
||||
* cause the COM-like construction of an nsParser.
|
||||
*
|
||||
* @update gess 4/8/98
|
||||
* @param nsIParser** ptr to newly instantiated parser
|
||||
* @return NS_xxx error result
|
||||
*/
|
||||
nsresult NS_NewWellFormed_DTD(nsIDTD** aInstancePtrResult)
|
||||
{
|
||||
CWellFormedDTD* it = new CWellFormedDTD();
|
||||
|
||||
if (it == 0) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kClassIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(CWellFormedDTD)
|
||||
NS_IMPL_RELEASE(CWellFormedDTD)
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @update gess 4/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
CWellFormedDTD::CWellFormedDTD() : nsIDTD() {
|
||||
NS_INIT_REFCNT();
|
||||
mParser=0;
|
||||
mSink=0;
|
||||
mLineNumber=1;
|
||||
mTokenizer=0;
|
||||
mDTDState=NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default destructor
|
||||
*
|
||||
* @update gess 4/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
CWellFormedDTD::~CWellFormedDTD(){
|
||||
mParser=0; //just to prove we destructed...
|
||||
NS_IF_RELEASE(mTokenizer);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/8/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
const nsIID& CWellFormedDTD::GetMostDerivedIID(void) const{
|
||||
return kClassIID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method if you want the DTD to construct a fresh
|
||||
* instance of itself.
|
||||
* @update gess7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult CWellFormedDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
||||
return NS_NewWellFormed_DTD(aInstancePtrResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can parse
|
||||
* a document in a given source-type.
|
||||
* NOTE: Parsing always assumes that the end result will involve
|
||||
* storing the result in the main content model.
|
||||
* @update gess6/24/98
|
||||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
NS_IMETHODIMP_(eAutoDetectResult)
|
||||
CWellFormedDTD::CanParse(CParserContext& aParserContext,
|
||||
const nsString& aBuffer, PRInt32 aVersion)
|
||||
{
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
|
||||
if(eViewSource!=aParserContext.mParserCommand) {
|
||||
if(aParserContext.mMimeType.EqualsWithConversion(kXMLTextContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kXMLApplicationContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kXHTMLApplicationContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kRDFTextContentType) ||
|
||||
aParserContext.mMimeType.EqualsWithConversion(kXULTextContentType)
|
||||
#ifdef MOZ_SVG
|
||||
|| aParserContext.mMimeType.Equals(NS_LITERAL_STRING(kSVGTextContentType))
|
||||
#endif
|
||||
) {
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
else if (aParserContext.mMimeType.IsEmpty()) {
|
||||
nsAReadableString::const_iterator iter, end;
|
||||
aBuffer.BeginReading(iter);
|
||||
aBuffer.EndReading(end);
|
||||
|
||||
if (FindInReadable(NS_LITERAL_STRING("<?xml "), iter, end)) {
|
||||
aParserContext.SetMimeType(NS_ConvertASCIItoUCS2(kXMLTextContentType));
|
||||
result=eValidDetect;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update rickg 03.20.2000
|
||||
* @param aParserContext
|
||||
* @param aSink
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
nsresult CWellFormedDTD::WillBuildModel( const CParserContext& aParserContext,nsIContentSink* aSink){
|
||||
|
||||
nsresult result=NS_OK;
|
||||
mFilename=aParserContext.mScanner->GetFilename();
|
||||
|
||||
mSink=aSink;
|
||||
if((!aParserContext.mPrevContext) && (mSink)) {
|
||||
mLineNumber=1;
|
||||
result = mSink->WillBuildModel();
|
||||
|
||||
#if 0
|
||||
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
|
||||
{
|
||||
|
||||
//now let's automatically open the html...
|
||||
CStartToken theHTMLToken(eHTMLTag_html);
|
||||
nsCParserNode theHTMLNode(&theHTMLToken,0);
|
||||
mSink->OpenHTML(theHTMLNode);
|
||||
|
||||
//now let's automatically open the body...
|
||||
CStartToken theBodyToken(eHTMLTag_body);
|
||||
nsCParserNode theBodyNode(&theBodyToken,0);
|
||||
mSink->OpenBody(theBodyNode);
|
||||
}
|
||||
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
|
||||
#endif
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess 1/4/99
|
||||
* @param aFilename is the name of the file being parsed.
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHODIMP CWellFormedDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITokenObserver* anObserver,nsIContentSink* aSink) {
|
||||
nsresult result=NS_OK;
|
||||
|
||||
if(aTokenizer) {
|
||||
nsHTMLTokenizer* oldTokenizer=mTokenizer;
|
||||
mTokenizer=(nsHTMLTokenizer*)aTokenizer;
|
||||
|
||||
while(NS_SUCCEEDED(result)){
|
||||
if(mDTDState!=NS_ERROR_HTMLPARSER_STOPPARSING) {
|
||||
CToken* theToken=mTokenizer->PopToken();
|
||||
if(theToken) {
|
||||
result=HandleToken(theToken,aParser);
|
||||
if(NS_SUCCEEDED(result) || (NS_ERROR_HTMLPARSER_BLOCK==result)) {
|
||||
IF_FREE(theToken, mTokenizer->GetTokenAllocator());
|
||||
}
|
||||
else {
|
||||
// if(NS_ERROR_HTMLPARSER_BLOCK!=result){
|
||||
mTokenizer->PushTokenFront(theToken);
|
||||
}
|
||||
}
|
||||
else break;
|
||||
}
|
||||
else result=mDTDState;
|
||||
}//while
|
||||
mTokenizer=oldTokenizer;
|
||||
}
|
||||
else result=NS_ERROR_HTMLPARSER_BADTOKENIZER;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHODIMP CWellFormedDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParser* aParser,nsIContentSink* aSink){
|
||||
nsresult result= NS_OK;
|
||||
|
||||
//ADD CODE HERE TO CLOSE OPEN CONTAINERS...
|
||||
|
||||
if(aParser){
|
||||
mSink=aParser->GetContentSink();
|
||||
if((aNotifySink) && (mSink)) {
|
||||
result = mSink->DidBuildModel(1);
|
||||
|
||||
#if 0
|
||||
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
|
||||
{
|
||||
nsIHTMLContentSink* mSink=(nsIHTMLContentSink*)mSink;
|
||||
|
||||
//now let's automatically open the body...
|
||||
CEndToken theBodyToken(eHTMLTag_body);
|
||||
nsCParserNode theBodyNode(&theBodyToken,0);
|
||||
mSink->CloseBody(theBodyNode);
|
||||
|
||||
//now let's automatically open the html...
|
||||
CEndToken theHTMLToken(eHTMLTag_html);
|
||||
nsCParserNode theHTMLNode(&theBodyToken,0);
|
||||
mSink->CloseHTML(theBodyNode);
|
||||
|
||||
}
|
||||
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess8/4/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsTokenAllocator* CWellFormedDTD::GetTokenAllocator(void){
|
||||
nsITokenizer* theTokenizer=0;
|
||||
|
||||
nsresult result=GetTokenizer(theTokenizer);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
return theTokenizer->GetTokenAllocator();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this id you want to stop the building content model
|
||||
* --------------[ Sets DTD to STOP mode ]----------------
|
||||
* It's recommended to use this method in accordance with
|
||||
* the parser's terminate() method. Here we process only
|
||||
* the "error" token.
|
||||
*
|
||||
* @update harishd 07/22/99
|
||||
* @param aParser - Parser that exists.
|
||||
* @return NS_ERROR_HTMLPARSER_STOPPARSING or the appropriate error.
|
||||
*/
|
||||
nsresult CWellFormedDTD::Terminate(nsIParser* aParser)
|
||||
{
|
||||
nsresult result=NS_OK;
|
||||
|
||||
if(mTokenizer) {
|
||||
nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();
|
||||
if(theAllocator) {
|
||||
eHTMLTokenTypes theType=eToken_unknown;
|
||||
|
||||
mDTDState=NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
|
||||
while(result==NS_OK){
|
||||
CToken* theToken=mTokenizer->PopToken();
|
||||
if(theToken) {
|
||||
theType=(eHTMLTokenTypes)theToken->GetTokenType();
|
||||
if(theType==eToken_error) {
|
||||
result=HandleToken(theToken,aParser);
|
||||
}
|
||||
IF_FREE(theToken, mTokenizer->GetTokenAllocator());
|
||||
}
|
||||
else break;
|
||||
}//while
|
||||
}//if
|
||||
}//if
|
||||
result=(NS_SUCCEEDED(result))? mDTDState:result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the preferred tokenizer for use by this DTD.
|
||||
* @update gess12/28/98
|
||||
* @param none
|
||||
* @return ptr to tokenizer
|
||||
*/
|
||||
nsresult CWellFormedDTD::GetTokenizer(nsITokenizer*& aTokenizer) {
|
||||
nsresult result=NS_OK;
|
||||
if(!mTokenizer) {
|
||||
mTokenizer=(nsHTMLTokenizer*)new nsExpatTokenizer(&mFilename);
|
||||
NS_IF_ADDREF(mTokenizer);
|
||||
}
|
||||
aTokenizer=mTokenizer;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHODIMP CWellFormedDTD::WillResumeParse(void){
|
||||
nsresult result = NS_OK;
|
||||
if(mSink) {
|
||||
result = mSink->WillResume();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHODIMP CWellFormedDTD::WillInterruptParse(void){
|
||||
nsresult result = NS_OK;
|
||||
if(mSink) {
|
||||
result = mSink->WillInterrupt();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the parser to enable/disable dtd verification of the
|
||||
* internal context stack.
|
||||
* @update gess 7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void CWellFormedDTD::SetVerification(PRBool aEnabled){
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- int tag of parent container
|
||||
* @param aChild -- int tag of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
PRBool CWellFormedDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const{
|
||||
PRBool result=PR_TRUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give rest of world access to our tag enums, so that CanContain(), etc,
|
||||
* become useful.
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
CWellFormedDTD::StringTagToIntTag(const nsAReadableString &aTag,
|
||||
PRInt32* aIntTag) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(const PRUnichar *)
|
||||
CWellFormedDTD::IntTagToStringTag(PRInt32 aIntTag) const
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CWellFormedDTD::ConvertEntityToUnicode(const nsAReadableString& aEntity,
|
||||
PRInt32* aUnicode) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag is itself a container
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aTag -- tag to test for containership
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
PRBool CWellFormedDTD::IsContainer(PRInt32 aTag) const{
|
||||
PRBool result=PR_TRUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update vidur 11/12/98
|
||||
* @param aToken -- token object to be put into content model
|
||||
* @return 0 if all is well; non-zero is an error
|
||||
*/
|
||||
NS_IMETHODIMP CWellFormedDTD::HandleToken(CToken* aToken,nsIParser* aParser) {
|
||||
nsresult result=NS_OK;
|
||||
CHTMLToken* theToken= (CHTMLToken*)(aToken);
|
||||
eHTMLTokenTypes theType= (eHTMLTokenTypes)theToken->GetTokenType();
|
||||
|
||||
mParser=(nsParser*)aParser;
|
||||
mSink=aParser->GetContentSink();
|
||||
|
||||
switch(theType) {
|
||||
|
||||
case eToken_newline:
|
||||
mLineNumber++; //now fall through
|
||||
case eToken_entity:
|
||||
case eToken_whitespace:
|
||||
case eToken_text:
|
||||
case eToken_cdatasection:
|
||||
case eToken_markupDecl:
|
||||
result=HandleLeafToken(aToken);
|
||||
break;
|
||||
case eToken_comment:
|
||||
result=HandleCommentToken(aToken);
|
||||
break;
|
||||
case eToken_instruction:
|
||||
result=HandleProcessingInstructionToken(aToken);
|
||||
break;
|
||||
case eToken_start:
|
||||
result=HandleStartToken(aToken);
|
||||
break;
|
||||
case eToken_end:
|
||||
result=HandleEndToken(aToken);
|
||||
break;
|
||||
case eToken_error:
|
||||
result=HandleErrorToken(aToken);
|
||||
break;
|
||||
case eToken_doctypeDecl:
|
||||
result=HandleDocTypeDeclToken(aToken);
|
||||
break;
|
||||
case eToken_style:
|
||||
case eToken_skippedcontent:
|
||||
default:
|
||||
result=NS_OK;
|
||||
}//switch
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a leaf token has been
|
||||
* encountered in the parse process.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleLeafToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenizer->GetTokenAllocator());
|
||||
result= (mSink)? mSink->AddLeaf(theNode):NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a comment token has been
|
||||
* encountered in the parse process. Here we also make sure
|
||||
* to count the newlines in the comment.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleCommentToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
CCommentToken* theToken = (CCommentToken*)aToken;
|
||||
mLineNumber += CountCharInReadable(theToken->GetStringValue(),
|
||||
PRUnichar(kNewLine));
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenizer->GetTokenAllocator());
|
||||
result=(mSink)? mSink->AddComment(theNode):NS_OK;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a prcessing instruction
|
||||
* has been encountered in the parse process.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleProcessingInstructionToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenizer->GetTokenAllocator());
|
||||
result=(mSink)? mSink->AddProcessingInstruction(theNode):NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a start token has been
|
||||
* encountered in the parse process.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next (start) token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleStartToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenizer->GetTokenAllocator());
|
||||
PRInt16 attrCount=aToken->GetAttributeCount();
|
||||
|
||||
if(0<attrCount){ //go collect the attributes...
|
||||
int attr=0;
|
||||
for(attr=0;attr<attrCount;attr++){
|
||||
CToken* theInnerToken= (mTokenizer)? mTokenizer->PeekToken():nsnull;
|
||||
if(theInnerToken) {
|
||||
eHTMLTokenTypes theInnerType=eHTMLTokenTypes(theInnerToken->GetTokenType());
|
||||
if(eToken_attribute==theInnerType){
|
||||
mTokenizer->PopToken(); //pop it for real...
|
||||
theNode.AddAttribute(theInnerToken);
|
||||
}
|
||||
}
|
||||
else return kEOF;
|
||||
}
|
||||
}
|
||||
|
||||
// Pass the ID Attribute atom from the start token to the parser node
|
||||
CStartToken* startToken = NS_STATIC_CAST(CStartToken *, aToken);
|
||||
nsCOMPtr<nsIAtom> IDAttr=nsnull;
|
||||
result = startToken->GetIDAttributeAtom(getter_AddRefs(IDAttr));
|
||||
if (IDAttr && NS_SUCCEEDED(result))
|
||||
result = theNode.SetIDAttributeAtom(IDAttr);
|
||||
|
||||
if(NS_OK==result){
|
||||
if(mSink) {
|
||||
result=mSink->OpenContainer(theNode);
|
||||
if(((CStartToken*)aToken)->IsEmpty()){
|
||||
result=mSink->CloseContainer(theNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when an end token has been
|
||||
* encountered in the parse process.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next (end) token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleEndToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenizer->GetTokenAllocator());
|
||||
result=(mSink)? mSink->CloseContainer(theNode):NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when an error token has been
|
||||
* encountered in the parse process.
|
||||
* FYI: when the document is malformed this is the only
|
||||
* token that will get reported to the content sink.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleErrorToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
nsresult result=NS_OK;
|
||||
|
||||
if(mTokenizer) {
|
||||
// Cycle through the remaining tokens in the token stream and handle them
|
||||
// These tokens were added so that content objects for the error message
|
||||
// are generated by the content sink
|
||||
while (PR_TRUE) {
|
||||
CToken* token = mTokenizer->PopToken();
|
||||
if(token) {
|
||||
eHTMLTokenTypes type = (eHTMLTokenTypes) token->GetTokenType();
|
||||
switch(type) {
|
||||
case eToken_newline:
|
||||
mLineNumber++; //now fall through
|
||||
case eToken_whitespace:
|
||||
case eToken_text:
|
||||
HandleLeafToken(token);
|
||||
break;
|
||||
case eToken_start:
|
||||
HandleStartToken(token);
|
||||
break;
|
||||
case eToken_end:
|
||||
HandleEndToken(token);
|
||||
break;
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
IF_FREE(token, mTokenizer->GetTokenAllocator());
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Propagate the error onto the content sink.
|
||||
CErrorToken *errTok = (CErrorToken *)aToken;
|
||||
const nsParserError* error = errTok->GetError();
|
||||
result=(mSink)? mSink->NotifyError(error):NS_OK;
|
||||
|
||||
// Output the error to the console
|
||||
if (error) {
|
||||
nsCAutoString temp;
|
||||
|
||||
temp.AssignWithConversion(mFilename);
|
||||
|
||||
PR_fprintf(PR_STDOUT, "XML Error in file '%s', ", temp.get());
|
||||
|
||||
PR_fprintf(PR_STDOUT, "Line Number: %d, ", error->lineNumber);
|
||||
PR_fprintf(PR_STDOUT, "Col Number: %d, ", error->colNumber);
|
||||
|
||||
temp.AssignWithConversion(error->description);
|
||||
|
||||
PR_fprintf(PR_STDOUT, "Description: %s\n", temp.get());
|
||||
|
||||
temp.AssignWithConversion(error->sourceLine);
|
||||
|
||||
PR_fprintf(PR_STDOUT, "Source Line: %s\n", temp.get());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a doc. type token has been
|
||||
* encountered in the parse process.
|
||||
*
|
||||
* @update harishd 08/18/99
|
||||
*
|
||||
* @param aToken -- next token to be handled
|
||||
* @return NS_OK if all went well; NS_ERROR_XXX if error occured
|
||||
*/
|
||||
|
||||
nsresult CWellFormedDTD::HandleDocTypeDeclToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,"null token");
|
||||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenizer->GetTokenAllocator());
|
||||
result = (mSink)? mSink->AddDocTypeDecl(theNode, 0):NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1,271 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
/**
|
||||
* MODULE NOTES:
|
||||
* @update gess 4/8/98
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __NS_WELLFORMED_DTD
|
||||
#define __NS_WELLFORMED_DTD
|
||||
|
||||
#include "nsIDTD.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsHTMLTokens.h"
|
||||
#include "nsIContentSink.h"
|
||||
|
||||
#define NS_WELLFORMED_DTD_IID \
|
||||
{0xa39c6bfd, 0x15f0, 0x11d2, \
|
||||
{0x80, 0x41, 0x0, 0x10, 0x4b, 0x98, 0x3f, 0xd4}}
|
||||
|
||||
|
||||
class nsIDTDDebug;
|
||||
class nsIParserNode;
|
||||
class nsParser;
|
||||
class nsHTMLTokenizer;
|
||||
|
||||
|
||||
class CWellFormedDTD : public nsIDTD
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 4/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
CWellFormedDTD();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 4/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual ~CWellFormedDTD();
|
||||
|
||||
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const;
|
||||
|
||||
/**
|
||||
* Call this method if you want the DTD to construct a clone of itself.
|
||||
* @update gess7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD CreateNewInstance(nsIDTD** aInstancePtrResult);
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can parse
|
||||
* a document in a given source-type.
|
||||
* NOTE: Parsing always assumes that the end result will involve
|
||||
* storing the result in the main content model.
|
||||
* @update gess6/24/98
|
||||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
NS_IMETHOD_(eAutoDetectResult) CanParse(CParserContext& aParserContext,
|
||||
const nsString& aBuffer,
|
||||
PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update rickg 03.20.2000
|
||||
* @param aParserContext
|
||||
* @param aSink
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext,
|
||||
nsIContentSink* aSink);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param aFilename is the name of the file being parsed.
|
||||
* @return error code (almost always 0)
|
||||
*/
|
||||
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer,
|
||||
nsITokenObserver* anObserver = nsnull,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
* calls DidBuildModel().
|
||||
* @update gess5/18/98
|
||||
* @param anErrorCode contans the last error that occured
|
||||
* @return error code
|
||||
*/
|
||||
NS_IMETHOD DidBuildModel(nsresult anErrorCode, PRBool aNotifySink,
|
||||
nsIParser* aParser,
|
||||
nsIContentSink* aSink = nsnull);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aToken -- token object to be put into content model
|
||||
* @return 0 if all is well; non-zero is an error
|
||||
*/
|
||||
NS_IMETHOD HandleToken(CToken* aToken, nsIParser* aParser);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 12/20/99
|
||||
* @param ptr-ref to (out) tokenizer
|
||||
* @return nsresult
|
||||
*/
|
||||
NS_IMETHOD GetTokenizer(nsITokenizer*& aTokenizer);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD WillResumeParse(void);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD WillInterruptParse(void);
|
||||
|
||||
/**
|
||||
* Set this to TRUE if you want the DTD to verify its
|
||||
* context stack.
|
||||
* @update gess 7/23/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual void SetVerification(PRBool aEnable);
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- int tag of parent container
|
||||
* @param aChild -- int tag of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent, PRInt32 aChild) const;
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag is itself a container
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aTag -- tag to test for containership
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const;
|
||||
|
||||
/**
|
||||
* Retrieve a ptr to the global token recycler...
|
||||
* @update gess8/4/98
|
||||
* @return ptr to recycler (or null)
|
||||
*/
|
||||
NS_IMETHOD_(nsTokenAllocator *) GetTokenAllocator(void);
|
||||
|
||||
/**
|
||||
* Use this id you want to stop the building content model
|
||||
* --------------[ Sets DTD to STOP mode ]----------------
|
||||
* It's recommended to use this method in accordance with
|
||||
* the parser's terminate() method.
|
||||
*
|
||||
* @update harishd 07/22/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMETHOD Terminate(nsIParser* aParser = nsnull);
|
||||
|
||||
/**
|
||||
* Give rest of world access to our tag enums, so that CanContain(), etc,
|
||||
* become useful.
|
||||
*/
|
||||
NS_IMETHOD StringTagToIntTag(const nsAReadableString &aTag,
|
||||
PRInt32* aIntTag) const;
|
||||
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const;
|
||||
|
||||
NS_IMETHOD ConvertEntityToUnicode(const nsAReadableString& aEntity,
|
||||
PRInt32* aUnicode) const;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
protected:
|
||||
/*
|
||||
NS_IMETHODIMP ConsumeTag(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeStartTag(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeText(const nsString& aString,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeNewline(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeWhitespace(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeEscapedContent(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeComment(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeEntity(PRUnichar aChar,nsScanner& aScanner,CToken*& aToken);
|
||||
NS_IMETHODIMP ConsumeAttributes(PRUnichar aChar,nsScanner& aScanner,CStartToken* aToken);
|
||||
*/
|
||||
nsresult HandleStartToken(CToken* aToken);
|
||||
nsresult HandleEndToken(CToken* aToken);
|
||||
nsresult HandleCommentToken(CToken* aToken);
|
||||
nsresult HandleErrorToken(CToken* aToken);
|
||||
nsresult HandleDocTypeDeclToken(CToken* aToken);
|
||||
nsresult HandleLeafToken(CToken* aToken);
|
||||
nsresult HandleProcessingInstructionToken(CToken* aToken);
|
||||
|
||||
nsParser* mParser;
|
||||
nsIContentSink* mSink;
|
||||
nsString mFilename;
|
||||
PRInt32 mLineNumber;
|
||||
nsHTMLTokenizer* mTokenizer;
|
||||
nsresult mDTDState;
|
||||
};
|
||||
|
||||
extern nsresult NS_NewWellFormed_DTD(nsIDTD** aInstancePtrResult);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -125,11 +125,11 @@ SetupRegistry(void)
|
|||
nsComponentManager::RegisterComponent(kIOServiceCID, NULL, NULL, NETLIB_DLL, PR_FALSE, PR_FALSE);
|
||||
|
||||
// parser
|
||||
static NS_DEFINE_CID(kParserCID, NS_PARSER_CID);
|
||||
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
|
||||
static NS_DEFINE_CID(kParserCID, NS_PARSER_CID);
|
||||
static NS_DEFINE_IID(kExpatDriverCID, NS_EXPAT_DRIVER_CID);
|
||||
|
||||
nsComponentManager::RegisterComponent(kParserCID, NULL, NULL, PARSER_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kWellFormedDTDCID, NULL, NULL, PARSER_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kParserCID, NULL, NULL, PARSER_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kExpatDriverCID, NULL, NULL, PARSER_DLL, PR_FALSE, PR_FALSE);
|
||||
|
||||
// layout
|
||||
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
||||
|
|
Загрузка…
Ссылка в новой задаче