This commit is contained in:
rickg%netscape.com 1998-11-13 04:36:46 +00:00
Родитель 9b21f39f54
Коммит 1a47a78ee2
14 изменённых файлов: 82 добавлений и 48 удалений

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

@ -168,7 +168,7 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
// XXX For now, we'll use the HTML DTD
NS_NewWellFormed_DTD(&theDTD);
mParser->RegisterDTD(theDTD);
mParser->SetCommand(aCommand);
mParser->SetContentSink(sink);
mParser->Parse(aUrl);
}

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

@ -49,6 +49,7 @@ static const char* kNullToken = "Error: Null token given";
static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kHTMLTextContentType = "text/html";
static char* kVerificationDir = "c:/temp";
static const char* kViewSourceCommand= "view-source";
static nsAutoString gEmpty;
@ -324,7 +325,10 @@ PRBool CNavDTD::Verify(nsString& aURLRef){
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
*/
PRBool CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
PRBool result=aContentType.Equals(kHTMLTextContentType);
PRBool result=PR_FALSE;
if(!aCommand.Equals(kViewSourceCommand)) {
result=aContentType.Equals(kHTMLTextContentType);
}
return result;
}

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

@ -92,8 +92,8 @@ class nsIParser : public nsISupports {
* this allows us to select a DTD which can do, say, view-source.
*
* @update gess 3/25/98
* @param aContentSink -- ptr to content sink that will receive output
* @return ptr to previously set contentsink (usually null)
* @param aCommand -- ptrs to string that contains command
* @return nada
*/
virtual void SetCommand(const char* aCommand)=0;

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

@ -57,6 +57,7 @@ static NS_DEFINE_IID(kClassIID, NS_VIEWSOURCE_HTML_IID);
//static const char* kNullToken = "Error: Null token given";
//static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kHTMLTextContentType = "text/html";
static const char* kXMLTextContentType = "text/xml";
static const char* kViewSourceCommand= "view-source";
static nsAutoString gEmpty;
@ -182,6 +183,7 @@ CViewSourceHTML::CViewSourceHTML() : nsIDTD(), mTokenDeque(gTokenKiller) {
mSink=0;
mFilename;
mLineNumber=0;
mIsHTML=PR_FALSE;
}
/**
@ -217,6 +219,9 @@ nsresult CViewSourceHTML::CreateNewInstance(nsIDTD** aInstancePtrResult){
*/
PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
PRBool result=(aContentType.Equals(kHTMLTextContentType) && (aCommand.Equals(kViewSourceCommand)));
if(!result) {
result=(aContentType.Equals(kXMLTextContentType) && (aCommand.Equals(kViewSourceCommand)));
}
return result;
}
@ -231,6 +236,8 @@ eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsStr
eAutoDetectResult result=eUnknownDetect;
if(PR_TRUE==aType.Equals(kHTMLTextContentType))
result=eValidDetect;
else if(PR_TRUE==aType.Equals(kXMLTextContentType))
result=eValidDetect;
return result;
}
@ -249,6 +256,7 @@ NS_IMETHODIMP CViewSourceHTML::WillBuildModel(nsString& aFilename,PRBool aNotify
result = mSink->WillBuildModel();
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
mIsHTML=(0<aFilename.RFind(".htm",PR_TRUE));
{
nsIHTMLContentSink* theSink=(nsIHTMLContentSink*)mSink;
@ -261,12 +269,10 @@ NS_IMETHODIMP CViewSourceHTML::WillBuildModel(nsString& aFilename,PRBool aNotify
CStartToken theBodyToken(eHTMLTag_body);
nsCParserNode theBodyNode(&theBodyToken,0);
theSink->OpenBody(theBodyNode);
SetFont("courier","-1",PR_TRUE,*mSink);
}
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
SetFont("courier","-1",PR_TRUE,*mSink);
}
return result;
@ -285,7 +291,6 @@ NS_IMETHODIMP CViewSourceHTML::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifyS
if((aNotifySink) && (mSink)) {
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
{
nsIHTMLContentSink* theSink=(nsIHTMLContentSink*)mSink;
@ -302,10 +307,9 @@ NS_IMETHODIMP CViewSourceHTML::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifyS
CEndToken theHTMLToken(eHTMLTag_html);
nsCParserNode theHTMLNode(&theBodyToken,0);
theSink->CloseHTML(theBodyNode);
result = mSink->DidBuildModel(1);
}
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
result = mSink->DidBuildModel(1);
}
return result;
@ -759,11 +763,11 @@ PRBool CViewSourceHTML::IsContainer(PRInt32 aTag) const{
* @param aTag -- tag to test for containership
* @return PR_TRUE if given tag can contain other tags
*/
PRBool EmitTag(nsCParserNode& aNode,nsIContentSink& aSink,PRBool anEndToken) {
PRBool EmitTag(nsCParserNode& aNode,nsIContentSink& aSink,PRBool anEndToken,PRBool aIsHTML) {
static nsString theString;
static nsAutoString theLTEntity("lt");
static nsAutoString theGTEntity("gt");
static const char* theColors[]={"purple","red"};
static const char* theColors[][2]={{"purple","purple"},{"purple","red"}};
PRBool result=PR_TRUE;
@ -772,7 +776,7 @@ PRBool EmitTag(nsCParserNode& aNode,nsIContentSink& aSink,PRBool anEndToken) {
aSink.AddLeaf(theStartNode);
SetStyle(eHTMLTag_b,PR_TRUE,aSink);
SetColor(theColors[eHTMLTag_userdefined==aNode.GetNodeType()],PR_TRUE,aSink);
SetColor(theColors[aIsHTML][eHTMLTag_userdefined==aNode.GetNodeType()],PR_TRUE,aSink);
if(anEndToken)
theString="/";
@ -869,19 +873,19 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken) {
break;
case eToken_comment:
case eToken_instruction:
{
SetColor("green",PR_TRUE,*mSink);
static const char* colors[] = {"orange","green"};
SetColor(colors[eToken_comment==theType],PR_TRUE,*mSink);
SetStyle(eHTMLTag_i,PR_TRUE,*mSink);
CTextToken theTextToken(aToken->GetStringValueXXX());
nsCParserNode theTextNode(&theTextToken,mLineNumber);
result=mSink->AddLeaf(theTextNode);
SetStyle(eHTMLTag_i,PR_FALSE,*mSink);
SetStyle(eHTMLTag_font,PR_FALSE,*mSink);
}
break;
case eToken_instruction:
result=mSink->AddProcessingInstruction(theNode);
break;
case eToken_start:
{
PRInt16 attrCount=aToken->GetAttributeCount();
@ -904,7 +908,7 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken) {
//intentionally fall through...
case eToken_end:
EmitTag(theNode,*mSink,theEndTag);
EmitTag(theNode,*mSink,theEndTag,mIsHTML);
break;
case eToken_style:

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

@ -234,6 +234,7 @@ protected:
nsString mFilename;
PRInt32 mLineNumber;
nsDeque mTokenDeque;
PRBool mIsHTML;
};
extern NS_HTMLPARS nsresult NS_NewViewSourceHTML(nsIDTD** aInstancePtrResult);

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

@ -57,6 +57,7 @@ static NS_DEFINE_IID(kClassIID, NS_WELLFORMED_DTD_IID);
//static const char* kNullToken = "Error: Null token given";
//static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kXMLTextContentType = "text/xml";
static const char* kViewSourceCommand= "view-source";
static nsAutoString gEmpty;
static CTokenRecycler gTokenRecycler;
@ -168,7 +169,10 @@ nsresult CWellFormedDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
*/
PRBool CWellFormedDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
PRBool result=aContentType.Equals(kXMLTextContentType);
PRBool result=PR_FALSE;
if(!aCommand.Equals(kViewSourceCommand)) {
result=aContentType.Equals(kXMLTextContentType);
}
return result;
}

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

@ -168,7 +168,7 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
// XXX For now, we'll use the HTML DTD
NS_NewWellFormed_DTD(&theDTD);
mParser->RegisterDTD(theDTD);
mParser->SetCommand(aCommand);
mParser->SetContentSink(sink);
mParser->Parse(aUrl);
}

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

@ -49,6 +49,7 @@ static const char* kNullToken = "Error: Null token given";
static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kHTMLTextContentType = "text/html";
static char* kVerificationDir = "c:/temp";
static const char* kViewSourceCommand= "view-source";
static nsAutoString gEmpty;
@ -324,7 +325,10 @@ PRBool CNavDTD::Verify(nsString& aURLRef){
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
*/
PRBool CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
PRBool result=aContentType.Equals(kHTMLTextContentType);
PRBool result=PR_FALSE;
if(!aCommand.Equals(kViewSourceCommand)) {
result=aContentType.Equals(kHTMLTextContentType);
}
return result;
}

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

@ -92,8 +92,8 @@ class nsIParser : public nsISupports {
* this allows us to select a DTD which can do, say, view-source.
*
* @update gess 3/25/98
* @param aContentSink -- ptr to content sink that will receive output
* @return ptr to previously set contentsink (usually null)
* @param aCommand -- ptrs to string that contains command
* @return nada
*/
virtual void SetCommand(const char* aCommand)=0;

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

@ -57,6 +57,7 @@ static NS_DEFINE_IID(kClassIID, NS_VIEWSOURCE_HTML_IID);
//static const char* kNullToken = "Error: Null token given";
//static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kHTMLTextContentType = "text/html";
static const char* kXMLTextContentType = "text/xml";
static const char* kViewSourceCommand= "view-source";
static nsAutoString gEmpty;
@ -182,6 +183,7 @@ CViewSourceHTML::CViewSourceHTML() : nsIDTD(), mTokenDeque(gTokenKiller) {
mSink=0;
mFilename;
mLineNumber=0;
mIsHTML=PR_FALSE;
}
/**
@ -217,6 +219,9 @@ nsresult CViewSourceHTML::CreateNewInstance(nsIDTD** aInstancePtrResult){
*/
PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
PRBool result=(aContentType.Equals(kHTMLTextContentType) && (aCommand.Equals(kViewSourceCommand)));
if(!result) {
result=(aContentType.Equals(kXMLTextContentType) && (aCommand.Equals(kViewSourceCommand)));
}
return result;
}
@ -231,6 +236,8 @@ eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsStr
eAutoDetectResult result=eUnknownDetect;
if(PR_TRUE==aType.Equals(kHTMLTextContentType))
result=eValidDetect;
else if(PR_TRUE==aType.Equals(kXMLTextContentType))
result=eValidDetect;
return result;
}
@ -249,6 +256,7 @@ NS_IMETHODIMP CViewSourceHTML::WillBuildModel(nsString& aFilename,PRBool aNotify
result = mSink->WillBuildModel();
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
mIsHTML=(0<aFilename.RFind(".htm",PR_TRUE));
{
nsIHTMLContentSink* theSink=(nsIHTMLContentSink*)mSink;
@ -261,12 +269,10 @@ NS_IMETHODIMP CViewSourceHTML::WillBuildModel(nsString& aFilename,PRBool aNotify
CStartToken theBodyToken(eHTMLTag_body);
nsCParserNode theBodyNode(&theBodyToken,0);
theSink->OpenBody(theBodyNode);
SetFont("courier","-1",PR_TRUE,*mSink);
}
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
SetFont("courier","-1",PR_TRUE,*mSink);
}
return result;
@ -285,7 +291,6 @@ NS_IMETHODIMP CViewSourceHTML::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifyS
if((aNotifySink) && (mSink)) {
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
{
nsIHTMLContentSink* theSink=(nsIHTMLContentSink*)mSink;
@ -302,10 +307,9 @@ NS_IMETHODIMP CViewSourceHTML::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifyS
CEndToken theHTMLToken(eHTMLTag_html);
nsCParserNode theHTMLNode(&theBodyToken,0);
theSink->CloseHTML(theBodyNode);
result = mSink->DidBuildModel(1);
}
/* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/
result = mSink->DidBuildModel(1);
}
return result;
@ -759,11 +763,11 @@ PRBool CViewSourceHTML::IsContainer(PRInt32 aTag) const{
* @param aTag -- tag to test for containership
* @return PR_TRUE if given tag can contain other tags
*/
PRBool EmitTag(nsCParserNode& aNode,nsIContentSink& aSink,PRBool anEndToken) {
PRBool EmitTag(nsCParserNode& aNode,nsIContentSink& aSink,PRBool anEndToken,PRBool aIsHTML) {
static nsString theString;
static nsAutoString theLTEntity("lt");
static nsAutoString theGTEntity("gt");
static const char* theColors[]={"purple","red"};
static const char* theColors[][2]={{"purple","purple"},{"purple","red"}};
PRBool result=PR_TRUE;
@ -772,7 +776,7 @@ PRBool EmitTag(nsCParserNode& aNode,nsIContentSink& aSink,PRBool anEndToken) {
aSink.AddLeaf(theStartNode);
SetStyle(eHTMLTag_b,PR_TRUE,aSink);
SetColor(theColors[eHTMLTag_userdefined==aNode.GetNodeType()],PR_TRUE,aSink);
SetColor(theColors[aIsHTML][eHTMLTag_userdefined==aNode.GetNodeType()],PR_TRUE,aSink);
if(anEndToken)
theString="/";
@ -869,19 +873,19 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken) {
break;
case eToken_comment:
case eToken_instruction:
{
SetColor("green",PR_TRUE,*mSink);
static const char* colors[] = {"orange","green"};
SetColor(colors[eToken_comment==theType],PR_TRUE,*mSink);
SetStyle(eHTMLTag_i,PR_TRUE,*mSink);
CTextToken theTextToken(aToken->GetStringValueXXX());
nsCParserNode theTextNode(&theTextToken,mLineNumber);
result=mSink->AddLeaf(theTextNode);
SetStyle(eHTMLTag_i,PR_FALSE,*mSink);
SetStyle(eHTMLTag_font,PR_FALSE,*mSink);
}
break;
case eToken_instruction:
result=mSink->AddProcessingInstruction(theNode);
break;
case eToken_start:
{
PRInt16 attrCount=aToken->GetAttributeCount();
@ -904,7 +908,7 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken) {
//intentionally fall through...
case eToken_end:
EmitTag(theNode,*mSink,theEndTag);
EmitTag(theNode,*mSink,theEndTag,mIsHTML);
break;
case eToken_style:

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

@ -234,6 +234,7 @@ protected:
nsString mFilename;
PRInt32 mLineNumber;
nsDeque mTokenDeque;
PRBool mIsHTML;
};
extern NS_HTMLPARS nsresult NS_NewViewSourceHTML(nsIDTD** aInstancePtrResult);

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

@ -57,6 +57,7 @@ static NS_DEFINE_IID(kClassIID, NS_WELLFORMED_DTD_IID);
//static const char* kNullToken = "Error: Null token given";
//static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kXMLTextContentType = "text/xml";
static const char* kViewSourceCommand= "view-source";
static nsAutoString gEmpty;
static CTokenRecycler gTokenRecycler;
@ -168,7 +169,10 @@ nsresult CWellFormedDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
*/
PRBool CWellFormedDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
PRBool result=aContentType.Equals(kXMLTextContentType);
PRBool result=PR_FALSE;
if(!aCommand.Equals(kViewSourceCommand)) {
result=aContentType.Equals(kXMLTextContentType);
}
return result;
}

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

@ -220,7 +220,7 @@ static char* gPluginTypes[] = {
"audio/midi",
"audio/x-midi",
"audio/wav",
"audio/x-wav",
"audio/x-wav",
"audio/aiff",
"audio/x-aiff",
"audio/basic",
@ -239,6 +239,10 @@ nsDocFactoryImpl::CreateInstance(nsIURL* aURL,
{
nsresult rv = NS_ERROR_FAILURE;
if(0==PL_strcmp(gXMLTypes[0],aContentType))
if(0==PL_strcmp(aCommand,"view-source"))
aContentType=gValidTypes[0];
int typeIndex=0;
while(gValidTypes[typeIndex]) {
if (0== PL_strcmp(gValidTypes[typeIndex++], aContentType)) {

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

@ -220,7 +220,7 @@ static char* gPluginTypes[] = {
"audio/midi",
"audio/x-midi",
"audio/wav",
"audio/x-wav",
"audio/x-wav",
"audio/aiff",
"audio/x-aiff",
"audio/basic",
@ -239,6 +239,10 @@ nsDocFactoryImpl::CreateInstance(nsIURL* aURL,
{
nsresult rv = NS_ERROR_FAILURE;
if(0==PL_strcmp(gXMLTypes[0],aContentType))
if(0==PL_strcmp(aCommand,"view-source"))
aContentType=gValidTypes[0];
int typeIndex=0;
while(gValidTypes[typeIndex]) {
if (0== PL_strcmp(gValidTypes[typeIndex++], aContentType)) {