2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
19
* $Id: DTDScanner.hpp 676911 2008-07-15 13:27:32Z amassari $
22
#if !defined(XERCESC_INCLUDE_GUARD_DTDSCANNER_HPP)
23
#define XERCESC_INCLUDE_GUARD_DTDSCANNER_HPP
25
#include <xercesc/validators/DTD/DTDGrammar.hpp>
26
#include <xercesc/validators/DTD/DTDEntityDecl.hpp>
28
XERCES_CPP_NAMESPACE_BEGIN
33
* Default implementation of an XML DTD scanner.
37
class VALIDATORS_EXPORT DTDScanner : public XMemory
40
// -----------------------------------------------------------------------
41
// Class specific types
44
// Returned from scanEntityRef() to indicate how the expanded text
49
// -----------------------------------------------------------------------
66
// -----------------------------------------------------------------------
67
// Constructors and Destructor
68
// -----------------------------------------------------------------------
71
DTDGrammar* dtdGrammar
72
, DocTypeHandler* const docTypeHandler
73
, MemoryManager* const grammarPoolMemoryManager
74
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
76
virtual ~DTDScanner();
78
// -----------------------------------------------------------------------
80
// -----------------------------------------------------------------------
81
DocTypeHandler* getDocTypeHandler();
82
const DocTypeHandler* getDocTypeHandler() const;
84
// -----------------------------------------------------------------------
87
// setScannerInfo() is called by the scanner to tell the DTDScanner
88
// about the stuff it needs to have access to.
89
// -----------------------------------------------------------------------
92
XMLScanner* const owningScanner
93
, ReaderMgr* const readerMgr
94
, XMLBufferMgr* const bufMgr
97
void setDocTypeHandler
99
DocTypeHandler* const handlerToSet
102
void scanExtSubsetDecl(const bool inIncludeSect, const bool isDTD);
103
bool scanInternalSubset();
106
XMLBuffer& pubIdToFill
107
, XMLBuffer& sysIdToFill
108
, const IDTypes whatKind
112
// -----------------------------------------------------------------------
113
// Unimplemented constructors and operators
114
// -----------------------------------------------------------------------
115
DTDScanner(const DTDScanner &);
116
DTDScanner& operator = (const DTDScanner&);
118
// -----------------------------------------------------------------------
119
// Private DTD scanning methods. These are all in XMLValidator2.cpp
120
// -----------------------------------------------------------------------
124
, const bool inMarkup
128
const bool scanExternal
129
, const bool inLiteral
130
, const bool inMarkup
131
, const bool throwEndOfExt = false
133
bool getQuotedString(XMLBuffer& toFill);
134
XMLAttDef* scanAttDef(DTDElementDecl& elemDecl, XMLBuffer& bufToUse);
137
const XMLCh* const attrName
139
, const XMLAttDef::AttTypes type
141
void scanAttListDecl();
142
ContentSpecNode* scanChildren
144
const DTDElementDecl& elemDecl
145
, XMLBuffer& bufToUse
147
bool scanCharRef(XMLCh& toFill, XMLCh& second);
149
bool scanContentSpec(DTDElementDecl& toFill);
150
void scanDefaultDecl(DTDAttDef& toFill);
151
void scanElementDecl();
152
void scanEntityDecl();
153
bool scanEntityDef();
154
bool scanEntityLiteral(XMLBuffer& toFill);
155
bool scanEntityDef(DTDEntityDecl& decl, const bool isPEDecl);
156
EntityExpRes scanEntityRef(XMLCh& firstCh, XMLCh& secondCh, bool& escaped);
159
const DTDAttDef& attDef
161
, const bool notation
164
void scanIgnoredSection();
165
void scanMarkupDecl(const bool parseTextDecl);
166
bool scanMixed(DTDElementDecl& toFill);
167
void scanNotationDecl();
169
bool scanPublicLiteral(XMLBuffer& toFill);
170
bool scanSystemLiteral(XMLBuffer& toFill);
172
bool isReadingExternalEntity();
175
// -----------------------------------------------------------------------
176
// Private data members
179
// This holds the optional doc type handler that can be installed
180
// and used to call back for all markup events. It is DTD specific.
185
// These are dummy objects into which mark decls are parsed when
186
// they are just overrides of previously declared markup decls. In
187
// such situations, the first one wins but we need to have somewhere
188
// to parse them into. So these are lazily created and used as needed
189
// when such markup decls are seen.
192
// This is used to track whether we are in the internal subset or not,
193
// in which case we are in the external subset.
196
// Since att defs are per-element, we don't have a validator wide
197
// attribute def pool. So we use a simpler data structure in each
198
// element decl to store its att defs, and we use this simple counter
199
// to apply a unique id to each new attribute.
202
// The DTD information we scanned like element decl, attribute decl
203
// are stored in this Grammar.
206
// This is the buffer manager of the scanner. This is provided as a
207
// convenience so that the DTDScanner doesn't have to create its own
208
// buffer manager during the parse process.
211
// This is a pointer to the reader manager that is being used by the scanner.
214
// The pointer to the scanner to which this DTDScanner belongs
217
// This is a pool of EntityDecl objects, which contains all of the
218
// parameter entities that are declared in the DTD subsets.
221
// The uri for all DTD decls
224
// The original reader in the fReaderMgr - to be compared against the
225
// current reader to decide whether we are processing an external/internal
227
// -----------------------------------------------------------------------
228
MemoryManager* fMemoryManager;
229
MemoryManager* fGrammarPoolMemoryManager;
230
DocTypeHandler* fDocTypeHandler;
231
DTDAttDef* fDumAttDef;
232
DTDElementDecl* fDumElemDecl;
233
DTDEntityDecl* fDumEntityDecl;
234
bool fInternalSubset;
235
unsigned int fNextAttrId;
236
DTDGrammar* fDTDGrammar;
237
XMLBufferMgr* fBufMgr;
238
ReaderMgr* fReaderMgr;
239
XMLScanner* fScanner;
240
NameIdPool<DTDEntityDecl>* fPEntityDeclPool;
241
unsigned int fEmptyNamespaceId;
242
XMLSize_t fDocTypeReaderId;
246
// ---------------------------------------------------------------------------
247
// DTDScanner: Getter methods
248
// ---------------------------------------------------------------------------
249
inline DocTypeHandler* DTDScanner::getDocTypeHandler()
251
return fDocTypeHandler;
254
inline const DocTypeHandler* DTDScanner::getDocTypeHandler() const
256
return fDocTypeHandler;
260
// ---------------------------------------------------------------------------
261
// DTDScanner: Setter methods
262
// ---------------------------------------------------------------------------
263
inline void DTDScanner::setDocTypeHandler(DocTypeHandler* const handlerToSet)
265
fDocTypeHandler = handlerToSet;
268
// -----------------------------------------------------------------------
270
// -----------------------------------------------------------------------
271
inline bool DTDScanner::isReadingExternalEntity() {
272
return (fDocTypeReaderId != fReaderMgr->getCurrentReaderNum());
275
XERCES_CPP_NAMESPACE_END