Back to index

lightning-sunbird  0.9+nobinonly
nsLoadSaveContentSink.cpp
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.org 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) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *      Boris Zbarsky <bzbarsky@mit.edu>  (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nscore.h"
00040 #include "nsLoadSaveContentSink.h"
00041 
00042 nsresult
00043 NS_NewLoadSaveContentSink(nsILoadSaveContentSink** aResult,
00044                           nsIXMLContentSink* aBaseSink)
00045 {
00046   NS_PRECONDITION(aResult, "Null out ptr?  Who do you think you are, flouting XPCOM contract?");
00047   NS_ENSURE_ARG_POINTER(aBaseSink);
00048   nsLoadSaveContentSink* it;
00049   NS_NEWXPCOM(it, nsLoadSaveContentSink);
00050   if (!it) {
00051     return NS_ERROR_OUT_OF_MEMORY;
00052   }
00053   
00054   nsresult rv = it->Init(aBaseSink);
00055   if (NS_FAILED(rv)) {
00056     delete it;
00057     return rv;
00058   }
00059 
00060   return CallQueryInterface(it, aResult);  
00061 }
00062 
00063 nsLoadSaveContentSink::nsLoadSaveContentSink()
00064 {
00065 }
00066 
00067 nsLoadSaveContentSink::~nsLoadSaveContentSink()
00068 {
00069 }
00070 
00071 nsresult
00072 nsLoadSaveContentSink::Init(nsIXMLContentSink* aBaseSink)
00073 {
00074   NS_PRECONDITION(aBaseSink, "aBaseSink needs to exist");
00075   mBaseSink = aBaseSink;
00076   mExpatSink = do_QueryInterface(aBaseSink);
00077   if (!mExpatSink) {
00078     return NS_ERROR_INVALID_ARG;
00079   }
00080 
00081   return NS_OK;
00082 }
00083 
00084 NS_IMPL_THREADSAFE_ADDREF(nsLoadSaveContentSink)
00085 NS_IMPL_THREADSAFE_RELEASE(nsLoadSaveContentSink)
00086 
00087 NS_INTERFACE_MAP_BEGIN(nsLoadSaveContentSink)
00088   NS_INTERFACE_MAP_ENTRY(nsIXMLContentSink)
00089   NS_INTERFACE_MAP_ENTRY(nsIExpatSink)
00090   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXMLContentSink)
00091 NS_INTERFACE_MAP_END
00092 
00093 // nsIContentSink
00094 NS_IMETHODIMP
00095 nsLoadSaveContentSink::WillBuildModel(void)
00096 {
00097   return mBaseSink->WillBuildModel();
00098 }
00099 
00100 NS_IMETHODIMP
00101 nsLoadSaveContentSink::DidBuildModel(void)
00102 {
00103   return mBaseSink->DidBuildModel();
00104 }
00105 
00106 NS_IMETHODIMP
00107 nsLoadSaveContentSink::WillInterrupt(void)
00108 {
00109   return mBaseSink->WillInterrupt();
00110 }
00111 
00112 NS_IMETHODIMP
00113 nsLoadSaveContentSink::WillResume(void)
00114 {
00115   return mBaseSink->WillResume();
00116 }
00117 
00118 NS_IMETHODIMP
00119 nsLoadSaveContentSink::SetParser(nsIParser* aParser)
00120 {
00121   return mBaseSink->SetParser(aParser);
00122 }
00123 
00124 void
00125 nsLoadSaveContentSink::FlushPendingNotifications(mozFlushType aType)
00126 {
00127   mBaseSink->FlushPendingNotifications(aType);
00128 }
00129 
00130 NS_IMETHODIMP
00131 nsLoadSaveContentSink::SetDocumentCharset(nsAString& aCharset)
00132 {
00133   return mBaseSink->SetDocumentCharset(aCharset);
00134 }
00135 
00136 // nsIExpatSink
00137 
00138 NS_IMETHODIMP
00139 nsLoadSaveContentSink::HandleStartElement(const PRUnichar *aName, 
00140                                           const PRUnichar **aAtts, 
00141                                           PRUint32 aAttsCount, 
00142                                           PRInt32 aIndex, 
00143                                           PRUint32 aLineNumber)
00144 {
00145   return mExpatSink->HandleStartElement(aName, aAtts, aAttsCount, aIndex,
00146                                         aLineNumber);
00147 }
00148 
00149 NS_IMETHODIMP
00150 nsLoadSaveContentSink::HandleEndElement(const PRUnichar *aName)
00151 {
00152   return mExpatSink->HandleEndElement(aName);
00153 }
00154 
00155 NS_IMETHODIMP
00156 nsLoadSaveContentSink::HandleComment(const PRUnichar *aName)
00157 {
00158   return mExpatSink->HandleComment(aName);
00159 }
00160 
00161 NS_IMETHODIMP
00162 nsLoadSaveContentSink::HandleCDataSection(const PRUnichar *aData, 
00163                                           PRUint32 aLength)
00164 {
00165   return mExpatSink->HandleCDataSection(aData, aLength);
00166 }
00167 
00168 NS_IMETHODIMP
00169 nsLoadSaveContentSink::HandleDoctypeDecl(const nsAString & aSubset, 
00170                                          const nsAString & aName, 
00171                                          const nsAString & aSystemId, 
00172                                          const nsAString & aPublicId,
00173                                          nsISupports* aCatalogData)
00174 {
00175   return mExpatSink->HandleDoctypeDecl(aSubset, aName, aSystemId, aPublicId,
00176                                        aCatalogData);
00177 }
00178 
00179 NS_IMETHODIMP
00180 nsLoadSaveContentSink::HandleCharacterData(const PRUnichar *aData, 
00181                                            PRUint32 aLength)
00182 {
00183   return mExpatSink->HandleCharacterData(aData, aLength);
00184 }
00185 
00186 NS_IMETHODIMP
00187 nsLoadSaveContentSink::HandleProcessingInstruction(const PRUnichar *aTarget, 
00188                                                    const PRUnichar *aData)
00189 {
00190   return mExpatSink->HandleProcessingInstruction(aTarget, aData);
00191 }
00192 
00193 NS_IMETHODIMP
00194 nsLoadSaveContentSink::HandleXMLDeclaration(const PRUnichar *aVersion,
00195                                             const PRUnichar *aEncoding,
00196                                             PRInt32 aStandalone)
00197 {
00198   return mExpatSink->HandleXMLDeclaration(aVersion, aEncoding, aStandalone);
00199 }
00200 
00201 NS_IMETHODIMP
00202 nsLoadSaveContentSink::ReportError(const PRUnichar* aErrorText, 
00203                                    const PRUnichar* aSourceText)
00204 {
00205   // XXX Do error reporting here.  I see no reason to call ReportError
00206   // on the "base" sink; all we need to do is drop the document on the
00207   // floor...
00208   return NS_OK;
00209 }