/* -*- 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.0 (the "NPL"); you may not use this file except in * compliance with the NPL. You may obtain a copy of the NPL at * http://www.mozilla.org/NPL/ * * Software distributed under the NPL is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL * for the specific language governing rights and limitations under the * NPL. * * The Initial Developer of this code under the NPL is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ /** * MODULE NOTES: * @update gess 4/1/98 * * This file declares the concrete HTMLContentSink class. * This class is used during the parsing process as the * primary interface between the parser and the content * model. */ #include "nsHTMLContentSinkStream.h" #include "nsHTMLTokens.h" #include #include "nsstring.h" #include "nsParserTypes.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIContentSinkIID,NS_IHTMLCONTENTSINK_IID); static NS_DEFINE_IID(kClassIID, NS_HTMLCONTENTSINK_STREAM_IID); static char* gHeaderComment = ""; static char* gDocTypeHeader = ""; const int gTabSize=2; static char gBuffer[500]; /** * 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 CHTMLContentSinkStream::QueryInterface(const nsIID& aIID, void** aInstancePtr) { if (NULL == aInstancePtr) { return NS_ERROR_NULL_POINTER; } if(aIID.Equals(kISupportsIID)) { //do IUnknown... *aInstancePtr = (nsIContentSink*)(this); } else if(aIID.Equals(kIContentSinkIID)) { //do IParser base class... *aInstancePtr = (nsIContentSink*)(this); } else if(aIID.Equals(kClassIID)) { //do this class... *aInstancePtr = (CHTMLContentSinkStream*)(this); } else { *aInstancePtr=0; return NS_NOINTERFACE; } ((nsISupports*) *aInstancePtr)->AddRef(); return NS_OK; } NS_IMPL_ADDREF(CHTMLContentSinkStream) NS_IMPL_RELEASE(CHTMLContentSinkStream) /** * This method is defined in nsIParser. It is used to * cause the COM-like construction of an nsParser. * * @update gess 4/8/98 * @param nsIParser** ptr to newly instantiated parser * @return NS_xxx error result */ NS_HTMLPARS nsresult NS_New_HTML_ContentSinkStream(CHTMLContentSinkStream** aInstancePtrResult,ostream* aStream) { CHTMLContentSinkStream* it = new CHTMLContentSinkStream(aStream); if (it == 0) { return NS_ERROR_OUT_OF_MEMORY; } return it->QueryInterface(kClassIID, (void **) aInstancePtrResult); } /** * Construct a content sink stream. * @update gess7/7/98 * @param * @return */ CHTMLContentSinkStream::CHTMLContentSinkStream(ostream* aStream) { mOutput=(0==aStream) ? &cout : aStream; } /** * * @update gess7/7/98 * @param * @return */ CHTMLContentSinkStream::~CHTMLContentSinkStream() { mOutput=0; //we don't own the stream we're given; just forget it. } /** * * @update gess7/7/98 * @param * @return */ void WriteAttributes(const nsIParserNode& aNode,ostream& aStream) { int theCount=aNode.GetAttributeCount(); if(theCount) { int i=0; for(i=0;i