Back to index

lightning-sunbird  0.9+nobinonly
nsLoggingSink.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef NS_LOGGING_SINK_H__
00039 #define NS_LOGGING_SINK_H__
00040 
00041 #include "nsILoggingSink.h"
00042 #include "nsIParser.h"
00043 
00044 class nsLoggingSink : public nsILoggingSink {
00045 public:
00046   nsLoggingSink();
00047   virtual ~nsLoggingSink();
00048 
00049   void SetProxySink(nsIHTMLContentSink *aSink) {
00050     mSink=aSink;    
00051   }
00052 
00053   void ReleaseProxySink() {
00054     NS_IF_RELEASE(mSink);
00055     mSink=0;
00056   }
00057 
00058 
00059   // nsISupports
00060   NS_DECL_ISUPPORTS
00061 
00062   // nsIContentSink
00063   NS_IMETHOD WillBuildModel();
00064   NS_IMETHOD DidBuildModel();
00065   NS_IMETHOD WillInterrupt();
00066   NS_IMETHOD WillResume();
00067   NS_IMETHOD SetParser(nsIParser* aParser);
00068   NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
00069   NS_IMETHOD CloseContainer(const nsHTMLTag aTag);
00070   NS_IMETHOD AddHeadContent(const nsIParserNode& aNode);
00071   NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
00072   NS_IMETHOD AddComment(const nsIParserNode& aNode);
00073   NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
00074   NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode);
00075   virtual void FlushPendingNotifications(mozFlushType aType) { }
00076   NS_IMETHOD SetDocumentCharset(nsACString& aCharset) { return NS_OK; }
00077   virtual nsISupports *GetTarget() { return nsnull; }
00078 
00079   // nsIHTMLContentSink
00080   NS_IMETHOD SetTitle(const nsString& aValue);
00081   NS_IMETHOD OpenHTML(const nsIParserNode& aNode);
00082   NS_IMETHOD CloseHTML();
00083   NS_IMETHOD OpenHead(const nsIParserNode& aNode);
00084   NS_IMETHOD CloseHead();
00085   NS_IMETHOD OpenBody(const nsIParserNode& aNode);
00086   NS_IMETHOD CloseBody();
00087   NS_IMETHOD OpenForm(const nsIParserNode& aNode);
00088   NS_IMETHOD CloseForm();
00089   NS_IMETHOD OpenMap(const nsIParserNode& aNode);
00090   NS_IMETHOD CloseMap();
00091   NS_IMETHOD OpenFrameset(const nsIParserNode& aNode);
00092   NS_IMETHOD CloseFrameset();
00093   NS_IMETHOD IsEnabled(PRInt32 aTag, PRBool* aReturn) 
00094   /* Take the largest possible feature set. */
00095   { NS_ENSURE_ARG_POINTER(aReturn); *aReturn = PR_TRUE; return NS_OK; }
00096   NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode) { return NS_OK; }
00097   NS_IMETHOD_(PRBool) IsFormOnStack() { return PR_FALSE; }
00098 
00099   NS_IMETHOD BeginContext(PRInt32 aPosition);
00100   NS_IMETHOD EndContext(PRInt32 aPosition);
00101   NS_IMETHOD WillProcessTokens(void) { return NS_OK; }
00102   NS_IMETHOD DidProcessTokens(void) { return NS_OK; }
00103   NS_IMETHOD WillProcessAToken(void) { return NS_OK; }
00104   NS_IMETHOD DidProcessAToken(void) { return NS_OK; }
00105 
00106   // nsILoggingSink
00107   NS_IMETHOD SetOutputStream(PRFileDesc *aStream,PRBool autoDelete=PR_FALSE);
00108 
00109   nsresult OpenNode(const char* aKind, const nsIParserNode& aNode);
00110   nsresult CloseNode(const char* aKind);
00111   nsresult LeafNode(const nsIParserNode& aNode);
00112   nsresult WriteAttributes(const nsIParserNode& aNode);
00113   nsresult QuoteText(const nsAString& aValue, nsString& aResult);
00114   nsresult GetNewCString(const nsAString& aValue, char** aResult);
00115   PRBool WillWriteAttributes(const nsIParserNode& aNode);
00116 
00117 protected:
00118   PRFileDesc          *mOutput;
00119        int                                   mLevel;
00120   nsIHTMLContentSink  *mSink;
00121   PRBool              mAutoDeleteOutput;
00122   nsIParser*          mParser;
00123 };
00124 
00125 #endif
00126