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