source: NonGTP/Xerces/xerces/include/xercesc/validators/DTD/DTDScanner.hpp @ 358

Revision 358, 11.1 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 1999-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * $Log: DTDScanner.hpp,v $
19 * Revision 1.11  2004/09/08 13:56:50  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.10  2004/01/29 11:52:30  cargilld
23 * Code cleanup changes to get rid of various compiler diagnostic messages.
24 *
25 * Revision 1.9  2003/07/10 19:50:12  peiyongz
26 * Stateless Grammar: create grammar components with grammarPool's memory Manager
27 *
28 * Revision 1.8  2003/05/16 21:43:19  knoaman
29 * Memory manager implementation: Modify constructors to pass in the memory manager.
30 *
31 * Revision 1.7  2003/05/15 18:54:51  knoaman
32 * Partial implementation of the configurable memory manager.
33 *
34 * Revision 1.6  2003/02/05 22:07:09  tng
35 * [Bug 3111] Problem with LexicalHandler::startDTD() and LexicalHandler::endDTD().
36 *
37 * Revision 1.5  2002/12/04 02:47:25  knoaman
38 * scanner re-organization.
39 *
40 * Revision 1.4  2002/11/04 14:50:40  tng
41 * C++ Namespace Support.
42 *
43 * Revision 1.3  2002/07/11 18:39:48  knoaman
44 * Access entities through the DTDGrammar instead of the scanner.
45 *
46 * Revision 1.2  2002/05/30 16:17:19  tng
47 * Add feature to optionally ignore external DTD.
48 *
49 * Revision 1.1.1.1  2002/02/01 22:22:44  peiyongz
50 * sane_include
51 *
52 * Revision 1.4  2001/06/21 14:25:56  knoaman
53 * Fix for bug 1946
54 *
55 * Revision 1.3  2001/05/11 13:27:10  tng
56 * Copyright update.
57 *
58 * Revision 1.2  2001/04/19 18:17:22  tng
59 * Schema: SchemaValidator update, and use QName in Content Model
60 *
61 * Revision 1.1  2001/03/21 21:56:20  tng
62 * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
63 *
64 */
65
66
67
68#if !defined(DTDSCANNER_HPP)
69#define DTDSCANNER_HPP
70
71#include <xercesc/validators/DTD/DTDGrammar.hpp>
72#include <xercesc/validators/DTD/DTDEntityDecl.hpp>
73
74XERCES_CPP_NAMESPACE_BEGIN
75
76class XMLScanner;
77
78/*
79 * Default implementation of an XML DTD scanner.
80 */
81class DocTypeHandler;
82
83class VALIDATORS_EXPORT DTDScanner : public XMemory
84{
85public:
86    // -----------------------------------------------------------------------
87    //  Class specific types
88    //
89    //  EntityExpRes
90    //      Returned from scanEntityRef() to indicate how the expanded text
91    //      was treated.
92    //
93    //  IDTypes
94    //      Type of the ID
95    // -----------------------------------------------------------------------
96    enum EntityExpRes
97    {
98        EntityExp_Failed
99        , EntityExp_Pushed
100        , EntityExp_Returned
101    };
102
103    enum IDTypes
104    {
105        IDType_Public
106        , IDType_External
107        , IDType_Either
108    };
109
110
111
112    // -----------------------------------------------------------------------
113    //  Constructors and Destructor
114    // -----------------------------------------------------------------------
115    DTDScanner
116    (
117          DTDGrammar*           dtdGrammar
118        , DocTypeHandler* const docTypeHandler
119        , MemoryManager* const  grammarPoolMemoryManager
120        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
121    );
122    virtual ~DTDScanner();
123
124    // -----------------------------------------------------------------------
125    //  Getter methods
126    // -----------------------------------------------------------------------
127    DocTypeHandler* getDocTypeHandler();
128    const DocTypeHandler* getDocTypeHandler() const;
129
130    // -----------------------------------------------------------------------
131    //  Setter methods
132    //
133    //  setScannerInfo() is called by the scanner to tell the DTDScanner
134    //  about the stuff it needs to have access to.
135    // -----------------------------------------------------------------------
136    void setScannerInfo
137    (
138        XMLScanner* const           owningScanner
139        , ReaderMgr* const          readerMgr
140        , XMLBufferMgr* const       bufMgr
141    );
142
143    void setDocTypeHandler
144    (
145            DocTypeHandler* const handlerToSet
146    );
147
148    void scanExtSubsetDecl(const bool inIncludeSect, const bool isDTD);
149    bool scanInternalSubset();
150    bool scanId
151    (
152                XMLBuffer&  pubIdToFill
153        ,       XMLBuffer&  sysIdToFill
154        , const IDTypes     whatKind
155    );
156
157private:
158    // -----------------------------------------------------------------------
159    // Unimplemented constructors and operators
160    // -----------------------------------------------------------------------
161    DTDScanner(const DTDScanner &);
162    DTDScanner& operator = (const  DTDScanner&);
163
164    // -----------------------------------------------------------------------
165    //  Private DTD scanning methods. These are all in XMLValidator2.cpp
166    // -----------------------------------------------------------------------
167    bool checkForPERef
168    (
169          const bool    inLiteral
170        , const bool    inMarkup
171    );
172    bool expandPERef
173    (
174        const   bool    scanExternal
175        , const bool    inLiteral
176        , const bool    inMarkup
177        , const bool    throwEndOfExt = false
178    );
179    bool getQuotedString(XMLBuffer& toFill);
180    XMLAttDef* scanAttDef(DTDElementDecl& elemDecl, XMLBuffer& bufToUse);
181    bool scanAttValue
182    (
183        const   XMLCh* const        attrName
184        ,       XMLBuffer&          toFill
185        , const XMLAttDef::AttTypes type
186    );
187    void scanAttListDecl();
188    ContentSpecNode* scanChildren
189    (
190        const   DTDElementDecl&     elemDecl
191        ,       XMLBuffer&          bufToUse
192    );
193    bool scanCharRef(XMLCh& toFill, XMLCh& second);
194    void scanComment();
195    bool scanContentSpec(DTDElementDecl& toFill);
196    void scanDefaultDecl(DTDAttDef& toFill);
197    void scanElementDecl();
198    void scanEntityDecl();
199    bool scanEntityDef();
200    bool scanEntityLiteral(XMLBuffer& toFill);
201    bool scanEntityDef(DTDEntityDecl& decl, const bool isPEDecl);
202    EntityExpRes scanEntityRef(XMLCh& firstCh, XMLCh& secondCh, bool& escaped);
203    bool scanEnumeration
204    (
205        const   DTDAttDef&  attDef
206        ,       XMLBuffer&  toFill
207        , const bool        notation
208    );
209    bool scanEq();
210    void scanIgnoredSection();
211    void scanMarkupDecl(const bool parseTextDecl);
212    bool scanMixed(DTDElementDecl& toFill);
213    void scanNotationDecl();
214    void scanPI();
215    bool scanPublicLiteral(XMLBuffer& toFill);
216    bool scanSystemLiteral(XMLBuffer& toFill);
217    void scanTextDecl();
218    bool isReadingExternalEntity();
219
220
221    // -----------------------------------------------------------------------
222    //  Private data members
223    //
224    //  fDocTypeHandler
225    //      This holds the optional doc type handler that can be installed
226    //      and used to call back for all markup events. It is DTD specific.
227    //
228    //  fDumAttDef
229    //  fDumElemDecl
230    //  fDumEntityDecl
231    //      These are dummy objects into which mark decls are parsed when
232    //      they are just overrides of previously declared markup decls. In
233    //      such situations, the first one wins but we need to have somewhere
234    //      to parse them into. So these are lazily created and used as needed
235    //      when such markup decls are seen.
236    //
237    //  fInternalSubset
238    //      This is used to track whether we are in the internal subset or not,
239    //      in which case we are in the external subset.
240    //
241    //  fNextAttrId
242    //      Since att defs are per-element, we don't have a validator wide
243    //      attribute def pool. So we use a simpler data structure in each
244    //      element decl to store its att defs, and we use this simple counter
245    //      to apply a unique id to each new attribute.
246    //
247    //  fDTDGrammar
248    //      The DTD information we scanned like element decl, attribute decl
249    //      are stored in this Grammar.
250    //
251    //  fBufMgr
252    //      This is the buffer manager of the scanner. This is provided as a
253    //      convenience so that the DTDScanner doesn't have to create its own
254    //      buffer manager during the parse process.
255    //
256    //  fReaderMgr
257    //      This is a pointer to the reader manager that is being used by the scanner.
258    //
259    //  fScanner
260    //      The pointer to the scanner to which this DTDScanner belongs
261    //
262    //  fPEntityDeclPool
263    //      This is a pool of EntityDecl objects, which contains all of the
264    //      parameter entities that are declared in the DTD subsets.
265    //
266    //  fEmptyNamespaceId
267    //      The uri for all DTD decls
268    //
269    //  fDocTypeReaderId
270    //      The original reader in the fReaderMgr - to be compared against the
271    //      current reader to decide whether we are processing an external/internal
272    //      declaration
273    // -----------------------------------------------------------------------
274    MemoryManager*                  fMemoryManager;
275    MemoryManager*                  fGrammarPoolMemoryManager;
276    DocTypeHandler*                 fDocTypeHandler;
277    DTDAttDef*                      fDumAttDef;
278    DTDElementDecl*                 fDumElemDecl;
279    DTDEntityDecl*                  fDumEntityDecl;
280    bool                            fInternalSubset;
281    unsigned int                    fNextAttrId;
282    DTDGrammar*                     fDTDGrammar;
283    XMLBufferMgr*                   fBufMgr;
284    ReaderMgr*                      fReaderMgr;
285    XMLScanner*                     fScanner;
286    NameIdPool<DTDEntityDecl>*      fPEntityDeclPool;
287    unsigned int                    fEmptyNamespaceId;
288    unsigned int                    fDocTypeReaderId;
289};
290
291
292// ---------------------------------------------------------------------------
293//  DTDScanner: Getter methods
294// ---------------------------------------------------------------------------
295inline DocTypeHandler* DTDScanner::getDocTypeHandler()
296{
297    return fDocTypeHandler;
298}
299
300inline const DocTypeHandler* DTDScanner::getDocTypeHandler() const
301{
302    return fDocTypeHandler;
303}
304
305
306// ---------------------------------------------------------------------------
307//  DTDScanner: Setter methods
308// ---------------------------------------------------------------------------
309inline void DTDScanner::setDocTypeHandler(DocTypeHandler* const handlerToSet)
310{
311    fDocTypeHandler = handlerToSet;
312}
313
314// -----------------------------------------------------------------------
315//  Helper methods
316// -----------------------------------------------------------------------
317inline bool DTDScanner::isReadingExternalEntity() {
318    return (fDocTypeReaderId != fReaderMgr->getCurrentReaderNum());
319}
320
321XERCES_CPP_NAMESPACE_END
322
323#endif
Note: See TracBrowser for help on using the repository browser.