source: NonGTP/Xerces/xercesc/validators/DTD/DTDScanner.hpp @ 188

Revision 188, 13.1 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 1999, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Log: DTDScanner.hpp,v $
59 * Revision 1.10  2004/01/29 11:52:30  cargilld
60 * Code cleanup changes to get rid of various compiler diagnostic messages.
61 *
62 * Revision 1.9  2003/07/10 19:50:12  peiyongz
63 * Stateless Grammar: create grammar components with grammarPool's memory Manager
64 *
65 * Revision 1.8  2003/05/16 21:43:19  knoaman
66 * Memory manager implementation: Modify constructors to pass in the memory manager.
67 *
68 * Revision 1.7  2003/05/15 18:54:51  knoaman
69 * Partial implementation of the configurable memory manager.
70 *
71 * Revision 1.6  2003/02/05 22:07:09  tng
72 * [Bug 3111] Problem with LexicalHandler::startDTD() and LexicalHandler::endDTD().
73 *
74 * Revision 1.5  2002/12/04 02:47:25  knoaman
75 * scanner re-organization.
76 *
77 * Revision 1.4  2002/11/04 14:50:40  tng
78 * C++ Namespace Support.
79 *
80 * Revision 1.3  2002/07/11 18:39:48  knoaman
81 * Access entities through the DTDGrammar instead of the scanner.
82 *
83 * Revision 1.2  2002/05/30 16:17:19  tng
84 * Add feature to optionally ignore external DTD.
85 *
86 * Revision 1.1.1.1  2002/02/01 22:22:44  peiyongz
87 * sane_include
88 *
89 * Revision 1.4  2001/06/21 14:25:56  knoaman
90 * Fix for bug 1946
91 *
92 * Revision 1.3  2001/05/11 13:27:10  tng
93 * Copyright update.
94 *
95 * Revision 1.2  2001/04/19 18:17:22  tng
96 * Schema: SchemaValidator update, and use QName in Content Model
97 *
98 * Revision 1.1  2001/03/21 21:56:20  tng
99 * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
100 *
101 */
102
103
104
105#if !defined(DTDSCANNER_HPP)
106#define DTDSCANNER_HPP
107
108#include <xercesc/validators/DTD/DTDGrammar.hpp>
109#include <xercesc/validators/DTD/DTDEntityDecl.hpp>
110
111XERCES_CPP_NAMESPACE_BEGIN
112
113class XMLScanner;
114
115/*
116 * Default implementation of an XML DTD scanner.
117 */
118class DocTypeHandler;
119
120class VALIDATORS_EXPORT DTDScanner : public XMemory
121{
122public:
123    // -----------------------------------------------------------------------
124    //  Class specific types
125    //
126    //  EntityExpRes
127    //      Returned from scanEntityRef() to indicate how the expanded text
128    //      was treated.
129    //
130    //  IDTypes
131    //      Type of the ID
132    // -----------------------------------------------------------------------
133    enum EntityExpRes
134    {
135        EntityExp_Failed
136        , EntityExp_Pushed
137        , EntityExp_Returned
138    };
139
140    enum IDTypes
141    {
142        IDType_Public
143        , IDType_External
144        , IDType_Either
145    };
146
147
148
149    // -----------------------------------------------------------------------
150    //  Constructors and Destructor
151    // -----------------------------------------------------------------------
152    DTDScanner
153    (
154          DTDGrammar*           dtdGrammar
155        , DocTypeHandler* const docTypeHandler
156        , MemoryManager* const  grammarPoolMemoryManager
157        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
158    );
159    virtual ~DTDScanner();
160
161    // -----------------------------------------------------------------------
162    //  Getter methods
163    // -----------------------------------------------------------------------
164    DocTypeHandler* getDocTypeHandler();
165    const DocTypeHandler* getDocTypeHandler() const;
166
167    // -----------------------------------------------------------------------
168    //  Setter methods
169    //
170    //  setScannerInfo() is called by the scanner to tell the DTDScanner
171    //  about the stuff it needs to have access to.
172    // -----------------------------------------------------------------------
173    void setScannerInfo
174    (
175        XMLScanner* const           owningScanner
176        , ReaderMgr* const          readerMgr
177        , XMLBufferMgr* const       bufMgr
178    );
179
180    void setDocTypeHandler
181    (
182            DocTypeHandler* const handlerToSet
183    );
184
185    void scanExtSubsetDecl(const bool inIncludeSect, const bool isDTD);
186    bool scanInternalSubset();
187    bool scanId
188    (
189                XMLBuffer&  pubIdToFill
190        ,       XMLBuffer&  sysIdToFill
191        , const IDTypes     whatKind
192    );
193
194private:
195    // -----------------------------------------------------------------------
196    // Unimplemented constructors and operators
197    // -----------------------------------------------------------------------
198    DTDScanner(const DTDScanner &);
199    DTDScanner& operator = (const  DTDScanner&);
200
201    // -----------------------------------------------------------------------
202    //  Private DTD scanning methods. These are all in XMLValidator2.cpp
203    // -----------------------------------------------------------------------
204    bool checkForPERef
205    (
206          const bool    inLiteral
207        , const bool    inMarkup
208    );
209    bool expandPERef
210    (
211        const   bool    scanExternal
212        , const bool    inLiteral
213        , const bool    inMarkup
214        , const bool    throwEndOfExt = false
215    );
216    bool getQuotedString(XMLBuffer& toFill);
217    XMLAttDef* scanAttDef(DTDElementDecl& elemDecl, XMLBuffer& bufToUse);
218    bool scanAttValue
219    (
220        const   XMLCh* const        attrName
221        ,       XMLBuffer&          toFill
222        , const XMLAttDef::AttTypes type
223    );
224    void scanAttListDecl();
225    ContentSpecNode* scanChildren
226    (
227        const   DTDElementDecl&     elemDecl
228        ,       XMLBuffer&          bufToUse
229    );
230    bool scanCharRef(XMLCh& toFill, XMLCh& second);
231    void scanComment();
232    bool scanContentSpec(DTDElementDecl& toFill);
233    void scanDefaultDecl(DTDAttDef& toFill);
234    void scanElementDecl();
235    void scanEntityDecl();
236    bool scanEntityDef();
237    bool scanEntityLiteral(XMLBuffer& toFill);
238    bool scanEntityDef(DTDEntityDecl& decl, const bool isPEDecl);
239    EntityExpRes scanEntityRef(XMLCh& firstCh, XMLCh& secondCh, bool& escaped);
240    bool scanEnumeration
241    (
242        const   DTDAttDef&  attDef
243        ,       XMLBuffer&  toFill
244        , const bool        notation
245    );
246    bool scanEq();
247    void scanIgnoredSection();
248    void scanMarkupDecl(const bool parseTextDecl);
249    bool scanMixed(DTDElementDecl& toFill);
250    void scanNotationDecl();
251    void scanPI();
252    bool scanPublicLiteral(XMLBuffer& toFill);
253    bool scanSystemLiteral(XMLBuffer& toFill);
254    void scanTextDecl();
255    bool isReadingExternalEntity();
256
257
258    // -----------------------------------------------------------------------
259    //  Private data members
260    //
261    //  fDocTypeHandler
262    //      This holds the optional doc type handler that can be installed
263    //      and used to call back for all markup events. It is DTD specific.
264    //
265    //  fDumAttDef
266    //  fDumElemDecl
267    //  fDumEntityDecl
268    //      These are dummy objects into which mark decls are parsed when
269    //      they are just overrides of previously declared markup decls. In
270    //      such situations, the first one wins but we need to have somewhere
271    //      to parse them into. So these are lazily created and used as needed
272    //      when such markup decls are seen.
273    //
274    //  fInternalSubset
275    //      This is used to track whether we are in the internal subset or not,
276    //      in which case we are in the external subset.
277    //
278    //  fNextAttrId
279    //      Since att defs are per-element, we don't have a validator wide
280    //      attribute def pool. So we use a simpler data structure in each
281    //      element decl to store its att defs, and we use this simple counter
282    //      to apply a unique id to each new attribute.
283    //
284    //  fDTDGrammar
285    //      The DTD information we scanned like element decl, attribute decl
286    //      are stored in this Grammar.
287    //
288    //  fBufMgr
289    //      This is the buffer manager of the scanner. This is provided as a
290    //      convenience so that the DTDScanner doesn't have to create its own
291    //      buffer manager during the parse process.
292    //
293    //  fReaderMgr
294    //      This is a pointer to the reader manager that is being used by the scanner.
295    //
296    //  fScanner
297    //      The pointer to the scanner to which this DTDScanner belongs
298    //
299    //  fPEntityDeclPool
300    //      This is a pool of EntityDecl objects, which contains all of the
301    //      parameter entities that are declared in the DTD subsets.
302    //
303    //  fEmptyNamespaceId
304    //      The uri for all DTD decls
305    //
306    //  fDocTypeReaderId
307    //      The original reader in the fReaderMgr - to be compared against the
308    //      current reader to decide whether we are processing an external/internal
309    //      declaration
310    // -----------------------------------------------------------------------
311    MemoryManager*                  fMemoryManager;
312    MemoryManager*                  fGrammarPoolMemoryManager;
313    DocTypeHandler*                 fDocTypeHandler;
314    DTDAttDef*                      fDumAttDef;
315    DTDElementDecl*                 fDumElemDecl;
316    DTDEntityDecl*                  fDumEntityDecl;
317    bool                            fInternalSubset;
318    unsigned int                    fNextAttrId;
319    DTDGrammar*                     fDTDGrammar;
320    XMLBufferMgr*                   fBufMgr;
321    ReaderMgr*                      fReaderMgr;
322    XMLScanner*                     fScanner;
323    NameIdPool<DTDEntityDecl>*      fPEntityDeclPool;
324    unsigned int                    fEmptyNamespaceId;
325    unsigned int                    fDocTypeReaderId;
326};
327
328
329// ---------------------------------------------------------------------------
330//  DTDScanner: Getter methods
331// ---------------------------------------------------------------------------
332inline DocTypeHandler* DTDScanner::getDocTypeHandler()
333{
334    return fDocTypeHandler;
335}
336
337inline const DocTypeHandler* DTDScanner::getDocTypeHandler() const
338{
339    return fDocTypeHandler;
340}
341
342
343// ---------------------------------------------------------------------------
344//  DTDScanner: Setter methods
345// ---------------------------------------------------------------------------
346inline void DTDScanner::setDocTypeHandler(DocTypeHandler* const handlerToSet)
347{
348    fDocTypeHandler = handlerToSet;
349}
350
351// -----------------------------------------------------------------------
352//  Helper methods
353// -----------------------------------------------------------------------
354inline bool DTDScanner::isReadingExternalEntity() {
355    return (fDocTypeReaderId != fReaderMgr->getCurrentReaderNum());
356}
357
358XERCES_CPP_NAMESPACE_END
359
360#endif
Note: See TracBrowser for help on using the repository browser.