Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
bool unknown = false;
prefixBuf.reset();
return fElemStack.mapPrefixToURI(XMLUni::fgZeroLenString, (ElemStack::MapModes) mode, unknown);
}
else
{
// Copy the chars up to but not including the colon into the prefix
// buffer.
prefixBuf.set(qName, prefixColonPos);
// Watch for the special namespace prefixes. We always map these to
// special URIs. 'xml' gets mapped to the official URI that its defined
// to map to by the NS spec. xmlns gets mapped to a special place holder
// URI that we define (so that it maps to something checkable.)
const XMLCh* prefixRawBuf = prefixBuf.getRawBuffer();
if (XMLString::equals(prefixRawBuf, XMLUni::fgXMLNSString)) {
// if this is an element, it is an error to have xmlns as prefix
if (mode == ElemStack::Mode_Element)
emitError(XMLErrs::NoXMLNSAsElementPrefix, qName);
return fXMLNSNamespaceId;
}
else if (XMLString::equals(prefixRawBuf, XMLUni::fgXMLString)) {
return fXMLNamespaceId;
}
else
{
bool unknown = false;
unsigned int uriId = fElemStack.mapPrefixToURI(prefixRawBuf, (ElemStack::MapModes) mode, unknown);
if (unknown)
emitError(XMLErrs::UnknownPrefix, prefixRawBuf);
return uriId;
}
}
}
// ---------------------------------------------------------------------------
// SGXMLScanner: IC activation methos
// ---------------------------------------------------------------------------
void SGXMLScanner::activateSelectorFor(IdentityConstraint* const ic, const int initialDepth) {
IC_Selector* selector = ic->getSelector();
if (!selector)
return;
XPathMatcher* matcher = selector->createMatcher
(
fFieldActivator
, initialDepth
, fMemoryManager
);
fMatcherStack->addMatcher(matcher);
matcher->startDocumentFragment();
}
// ---------------------------------------------------------------------------
// SGXMLScanner: Grammar preparsing
// ---------------------------------------------------------------------------
Grammar* SGXMLScanner::loadGrammar(const InputSource& src
, const short grammarType
, const bool toCache)
{
Grammar* loadedGrammar = 0;
try
{
fGrammarResolver->cacheGrammarFromParse(false);
Alberto Massari
committed
// if the new grammar has to be cached, better use the already cached
// grammars, or the an exception will be thrown when caching an already
// cached grammar
fGrammarResolver->useCachedGrammarInParse(toCache);
fRootGrammar = 0;
if (fValScheme == Val_Auto) {
fValidate = true;
}
// Reset some status flags
fInException = false;
fStandalone = false;
fErrorCount = 0;
fHasNoDTD = true;
fSeeXsi = false;
if (grammarType == Grammar::SchemaGrammarType) {
loadedGrammar = loadXMLSchemaGrammar(src, toCache);
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
}
// Reset the reader manager to close all files, sockets, etc...
fReaderMgr.reset();
}
// NOTE:
//
// In all of the error processing below, the emitError() call MUST come
// before the flush of the reader mgr, or it will fail because it tries
// to find out the position in the XML source of the error.
catch(const XMLErrs::Codes)
{
// This is a 'first fatal error' type exit, so reset and fall through
fReaderMgr.reset();
}
catch(const XMLValid::Codes)
{
// This is a 'first fatal error' type exit, so reset and fall through
fReaderMgr.reset();
}
catch(const XMLException& excToCatch)
{
// Emit the error and catch any user exception thrown from here. Make
// sure in all cases we flush the reader manager.
fInException = true;
try
{
if (excToCatch.getErrorType() == XMLErrorReporter::ErrType_Warning)
emitError
(
XMLErrs::DisplayErrorMessage
, excToCatch.getMessage()
);
else if (excToCatch.getErrorType() >= XMLErrorReporter::ErrType_Fatal)
emitError
(
XMLErrs::XMLException_Fatal
, excToCatch.getType()
, excToCatch.getMessage()
);
else
emitError
(
XMLErrs::XMLException_Error
, excToCatch.getType()
, excToCatch.getMessage()
);
}
Neil Graham
committed
catch(const OutOfMemoryException&)
{
throw;
}
catch(...)
{
// Flush the reader manager and rethrow user's error
fReaderMgr.reset();
throw;
}
// If it returned, then reset the reader manager and fall through
fReaderMgr.reset();
}
Neil Graham
committed
catch(const OutOfMemoryException&)
{
throw;
}
catch(...)
{
// Reset and rethrow
fReaderMgr.reset();
throw;
}
return loadedGrammar;
}
// ---------------------------------------------------------------------------
// SGXMLScanner: Private helper methods
// ---------------------------------------------------------------------------
// This method handles the common initialization, to avoid having to do
// it redundantly in multiple constructors.
void SGXMLScanner::commonInit()
{
// Create the element state array
fElemState = (unsigned int*) fMemoryManager->allocate
(
fElemStateSize * sizeof(unsigned int)
); //new unsigned int[fElemStateSize];
// And we need one for the raw attribute scan. This just stores key/
// value string pairs (prior to any processing.)
fRawAttrList = new (fMemoryManager) RefVectorOf<KVStringPair>(32, true, fMemoryManager);
fSchemaGrammar = new (fGrammarPoolMemoryManager) SchemaGrammar(fGrammarPoolMemoryManager);
fSchemaValidator = new (fMemoryManager) SchemaValidator(0, fMemoryManager);
initValidator(fSchemaValidator);
// Create IdentityConstraint info
fMatcherStack = new (fMemoryManager) XPathMatcherStack(fMemoryManager);
fValueStoreCache = new (fMemoryManager) ValueStoreCache(fMemoryManager);
fFieldActivator = new (fMemoryManager) FieldActivator(fValueStoreCache, fMatcherStack, fMemoryManager);
fValueStoreCache->setScanner(this);
// Add the default entity entries for the character refs that must always
// be present.
fEntityTable = new (fMemoryManager) ValueHashTableOf<XMLCh>(11, fMemoryManager);
fEntityTable->put((void*) XMLUni::fgAmp, chAmpersand);
fEntityTable->put((void*) XMLUni::fgLT, chOpenAngle);
fEntityTable->put((void*) XMLUni::fgGT, chCloseAngle);
fEntityTable->put((void*) XMLUni::fgQuot, chDoubleQuote);
fEntityTable->put((void*) XMLUni::fgApos, chSingleQuote);
Neil Graham
committed
fElemNonDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(29, true, 128, fMemoryManager);
fAttDefRegistry = new (fMemoryManager) RefHashTableOf<unsigned int>
(
131, false, new (fMemoryManager)HashPtr(), fMemoryManager
);
fUndeclaredAttrRegistryNS = new (fMemoryManager) RefHash2KeysTableOf<unsigned int>
(
131, false, new (fMemoryManager)HashXMLCh(), fMemoryManager
fPSVIAttrList = new (fMemoryManager) PSVIAttributeList(fMemoryManager);
fMemoryManager->deallocate(fElemState); //delete [] fElemState;
delete fSchemaGrammar;
delete fEntityTable;
delete fRawAttrList;
delete fSchemaValidator;
delete fFieldActivator;
delete fMatcherStack;
delete fValueStoreCache;
Neil Graham
committed
delete fElemNonDeclPool;
delete fAttDefRegistry;
delete fUndeclaredAttrRegistryNS;
}
void SGXMLScanner::resizeElemState() {
unsigned int newSize = fElemStateSize * 2;
unsigned int* newElemState = (unsigned int*) fMemoryManager->allocate
(
newSize * sizeof(unsigned int)
); //new unsigned int[newSize];
// Copy the existing values
unsigned int index = 0;
for (; index < fElemStateSize; index++)
newElemState[index] = fElemState[index];
for (; index < newSize; index++)
newElemState[index] = 0;
// Delete the old array and udpate our members
fMemoryManager->deallocate(fElemState); //delete [] fElemState;
fElemState = newElemState;
fElemStateSize = newSize;
}
// This method is called from scanStartTag() to build up the list of
// XMLAttr objects that will be passed out in the start tag callout. We
// get the key/value pairs from the raw scan of explicitly provided attrs,
// which have not been normalized. And we get the element declaration from
// which we will get any defaulted or fixed attribute defs and add those
// in as well.
unsigned int
SGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs
, const unsigned int attCount
, XMLElementDecl* elemDecl
, RefVectorOf<XMLAttr>& toFill)
{
// Ask the element to clear the 'provided' flag on all of the att defs
// that it owns, and to return us a boolean indicating whether it has
// any defs.
Neil Graham
committed
ComplexTypeInfo *currType = (fValidate)
?((SchemaValidator*)fValidator)->getCurrentTypeInfo()
:0;
const bool hasDefs = (currType && fValidate)
? currType->resetDefs()
: elemDecl->resetDefs();
fElemCount++;
// If there are no expliclitily provided attributes and there are no
// defined attributes for the element, the we don't have anything to do.
// So just return zero in this case.
if (!hasDefs && !attCount)
return 0;
// PSVI handling
if(getPSVIHandler())
fPSVIAttrList->reset();
PSVIItem::VALIDITY_STATE attrValid = PSVIItem::VALIDITY_VALID;
PSVIItem::ASSESSMENT_TYPE attrAssessed = PSVIItem::VALIDATION_FULL;
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
// Keep up with how many attrs we end up with total
unsigned int retCount = 0;
// And get the current size of the output vector. This lets us use
// existing elements until we fill it, then start adding new ones.
const unsigned int curAttListSize = toFill.size();
// We need a buffer into which raw scanned attribute values will be
// normalized.
XMLBufBid bbNormal(&fBufMgr);
XMLBuffer& normBuf = bbNormal.getBuffer();
// Loop through our explicitly provided attributes, which are in the raw
// scanned form, and build up XMLAttr objects.
unsigned int index;
for (index = 0; index < attCount; index++)
{
const KVStringPair* curPair = providedAttrs.elementAt(index);
// We have to split the name into its prefix and name parts. Then
// we map the prefix to its URI.
const XMLCh* const namePtr = curPair->getKey();
ArrayJanitor <XMLCh> janName(0);
// use a stack-based buffer when possible.
XMLCh tempBuffer[100];
const int colonInd = XMLString::indexOf(namePtr, chColon);
const XMLCh* prefPtr = XMLUni::fgZeroLenString;
const XMLCh* suffPtr = XMLUni::fgZeroLenString;
if (colonInd != -1)
{
// We have to split the string, so make a copy.
if (XMLString::stringLen(namePtr) < sizeof(tempBuffer) / sizeof(tempBuffer[0]))
{
XMLString::copyString(tempBuffer, namePtr);
tempBuffer[colonInd] = chNull;
prefPtr = tempBuffer;
}
else
{
janName.reset(XMLString::replicate(namePtr, fMemoryManager), fMemoryManager);
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
janName[colonInd] = chNull;
prefPtr = janName.get();
}
suffPtr = prefPtr + colonInd + 1;
}
else
{
// No colon, so we just have a name with no prefix
suffPtr = namePtr;
}
// Map the prefix to a URI id. We tell him that we are mapping an
// attr prefix, so any xmlns attrs at this level will not affect it.
const unsigned int uriId = resolvePrefix(prefPtr, ElemStack::Mode_Attribute);
// If the uri comes back as the xmlns or xml URI or its just a name
// and that name is 'xmlns', then we handle it specially. So set a
// boolean flag that lets us quickly below know which we are dealing
// with.
const bool isNSAttr = (uriId == fXMLNSNamespaceId)
|| (uriId == fXMLNamespaceId)
|| XMLString::equals(suffPtr, XMLUni::fgXMLNSString)
|| XMLString::equals(getURIText(uriId), SchemaSymbols::fgURI_XSI);
// If its not a special case namespace attr of some sort, then we
// do normal checking and processing.
XMLAttDef::AttTypes attType;
DatatypeValidator *attrValidator = 0;
if (!isNSAttr)
{
// Some checking for attribute wild card first (for schema)
bool laxThisOne = false;
bool skipThisOne = false;
XMLAttDef* attDefForWildCard = 0;
XMLAttDef* attDef = 0;
if (fGrammarType == Grammar::SchemaGrammarType && currType) {
attDef = currType->getAttDef(suffPtr, uriId);
// if not found or faulted in - check for a matching wildcard attribute
// if no matching wildcard attribute, check (un)qualifed cases and flag
// appropriate errors
if (!attDef || (attDef->getCreateReason() == XMLAttDef::JustFaultIn)) {
SchemaAttDef* attWildCard = currType->getAttWildCard();
if(!attWildCard)
// check explicitly-set wildcard
attWildCard = ((SchemaElementDecl*)elemDecl)->getAttWildCard();
if (attWildCard) {
//if schema, see if we should lax or skip the validation of this attribute
if (anyAttributeValidation(attWildCard, uriId, skipThisOne, laxThisOne)) {
Neil Graham
committed
if(!skipThisOne)
{
SchemaGrammar* sGrammar = (SchemaGrammar*) fGrammarResolver->getGrammar(getURIText(uriId));
if (sGrammar && sGrammar->getGrammarType() == Grammar::SchemaGrammarType) {
RefHashTableOf<XMLAttDef>* attRegistry = sGrammar->getAttributeDeclRegistry();
if (attRegistry) {
attDefForWildCard = attRegistry->get(suffPtr);
}
}
}
}
}
else {
// not found, see if the attDef should be qualified or not
if (uriId == fEmptyNamespaceId) {
attDef = currType->getAttDef(suffPtr, fURIStringPool->getId(fGrammar->getTargetNamespace()));
if (fValidate
&& attDef
&& attDef->getCreateReason() != XMLAttDef::JustFaultIn) {
// the attribute should be qualified
fValidator->emitError
(
XMLValid::AttributeNotQualified
, attDef->getFullName()
);
Gareth Reakes
committed
((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::INVALID);
fPSVIElemContext.fErrorOccurred = true;
if (getPSVIHandler())
{
attDef = currType->getAttDef(suffPtr, fEmptyNamespaceId);
if (fValidate
&& attDef
&& attDef->getCreateReason() != XMLAttDef::JustFaultIn) {
// the attribute should be qualified
fValidator->emitError
(
XMLValid::AttributeNotUnQualified
, attDef->getFullName()
);
Gareth Reakes
committed
((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::INVALID);
fPSVIElemContext.fErrorOccurred = true;
if (getPSVIHandler())
{
// now need to prepare for duplicate detection
if(attDef)
{
unsigned int *curCountPtr = fAttDefRegistry->get(attDef);
if(!curCountPtr)
{
curCountPtr = getNewUIntPtr();
*curCountPtr = fElemCount;
fAttDefRegistry->put(attDef, curCountPtr);
}
else if(*curCountPtr < fElemCount)
*curCountPtr = fElemCount;
else
{
emitError
(
XMLErrs::AttrAlreadyUsedInSTag
, attDef->getFullName()
, elemDecl->getFullName()
);
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
}
}
else
{
unsigned int *curCountPtr = fUndeclaredAttrRegistryNS->get(suffPtr, uriId);
if(!curCountPtr)
{
curCountPtr = getNewUIntPtr();
*curCountPtr = fElemCount;
fUndeclaredAttrRegistryNS->put((void *)suffPtr, uriId, curCountPtr);
}
else if(*curCountPtr < fElemCount)
*curCountPtr = fElemCount;
else
{
emitError
(
XMLErrs::AttrAlreadyUsedInSTag
, namePtr
, elemDecl->getFullName()
);
}
}
if(!skipThisOne && fGrammarType == Grammar::SchemaGrammarType && attDef) {
Gareth Reakes
committed
//we may have set it to invalid already, but this is the first time we are guarenteed to have the attDef
if(((SchemaAttDef *)(attDef))->getValidity() != PSVIDefs::INVALID)
{
((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::VALID);
}
Gareth Reakes
committed
((SchemaAttDef *)(attDef))->setValidationAttempted(PSVIDefs::FULL);
// if we've found either an attDef or an attDefForWildCard,
// then we're doing full validation and it may still be valid.
if(!attDef && !attDefForWildCard)
if(!laxThisOne && !skipThisOne)
{
fPSVIElemContext.fErrorOccurred = true;
}
if(getPSVIHandler())
else if(laxThisOne)
{
attrValid = PSVIItem::VALIDITY_NOTKNOWN;
attrAssessed = PSVIItem::VALIDATION_PARTIAL;
}
else
{
attrValid = PSVIItem::VALIDITY_NOTKNOWN;
attrAssessed = PSVIItem::VALIDATION_NONE;
}
Gareth Reakes
committed
}
bool errorCondition = fValidate && !attDefForWildCard && !attDef;
Gareth Reakes
committed
if (errorCondition && !skipThisOne && !laxThisOne)
{
//
// Its not valid for this element, so issue an error if we are
// validating.
//
XMLBufBid bbMsg(&fBufMgr);
XMLBuffer& bufMsg = bbMsg.getBuffer();
if (uriId != fEmptyNamespaceId) {
XMLBufBid bbURI(&fBufMgr);
XMLBuffer& bufURI = bbURI.getBuffer();
getURIText(uriId, bufURI);
bufMsg.append(chOpenCurly);
bufMsg.append(bufURI.getRawBuffer());
bufMsg.append(chCloseCurly);
}
bufMsg.append(suffPtr);
fValidator->emitError
(
XMLValid::AttNotDefinedForElement
, bufMsg.getRawBuffer()
, elemDecl->getFullName()
);
if(attDef)
((SchemaAttDef *)attDef)->setValidity(PSVIDefs::INVALID);
Gareth Reakes
committed
}
else if(errorCondition && laxThisOne && attDef) {
Gareth Reakes
committed
((SchemaAttDef *)(attDef))->setValidationAttempted(PSVIDefs::NONE);
((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::UNKNOWN);
}
// Now normalize the raw value since we have the attribute type. We
// don't care about the return status here. If it failed, an error
// was issued, which is all we care about.
if (attDefForWildCard) {
if(attDef)
((SchemaAttDef*)attDef)->setAnyDatatypeValidator(((SchemaAttDef*) attDefForWildCard)->getDatatypeValidator());
, namePtr
, curPair->getValue()
, normBuf
);
// If we found an attdef for this one, then lets validate it.
if (fNormalizeData)
{
DatatypeValidator* tempDV = ((SchemaAttDef*) attDefForWildCard)->getDatatypeValidator();
if (tempDV && tempDV->getWSFacet() != DatatypeValidator::PRESERVE)
{
// normalize the attribute according to schema whitespace facet
XMLBufBid bbtemp(&fBufMgr);
XMLBuffer& tempBuf = bbtemp.getBuffer();
((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, normBuf.getRawBuffer(), tempBuf);
normBuf.set(tempBuf.getRawBuffer());
}
Neil Graham
committed
if (fValidate ) {
fValidator->validateAttrValue
(
attDefForWildCard
, normBuf.getRawBuffer()
, false
, elemDecl
);
attrValidator = ((SchemaValidator *)fValidator)->getMostRecentAttrValidator();
if(((SchemaValidator *)fValidator)->getErrorOccurred())
{
fPSVIElemContext.fErrorOccurred = true;
if(getPSVIHandler())
attrValid = PSVIItem::VALIDITY_INVALID;
else // no decl; default DOMTypeInfo to anySimpleType
attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYSIMPLETYPE);
// Save the type for later use
attType = attDefForWildCard->getType();
Gareth Reakes
committed
if(attDef)
((SchemaElementDecl *)(elemDecl))->updateValidityFromAttribute((SchemaAttDef *)attDef);
Gareth Reakes
committed
DatatypeValidator* tempDV = ((SchemaAttDef*) attDefForWildCard)->getDatatypeValidator();
if(tempDV && tempDV->getType() == DatatypeValidator::Union && attDef)
((SchemaAttDef*)attDef)->setMembertypeValidator(attrValidator);
}
else {
normalizeAttValue
(
attDef
, namePtr
, curPair->getValue()
, normBuf
);
// If we found an attdef for this one, then lets validate it.
if (attDef)
{
if (fNormalizeData && (fGrammarType == Grammar::SchemaGrammarType))
{
DatatypeValidator* tempDV = ((SchemaAttDef*) attDef)->getDatatypeValidator();
if (tempDV && tempDV->getWSFacet() != DatatypeValidator::PRESERVE)
{
// normalize the attribute according to schema whitespace facet
XMLBufBid bbtemp(&fBufMgr);
XMLBuffer& tempBuf = bbtemp.getBuffer();
((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, normBuf.getRawBuffer(), tempBuf);
normBuf.set(tempBuf.getRawBuffer());
}
}
if (fValidate && !skipThisOne)
{
fValidator->validateAttrValue
(
attDef
, normBuf.getRawBuffer()
, false
, elemDecl
);
attrValidator = ((SchemaValidator *)fValidator)->getMostRecentAttrValidator();
if(((SchemaValidator *)fValidator)->getErrorOccurred())
{
fPSVIElemContext.fErrorOccurred = true;
if(getPSVIHandler())
attrValid = PSVIItem::VALIDITY_INVALID;
else
attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYSIMPLETYPE);
else
attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYSIMPLETYPE);
attType = (attDef)?attDef->getType():XMLAttDef::CData;
if(attDef)
{
((SchemaElementDecl *)(elemDecl))->updateValidityFromAttribute((SchemaAttDef *)attDef);
}
// now fill in the PSVIAttributes entry for this attribute:
if(getPSVIHandler())
{
SchemaAttDef *actualAttDef = 0;
if(attDef)
actualAttDef = (SchemaAttDef *)attDef;
else if (attDefForWildCard)
actualAttDef = (SchemaAttDef *)attDefForWildCard;
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
if(actualAttDef)
{
XSAttributeDeclaration *attrDecl = (XSAttributeDeclaration *)fModel->getXSObject(actualAttDef);
PSVIAttribute *toFill = fPSVIAttrList->getPSVIAttributeToFill();
DatatypeValidator * attrDataType = actualAttDef->getDatatypeValidator();
XSSimpleTypeDefinition *validatingType = (XSSimpleTypeDefinition *)fModel->getXSObject(attrDataType);
if(attrValid != PSVIItem::VALIDITY_VALID)
{
toFill->reset(
fRootElemName
, attrValid
, attrAssessed
, normBuf.getRawBuffer()
, validatingType
, 0
, actualAttDef->getValue()
, false
, attrDecl
, 0
);
}
else
{
XSSimpleTypeDefinition *memberType = 0;
if(validatingType->getVariety() == XSSimpleTypeDefinition::VARIETY_UNION)
memberType = (XSSimpleTypeDefinition *)fModel->getXSObject(attrValidator);
toFill->reset(
fRootElemName
, attrValid
, attrAssessed
, normBuf.getRawBuffer()
, validatingType
, memberType
, actualAttDef->getValue()
, false
, attrDecl
, (memberType)?attrValidator:attrDataType
);
}
}
}
else
{
// Just normalize as CDATA
attType = XMLAttDef::CData;
normalizeAttRawValue
(
namePtr
if((uriId == fXMLNSNamespaceId)
|| XMLString::equals(getURIText(uriId), SchemaSymbols::fgURI_XSI))
attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYURI);
PSVIAttribute *toFill = fPSVIAttrList->getPSVIAttributeToFill();
XSSimpleTypeDefinition *validatingType = (attrValidator)
? (XSSimpleTypeDefinition *)fModel->getXSObject(attrValidator)
: 0;
// no attribute declarations for these...
toFill->reset(
fRootElemName
, PSVIItem::VALIDITY_NOTKNOWN
, PSVIItem::VALIDATION_NONE
, normBuf.getRawBuffer()
, validatingType
, 0
, 0
, false
, 0
, attrValidator
}
// Add this attribute to the attribute list that we use to pass them
// to the handler. We reuse its existing elements but expand it as
// required.
XMLAttr* curAttr;
if (retCount >= curAttListSize)
{
curAttr = new (fMemoryManager) XMLAttr
(
uriId
, suffPtr
, prefPtr
, normBuf.getRawBuffer()
, attType
, true
, fMemoryManager
, attrValidator
, true
);
toFill.addElement(curAttr);
}
else
{
curAttr = toFill.elementAt(retCount);
curAttr->set
(
uriId
, suffPtr
, prefPtr
, normBuf.getRawBuffer()
, attType
, attrValidator
, true
);
curAttr->setSpecified(true);
}
// Bump the count of attrs in the list
retCount++;
}
// Now, if there are any attributes declared by this element, let's
// go through them and make sure that any required ones are provided,
// and fault in any fixed ones and defaulted ones that are not provided
// literally.
if (hasDefs)
{
// Check after all specified attrs are scanned
// (1) report error for REQUIRED attrs that are missing (V_TAGc)
// (2) add default attrs if missing (FIXED and NOT_FIXED)
XMLAttDefList& attDefList = getAttDefList(currType, elemDecl);
Neil Graham
committed
for(unsigned int i=0; i<attDefList.getAttDefCount(); i++)
{
// Get the current att def, for convenience and its def type
XMLAttDef *curDef = &attDefList.getAttDef(i);
Gareth Reakes
committed
const XMLAttDef::DefAttTypes defType = curDef->getDefaultType();
unsigned int *attCountPtr = fAttDefRegistry->get(curDef);
if (!attCountPtr || *attCountPtr < fElemCount)
{ // did not occur
Gareth Reakes
committed
((SchemaAttDef *)curDef)->setValidationAttempted(PSVIDefs::FULL);
((SchemaAttDef *)curDef)->setValidity(PSVIDefs::VALID);
// note that since there is no attribute information
// item present, there is no PSVI infoset to augment here *except*
// that the element is invalid
Gareth Reakes
committed
//the attribute is not provided
if (fValidate)
{
// If we are validating and its required, then an error
if ((defType == XMLAttDef::Required) ||
(defType == XMLAttDef::Required_And_Fixed) )
{
fValidator->emitError
(
XMLValid::RequiredAttrNotProvided
Gareth Reakes
committed
, curDef->getFullName()
Gareth Reakes
committed
((SchemaAttDef *)(curDef))->setValidity(PSVIDefs::INVALID);
}
else if ((defType == XMLAttDef::Default) ||
(defType == XMLAttDef::Fixed) )
{
Gareth Reakes
committed
if (fStandalone && curDef->isExternal())
{
// XML 1.0 Section 2.9
// Document is standalone, so attributes must not be defaulted.
Gareth Reakes
committed
fValidator->emitError(XMLValid::NoDefAttForStandalone, curDef->getFullName(), elemDecl->getFullName());
((SchemaAttDef *)(curDef))->setValidity(PSVIDefs::INVALID);
}
}
}
// Fault in the value if needed, and bump the att count.
if ((defType == XMLAttDef::Default)
|| (defType == XMLAttDef::Fixed))
{
// Let the validator pass judgement on the attribute value
if (fValidate)
{
fValidator->validateAttrValue
(
Gareth Reakes
committed
curDef
, curDef->getValue()
, false
, elemDecl
);
}
XMLAttr* curAtt;
if (retCount >= curAttListSize)
{
curAtt = new (fMemoryManager) XMLAttr(fMemoryManager);
Gareth Reakes
committed
fValidator->faultInAttr(*curAtt, *curDef);
fAttrList->addElement(curAtt);
}
else
{
curAtt = fAttrList->elementAt(retCount);
Gareth Reakes
committed
fValidator->faultInAttr(*curAtt, *curDef);
}
// Indicate it was not explicitly specified and bump count
curAtt->setSpecified(false);
retCount++;
if(getPSVIHandler())
{
PSVIAttribute *defAttrToFill = fPSVIAttrList->getPSVIAttributeToFill();
XSAttributeDeclaration *defAttrDecl = (XSAttributeDeclaration *)fModel->getXSObject((void *)curDef);
DatatypeValidator * attrDataType = ((SchemaAttDef *)curDef)->getDatatypeValidator();
(XSSimpleTypeDefinition*)fModel->getXSObject(attrDataType);
// would have occurred during validation of default value
if(((SchemaValidator *)fValidator)->getErrorOccurred())
{
defAttrToFill->reset(
fRootElemName
, PSVIItem::VALIDITY_INVALID
, PSVIItem::VALIDATION_FULL
, curDef->getValue()
, defAttrType
, 0
, curDef->getValue()
, true
, defAttrDecl
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
);
}
else
{
XSSimpleTypeDefinition *defAttrMemberType = 0;
if(defAttrType->getVariety() == XSSimpleTypeDefinition::VARIETY_UNION)
{
defAttrMemberType = (XSSimpleTypeDefinition *)fModel->getXSObject
(
((SchemaValidator*)fValidator)->getMostRecentAttrValidator()
);
}
defAttrToFill->reset(
fRootElemName
, PSVIItem::VALIDITY_VALID
, PSVIItem::VALIDATION_FULL
, curDef->getValue()
, defAttrType
, defAttrMemberType
, curDef->getValue()
, true
, defAttrDecl
, (defAttrMemberType)?((SchemaValidator *)fValidator)->getMostRecentAttrValidator():attrDataType
Gareth Reakes
committed
((SchemaElementDecl *)elemDecl)->updateValidityFromAttribute((SchemaAttDef *)curDef);
else if (attCountPtr)
{
//attribute is provided
// (schema) report error for PROHIBITED attrs that are present (V_TAGc)
if (defType == XMLAttDef::Prohibited && fValidate)
{
fValidator->emitError
(
XMLValid::ProhibitedAttributePresent
Gareth Reakes
committed
, curDef->getFullName()
((SchemaAttDef *)curDef)->setValidity(PSVIDefs::INVALID);
fPSVIElemContext.fErrorOccurred = true;
if (getPSVIHandler())
{
QName *attQName = ((SchemaAttDef *)curDef)->getAttName();
// bad luck...
PSVIAttribute *prohibitedAttr = fPSVIAttrList->getAttributePSVIByName
(
attQName->getLocalPart(),
fURIStringPool->getValueForId(attQName->getURI())
);
prohibitedAttr->updateValidity(PSVIItem::VALIDITY_INVALID);
Gareth Reakes
committed
}
((SchemaElementDecl *)elemDecl)->updateValidityFromAttribute((SchemaAttDef *)curDef);
Gareth Reakes
committed
return retCount;
}
// This method will take a raw attribute value and normalize it according to
// the rules of the attribute type. It will put the resulting value into the
// passed buffer.
//
// This code assumes that escaped characters in the original value (via char
// refs) are prefixed by a 0xFFFF character. This is because some characters
// are legal if escaped only. And some escape chars are not subject to
// normalization rules.
bool SGXMLScanner::normalizeAttValue( const XMLAttDef* const attDef
, const XMLCh* const attrName