зеркало из https://github.com/mozilla/pjs.git
new primaryDetect code in DTD detection system; fixes XIF
This commit is contained in:
Родитель
7eb8ca88d0
Коммит
3a8879990b
|
@ -437,40 +437,29 @@ PRBool CNavDTD::Verify(nsString& aURLRef,nsIParser* aParser){
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
PRBool result=PR_FALSE;
|
||||
if(!aCommand.Equals(kViewSourceCommand)) {
|
||||
if(PR_TRUE==aContentType.Equals(kHTMLTextContentType) || PR_TRUE==aContentType.Equals(kPlainTextContentType)) {
|
||||
result=PR_TRUE;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAutoDetectResult CNavDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
eAutoDetectResult CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
|
||||
if(PR_TRUE==aType.Equals(kHTMLTextContentType) ||
|
||||
PR_TRUE==aType.Equals(kPlainTextContentType)) {
|
||||
result=eValidDetect;
|
||||
}
|
||||
else {
|
||||
//otherwise, look into the buffer to see if you recognize anything...
|
||||
if(BufferContainsHTML(aBuffer)){
|
||||
if(!aCommand.Equals(kViewSourceCommand)) {
|
||||
if(PR_TRUE==aContentType.Equals(kHTMLTextContentType)) {
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
else if(PR_TRUE==aContentType.Equals(kPlainTextContentType)) {
|
||||
result=eValidDetect;
|
||||
if(0==aType.Length())
|
||||
aType=kHTMLTextContentType;
|
||||
}
|
||||
else {
|
||||
//otherwise, look into the buffer to see if you recognize anything...
|
||||
if(BufferContainsHTML(aBuffer)){
|
||||
result=ePrimaryDetect;
|
||||
if(0==aContentType.Length())
|
||||
aContentType=kHTMLTextContentType;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
|
@ -558,17 +547,21 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse
|
|||
result = CloseContainersTo(0,eHTMLTag_unknown,PR_FALSE);
|
||||
}
|
||||
|
||||
result = mSink->DidBuildModel(1);
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef NS_DEBUG
|
||||
if(mComputedCRC32!=mExpectedCRC32) {
|
||||
if(mExpectedCRC32!=0) {
|
||||
printf("Expected CRC: %u,",mExpectedCRC32);
|
||||
result = mSink->DidBuildModel(2);
|
||||
}
|
||||
else {
|
||||
printf("Computed CRC: %u.\n",mComputedCRC32);
|
||||
result = mSink->DidBuildModel(3);
|
||||
}
|
||||
printf("Computed CRC: %u.\n",mComputedCRC32);
|
||||
}
|
||||
else result = mSink->DidBuildModel(0);
|
||||
#else
|
||||
result = mSink->DidBuildModel(3);
|
||||
#endif
|
||||
|
||||
if(mDTDDebug) {
|
||||
mDTDDebug->DumpVectorRecord();
|
||||
}
|
||||
|
@ -631,7 +624,7 @@ nsresult CNavDTD::ReleaseTokenPump(nsITagHandler* aHandler){
|
|||
nsresult result=NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This gets called after we've handled a given start tag.
|
||||
* It's a generic hook to let us to post processing.
|
||||
|
@ -639,7 +632,7 @@ nsresult CNavDTD::ReleaseTokenPump(nsITagHandler* aHandler){
|
|||
* @param aChildTag is the tag itself.
|
||||
* @return status
|
||||
*/
|
||||
nsresult CNavDTD::DidHandleStartTag(CToken* aToken,eHTMLTags aChildTag){
|
||||
nsresult CNavDTD::DidHandleStartTag(nsCParserNode& aNode,eHTMLTags aChildTag){
|
||||
nsresult result=NS_OK;
|
||||
|
||||
CToken* theNextToken=mTokenizer->PeekToken();
|
||||
|
@ -676,10 +669,9 @@ nsresult CNavDTD::DidHandleStartTag(CToken* aToken,eHTMLTags aChildTag){
|
|||
case eHTMLTag_plaintext:
|
||||
case eHTMLTag_xmp:
|
||||
//grab the skipped content and dump it out as text...
|
||||
if(theNextToken && mSink){
|
||||
eHTMLTokenTypes theType=eHTMLTokenTypes(theNextToken->GetTokenType());
|
||||
if(eToken_skippedcontent==theType){
|
||||
nsString& theText=((CAttributeToken*)theNextToken)->GetKey();
|
||||
{
|
||||
const nsString& theText=aNode.GetSkippedContent();
|
||||
if(0<theText.Length()) {
|
||||
CViewSourceHTML::WriteText(theText,*mSink,PR_TRUE);
|
||||
}
|
||||
}
|
||||
|
@ -1061,7 +1053,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
|
|||
} //switch
|
||||
//now do any post processing necessary on the tag...
|
||||
if(NS_OK==result)
|
||||
DidHandleStartTag(aToken,theChildTag);
|
||||
DidHandleStartTag(attrNode,theChildTag);
|
||||
}
|
||||
} //if
|
||||
|
||||
|
|
|
@ -159,18 +159,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
* being asked to parse).
|
||||
* @return TRUE if this DTD parse the given type; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* This method gets called to determine if the DTD can determine the
|
||||
* kind of data contained in the given buffer string. If you know the
|
||||
* type, the you should enter its stringname aType.
|
||||
* @update gess7/7/98
|
||||
* @param aBuffer contains data to be examined for autodetection.
|
||||
* @param aType will contain a typename you specify.
|
||||
* @return unknown, valid (if you know the type), invalid (if you dont)
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* Called by the parser to initiate dtd verification of the
|
||||
|
@ -516,7 +505,7 @@ protected:
|
|||
nsresult CollectAttributes(nsCParserNode& aNode,PRInt32 aCount);
|
||||
nsresult CollectSkippedContent(nsCParserNode& aNode,PRInt32& aCount);
|
||||
nsresult WillHandleStartTag(CToken* aToken,eHTMLTags aChildTag,nsCParserNode& aNode);
|
||||
nsresult DidHandleStartTag(CToken* aToken,eHTMLTags aChildTag);
|
||||
nsresult DidHandleStartTag(nsCParserNode& aNode,eHTMLTags aChildTag);
|
||||
|
||||
|
||||
nsIHTMLContentSink* mSink;
|
||||
|
|
|
@ -177,21 +177,10 @@ nsresult COtherDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool COtherDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
return CNavDTD::CanParse(aContentType,aCommand,aVersion);
|
||||
eAutoDetectResult COtherDTD::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
return CNavDTD::CanParse(aContentType,aCommand,aBuffer,aVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAutoDetectResult COtherDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
return CNavDTD::AutoDetectContentType(aBuffer,aType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called when a start token has been
|
||||
* encountered in the parse process. If the current container
|
||||
|
|
|
@ -81,15 +81,7 @@ class COtherDTD : public CNavDTD {
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -242,23 +242,14 @@ nsresult CRtfDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool CRtfDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
PRBool result=aContentType.Equals(kRTFTextContentType);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAutoDetectResult CRtfDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
eAutoDetectResult CRtfDTD::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
if(kNotFound!=aBuffer.Find(kRTFDocHeader))
|
||||
if(PR_TRUE==aType.Equals(kRTFTextContentType))
|
||||
result=eValidDetect;
|
||||
if(aContentType.Equals(kRTFTextContentType)) {
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
else if(kNotFound!=aBuffer.Find(kRTFDocHeader)) {
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -184,15 +184,7 @@ class CRtfDTD : public nsIDTD {
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
|
|
|
@ -39,6 +39,14 @@
|
|||
#define NS_IDTD_IID \
|
||||
{ 0xa6cf9053, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
enum eAutoDetectResult {
|
||||
eUnknownDetect,
|
||||
eValidDetect,
|
||||
ePrimaryDetect,
|
||||
eInvalidDetect
|
||||
};
|
||||
|
||||
|
||||
class nsIParser;
|
||||
class CToken;
|
||||
class nsIDTDDebug;
|
||||
|
@ -47,9 +55,6 @@ class nsString;
|
|||
class nsITagHandler;
|
||||
class nsIContentSink;
|
||||
|
||||
enum eAutoDetectResult {eUnknownDetect, eValidDetect, eInvalidDetect};
|
||||
|
||||
|
||||
|
||||
class nsIDTD : public nsISupports {
|
||||
public:
|
||||
|
@ -80,18 +85,7 @@ class nsIDTD : public nsISupports {
|
|||
* @param aContentType -- string representing type of doc to be converted (ie text/html)
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion)=0;
|
||||
|
||||
/**
|
||||
* This method, typically called by the parser, is used to try to autodetect the
|
||||
* type of data contained in the given buffer. The implementor should look at the
|
||||
* buffers contents to try to determine its encoding type.
|
||||
* @update gess7/7/98
|
||||
* @param aBuffer-contains data to be scanned to autodetect type
|
||||
* @param aType-will hold the result if type is autodetected
|
||||
* @return eValid (if detected), eInvalid (if not) or eUnknown (if nothing can be done)
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType)=0;
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion)=0;
|
||||
|
||||
/**
|
||||
* Called by the parser just before the parsing process begins
|
||||
|
|
|
@ -65,6 +65,7 @@ enum eCRCQuality {
|
|||
eCRCPoor
|
||||
};
|
||||
|
||||
|
||||
enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
|
||||
|
||||
/**
|
||||
|
@ -114,17 +115,6 @@ class nsIParser : public nsISupports {
|
|||
*/
|
||||
virtual void SetCommand(const char* aCommand)=0;
|
||||
|
||||
/**
|
||||
* This internal method is used when the parser needs to determine the
|
||||
* type of content it's being asked to parse.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aBuffer -- contains data to be tested (autodetected) for type
|
||||
* @param aType -- string where you store the detected type (if any)
|
||||
* @return autodetect enum (valid, invalid, unknown)
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType)=0;
|
||||
|
||||
|
||||
/******************************************************************************************
|
||||
* Parse methods always begin with an input source, and perform conversions
|
||||
|
|
|
@ -327,68 +327,34 @@ eParseMode nsParser::GetParseMode(void){
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRBool FindSuitableDTD( CParserContext& aParserContext,nsString& aCommand) {
|
||||
PRBool FindSuitableDTD( CParserContext& aParserContext,nsString& aCommand,nsString& aBuffer) {
|
||||
|
||||
//Let's start by tring the defaultDTD, if one exists...
|
||||
if(aParserContext.mDTD)
|
||||
if(aParserContext.mDTD->CanParse(aParserContext.mSourceType,aCommand,0))
|
||||
if(aParserContext.mDTD->CanParse(aParserContext.mSourceType,aCommand,aBuffer,0))
|
||||
return PR_TRUE;
|
||||
|
||||
PRBool result=PR_FALSE;
|
||||
|
||||
nsDequeIterator b=gSharedParserObjects.mDTDDeque.Begin();
|
||||
nsDequeIterator e=gSharedParserObjects.mDTDDeque.End();
|
||||
|
||||
while(b<e){
|
||||
aParserContext.mAutoDetectStatus=eUnknownDetect;
|
||||
nsIDTD* theBestDTD=0;
|
||||
while((b<e) && (aParserContext.mAutoDetectStatus!=ePrimaryDetect)){
|
||||
nsIDTD* theDTD=(nsIDTD*)b.GetCurrent();
|
||||
if(theDTD) {
|
||||
result=theDTD->CanParse(aParserContext.mSourceType,aCommand,0);
|
||||
if(result){
|
||||
theDTD->CreateNewInstance(&aParserContext.mDTD);
|
||||
break;
|
||||
aParserContext.mAutoDetectStatus=theDTD->CanParse(aParserContext.mSourceType,aCommand,aBuffer,0);
|
||||
if((eValidDetect==aParserContext.mAutoDetectStatus) || (ePrimaryDetect==aParserContext.mAutoDetectStatus)) {
|
||||
theBestDTD=theDTD;
|
||||
}
|
||||
}
|
||||
b++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method if you want the known DTD's to try
|
||||
* to detect the document type based through analysis
|
||||
* of the underlying stream.
|
||||
*
|
||||
* @update gess6/22/98
|
||||
* @param aBuffer -- nsString containing sample data to be analyzed.
|
||||
* @param aType -- may hold typename given from netlib; will hold result given by DTD's.
|
||||
* @return auto-detect result: eValid, eInvalid, eUnknown
|
||||
*/
|
||||
eAutoDetectResult nsParser::AutoDetectContentType(nsString& aBuffer,nsString& aType) {
|
||||
|
||||
//The process:
|
||||
// You should go out and ask each DTD if they
|
||||
// recognize the content in the scanner.
|
||||
// Somebody should say yes, or we can't continue.
|
||||
|
||||
//This method may change mSourceType and mParserContext->mDTD.
|
||||
//It absolutely changes mParserContext->mAutoDetectStatus
|
||||
|
||||
nsDequeIterator b=gSharedParserObjects.mDTDDeque.Begin();
|
||||
nsDequeIterator e=gSharedParserObjects.mDTDDeque.End();
|
||||
|
||||
mParserContext->mAutoDetectStatus=eUnknownDetect;
|
||||
while(b<e){
|
||||
nsIDTD* theDTD=(nsIDTD*)b.GetCurrent();
|
||||
if(theDTD) {
|
||||
mParserContext->mAutoDetectStatus=theDTD->AutoDetectContentType(aBuffer,aType);
|
||||
if(eValidDetect==mParserContext->mAutoDetectStatus)
|
||||
break;
|
||||
}
|
||||
b++;
|
||||
}
|
||||
|
||||
return mParserContext->mAutoDetectStatus;
|
||||
if(theBestDTD) {
|
||||
theBestDTD->CreateNewInstance(&aParserContext.mDTD);
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -443,24 +409,21 @@ nsresult nsParser::WillBuildModel(nsString& aFilename,nsIDTD* aDefaultDTD){
|
|||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
if(eOnStart==mParserContext->mStreamListenerState) {
|
||||
mMajorIteration=-1;
|
||||
mMinorIteration=-1;
|
||||
if(eUnknownDetect==mParserContext->mAutoDetectStatus) {
|
||||
if(eValidDetect==AutoDetectContentType(mParserContext->mScanner->GetBuffer(),mParserContext->mSourceType)) {
|
||||
if(mParserContext){
|
||||
if(mParserContext){
|
||||
if(eOnStart==mParserContext->mStreamListenerState) {
|
||||
mMajorIteration=-1;
|
||||
mMinorIteration=-1;
|
||||
if(eUnknownDetect==mParserContext->mAutoDetectStatus) {
|
||||
mParserContext->mDTD=aDefaultDTD;
|
||||
if(PR_TRUE==FindSuitableDTD(*mParserContext,mCommand,mParserContext->mScanner->GetBuffer())) {
|
||||
mParserContext->mParseMode=DetermineParseMode(*this);
|
||||
mParserContext->mDTD=aDefaultDTD;
|
||||
if(PR_TRUE==FindSuitableDTD(*mParserContext,mCommand)) {
|
||||
//mParserContext->mDTD->SetContentSink(mSink);
|
||||
mParserContext->mStreamListenerState=eOnDataAvail;
|
||||
mParserContext->mDTD->WillBuildModel(aFilename,PRBool(0==mParserContext->mPrevContext),this,mSink);
|
||||
}
|
||||
}
|
||||
else result=kInvalidParserContext;
|
||||
} //if
|
||||
}
|
||||
}
|
||||
mParserContext->mStreamListenerState=eOnDataAvail;
|
||||
mParserContext->mDTD->WillBuildModel(aFilename,PRBool(0==mParserContext->mPrevContext),this,mSink);
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
}
|
||||
else result=kInvalidParserContext;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -290,18 +290,6 @@ private:
|
|||
*/
|
||||
PRBool DidTokenize();
|
||||
|
||||
/**
|
||||
* This method is used as a backstop to compute the kind of content
|
||||
* that is contained in the scanner stream. This method is important
|
||||
* because it allows us to defer the resolution of our DTD (and hence)
|
||||
* filters and maybe eventually sinks based on the input type.
|
||||
*
|
||||
* @update gess6/22/98
|
||||
* @param
|
||||
* @return TRUE if we figured it out.
|
||||
*/
|
||||
eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
|
||||
|
||||
protected:
|
||||
//*********************************************
|
||||
|
|
|
@ -176,12 +176,11 @@ nsresult CValidDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool CValidDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
PRBool result=aContentType.Equals(kXMLTextContentType);
|
||||
eAutoDetectResult CValidDTD::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can perform
|
||||
* a document conversion from a given source-type to a given target-type.
|
||||
|
@ -195,17 +194,6 @@ PRBool CValidDTD::CanConvert(nsString& aSourceType, nsString& aTargetType, PRInt
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAutoDetectResult CValidDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
|
|
|
@ -92,8 +92,7 @@ class CValidDTD : public nsIDTD {
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can perform
|
||||
|
@ -105,14 +104,6 @@ class CValidDTD : public nsIDTD {
|
|||
*/
|
||||
virtual PRBool CanConvert(nsString& aSourceType, nsString& aTargetType, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
|
|
|
@ -227,30 +227,17 @@ nsresult CViewSourceHTML::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
PRBool result=PR_FALSE;
|
||||
if(aCommand.Equals(kViewSourceCommand)) {
|
||||
result=(aContentType.Equals(kXMLTextContentType) ||
|
||||
aContentType.Equals(kRDFTextContentType) ||
|
||||
aContentType.Equals(kHTMLTextContentType) ||
|
||||
aContentType.Equals(kPlainTextContentType) ||
|
||||
aContentType.Equals(kXULTextContentType));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is called to ask the DTD if it recognizes either the aType or data in the buffer.
|
||||
* We intentionally say NO to autodetect types so that XML and HTML dtds can do the right thing.
|
||||
* If either of those DTD's say YES, then we'll agree and render either.
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return detect result
|
||||
*/
|
||||
eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
eAutoDetectResult CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
if(aCommand.Equals(kViewSourceCommand)) {
|
||||
if(aContentType.Equals(kXMLTextContentType) ||
|
||||
aContentType.Equals(kRDFTextContentType) ||
|
||||
aContentType.Equals(kHTMLTextContentType) ||
|
||||
aContentType.Equals(kPlainTextContentType) ||
|
||||
aContentType.Equals(kXULTextContentType)) {
|
||||
result=eValidDetect;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -503,7 +490,7 @@ nsresult WriteNBSP(PRInt32 aCount, nsIContentSink& aSink) {
|
|||
* @param
|
||||
* @return result status
|
||||
*/
|
||||
nsresult CViewSourceHTML::WriteText(nsString& aTextString,nsIContentSink& aSink,PRBool aPreserveSpace) {
|
||||
nsresult CViewSourceHTML::WriteText(const nsString& aTextString,nsIContentSink& aSink,PRBool aPreserveSpace) {
|
||||
nsresult result=NS_OK;
|
||||
|
||||
CTextToken theTextToken;
|
||||
|
|
|
@ -93,15 +93,7 @@ class CViewSourceHTML: public nsIDTD {
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
|
@ -233,7 +225,7 @@ class CViewSourceHTML: public nsIDTD {
|
|||
virtual PRBool IsContainer(PRInt32 aTag) const;
|
||||
|
||||
|
||||
static nsresult WriteText(nsString& aTextString,nsIContentSink& aSink,PRBool aPreserveText);
|
||||
static nsresult WriteText(const nsString& aTextString,nsIContentSink& aSink,PRBool aPreserveText);
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -179,39 +179,28 @@ nsresult CWellFormedDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool CWellFormedDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
PRBool result=PR_FALSE;
|
||||
if(!aCommand.Equals(kViewSourceCommand)) {
|
||||
result=(aContentType.Equals(kXMLTextContentType) ||
|
||||
aContentType.Equals(kRDFTextContentType) ||
|
||||
aContentType.Equals(kXULTextContentType));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAutoDetectResult CWellFormedDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
eAutoDetectResult CWellFormedDTD::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
if(PR_TRUE==aType.Equals(kXMLTextContentType) ||
|
||||
PR_TRUE==aType.Equals(kRDFTextContentType) ||
|
||||
PR_TRUE==aType.Equals(kXULTextContentType)) {
|
||||
result=eValidDetect;
|
||||
}
|
||||
else {
|
||||
if(-1<aBuffer.Find("<?xml ")) {
|
||||
aType = kXMLTextContentType;
|
||||
|
||||
if(!aCommand.Equals(kViewSourceCommand)) {
|
||||
if(aContentType.Equals(kXMLTextContentType) ||
|
||||
aContentType.Equals(kRDFTextContentType) ||
|
||||
aContentType.Equals(kXULTextContentType)) {
|
||||
result=eValidDetect;
|
||||
}
|
||||
else {
|
||||
if(-1<aBuffer.Find("<?xml ")) {
|
||||
if(0==aContentType.Length()) {
|
||||
aContentType = kXMLTextContentType; //only reset it if it's empty
|
||||
}
|
||||
result=eValidDetect;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
|
|
|
@ -91,15 +91,7 @@ class CWellFormedDTD : public nsIDTD {
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
|
|
|
@ -383,31 +383,23 @@ nsresult nsXIFDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
|||
* 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 gpk 07/09/98
|
||||
* @update gess 02/16/99
|
||||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool nsXIFDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
PRBool result=aContentType.Equals(kXIFTextContentType);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gpk 07/09/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAutoDetectResult nsXIFDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
eAutoDetectResult nsXIFDTD::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
if(kNotFound!=aBuffer.Find(kXIFDocHeader))
|
||||
{
|
||||
PRInt32 offset = aBuffer.Find("<section>");
|
||||
if (offset != -1)
|
||||
aBuffer.Cut(0,offset);
|
||||
aType = kXIFTextContentType;
|
||||
result=eValidDetect;
|
||||
if(aContentType.Equals(kXIFTextContentType)){
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
else {
|
||||
if(kNotFound!=aBuffer.Find(kXIFDocHeader)) {
|
||||
PRInt32 offset = aBuffer.Find("<section>");
|
||||
if (offset != -1)
|
||||
aBuffer.Cut(0,offset);
|
||||
aContentType= kXIFTextContentType;
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -146,17 +146,7 @@ class nsXIFDTD : public nsIDTD {
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gpk 7/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
|
||||
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -437,40 +437,29 @@ PRBool CNavDTD::Verify(nsString& aURLRef,nsIParser* aParser){
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
PRBool result=PR_FALSE;
|
||||
if(!aCommand.Equals(kViewSourceCommand)) {
|
||||
if(PR_TRUE==aContentType.Equals(kHTMLTextContentType) || PR_TRUE==aContentType.Equals(kPlainTextContentType)) {
|
||||
result=PR_TRUE;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAutoDetectResult CNavDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
eAutoDetectResult CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
|
||||
if(PR_TRUE==aType.Equals(kHTMLTextContentType) ||
|
||||
PR_TRUE==aType.Equals(kPlainTextContentType)) {
|
||||
result=eValidDetect;
|
||||
}
|
||||
else {
|
||||
//otherwise, look into the buffer to see if you recognize anything...
|
||||
if(BufferContainsHTML(aBuffer)){
|
||||
if(!aCommand.Equals(kViewSourceCommand)) {
|
||||
if(PR_TRUE==aContentType.Equals(kHTMLTextContentType)) {
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
else if(PR_TRUE==aContentType.Equals(kPlainTextContentType)) {
|
||||
result=eValidDetect;
|
||||
if(0==aType.Length())
|
||||
aType=kHTMLTextContentType;
|
||||
}
|
||||
else {
|
||||
//otherwise, look into the buffer to see if you recognize anything...
|
||||
if(BufferContainsHTML(aBuffer)){
|
||||
result=ePrimaryDetect;
|
||||
if(0==aContentType.Length())
|
||||
aContentType=kHTMLTextContentType;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
|
@ -558,17 +547,21 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse
|
|||
result = CloseContainersTo(0,eHTMLTag_unknown,PR_FALSE);
|
||||
}
|
||||
|
||||
result = mSink->DidBuildModel(1);
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef NS_DEBUG
|
||||
if(mComputedCRC32!=mExpectedCRC32) {
|
||||
if(mExpectedCRC32!=0) {
|
||||
printf("Expected CRC: %u,",mExpectedCRC32);
|
||||
result = mSink->DidBuildModel(2);
|
||||
}
|
||||
else {
|
||||
printf("Computed CRC: %u.\n",mComputedCRC32);
|
||||
result = mSink->DidBuildModel(3);
|
||||
}
|
||||
printf("Computed CRC: %u.\n",mComputedCRC32);
|
||||
}
|
||||
else result = mSink->DidBuildModel(0);
|
||||
#else
|
||||
result = mSink->DidBuildModel(3);
|
||||
#endif
|
||||
|
||||
if(mDTDDebug) {
|
||||
mDTDDebug->DumpVectorRecord();
|
||||
}
|
||||
|
@ -631,7 +624,7 @@ nsresult CNavDTD::ReleaseTokenPump(nsITagHandler* aHandler){
|
|||
nsresult result=NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This gets called after we've handled a given start tag.
|
||||
* It's a generic hook to let us to post processing.
|
||||
|
@ -639,7 +632,7 @@ nsresult CNavDTD::ReleaseTokenPump(nsITagHandler* aHandler){
|
|||
* @param aChildTag is the tag itself.
|
||||
* @return status
|
||||
*/
|
||||
nsresult CNavDTD::DidHandleStartTag(CToken* aToken,eHTMLTags aChildTag){
|
||||
nsresult CNavDTD::DidHandleStartTag(nsCParserNode& aNode,eHTMLTags aChildTag){
|
||||
nsresult result=NS_OK;
|
||||
|
||||
CToken* theNextToken=mTokenizer->PeekToken();
|
||||
|
@ -676,10 +669,9 @@ nsresult CNavDTD::DidHandleStartTag(CToken* aToken,eHTMLTags aChildTag){
|
|||
case eHTMLTag_plaintext:
|
||||
case eHTMLTag_xmp:
|
||||
//grab the skipped content and dump it out as text...
|
||||
if(theNextToken && mSink){
|
||||
eHTMLTokenTypes theType=eHTMLTokenTypes(theNextToken->GetTokenType());
|
||||
if(eToken_skippedcontent==theType){
|
||||
nsString& theText=((CAttributeToken*)theNextToken)->GetKey();
|
||||
{
|
||||
const nsString& theText=aNode.GetSkippedContent();
|
||||
if(0<theText.Length()) {
|
||||
CViewSourceHTML::WriteText(theText,*mSink,PR_TRUE);
|
||||
}
|
||||
}
|
||||
|
@ -1061,7 +1053,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
|
|||
} //switch
|
||||
//now do any post processing necessary on the tag...
|
||||
if(NS_OK==result)
|
||||
DidHandleStartTag(aToken,theChildTag);
|
||||
DidHandleStartTag(attrNode,theChildTag);
|
||||
}
|
||||
} //if
|
||||
|
||||
|
|
|
@ -159,18 +159,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
* being asked to parse).
|
||||
* @return TRUE if this DTD parse the given type; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* This method gets called to determine if the DTD can determine the
|
||||
* kind of data contained in the given buffer string. If you know the
|
||||
* type, the you should enter its stringname aType.
|
||||
* @update gess7/7/98
|
||||
* @param aBuffer contains data to be examined for autodetection.
|
||||
* @param aType will contain a typename you specify.
|
||||
* @return unknown, valid (if you know the type), invalid (if you dont)
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* Called by the parser to initiate dtd verification of the
|
||||
|
@ -516,7 +505,7 @@ protected:
|
|||
nsresult CollectAttributes(nsCParserNode& aNode,PRInt32 aCount);
|
||||
nsresult CollectSkippedContent(nsCParserNode& aNode,PRInt32& aCount);
|
||||
nsresult WillHandleStartTag(CToken* aToken,eHTMLTags aChildTag,nsCParserNode& aNode);
|
||||
nsresult DidHandleStartTag(CToken* aToken,eHTMLTags aChildTag);
|
||||
nsresult DidHandleStartTag(nsCParserNode& aNode,eHTMLTags aChildTag);
|
||||
|
||||
|
||||
nsIHTMLContentSink* mSink;
|
||||
|
|
|
@ -177,21 +177,10 @@ nsresult COtherDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool COtherDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
return CNavDTD::CanParse(aContentType,aCommand,aVersion);
|
||||
eAutoDetectResult COtherDTD::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
return CNavDTD::CanParse(aContentType,aCommand,aBuffer,aVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAutoDetectResult COtherDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
return CNavDTD::AutoDetectContentType(aBuffer,aType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called when a start token has been
|
||||
* encountered in the parse process. If the current container
|
||||
|
|
|
@ -81,15 +81,7 @@ class COtherDTD : public CNavDTD {
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -242,23 +242,14 @@ nsresult CRtfDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool CRtfDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
PRBool result=aContentType.Equals(kRTFTextContentType);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAutoDetectResult CRtfDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
eAutoDetectResult CRtfDTD::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
if(kNotFound!=aBuffer.Find(kRTFDocHeader))
|
||||
if(PR_TRUE==aType.Equals(kRTFTextContentType))
|
||||
result=eValidDetect;
|
||||
if(aContentType.Equals(kRTFTextContentType)) {
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
else if(kNotFound!=aBuffer.Find(kRTFDocHeader)) {
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -184,15 +184,7 @@ class CRtfDTD : public nsIDTD {
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
|
|
|
@ -39,6 +39,14 @@
|
|||
#define NS_IDTD_IID \
|
||||
{ 0xa6cf9053, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
enum eAutoDetectResult {
|
||||
eUnknownDetect,
|
||||
eValidDetect,
|
||||
ePrimaryDetect,
|
||||
eInvalidDetect
|
||||
};
|
||||
|
||||
|
||||
class nsIParser;
|
||||
class CToken;
|
||||
class nsIDTDDebug;
|
||||
|
@ -47,9 +55,6 @@ class nsString;
|
|||
class nsITagHandler;
|
||||
class nsIContentSink;
|
||||
|
||||
enum eAutoDetectResult {eUnknownDetect, eValidDetect, eInvalidDetect};
|
||||
|
||||
|
||||
|
||||
class nsIDTD : public nsISupports {
|
||||
public:
|
||||
|
@ -80,18 +85,7 @@ class nsIDTD : public nsISupports {
|
|||
* @param aContentType -- string representing type of doc to be converted (ie text/html)
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion)=0;
|
||||
|
||||
/**
|
||||
* This method, typically called by the parser, is used to try to autodetect the
|
||||
* type of data contained in the given buffer. The implementor should look at the
|
||||
* buffers contents to try to determine its encoding type.
|
||||
* @update gess7/7/98
|
||||
* @param aBuffer-contains data to be scanned to autodetect type
|
||||
* @param aType-will hold the result if type is autodetected
|
||||
* @return eValid (if detected), eInvalid (if not) or eUnknown (if nothing can be done)
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType)=0;
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion)=0;
|
||||
|
||||
/**
|
||||
* Called by the parser just before the parsing process begins
|
||||
|
|
|
@ -65,6 +65,7 @@ enum eCRCQuality {
|
|||
eCRCPoor
|
||||
};
|
||||
|
||||
|
||||
enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
|
||||
|
||||
/**
|
||||
|
@ -114,17 +115,6 @@ class nsIParser : public nsISupports {
|
|||
*/
|
||||
virtual void SetCommand(const char* aCommand)=0;
|
||||
|
||||
/**
|
||||
* This internal method is used when the parser needs to determine the
|
||||
* type of content it's being asked to parse.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aBuffer -- contains data to be tested (autodetected) for type
|
||||
* @param aType -- string where you store the detected type (if any)
|
||||
* @return autodetect enum (valid, invalid, unknown)
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType)=0;
|
||||
|
||||
|
||||
/******************************************************************************************
|
||||
* Parse methods always begin with an input source, and perform conversions
|
||||
|
|
|
@ -327,68 +327,34 @@ eParseMode nsParser::GetParseMode(void){
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRBool FindSuitableDTD( CParserContext& aParserContext,nsString& aCommand) {
|
||||
PRBool FindSuitableDTD( CParserContext& aParserContext,nsString& aCommand,nsString& aBuffer) {
|
||||
|
||||
//Let's start by tring the defaultDTD, if one exists...
|
||||
if(aParserContext.mDTD)
|
||||
if(aParserContext.mDTD->CanParse(aParserContext.mSourceType,aCommand,0))
|
||||
if(aParserContext.mDTD->CanParse(aParserContext.mSourceType,aCommand,aBuffer,0))
|
||||
return PR_TRUE;
|
||||
|
||||
PRBool result=PR_FALSE;
|
||||
|
||||
nsDequeIterator b=gSharedParserObjects.mDTDDeque.Begin();
|
||||
nsDequeIterator e=gSharedParserObjects.mDTDDeque.End();
|
||||
|
||||
while(b<e){
|
||||
aParserContext.mAutoDetectStatus=eUnknownDetect;
|
||||
nsIDTD* theBestDTD=0;
|
||||
while((b<e) && (aParserContext.mAutoDetectStatus!=ePrimaryDetect)){
|
||||
nsIDTD* theDTD=(nsIDTD*)b.GetCurrent();
|
||||
if(theDTD) {
|
||||
result=theDTD->CanParse(aParserContext.mSourceType,aCommand,0);
|
||||
if(result){
|
||||
theDTD->CreateNewInstance(&aParserContext.mDTD);
|
||||
break;
|
||||
aParserContext.mAutoDetectStatus=theDTD->CanParse(aParserContext.mSourceType,aCommand,aBuffer,0);
|
||||
if((eValidDetect==aParserContext.mAutoDetectStatus) || (ePrimaryDetect==aParserContext.mAutoDetectStatus)) {
|
||||
theBestDTD=theDTD;
|
||||
}
|
||||
}
|
||||
b++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method if you want the known DTD's to try
|
||||
* to detect the document type based through analysis
|
||||
* of the underlying stream.
|
||||
*
|
||||
* @update gess6/22/98
|
||||
* @param aBuffer -- nsString containing sample data to be analyzed.
|
||||
* @param aType -- may hold typename given from netlib; will hold result given by DTD's.
|
||||
* @return auto-detect result: eValid, eInvalid, eUnknown
|
||||
*/
|
||||
eAutoDetectResult nsParser::AutoDetectContentType(nsString& aBuffer,nsString& aType) {
|
||||
|
||||
//The process:
|
||||
// You should go out and ask each DTD if they
|
||||
// recognize the content in the scanner.
|
||||
// Somebody should say yes, or we can't continue.
|
||||
|
||||
//This method may change mSourceType and mParserContext->mDTD.
|
||||
//It absolutely changes mParserContext->mAutoDetectStatus
|
||||
|
||||
nsDequeIterator b=gSharedParserObjects.mDTDDeque.Begin();
|
||||
nsDequeIterator e=gSharedParserObjects.mDTDDeque.End();
|
||||
|
||||
mParserContext->mAutoDetectStatus=eUnknownDetect;
|
||||
while(b<e){
|
||||
nsIDTD* theDTD=(nsIDTD*)b.GetCurrent();
|
||||
if(theDTD) {
|
||||
mParserContext->mAutoDetectStatus=theDTD->AutoDetectContentType(aBuffer,aType);
|
||||
if(eValidDetect==mParserContext->mAutoDetectStatus)
|
||||
break;
|
||||
}
|
||||
b++;
|
||||
}
|
||||
|
||||
return mParserContext->mAutoDetectStatus;
|
||||
if(theBestDTD) {
|
||||
theBestDTD->CreateNewInstance(&aParserContext.mDTD);
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -443,24 +409,21 @@ nsresult nsParser::WillBuildModel(nsString& aFilename,nsIDTD* aDefaultDTD){
|
|||
|
||||
nsresult result=NS_OK;
|
||||
|
||||
if(eOnStart==mParserContext->mStreamListenerState) {
|
||||
mMajorIteration=-1;
|
||||
mMinorIteration=-1;
|
||||
if(eUnknownDetect==mParserContext->mAutoDetectStatus) {
|
||||
if(eValidDetect==AutoDetectContentType(mParserContext->mScanner->GetBuffer(),mParserContext->mSourceType)) {
|
||||
if(mParserContext){
|
||||
if(mParserContext){
|
||||
if(eOnStart==mParserContext->mStreamListenerState) {
|
||||
mMajorIteration=-1;
|
||||
mMinorIteration=-1;
|
||||
if(eUnknownDetect==mParserContext->mAutoDetectStatus) {
|
||||
mParserContext->mDTD=aDefaultDTD;
|
||||
if(PR_TRUE==FindSuitableDTD(*mParserContext,mCommand,mParserContext->mScanner->GetBuffer())) {
|
||||
mParserContext->mParseMode=DetermineParseMode(*this);
|
||||
mParserContext->mDTD=aDefaultDTD;
|
||||
if(PR_TRUE==FindSuitableDTD(*mParserContext,mCommand)) {
|
||||
//mParserContext->mDTD->SetContentSink(mSink);
|
||||
mParserContext->mStreamListenerState=eOnDataAvail;
|
||||
mParserContext->mDTD->WillBuildModel(aFilename,PRBool(0==mParserContext->mPrevContext),this,mSink);
|
||||
}
|
||||
}
|
||||
else result=kInvalidParserContext;
|
||||
} //if
|
||||
}
|
||||
}
|
||||
mParserContext->mStreamListenerState=eOnDataAvail;
|
||||
mParserContext->mDTD->WillBuildModel(aFilename,PRBool(0==mParserContext->mPrevContext),this,mSink);
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
}
|
||||
else result=kInvalidParserContext;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -290,18 +290,6 @@ private:
|
|||
*/
|
||||
PRBool DidTokenize();
|
||||
|
||||
/**
|
||||
* This method is used as a backstop to compute the kind of content
|
||||
* that is contained in the scanner stream. This method is important
|
||||
* because it allows us to defer the resolution of our DTD (and hence)
|
||||
* filters and maybe eventually sinks based on the input type.
|
||||
*
|
||||
* @update gess6/22/98
|
||||
* @param
|
||||
* @return TRUE if we figured it out.
|
||||
*/
|
||||
eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
|
||||
|
||||
protected:
|
||||
//*********************************************
|
||||
|
|
|
@ -176,12 +176,11 @@ nsresult CValidDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool CValidDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
PRBool result=aContentType.Equals(kXMLTextContentType);
|
||||
eAutoDetectResult CValidDTD::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can perform
|
||||
* a document conversion from a given source-type to a given target-type.
|
||||
|
@ -195,17 +194,6 @@ PRBool CValidDTD::CanConvert(nsString& aSourceType, nsString& aTargetType, PRInt
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAutoDetectResult CValidDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
|
|
|
@ -92,8 +92,7 @@ class CValidDTD : public nsIDTD {
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* This method is called to determine if the given DTD can perform
|
||||
|
@ -105,14 +104,6 @@ class CValidDTD : public nsIDTD {
|
|||
*/
|
||||
virtual PRBool CanConvert(nsString& aSourceType, nsString& aTargetType, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
* the process begins, WillBuildModel() is called. Afterwards the parser
|
||||
|
|
|
@ -227,30 +227,17 @@ nsresult CViewSourceHTML::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
PRBool result=PR_FALSE;
|
||||
if(aCommand.Equals(kViewSourceCommand)) {
|
||||
result=(aContentType.Equals(kXMLTextContentType) ||
|
||||
aContentType.Equals(kRDFTextContentType) ||
|
||||
aContentType.Equals(kHTMLTextContentType) ||
|
||||
aContentType.Equals(kPlainTextContentType) ||
|
||||
aContentType.Equals(kXULTextContentType));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is called to ask the DTD if it recognizes either the aType or data in the buffer.
|
||||
* We intentionally say NO to autodetect types so that XML and HTML dtds can do the right thing.
|
||||
* If either of those DTD's say YES, then we'll agree and render either.
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return detect result
|
||||
*/
|
||||
eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
eAutoDetectResult CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
if(aCommand.Equals(kViewSourceCommand)) {
|
||||
if(aContentType.Equals(kXMLTextContentType) ||
|
||||
aContentType.Equals(kRDFTextContentType) ||
|
||||
aContentType.Equals(kHTMLTextContentType) ||
|
||||
aContentType.Equals(kPlainTextContentType) ||
|
||||
aContentType.Equals(kXULTextContentType)) {
|
||||
result=eValidDetect;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -503,7 +490,7 @@ nsresult WriteNBSP(PRInt32 aCount, nsIContentSink& aSink) {
|
|||
* @param
|
||||
* @return result status
|
||||
*/
|
||||
nsresult CViewSourceHTML::WriteText(nsString& aTextString,nsIContentSink& aSink,PRBool aPreserveSpace) {
|
||||
nsresult CViewSourceHTML::WriteText(const nsString& aTextString,nsIContentSink& aSink,PRBool aPreserveSpace) {
|
||||
nsresult result=NS_OK;
|
||||
|
||||
CTextToken theTextToken;
|
||||
|
|
|
@ -93,15 +93,7 @@ class CViewSourceHTML: public nsIDTD {
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
|
@ -233,7 +225,7 @@ class CViewSourceHTML: public nsIDTD {
|
|||
virtual PRBool IsContainer(PRInt32 aTag) const;
|
||||
|
||||
|
||||
static nsresult WriteText(nsString& aTextString,nsIContentSink& aSink,PRBool aPreserveText);
|
||||
static nsresult WriteText(const nsString& aTextString,nsIContentSink& aSink,PRBool aPreserveText);
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -179,39 +179,28 @@ nsresult CWellFormedDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool CWellFormedDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
PRBool result=PR_FALSE;
|
||||
if(!aCommand.Equals(kViewSourceCommand)) {
|
||||
result=(aContentType.Equals(kXMLTextContentType) ||
|
||||
aContentType.Equals(kRDFTextContentType) ||
|
||||
aContentType.Equals(kXULTextContentType));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAutoDetectResult CWellFormedDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
eAutoDetectResult CWellFormedDTD::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
if(PR_TRUE==aType.Equals(kXMLTextContentType) ||
|
||||
PR_TRUE==aType.Equals(kRDFTextContentType) ||
|
||||
PR_TRUE==aType.Equals(kXULTextContentType)) {
|
||||
result=eValidDetect;
|
||||
}
|
||||
else {
|
||||
if(-1<aBuffer.Find("<?xml ")) {
|
||||
aType = kXMLTextContentType;
|
||||
|
||||
if(!aCommand.Equals(kViewSourceCommand)) {
|
||||
if(aContentType.Equals(kXMLTextContentType) ||
|
||||
aContentType.Equals(kRDFTextContentType) ||
|
||||
aContentType.Equals(kXULTextContentType)) {
|
||||
result=eValidDetect;
|
||||
}
|
||||
else {
|
||||
if(-1<aBuffer.Find("<?xml ")) {
|
||||
if(0==aContentType.Length()) {
|
||||
aContentType = kXMLTextContentType; //only reset it if it's empty
|
||||
}
|
||||
result=eValidDetect;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/18/98
|
||||
|
|
|
@ -91,15 +91,7 @@ class CWellFormedDTD : public nsIDTD {
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/7/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
* The parser uses a code sandwich to wrap the parsing process. Before
|
||||
|
|
|
@ -383,31 +383,23 @@ nsresult nsXIFDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
|
|||
* 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 gpk 07/09/98
|
||||
* @update gess 02/16/99
|
||||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
PRBool nsXIFDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
|
||||
PRBool result=aContentType.Equals(kXIFTextContentType);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gpk 07/09/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAutoDetectResult nsXIFDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
|
||||
eAutoDetectResult nsXIFDTD::CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion) {
|
||||
eAutoDetectResult result=eUnknownDetect;
|
||||
if(kNotFound!=aBuffer.Find(kXIFDocHeader))
|
||||
{
|
||||
PRInt32 offset = aBuffer.Find("<section>");
|
||||
if (offset != -1)
|
||||
aBuffer.Cut(0,offset);
|
||||
aType = kXIFTextContentType;
|
||||
result=eValidDetect;
|
||||
if(aContentType.Equals(kXIFTextContentType)){
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
else {
|
||||
if(kNotFound!=aBuffer.Find(kXIFDocHeader)) {
|
||||
PRInt32 offset = aBuffer.Find("<section>");
|
||||
if (offset != -1)
|
||||
aBuffer.Cut(0,offset);
|
||||
aContentType= kXIFTextContentType;
|
||||
result=ePrimaryDetect;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -146,17 +146,7 @@ class nsXIFDTD : public nsIDTD {
|
|||
* @param
|
||||
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
|
||||
*/
|
||||
virtual PRBool CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gpk 7/9/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType);
|
||||
|
||||
|
||||
virtual eAutoDetectResult CanParse(nsString& aContentType, nsString& aCommand, nsString& aBuffer, PRInt32 aVersion);
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче