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: AbstractStringValidator.cpp 834826 2009-11-11 10:03:53Z borisk $
20  */
21 
22 // ---------------------------------------------------------------------------
23 //  Includes
24 // ---------------------------------------------------------------------------
25 #include <xercesc/validators/datatype/AbstractStringValidator.hpp>
26 #include <xercesc/validators/datatype/InvalidDatatypeFacetException.hpp>
27 #include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp>
28 #include <xercesc/util/NumberFormatException.hpp>
29 
30 #include <xercesc/internal/XTemplateSerializer.hpp>
31 
32 XERCES_CPP_NAMESPACE_BEGIN
33 
34 static const int BUF_LEN = 64;
35 
36 #define  REPORT_FACET_ERROR(val1, val2, except_code, manager)    \
37     XMLCh value1[BUF_LEN+1]; \
38     XMLCh value2[BUF_LEN+1]; \
39    XMLString::sizeToText(val1, value1, BUF_LEN, 10, manager);     \
40    XMLString::sizeToText(val2, value2, BUF_LEN, 10, manager);     \
41    ThrowXMLwithMemMgr2(InvalidDatatypeFacetException              \
42            , except_code                                \
43            , value1                                     \
44            , value2                                     \
45            , manager);
46 
47 #define  REPORT_VALUE_ERROR(data, val1, val2, except_code, manager)       \
48     XMLCh value1[BUF_LEN+1]; \
49     XMLCh value2[BUF_LEN+1]; \
50    XMLString::sizeToText(val1, value1, BUF_LEN, 10, manager);             \
51    XMLString::sizeToText(val2, value2, BUF_LEN, 10, manager);             \
52    ThrowXMLwithMemMgr3(InvalidDatatypeValueException                      \
53            , except_code                                        \
54            , data                                               \
55            , value1                                             \
56            , value2                                             \
57            , manager);
58 
59 // ---------------------------------------------------------------------------
60 //  Constructors and Destructor
61 // ---------------------------------------------------------------------------
~AbstractStringValidator()62 AbstractStringValidator::~AbstractStringValidator()
63 {
64     //~RefVectorOf will delete all adopted elements
65     if ( !fEnumerationInherited && fEnumeration)
66     {
67         delete fEnumeration;
68         fEnumeration = 0;
69     }
70 }
71 
AbstractStringValidator(DatatypeValidator * const baseValidator,RefHashTableOf<KVStringPair> * const facets,const int finalSet,const ValidatorType type,MemoryManager * const manager)72 AbstractStringValidator::AbstractStringValidator(
73                           DatatypeValidator*            const baseValidator
74                         , RefHashTableOf<KVStringPair>* const facets
75                         , const int                           finalSet
76                         , const ValidatorType                 type
77                         , MemoryManager* const                manager)
78 :DatatypeValidator(baseValidator, facets, finalSet, type, manager)
79 ,fLength(0)
80 ,fMaxLength(SchemaSymbols::fgINT_MAX_VALUE)
81 ,fMinLength(0)
82 ,fEnumerationInherited(false)
83 ,fEnumeration(0)
84 {
85     // init() is invoked from derived class's ctor instead of from
86     // here to allow correct resolution of virutal method, such as
87     // assigneAdditionalFacet(), inheritAdditionalFacet().
88 }
89 
init(RefArrayVectorOf<XMLCh> * const enums,MemoryManager * const manager)90 void AbstractStringValidator::init(RefArrayVectorOf<XMLCh>*           const enums
91                                    ,MemoryManager*                    const manager)
92 {
93 
94     if (enums)
95     {
96         setEnumeration(enums, false);
97         normalizeEnumeration(manager);
98     }
99 
100     assignFacet(manager);
101     inspectFacet(manager);
102     inspectFacetBase(manager);
103     inheritFacet();
104 
105 }
106 
107 //
108 //   Assign facets
109 //        assign common facets
110 //        assign additional facet
111 //
assignFacet(MemoryManager * const manager)112 void AbstractStringValidator::assignFacet(MemoryManager* const manager)
113 {
114 
115     RefHashTableOf<KVStringPair>* facets = getFacets();
116 
117     if (!facets)
118         return;
119 
120     XMLCh* key;
121     RefHashTableOfEnumerator<KVStringPair> e(facets, false, manager);
122 
123     while (e.hasMoreElements())
124     {
125         KVStringPair pair = e.nextElement();
126         key = pair.getKey();
127         XMLCh* value = pair.getValue();
128 
129         if (XMLString::equals(key, SchemaSymbols::fgELT_LENGTH))
130         {
131             int val;
132             try
133             {
134                 val = XMLString::parseInt(value, manager);
135             }
136             catch (NumberFormatException&)
137             {
138                 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Len, value, manager);
139             }
140 
141             if ( val < 0 )
142                 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_Len, value, manager);
143 
144             setLength(val);
145             setFacetsDefined(DatatypeValidator::FACET_LENGTH);
146         }
147         else if (XMLString::equals(key, SchemaSymbols::fgELT_MINLENGTH))
148         {
149             int val;
150             try
151             {
152                 val = XMLString::parseInt(value, manager);
153             }
154             catch (NumberFormatException&)
155             {
156                 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_minLen, value, manager);
157             }
158 
159             if ( val < 0 )
160                 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_minLen, value, manager);
161 
162             setMinLength(val);
163             setFacetsDefined(DatatypeValidator::FACET_MINLENGTH);
164         }
165         else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXLENGTH))
166         {
167             int val;
168             try
169             {
170                 val = XMLString::parseInt(value, manager);
171             }
172             catch (NumberFormatException&)
173             {
174                 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_maxLen, value, manager);
175             }
176 
177             if ( val < 0 )
178                 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_maxLen, value, manager);
179 
180             setMaxLength(val);
181             setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH);
182         }
183         else if (XMLString::equals(key, SchemaSymbols::fgELT_PATTERN))
184         {
185             setPattern(value);
186             if (getPattern())
187                 setFacetsDefined(DatatypeValidator::FACET_PATTERN);
188             // do not construct regex until needed
189         }
190         else if (XMLString::equals(key, SchemaSymbols::fgATT_FIXED))
191         {
192             unsigned int val;
193             bool         retStatus;
194             try
195             {
196                 retStatus = XMLString::textToBin(value, val, fMemoryManager);
197             }
198             catch (RuntimeException&)
199             {
200                 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager);
201             }
202 
203             if (!retStatus)
204             {
205                 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager);
206             }
207 
208             setFixed(val);
209             //no setFacetsDefined here
210         }
211         //
212         // else if (XMLString::equals(key, SchemaSymbols::fgELT_SPECIAL_TOKEN))
213         // TODO
214         //
215         // Note: whitespace is taken care of by TraverseSchema.
216         //
217         else
218         {
219             assignAdditionalFacet(key, value, manager);
220         }
221     }//while
222 }//end of assigneFacet()
223 
224 //
225 // Check facet among self
226 //         check common facets
227 //         check Additional Facet Constraint
228 //
inspectFacet(MemoryManager * const manager)229 void AbstractStringValidator::inspectFacet(MemoryManager* const manager)
230 {
231 
232     int thisFacetsDefined = getFacetsDefined();
233 
234     if (!thisFacetsDefined)
235         return;
236 
237     // check 4.3.1.c1 error: length & (maxLength | minLength)
238     if ((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0)
239     {
240         if ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) != 0)
241             ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen, manager);
242         else if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0))
243             ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen, manager);
244     }
245 
246     // check 4.3.2.c1 must: minLength <= maxLength
247     if ((thisFacetsDefined & (DatatypeValidator::FACET_MINLENGTH
248         |DatatypeValidator::FACET_MAXLENGTH)) != 0)
249     {
250         XMLSize_t thisMinLength = getMinLength();
251         XMLSize_t thisMaxLength = getMaxLength();
252         if ( thisMinLength > thisMaxLength )
253         {
254             REPORT_FACET_ERROR(thisMaxLength
255                              , thisMinLength
256                              , XMLExcepts::FACET_maxLen_minLen
257                              , manager)
258         }
259     }
260 
261 }// end of inspectFacet()
262 
263 //
264 //  Check vs base
265 //         check common facets
266 //         check enumeration
267 //         check Additional Facet Constraint
268 //
inspectFacetBase(MemoryManager * const manager)269 void AbstractStringValidator::inspectFacetBase(MemoryManager* const manager)
270 {
271 
272     AbstractStringValidator *pBaseValidator = (AbstractStringValidator*) getBaseValidator();
273     int thisFacetsDefined = getFacetsDefined();
274 
275     if ( (!thisFacetsDefined && !fEnumeration) ||
276          (!pBaseValidator)                      )
277         return;
278 
279     int baseFacetsDefined = pBaseValidator->getFacetsDefined();
280 
281     XMLSize_t thisLength    = getLength();
282     XMLSize_t thisMinLength = getMinLength();
283     XMLSize_t thisMaxLength = getMaxLength();
284 
285     XMLSize_t baseLength    = pBaseValidator->getLength();
286     XMLSize_t baseMinLength = pBaseValidator->getMinLength();
287     XMLSize_t baseMaxLength = pBaseValidator->getMaxLength();
288     int baseFixed     = pBaseValidator->getFixed();
289 
290     /***
291        check facets against base.facets
292        Note: later we need to check the "fix" option of the base type
293             and apply that to every individual facet.
294     ***/
295 
296     /***
297                 Non coexistence of derived' length and base'    (minLength | maxLength)
298                                    base'    length and derived' (minLength | maxLength)
299 
300      E2-35
301      It is an error for both length and either of minLength or maxLength to be members of {facets},
302      unless they are specified in different derivation steps in which case the following must be true:
303      the {value} of minLength <= the {value} of length <= the {value} of maxLength
304     ***/
305 
306     // error: length > base.maxLength
307     //        length < base.minLength
308     if ((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0)
309     {
310         if (((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0) &&
311              (thisLength > baseMaxLength)                                   )
312         {
313             REPORT_FACET_ERROR(thisLength
314                              , baseMaxLength
315                              , XMLExcepts::FACET_Len_baseMaxLen
316                              , manager)
317         }
318 
319         if (((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) &&
320              (thisLength < baseMinLength)                                   )
321         {
322             REPORT_FACET_ERROR(thisLength
323                              , baseMinLength
324                              , XMLExcepts::FACET_Len_baseMinLen
325                              , manager)
326         }
327     }
328 
329     // error: baseLength > maxLength
330     //        baseLength < minLength
331     if ((baseFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0)
332     {
333         if (((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0) &&
334              (baseLength > thisMaxLength)                                   )
335         {
336             REPORT_FACET_ERROR(thisMaxLength
337                              , baseLength
338                              , XMLExcepts::FACET_maxLen_baseLen
339                              , manager)
340         }
341 
342         if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) &&
343              (baseLength < thisMinLength)                                   )
344         {
345             REPORT_FACET_ERROR(thisMinLength
346                              , baseLength
347                              , XMLExcepts::FACET_minLen_baseLen
348                              , manager)
349         }
350     }
351 
352     // check 4.3.1.c2 error: length != base.length
353     if (((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0) &&
354         ((baseFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0))
355     {
356         if ( thisLength != baseLength )
357         {
358             REPORT_FACET_ERROR(thisLength
359                              , baseLength
360                              , XMLExcepts::FACET_Len_baseLen
361                              , manager)
362         }
363     }
364 
365     /***
366                                    |---  derived   ---|
367                 base.minLength <= minLength <= maxLength <= base.maxLength
368                 |-------------------        base      -------------------|
369     ***/
370 
371     // check 4.3.2.c1 must: minLength <= base.maxLength
372     if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH ) != 0) &&
373         ((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH ) != 0))
374     {
375         if ( thisMinLength > baseMaxLength )
376         {
377             REPORT_FACET_ERROR(thisMinLength
378                              , baseMaxLength
379                              , XMLExcepts::FACET_minLen_basemaxLen
380                              , manager)
381         }
382     }
383 
384     // check 4.3.2.c2 error: minLength < base.minLength
385     if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) &&
386         ((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0))
387     {
388         if ((baseFixed & DatatypeValidator::FACET_MINLENGTH) !=0)
389         {
390             if ( thisMinLength != baseMinLength )
391             {
392                 REPORT_FACET_ERROR(thisMinLength
393                                  , baseMinLength
394                                  , XMLExcepts::FACET_minLen_base_fixed
395                                  , manager)
396             }
397 
398         }
399         else
400         {
401             if ( thisMinLength < baseMinLength )
402             {
403                 REPORT_FACET_ERROR(thisMinLength
404                                  , baseMinLength
405                                  , XMLExcepts::FACET_minLen_baseminLen
406                                  , manager)
407             }
408         }
409     }
410 
411     // check 4.3.2.c1 must: base.minLength <= maxLength
412     if (((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) &&
413         ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0))
414     {
415         if ( baseMinLength > thisMaxLength )
416         {
417             REPORT_FACET_ERROR(thisMaxLength
418                              , baseMinLength
419                              , XMLExcepts::FACET_maxLen_baseminLen
420                              , manager)
421         }
422     }
423 
424     // check 4.3.3.c1 error: maxLength > base.maxLength
425     if (((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0) &&
426         ((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0))
427     {
428         if ((baseFixed & DatatypeValidator::FACET_MAXLENGTH) !=0)
429         {
430             if ( thisMaxLength != baseMaxLength )
431             {
432                 REPORT_FACET_ERROR(thisMaxLength
433                                  , baseMaxLength
434                                  , XMLExcepts::FACET_maxLen_base_fixed
435                                  , manager)
436             }
437         }
438         else
439         {
440             if ( thisMaxLength > baseMaxLength )
441             {
442                 REPORT_FACET_ERROR(thisMaxLength
443                                  , baseMaxLength
444                                  , XMLExcepts::FACET_maxLen_basemaxLen
445                                  , manager)
446             }
447         }
448     }
449 
450     // check 4.3.5.c0 must: enumeration values from the value space of base
451     if ( ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0) &&
452         (getEnumeration() !=0))
453     {
454         XMLSize_t i = 0;
455         XMLSize_t enumLength = getEnumeration()->size();
456         for ( ; i < enumLength; i++)
457         {
458             // ask parent do a complete check
459             pBaseValidator->checkContent(getEnumeration()->elementAt(i), (ValidationContext*)0, false, manager);
460 #if 0
461 // spec says that only base has to checkContent
462             // enum shall pass this->checkContent() as well.
463             checkContent(getEnumeration()->elementAt(i), (ValidationContext*)0, false, manager);
464 #endif
465         }
466     }
467 
468     checkAdditionalFacetConstraints(manager);
469 
470 } //end of inspectFacetBase
471 
472 //
473 //  Inherit facet from base
474 //    a. inherit common facets
475 //    b. inherit additional facet
476 //
inheritFacet()477 void AbstractStringValidator::inheritFacet()
478 {
479     /***
480         P3. Inherit facets from base.facets
481 
482         The reason of this inheriting (or copying values) is to ease
483         schema constraint checking, so that we need NOT trace back to our
484         very first base validator in the hierachy. Instead, we are pretty
485         sure checking against immediate base validator is enough.
486     ***/
487 
488     AbstractStringValidator *pBaseValidator = (AbstractStringValidator*) getBaseValidator();
489 
490     if (!pBaseValidator)
491         return;
492 
493     int thisFacetsDefined = getFacetsDefined();
494     int baseFacetsDefined = pBaseValidator->getFacetsDefined();
495 
496     // inherit length
497     if (((baseFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0) &&
498         ((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) == 0))
499     {
500         setLength(pBaseValidator->getLength());
501         setFacetsDefined(DatatypeValidator::FACET_LENGTH);
502     }
503 
504     // inherit minLength
505     if (((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) &&
506         ((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) == 0))
507     {
508         setMinLength(pBaseValidator->getMinLength());
509         setFacetsDefined(DatatypeValidator::FACET_MINLENGTH);
510     }
511 
512     // inherit maxLength
513     if (((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0) &&
514         ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) == 0))
515     {
516         setMaxLength(pBaseValidator->getMaxLength());
517         setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH);
518     }
519 
520     // inherit enumeration
521     if (((baseFacetsDefined & DatatypeValidator::FACET_ENUMERATION) !=0) &&
522         ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) == 0))
523     {
524         setEnumeration(pBaseValidator->getEnumeration(), true);
525     }
526 
527     // we don't inherit pattern
528 
529     // inherit "fixed" option
530     setFixed(getFixed() | pBaseValidator->getFixed());
531 
532     // inherit additional facet
533     inheritAdditionalFacet();
534 
535 } // end of inheritance
536 
537 
538 // -----------------------------------------------------------------------
539 // Compare methods
540 // -----------------------------------------------------------------------
compare(const XMLCh * const lValue,const XMLCh * const rValue,MemoryManager * const)541 int AbstractStringValidator::compare(const XMLCh* const lValue
542                                    , const XMLCh* const rValue
543                                    , MemoryManager*     const)
544 {
545     return XMLString::compareString(lValue, rValue);
546 }
547 
validate(const XMLCh * const content,ValidationContext * const context,MemoryManager * const manager)548 void AbstractStringValidator::validate( const XMLCh*             const content
549                                       ,       ValidationContext* const context
550                                       ,       MemoryManager*     const manager)
551 {
552     checkContent(content, context, false, manager);
553 }
554 
checkContent(const XMLCh * const content,ValidationContext * const context,bool asBase,MemoryManager * const manager)555 void AbstractStringValidator::checkContent( const XMLCh*             const content
556                                           ,       ValidationContext* const context
557                                           ,       bool                     asBase
558                                           ,       MemoryManager*     const manager
559                                           )
560 {
561 
562     //validate against base validator if any
563     AbstractStringValidator *pBaseValidator = (AbstractStringValidator*) this->getBaseValidator();
564     if (pBaseValidator)
565         pBaseValidator->checkContent(content, context, true, manager);
566 
567     int thisFacetsDefined = getFacetsDefined();
568 
569     // we check pattern first
570     if ( (thisFacetsDefined & DatatypeValidator::FACET_PATTERN ) != 0 )
571     {
572         if (getRegex()->matches(content, manager) ==false)
573         {
574             ThrowXMLwithMemMgr2(InvalidDatatypeValueException
575                     , XMLExcepts::VALUE_NotMatch_Pattern
576                     , content
577                     , getPattern()
578                     , manager);
579         }
580     }
581 
582     // if this is a base validator, we only need to check pattern facet
583     // all other facet were inherited by the derived type
584     if (asBase)
585         return;
586 
587     checkValueSpace(content, manager);
588     XMLSize_t length = getLength(content, manager);
589 
590     if (((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) != 0) &&
591         (length > getMaxLength()))
592     {
593         REPORT_VALUE_ERROR(content
594                          , length
595                          , getMaxLength()
596                          , XMLExcepts::VALUE_GT_maxLen
597                          , manager)
598     }
599 
600     if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0) &&
601         (length < getMinLength()))
602     {
603         REPORT_VALUE_ERROR(content
604                          , length
605                          , getMinLength()
606                          , XMLExcepts::VALUE_LT_minLen
607                          , manager)
608     }
609 
610     if (((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0) &&
611         (length != getLength()))
612     {
613         REPORT_VALUE_ERROR(content
614                          , length
615                          , getLength()
616                          , XMLExcepts::VALUE_NE_Len
617                          , manager)
618     }
619 
620     if ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0 &&
621         (getEnumeration() != 0))
622     {
623         XMLCh* normContent = XMLString::replicate(content, manager);
624         ArrayJanitor<XMLCh>  jan(normContent, manager);
625         normalizeContent(normContent, manager);
626 
627         XMLSize_t i=0;
628         XMLSize_t enumLength = getEnumeration()->size();
629         for ( ; i < enumLength; i++)
630         {
631             if (XMLString::equals(normContent, getEnumeration()->elementAt(i)))
632                 break;
633         }
634 
635         if (i == enumLength)
636             ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content, manager);
637     }
638 
639     checkAdditionalFacet(content, manager);
640 
641 }
642 
getEnumString() const643 const RefArrayVectorOf<XMLCh>* AbstractStringValidator::getEnumString() const
644 {
645 	return getEnumeration();
646 }
647 
normalizeEnumeration(MemoryManager * const manager)648 void AbstractStringValidator::normalizeEnumeration(MemoryManager* const manager)
649 {
650     AbstractStringValidator *pBaseValidator = (AbstractStringValidator*) getBaseValidator();
651 
652     if (!fEnumeration || !pBaseValidator)
653         return;
654 
655     int baseFacetsDefined = pBaseValidator->getFacetsDefined();
656     if ((baseFacetsDefined & DatatypeValidator::FACET_WHITESPACE) == 0)
657         return;
658 
659     short whiteSpace = pBaseValidator->getWSFacet();
660 
661     if ( whiteSpace == DatatypeValidator::PRESERVE )
662     {
663         return;
664     }
665     else if ( whiteSpace == DatatypeValidator::REPLACE )
666     {
667         XMLSize_t enumLength = getEnumeration()->size();
668         for ( XMLSize_t i=0; i < enumLength; i++)
669         {
670             XMLString::replaceWS(getEnumeration()->elementAt(i), manager);
671         }
672     }
673     else if ( whiteSpace == DatatypeValidator::COLLAPSE )
674     {
675         XMLSize_t enumLength = getEnumeration()->size();
676         for ( XMLSize_t i=0; i < enumLength; i++)
677         {
678             XMLString::collapseWS(getEnumeration()->elementAt(i), manager);
679         }
680     }
681 }
682 
normalizeContent(XMLCh * const,MemoryManager * const) const683 void AbstractStringValidator::normalizeContent(XMLCh* const, MemoryManager* const) const
684 {
685     // default implementation: do nothing
686     return;
687 }
688 
689 
checkAdditionalFacetConstraints(MemoryManager * const) const690 void AbstractStringValidator::checkAdditionalFacetConstraints(MemoryManager* const) const
691 {
692     return;
693 }
694 
checkAdditionalFacet(const XMLCh * const,MemoryManager * const) const695 void AbstractStringValidator::checkAdditionalFacet(const XMLCh* const
696                                     , MemoryManager* const) const
697 {
698     return;
699 }
700 
inheritAdditionalFacet()701 void AbstractStringValidator::inheritAdditionalFacet()
702 {
703     return;
704 }
705 
assignAdditionalFacet(const XMLCh * const key,const XMLCh * const,MemoryManager * const manager)706 void AbstractStringValidator::assignAdditionalFacet( const XMLCh* const key
707                                                    , const XMLCh* const
708                                                    , MemoryManager* const manager)
709 {
710     ThrowXMLwithMemMgr1(InvalidDatatypeFacetException
711             , XMLExcepts::FACET_Invalid_Tag
712             , key
713             , manager);
714 }
715 
getLength(const XMLCh * const content,MemoryManager * const) const716 XMLSize_t AbstractStringValidator::getLength(const XMLCh* const content
717                                            , MemoryManager* const) const
718 {
719     return XMLString::stringLen(content);
720 }
721 
722 /***
723  * Support for Serialization/De-serialization
724  ***/
725 
IMPL_XSERIALIZABLE_NOCREATE(AbstractStringValidator)726 IMPL_XSERIALIZABLE_NOCREATE(AbstractStringValidator)
727 
728 void AbstractStringValidator::serialize(XSerializeEngine& serEng)
729 {
730 
731     DatatypeValidator::serialize(serEng);
732 
733     if (serEng.isStoring())
734     {
735         serEng.writeSize (fLength);
736         serEng.writeSize (fMaxLength);
737         serEng.writeSize (fMinLength);
738         serEng<<fEnumerationInherited;
739 
740         /***
741          *
742          * Serialize RefArrayVectorOf<XMLCh>
743          *
744          ***/
745         XTemplateSerializer::storeObject(fEnumeration, serEng);
746 
747     }
748     else
749     {
750         serEng.readSize (fLength);
751         serEng.readSize (fMaxLength);
752         serEng.readSize (fMinLength);
753         serEng>>fEnumerationInherited;
754 
755         /***
756          *
757          *  Deserialize RefArrayVectorOf<XMLCh>
758          *
759         ***/
760         XTemplateSerializer::loadObject(&fEnumeration, 8, true, serEng);
761 
762     }
763 
764 }
765 
766 XERCES_CPP_NAMESPACE_END
767 
768 /**
769   * End of file AbstractStringValidator.cpp
770   */
771