Grammar* GrammarResolver::getGrammar( const XMLCh* const namespaceKey) { if (!namespaceKey) return 0; Grammar* grammar = fGrammarBucket->get(namespaceKey); if (grammar) return grammar; if (fUseCachedGrammar) { grammar = fGrammarFromPool->get(namespaceKey); if (grammar) { return grammar; } else { XMLSchemaDescription* gramDesc = fGrammarPool->createSchemaDescription(namespaceKey); Janitor<XMLGrammarDescription> janName(gramDesc); grammar = fGrammarPool->retrieveGrammar(gramDesc); if (grammar) { fGrammarFromPool->put((void*) grammar->getGrammarDescription()->getGrammarKey(), grammar); } return grammar; } } return 0; }
XMLBigInteger::XMLBigInteger(const XMLCh* const strValue, MemoryManager* const manager) : fSign(0) , fMagnitude(0) , fRawData(0) , fMemoryManager(manager) { if (!strValue) ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_emptyString, fMemoryManager); XMLCh* ret_value = (XMLCh*) fMemoryManager->allocate ( (XMLString::stringLen(strValue) + 1) * sizeof(XMLCh) );//new XMLCh[XMLString::stringLen(strValue)+1]; ArrayJanitor<XMLCh> janName(ret_value, fMemoryManager); parseBigInteger(strValue, ret_value, fSign, fMemoryManager); if (fSign == 0) fMagnitude = XMLString::replicate(XMLUni::fgZeroLenString, fMemoryManager); else fMagnitude = XMLString::replicate(ret_value, fMemoryManager); fRawData = XMLString::replicate(strValue, fMemoryManager); }
int ListDatatypeValidator::getLength(const XMLCh* const content , MemoryManager* const manager) const { BaseRefVectorOf<XMLCh>* tokenVector = XMLString::tokenizeString(content, manager); Janitor<BaseRefVectorOf<XMLCh> > janName(tokenVector); return tokenVector->size(); }
void ListDatatypeValidator::validate( const XMLCh* const content , ValidationContext* const context , MemoryManager* const manager) { setContent(content); BaseRefVectorOf<XMLCh>* tokenVector = XMLString::tokenizeString(content, manager); Janitor<BaseRefVectorOf<XMLCh> > janName(tokenVector); checkContent(tokenVector, content, context, false, manager); }
// --------------------------------------------------------------------------- // XMLTransService: Non-virtual API // --------------------------------------------------------------------------- XMLTranscoder* XMLTransService::makeNewTranscoderFor( const char* const encodingName , XMLTransService::Codes& resValue , const unsigned int blockSize , MemoryManager* const manager) { XMLCh* tmpName = XMLString::transcode(encodingName, manager); ArrayJanitor<XMLCh> janName(tmpName, manager); return makeNewTranscoderFor(tmpName, resValue, blockSize, manager); }
BinFileOutputStream::BinFileOutputStream(const char* const fileName , MemoryManager* const manager) :fSource(0) ,fMemoryManager(manager) { // Transcode the file name and put a janitor on the temp buffer XMLCh* realName = XMLString::transcode(fileName, manager); ArrayJanitor<XMLCh> janName(realName, manager); // Try to open the file fSource = XMLPlatformUtils::openFileToWrite(realName, manager); }
// // Remove all occurrences of './' when it is part of '/./' // // Since it could be '.\' or other combination on windows ( eg, '.'+chYanSign) // we can't make use of patterMatch(). // // void XMLPlatformUtils::removeDotSlash(XMLCh* const path , MemoryManager* const manager) { if ((!path) || (!*path)) return; XMLCh* srcPtr = XMLString::replicate(path, manager); int srcLen = XMLString::stringLen(srcPtr); ArrayJanitor<XMLCh> janName(srcPtr, manager); XMLCh* tarPtr = path; while (*srcPtr) { if ( 3 <= srcLen ) { if ( (isAnySlash(*srcPtr)) && (chPeriod == *(srcPtr+1)) && (isAnySlash(*(srcPtr+2))) ) { // "\.\x" seen // skip the first two, and start from the 3rd, // since "\x" could be another "\." srcPtr+=2; srcLen-=2; } else { *tarPtr++ = *srcPtr++; // eat the current char srcLen--; } } else if ( 1 == srcLen ) { *tarPtr++ = *srcPtr++; } else if ( 2 == srcLen) { *tarPtr++ = *srcPtr++; *tarPtr++ = *srcPtr++; } } *tarPtr = 0; return; }
bool ListDatatypeValidator::valueSpaceCheck(BaseRefVectorOf<XMLCh>* tokenVector , const XMLCh* const enumStr , MemoryManager* const manager) const { DatatypeValidator* theItemTypeDTV = getItemTypeDTV(); BaseRefVectorOf<XMLCh>* enumVector = XMLString::tokenizeString(enumStr, manager); Janitor<BaseRefVectorOf<XMLCh> > janName(enumVector); if (tokenVector->size() != enumVector->size()) return false; for ( unsigned int j = 0; j < tokenVector->size(); j++ ) { if (theItemTypeDTV->compare(tokenVector->elementAt(j), enumVector->elementAt(j), manager) != 0) return false; } return true; }
const XMLCh* VecAttrListImpl::getValue(const char* const name) const { // Temporarily transcode the name for lookup XMLCh* wideName = XMLString::transcode(name, XMLPlatformUtils::fgMemoryManager); ArrayJanitor<XMLCh> janName(wideName, XMLPlatformUtils::fgMemoryManager); // // Search the vector for the attribute with the given name and return // its type. // for (unsigned int index = 0; index < fCount; index++) { const XMLAttr* curElem = fVector->elementAt(index); if (XMLString::equals(curElem->getQName(), wideName)) return curElem->getValue(); } return 0; }
bool GrammarResolver::containsNameSpace( const XMLCh* const nameSpaceKey ) { if (!nameSpaceKey) return false; if (fGrammarBucket->containsKey(nameSpaceKey)) return true; if (fUseCachedGrammar) { if (fGrammarFromPool->containsKey(nameSpaceKey)) return true; // Lastly, need to check in fGrammarPool XMLSchemaDescription* gramDesc = fGrammarPool->createSchemaDescription(nameSpaceKey); Janitor<XMLGrammarDescription> janName(gramDesc); Grammar* grammar = fGrammarPool->retrieveGrammar(gramDesc); if (grammar) return true; } return false; }
/*** * 2.5.1.2 List datatypes * * The canonical-lexical-representation for the ·list· datatype is defined as * the lexical form in which each item in the ·list· has the canonical * lexical representation of its ·itemType·. ***/ const XMLCh* ListDatatypeValidator::getCanonicalRepresentation(const XMLCh* const rawData , MemoryManager* const memMgr , bool toValidate) const { MemoryManager* toUse = memMgr? memMgr : getMemoryManager(); ListDatatypeValidator* temp = (ListDatatypeValidator*) this; temp->setContent(rawData); BaseRefVectorOf<XMLCh>* tokenVector = XMLString::tokenizeString(rawData, toUse); Janitor<BaseRefVectorOf<XMLCh> > janName(tokenVector); if (toValidate) { try { temp->checkContent(tokenVector, rawData, 0, false, toUse); } catch (...) { return 0; } } unsigned int retBufSize = 2 * XMLString::stringLen(rawData); XMLCh* retBuf = (XMLCh*) toUse->allocate(retBufSize * sizeof(XMLCh)); retBuf[0] = 0; XMLCh* retBufPtr = retBuf; DatatypeValidator* itemDv = this->getItemTypeDTV(); try { for (unsigned int i = 0; i < tokenVector->size(); i++) { XMLCh* itemCanRep = (XMLCh*) itemDv->getCanonicalRepresentation(tokenVector->elementAt(i), toUse, false); unsigned int itemLen = XMLString::stringLen(itemCanRep); if(retBufPtr+itemLen+2 >= retBuf+retBufSize) { // need to resize XMLCh * oldBuf = retBuf; retBuf = (XMLCh*) toUse->allocate(retBufSize * sizeof(XMLCh) * 4); memcpy(retBuf, oldBuf, retBufSize * sizeof(XMLCh )); retBufPtr = (retBufPtr - oldBuf) + retBuf; toUse->deallocate(oldBuf); retBufSize <<= 2; } XMLString::catString(retBufPtr, itemCanRep); retBufPtr = retBufPtr + itemLen + 1; *(retBufPtr++) = chSpace; *(retBufPtr) = chNull; toUse->deallocate(itemCanRep); } return retBuf; } catch (...) { return 0; } }
DatatypeValidator* DatatypeValidator::loadDV(XSerializeEngine& serEng) { int flag; serEng>>flag; if (DV_BUILTIN == flag) { XMLCh* dvName; serEng.readString(dvName); ArrayJanitor<XMLCh> janName(dvName, serEng.getMemoryManager()); return DatatypeValidatorFactory::getBuiltInRegistry()->get(dvName); } else if (DV_ZERO == flag) { return 0; } int type; serEng>>type; switch((ValidatorType)type) { case String: StringDatatypeValidator* stringdv; serEng>>stringdv; return stringdv; case AnyURI: AnyURIDatatypeValidator* anyuridv; serEng>>anyuridv; return anyuridv; case QName: QNameDatatypeValidator* qnamedv; serEng>>qnamedv; return qnamedv; case Name: NameDatatypeValidator* namedv; serEng>>namedv; return namedv; case NCName: NCNameDatatypeValidator* ncnamedv; serEng>>ncnamedv; return ncnamedv; case Boolean: BooleanDatatypeValidator* booleandv; serEng>>booleandv; return booleandv; case Float: FloatDatatypeValidator* floatdv; serEng>>floatdv; return floatdv; case Double: DoubleDatatypeValidator* doubledv; serEng>>doubledv; return doubledv; case Decimal: DecimalDatatypeValidator* decimaldv; serEng>>decimaldv; return decimaldv; case HexBinary: HexBinaryDatatypeValidator* hexbinarydv; serEng>>hexbinarydv; return hexbinarydv; case Base64Binary: Base64BinaryDatatypeValidator* base64binarydv; serEng>>base64binarydv; return base64binarydv; case Duration: DurationDatatypeValidator* durationdv; serEng>>durationdv; return durationdv; case DateTime: DateTimeDatatypeValidator* datetimedv; serEng>>datetimedv; return datetimedv; case Date: DateDatatypeValidator* datedv; serEng>>datedv; return datedv; case Time: TimeDatatypeValidator* timedv; serEng>>timedv; return timedv; case MonthDay: MonthDayDatatypeValidator* monthdaydv; serEng>>monthdaydv; return monthdaydv; case YearMonth: YearMonthDatatypeValidator* yearmonthdv; serEng>>yearmonthdv; return yearmonthdv; case Year: YearDatatypeValidator* yeardv; serEng>>yeardv; return yeardv; case Month: MonthDatatypeValidator* monthdv; serEng>>monthdv; return monthdv; case Day: DayDatatypeValidator* daydv; serEng>>daydv; return daydv; case ID: IDDatatypeValidator* iddv; serEng>>iddv; return iddv; case IDREF: IDREFDatatypeValidator* idrefdv; serEng>>idrefdv; return idrefdv; case ENTITY: ENTITYDatatypeValidator* entitydv; serEng>>entitydv; return entitydv; case NOTATION: NOTATIONDatatypeValidator* notationdv; serEng>>notationdv; return notationdv; case List: ListDatatypeValidator* listdv; serEng>>listdv; return listdv; case Union: UnionDatatypeValidator* uniondv; serEng>>uniondv; return uniondv; case AnySimpleType: AnySimpleTypeDatatypeValidator* anysimpletypedv; serEng>>anysimpletypedv; return anysimpletypedv; case UnKnown: return 0; default: //we treat this same as UnKnown return 0; } }
void DatatypeValidator::serialize(XSerializeEngine& serEng) { if (serEng.isStoring()) { serEng<<fAnonymous; serEng<<fFinite; serEng<<fBounded; serEng<<fNumeric; serEng<<fWhiteSpace; serEng<<fFinalSet; serEng<<fFacetsDefined; serEng<<fFixed; serEng<<(int)fType; serEng<<(int)fOrdered; storeDV(serEng, fBaseValidator); /*** * Serialize RefHashTableOf<KVStringPair> ***/ XTemplateSerializer::storeObject(fFacets, serEng); serEng.writeString(fPattern); if (fTypeUri==XMLUni::fgZeroLenString) { serEng<<TYPENAME_ZERO; } else if (fTypeUri == SchemaSymbols::fgURI_SCHEMAFORSCHEMA) { serEng<<TYPENAME_S4S; serEng.writeString(fTypeLocalName); } else { serEng<<TYPENAME_NORMAL; serEng.writeString(fTypeLocalName); serEng.writeString(fTypeUri); } /*** * don't serialize * fRegex ***/ } else { serEng>>fAnonymous; serEng>>fFinite; serEng>>fBounded; serEng>>fNumeric; serEng>>fWhiteSpace; serEng>>fFinalSet; serEng>>fFacetsDefined; serEng>>fFixed; int type; serEng>>type; fType=(ValidatorType)type; serEng>>type; fOrdered = (XSSimpleTypeDefinition::ORDERING)type; fBaseValidator = loadDV(serEng); /*** * * Deserialize RefHashTableOf<KVStringPair> * ***/ XTemplateSerializer::loadObject(&fFacets, 29, true, serEng); serEng.readString(fPattern); /*** * Recreate through setTypeName() * fTypeName ***/ int flag; serEng>>flag; if ( TYPENAME_ZERO == flag ) { setTypeName(0); } else if ( TYPENAME_S4S == flag ) { XMLCh* typeLocalName; serEng.readString(typeLocalName); ArrayJanitor<XMLCh> janName(typeLocalName, fMemoryManager); setTypeName(typeLocalName); } else // TYPENAME_NORMAL { XMLCh* typeLocalName; serEng.readString(typeLocalName); ArrayJanitor<XMLCh> janName(typeLocalName, fMemoryManager); XMLCh* typeUri; serEng.readString(typeUri); ArrayJanitor<XMLCh> janUri(typeUri, fMemoryManager); setTypeName(typeLocalName, typeUri); } /*** * don't serialize fRegex ***/ fRegex = new (fMemoryManager) RegularExpression(fPattern, SchemaSymbols::fgRegEx_XOption, fMemoryManager); } }
/*** * 3.2.3 decimal * * . the preceding optional "+" sign is prohibited. * . The decimal point is required. * . Leading and trailing zeroes are prohibited subject to the following: * there must be at least one digit to the right and to the left of the decimal point which may be a zero. * ***/ XMLCh* XMLBigDecimal::getCanonicalRepresentation(const XMLCh* const rawData , MemoryManager* const memMgr) { try { XMLCh* retBuf = (XMLCh*) memMgr->allocate( (XMLString::stringLen(rawData)+1) * sizeof(XMLCh)); ArrayJanitor<XMLCh> janName(retBuf, memMgr); int sign, totalDigits, fractDigits; XMLBigDecimal::parseDecimal(rawData, retBuf, sign, totalDigits, fractDigits, memMgr); //Extra space reserved in case strLen is zero int strLen = XMLString::stringLen(retBuf); XMLCh* retBuffer = (XMLCh*) memMgr->allocate( (strLen + 4) * sizeof(XMLCh)); if ( (sign == 0) || (totalDigits == 0)) { retBuffer[0] = chDigit_0; retBuffer[1] = chPeriod; retBuffer[2] = chDigit_0; retBuffer[3] = chNull; } else { XMLCh* retPtr = retBuffer; if (sign == -1) { *retPtr++ = chDash; } if (fractDigits == totalDigits) // no integer { *retPtr++ = chDigit_0; *retPtr++ = chPeriod; XMLString::copyNString(retPtr, retBuf, strLen); retPtr += strLen; *retPtr = chNull; } else if (fractDigits == 0) // no fraction { XMLString::copyNString(retPtr, retBuf, strLen); retPtr += strLen; *retPtr++ = chPeriod; *retPtr++ = chDigit_0; *retPtr = chNull; } else // normal { int intLen = totalDigits - fractDigits; XMLString::copyNString(retPtr, retBuf, intLen); retPtr += intLen; *retPtr++ = chPeriod; XMLString::copyNString(retPtr, &(retBuf[intLen]), fractDigits); retPtr += fractDigits; *retPtr = chNull; } } return retBuffer; }//try catch (...) { return 0; } }
void DatatypeValidator::serialize(XSerializeEngine& serEng) { if (serEng.isStoring()) { serEng<<fAnonymous; serEng<<fWhiteSpace; serEng<<fFinalSet; serEng<<fFacetsDefined; serEng<<fFixed; serEng<<(int)fType; serEng<<(int)fOrdered; serEng<<fFinite; serEng<<fBounded; serEng<<fNumeric; /*** * don't serialize the fBaseValidator if it is a built-in ***/ if (isBuiltInDV(fBaseValidator)) { serEng<<true; serEng.writeString(fBaseValidator->getTypeName()); } else { serEng<<false; storeDV(serEng, fBaseValidator); } /*** * Serialize RefHashTableOf<KVStringPair> ***/ XTemplateSerializer::storeObject(fFacets, serEng); serEng.writeString(fPattern); /*** * don't serialize * fRegex * fTypeLocalName * fTypeUri ***/ serEng.writeString(fTypeName); } else { serEng>>fAnonymous; serEng>>fWhiteSpace; serEng>>fFinalSet; serEng>>fFacetsDefined; serEng>>fFixed; int type; serEng>>type; fType=(ValidatorType)type; serEng>>type; fOrdered = (XSSimpleTypeDefinition::ORDERING)type; serEng>>fFinite; serEng>>fBounded; serEng>>fNumeric; /*** * * get the basevalidator's type * ***/ bool isBuiltInDV = false; serEng>>isBuiltInDV; if (isBuiltInDV) { XMLCh* baseTypeName; serEng.readString(baseTypeName); ArrayJanitor<XMLCh> janName(baseTypeName, fMemoryManager); /*** * Link to the fBuiltInRegistry * * Since DatatypeValidatorFactory is always the first one * to be deserialized in SchemaGrammar, we are sure that * the BuiltInRegistry shall be available now. ***/ fBaseValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(baseTypeName); } else { fBaseValidator = loadDV(serEng); } /*** * * Deserialize RefHashTableOf<KVStringPair> * ***/ XTemplateSerializer::loadObject(&fFacets, 29, true, serEng); serEng.readString(fPattern); /*** * don't serialize fRegex ***/ fRegex = 0; /*** * Recreate through setTypeName() * fTypeName * fTypeLocalName * fTypeUri ***/ XMLCh* typeName; serEng.readString(typeName); ArrayJanitor<XMLCh> janName(typeName, fMemoryManager); setTypeName(typeName); } }