This commit is contained in:
rickg%netscape.com 1999-05-27 06:44:44 +00:00
Родитель 765900b01b
Коммит 54159e2012
4 изменённых файлов: 98 добавлений и 10 удалений

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

@ -30,7 +30,9 @@
#include "nshtmlpars.h"
#include "CNavDTD.h"
#include "nsWellFormedDTD.h"
#include "nsViewSourceHTML.h" //uncomment this to partially enable viewsource...
#include "nsViewSourceHTML.h"
#include "nsHTMLContentSinkStream.h" //this is here so we can get a null sink, which really should be gotten from nsICOntentSink.h
#include "nsIStringStream.h"
#undef rickgdebug
#ifdef rickgdebug
@ -747,16 +749,59 @@ nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aCon
}
/**
*
* Call this method to test whether a given fragment is valid within a given context-stack.
* @update gess 04/01/99
* @param
* @return
* @param aSourceBuffer contains the content blob you're trying to insert
* @param aInsertPos tells us where in the context stack you're trying to do the insertion
* @param aContentType tells us what kind of stuff you're inserting
* @return TRUE if valid, otherwise FALSE
*/
PRBool nsParser::IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType){
/************************************************************************************
This method works like this:
1. Convert aStack to a markup string
2. Append a "sentinel" tag to markup string so we know where new content is inserted
3. Append new context to markup stack
4. Call the normal parse() methods for a string, using an HTMLContentSink.
The output of this call is stored in an outputstring
5. Scan the output string looking for markup inside our sentinel. If non-empty
then we have to assume that the fragment is valid (at least in part)
************************************************************************************/
nsAutoString theContext;
PRUint32 theCount=aStack.GetSize();
PRUint32 theIndex=0;
while(theIndex++<theCount){
theContext.Append("<");
theContext.Append(aStack.TagAt(theCount-theIndex));
theContext.Append(">");
}
theContext.Append("<endnote>");
nsAutoString theBuffer(theContext);
theBuffer.Append(aSourceBuffer);
PRBool result=PR_FALSE;
if(theBuffer.Length()){
//now it's time to try to build the model from this fragment
nsString2 theOutput("",eOneByte);
nsIHTMLContentSink* theSink=0;
nsresult theResult=NS_New_HTML_ContentSinkStream(&theSink,&theOutput,PR_FALSE,PR_FALSE);
SetContentSink(theSink);
theResult=Parse(theBuffer,(void*)&theBuffer,aContentType,PR_FALSE,PR_TRUE);
theOutput.StripWhitespace();
if(NS_OK==theResult){
theOutput.Cut(0,theContext.Length());
PRInt32 aPos=theOutput.RFind("</endnote>");
if(-1<aPos)
theOutput.Truncate(aPos);
result=!theOutput.IsEmpty();
}
}
return result;
}
/**
*
* @update gess 04/01/99

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

@ -65,7 +65,6 @@
#include "nsHTMLTags.h"
class IContentSink;
class nsIHTMLContentSink;
class nsIDTD;
class nsScanner;
class nsIParserFilter;

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

@ -30,7 +30,9 @@
#include "nshtmlpars.h"
#include "CNavDTD.h"
#include "nsWellFormedDTD.h"
#include "nsViewSourceHTML.h" //uncomment this to partially enable viewsource...
#include "nsViewSourceHTML.h"
#include "nsHTMLContentSinkStream.h" //this is here so we can get a null sink, which really should be gotten from nsICOntentSink.h
#include "nsIStringStream.h"
#undef rickgdebug
#ifdef rickgdebug
@ -747,16 +749,59 @@ nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aCon
}
/**
*
* Call this method to test whether a given fragment is valid within a given context-stack.
* @update gess 04/01/99
* @param
* @return
* @param aSourceBuffer contains the content blob you're trying to insert
* @param aInsertPos tells us where in the context stack you're trying to do the insertion
* @param aContentType tells us what kind of stuff you're inserting
* @return TRUE if valid, otherwise FALSE
*/
PRBool nsParser::IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType){
/************************************************************************************
This method works like this:
1. Convert aStack to a markup string
2. Append a "sentinel" tag to markup string so we know where new content is inserted
3. Append new context to markup stack
4. Call the normal parse() methods for a string, using an HTMLContentSink.
The output of this call is stored in an outputstring
5. Scan the output string looking for markup inside our sentinel. If non-empty
then we have to assume that the fragment is valid (at least in part)
************************************************************************************/
nsAutoString theContext;
PRUint32 theCount=aStack.GetSize();
PRUint32 theIndex=0;
while(theIndex++<theCount){
theContext.Append("<");
theContext.Append(aStack.TagAt(theCount-theIndex));
theContext.Append(">");
}
theContext.Append("<endnote>");
nsAutoString theBuffer(theContext);
theBuffer.Append(aSourceBuffer);
PRBool result=PR_FALSE;
if(theBuffer.Length()){
//now it's time to try to build the model from this fragment
nsString2 theOutput("",eOneByte);
nsIHTMLContentSink* theSink=0;
nsresult theResult=NS_New_HTML_ContentSinkStream(&theSink,&theOutput,PR_FALSE,PR_FALSE);
SetContentSink(theSink);
theResult=Parse(theBuffer,(void*)&theBuffer,aContentType,PR_FALSE,PR_TRUE);
theOutput.StripWhitespace();
if(NS_OK==theResult){
theOutput.Cut(0,theContext.Length());
PRInt32 aPos=theOutput.RFind("</endnote>");
if(-1<aPos)
theOutput.Truncate(aPos);
result=!theOutput.IsEmpty();
}
}
return result;
}
/**
*
* @update gess 04/01/99

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

@ -65,7 +65,6 @@
#include "nsHTMLTags.h"
class IContentSink;
class nsIHTMLContentSink;
class nsIDTD;
class nsScanner;
class nsIParserFilter;