1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef NS_EXPAT_DRIVER__
39 #define NS_EXPAT_DRIVER__
41 #include "expat_config.h"
46 #include "nsITokenizer.h"
47 #include "nsIInputStream.h"
48 #include "nsIParser.h"
49 #include "nsCycleCollectionParticipant.h"
52 class nsIExtendedExpatSink
;
55 class nsExpatDriver
: public nsIDTD
,
59 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
62 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsExpatDriver
, nsIDTD
)
65 virtual ~nsExpatDriver();
67 int HandleExternalEntityRef(const PRUnichar
*aOpenEntityNames
,
68 const PRUnichar
*aBase
,
69 const PRUnichar
*aSystemId
,
70 const PRUnichar
*aPublicId
);
71 nsresult
HandleStartElement(const PRUnichar
*aName
, const PRUnichar
**aAtts
);
72 nsresult
HandleEndElement(const PRUnichar
*aName
);
73 nsresult
HandleCharacterData(const PRUnichar
*aCData
, const PRUint32 aLength
);
74 nsresult
HandleComment(const PRUnichar
*aName
);
75 nsresult
HandleProcessingInstruction(const PRUnichar
*aTarget
,
76 const PRUnichar
*aData
);
77 nsresult
HandleXMLDeclaration(const PRUnichar
*aVersion
,
78 const PRUnichar
*aEncoding
,
80 nsresult
HandleDefault(const PRUnichar
*aData
, const PRUint32 aLength
);
81 nsresult
HandleStartCdataSection();
82 nsresult
HandleEndCdataSection();
83 nsresult
HandleStartDoctypeDecl(const PRUnichar
* aDoctypeName
,
84 const PRUnichar
* aSysid
,
85 const PRUnichar
* aPubid
,
86 PRBool aHasInternalSubset
);
87 nsresult
HandleEndDoctypeDecl();
88 nsresult
HandleStartNamespaceDecl(const PRUnichar
* aPrefix
,
89 const PRUnichar
* aUri
);
90 nsresult
HandleEndNamespaceDecl(const PRUnichar
* aPrefix
);
91 nsresult
HandleNotationDecl(const PRUnichar
* aNotationName
,
92 const PRUnichar
* aBase
,
93 const PRUnichar
* aSysid
,
94 const PRUnichar
* aPubid
);
95 nsresult
HandleUnparsedEntityDecl(const PRUnichar
* aEntityName
,
96 const PRUnichar
* aBase
,
97 const PRUnichar
* aSysid
,
98 const PRUnichar
* aPubid
,
99 const PRUnichar
* aNotationName
);
102 // Load up an external stream to get external entity information
103 nsresult
OpenInputStreamFromExternalDTD(const PRUnichar
* aFPIStr
,
104 const PRUnichar
* aURLStr
,
105 const PRUnichar
* aBaseURL
,
106 nsIInputStream
** aStream
,
110 * Pass a buffer to Expat. If Expat is blocked aBuffer should be null and
111 * aLength should be 0. The result of the call will be stored in
112 * mInternalState. Expat will parse as much of the buffer as it can and store
113 * the rest in its internal buffer.
115 * @param aBuffer the buffer to pass to Expat. May be null.
116 * @param aLength the length of the buffer to pass to Expat (in number of
117 * PRUnichar's). Must be 0 if aBuffer is null and > 0 if
118 * aBuffer is not null.
119 * @param aIsFinal whether there will definitely not be any more new buffers
120 * passed in to ParseBuffer
121 * @param aConsumed [out] the number of PRUnichars that Expat consumed. This
122 * doesn't include the PRUnichars that Expat stored in
123 * its buffer but didn't parse yet.
125 void ParseBuffer(const PRUnichar
*aBuffer
, PRUint32 aLength
, PRBool aIsFinal
,
126 PRUint32
*aConsumed
);
127 nsresult
HandleError();
129 void MaybeStopParser(nsresult aState
);
131 PRBool
BlockedOrInterrupted()
133 return mInternalState
== NS_ERROR_HTMLPARSER_BLOCK
||
134 mInternalState
== NS_ERROR_HTMLPARSER_INTERRUPTED
;
137 XML_Parser mExpatParser
;
140 // Various parts of a doctype
141 nsString mDoctypeName
;
144 nsString mInternalSubset
;
145 PRPackedBool mInCData
;
146 PRPackedBool mInInternalSubset
;
147 PRPackedBool mInExternalDTD
;
149 // Whether we're sure that we won't be getting more buffers to parse from
151 PRPackedBool mIsFinalChunk
;
153 nsresult mInternalState
;
155 // The length of the data in Expat's buffer (in number of PRUnichars).
156 PRUint32 mExpatBuffered
;
158 nsCOMPtr
<nsIExpatSink
> mSink
;
159 nsCOMPtr
<nsIExtendedExpatSink
> mExtendedSink
;
160 const nsCatalogData
* mCatalogData
; // weak