Coverage Report

Created: 2023-03-26 07:54

/src/xerces-c/src/xercesc/internal/SGXMLScanner.hpp
Line
Count
Source (jump to first uncovered line)
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: SGXMLScanner.hpp 882548 2009-11-20 13:44:14Z borisk $
20
 */
21
22
#if !defined(XERCESC_INCLUDE_GUARD_SGXMLSCANNER_HPP)
23
#define XERCESC_INCLUDE_GUARD_SGXMLSCANNER_HPP
24
25
#include <xercesc/internal/XMLScanner.hpp>
26
#include <xercesc/util/KVStringPair.hpp>
27
#include <xercesc/util/ValueHashTableOf.hpp>
28
#include <xercesc/util/RefHash2KeysTableOf.hpp>
29
#include <xercesc/util/RefHash3KeysIdPool.hpp>
30
#include <xercesc/util/Hash2KeysSetOf.hpp>
31
#include <xercesc/validators/common/Grammar.hpp>
32
#include <xercesc/validators/schema/SchemaInfo.hpp>
33
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
34
35
36
XERCES_CPP_NAMESPACE_BEGIN
37
38
class SchemaGrammar;
39
class SchemaValidator;
40
class IdentityConstraintHandler;
41
class IdentityConstraint;
42
class ContentLeafNameTypeVector;
43
class SchemaAttDef;
44
class XMLContentModel;
45
class XSModel;
46
class PSVIAttributeList;
47
class PSVIElement;
48
49
//  This is a scanner class, which process XML Schema grammar.
50
class XMLPARSER_EXPORT SGXMLScanner : public XMLScanner
51
{
52
public :
53
    // -----------------------------------------------------------------------
54
    //  Constructors and Destructor
55
    // -----------------------------------------------------------------------
56
    SGXMLScanner
57
    (
58
        XMLValidator* const       valToAdopt
59
        , GrammarResolver* const grammarResolver
60
        , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
61
    );
62
    SGXMLScanner
63
    (
64
        XMLDocumentHandler* const docHandler
65
        , DocTypeHandler* const   docTypeHandler
66
        , XMLEntityHandler* const entityHandler
67
        , XMLErrorReporter* const errReporter
68
        , XMLValidator* const     valToAdopt
69
        , GrammarResolver* const  grammarResolver
70
        , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
71
    );
72
    virtual ~SGXMLScanner();
73
74
    // -----------------------------------------------------------------------
75
    //  XMLScanner public virtual methods
76
    // -----------------------------------------------------------------------
77
    virtual const XMLCh* getName() const;
78
    virtual NameIdPool<DTDEntityDecl>* getEntityDeclPool();
79
    virtual const NameIdPool<DTDEntityDecl>* getEntityDeclPool() const;
80
    virtual void scanDocument
81
    (
82
        const   InputSource&    src
83
    );
84
    virtual bool scanNext(XMLPScanToken& toFill);
85
    virtual Grammar* loadGrammar
86
    (
87
        const   InputSource&    src
88
        , const short           grammarType
89
        , const bool            toCache = false
90
    );
91
92
    virtual void resetCachedGrammar ();
93
    virtual Grammar::GrammarType getCurrentGrammarType() const;
94
95
protected:
96
    // -----------------------------------------------------------------------
97
    //  XMLScanner virtual methods
98
    // -----------------------------------------------------------------------
99
    virtual void scanReset(const InputSource& src);
100
101
    // -----------------------------------------------------------------------
102
    //  SGXMLScanner virtual methods
103
    // -----------------------------------------------------------------------
104
    virtual bool scanStartTag(bool& gotData);
105
    virtual void scanEndTag(bool& gotData);
106
107
    // -----------------------------------------------------------------------
108
    //  Helper methods
109
    // -----------------------------------------------------------------------
110
    XMLSize_t buildAttList
111
    (
112
        const   RefVectorOf<KVStringPair>&  providedAttrs
113
        , const XMLSize_t                   attCount
114
        ,       XMLElementDecl*             elemDecl
115
        ,       RefVectorOf<XMLAttr>&       toFill
116
    );
117
    bool laxElementValidation(QName* element, ContentLeafNameTypeVector* cv,
118
                              const XMLContentModel* const cm,
119
                              const XMLSize_t parentElemDepth);
120
    XMLSize_t rawAttrScan
121
    (
122
        const   XMLCh* const                elemName
123
        ,       RefVectorOf<KVStringPair>&  toFill
124
        ,       bool&                       isEmpty
125
    );
126
    void updateNSMap
127
    (
128
        const   XMLCh* const    attrName
129
        , const XMLCh* const    attrValue
130
    );
131
    void resizeElemState();
132
133
    void updateNSMap
134
    (
135
        const   XMLCh* const    attrName
136
        , const XMLCh* const    attrValue
137
        , const int             colonPosition
138
    );
139
    void resizeRawAttrColonList();
140
    // -----------------------------------------------------------------------
141
    //  Data members
142
    //
143
    //  fRawAttrList
144
    //      During the initial scan of the attributes we can only do a raw
145
    //      scan for key/value pairs. So this vector is used to store them
146
    //      until they can be processed (and put into fAttrList.)
147
    //
148
    //  fSchemaValidator
149
    //      The Schema validator instance.
150
    //
151
    //  fSeeXsi
152
    //      This flag indicates a schema has been seen.
153
    //
154
    //  fElemState
155
    //  fElemLoopState
156
    //  fElemStateSize
157
    //      Stores an element next state from DFA content model - used for
158
    //      wildcard validation
159
    //
160
    // fElemNonDeclPool
161
    //      registry for elements without decls in the grammar
162
    // fElemCount
163
    //      count of the number of start tags seen so far (starts at 1).
164
    //      Used for duplicate attribute detection/processing of required/defaulted attributes
165
    // fAttDefRegistry
166
    //      mapping from XMLAttDef instances to the count of the last
167
    //      start tag where they were utilized.
168
    // fUndeclaredAttrRegistry
169
    //      set of namespaceId/localName pairs to detect duplicates
170
    // fPSVIAttrList
171
    //      PSVI attribute list implementation that needs to be
172
    //      filled when a PSVIHandler is registered
173
    // fSchemaInfoList
174
    //      Transient schema info list that is passed to TraverseSchema instances.
175
    // fCachedSchemaInfoList
176
    //      Cached Schema info list that is passed to TraverseSchema instances.
177
    //
178
    // -----------------------------------------------------------------------
179
    bool                                    fSeeXsi;
180
    Grammar::GrammarType                    fGrammarType;
181
    unsigned int                            fElemStateSize;
182
    unsigned int*                           fElemState;
183
    unsigned int*                           fElemLoopState;
184
    XMLBuffer                               fContent;
185
    ValueHashTableOf<XMLCh>*                fEntityTable;
186
    RefVectorOf<KVStringPair>*              fRawAttrList;
187
    unsigned int                            fRawAttrColonListSize;
188
    int*                                    fRawAttrColonList;
189
    SchemaGrammar*                          fSchemaGrammar;
190
    SchemaValidator*                        fSchemaValidator;
191
    IdentityConstraintHandler*              fICHandler;
192
    RefHash3KeysIdPool<SchemaElementDecl>*  fElemNonDeclPool;
193
    unsigned int                            fElemCount;
194
    RefHashTableOf<unsigned int, PtrHasher>*fAttDefRegistry;
195
    Hash2KeysSetOf<StringHasher>*           fUndeclaredAttrRegistry;
196
    PSVIAttributeList *                     fPSVIAttrList;
197
    XSModel*                                fModel;
198
    PSVIElement*                            fPSVIElement;
199
    ValueStackOf<bool>*                     fErrorStack;
200
    PSVIElemContext                         fPSVIElemContext;
201
    RefHash2KeysTableOf<SchemaInfo>*        fSchemaInfoList;
202
    RefHash2KeysTableOf<SchemaInfo>*        fCachedSchemaInfoList;
203
204
private :
205
    // -----------------------------------------------------------------------
206
    //  Unimplemented constructors and operators
207
    // -----------------------------------------------------------------------
208
    SGXMLScanner();
209
    SGXMLScanner(const SGXMLScanner&);
210
    SGXMLScanner& operator=(const SGXMLScanner&);
211
212
    // -----------------------------------------------------------------------
213
    //  XMLScanner virtual methods
214
    // -----------------------------------------------------------------------
215
    virtual void scanCDSection();
216
    virtual void scanCharData(XMLBuffer& toToUse);
217
    virtual EntityExpRes scanEntityRef
218
    (
219
        const   bool    inAttVal
220
        ,       XMLCh&  firstCh
221
        ,       XMLCh&  secondCh
222
        ,       bool&   escaped
223
    );
224
    virtual void scanDocTypeDecl();
225
    virtual void sendCharData(XMLBuffer& toSend);
226
    virtual InputSource* resolveSystemId(const XMLCh* const sysId
227
                                        ,const XMLCh* const pubId);
228
229
    // -----------------------------------------------------------------------
230
    //  Private helper methods
231
    // -----------------------------------------------------------------------
232
    void commonInit();
233
    void cleanUp();
234
235
    bool normalizeAttValue
236
    (
237
        const   XMLAttDef* const    attDef
238
        , const XMLCh* const        attrName
239
        , const XMLCh* const        value
240
        ,       XMLBuffer&          toFill
241
    );
242
    bool normalizeAttRawValue
243
    (
244
        const   XMLCh* const        attrName
245
        , const XMLCh* const        value
246
        ,       XMLBuffer&          toFill
247
    );
248
    void scanRawAttrListforNameSpaces(XMLSize_t attCount);
249
    void parseSchemaLocation(const XMLCh* const schemaLocationStr, bool ignoreLoadSchema = false);
250
    void resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* const uri, bool ignoreLoadSchema = false);
251
    bool switchGrammar(const XMLCh* const newGrammarNameSpace);
252
    bool anyAttributeValidation(SchemaAttDef* attWildCard,
253
                                unsigned int uriId,
254
                                bool& skipThisOne,
255
                                bool& laxThisOne);
256
257
    // -----------------------------------------------------------------------
258
    //  Private scanning methods
259
    // -----------------------------------------------------------------------
260
    bool basicAttrValueScan
261
    (
262
        const   XMLCh* const    attrName
263
        ,       XMLBuffer&      toFill
264
    );
265
    bool scanAttValue
266
    (
267
        const   XMLAttDef* const    attDef
268
        ,       XMLBuffer&          toFill
269
    );
270
    bool scanContent();
271
272
    // -----------------------------------------------------------------------
273
    //  IdentityConstraints Activation methods
274
    // -----------------------------------------------------------------------
275
    inline bool toCheckIdentityConstraint()  const;
276
277
    // -----------------------------------------------------------------------
278
    //  Grammar preparsing methods
279
    // -----------------------------------------------------------------------
280
    Grammar* loadXMLSchemaGrammar(const InputSource& src, const bool toCache = false);
281
282
    // -----------------------------------------------------------------------
283
    //  PSVI handling methods
284
    // -----------------------------------------------------------------------
285
    void endElementPSVI(SchemaElementDecl* const elemDecl,
286
                        DatatypeValidator* const memberDV);
287
    void resetPSVIElemContext();
288
};
289
290
inline const XMLCh* SGXMLScanner::getName() const
291
0
{
292
0
    return XMLUni::fgSGXMLScanner;
293
0
}
294
295
inline bool SGXMLScanner::toCheckIdentityConstraint()  const
296
0
{
297
0
    return fValidate && fIdentityConstraintChecking && fICHandler;
298
0
}
299
300
inline Grammar::GrammarType SGXMLScanner::getCurrentGrammarType() const
301
0
{
302
0
    return fGrammarType;
303
0
}
304
305
XERCES_CPP_NAMESPACE_END
306
307
#endif