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: GeneralAttributeCheck.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(GENERALATTRIBUTECHECK_HPP) |
---|
23 | #define GENERALATTRIBUTECHECK_HPP |
---|
24 | |
---|
25 | /** |
---|
26 | * A general purpose class to check for valid values of attributes, as well |
---|
27 | * as check for proper association with corresponding schema elements. |
---|
28 | */ |
---|
29 | |
---|
30 | // --------------------------------------------------------------------------- |
---|
31 | // Includes |
---|
32 | // --------------------------------------------------------------------------- |
---|
33 | #include <xercesc/util/RefHashTableOf.hpp> |
---|
34 | #include <xercesc/util/ValueHashTableOf.hpp> |
---|
35 | #include <xercesc/validators/datatype/IDDatatypeValidator.hpp> |
---|
36 | #include <xercesc/framework/ValidationContext.hpp> |
---|
37 | |
---|
38 | XERCES_CPP_NAMESPACE_BEGIN |
---|
39 | |
---|
40 | // --------------------------------------------------------------------------- |
---|
41 | // Forward declaration |
---|
42 | // --------------------------------------------------------------------------- |
---|
43 | class TraverseSchema; |
---|
44 | class DOMElement; |
---|
45 | class DOMNode; |
---|
46 | |
---|
47 | class VALIDATORS_EXPORT GeneralAttributeCheck : public XMemory |
---|
48 | { |
---|
49 | public: |
---|
50 | // ----------------------------------------------------------------------- |
---|
51 | // Constants |
---|
52 | // ----------------------------------------------------------------------- |
---|
53 | //Elements |
---|
54 | enum |
---|
55 | { |
---|
56 | E_All, |
---|
57 | E_Annotation, |
---|
58 | E_Any, |
---|
59 | E_AnyAttribute, |
---|
60 | E_Appinfo, |
---|
61 | E_AttributeGlobal, |
---|
62 | E_AttributeLocal, |
---|
63 | E_AttributeRef, |
---|
64 | E_AttributeGroupGlobal, |
---|
65 | E_AttributeGroupRef, |
---|
66 | E_Choice, |
---|
67 | E_ComplexContent, |
---|
68 | E_ComplexTypeGlobal, |
---|
69 | E_ComplexTypeLocal, |
---|
70 | E_Documentation, |
---|
71 | E_ElementGlobal, |
---|
72 | E_ElementLocal, |
---|
73 | E_ElementRef, |
---|
74 | E_Enumeration, |
---|
75 | E_Extension, |
---|
76 | E_Field, |
---|
77 | E_FractionDigits, |
---|
78 | E_GroupGlobal, |
---|
79 | E_GroupRef, |
---|
80 | E_Import, |
---|
81 | E_Include, |
---|
82 | E_Key, |
---|
83 | E_KeyRef, |
---|
84 | E_Length, |
---|
85 | E_List, |
---|
86 | E_MaxExclusive, |
---|
87 | E_MaxInclusive, |
---|
88 | E_MaxLength, |
---|
89 | E_MinExclusive, |
---|
90 | E_MinInclusive, |
---|
91 | E_MinLength, |
---|
92 | E_Notation, |
---|
93 | E_Pattern, |
---|
94 | E_Redefine, |
---|
95 | E_Restriction, |
---|
96 | E_Schema, |
---|
97 | E_Selector, |
---|
98 | E_Sequence, |
---|
99 | E_SimpleContent, |
---|
100 | E_SimpleTypeGlobal, |
---|
101 | E_SimpleTypeLocal, |
---|
102 | E_TotalDigits, |
---|
103 | E_Union, |
---|
104 | E_Unique, |
---|
105 | E_WhiteSpace, |
---|
106 | |
---|
107 | E_Count, |
---|
108 | E_Invalid = -1 |
---|
109 | }; |
---|
110 | |
---|
111 | //Attributes |
---|
112 | enum |
---|
113 | { |
---|
114 | A_Abstract, |
---|
115 | A_AttributeFormDefault, |
---|
116 | A_Base, |
---|
117 | A_Block, |
---|
118 | A_BlockDefault, |
---|
119 | A_Default, |
---|
120 | A_ElementFormDefault, |
---|
121 | A_Final, |
---|
122 | A_FinalDefault, |
---|
123 | A_Fixed, |
---|
124 | A_Form, |
---|
125 | A_ID, |
---|
126 | A_ItemType, |
---|
127 | A_MaxOccurs, |
---|
128 | A_MemberTypes, |
---|
129 | A_MinOccurs, |
---|
130 | A_Mixed, |
---|
131 | A_Name, |
---|
132 | A_Namespace, |
---|
133 | A_Nillable, |
---|
134 | A_ProcessContents, |
---|
135 | A_Public, |
---|
136 | A_Ref, |
---|
137 | A_Refer, |
---|
138 | A_SchemaLocation, |
---|
139 | A_Source, |
---|
140 | A_SubstitutionGroup, |
---|
141 | A_System, |
---|
142 | A_TargetNamespace, |
---|
143 | A_Type, |
---|
144 | A_Use, |
---|
145 | A_Value, |
---|
146 | A_Version, |
---|
147 | A_XPath, |
---|
148 | |
---|
149 | A_Count, |
---|
150 | A_Invalid = -1 |
---|
151 | }; |
---|
152 | |
---|
153 | //Validators |
---|
154 | enum { |
---|
155 | |
---|
156 | DV_String = 0, |
---|
157 | DV_AnyURI = 4, |
---|
158 | DV_NonNegInt = 8, |
---|
159 | DV_Boolean = 16, |
---|
160 | DV_ID = 32, |
---|
161 | DV_Form = 64, |
---|
162 | DV_MaxOccurs = 128, |
---|
163 | DV_MaxOccurs1 = 256, |
---|
164 | DV_MinOccurs1 = 512, |
---|
165 | DV_ProcessContents = 1024, |
---|
166 | DV_Use = 2048, |
---|
167 | DV_WhiteSpace = 4096, |
---|
168 | |
---|
169 | DV_Mask = (DV_AnyURI | DV_NonNegInt | DV_Boolean | DV_ID | DV_Form | |
---|
170 | DV_MaxOccurs | DV_MaxOccurs1 | DV_MinOccurs1 | |
---|
171 | DV_ProcessContents | DV_Use | DV_WhiteSpace) |
---|
172 | }; |
---|
173 | |
---|
174 | // generate element-attributes map table |
---|
175 | #if defined(NEED_TO_GEN_ELEM_ATT_MAP_TABLE) |
---|
176 | static void initCharFlagTable(); |
---|
177 | #endif |
---|
178 | |
---|
179 | // ----------------------------------------------------------------------- |
---|
180 | // Constructor/Destructor |
---|
181 | // ----------------------------------------------------------------------- |
---|
182 | GeneralAttributeCheck(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
183 | ~GeneralAttributeCheck(); |
---|
184 | |
---|
185 | // ----------------------------------------------------------------------- |
---|
186 | // Getter methods |
---|
187 | // ----------------------------------------------------------------------- |
---|
188 | unsigned short getFacetId(const XMLCh* const facetName, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
189 | |
---|
190 | // ----------------------------------------------------------------------- |
---|
191 | // Setter methods |
---|
192 | // ----------------------------------------------------------------------- |
---|
193 | |
---|
194 | //deprecated |
---|
195 | void setIDRefList(RefHashTableOf<XMLRefInfo>* const refList); |
---|
196 | |
---|
197 | inline void setValidationContext(ValidationContext* const); |
---|
198 | |
---|
199 | // ----------------------------------------------------------------------- |
---|
200 | // Validation methods |
---|
201 | // ----------------------------------------------------------------------- |
---|
202 | void checkAttributes(const DOMElement* const elem, |
---|
203 | const unsigned short elemContext, |
---|
204 | TraverseSchema* const schema, |
---|
205 | const bool isTopLevel = false, |
---|
206 | ValueVectorOf<DOMNode*>* const nonXSAttList = 0); |
---|
207 | |
---|
208 | // ----------------------------------------------------------------------- |
---|
209 | // Notification that lazy data has been deleted |
---|
210 | // ----------------------------------------------------------------------- |
---|
211 | static void reinitGeneralAttCheck(); |
---|
212 | |
---|
213 | private: |
---|
214 | // ----------------------------------------------------------------------- |
---|
215 | // Unimplemented constructors and operators |
---|
216 | // ----------------------------------------------------------------------- |
---|
217 | GeneralAttributeCheck(const GeneralAttributeCheck&); |
---|
218 | GeneralAttributeCheck& operator=(const GeneralAttributeCheck&); |
---|
219 | |
---|
220 | // ----------------------------------------------------------------------- |
---|
221 | // Setup methods |
---|
222 | // ----------------------------------------------------------------------- |
---|
223 | void setUpValidators(); |
---|
224 | void mapElements(); |
---|
225 | void mapAttributes(); |
---|
226 | |
---|
227 | // ----------------------------------------------------------------------- |
---|
228 | // Validation methods |
---|
229 | // ----------------------------------------------------------------------- |
---|
230 | void validate(const DOMElement* const elem, const XMLCh* const attName, const XMLCh* const attValue, |
---|
231 | const short dvIndex, TraverseSchema* const schema); |
---|
232 | |
---|
233 | // ----------------------------------------------------------------------- |
---|
234 | // Private Constants |
---|
235 | // ----------------------------------------------------------------------- |
---|
236 | // optional vs. required attribute |
---|
237 | enum { |
---|
238 | Att_Required = 1, |
---|
239 | Att_Optional = 2, |
---|
240 | Att_Mask = 3 |
---|
241 | }; |
---|
242 | |
---|
243 | // ----------------------------------------------------------------------- |
---|
244 | // Private data members |
---|
245 | // ----------------------------------------------------------------------- |
---|
246 | static ValueHashTableOf<unsigned short>* fAttMap; |
---|
247 | static ValueHashTableOf<unsigned short>* fFacetsMap; |
---|
248 | static DatatypeValidator* fNonNegIntDV; |
---|
249 | static DatatypeValidator* fBooleanDV; |
---|
250 | static DatatypeValidator* fAnyURIDV; |
---|
251 | static unsigned short fgElemAttTable[E_Count][A_Count]; |
---|
252 | static const XMLCh* fAttNames[A_Count]; |
---|
253 | MemoryManager* fMemoryManager; |
---|
254 | ValidationContext* fValidationContext; |
---|
255 | IDDatatypeValidator fIDValidator; |
---|
256 | }; |
---|
257 | |
---|
258 | |
---|
259 | // --------------------------------------------------------------------------- |
---|
260 | // GeneralAttributeCheck: Getter methods |
---|
261 | // --------------------------------------------------------------------------- |
---|
262 | inline unsigned short |
---|
263 | GeneralAttributeCheck::getFacetId(const XMLCh* const facetName, MemoryManager* const manager) { |
---|
264 | |
---|
265 | return fFacetsMap->get(facetName, manager); |
---|
266 | } |
---|
267 | |
---|
268 | // --------------------------------------------------------------------------- |
---|
269 | // GeneralAttributeCheck: Setter methods |
---|
270 | // --------------------------------------------------------------------------- |
---|
271 | inline void GeneralAttributeCheck::setValidationContext(ValidationContext* const newValidationContext) |
---|
272 | { |
---|
273 | fValidationContext = newValidationContext; |
---|
274 | } |
---|
275 | |
---|
276 | inline void |
---|
277 | GeneralAttributeCheck::setIDRefList(RefHashTableOf<XMLRefInfo>* const refList) { |
---|
278 | |
---|
279 | fValidationContext->setIdRefList(refList); |
---|
280 | } |
---|
281 | |
---|
282 | XERCES_CPP_NAMESPACE_END |
---|
283 | |
---|
284 | #endif |
---|
285 | |
---|
286 | /** |
---|
287 | * End of file GeneralAttributeCheck.hpp |
---|
288 | */ |
---|
289 | |
---|