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$
20  */
21 
22 // ---------------------------------------------------------------------------
23 //  Includes
24 // ---------------------------------------------------------------------------
25 #include <xercesc/validators/datatype/IDREFDatatypeValidator.hpp>
26 #include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp>
27 #include <xercesc/util/XMLChar.hpp>
28 
29 XERCES_CPP_NAMESPACE_BEGIN
30 
31 // ---------------------------------------------------------------------------
32 //  Constructors and Destructor
33 // ---------------------------------------------------------------------------
IDREFDatatypeValidator(MemoryManager * const manager)34 IDREFDatatypeValidator::IDREFDatatypeValidator(MemoryManager* const manager)
35 :StringDatatypeValidator(0, 0, 0, DatatypeValidator::IDREF, manager)
36 {}
37 
IDREFDatatypeValidator(DatatypeValidator * const baseValidator,RefHashTableOf<KVStringPair> * const facets,RefArrayVectorOf<XMLCh> * const enums,const int finalSet,MemoryManager * const manager)38 IDREFDatatypeValidator::IDREFDatatypeValidator(
39                                            DatatypeValidator*            const baseValidator
40                                          , RefHashTableOf<KVStringPair>* const facets
41                                          , RefArrayVectorOf<XMLCh>*      const enums
42                                          , const int                           finalSet
43                                          , MemoryManager* const                manager)
44 :StringDatatypeValidator(baseValidator, facets, finalSet, DatatypeValidator::IDREF, manager)
45 {
46     init(enums, manager);
47 }
48 
~IDREFDatatypeValidator()49 IDREFDatatypeValidator::~IDREFDatatypeValidator()
50 {}
51 
newInstance(RefHashTableOf<KVStringPair> * const facets,RefArrayVectorOf<XMLCh> * const enums,const int finalSet,MemoryManager * const manager)52 DatatypeValidator* IDREFDatatypeValidator::newInstance
53 (
54       RefHashTableOf<KVStringPair>* const facets
55     , RefArrayVectorOf<XMLCh>* const      enums
56     , const int                           finalSet
57     , MemoryManager* const                manager
58 )
59 {
60     return (DatatypeValidator*) new (manager) IDREFDatatypeValidator(this, facets, enums, finalSet, manager);
61 }
62 
IDREFDatatypeValidator(DatatypeValidator * const baseValidator,RefHashTableOf<KVStringPair> * const facets,const int finalSet,const ValidatorType type,MemoryManager * const manager)63 IDREFDatatypeValidator::IDREFDatatypeValidator(
64                           DatatypeValidator*            const baseValidator
65                         , RefHashTableOf<KVStringPair>* const facets
66                         , const int                           finalSet
67                         , const ValidatorType                 type
68                         , MemoryManager* const                manager)
69 :StringDatatypeValidator(baseValidator, facets, finalSet, type, manager)
70 {
71     // do not invoke init() here!!!
72 }
73 
validate(const XMLCh * const content,ValidationContext * const context,MemoryManager * const manager)74 void IDREFDatatypeValidator::validate(const XMLCh*             const content
75                                     ,       ValidationContext* const context
76                                     ,       MemoryManager*     const manager)
77 {
78     // use StringDatatypeValidator (which in turn, invoke
79     // the baseValidator) to validate content against
80     // facets if any.
81     //
82     StringDatatypeValidator::validate(content, context, manager);
83 
84     // this is different from java, since we always add, while
85     // in java, it is done as told. REVISIT.
86     //
87     if (context)
88     {
89         context->addIdRef(content);
90     }
91 
92 }
93 
checkValueSpace(const XMLCh * const content,MemoryManager * const manager)94 void IDREFDatatypeValidator::checkValueSpace(const XMLCh* const content
95                                              , MemoryManager* const manager)
96 {
97     //
98     // 3.3.9 check must: "NCName"
99     //
100     if ( !XMLChar1_0::isValidNCName(content, XMLString::stringLen(content)) )
101     {
102         ThrowXMLwithMemMgr1(InvalidDatatypeValueException
103                 , XMLExcepts::VALUE_Invalid_NCName
104                 , content
105                 , manager);
106     }
107 
108 }
109 
110 /***
111  * Support for Serialization/De-serialization
112  ***/
113 
IMPL_XSERIALIZABLE_TOCREATE(IDREFDatatypeValidator)114 IMPL_XSERIALIZABLE_TOCREATE(IDREFDatatypeValidator)
115 
116 void IDREFDatatypeValidator::serialize(XSerializeEngine& serEng)
117 {
118     StringDatatypeValidator::serialize(serEng);
119 }
120 
121 XERCES_CPP_NAMESPACE_END
122 
123 /**
124   * End of file IDREFDatatypeValidator.cpp
125   */
126