Back to index

lightning-sunbird  0.9+nobinonly
nsExpatDriver.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.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) 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_EXPAT_DRIVER__
00039 #define NS_EXPAT_DRIVER__
00040 
00041 #include "expat_config.h"
00042 #include "expat.h"
00043 #include "nsCOMPtr.h"
00044 #include "nsString.h"
00045 #include "nsIDTD.h"
00046 #include "nsITokenizer.h"
00047 #include "nsIInputStream.h"
00048 
00049 class nsIExpatSink;
00050 class nsIExtendedExpatSink;
00051 struct nsCatalogData;
00052 
00053 class nsExpatDriver : public nsIDTD,
00054                       public nsITokenizer
00055 {
00056 public:
00057   NS_DECL_ISUPPORTS
00058   NS_DECL_NSIDTD
00059   NS_DECL_NSITOKENIZER
00060 
00061   nsExpatDriver();
00062   virtual ~nsExpatDriver();
00063 
00064   int HandleExternalEntityRef(const PRUnichar *aOpenEntityNames,
00065                               const PRUnichar *aBase,
00066                               const PRUnichar *aSystemId,
00067                               const PRUnichar *aPublicId);
00068   nsresult HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts);
00069   nsresult HandleEndElement(const PRUnichar *aName);
00070   nsresult HandleCharacterData(const PRUnichar *aCData, const PRUint32 aLength);
00071   nsresult HandleComment(const PRUnichar *aName);
00072   nsresult HandleProcessingInstruction(const PRUnichar *aTarget,
00073                                        const PRUnichar *aData);
00074   nsresult HandleXMLDeclaration(const PRUnichar *aVersion,
00075                                 const PRUnichar *aEncoding,
00076                                 PRInt32 aStandalone);
00077   nsresult HandleDefault(const PRUnichar *aData, const PRUint32 aLength);
00078   nsresult HandleStartCdataSection();
00079   nsresult HandleEndCdataSection();
00080   nsresult HandleStartDoctypeDecl(const PRUnichar* aDoctypeName,
00081                                   const PRUnichar* aSysid,
00082                                   const PRUnichar* aPubid,
00083                                   PRBool aHasInternalSubset);
00084   nsresult HandleEndDoctypeDecl();
00085   nsresult HandleStartNamespaceDecl(const PRUnichar* aPrefix,
00086                                     const PRUnichar* aUri);
00087   nsresult HandleEndNamespaceDecl(const PRUnichar* aPrefix);
00088   nsresult HandleNotationDecl(const PRUnichar* aNotationName,
00089                               const PRUnichar* aBase,
00090                               const PRUnichar* aSysid,
00091                               const PRUnichar* aPubid);
00092   nsresult HandleUnparsedEntityDecl(const PRUnichar* aEntityName,
00093                                     const PRUnichar* aBase,
00094                                     const PRUnichar* aSysid,
00095                                     const PRUnichar* aPubid,
00096                                     const PRUnichar* aNotationName);
00097 
00098 private:
00099   // Load up an external stream to get external entity information
00100   nsresult OpenInputStreamFromExternalDTD(const PRUnichar* aFPIStr,
00101                                           const PRUnichar* aURLStr,
00102                                           const PRUnichar* aBaseURL,
00103                                           nsIInputStream** aStream,
00104                                           nsAString& aAbsURL);
00105 
00106   nsresult ParseBuffer(const char* aBuffer, PRUint32 aLength, PRBool aIsFinal);
00107   nsresult HandleError();
00108   void GetLine(const char* aSourceBuffer, PRUint32 aLength, PRUint32 aOffset,
00109                nsString& aLine);
00110 
00111   XML_Parser       mExpatParser;
00112   nsString         mLastLine;
00113   nsString         mCDataText;
00114   // Various parts of a doctype
00115   nsString         mDoctypeName;
00116   nsString         mSystemID;
00117   nsString         mPublicID;
00118   nsString         mInternalSubset;
00119   PRPackedBool     mInCData;
00120   PRPackedBool     mInInternalSubset;
00121   PRPackedBool     mInExternalDTD;
00122 
00123   // Number of bytes parsed in the current buffer.
00124   PRInt32          mBytePosition;
00125   nsresult         mInternalState;
00126 
00127   // Total number of bytes parsed.
00128   PRUint32         mBytesParsed;
00129   nsCOMPtr<nsIExpatSink> mSink;
00130   nsCOMPtr<nsIExtendedExpatSink> mExtendedSink;
00131   const nsCatalogData* mCatalogData; // weak
00132   nsString         mURISpec;
00133 };
00134 
00135 nsresult NS_NewExpatDriver(nsIDTD** aDriver);
00136 
00137 #endif