~ubuntu-branches/ubuntu/precise/xerces-c/precise

« back to all changes in this revision

Viewing changes to src/xercesc/validators/DTD/DTDScanner.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Jay Berkenbilt
  • Date: 2009-02-22 16:52:23 UTC
  • Revision ID: james.westby@ubuntu.com-20090222165223-klimp8u8m73yn9zp
Tags: upstream-3.0.1
ImportĀ upstreamĀ versionĀ 3.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
8
 * 
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 * 
 
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.
 
16
 */
 
17
 
 
18
/*
 
19
 * $Id: DTDScanner.hpp 676911 2008-07-15 13:27:32Z amassari $
 
20
 */
 
21
 
 
22
#if !defined(XERCESC_INCLUDE_GUARD_DTDSCANNER_HPP)
 
23
#define XERCESC_INCLUDE_GUARD_DTDSCANNER_HPP
 
24
 
 
25
#include <xercesc/validators/DTD/DTDGrammar.hpp>
 
26
#include <xercesc/validators/DTD/DTDEntityDecl.hpp>
 
27
 
 
28
XERCES_CPP_NAMESPACE_BEGIN
 
29
 
 
30
class XMLScanner;
 
31
 
 
32
/*
 
33
 * Default implementation of an XML DTD scanner.
 
34
 */
 
35
class DocTypeHandler;
 
36
 
 
37
class VALIDATORS_EXPORT DTDScanner : public XMemory
 
38
{
 
39
public:
 
40
    // -----------------------------------------------------------------------
 
41
    //  Class specific types
 
42
    //
 
43
    //  EntityExpRes
 
44
    //      Returned from scanEntityRef() to indicate how the expanded text
 
45
    //      was treated.
 
46
    //
 
47
    //  IDTypes
 
48
    //      Type of the ID
 
49
    // -----------------------------------------------------------------------
 
50
    enum EntityExpRes
 
51
    {
 
52
        EntityExp_Failed
 
53
        , EntityExp_Pushed
 
54
        , EntityExp_Returned
 
55
    };
 
56
 
 
57
    enum IDTypes
 
58
    {
 
59
        IDType_Public
 
60
        , IDType_External
 
61
        , IDType_Either
 
62
    };
 
63
 
 
64
 
 
65
 
 
66
    // -----------------------------------------------------------------------
 
67
    //  Constructors and Destructor
 
68
    // -----------------------------------------------------------------------
 
69
    DTDScanner
 
70
    (
 
71
          DTDGrammar*           dtdGrammar
 
72
        , DocTypeHandler* const docTypeHandler
 
73
        , MemoryManager* const  grammarPoolMemoryManager
 
74
        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
 
75
    );
 
76
    virtual ~DTDScanner();
 
77
 
 
78
    // -----------------------------------------------------------------------
 
79
    //  Getter methods
 
80
    // -----------------------------------------------------------------------
 
81
    DocTypeHandler* getDocTypeHandler();
 
82
    const DocTypeHandler* getDocTypeHandler() const;
 
83
 
 
84
    // -----------------------------------------------------------------------
 
85
    //  Setter methods
 
86
    //
 
87
    //  setScannerInfo() is called by the scanner to tell the DTDScanner
 
88
    //  about the stuff it needs to have access to.
 
89
    // -----------------------------------------------------------------------
 
90
    void setScannerInfo
 
91
    (
 
92
        XMLScanner* const           owningScanner
 
93
        , ReaderMgr* const          readerMgr
 
94
        , XMLBufferMgr* const       bufMgr
 
95
    );
 
96
 
 
97
    void setDocTypeHandler
 
98
    (
 
99
            DocTypeHandler* const handlerToSet
 
100
    );
 
101
 
 
102
    void scanExtSubsetDecl(const bool inIncludeSect, const bool isDTD);
 
103
    bool scanInternalSubset();
 
104
    bool scanId
 
105
    (
 
106
                XMLBuffer&  pubIdToFill
 
107
        ,       XMLBuffer&  sysIdToFill
 
108
        , const IDTypes     whatKind
 
109
    );
 
110
 
 
111
private:
 
112
    // -----------------------------------------------------------------------
 
113
    // Unimplemented constructors and operators
 
114
    // -----------------------------------------------------------------------
 
115
    DTDScanner(const DTDScanner &);
 
116
    DTDScanner& operator = (const  DTDScanner&);
 
117
 
 
118
    // -----------------------------------------------------------------------
 
119
    //  Private DTD scanning methods. These are all in XMLValidator2.cpp
 
120
    // -----------------------------------------------------------------------
 
121
    bool checkForPERef
 
122
    (
 
123
          const bool    inLiteral
 
124
        , const bool    inMarkup
 
125
    );
 
126
    bool expandPERef
 
127
    (
 
128
        const   bool    scanExternal
 
129
        , const bool    inLiteral
 
130
        , const bool    inMarkup
 
131
        , const bool    throwEndOfExt = false
 
132
    );
 
133
    bool getQuotedString(XMLBuffer& toFill);
 
134
    XMLAttDef* scanAttDef(DTDElementDecl& elemDecl, XMLBuffer& bufToUse);
 
135
    bool scanAttValue
 
136
    (
 
137
        const   XMLCh* const        attrName
 
138
        ,       XMLBuffer&          toFill
 
139
        , const XMLAttDef::AttTypes type
 
140
    );
 
141
    void scanAttListDecl();
 
142
    ContentSpecNode* scanChildren
 
143
    (
 
144
        const   DTDElementDecl&     elemDecl
 
145
        ,       XMLBuffer&          bufToUse
 
146
    );
 
147
    bool scanCharRef(XMLCh& toFill, XMLCh& second);
 
148
    void scanComment();
 
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);
 
157
    bool scanEnumeration
 
158
    (
 
159
        const   DTDAttDef&  attDef
 
160
        ,       XMLBuffer&  toFill
 
161
        , const bool        notation
 
162
    );
 
163
    bool scanEq();
 
164
    void scanIgnoredSection();
 
165
    void scanMarkupDecl(const bool parseTextDecl);
 
166
    bool scanMixed(DTDElementDecl& toFill);
 
167
    void scanNotationDecl();
 
168
    void scanPI();
 
169
    bool scanPublicLiteral(XMLBuffer& toFill);
 
170
    bool scanSystemLiteral(XMLBuffer& toFill);
 
171
    void scanTextDecl();
 
172
    bool isReadingExternalEntity();
 
173
 
 
174
 
 
175
    // -----------------------------------------------------------------------
 
176
    //  Private data members
 
177
    //
 
178
    //  fDocTypeHandler
 
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.
 
181
    //
 
182
    //  fDumAttDef
 
183
    //  fDumElemDecl
 
184
    //  fDumEntityDecl
 
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.
 
190
    //
 
191
    //  fInternalSubset
 
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.
 
194
    //
 
195
    //  fNextAttrId
 
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.
 
200
    //
 
201
    //  fDTDGrammar
 
202
    //      The DTD information we scanned like element decl, attribute decl
 
203
    //      are stored in this Grammar.
 
204
    //
 
205
    //  fBufMgr
 
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.
 
209
    //
 
210
    //  fReaderMgr
 
211
    //      This is a pointer to the reader manager that is being used by the scanner.
 
212
    //
 
213
    //  fScanner
 
214
    //      The pointer to the scanner to which this DTDScanner belongs
 
215
    //
 
216
    //  fPEntityDeclPool
 
217
    //      This is a pool of EntityDecl objects, which contains all of the
 
218
    //      parameter entities that are declared in the DTD subsets.
 
219
    //
 
220
    //  fEmptyNamespaceId
 
221
    //      The uri for all DTD decls
 
222
    //
 
223
    //  fDocTypeReaderId
 
224
    //      The original reader in the fReaderMgr - to be compared against the
 
225
    //      current reader to decide whether we are processing an external/internal
 
226
    //      declaration
 
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;
 
243
};
 
244
 
 
245
 
 
246
// ---------------------------------------------------------------------------
 
247
//  DTDScanner: Getter methods
 
248
// ---------------------------------------------------------------------------
 
249
inline DocTypeHandler* DTDScanner::getDocTypeHandler()
 
250
{
 
251
    return fDocTypeHandler;
 
252
}
 
253
 
 
254
inline const DocTypeHandler* DTDScanner::getDocTypeHandler() const
 
255
{
 
256
    return fDocTypeHandler;
 
257
}
 
258
 
 
259
 
 
260
// ---------------------------------------------------------------------------
 
261
//  DTDScanner: Setter methods
 
262
// ---------------------------------------------------------------------------
 
263
inline void DTDScanner::setDocTypeHandler(DocTypeHandler* const handlerToSet)
 
264
{
 
265
    fDocTypeHandler = handlerToSet;
 
266
}
 
267
 
 
268
// -----------------------------------------------------------------------
 
269
//  Helper methods
 
270
// -----------------------------------------------------------------------
 
271
inline bool DTDScanner::isReadingExternalEntity() {
 
272
    return (fDocTypeReaderId != fReaderMgr->getCurrentReaderNum());
 
273
}
 
274
 
 
275
XERCES_CPP_NAMESPACE_END
 
276
 
 
277
#endif