1 | /*
|
---|
2 | * The Apache Software License, Version 1.1
|
---|
3 | *
|
---|
4 | * Copyright (c) 2001 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: XMLDateTime.hpp,v 1.17 2004/01/29 11:48:47 cargilld Exp $
|
---|
59 | * $Log: XMLDateTime.hpp,v $
|
---|
60 | * Revision 1.17 2004/01/29 11:48:47 cargilld
|
---|
61 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
62 | *
|
---|
63 | * Revision 1.16 2004/01/13 19:50:56 peiyongz
|
---|
64 | * remove parseContent()
|
---|
65 | *
|
---|
66 | * Revision 1.14 2003/12/31 02:34:11 neilg
|
---|
67 | * enable production of canonical representations for dates with negative years, or years >9999
|
---|
68 | *
|
---|
69 | * Revision 1.13 2003/12/17 20:00:49 cargilld
|
---|
70 | * Update for memory management so that the static memory manager (one
|
---|
71 | * used to call Initialize) is only for static data.
|
---|
72 | *
|
---|
73 | * Revision 1.12 2003/12/17 00:18:35 cargilld
|
---|
74 | * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
|
---|
75 | *
|
---|
76 | * Revision 1.11 2003/12/11 21:38:12 peiyongz
|
---|
77 | * support for Canonical Representation for Datatype
|
---|
78 | *
|
---|
79 | * Revision 1.10 2003/09/23 18:16:07 peiyongz
|
---|
80 | * Inplementation for Serialization/Deserialization
|
---|
81 | *
|
---|
82 | * Revision 1.9 2003/08/14 02:57:27 knoaman
|
---|
83 | * Code refactoring to improve performance of validation.
|
---|
84 | *
|
---|
85 | * Revision 1.8 2003/05/18 14:02:05 knoaman
|
---|
86 | * Memory manager implementation: pass per instance manager.
|
---|
87 | *
|
---|
88 | * Revision 1.7 2003/05/15 19:07:46 knoaman
|
---|
89 | * Partial implementation of the configurable memory manager.
|
---|
90 | *
|
---|
91 | * Revision 1.6 2003/05/09 15:13:46 peiyongz
|
---|
92 | * Deprecated toString() in XMLNumber family
|
---|
93 | *
|
---|
94 | * Revision 1.5 2003/03/10 20:55:58 peiyongz
|
---|
95 | * Schema Errata E2-40 double/float
|
---|
96 | *
|
---|
97 | * Revision 1.4 2003/02/02 23:54:43 peiyongz
|
---|
98 | * getFormattedString() added to return original and converted value.
|
---|
99 | *
|
---|
100 | * Revision 1.3 2003/01/30 21:55:22 tng
|
---|
101 | * Performance: create getRawData which is similar to toString but return the internal data directly, user is not required to delete the returned memory.
|
---|
102 | *
|
---|
103 | * Revision 1.2 2002/11/04 15:22:05 tng
|
---|
104 | * C++ Namespace Support.
|
---|
105 | *
|
---|
106 | * Revision 1.1.1.1 2002/02/01 22:22:14 peiyongz
|
---|
107 | * sane_include
|
---|
108 | *
|
---|
109 | * Revision 1.4 2001/11/22 20:23:00 peiyongz
|
---|
110 | * _declspec(dllimport) and inline warning C4273
|
---|
111 | *
|
---|
112 | * Revision 1.3 2001/11/12 20:36:54 peiyongz
|
---|
113 | * SchemaDateTimeException defined
|
---|
114 | *
|
---|
115 | * Revision 1.2 2001/11/09 20:41:45 peiyongz
|
---|
116 | * Fix: compilation error on Solaris and AIX.
|
---|
117 | *
|
---|
118 | * Revision 1.1 2001/11/07 19:16:03 peiyongz
|
---|
119 | * DateTime Port
|
---|
120 | *
|
---|
121 | */
|
---|
122 |
|
---|
123 | #ifndef XML_DATETIME_HPP
|
---|
124 | #define XML_DATETIME_HPP
|
---|
125 |
|
---|
126 | #include <xercesc/util/XMLNumber.hpp>
|
---|
127 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
128 | #include <xercesc/util/XMLString.hpp>
|
---|
129 | #include <xercesc/util/XMLUniDefs.hpp>
|
---|
130 | #include <xercesc/util/SchemaDateTimeException.hpp>
|
---|
131 |
|
---|
132 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
133 |
|
---|
134 | class XMLUTIL_EXPORT XMLDateTime : public XMLNumber
|
---|
135 | {
|
---|
136 | public:
|
---|
137 |
|
---|
138 | enum valueIndex
|
---|
139 | {
|
---|
140 | CentYear = 0,
|
---|
141 | Month ,
|
---|
142 | Day ,
|
---|
143 | Hour ,
|
---|
144 | Minute ,
|
---|
145 | Second ,
|
---|
146 | MiliSecond ,
|
---|
147 | utc ,
|
---|
148 | TOTAL_SIZE
|
---|
149 | };
|
---|
150 |
|
---|
151 | enum utcType
|
---|
152 | {
|
---|
153 | UTC_UNKNOWN = 0,
|
---|
154 | UTC_STD , // set in parse() or normalize()
|
---|
155 | UTC_POS , // set in parse()
|
---|
156 | UTC_NEG // set in parse()
|
---|
157 | };
|
---|
158 |
|
---|
159 | // -----------------------------------------------------------------------
|
---|
160 | // ctors and dtor
|
---|
161 | // -----------------------------------------------------------------------
|
---|
162 |
|
---|
163 | XMLDateTime(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
164 | XMLDateTime(const XMLCh* const,
|
---|
165 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
166 | ~XMLDateTime();
|
---|
167 |
|
---|
168 | inline void setBuffer(const XMLCh* const);
|
---|
169 |
|
---|
170 | // -----------------------------------------------------------------------
|
---|
171 | // Copy ctor and Assignment operators
|
---|
172 | // -----------------------------------------------------------------------
|
---|
173 |
|
---|
174 | XMLDateTime(const XMLDateTime&);
|
---|
175 |
|
---|
176 | XMLDateTime& operator=(const XMLDateTime&);
|
---|
177 |
|
---|
178 | // -----------------------------------------------------------------------
|
---|
179 | // Implementation of Abstract Interface
|
---|
180 | // -----------------------------------------------------------------------
|
---|
181 |
|
---|
182 | /**
|
---|
183 | *
|
---|
184 | * Deprecated: please use getRawData
|
---|
185 | *
|
---|
186 | */
|
---|
187 | virtual XMLCh* toString() const;
|
---|
188 |
|
---|
189 | virtual XMLCh* getRawData() const;
|
---|
190 |
|
---|
191 | virtual const XMLCh* getFormattedString() const;
|
---|
192 |
|
---|
193 | virtual int getSign() const;
|
---|
194 |
|
---|
195 | // -----------------------------------------------------------------------
|
---|
196 | // Canonical Representation
|
---|
197 | // -----------------------------------------------------------------------
|
---|
198 |
|
---|
199 | XMLCh* getDateTimeCanonicalRepresentation(MemoryManager* const memMgr) const;
|
---|
200 |
|
---|
201 | XMLCh* getTimeCanonicalRepresentation(MemoryManager* const memMgr) const;
|
---|
202 |
|
---|
203 | // -----------------------------------------------------------------------
|
---|
204 | // parsers
|
---|
205 | // -----------------------------------------------------------------------
|
---|
206 |
|
---|
207 | void parseDateTime(); //DateTime
|
---|
208 |
|
---|
209 | void parseDate(); //Date
|
---|
210 |
|
---|
211 | void parseTime(); //Time
|
---|
212 |
|
---|
213 | void parseDay(); //gDay
|
---|
214 |
|
---|
215 | void parseMonth(); //gMonth
|
---|
216 |
|
---|
217 | void parseYear(); //gYear
|
---|
218 |
|
---|
219 | void parseMonthDay(); //gMonthDay
|
---|
220 |
|
---|
221 | void parseYearMonth(); //gYearMonth
|
---|
222 |
|
---|
223 | void parseDuration(); //duration
|
---|
224 |
|
---|
225 | // -----------------------------------------------------------------------
|
---|
226 | // Comparison
|
---|
227 | // -----------------------------------------------------------------------
|
---|
228 | static int compare(const XMLDateTime* const
|
---|
229 | , const XMLDateTime* const);
|
---|
230 |
|
---|
231 | static int compare(const XMLDateTime* const
|
---|
232 | , const XMLDateTime* const
|
---|
233 | , bool );
|
---|
234 |
|
---|
235 | static int compareOrder(const XMLDateTime* const
|
---|
236 | , const XMLDateTime* const);
|
---|
237 |
|
---|
238 | /***
|
---|
239 | * Support for Serialization/De-serialization
|
---|
240 | ***/
|
---|
241 | DECL_XSERIALIZABLE(XMLDateTime)
|
---|
242 |
|
---|
243 | private:
|
---|
244 |
|
---|
245 | // -----------------------------------------------------------------------
|
---|
246 | // Constant data
|
---|
247 | // -----------------------------------------------------------------------
|
---|
248 | //
|
---|
249 | enum timezoneIndex
|
---|
250 | {
|
---|
251 | hh = 0,
|
---|
252 | mm ,
|
---|
253 | TIMEZONE_ARRAYSIZE
|
---|
254 | };
|
---|
255 |
|
---|
256 | // -----------------------------------------------------------------------
|
---|
257 | // Comparison
|
---|
258 | // -----------------------------------------------------------------------
|
---|
259 | static int compareResult(int
|
---|
260 | , int
|
---|
261 | , bool);
|
---|
262 |
|
---|
263 | static void addDuration(XMLDateTime* pDuration
|
---|
264 | , const XMLDateTime* const pBaseDate
|
---|
265 | , int index);
|
---|
266 |
|
---|
267 |
|
---|
268 | static int compareResult(const XMLDateTime* const
|
---|
269 | , const XMLDateTime* const
|
---|
270 | , bool
|
---|
271 | , int);
|
---|
272 |
|
---|
273 | static inline int getRetVal(int, int);
|
---|
274 |
|
---|
275 | // -----------------------------------------------------------------------
|
---|
276 | // helper
|
---|
277 | // -----------------------------------------------------------------------
|
---|
278 |
|
---|
279 | inline void reset();
|
---|
280 |
|
---|
281 | inline void assertBuffer() const;
|
---|
282 |
|
---|
283 | inline void copy(const XMLDateTime&);
|
---|
284 |
|
---|
285 | // allow multiple parsing
|
---|
286 | inline void initParser();
|
---|
287 |
|
---|
288 | inline bool isNormalized() const;
|
---|
289 |
|
---|
290 | // -----------------------------------------------------------------------
|
---|
291 | // scaners
|
---|
292 | // -----------------------------------------------------------------------
|
---|
293 |
|
---|
294 | void getDate();
|
---|
295 |
|
---|
296 | void getTime();
|
---|
297 |
|
---|
298 | void getYearMonth();
|
---|
299 |
|
---|
300 | void getTimeZone(const int);
|
---|
301 |
|
---|
302 | void parseTimeZone();
|
---|
303 |
|
---|
304 | // -----------------------------------------------------------------------
|
---|
305 | // locator and converter
|
---|
306 | // -----------------------------------------------------------------------
|
---|
307 |
|
---|
308 | int findUTCSign(const int start);
|
---|
309 |
|
---|
310 | int indexOf(const int start
|
---|
311 | , const int end
|
---|
312 | , const XMLCh ch) const;
|
---|
313 |
|
---|
314 | int parseInt(const int start
|
---|
315 | , const int end) const;
|
---|
316 |
|
---|
317 | int parseIntYear(const int end) const;
|
---|
318 |
|
---|
319 | // -----------------------------------------------------------------------
|
---|
320 | // validator and normalizer
|
---|
321 | // -----------------------------------------------------------------------
|
---|
322 |
|
---|
323 | void validateDateTime() const;
|
---|
324 |
|
---|
325 | void normalize();
|
---|
326 |
|
---|
327 | void fillString(XMLCh*& ptr, valueIndex ind, int expLen) const;
|
---|
328 |
|
---|
329 | int fillYearString(XMLCh*& ptr, valueIndex ind) const;
|
---|
330 |
|
---|
331 | void searchMiliSeconds(XMLCh*& miliStartPtr, XMLCh*& miliEndPtr) const;
|
---|
332 |
|
---|
333 | // -----------------------------------------------------------------------
|
---|
334 | // Unimplemented operator ==
|
---|
335 | // -----------------------------------------------------------------------
|
---|
336 | bool operator==(const XMLDateTime& toCompare) const;
|
---|
337 |
|
---|
338 |
|
---|
339 | // -----------------------------------------------------------------------
|
---|
340 | // Private data members
|
---|
341 | //
|
---|
342 | // fValue[]
|
---|
343 | // object representation of date time.
|
---|
344 | //
|
---|
345 | // fTimeZone[]
|
---|
346 | // temporary storage for normalization
|
---|
347 | //
|
---|
348 | // fStart, fEnd
|
---|
349 | // pointers to the portion of fBuffer being parsed
|
---|
350 | //
|
---|
351 | // fBuffer
|
---|
352 | // raw data to be parsed, own it.
|
---|
353 | //
|
---|
354 | // -----------------------------------------------------------------------
|
---|
355 |
|
---|
356 | int fValue[TOTAL_SIZE];
|
---|
357 | int fTimeZone[TIMEZONE_ARRAYSIZE];
|
---|
358 | int fStart;
|
---|
359 | int fEnd;
|
---|
360 | int fBufferMaxLen;
|
---|
361 | XMLCh* fBuffer;
|
---|
362 | MemoryManager* fMemoryManager;
|
---|
363 | };
|
---|
364 |
|
---|
365 | inline void XMLDateTime::setBuffer(const XMLCh* const aString)
|
---|
366 | {
|
---|
367 | reset();
|
---|
368 |
|
---|
369 | fEnd = XMLString::stringLen(aString);
|
---|
370 | if (fEnd > 0) {
|
---|
371 |
|
---|
372 | if (fEnd > fBufferMaxLen)
|
---|
373 | {
|
---|
374 | fMemoryManager->deallocate(fBuffer);
|
---|
375 | fBufferMaxLen = fEnd + 8;
|
---|
376 | fBuffer = (XMLCh*) fMemoryManager->allocate((fBufferMaxLen+1) * sizeof(XMLCh));
|
---|
377 | }
|
---|
378 |
|
---|
379 | memcpy(fBuffer, aString, (fEnd+1) * sizeof(XMLCh));
|
---|
380 | }
|
---|
381 | }
|
---|
382 |
|
---|
383 | inline void XMLDateTime::reset()
|
---|
384 | {
|
---|
385 | for ( int i=0; i < TOTAL_SIZE; i++ )
|
---|
386 | fValue[i] = 0;
|
---|
387 |
|
---|
388 | fTimeZone[hh] = fTimeZone[mm] = 0;
|
---|
389 | fStart = fEnd = 0;
|
---|
390 |
|
---|
391 | if (fBuffer)
|
---|
392 | *fBuffer = 0;
|
---|
393 | }
|
---|
394 |
|
---|
395 | inline void XMLDateTime::copy(const XMLDateTime& rhs)
|
---|
396 | {
|
---|
397 | for ( int i = 0; i < TOTAL_SIZE; i++ )
|
---|
398 | fValue[i] = rhs.fValue[i];
|
---|
399 |
|
---|
400 | fTimeZone[hh] = rhs.fTimeZone[hh];
|
---|
401 | fTimeZone[mm] = rhs.fTimeZone[mm];
|
---|
402 | fStart = rhs.fStart;
|
---|
403 | fEnd = rhs.fEnd;
|
---|
404 |
|
---|
405 | if (fEnd > 0)
|
---|
406 | {
|
---|
407 | if (fEnd > fBufferMaxLen)
|
---|
408 | {
|
---|
409 | fMemoryManager->deallocate(fBuffer);//delete[] fBuffer;
|
---|
410 | fBufferMaxLen = rhs.fBufferMaxLen;
|
---|
411 | fBuffer = (XMLCh*) fMemoryManager->allocate((fBufferMaxLen+1) * sizeof(XMLCh));
|
---|
412 | }
|
---|
413 |
|
---|
414 | memcpy(fBuffer, rhs.fBuffer, (fEnd+1) * sizeof(XMLCh));
|
---|
415 | }
|
---|
416 | }
|
---|
417 |
|
---|
418 | inline void XMLDateTime::assertBuffer() const
|
---|
419 | {
|
---|
420 | if ( ( !fBuffer ) ||
|
---|
421 | ( fBuffer[0] == chNull ) )
|
---|
422 | {
|
---|
423 | ThrowXMLwithMemMgr(SchemaDateTimeException
|
---|
424 | , XMLExcepts::DateTime_Assert_Buffer_Fail
|
---|
425 | , fMemoryManager);
|
---|
426 | }
|
---|
427 |
|
---|
428 | }
|
---|
429 |
|
---|
430 | inline void XMLDateTime::initParser()
|
---|
431 | {
|
---|
432 | assertBuffer();
|
---|
433 | fStart = 0; // to ensure scan from the very first beginning
|
---|
434 | // in case the pointer is updated accidentally by someone else.
|
---|
435 | }
|
---|
436 |
|
---|
437 | inline bool XMLDateTime::isNormalized() const
|
---|
438 | {
|
---|
439 | return ( fValue[utc] == UTC_STD ? true : false );
|
---|
440 | }
|
---|
441 |
|
---|
442 | inline int XMLDateTime::getRetVal(int c1, int c2)
|
---|
443 | {
|
---|
444 | if ((c1 == LESS_THAN && c2 == GREATER_THAN) ||
|
---|
445 | (c1 == GREATER_THAN && c2 == LESS_THAN) )
|
---|
446 | {
|
---|
447 | return INDETERMINATE;
|
---|
448 | }
|
---|
449 |
|
---|
450 | return ( c1 != INDETERMINATE ) ? c1 : c2;
|
---|
451 | }
|
---|
452 |
|
---|
453 | XERCES_CPP_NAMESPACE_END
|
---|
454 |
|
---|
455 | #endif
|
---|