xsvalue.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,743 行 · 第 1/5 页
CPP
1,743 行
/* * Copyright 2004,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * $Log: XSValue.cpp,v $ * Revision 1.13 2004/09/28 08:54:34 amassari * Silence a warning about missing final "return" * * Revision 1.12 2004/09/23 21:22:47 peiyongz * Documentation * st_noContent added * unused parameter removed * * Revision 1.11 2004/09/13 21:24:20 peiyongz * 1. returned data to contain datatype in addition to value * 2. registry to map type name (in string) to type name enum * * Revision 1.10 2004/09/09 20:08:31 peiyongz * Using new error code * * Revision 1.9 2004/09/08 19:56:05 peiyongz * Remove parameter toValidate from validation interface * * Revision 1.8 2004/09/08 13:56:09 peiyongz * Apache License Version 2.0 * * Revision 1.7 2004/08/31 20:52:25 peiyongz * Return additional double value for decimal * remove tz_hh/tz_mm * * Revision 1.6 2004/08/31 15:14:47 peiyongz * remove XSValueContext * * Revision 1.5 2004/08/24 15:59:20 peiyongz * using SCHAR_MIN/SCHAR_MAX * * Revision 1.4 2004/08/17 21:11:41 peiyongz * no more Unrepresentable * * Revision 1.3 2004/08/13 21:29:21 peiyongz * fMemAllocated * * Revision 1.2 2004/08/11 17:06:44 peiyongz * Do not panic if can't create RegEx * * $Id: XSValue.cpp,v 1.13 2004/09/28 08:54:34 amassari Exp $ */#include <limits.h>#include <errno.h>#include <xercesc/framework/psvi/XSValue.hpp>#include <xercesc/util/XMLString.hpp>#include <xercesc/util/XMLStringTokenizer.hpp>#include <xercesc/util/XMLBigDecimal.hpp>#include <xercesc/util/XMLBigInteger.hpp>#include <xercesc/util/XMLFloat.hpp>#include <xercesc/util/XMLDouble.hpp>#include <xercesc/util/XMLDateTime.hpp>#include <xercesc/util/HexBin.hpp>#include <xercesc/util/Base64.hpp>#include <xercesc/util/XMLUri.hpp>#include <xercesc/util/XMLChar.hpp>#include <xercesc/util/Janitor.hpp>#include <xercesc/util/XMLRegisterCleanup.hpp>#include <xercesc/util/regx/RegularExpression.hpp>#include <xercesc/validators/schema/SchemaSymbols.hpp>XERCES_CPP_NAMESPACE_BEGIN/*** issues * * 1. For float, double, datetime family, the validation is almost similar to getActualValue * * * DataType DataGroup * num dtm str validation canonical actual-value * ====================================================================================================== * dt_string str [2] Char NA content * dt_boolean str {true, false, 1, 0} {true, false} bool * dt_decimal num lexical only yes double * dt_float num lexical/value yes double * dt_double num lexical/value yes double * --------------------------------------------------------------------------------------------------------- * 5 dt_duration dtm yes NA struct datetime * dt_dateTime dtm yes yes struct datetime * dt_time dtm yes yes struct datetime * dt_date dtm yes NA struct datetime * dt_gYearMonth dtm yes NA struct datetime * --------------------------------------------------------------------------------------------------------- * 10 dt_gYear dtm yes NA struct datetime * dt_gMonthDay dtm yes NA struct datetime * dt_gDay dtm yes NA struct datetime * dt_gMonth dtm yes NA struct datetime * dt_hexBinary str decoding ([a-f]) unsigned long ? * --------------------------------------------------------------------------------------------------------- * 15 dt_base64Binary str decoding NA (errata?) unsigned long ? * dt_anyURI str yes NA content * dt_QName str a:b , [6]QName NA content * dt_NOTATION str [6]QName NA content * dt_normalizedString str no #xD #xA #x9 NA content * --------------------------------------------------------------------------------------------------------- * 20 dt_token str no #xD #xA #x9 traling NA content * dt_language str language id NA content * dt_NMTOKEN str [7] Nmtoken NA content * dt_NMTOKENS str [8] Nmtokens NA content * dt_Name str [5] Name NA content * --------------------------------------------------------------------------------------------------------- * 25 dt_NCName str [4] NCName NA content * dt_ID str [4] NCName NA content * dt_IDREF str [4] NCName NA content * dt_IDREFS str ws seped IDREF NA content * dt_ENTITY str [4] NCName NA content * --------------------------------------------------------------------------------------------------------- * 30 dt_ENTITIES str ws seped ENTITY NA content * dt_integer num lexical yes long * dt_nonPositiveInteger num lexical yes long * dt_negativeInteger num lexical yes long * dt_long num lexical yes long * --------------------------------------------------------------------------------------------------------- * 35 dt_int num lexical yes int * dt_short num lexical yes short * dt_byte num lexical yes char * dt_nonNegativeInteger num lexical yes unsigned long * dt_unsignedLong num lexical yes unsigned long * --------------------------------------------------------------------------------------------------------- * 40 dt_unsignedInt num lexical yes unsigned int * dt_unsignedShort num lexical yes unsigned short * dt_unsignedByte num lexical yes unsigned char * dt_positiveInteger num lexical yes unsigned long * ***/const XSValue::DataGroup XSValue::inGroup[XSValue::dt_MAXCOUNT] = { dg_strings, dg_strings, dg_numerics, dg_numerics, dg_numerics, dg_datetimes, dg_datetimes, dg_datetimes, dg_datetimes, dg_datetimes, dg_datetimes, dg_datetimes, dg_datetimes, dg_datetimes, dg_strings, dg_strings, dg_strings, dg_strings, dg_strings, dg_strings, dg_strings, dg_strings, dg_strings, dg_strings, dg_strings, dg_strings, dg_strings, dg_strings, dg_strings, dg_strings, dg_strings, dg_numerics, dg_numerics, dg_numerics, dg_numerics, dg_numerics, dg_numerics, dg_numerics, dg_numerics, dg_numerics, dg_numerics, dg_numerics, dg_numerics, dg_numerics};// ---------------------------------------------------------------------------// Local static functions// ---------------------------------------------------------------------------static XMLMutex* sXSValueMutext = 0;static XMLRegisterCleanup XSValueMutexCleanup;static RegularExpression* sXSValueRegEx = 0;static XMLRegisterCleanup XSValueRegExCleanup;RefHashTableOf<XSValue>* XSValue::fDataTypeRegistry = 0;static XMLRegisterCleanup XSValueRegistryCleanup;static XMLMutex& gXSValueMutex(){ if (!sXSValueMutext) { XMLMutexLock lockInit(XMLPlatformUtils::fgAtomicMutex); if (!sXSValueMutext) { sXSValueMutext = new XMLMutex; XSValueRegExCleanup.registerCleanup(XSValue::reinitMutex); } } return *sXSValueMutext;}static RegularExpression* getRegEx(){ if (!sXSValueRegEx) { // Lock the mutex XMLMutexLock lockInit(&gXSValueMutex()); if (!sXSValueRegEx) { try { sXSValueRegEx = new (XMLPlatformUtils::fgMemoryManager) RegularExpression( XMLUni::fgLangPattern , SchemaSymbols::fgRegEx_XOption , XMLPlatformUtils::fgMemoryManager ); } catch (...) { return 0; } XSValueRegExCleanup.registerCleanup(XSValue::reinitRegEx); } } return sXSValueRegEx;}XSValue::DataType XSValue::getDataType(const XMLCh* const dtString){ if (!fDataTypeRegistry) { // Lock the mutex XMLMutexLock lockInit(&gXSValueMutex()); if (!fDataTypeRegistry) { try { //using the XMLPlatformUtils::fgMemoryManager fDataTypeRegistry = new RefHashTableOf<XSValue>(43, true, new HashXMLCh() ); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_STRING, new XSValue(dt_string)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_BOOLEAN, new XSValue(dt_boolean)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_DECIMAL, new XSValue(dt_decimal)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_FLOAT, new XSValue(dt_float)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_DOUBLE, new XSValue(dt_double)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_DURATION, new XSValue(dt_duration)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_DATETIME, new XSValue(dt_dateTime)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_TIME, new XSValue(dt_time)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_DATE, new XSValue(dt_date)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_YEARMONTH, new XSValue(dt_gYearMonth)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_YEAR, new XSValue(dt_gYear)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_MONTHDAY, new XSValue(dt_gMonthDay)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_DAY, new XSValue(dt_gDay)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_MONTH, new XSValue(dt_gMonth)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_HEXBINARY, new XSValue(dt_hexBinary)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_BASE64BINARY, new XSValue(dt_base64Binary)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_ANYURI, new XSValue(dt_anyURI)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_QNAME, new XSValue(dt_QName)); fDataTypeRegistry->put((void*) XMLUni::fgNotationString, new XSValue(dt_NOTATION)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_NORMALIZEDSTRING, new XSValue(dt_normalizedString)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_TOKEN, new XSValue(dt_token)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_LANGUAGE, new XSValue(dt_language)); fDataTypeRegistry->put((void*) XMLUni::fgNmTokenString, new XSValue(dt_NMTOKEN)); fDataTypeRegistry->put((void*) XMLUni::fgNmTokensString, new XSValue(dt_NMTOKENS)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_NAME, new XSValue(dt_Name)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_NCNAME, new XSValue(dt_NCName)); fDataTypeRegistry->put((void*) XMLUni::fgIDString, new XSValue(dt_ID)); fDataTypeRegistry->put((void*) XMLUni::fgIDRefString, new XSValue(dt_IDREF)); fDataTypeRegistry->put((void*) XMLUni::fgIDRefsString, new XSValue(dt_IDREFS)); fDataTypeRegistry->put((void*) XMLUni::fgEntityString, new XSValue(dt_ENTITY)); fDataTypeRegistry->put((void*) XMLUni::fgEntitiesString, new XSValue(dt_ENTITIES)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_INTEGER, new XSValue(dt_integer)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_NONPOSITIVEINTEGER, new XSValue(dt_nonPositiveInteger)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_NEGATIVEINTEGER, new XSValue(dt_negativeInteger)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_LONG, new XSValue(dt_long)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_INT, new XSValue(dt_int)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_SHORT, new XSValue(dt_short)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_BYTE, new XSValue(dt_byte)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_NONNEGATIVEINTEGER, new XSValue(dt_nonNegativeInteger)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_ULONG, new XSValue(dt_unsignedLong)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_UINT, new XSValue(dt_unsignedInt)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_USHORT, new XSValue(dt_unsignedShort)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_UBYTE, new XSValue(dt_unsignedByte)); fDataTypeRegistry->put((void*) SchemaSymbols::fgDT_POSITIVEINTEGER, new XSValue(dt_positiveInteger)); } catch (...) { return dt_MAXCOUNT; } XSValueRegistryCleanup.registerCleanup(XSValue::reinitRegistry); } } XSValue* data = fDataTypeRegistry->get(dtString); return data? data->fData.f_datatype : dt_MAXCOUNT;}inlinestatic bool checkTimeZoneError(XSValue::DataType const &datatype , SchemaDateTimeException const &e ){ return (((datatype == XSValue::dt_dateTime) || (datatype == XSValue::dt_time)) && ((e.getCode() == XMLExcepts::DateTime_tz_noUTCsign) || (e.getCode() == XMLExcepts::DateTime_tz_stuffAfterZ) || (e.getCode() == XMLExcepts::DateTime_tz_invalid) || (e.getCode() == XMLExcepts::DateTime_tz_hh_invalid)));}// ---------------------------------------------------------------------------// Local Data// --------------------------------------------------------------------------- static const XMLCh Separator_20[] = {chSpace, chNull};static const XMLCh Separator_ws[] = {chSpace, chLF, chCR, chHTab, chNull};static const int convert_2_long = 1;static const int convert_2_ulong = 2;static const int base_decimal = 10;// ---------------------------------------------------------------------------// XSValue: Constructors and Destructor// ---------------------------------------------------------------------------XSValue::XSValue(DataType const dt , MemoryManager* const manager):fMemAllocated(false),fMemoryManager(manager){ fData.f_datatype = dt;}XSValue::~XSValue(){ if (fMemAllocated) fMemoryManager->deallocate(fData.fValue.f_strVal);} // ---------------------------------------------------------------------------// XSValue: Public Interface//// No exception is thrown from these methods//// ---------------------------------------------------------------------------bool XSValue::validate(const XMLCh* const content , DataType datatype , Status& status , XMLVersion version , MemoryManager* const manager){ if (!content || !*content) { status=st_NoContent; return false; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?