From 55694b4cadf476b755470a442d4e13fb60fe40bf Mon Sep 17 00:00:00 2001 From: "jaggernaut%netscape.com" Date: Tue, 26 Jun 2001 05:22:23 +0000 Subject: [PATCH] Bug 78458: ``Remove our broken text/rtf support'', patch by Boris Zbarsky , r=harishd, sr=jst --- content/build/nsContentDLF.cpp | 1 - htmlparser/src/CNavDTD.cpp | 3 - htmlparser/src/COtherDTD.cpp | 3 - htmlparser/src/CRtfDTD.cpp | 1206 ----------------- htmlparser/src/CRtfDTD.h | 359 ----- htmlparser/src/MANIFEST | 1 - htmlparser/src/nsIParser.h | 1 - htmlparser/src/nsParserCIID.h | 3 - layout/build/nsContentDLF.cpp | 1 - layout/build/nsLayoutDLF.cpp | 1 - netwerk/mime/public/nsMimeTypes.h | 2 - netwerk/mime/src/nsXMLMIMEDataSource.cpp | 8 - parser/htmlparser/src/CNavDTD.cpp | 3 - parser/htmlparser/src/COtherDTD.cpp | 3 - parser/htmlparser/src/CRtfDTD.cpp | 1206 ----------------- parser/htmlparser/src/CRtfDTD.h | 359 ----- parser/htmlparser/src/MANIFEST | 1 - parser/htmlparser/src/nsIParser.h | 1 - parser/htmlparser/src/nsParserCIID.h | 3 - .../exthandler/nsExternalHelperAppService.cpp | 2 - 20 files changed, 3167 deletions(-) delete mode 100644 htmlparser/src/CRtfDTD.cpp delete mode 100644 htmlparser/src/CRtfDTD.h delete mode 100644 parser/htmlparser/src/CRtfDTD.cpp delete mode 100644 parser/htmlparser/src/CRtfDTD.h diff --git a/content/build/nsContentDLF.cpp b/content/build/nsContentDLF.cpp index c33447b204ad..c21765bbbe0b 100644 --- a/content/build/nsContentDLF.cpp +++ b/content/build/nsContentDLF.cpp @@ -58,7 +58,6 @@ extern nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult); static char* gHTMLTypes[] = { "text/html", "text/plain", - "text/rtf", "text/css", 0 }; diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index 8190603af981..b6414f2ad1d3 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -346,9 +346,6 @@ eAutoDetectResult CNavDTD::CanParse(CParserContext& aParserContext,nsString& aBu if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kPlainTextContentType)) { result=ePrimaryDetect; } - else if(aParserContext.mMimeType.EqualsWithConversion(kRTFTextContentType)){ - result=ePrimaryDetect; - } } else { if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kHTMLTextContentType)) { diff --git a/htmlparser/src/COtherDTD.cpp b/htmlparser/src/COtherDTD.cpp index 672a26384d6c..dffe44817436 100644 --- a/htmlparser/src/COtherDTD.cpp +++ b/htmlparser/src/COtherDTD.cpp @@ -292,9 +292,6 @@ eAutoDetectResult COtherDTD::CanParse(CParserContext& aParserContext,nsString& a if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kPlainTextContentType)) { result=eValidDetect; } - else if(aParserContext.mMimeType.EqualsWithConversion(kRTFTextContentType)){ - result=eValidDetect; - } } else { if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kPlainTextContentType)) { diff --git a/htmlparser/src/CRtfDTD.cpp b/htmlparser/src/CRtfDTD.cpp deleted file mode 100644 index 0b12cf5cc7b3..000000000000 --- a/htmlparser/src/CRtfDTD.cpp +++ /dev/null @@ -1,1206 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * 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 1/31/00 - * - * - */ - - -#include "nsIDTDDebug.h" -#include "CRtfDTD.h" -#include "nsCRT.h" -#include "nsParser.h" -#include "nsScanner.h" -#include "nsIParser.h" -#include "nsTokenHandler.h" -#include "nsITokenizer.h" -#include "nsIHTMLContentSink.h" -#include "nsHTMLEntities.h" -#include "nsDTDUtils.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 "nsDebug.h" - -#include "prmem.h" - - -static NS_DEFINE_IID(kIHTMLContentSinkIID, NS_IHTML_CONTENT_SINK_IID); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); -static NS_DEFINE_IID(kClassIID, NS_RTF_DTD_IID); -static NS_DEFINE_IID(kITokenizerIID,NS_ITOKENIZER_IID); - - -static const char* kRTFDocHeader= "{\\rtf0"; - - -class nsRTFTokenizer: public nsITokenizer { -public: - nsRTFTokenizer(); - virtual ~nsRTFTokenizer(); - - 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: - - nsDeque mTokenDeque; - nsTokenAllocator* mTokenAllocator; -}; - - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -class CRTFGroup { -public: - CRTFGroup() { - nsCRT::zero(mContainers,sizeof(mContainers)); - mColor=0; - } - - PRBool mContainers[eRTFCtrl_last]; - PRInt32 mColor; -}; - - - -/** - * This method is defined in nsRTFTokenizer.h. It is used to - * cause the COM-like construction of an RTFTokenizer. - * - * @update gess 1/31/00 - * @param nsIParser** ptr to newly instantiated parser - * @return NS_xxx error result - */ - -nsresult NS_NewRTFTokenizer(nsITokenizer** aInstancePtrResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsRTFTokenizer* it = new nsRTFTokenizer(); - if (nsnull == it) { - return NS_ERROR_OUT_OF_MEMORY; - } - return it->QueryInterface(kClassIID, (void **) aInstancePtrResult); -} - - - -struct RTFEntry { - char mName[10]; - eRTFTags mTagID; -}; - -#if 1 -static RTFEntry gRTFTable[] = { - - {"$",eRTFCtrl_unknown}, - {"'",eRTFCtrl_quote}, - {"*",eRTFCtrl_star}, - {"0x0a",eRTFCtrl_linefeed}, - {"0x0d",eRTFCtrl_return}, - {"\\",eRTFCtrl_begincontrol}, - {"ansi",eRTFCtrl_ansi}, - {"b",eRTFCtrl_bold}, - {"bin",eRTFCtrl_bin}, - {"blue",eRTFCtrl_blue}, - {"cols",eRTFCtrl_cols}, - {"comment",eRTFCtrl_comment}, - {"f",eRTFCtrl_font}, - {"fonttbl",eRTFCtrl_fonttable}, - {"green",eRTFCtrl_green}, - {"i",eRTFCtrl_italic}, - {"margb",eRTFCtrl_bottommargin}, - {"margl",eRTFCtrl_leftmargin}, - {"margr",eRTFCtrl_rightmargin}, - {"margt",eRTFCtrl_topmargin}, - {"par",eRTFCtrl_par}, - {"pard",eRTFCtrl_pard}, - {"plain",eRTFCtrl_plain}, - {"qc",eRTFCtrl_justified}, - {"qj",eRTFCtrl_fulljustified}, - {"ql",eRTFCtrl_leftjustified}, - {"qr",eRTFCtrl_rightjustified}, - {"rdblquote",eRTFCtrl_rdoublequote}, - {"red",eRTFCtrl_red}, - {"rtf",eRTFCtrl_rtf}, - {"tab",eRTFCtrl_tab}, - {"title",eRTFCtrl_title}, - {"u",eRTFCtrl_underline}, - {"{",eRTFCtrl_startgroup}, - {"}",eRTFCtrl_endgroup}, - {"~",eRTFCtrl_last} //make sure this stays the last token... -}; - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -#if 0 -static const char* GetTagName(eRTFTags aTag) { - PRInt32 cnt=sizeof(gRTFTable)/sizeof(RTFEntry); - PRInt32 low=0; - PRInt32 high=cnt-1; - PRInt32 middle=kNotFound; - - while(low<=high) { - middle=(PRInt32)(low+high)/2; - if(aTag==gRTFTable[middle].mTagID) - return gRTFTable[middle].mName; - if(aTagQueryInterface(kClassIID, (void **) aInstancePtrResult); -} - - -NS_IMPL_ADDREF(CRtfDTD) -NS_IMPL_RELEASE(CRtfDTD) - - -/** - * Default constructor - * - * @update gess 1/31/00 - * @param - * @return - */ -CRtfDTD::CRtfDTD() : nsIDTD(), mGroups(0) { - NS_INIT_REFCNT(); - mParser=0; - mFilename=0; - mTokenizer=0; - mHasHeader=PR_FALSE; - mSink=0; -} - -/** - * Default destructor - * - * @update gess 1/31/00 - * @param - * @return - */ -CRtfDTD::~CRtfDTD(){ -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -const nsIID& CRtfDTD::GetMostDerivedIID(void) const{ - return kClassIID; -} - -/** - * Call this method if you want the DTD to construct fresh instance - * of itself. - * @update gess 1/31/00 - * @param - * @return - */ -nsresult CRtfDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){ - return NS_NewRTF_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 gess 1/31/00 - * @param - * @return TRUE if this DTD can satisfy the request; FALSE otherwise. - */ -eAutoDetectResult CRtfDTD::CanParse(CParserContext& aParserContext,nsString& aBuffer, PRInt32 aVersion) { - eAutoDetectResult result=eUnknownDetect; - - if(eViewSource!=aParserContext.mParserCommand) { - if(aParserContext.mMimeType.EqualsWithConversion(kRTFTextContentType)) { - result=ePrimaryDetect; - } - else if(kNotFound!=aBuffer.Find(kRTFDocHeader)) { - result=ePrimaryDetect; - } - } - 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 CRtfDTD::WillBuildModel( const CParserContext& aParserContext,nsIContentSink* aSink){ - - nsresult result=NS_OK; - mGroupCount=0; - - - if((!aParserContext.mPrevContext) && (aSink)) { - - if(aSink && (!mSink)) { - result=aSink->QueryInterface(kIHTMLContentSinkIID, (void **)&mSink); - } - - if(result==NS_OK) { - result = aSink->WillBuildModel(); - - } - } - - - 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/31/00 - * @param aFilename is the name of the file being parsed. - * @return error code (almost always 0) - */ -NS_IMETHODIMP CRtfDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITokenObserver* anObserver,nsIContentSink* aSink) { - nsresult result=NS_OK; - - if(aTokenizer) { - nsITokenizer* oldTokenizer=mTokenizer; - mTokenizer=aTokenizer; - mParser=(nsParser*)aParser; - - if(mTokenizer) { - - if(aSink) { - - do { - -#if 0 - int n=aTokenizer->GetCount(); - if(n>50) n=50; - for(int i=0;iGetTokenAt(i); - printf("\nToken[%i],%p",i,theToken); - } - printf("\n"); -#endif - - CToken* theToken=mTokenizer->PopToken(); - if(theToken) { - result=HandleToken(theToken,aParser); - } - else break; - } while(NS_SUCCEEDED(result) && mGroups.GetSize()); - - mTokenizer=oldTokenizer; - } - } - } - else result=NS_ERROR_HTMLPARSER_BADTOKENIZER; - return result; -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -NS_IMETHODIMP CRtfDTD::DidBuildModel(nsresult anErrorCode,PRInt32 aLevel,nsIParser* aParser,nsIContentSink* aSink){ - nsresult result=NS_OK; - - CloseContainer(eHTMLTag_pre); - CloseContainer(eHTMLTag_body); - CloseContainer(eHTMLTag_html); - - if(mSink) mSink->DidBuildModel(0); - - return result; -} - -/** - * Retrieve the preferred tokenizer for use by this DTD. - * @update gess 1/31/00 - * @param none - * @return ptr to tokenizer - */ -nsresult CRtfDTD::GetTokenizer(nsITokenizer*& aTokenizer) { - nsresult result=NS_OK; - if(!mTokenizer) { - result=NS_NewRTFTokenizer(&mTokenizer); - } - aTokenizer=mTokenizer; - return result; -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -nsresult CRtfDTD::WillResumeParse(void){ - return NS_OK; -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -nsresult CRtfDTD::WillInterruptParse(void){ - return NS_OK; -} - -/** - * Called by the parser to initiate dtd verification of the - * internal context stack. - * @update gess 1/31/00 - * @param - * @return - */ -PRBool CRtfDTD::Verify(nsString& aURLRef,nsIParser* aParser){ - PRBool result=PR_TRUE; - mParser=(nsParser*)aParser; - return result; -} - -/** - * Called by the parser to enable/disable dtd verification of the - * internal context stack. - * @update gess 1/31/00 - * @param - * @return - */ -void CRtfDTD::SetVerification(PRBool aEnabled){ -} - -/** - * This method gets called to determine whether a given - * tag is itself a container - * - * @update gess 1/31/00 - * @param aTag -- tag to test for containership - * @return PR_TRUE if given tag can contain other tags - */ -PRBool CRtfDTD::IsContainer(PRInt32 aTag) const{ - PRBool result=PR_FALSE; - return result; -} - - -/** - * This method is called to determine whether or not a tag - * of one type can contain a tag of another type. - * - * @update gess 1/31/00 - * @param aParent -- int tag of parent container - * @param aChild -- int tag of child container - * @return PR_TRUE if parent can contain child - */ -PRBool CRtfDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const{ - PRBool result=PR_FALSE; - return result; -} - -/** - * Give rest of world access to our tag enums, so that CanContain(), etc, - * become useful. - */ -NS_IMETHODIMP CRtfDTD::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const { - *aIntTag = nsHTMLTags::LookupTag(aTag); - return NS_OK; -} - -NS_IMETHODIMP CRtfDTD::IntTagToStringTag(PRInt32 aIntTag, nsString& aTag) const { - aTag.AssignWithConversion(nsHTMLTags::GetStringValue((nsHTMLTag)aIntTag)); - return NS_OK; -} - -NS_IMETHODIMP CRtfDTD::ConvertEntityToUnicode(const nsString& aEntity, PRInt32* aUnicode) const { - *aUnicode = nsHTMLEntities::EntityToUnicode(aEntity); - return NS_OK; -} - - -/** - * - * @update gess 1/31/00 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::PushGroup(){ - nsresult result=NS_OK; - - CRTFGroup* theGroup=new CRTFGroup(); - if(theGroup) - mGroups.Push(theGroup); - else result=NS_ERROR_OUT_OF_MEMORY; - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::PopGroup(){ - nsresult result=NS_OK; - - CRTFGroup* theGroup=(CRTFGroup*)mGroups.Pop(); - if(theGroup) - delete theGroup; - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aTag -- text containing the tag to open - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::AddLeafContainer(eHTMLTags aTag,const char* aTagName){ - nsresult result=NS_OK; - - if(mSink) { - nsAutoString theStr; theStr.AssignWithConversion(aTagName); - CStartToken theToken(theStr,aTag); - nsCParserNode theNode(&theToken); - - switch(aTag) { - case eHTMLTag_br: - default: - result=mSink->AddLeaf(theNode); - break; - } - } - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aTag -- text containing the tag to open - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::OpenContainer(eHTMLTags aTag,const char* aTagName){ - nsresult result=NS_OK; - - if(mSink) { - nsAutoString theStr; theStr.AssignWithConversion(aTagName); - CStartToken theToken(theStr,aTag); - nsCParserNode theNode(&theToken); - - switch(aTag) { - case eHTMLTag_html: - mSink->OpenHTML(theNode); - break; - case eHTMLTag_body: - mSink->OpenBody(theNode); - break; - default: - mSink->OpenContainer(theNode); - break; - } - } - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aTag -- text containing the tag to close - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::CloseContainer(eHTMLTags aTag){ - nsresult result=NS_OK; - - if(mSink) { - CEndToken theToken(aTag); - nsCParserNode theNode(&theToken); - - switch(aTag) { - case eHTMLTag_html: - mSink->CloseHTML(theNode); - break; - case eHTMLTag_body: - mSink->CloseBody(theNode); - break; - case eHTMLTag_p: - break; - default: - mSink->CloseContainer(theNode); - break; - } - } - - return result; -} - - -/** - * - * @update gess 1/31/00 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::EmitStyleContainer(CToken* aToken,eRTFTags aTag,PRBool aState){ - nsresult result=NS_OK; - - const char* theTag=0; - eHTMLTags theID=eHTMLTag_unknown; - - switch(aTag) { - case eRTFCtrl_bold: - theTag="b"; - theID=eHTMLTag_b; - break; - case eRTFCtrl_italic: - theTag="i"; - theID=eHTMLTag_i; - break; - case eRTFCtrl_underline: - theTag="u"; - theID=eHTMLTag_u; - break; - case eRTFCtrl_plain: - result=EmitStyleContainer(aToken,eRTFCtrl_bold,PR_FALSE); - result=EmitStyleContainer(aToken,eRTFCtrl_italic,PR_FALSE); - result=EmitStyleContainer(aToken,eRTFCtrl_underline,PR_FALSE); - break; - default: - break; - } //switch - - CRTFGroup* theGroup=(CRTFGroup*)mGroups.ObjectAt(mGroups.GetSize()-1); - - if(aState) { - if(!theGroup->mContainers[aTag]) { - result=OpenContainer(theID,theTag); - theGroup->mContainers[aTag]=PR_TRUE; - } - } - else { - if(theGroup->mContainers[aTag]) { - result=CloseContainer(theID); - theGroup->mContainers[aTag]=PR_FALSE; - } - } - - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::HandleControlWord(CToken* aToken){ - nsresult result=NS_OK; - - eRTFTags theTag=(eRTFTags)aToken->GetTypeID(); - - switch(theTag) { - case eRTFCtrl_startgroup: - PushGroup(); - break; - case eRTFCtrl_endgroup: - PopGroup(); - break; - case eRTFCtrl_rtf: - mHasHeader=PR_TRUE; - OpenContainer(eHTMLTag_html,"html"); - OpenContainer(eHTMLTag_body,"body"); - OpenContainer(eHTMLTag_pre,"pre"); - break; - default: - if(mGroups.GetSize() && mHasHeader) { - - CRTFControlWord* theToken=(CRTFControlWord*)aToken; - - switch(theTag) { - case eRTFCtrl_ansi: - break; - case eRTFCtrl_tab: - { - CTextToken theToken2( NS_LITERAL_STRING(" ") ); - result=HandleContent(&theToken2); - } - break; - case eRTFCtrl_bold: - case eRTFCtrl_italic: - case eRTFCtrl_underline: - case eRTFCtrl_plain: - result=EmitStyleContainer(theToken,theTag,theToken->mArgument.CharAt(0)!='0'); - break; - case eRTFCtrl_par: - AddLeafContainer(eHTMLTag_br,"br"); - break; - default: - break; //just drop it on the floor. - } - } - break; - } -// PushGroup(); - - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::HandleContent(CToken* aToken){ - nsresult result=NS_OK; - - if(mSink) { - CTextToken theToken(aToken->GetStringValueXXX()); - nsCParserNode theNode(&theToken); - mSink->AddLeaf(theNode); - } - - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::HandleToken(CToken* aToken,nsIParser* aParser) { - nsresult result=NS_OK; - - mParser=(nsParser*)aParser; - if(aToken) { - eRTFTokenTypes theType=eRTFTokenTypes(aToken->GetTokenType()); - - switch(theType) { - - case eRTFToken_controlword: - result=HandleControlWord(aToken); break; - - case eRTFToken_content: - case eToken_newline: - case eHTMLTag_text: - result=HandleContent(aToken); break; - - default: - break; - //everything else is just text or attributes of controls... - } - - }//if - - return result; -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -nsTokenAllocator* CRtfDTD::GetTokenAllocator(void){ - 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. - * - * @update harishd 07/22/99 - * @update gess 1/31/00 - * @param - * @return - */ -nsresult CRtfDTD::Terminate(nsIParser* aParser) -{ - return NS_ERROR_HTMLPARSER_STOPPARSING; -} - -/*************************************************************** - Heres's the RTFControlWord subclass... - ***************************************************************/ - - -CRTFControlWord::CRTFControlWord(eRTFTags aTagID) : CToken(aTagID) { -} - -/** - * - * @update gess 1/31/00 - * @param - * @return 0 if all is well; non-zero is an error - */ -PRInt32 CRTFControlWord::GetTokenType() { - return eRTFToken_controlword; -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -nsresult CRTFControlWord::Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode) { - const char* gAlphaChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - const char* gDigits="-0123456789"; - - //First, decide if it's a control word or a control symbol (1 char) - PRUnichar theChar=0; - nsresult result=aScanner.Peek(theChar); - - if(NS_SUCCEEDED(result)) { - if(('a'<=theChar) && (theChar<='z')) { - nsAutoString temp; temp.AssignWithConversion(gAlphaChars); - result=aScanner.ReadWhile(mTextValue,temp,PR_FALSE); - if(NS_OK==result) { - //ok, now look for an option parameter... - - mTypeID=GetTagID(mTextValue); - result=aScanner.Peek(theChar); - - switch(theChar) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - case kMinus: - { - nsAutoString theDigits; theDigits.AssignWithConversion(gDigits); - result=aScanner.ReadWhile(mArgument,theDigits,PR_FALSE); - } - break; - - case kSpace: - default: - break; - } - } - if(NS_OK==result) - result=aScanner.SkipWhitespace(); - } - else { - //it's a control symbol - } - } - return result; -} - - -/*************************************************************** - Heres's the RTFContent subclass... - ***************************************************************/ - - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -CRTFContent::CRTFContent(PRUnichar* aKey) : CToken(nsAutoString(aKey)) { -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -PRInt32 CRTFContent::GetTokenType() { - return eRTFToken_content; -} - - - -/** - * We're supposed to read text until we encounter one - * of the RTF control characters: \.{,}. - * @update gess 1/31/00 - * @param - * @return - */ - -nsresult CRTFContent::Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode) { - static const char* textTerminators="\\{}\r\n"; - mTextValue.Append(aChar); - PRInt32 result=aScanner.ReadUntil(mTextValue,textTerminators,PR_FALSE); - if(NS_SUCCEEDED(result)) { - mTypeID=eHTMLTag_text; - } - return result; -} - -/*************************************************************** - Heres's the nsRTFTokenizer class... - ***************************************************************/ - - -/** - * 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 nsRTFTokenizer::QueryInterface(const nsIID& aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - - if(aIID.Equals(kISupportsIID)) { //do IUnknown... - *aInstancePtr = (nsISupports*)(this); - } - else if(aIID.Equals(kITokenizerIID)) { //do IParser base class... - *aInstancePtr = (nsITokenizer*)(this); - } - else if(aIID.Equals(kClassIID)) { //do this class... - *aInstancePtr = (nsRTFTokenizer*)(this); - } - else { - *aInstancePtr=0; - return NS_NOINTERFACE; - } - NS_ADDREF_THIS(); - return NS_OK; -} - -nsRTFTokenizer::nsRTFTokenizer() : mTokenDeque(0) { - NS_INIT_REFCNT(); -} - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -nsRTFTokenizer::~nsRTFTokenizer() { -} - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -nsresult nsRTFTokenizer::WillTokenize(PRBool aIsFinalChunk,nsTokenAllocator* aTokenAllocator) { - nsresult result=NS_OK; - mTokenAllocator=aTokenAllocator; - return result; -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -nsTokenAllocator* nsRTFTokenizer::GetTokenAllocator(void) { - //let's move to this once we eliminate the leaking of tokens... - return mTokenAllocator; -} - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -nsresult nsRTFTokenizer::ConsumeToken(nsScanner& aScanner,PRBool& aFlushTokens) { - nsresult result=NS_OK; - - PRUnichar theChar=0; - result=aScanner.GetChar(theChar); - if(NS_SUCCEEDED(result)) { - switch(theChar) { - case '}': - case '{': - { - eRTFTags theTag= ('{'==theChar) ? eRTFCtrl_startgroup : eRTFCtrl_endgroup; - CRTFControlWord* theToken=(CRTFControlWord*)mTokenAllocator->CreateRTFTokenOfType(eRTFToken_controlword,theTag); - - if(theToken) { - mTokenDeque.Push(theToken); - } - else result=NS_ERROR_OUT_OF_MEMORY; - } - break; - case '\\': - { - CRTFControlWord* theWord =(CRTFControlWord*)mTokenAllocator->CreateRTFTokenOfType(eRTFToken_controlword,eRTFCtrl_unknown); - if(theWord) { - result=theWord->Consume(theChar,aScanner,0); - if(NS_SUCCEEDED(result)) { - mTokenDeque.Push(theWord); - } - } - } - break; - case '\n': - case '\r': - { - CNewlineToken* theContent=(CNewlineToken*)mTokenAllocator->CreateTokenOfType(eToken_newline,eHTMLTag_newline); - if(theContent) { - result=theContent->Consume(theChar,aScanner,0); - if(NS_SUCCEEDED(result)) { - mTokenDeque.Push(theContent); - } - } - } - break; - default: - CRTFContent* theContent=(CRTFContent*)mTokenAllocator->CreateRTFTokenOfType(eRTFToken_content,(eRTFTags)0); - if(theContent) { - result=theContent->Consume(theChar,aScanner,0); - if(NS_SUCCEEDED(result)) { - mTokenDeque.Push(theContent); - } - } - break; - } - } - return result; -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -nsresult nsRTFTokenizer::DidTokenize(PRBool aIsFinalChunk) { - nsresult result=NS_OK; - return result; -} - - -/** - * This method provides access to the topmost token in the tokenDeque. - * The token is not really removed from the list. - * @update gess 1/31/00 - * @return ptr to token - */ -CToken* nsRTFTokenizer::PeekToken() { - return (CToken*)mTokenDeque.PeekFront(); -} - - -/** - * This method provides access to the topmost token in the tokenDeque. - * The token is really removed from the list; if the list is empty we return 0. - * @update gess 1/31/00 - * @return ptr to token or NULL - */ -CToken* nsRTFTokenizer::PopToken() { - CToken* result=nsnull; - result=(CToken*)mTokenDeque.PopFront(); - return result; -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -CToken* nsRTFTokenizer::PushTokenFront(CToken* theToken) { - mTokenDeque.PushFront(theToken); - return theToken; -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -CToken* nsRTFTokenizer::PushToken(CToken* theToken) { - mTokenDeque.Push(theToken); - return theToken; -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -PRInt32 nsRTFTokenizer::GetCount(void) { - return mTokenDeque.GetSize(); -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -CToken* nsRTFTokenizer::GetTokenAt(PRInt32 anIndex){ - return (CToken*)mTokenDeque.ObjectAt(anIndex); -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -void nsRTFTokenizer::PrependTokens(nsDeque& aDeque) { -} - - -NS_IMPL_ADDREF(nsRTFTokenizer) -NS_IMPL_RELEASE(nsRTFTokenizer) - - diff --git a/htmlparser/src/CRtfDTD.h b/htmlparser/src/CRtfDTD.h deleted file mode 100644 index 63245e56b318..000000000000 --- a/htmlparser/src/CRtfDTD.h +++ /dev/null @@ -1,359 +0,0 @@ - -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * 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_RTFDTD__ -#define NS_RTFDTD__ - -#include "nsIDTD.h" -#include "nsISupports.h" -#include "nsHTMLTokens.h" -#include "nshtmlpars.h" -#include "nsVoidArray.h" -#include "nsDeque.h" -#include "nsToken.h" - - -#define NS_RTF_DTD_IID \ - {0xa39c6bfc, 0x15f0, 0x11d2, \ - {0x80, 0x41, 0x00, 0x10, 0x4b, 0x98, 0x3f, 0xd4}} - -class nsIParserNode; -class nsParser; -class nsITokenizer; -class nsIHTMLContentSink; - -enum eRTFTokenTypes { - eRTFToken_unknown=0, - eRTFToken_group, // '{' - eRTFToken_controlword, // '\' - eRTFToken_content, // contains all document content - //everything else is just text or attributes of controls... - eRTFToken_last //make sure this stays the last token... -}; - - -enum eRTFTags { - eRTFCtrl_unknown=0, - eRTFCtrl_quote, - eRTFCtrl_star, - eRTFCtrl_linefeed, - eRTFCtrl_return, - eRTFCtrl_begincontrol, - eRTFCtrl_text, - eRTFCtrl_ansi, - eRTFCtrl_bold, - eRTFCtrl_bin, - eRTFCtrl_blue, - eRTFCtrl_cols, - eRTFCtrl_comment, - eRTFCtrl_italic, - eRTFCtrl_font, - eRTFCtrl_fonttable, - eRTFCtrl_green, - eRTFCtrl_bottommargin, - eRTFCtrl_leftmargin, - eRTFCtrl_rightmargin, - eRTFCtrl_topmargin, - eRTFCtrl_par, - eRTFCtrl_pard, - eRTFCtrl_plain, - eRTFCtrl_justified, - eRTFCtrl_fulljustified, - eRTFCtrl_leftjustified, - eRTFCtrl_rightjustified, - eRTFCtrl_rdoublequote, - eRTFCtrl_red, - eRTFCtrl_rtf, - eRTFCtrl_tab, - eRTFCtrl_title, - eRTFCtrl_underline, - eRTFCtrl_startgroup, // { - eRTFCtrl_endgroup, // } - eRTFCtrl_last //make sure this stays the last token... -}; - - - -/** - * Represents the token of RTF. Always has form \xxxxdelimiter - * - * @update gess7/8/98 - * @param - * @return - */ -class CRTFControlWord : public CToken { -public: - CRTFControlWord(eRTFTags aTagID); - virtual PRInt32 GetTokenType(); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - - eRTFTags mTag; - nsString mArgument; -}; - - -/** - * This represents the document content. - * - * @update gess7/8/98 - * @param - * @return - */ -class CRTFContent: public CToken { -public: - CRTFContent(PRUnichar* aKey=0); - virtual PRInt32 GetTokenType(); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); -}; - - -class CRtfDTD : public nsIDTD { - - public: - - NS_DECL_ISUPPORTS - - - /** - * - * - * @update gess 4/9/98 - * @param - * @return - */ - CRtfDTD(); - - /** - * - * - * @update gess 4/9/98 - * @param - * @return - */ - virtual ~CRtfDTD(); - - virtual 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 - */ - virtual nsresult 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. - */ - virtual eAutoDetectResult CanParse(CParserContext& aParserContext,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=0,nsIContentSink* aSink=0); - - /** - * 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,PRInt32 aLevel,nsIParser* aParser,nsIContentSink* aSink=0); - - /** - * - * @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 HandleControlWord(CToken* aToken); - - /** - * - * @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 HandleContent(CToken* aToken); - - /** - * - * @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); - - - /** - * Called by the parser to initiate dtd verification of the - * internal context stack. - * @update gess 7/23/98 - * @param - * @return - */ - virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); - - /** - * 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 - */ - virtual 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 - */ - virtual PRBool IsContainer(PRInt32 aTag) const; - - /** - * Retrieve a ptr to the global token recycler... - * @update gess8/4/98 - * @return ptr to recycler (or null) - */ - virtual 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 - */ - virtual nsresult Terminate(nsIParser* aParser=nsnull); - - /** - * Give rest of world access to our tag enums, so that CanContain(), etc, - * become useful. - */ - NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const; - - NS_IMETHOD IntTagToStringTag(PRInt32 aIntTag, nsString& aTag) const; - - NS_IMETHOD ConvertEntityToUnicode(const nsString& aEntity, PRInt32* aUnicode) const; - - virtual PRBool IsBlockElement(PRInt32 aTagID,PRInt32 aParentID) const {return PR_FALSE;} - virtual PRBool IsInlineElement(PRInt32 aTagID,PRInt32 aParentID) const {return PR_FALSE;} - - -protected: - - nsParser* mParser; - char* mFilename; - nsITokenizer* mTokenizer; - PRBool mHasHeader; - nsDeque mGroups; - PRInt32 mGroupCount; - nsIHTMLContentSink* mSink; - -private: - nsresult PushGroup(); - nsresult PopGroup(); - nsresult OpenContainer(eHTMLTags aTag,const char* aTagName); - nsresult CloseContainer(eHTMLTags aTag); - nsresult AddLeafContainer(eHTMLTags aTag,const char* aTagName); - nsresult EmitStyleContainer(CToken* aToken,eRTFTags aTag,PRBool aState); -}; - -extern NS_HTMLPARS nsresult NS_NewRTF_DTD(nsIDTD** aInstancePtrResult); - -#endif - - - diff --git a/htmlparser/src/MANIFEST b/htmlparser/src/MANIFEST index cb053e2ebfdb..ce7b04be86e2 100644 --- a/htmlparser/src/MANIFEST +++ b/htmlparser/src/MANIFEST @@ -15,7 +15,6 @@ nsToken.h nsIDTDDebug.h nsIDTD.h CNavDTD.h -CRtfDTD.h nsHTMLTags.h nsHTMLTagList.h nsParserCIID.h diff --git a/htmlparser/src/nsIParser.h b/htmlparser/src/nsIParser.h index bc21410892af..e8dbfe8113d2 100644 --- a/htmlparser/src/nsIParser.h +++ b/htmlparser/src/nsIParser.h @@ -374,7 +374,6 @@ const PRUnichar kNullCh = '\0'; #define kTextCSSContentType "text/css" #define kApplicationJSContentType "application/x-javascript" #define kTextJSContentType "text/javascript" -#define kRTFTextContentType "text/rtf" #define kSGMLTextContentType "text/sgml" diff --git a/htmlparser/src/nsParserCIID.h b/htmlparser/src/nsParserCIID.h index 3a7965f4856a..c2d5a680c873 100644 --- a/htmlparser/src/nsParserCIID.h +++ b/htmlparser/src/nsParserCIID.h @@ -65,9 +65,6 @@ #define NS_VIEWSOURCE_DTD_CID \ { 0x8323fad0, 0x2102, 0x11d4, { 0x81, 0x42, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } -// {8323FAD1-2102-11d4-8142-000064657374} -#define NS_CRTF_DTD_CID \ -{ 0x8323fad1, 0x2102, 0x11d4, { 0x81, 0x42, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } // {a6cf910f-15b3-11d2-932e-00805f8add32} diff --git a/layout/build/nsContentDLF.cpp b/layout/build/nsContentDLF.cpp index c33447b204ad..c21765bbbe0b 100644 --- a/layout/build/nsContentDLF.cpp +++ b/layout/build/nsContentDLF.cpp @@ -58,7 +58,6 @@ extern nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult); static char* gHTMLTypes[] = { "text/html", "text/plain", - "text/rtf", "text/css", 0 }; diff --git a/layout/build/nsLayoutDLF.cpp b/layout/build/nsLayoutDLF.cpp index 3108941eef41..582f61c10c9f 100644 --- a/layout/build/nsLayoutDLF.cpp +++ b/layout/build/nsLayoutDLF.cpp @@ -61,7 +61,6 @@ static NS_DEFINE_IID(kXULDocumentCID, NS_XULDOCUMENT_CID); static char* gHTMLTypes[] = { "text/html", "text/plain", - "text/rtf", "text/css", "text/javascript", "application/x-javascript", diff --git a/netwerk/mime/public/nsMimeTypes.h b/netwerk/mime/public/nsMimeTypes.h index f9f932663a8b..0ac4defc28a3 100644 --- a/netwerk/mime/public/nsMimeTypes.h +++ b/netwerk/mime/public/nsMimeTypes.h @@ -116,8 +116,6 @@ #define TEXT_XML "text/xml" #define TEXT_RDF "text/rdf" #define TEXT_XUL "application/vnd.mozilla.xul+xml" -#define TEXT_RTF "text/rtf" -#define TEXT_CPP "text/cpp" #define VIDEO_MPEG "video/mpeg" diff --git a/netwerk/mime/src/nsXMLMIMEDataSource.cpp b/netwerk/mime/src/nsXMLMIMEDataSource.cpp index c8808ab5f9bd..82933a024ff8 100644 --- a/netwerk/mime/src/nsXMLMIMEDataSource.cpp +++ b/netwerk/mime/src/nsXMLMIMEDataSource.cpp @@ -494,14 +494,6 @@ nsXMLMIMEDataSource::InitFromHack() { rv = AppendExtension(APPLICATION_POSTSCRIPT, "ai"); if (NS_FAILED(rv)) return rv; - - rv = AddMapping(TEXT_RTF, "rtf", "Rich Text Format", nsnull); - if (NS_FAILED(rv)) return rv; - - - rv = AddMapping(TEXT_CPP, "cpp", "CPP file", nsnull, 'TEXT','CWIE'); - if (NS_FAILED(rv)) return rv; - rv = AddMapping( "application/x-arj", "arj", "ARJ file", nsnull); if (NS_FAILED(rv)) return rv; diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp index 8190603af981..b6414f2ad1d3 100644 --- a/parser/htmlparser/src/CNavDTD.cpp +++ b/parser/htmlparser/src/CNavDTD.cpp @@ -346,9 +346,6 @@ eAutoDetectResult CNavDTD::CanParse(CParserContext& aParserContext,nsString& aBu if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kPlainTextContentType)) { result=ePrimaryDetect; } - else if(aParserContext.mMimeType.EqualsWithConversion(kRTFTextContentType)){ - result=ePrimaryDetect; - } } else { if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kHTMLTextContentType)) { diff --git a/parser/htmlparser/src/COtherDTD.cpp b/parser/htmlparser/src/COtherDTD.cpp index 672a26384d6c..dffe44817436 100644 --- a/parser/htmlparser/src/COtherDTD.cpp +++ b/parser/htmlparser/src/COtherDTD.cpp @@ -292,9 +292,6 @@ eAutoDetectResult COtherDTD::CanParse(CParserContext& aParserContext,nsString& a if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kPlainTextContentType)) { result=eValidDetect; } - else if(aParserContext.mMimeType.EqualsWithConversion(kRTFTextContentType)){ - result=eValidDetect; - } } else { if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kPlainTextContentType)) { diff --git a/parser/htmlparser/src/CRtfDTD.cpp b/parser/htmlparser/src/CRtfDTD.cpp deleted file mode 100644 index 0b12cf5cc7b3..000000000000 --- a/parser/htmlparser/src/CRtfDTD.cpp +++ /dev/null @@ -1,1206 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * 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 1/31/00 - * - * - */ - - -#include "nsIDTDDebug.h" -#include "CRtfDTD.h" -#include "nsCRT.h" -#include "nsParser.h" -#include "nsScanner.h" -#include "nsIParser.h" -#include "nsTokenHandler.h" -#include "nsITokenizer.h" -#include "nsIHTMLContentSink.h" -#include "nsHTMLEntities.h" -#include "nsDTDUtils.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 "nsDebug.h" - -#include "prmem.h" - - -static NS_DEFINE_IID(kIHTMLContentSinkIID, NS_IHTML_CONTENT_SINK_IID); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); -static NS_DEFINE_IID(kClassIID, NS_RTF_DTD_IID); -static NS_DEFINE_IID(kITokenizerIID,NS_ITOKENIZER_IID); - - -static const char* kRTFDocHeader= "{\\rtf0"; - - -class nsRTFTokenizer: public nsITokenizer { -public: - nsRTFTokenizer(); - virtual ~nsRTFTokenizer(); - - 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: - - nsDeque mTokenDeque; - nsTokenAllocator* mTokenAllocator; -}; - - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -class CRTFGroup { -public: - CRTFGroup() { - nsCRT::zero(mContainers,sizeof(mContainers)); - mColor=0; - } - - PRBool mContainers[eRTFCtrl_last]; - PRInt32 mColor; -}; - - - -/** - * This method is defined in nsRTFTokenizer.h. It is used to - * cause the COM-like construction of an RTFTokenizer. - * - * @update gess 1/31/00 - * @param nsIParser** ptr to newly instantiated parser - * @return NS_xxx error result - */ - -nsresult NS_NewRTFTokenizer(nsITokenizer** aInstancePtrResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsRTFTokenizer* it = new nsRTFTokenizer(); - if (nsnull == it) { - return NS_ERROR_OUT_OF_MEMORY; - } - return it->QueryInterface(kClassIID, (void **) aInstancePtrResult); -} - - - -struct RTFEntry { - char mName[10]; - eRTFTags mTagID; -}; - -#if 1 -static RTFEntry gRTFTable[] = { - - {"$",eRTFCtrl_unknown}, - {"'",eRTFCtrl_quote}, - {"*",eRTFCtrl_star}, - {"0x0a",eRTFCtrl_linefeed}, - {"0x0d",eRTFCtrl_return}, - {"\\",eRTFCtrl_begincontrol}, - {"ansi",eRTFCtrl_ansi}, - {"b",eRTFCtrl_bold}, - {"bin",eRTFCtrl_bin}, - {"blue",eRTFCtrl_blue}, - {"cols",eRTFCtrl_cols}, - {"comment",eRTFCtrl_comment}, - {"f",eRTFCtrl_font}, - {"fonttbl",eRTFCtrl_fonttable}, - {"green",eRTFCtrl_green}, - {"i",eRTFCtrl_italic}, - {"margb",eRTFCtrl_bottommargin}, - {"margl",eRTFCtrl_leftmargin}, - {"margr",eRTFCtrl_rightmargin}, - {"margt",eRTFCtrl_topmargin}, - {"par",eRTFCtrl_par}, - {"pard",eRTFCtrl_pard}, - {"plain",eRTFCtrl_plain}, - {"qc",eRTFCtrl_justified}, - {"qj",eRTFCtrl_fulljustified}, - {"ql",eRTFCtrl_leftjustified}, - {"qr",eRTFCtrl_rightjustified}, - {"rdblquote",eRTFCtrl_rdoublequote}, - {"red",eRTFCtrl_red}, - {"rtf",eRTFCtrl_rtf}, - {"tab",eRTFCtrl_tab}, - {"title",eRTFCtrl_title}, - {"u",eRTFCtrl_underline}, - {"{",eRTFCtrl_startgroup}, - {"}",eRTFCtrl_endgroup}, - {"~",eRTFCtrl_last} //make sure this stays the last token... -}; - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -#if 0 -static const char* GetTagName(eRTFTags aTag) { - PRInt32 cnt=sizeof(gRTFTable)/sizeof(RTFEntry); - PRInt32 low=0; - PRInt32 high=cnt-1; - PRInt32 middle=kNotFound; - - while(low<=high) { - middle=(PRInt32)(low+high)/2; - if(aTag==gRTFTable[middle].mTagID) - return gRTFTable[middle].mName; - if(aTagQueryInterface(kClassIID, (void **) aInstancePtrResult); -} - - -NS_IMPL_ADDREF(CRtfDTD) -NS_IMPL_RELEASE(CRtfDTD) - - -/** - * Default constructor - * - * @update gess 1/31/00 - * @param - * @return - */ -CRtfDTD::CRtfDTD() : nsIDTD(), mGroups(0) { - NS_INIT_REFCNT(); - mParser=0; - mFilename=0; - mTokenizer=0; - mHasHeader=PR_FALSE; - mSink=0; -} - -/** - * Default destructor - * - * @update gess 1/31/00 - * @param - * @return - */ -CRtfDTD::~CRtfDTD(){ -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -const nsIID& CRtfDTD::GetMostDerivedIID(void) const{ - return kClassIID; -} - -/** - * Call this method if you want the DTD to construct fresh instance - * of itself. - * @update gess 1/31/00 - * @param - * @return - */ -nsresult CRtfDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){ - return NS_NewRTF_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 gess 1/31/00 - * @param - * @return TRUE if this DTD can satisfy the request; FALSE otherwise. - */ -eAutoDetectResult CRtfDTD::CanParse(CParserContext& aParserContext,nsString& aBuffer, PRInt32 aVersion) { - eAutoDetectResult result=eUnknownDetect; - - if(eViewSource!=aParserContext.mParserCommand) { - if(aParserContext.mMimeType.EqualsWithConversion(kRTFTextContentType)) { - result=ePrimaryDetect; - } - else if(kNotFound!=aBuffer.Find(kRTFDocHeader)) { - result=ePrimaryDetect; - } - } - 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 CRtfDTD::WillBuildModel( const CParserContext& aParserContext,nsIContentSink* aSink){ - - nsresult result=NS_OK; - mGroupCount=0; - - - if((!aParserContext.mPrevContext) && (aSink)) { - - if(aSink && (!mSink)) { - result=aSink->QueryInterface(kIHTMLContentSinkIID, (void **)&mSink); - } - - if(result==NS_OK) { - result = aSink->WillBuildModel(); - - } - } - - - 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/31/00 - * @param aFilename is the name of the file being parsed. - * @return error code (almost always 0) - */ -NS_IMETHODIMP CRtfDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITokenObserver* anObserver,nsIContentSink* aSink) { - nsresult result=NS_OK; - - if(aTokenizer) { - nsITokenizer* oldTokenizer=mTokenizer; - mTokenizer=aTokenizer; - mParser=(nsParser*)aParser; - - if(mTokenizer) { - - if(aSink) { - - do { - -#if 0 - int n=aTokenizer->GetCount(); - if(n>50) n=50; - for(int i=0;iGetTokenAt(i); - printf("\nToken[%i],%p",i,theToken); - } - printf("\n"); -#endif - - CToken* theToken=mTokenizer->PopToken(); - if(theToken) { - result=HandleToken(theToken,aParser); - } - else break; - } while(NS_SUCCEEDED(result) && mGroups.GetSize()); - - mTokenizer=oldTokenizer; - } - } - } - else result=NS_ERROR_HTMLPARSER_BADTOKENIZER; - return result; -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -NS_IMETHODIMP CRtfDTD::DidBuildModel(nsresult anErrorCode,PRInt32 aLevel,nsIParser* aParser,nsIContentSink* aSink){ - nsresult result=NS_OK; - - CloseContainer(eHTMLTag_pre); - CloseContainer(eHTMLTag_body); - CloseContainer(eHTMLTag_html); - - if(mSink) mSink->DidBuildModel(0); - - return result; -} - -/** - * Retrieve the preferred tokenizer for use by this DTD. - * @update gess 1/31/00 - * @param none - * @return ptr to tokenizer - */ -nsresult CRtfDTD::GetTokenizer(nsITokenizer*& aTokenizer) { - nsresult result=NS_OK; - if(!mTokenizer) { - result=NS_NewRTFTokenizer(&mTokenizer); - } - aTokenizer=mTokenizer; - return result; -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -nsresult CRtfDTD::WillResumeParse(void){ - return NS_OK; -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -nsresult CRtfDTD::WillInterruptParse(void){ - return NS_OK; -} - -/** - * Called by the parser to initiate dtd verification of the - * internal context stack. - * @update gess 1/31/00 - * @param - * @return - */ -PRBool CRtfDTD::Verify(nsString& aURLRef,nsIParser* aParser){ - PRBool result=PR_TRUE; - mParser=(nsParser*)aParser; - return result; -} - -/** - * Called by the parser to enable/disable dtd verification of the - * internal context stack. - * @update gess 1/31/00 - * @param - * @return - */ -void CRtfDTD::SetVerification(PRBool aEnabled){ -} - -/** - * This method gets called to determine whether a given - * tag is itself a container - * - * @update gess 1/31/00 - * @param aTag -- tag to test for containership - * @return PR_TRUE if given tag can contain other tags - */ -PRBool CRtfDTD::IsContainer(PRInt32 aTag) const{ - PRBool result=PR_FALSE; - return result; -} - - -/** - * This method is called to determine whether or not a tag - * of one type can contain a tag of another type. - * - * @update gess 1/31/00 - * @param aParent -- int tag of parent container - * @param aChild -- int tag of child container - * @return PR_TRUE if parent can contain child - */ -PRBool CRtfDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const{ - PRBool result=PR_FALSE; - return result; -} - -/** - * Give rest of world access to our tag enums, so that CanContain(), etc, - * become useful. - */ -NS_IMETHODIMP CRtfDTD::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const { - *aIntTag = nsHTMLTags::LookupTag(aTag); - return NS_OK; -} - -NS_IMETHODIMP CRtfDTD::IntTagToStringTag(PRInt32 aIntTag, nsString& aTag) const { - aTag.AssignWithConversion(nsHTMLTags::GetStringValue((nsHTMLTag)aIntTag)); - return NS_OK; -} - -NS_IMETHODIMP CRtfDTD::ConvertEntityToUnicode(const nsString& aEntity, PRInt32* aUnicode) const { - *aUnicode = nsHTMLEntities::EntityToUnicode(aEntity); - return NS_OK; -} - - -/** - * - * @update gess 1/31/00 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::PushGroup(){ - nsresult result=NS_OK; - - CRTFGroup* theGroup=new CRTFGroup(); - if(theGroup) - mGroups.Push(theGroup); - else result=NS_ERROR_OUT_OF_MEMORY; - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::PopGroup(){ - nsresult result=NS_OK; - - CRTFGroup* theGroup=(CRTFGroup*)mGroups.Pop(); - if(theGroup) - delete theGroup; - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aTag -- text containing the tag to open - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::AddLeafContainer(eHTMLTags aTag,const char* aTagName){ - nsresult result=NS_OK; - - if(mSink) { - nsAutoString theStr; theStr.AssignWithConversion(aTagName); - CStartToken theToken(theStr,aTag); - nsCParserNode theNode(&theToken); - - switch(aTag) { - case eHTMLTag_br: - default: - result=mSink->AddLeaf(theNode); - break; - } - } - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aTag -- text containing the tag to open - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::OpenContainer(eHTMLTags aTag,const char* aTagName){ - nsresult result=NS_OK; - - if(mSink) { - nsAutoString theStr; theStr.AssignWithConversion(aTagName); - CStartToken theToken(theStr,aTag); - nsCParserNode theNode(&theToken); - - switch(aTag) { - case eHTMLTag_html: - mSink->OpenHTML(theNode); - break; - case eHTMLTag_body: - mSink->OpenBody(theNode); - break; - default: - mSink->OpenContainer(theNode); - break; - } - } - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aTag -- text containing the tag to close - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::CloseContainer(eHTMLTags aTag){ - nsresult result=NS_OK; - - if(mSink) { - CEndToken theToken(aTag); - nsCParserNode theNode(&theToken); - - switch(aTag) { - case eHTMLTag_html: - mSink->CloseHTML(theNode); - break; - case eHTMLTag_body: - mSink->CloseBody(theNode); - break; - case eHTMLTag_p: - break; - default: - mSink->CloseContainer(theNode); - break; - } - } - - return result; -} - - -/** - * - * @update gess 1/31/00 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::EmitStyleContainer(CToken* aToken,eRTFTags aTag,PRBool aState){ - nsresult result=NS_OK; - - const char* theTag=0; - eHTMLTags theID=eHTMLTag_unknown; - - switch(aTag) { - case eRTFCtrl_bold: - theTag="b"; - theID=eHTMLTag_b; - break; - case eRTFCtrl_italic: - theTag="i"; - theID=eHTMLTag_i; - break; - case eRTFCtrl_underline: - theTag="u"; - theID=eHTMLTag_u; - break; - case eRTFCtrl_plain: - result=EmitStyleContainer(aToken,eRTFCtrl_bold,PR_FALSE); - result=EmitStyleContainer(aToken,eRTFCtrl_italic,PR_FALSE); - result=EmitStyleContainer(aToken,eRTFCtrl_underline,PR_FALSE); - break; - default: - break; - } //switch - - CRTFGroup* theGroup=(CRTFGroup*)mGroups.ObjectAt(mGroups.GetSize()-1); - - if(aState) { - if(!theGroup->mContainers[aTag]) { - result=OpenContainer(theID,theTag); - theGroup->mContainers[aTag]=PR_TRUE; - } - } - else { - if(theGroup->mContainers[aTag]) { - result=CloseContainer(theID); - theGroup->mContainers[aTag]=PR_FALSE; - } - } - - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::HandleControlWord(CToken* aToken){ - nsresult result=NS_OK; - - eRTFTags theTag=(eRTFTags)aToken->GetTypeID(); - - switch(theTag) { - case eRTFCtrl_startgroup: - PushGroup(); - break; - case eRTFCtrl_endgroup: - PopGroup(); - break; - case eRTFCtrl_rtf: - mHasHeader=PR_TRUE; - OpenContainer(eHTMLTag_html,"html"); - OpenContainer(eHTMLTag_body,"body"); - OpenContainer(eHTMLTag_pre,"pre"); - break; - default: - if(mGroups.GetSize() && mHasHeader) { - - CRTFControlWord* theToken=(CRTFControlWord*)aToken; - - switch(theTag) { - case eRTFCtrl_ansi: - break; - case eRTFCtrl_tab: - { - CTextToken theToken2( NS_LITERAL_STRING(" ") ); - result=HandleContent(&theToken2); - } - break; - case eRTFCtrl_bold: - case eRTFCtrl_italic: - case eRTFCtrl_underline: - case eRTFCtrl_plain: - result=EmitStyleContainer(theToken,theTag,theToken->mArgument.CharAt(0)!='0'); - break; - case eRTFCtrl_par: - AddLeafContainer(eHTMLTag_br,"br"); - break; - default: - break; //just drop it on the floor. - } - } - break; - } -// PushGroup(); - - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::HandleContent(CToken* aToken){ - nsresult result=NS_OK; - - if(mSink) { - CTextToken theToken(aToken->GetStringValueXXX()); - nsCParserNode theNode(&theToken); - mSink->AddLeaf(theNode); - } - - return result; -} - -/** - * - * @update gess 1/31/00 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ -nsresult CRtfDTD::HandleToken(CToken* aToken,nsIParser* aParser) { - nsresult result=NS_OK; - - mParser=(nsParser*)aParser; - if(aToken) { - eRTFTokenTypes theType=eRTFTokenTypes(aToken->GetTokenType()); - - switch(theType) { - - case eRTFToken_controlword: - result=HandleControlWord(aToken); break; - - case eRTFToken_content: - case eToken_newline: - case eHTMLTag_text: - result=HandleContent(aToken); break; - - default: - break; - //everything else is just text or attributes of controls... - } - - }//if - - return result; -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -nsTokenAllocator* CRtfDTD::GetTokenAllocator(void){ - 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. - * - * @update harishd 07/22/99 - * @update gess 1/31/00 - * @param - * @return - */ -nsresult CRtfDTD::Terminate(nsIParser* aParser) -{ - return NS_ERROR_HTMLPARSER_STOPPARSING; -} - -/*************************************************************** - Heres's the RTFControlWord subclass... - ***************************************************************/ - - -CRTFControlWord::CRTFControlWord(eRTFTags aTagID) : CToken(aTagID) { -} - -/** - * - * @update gess 1/31/00 - * @param - * @return 0 if all is well; non-zero is an error - */ -PRInt32 CRTFControlWord::GetTokenType() { - return eRTFToken_controlword; -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -nsresult CRTFControlWord::Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode) { - const char* gAlphaChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - const char* gDigits="-0123456789"; - - //First, decide if it's a control word or a control symbol (1 char) - PRUnichar theChar=0; - nsresult result=aScanner.Peek(theChar); - - if(NS_SUCCEEDED(result)) { - if(('a'<=theChar) && (theChar<='z')) { - nsAutoString temp; temp.AssignWithConversion(gAlphaChars); - result=aScanner.ReadWhile(mTextValue,temp,PR_FALSE); - if(NS_OK==result) { - //ok, now look for an option parameter... - - mTypeID=GetTagID(mTextValue); - result=aScanner.Peek(theChar); - - switch(theChar) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - case kMinus: - { - nsAutoString theDigits; theDigits.AssignWithConversion(gDigits); - result=aScanner.ReadWhile(mArgument,theDigits,PR_FALSE); - } - break; - - case kSpace: - default: - break; - } - } - if(NS_OK==result) - result=aScanner.SkipWhitespace(); - } - else { - //it's a control symbol - } - } - return result; -} - - -/*************************************************************** - Heres's the RTFContent subclass... - ***************************************************************/ - - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -CRTFContent::CRTFContent(PRUnichar* aKey) : CToken(nsAutoString(aKey)) { -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -PRInt32 CRTFContent::GetTokenType() { - return eRTFToken_content; -} - - - -/** - * We're supposed to read text until we encounter one - * of the RTF control characters: \.{,}. - * @update gess 1/31/00 - * @param - * @return - */ - -nsresult CRTFContent::Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode) { - static const char* textTerminators="\\{}\r\n"; - mTextValue.Append(aChar); - PRInt32 result=aScanner.ReadUntil(mTextValue,textTerminators,PR_FALSE); - if(NS_SUCCEEDED(result)) { - mTypeID=eHTMLTag_text; - } - return result; -} - -/*************************************************************** - Heres's the nsRTFTokenizer class... - ***************************************************************/ - - -/** - * 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 nsRTFTokenizer::QueryInterface(const nsIID& aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - - if(aIID.Equals(kISupportsIID)) { //do IUnknown... - *aInstancePtr = (nsISupports*)(this); - } - else if(aIID.Equals(kITokenizerIID)) { //do IParser base class... - *aInstancePtr = (nsITokenizer*)(this); - } - else if(aIID.Equals(kClassIID)) { //do this class... - *aInstancePtr = (nsRTFTokenizer*)(this); - } - else { - *aInstancePtr=0; - return NS_NOINTERFACE; - } - NS_ADDREF_THIS(); - return NS_OK; -} - -nsRTFTokenizer::nsRTFTokenizer() : mTokenDeque(0) { - NS_INIT_REFCNT(); -} - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -nsRTFTokenizer::~nsRTFTokenizer() { -} - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -nsresult nsRTFTokenizer::WillTokenize(PRBool aIsFinalChunk,nsTokenAllocator* aTokenAllocator) { - nsresult result=NS_OK; - mTokenAllocator=aTokenAllocator; - return result; -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -nsTokenAllocator* nsRTFTokenizer::GetTokenAllocator(void) { - //let's move to this once we eliminate the leaking of tokens... - return mTokenAllocator; -} - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -nsresult nsRTFTokenizer::ConsumeToken(nsScanner& aScanner,PRBool& aFlushTokens) { - nsresult result=NS_OK; - - PRUnichar theChar=0; - result=aScanner.GetChar(theChar); - if(NS_SUCCEEDED(result)) { - switch(theChar) { - case '}': - case '{': - { - eRTFTags theTag= ('{'==theChar) ? eRTFCtrl_startgroup : eRTFCtrl_endgroup; - CRTFControlWord* theToken=(CRTFControlWord*)mTokenAllocator->CreateRTFTokenOfType(eRTFToken_controlword,theTag); - - if(theToken) { - mTokenDeque.Push(theToken); - } - else result=NS_ERROR_OUT_OF_MEMORY; - } - break; - case '\\': - { - CRTFControlWord* theWord =(CRTFControlWord*)mTokenAllocator->CreateRTFTokenOfType(eRTFToken_controlword,eRTFCtrl_unknown); - if(theWord) { - result=theWord->Consume(theChar,aScanner,0); - if(NS_SUCCEEDED(result)) { - mTokenDeque.Push(theWord); - } - } - } - break; - case '\n': - case '\r': - { - CNewlineToken* theContent=(CNewlineToken*)mTokenAllocator->CreateTokenOfType(eToken_newline,eHTMLTag_newline); - if(theContent) { - result=theContent->Consume(theChar,aScanner,0); - if(NS_SUCCEEDED(result)) { - mTokenDeque.Push(theContent); - } - } - } - break; - default: - CRTFContent* theContent=(CRTFContent*)mTokenAllocator->CreateRTFTokenOfType(eRTFToken_content,(eRTFTags)0); - if(theContent) { - result=theContent->Consume(theChar,aScanner,0); - if(NS_SUCCEEDED(result)) { - mTokenDeque.Push(theContent); - } - } - break; - } - } - return result; -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -nsresult nsRTFTokenizer::DidTokenize(PRBool aIsFinalChunk) { - nsresult result=NS_OK; - return result; -} - - -/** - * This method provides access to the topmost token in the tokenDeque. - * The token is not really removed from the list. - * @update gess 1/31/00 - * @return ptr to token - */ -CToken* nsRTFTokenizer::PeekToken() { - return (CToken*)mTokenDeque.PeekFront(); -} - - -/** - * This method provides access to the topmost token in the tokenDeque. - * The token is really removed from the list; if the list is empty we return 0. - * @update gess 1/31/00 - * @return ptr to token or NULL - */ -CToken* nsRTFTokenizer::PopToken() { - CToken* result=nsnull; - result=(CToken*)mTokenDeque.PopFront(); - return result; -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -CToken* nsRTFTokenizer::PushTokenFront(CToken* theToken) { - mTokenDeque.PushFront(theToken); - return theToken; -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -CToken* nsRTFTokenizer::PushToken(CToken* theToken) { - mTokenDeque.Push(theToken); - return theToken; -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -PRInt32 nsRTFTokenizer::GetCount(void) { - return mTokenDeque.GetSize(); -} - -/** - * - * @update gess 1/31/00 - * @param - * @return - */ -CToken* nsRTFTokenizer::GetTokenAt(PRInt32 anIndex){ - return (CToken*)mTokenDeque.ObjectAt(anIndex); -} - - -/** - * - * @update gess 1/31/00 - * @param - * @return nsresult - */ -void nsRTFTokenizer::PrependTokens(nsDeque& aDeque) { -} - - -NS_IMPL_ADDREF(nsRTFTokenizer) -NS_IMPL_RELEASE(nsRTFTokenizer) - - diff --git a/parser/htmlparser/src/CRtfDTD.h b/parser/htmlparser/src/CRtfDTD.h deleted file mode 100644 index 63245e56b318..000000000000 --- a/parser/htmlparser/src/CRtfDTD.h +++ /dev/null @@ -1,359 +0,0 @@ - -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * 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_RTFDTD__ -#define NS_RTFDTD__ - -#include "nsIDTD.h" -#include "nsISupports.h" -#include "nsHTMLTokens.h" -#include "nshtmlpars.h" -#include "nsVoidArray.h" -#include "nsDeque.h" -#include "nsToken.h" - - -#define NS_RTF_DTD_IID \ - {0xa39c6bfc, 0x15f0, 0x11d2, \ - {0x80, 0x41, 0x00, 0x10, 0x4b, 0x98, 0x3f, 0xd4}} - -class nsIParserNode; -class nsParser; -class nsITokenizer; -class nsIHTMLContentSink; - -enum eRTFTokenTypes { - eRTFToken_unknown=0, - eRTFToken_group, // '{' - eRTFToken_controlword, // '\' - eRTFToken_content, // contains all document content - //everything else is just text or attributes of controls... - eRTFToken_last //make sure this stays the last token... -}; - - -enum eRTFTags { - eRTFCtrl_unknown=0, - eRTFCtrl_quote, - eRTFCtrl_star, - eRTFCtrl_linefeed, - eRTFCtrl_return, - eRTFCtrl_begincontrol, - eRTFCtrl_text, - eRTFCtrl_ansi, - eRTFCtrl_bold, - eRTFCtrl_bin, - eRTFCtrl_blue, - eRTFCtrl_cols, - eRTFCtrl_comment, - eRTFCtrl_italic, - eRTFCtrl_font, - eRTFCtrl_fonttable, - eRTFCtrl_green, - eRTFCtrl_bottommargin, - eRTFCtrl_leftmargin, - eRTFCtrl_rightmargin, - eRTFCtrl_topmargin, - eRTFCtrl_par, - eRTFCtrl_pard, - eRTFCtrl_plain, - eRTFCtrl_justified, - eRTFCtrl_fulljustified, - eRTFCtrl_leftjustified, - eRTFCtrl_rightjustified, - eRTFCtrl_rdoublequote, - eRTFCtrl_red, - eRTFCtrl_rtf, - eRTFCtrl_tab, - eRTFCtrl_title, - eRTFCtrl_underline, - eRTFCtrl_startgroup, // { - eRTFCtrl_endgroup, // } - eRTFCtrl_last //make sure this stays the last token... -}; - - - -/** - * Represents the token of RTF. Always has form \xxxxdelimiter - * - * @update gess7/8/98 - * @param - * @return - */ -class CRTFControlWord : public CToken { -public: - CRTFControlWord(eRTFTags aTagID); - virtual PRInt32 GetTokenType(); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - - eRTFTags mTag; - nsString mArgument; -}; - - -/** - * This represents the document content. - * - * @update gess7/8/98 - * @param - * @return - */ -class CRTFContent: public CToken { -public: - CRTFContent(PRUnichar* aKey=0); - virtual PRInt32 GetTokenType(); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); -}; - - -class CRtfDTD : public nsIDTD { - - public: - - NS_DECL_ISUPPORTS - - - /** - * - * - * @update gess 4/9/98 - * @param - * @return - */ - CRtfDTD(); - - /** - * - * - * @update gess 4/9/98 - * @param - * @return - */ - virtual ~CRtfDTD(); - - virtual 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 - */ - virtual nsresult 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. - */ - virtual eAutoDetectResult CanParse(CParserContext& aParserContext,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=0,nsIContentSink* aSink=0); - - /** - * 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,PRInt32 aLevel,nsIParser* aParser,nsIContentSink* aSink=0); - - /** - * - * @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 HandleControlWord(CToken* aToken); - - /** - * - * @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 HandleContent(CToken* aToken); - - /** - * - * @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); - - - /** - * Called by the parser to initiate dtd verification of the - * internal context stack. - * @update gess 7/23/98 - * @param - * @return - */ - virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); - - /** - * 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 - */ - virtual 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 - */ - virtual PRBool IsContainer(PRInt32 aTag) const; - - /** - * Retrieve a ptr to the global token recycler... - * @update gess8/4/98 - * @return ptr to recycler (or null) - */ - virtual 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 - */ - virtual nsresult Terminate(nsIParser* aParser=nsnull); - - /** - * Give rest of world access to our tag enums, so that CanContain(), etc, - * become useful. - */ - NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const; - - NS_IMETHOD IntTagToStringTag(PRInt32 aIntTag, nsString& aTag) const; - - NS_IMETHOD ConvertEntityToUnicode(const nsString& aEntity, PRInt32* aUnicode) const; - - virtual PRBool IsBlockElement(PRInt32 aTagID,PRInt32 aParentID) const {return PR_FALSE;} - virtual PRBool IsInlineElement(PRInt32 aTagID,PRInt32 aParentID) const {return PR_FALSE;} - - -protected: - - nsParser* mParser; - char* mFilename; - nsITokenizer* mTokenizer; - PRBool mHasHeader; - nsDeque mGroups; - PRInt32 mGroupCount; - nsIHTMLContentSink* mSink; - -private: - nsresult PushGroup(); - nsresult PopGroup(); - nsresult OpenContainer(eHTMLTags aTag,const char* aTagName); - nsresult CloseContainer(eHTMLTags aTag); - nsresult AddLeafContainer(eHTMLTags aTag,const char* aTagName); - nsresult EmitStyleContainer(CToken* aToken,eRTFTags aTag,PRBool aState); -}; - -extern NS_HTMLPARS nsresult NS_NewRTF_DTD(nsIDTD** aInstancePtrResult); - -#endif - - - diff --git a/parser/htmlparser/src/MANIFEST b/parser/htmlparser/src/MANIFEST index cb053e2ebfdb..ce7b04be86e2 100644 --- a/parser/htmlparser/src/MANIFEST +++ b/parser/htmlparser/src/MANIFEST @@ -15,7 +15,6 @@ nsToken.h nsIDTDDebug.h nsIDTD.h CNavDTD.h -CRtfDTD.h nsHTMLTags.h nsHTMLTagList.h nsParserCIID.h diff --git a/parser/htmlparser/src/nsIParser.h b/parser/htmlparser/src/nsIParser.h index bc21410892af..e8dbfe8113d2 100644 --- a/parser/htmlparser/src/nsIParser.h +++ b/parser/htmlparser/src/nsIParser.h @@ -374,7 +374,6 @@ const PRUnichar kNullCh = '\0'; #define kTextCSSContentType "text/css" #define kApplicationJSContentType "application/x-javascript" #define kTextJSContentType "text/javascript" -#define kRTFTextContentType "text/rtf" #define kSGMLTextContentType "text/sgml" diff --git a/parser/htmlparser/src/nsParserCIID.h b/parser/htmlparser/src/nsParserCIID.h index 3a7965f4856a..c2d5a680c873 100644 --- a/parser/htmlparser/src/nsParserCIID.h +++ b/parser/htmlparser/src/nsParserCIID.h @@ -65,9 +65,6 @@ #define NS_VIEWSOURCE_DTD_CID \ { 0x8323fad0, 0x2102, 0x11d4, { 0x81, 0x42, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } -// {8323FAD1-2102-11d4-8142-000064657374} -#define NS_CRTF_DTD_CID \ -{ 0x8323fad1, 0x2102, 0x11d4, { 0x81, 0x42, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } // {a6cf910f-15b3-11d2-932e-00805f8add32} diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp index b89eca87cae0..0ecc0d98c8a5 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -113,8 +113,6 @@ static nsDefaultMimeTypeEntry extraMimeEntries [] = { IMAGE_ART, "art", "ART Image", 0, 0 }, { IMAGE_TIFF, "tiff,tif", "TIFF Image", 0, 0 }, { APPLICATION_POSTSCRIPT, "ps,eps,ai", "Postscript File",0, 0 }, - { TEXT_RTF, "rtf", "Rich Text Format", 0, 0 }, - { TEXT_CPP, "cpp", "CPP file", 'TEXT','CWIE' }, { "application/x-arj", "arj", "ARJ file", 0,0 }, };