source: icXML/icXML-devel/src/xercesc/validators/datatype/DateDatatypeValidator.cpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 4.1 KB
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: DateDatatypeValidator.cpp 471747 2006-11-06 14:31:56Z amassari $
20 */
21
22// ---------------------------------------------------------------------------
23//  Includes
24// ---------------------------------------------------------------------------
25#include <xercesc/validators/datatype/DateDatatypeValidator.hpp>
26#include <xercesc/util/OutOfMemoryException.hpp>
27
28XERCES_CPP_NAMESPACE_BEGIN
29
30// ---------------------------------------------------------------------------
31//  Constructors and Destructor
32// ---------------------------------------------------------------------------
33DateDatatypeValidator::DateDatatypeValidator(MemoryManager* const manager)
34:DateTimeValidator(0, 0, 0, DatatypeValidator::Date, manager)
35{
36    setOrdered(XSSimpleTypeDefinition::ORDERED_PARTIAL);
37}
38
39DateDatatypeValidator::DateDatatypeValidator(
40                          DatatypeValidator*            const baseValidator
41                        , RefHashTableOf<KVStringPair>* const facets
42                        , RefArrayVectorOf<XMLCh>*      const enums
43                        , const int                           finalSet
44                        , MemoryManager* const                manager)
45:DateTimeValidator(baseValidator, facets, finalSet, DatatypeValidator::Date, manager)
46{
47    init(enums, manager);
48}
49
50DateDatatypeValidator::~DateDatatypeValidator()
51{}
52
53DatatypeValidator* DateDatatypeValidator::newInstance
54(
55      RefHashTableOf<KVStringPair>* const facets
56    , RefArrayVectorOf<XMLCh>* const      enums
57    , const int                           finalSet
58    , MemoryManager* const                manager
59)
60{
61    return (DatatypeValidator*) new (manager) DateDatatypeValidator(this, facets, enums, finalSet, manager);
62}
63
64//
65// caller need to release the date created here
66//
67XMLDateTime* DateDatatypeValidator::parse(const XMLCh* const content, MemoryManager* const manager)
68{
69    XMLDateTime *pRetDate = new (manager) XMLDateTime(content, manager);
70    Janitor<XMLDateTime> jan(pRetDate);
71
72    try
73    {
74        pRetDate->parseDate();
75    }
76    catch(const OutOfMemoryException&)
77    {
78        jan.release();
79
80        throw;
81    }
82
83    return jan.release();
84}
85
86void DateDatatypeValidator::parse(XMLDateTime* const pDate)
87{
88    pDate->parseDate();
89}
90
91const XMLCh* DateDatatypeValidator::getCanonicalRepresentation(const XMLCh*         const rawData
92                                                              ,      MemoryManager* const memMgr
93                                                              ,      bool                 toValidate) const
94{
95    MemoryManager* toUse = memMgr? memMgr : fMemoryManager;
96
97    if (toValidate)
98    {
99        DateDatatypeValidator* temp = (DateDatatypeValidator*) this;
100
101        try
102        {
103            temp->checkContent(rawData, 0, false, toUse);   
104        }
105        catch (...)
106        {
107            return 0;
108        }
109    }
110   
111    try
112    {
113        XMLDateTime aDateTime(rawData, toUse);
114        aDateTime.parseDate();
115        return aDateTime.getDateCanonicalRepresentation(toUse);
116    }
117    catch (...)
118    {
119        return 0;
120    }
121
122}
123
124/***
125 * Support for Serialization/De-serialization
126 ***/
127
128IMPL_XSERIALIZABLE_TOCREATE(DateDatatypeValidator)
129
130void DateDatatypeValidator::serialize(XSerializeEngine& serEng)
131{
132    DateTimeValidator::serialize(serEng);
133}
134
135XERCES_CPP_NAMESPACE_END
136
137/**
138  * End of file DateDatatypeValidator::cpp
139  */
140
Note: See TracBrowser for help on using the repository browser.