Newer
Older
fValidator->emitError
(
XMLValid::NotEnoughElemsForCM
, topElem->fThisElement->getFormattedContentModel()
);
}
else
{
fValidator->emitError
(
XMLValid::ElementNotValidForContent
, topElem->fChildren[res]->getRawName()
, topElem->fThisElement->getFormattedContentModel()
);
}
if (((SchemaValidator*) fValidator)->getErrorOccurred())
fPSVIElemContext.fErrorOccurred = true;
else if (fPSVIElemContext.fCurrentDV && fPSVIElemContext.fCurrentDV->getType() == DatatypeValidator::Union)
psviMemberType = fValidationContext->getValidatingMemberType();
{
fPSVIElemContext.fIsSpecified = ((SchemaValidator*) fValidator)->getIsElemSpecified();
if(fPSVIElemContext.fIsSpecified)
fPSVIElemContext.fNormalizedValue = ((SchemaElementDecl *)topElem->fThisElement)->getDefaultValue();
}
// call matchers and de-activate context
if (toCheckIdentityConstraint())
{
fICHandler->deactivateContext
(
(SchemaElementDecl *) topElem->fThisElement
, fContent.getRawBuffer()
);
Gareth Reakes
committed
if(!isRoot)
((SchemaElementDecl *)fElemStack.topElement()->fThisElement)->updateValidityFromElement(topElem->fThisElement, fGrammarType);
if (fPSVIHandler)
{
endElementPSVI
(
(SchemaElementDecl*)topElem->fThisElement, psviMemberType
);
}
Neil Graham
committed
// now we can reset the datatype buffer, since the
// application has had a chance to copy the characters somewhere else
((SchemaValidator *)fValidator)->clearDatatypeBuffer();
// If we have a doc handler, tell it about the end tag
if (fDocHandler)
{
fDocHandler->endElement
(
*topElem->fThisElement
, uriId
, isRoot
, fPrefixBuf.getRawBuffer()
);
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
// pass information about type info:
const XMLCh *typeName = SchemaSymbols::fgATTVAL_ANYTYPE;
const XMLCh *typeURI = SchemaSymbols::fgURI_SCHEMAFORSCHEMA;
if(!fPSVIElemContext.fErrorOccurred)
{
if(fPSVIElemContext.fCurrentTypeInfo != 0)
{
if(fPSVIElemContext.fCurrentTypeInfo->getAnonymous())
typeName = XMLUni::fgZeroLenString;
else
typeName = fPSVIElemContext.fCurrentTypeInfo->getTypeLocalName();
typeURI = fPSVIElemContext.fCurrentTypeInfo->getTypeUri();
}
else
{
DatatypeValidator *actualDV = (psviMemberType)?psviMemberType:fPSVIElemContext.fCurrentDV;
if(actualDV)
{
if(actualDV->getAnonymous())
typeName = XMLUni::fgZeroLenString;
else
typeName = actualDV->getTypeLocalName();
typeURI = actualDV->getTypeUri();
}
}
}
else
{
// idiosyncratically, if there's an
// error but this element was simpleType-validated,
// the tests demand anySimpleType be returned
if(fPSVIElemContext.fCurrentDV)
typeName = SchemaSymbols::fgDT_ANYSIMPLETYPE;
}
fDocHandler->elementTypeInfo(typeName, typeURI);
// reset xsi:type ComplexTypeInfo
Gareth Reakes
committed
((SchemaElementDecl*)topElem->fThisElement)->reset();
if (!isRoot)
Gareth Reakes
committed
((SchemaElementDecl*)(fElemStack.topElement()->fThisElement))->
setXsiComplexTypeInfo(((SchemaValidator*)fValidator)->getCurrentTypeInfo());
// update error information
fErrorStack->push(fErrorStack->pop() || fPSVIElemContext.fErrorOccurred);
}
Gareth Reakes
committed
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
// If this was the root, then done with content
gotData = !isRoot;
if (gotData) {
// Restore the grammar
fGrammar = fElemStack.getCurrentGrammar();
fGrammarType = fGrammar->getGrammarType();
fValidator->setGrammar(fGrammar);
// Restore the validation flag
fValidate = fElemStack.getValidationFlag();
}
}
// This method handles the high level logic of scanning the DOCType
// declaration. This calls the DTDScanner and kicks off both the scanning of
// the internal subset and the scanning of the external subset, if any.
//
// When we get here the '<!DOCTYPE' part has already been scanned, which is
// what told us that we had a doc type decl to parse.
void SGXMLScanner::scanDocTypeDecl()
{
// Just skips over it
// REVISIT: Should we issue a warning
static const XMLCh doctypeIE[] =
{
chOpenSquare, chCloseAngle, chNull
};
XMLCh nextCh = fReaderMgr.skipUntilIn(doctypeIE);
if (nextCh == chOpenSquare)
fReaderMgr.skipPastChar(chCloseSquare);
fReaderMgr.skipPastChar(chCloseAngle);
}
// This method is called to scan a start tag when we are processing
// namespaces. This method is called after we've scanned the < of a
// start tag. So we have to get the element name, then scan the attributes,
// after which we are either going to see >, />, or attributes followed
// by one of those sequences.
bool SGXMLScanner::scanStartTag(bool& gotData)
{
// Assume we will still have data until proven otherwise. It will only
// ever be false if this is the root and its empty.
gotData = true;
// Reset element content
fContent.reset();
// The current position is after the open bracket, so we need to read in
// in the element name.
if (!fReaderMgr.getName(fQNameBuf))
{
emitError(XMLErrs::ExpectedElementName);
fReaderMgr.skipToChar(chOpenAngle);
return false;
}
// See if its the root element
const bool isRoot = fElemStack.isEmpty();
// Skip any whitespace after the name
fReaderMgr.skipPastSpaces();
// First we have to do the rawest attribute scan. We don't do any
// normalization of them at all, since we don't know yet what type they
// might be (since we need the element decl in order to do that.)
const XMLCh* qnameRawBuf = fQNameBuf.getRawBuffer();
bool isEmpty;
unsigned int attCount = rawAttrScan
(
qnameRawBuf
, *fRawAttrList
, isEmpty
);
// save the contentleafname and currentscope before addlevel, for later use
ContentLeafNameTypeVector* cv = 0;
XMLContentModel* cm = 0;
int currentScope = Grammar::TOP_LEVEL_SCOPE;
bool laxThisOne = false;
if (!isRoot)
{
// schema validator will have correct type if validating
SchemaElementDecl* tempElement = (SchemaElementDecl*)
fElemStack.topElement()->fThisElement;
SchemaElementDecl::ModelTypes modelType = tempElement->getModelType();
ComplexTypeInfo *currType = 0;
if (fValidate)
{
currType = ((SchemaValidator*)fValidator)->getCurrentTypeInfo();
if (currType)
modelType = (SchemaElementDecl::ModelTypes)currType->getContentType();
else // something must have gone wrong
modelType = SchemaElementDecl::Any;
}
else
{
currType = tempElement->getComplexTypeInfo();
}
if ((modelType == SchemaElementDecl::Mixed_Simple)
|| (modelType == SchemaElementDecl::Mixed_Complex)
|| (modelType == SchemaElementDecl::Children))
{
cm = currType->getContentModel();
cv = cm->getContentLeafNameTypeVector();
currentScope = fElemStack.getCurrentScope();
}
else if (modelType == SchemaElementDecl::Any) {
laxThisOne = true;
}
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
}
// Now, since we might have to update the namespace map for this element,
// but we don't have the element decl yet, we just tell the element stack
// to expand up to get ready.
unsigned int elemDepth = fElemStack.addLevel();
fElemStack.setValidationFlag(fValidate);
// Check if there is any external schema location specified, and if we are at root,
// go through them first before scanning those specified in the instance document
if (isRoot
&& (fExternalSchemaLocation || fExternalNoNamespaceSchemaLocation)) {
if (fExternalSchemaLocation)
parseSchemaLocation(fExternalSchemaLocation);
if (fExternalNoNamespaceSchemaLocation)
resolveSchemaGrammar(fExternalNoNamespaceSchemaLocation, XMLUni::fgZeroLenString);
}
// Make an initial pass through the list and find any xmlns attributes or
// schema attributes.
if (attCount)
David Abram Cargill
committed
scanRawAttrListforNameSpaces(attCount);
// Resolve the qualified name to a URI and name so that we can look up
// the element decl for this element. We have now update the prefix to
// namespace map so we should get the correct element now.
int prefixColonPos = -1;
unsigned int uriId = resolveQName
(
qnameRawBuf
, fPrefixBuf
, ElemStack::Mode_Element
, prefixColonPos
);
//if schema, check if we should lax or skip the validation of this element
bool parentValidation = fValidate;
if (cv) {
QName element(fPrefixBuf.getRawBuffer(), &qnameRawBuf[prefixColonPos + 1], uriId, fMemoryManager);
// elementDepth will be > 0, as cv is only constructed if element is not
// root.
laxThisOne = laxElementValidation(&element, cv, cm, elemDepth - 1);
}
// Look up the element now in the grammar. This will get us back a
// generic element decl object. We tell him to fault one in if he does
// not find it.
XMLElementDecl* elemDecl = 0;
bool wasAdded = false;
Gareth Reakes
committed
bool errorBeforeElementFound = false;
bool laxBeforeElementFound = false;
const XMLCh* nameRawBuf = &qnameRawBuf[prefixColonPos + 1];
const XMLCh* original_uriStr = fGrammar->getTargetNamespace();
if (uriId != fEmptyNamespaceId) {
// Check in current grammar before switching if necessary
elemDecl = fGrammar->getElemDecl
(
uriId
, nameRawBuf
, qnameRawBuf
, currentScope
);
Neil Graham
committed
if(!elemDecl)
{
// look in the list of undeclared elements, as would have been done
// before we made grammars stateless:
elemDecl = fElemNonDeclPool->getByKey(nameRawBuf, uriId, currentScope);
}
if (!elemDecl && ( fURIStringPool->getId(original_uriStr) != uriId)) {
// not found, switch to the specified grammar
const XMLCh* uriStr = getURIText(uriId);
Gareth Reakes
committed
bool errorCondition = !switchGrammar(uriStr) && fValidate;
if (errorCondition && !laxThisOne)
{
fValidator->emitError
(
XMLValid::GrammarNotFound
,uriStr
);
Gareth Reakes
committed
errorBeforeElementFound = true;
}
Gareth Reakes
committed
else if(errorCondition)
laxBeforeElementFound = true;
elemDecl = fGrammar->getElemDecl
(
uriId
, nameRawBuf
, qnameRawBuf
, currentScope
);
}
if (!elemDecl && currentScope != Grammar::TOP_LEVEL_SCOPE) {
// if not found, then it may be a reference, try TOP_LEVEL_SCOPE
elemDecl = fGrammar->getElemDecl
(
uriId
, nameRawBuf
, qnameRawBuf
, Grammar::TOP_LEVEL_SCOPE
);
Neil Graham
committed
if(!elemDecl)
{
// look in the list of undeclared elements, as would have been done
// before we made grammars stateless:
elemDecl = fElemNonDeclPool->getByKey(nameRawBuf, uriId, Grammar::TOP_LEVEL_SCOPE);
}
if(!elemDecl) {
// still not found in specified uri
// try emptyNamesapce see if element should be un-qualified.
elemDecl = fGrammar->getElemDecl
(
fEmptyNamespaceId
, nameRawBuf
, qnameRawBuf
, currentScope
Neil Graham
committed
);
Gareth Reakes
committed
bool errorCondition = elemDecl && elemDecl->getCreateReason() != XMLElementDecl::JustFaultIn;
if (errorCondition && fValidate) {
fValidator->emitError
(
XMLValid::ElementNotUnQualified
, elemDecl->getFullName()
);
Gareth Reakes
committed
errorBeforeElementFound = true;
else if(errorCondition)
Gareth Reakes
committed
laxBeforeElementFound = true;
}
}
if (!elemDecl) {
// still not found, fault this in and issue error later
// switch back to original grammar first
switchGrammar(original_uriStr);
Neil Graham
committed
elemDecl = new (fMemoryManager) SchemaElementDecl
(
fPrefixBuf.getRawBuffer()
, nameRawBuf
, uriId
, SchemaElementDecl::Any
, Grammar::TOP_LEVEL_SCOPE
, fMemoryManager
);
elemDecl->setId(fElemNonDeclPool->put((void*)elemDecl->getBaseName(), uriId, currentScope, (SchemaElementDecl*)elemDecl));
wasAdded = true;
}
}
else if (!elemDecl)
{
//the element has no prefix,
//thus it is either a non-qualified element defined in current targetNS
//or an element that is defined in the globalNS
//try unqualifed first
elemDecl = fGrammar->getElemDecl
(
uriId
, nameRawBuf
, qnameRawBuf
, currentScope
);
Neil Graham
committed
if(!elemDecl)
{
// look in the list of undeclared elements, as would have been done
// before we made grammars stateless:
elemDecl = fElemNonDeclPool->getByKey(nameRawBuf, uriId, currentScope);
}
// this is initialized correctly only if there is
// no element decl. The other uses in this scope will only
// be encountered if there continues to be no element decl--which
// implies that this will have been initialized correctly.
unsigned orgGrammarUri = fEmptyNamespaceId;
if (!elemDecl && (orgGrammarUri = fURIStringPool->getId(original_uriStr)) != fEmptyNamespaceId) {
Gareth Reakes
committed
bool errorCondition = !switchGrammar(XMLUni::fgZeroLenString) && fValidate;
if (errorCondition && !laxThisOne)
{
fValidator->emitError
(
XMLValid::GrammarNotFound
, XMLUni::fgZeroLenString
);
Gareth Reakes
committed
errorBeforeElementFound = true;
Gareth Reakes
committed
else if(errorCondition)
laxBeforeElementFound = true;
elemDecl = fGrammar->getElemDecl
(
uriId
, nameRawBuf
, qnameRawBuf
, currentScope
);
}
if (!elemDecl && currentScope != Grammar::TOP_LEVEL_SCOPE) {
// if not found, then it may be a reference, try TOP_LEVEL_SCOPE
elemDecl = fGrammar->getElemDecl
(
uriId
, nameRawBuf
, qnameRawBuf
, Grammar::TOP_LEVEL_SCOPE
);
Neil Graham
committed
if(!elemDecl)
{
// look in the list of undeclared elements, as would have been done
// before we made grammars stateless:
elemDecl = fElemNonDeclPool->getByKey(nameRawBuf, uriId, Grammar::TOP_LEVEL_SCOPE);
}
if (!elemDecl && orgGrammarUri != fEmptyNamespaceId) {
// still Not found in specified uri
// go to original Grammar again to see if element needs to be fully qualified.
Gareth Reakes
committed
bool errorCondition = !switchGrammar(original_uriStr) && fValidate;
if (errorCondition && !laxThisOne)
{
fValidator->emitError
(
XMLValid::GrammarNotFound
,original_uriStr
Gareth Reakes
committed
errorBeforeElementFound = true;
Gareth Reakes
committed
else if(errorCondition)
laxBeforeElementFound = true;
elemDecl = fGrammar->getElemDecl
(
orgGrammarUri
, nameRawBuf
, qnameRawBuf
, currentScope
);
if (elemDecl && elemDecl->getCreateReason() != XMLElementDecl::JustFaultIn && fValidate) {
fValidator->emitError
(
XMLValid::ElementNotQualified
, elemDecl->getFullName()
);
Gareth Reakes
committed
errorBeforeElementFound = true;
}
}
}
if (!elemDecl) {
// still not found, fault this in and issue error later
// switch back to original grammar first
switchGrammar(original_uriStr);
Neil Graham
committed
elemDecl = new (fMemoryManager) SchemaElementDecl
(
fPrefixBuf.getRawBuffer()
, nameRawBuf
, uriId
, SchemaElementDecl::Any
, Grammar::TOP_LEVEL_SCOPE
, fMemoryManager
);
elemDecl->setId(fElemNonDeclPool->put((void*)elemDecl->getBaseName(), uriId, currentScope, (SchemaElementDecl*)elemDecl));
// this info needed for DOMTypeInfo
fPSVIElemContext.fErrorOccurred = false;
Gareth Reakes
committed
// We do something different here according to whether we found the
// element or not.
if (wasAdded)
{
if (laxThisOne) {
fValidate = false;
fElemStack.setValidationFlag(fValidate);
}
Gareth Reakes
committed
else if(fValidate) {
((SchemaElementDecl *)(elemDecl))->setValidationAttempted(PSVIDefs::FULL);
}
// If validating then emit an error
if (fValidate)
{
// This is to tell the reuse Validator that this element was
// faulted-in, was not an element in the grammar pool originally
elemDecl->setCreateReason(XMLElementDecl::JustFaultIn);
fValidator->emitError
(
XMLValid::ElementNotDefined
, elemDecl->getFullName()
);
Gareth Reakes
committed
((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
fPSVIElemContext.fErrorOccurred = true;
Gareth Reakes
committed
if(!laxBeforeElementFound) {
if (fValidate) {
((SchemaElementDecl *)(elemDecl))->setValidationAttempted(PSVIDefs::FULL);
((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::VALID);
}
}
// If its not marked declared and validating, then emit an error
if (!elemDecl->isDeclared()) {
Gareth Reakes
committed
if(elemDecl->getCreateReason() == XMLElementDecl::NoReason) {
((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
((SchemaElementDecl *)(elemDecl))->setValidationAttempted(PSVIDefs::FULL);
fPSVIElemContext.fErrorOccurred = true;
Gareth Reakes
committed
}
fElemStack.setValidationFlag(fValidate);
Gareth Reakes
committed
{
fValidator->emitError
(
XMLValid::ElementNotDefined
, elemDecl->getFullName()
);
}
}
((SchemaElementDecl*)elemDecl)->setXsiComplexTypeInfo(0);
Gareth Reakes
committed
((SchemaElementDecl*)elemDecl)->setXsiSimpleTypeInfo(0);
}
if(errorBeforeElementFound) {
((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
}
// Now we can update the element stack to set the current element
// decl. We expanded the stack above, but couldn't store the element
// decl because we didn't know it yet.
fElemStack.setElement(elemDecl, fReaderMgr.getCurrentReaderNum());
fElemStack.setCurrentURI(uriId);
if (isRoot)
fRootElemName = XMLString::replicate(qnameRawBuf, fMemoryManager);
}
if (fPSVIHandler)
{
fPSVIElemContext.fElemDepth++;
if (elemDecl->isDeclared())
{
fPSVIElemContext.fNoneValidationDepth = fPSVIElemContext.fElemDepth;
}
else
{
fPSVIElemContext.fFullValidationDepth = fPSVIElemContext.fElemDepth;
/******
* While we report an error for historical reasons, this should
* actually result in lax assessment - NG.
if (isRoot && fValidate)
fPSVIElemContext.fErrorOccurred = true;
if (((SchemaValidator*) fValidator)->getErrorOccurred())
fPSVIElemContext.fErrorOccurred = true;
// squirrel away the element's QName, so that we can do an efficient
// end-tag match
fElemStack.setCurrentSchemaElemName(fQNameBuf.getRawBuffer());
ComplexTypeInfo* typeinfo = (fValidate)
? ((SchemaValidator*)fValidator)->getCurrentTypeInfo()
: ((SchemaElementDecl*) elemDecl)->getComplexTypeInfo();
if (typeinfo) {
currentScope = typeinfo->getScopeDefined();
// switch grammar if the typeinfo has a different grammar (happens when there is xsi:type)
XMLCh* typeName = typeinfo->getTypeName();
const XMLCh poundStr[] = {chPound, chNull};
if (!XMLString::startsWith(typeName, poundStr)) {
const int comma = XMLString::indexOf(typeName, chComma);
if (comma > 0) {
Khaled Noaman
committed
XMLBuffer prefixBuf(comma+1, fMemoryManager);
prefixBuf.append(typeName, comma);
const XMLCh* uriStr = prefixBuf.getRawBuffer();
Gareth Reakes
committed
bool errorCondition = !switchGrammar(uriStr) && fValidate;
if (errorCondition && !laxThisOne)
{
fValidator->emitError
(
XMLValid::GrammarNotFound
, prefixBuf.getRawBuffer()
);
Gareth Reakes
committed
((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
}
else if(errorCondition) {
((SchemaElementDecl *)(elemDecl))->setValidationAttempted(PSVIDefs::NONE);
((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::UNKNOWN);
Gareth Reakes
committed
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
}
}
}
fElemStack.setCurrentScope(currentScope);
// Set element next state
if (elemDepth >= fElemStateSize) {
resizeElemState();
}
fElemState[elemDepth] = 0;
fElemStack.setCurrentGrammar(fGrammar);
// If this is the first element and we are validating, check the root
// element.
if (isRoot)
{
if (fValidate)
{
// Some validators may also want to check the root, call the
// XMLValidator::checkRootElement
Gareth Reakes
committed
if (fValidatorFromUser && !fValidator->checkRootElement(elemDecl->getId())) {
fValidator->emitError(XMLValid::RootElemNotLikeDocType);
Gareth Reakes
committed
((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
}
}
}
else if (parentValidation)
{
// If the element stack is not empty, then add this element as a
// child of the previous top element. If its empty, this is the root
// elem and is not the child of anything.
fElemStack.addChild(elemDecl->getElementName(), true);
}
// PSVI handling: must reset this, even if no attributes...
if(getPSVIHandler())
fPSVIAttrList->reset();
// Now lets get the fAttrList filled in. This involves faulting in any
// defaulted and fixed attributes and normalizing the values of any that
// we got explicitly.
//
// We update the attCount value with the total number of attributes, but
// it goes in with the number of values we got during the raw scan of
// explictly provided attrs above.
attCount = buildAttList(*fRawAttrList, attCount, elemDecl, *fAttrList);
if(attCount)
{
// clean up after ourselves:
// clear the map used to detect duplicate attributes
fUndeclaredAttrRegistryNS->removeAll();
}
if (toCheckIdentityConstraint())
{
fICHandler->activateIdentityConstraint
(
(SchemaElementDecl*) elemDecl
, (int) elemDepth
, uriId
, fPrefixBuf.getRawBuffer()
, *fAttrList
, attCount
);
}
// Since the element may have default values, call start tag now regardless if it is empty or not
// If we have a document handler, then tell it about this start tag
if (fDocHandler)
{
fDocHandler->startElement
(
*elemDecl
, uriId
, fPrefixBuf.getRawBuffer()
, *fAttrList
, attCount
, false
, isRoot
);
Neil Graham
committed
} // may be where we output something...
// if we have a PSVIHandler, now's the time to call
// its handleAttributesPSVI method:
if(fPSVIHandler)
{
QName *eName = elemDecl->getElementName();
fPSVIHandler->handleAttributesPSVI
(
eName->getLocalPart()
, fURIStringPool->getValueForId(eName->getURI())
, fPSVIAttrList
);
}
// If empty, validate content right now if we are validating and then
// pop the element stack top. Else, we have to update the current stack
// top's namespace mapping elements.
if (isEmpty)
{
// Pop the element stack back off since it'll never be used now
fElemStack.popTop();
DatatypeValidator* psviMemberType = 0;
if (fGrammarType == Grammar::SchemaGrammarType)
{
if (fValidate && elemDecl->isDeclared())
{
fPSVIElemContext.fCurrentTypeInfo = ((SchemaValidator*) fValidator)->getCurrentTypeInfo();
if(!fPSVIElemContext.fCurrentTypeInfo)
fPSVIElemContext.fCurrentDV = ((SchemaValidator*) fValidator)->getCurrentDatatypeValidator();
else
fPSVIElemContext.fCurrentDV = 0;
if(fPSVIHandler)
{
fPSVIElemContext.fNormalizedValue = ((SchemaValidator*) fValidator)->getNormalizedValue();
if (XMLString::equals(fPSVIElemContext.fNormalizedValue, XMLUni::fgZeroLenString))
fPSVIElemContext.fNormalizedValue = 0;
}
}
else
{
fPSVIElemContext.fCurrentDV = 0;
fPSVIElemContext.fCurrentTypeInfo = 0;
fPSVIElemContext.fNormalizedValue = 0;
// If validating, then insure that its legal to have no content
if (fValidate)
{
const int res = fValidator->checkContent(elemDecl, 0, 0);
if (res >= 0)
{
// REVISIT: in the case of xsi:type, this may
// return the wrong string...
fValidator->emitError
(
XMLValid::ElementNotValidForContent
, elemDecl->getFullName()
, elemDecl->getFormattedContentModel()
);
Gareth Reakes
committed
((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
if (((SchemaValidator*) fValidator)->getErrorOccurred())
fPSVIElemContext.fErrorOccurred = true;
// note that if we're empty, won't be a current DV
else
{
fPSVIElemContext.fIsSpecified = ((SchemaValidator*) fValidator)->getIsElemSpecified();
if(fPSVIElemContext.fIsSpecified)
fPSVIElemContext.fNormalizedValue = ((SchemaElementDecl *)elemDecl)->getDefaultValue();
}
if (fPSVIElemContext.fCurrentDV && fPSVIElemContext.fCurrentDV->getType() == DatatypeValidator::Union)
psviMemberType = fValidationContext->getValidatingMemberType();
if (toCheckIdentityConstraint())
{
fICHandler->deactivateContext
(
(SchemaElementDecl *) elemDecl
, fContent.getRawBuffer()
);
Gareth Reakes
committed
if(!isRoot)
((SchemaElementDecl *)fElemStack.topElement()->fThisElement)->updateValidityFromElement(elemDecl, fGrammarType);
if (fPSVIHandler)
{
endElementPSVI
(
(SchemaElementDecl*)elemDecl, psviMemberType
);
}
// If we have a doc handler, tell it about the end tag
if (fDocHandler)
{
fDocHandler->endElement
(
*elemDecl
, uriId
, isRoot
, fPrefixBuf.getRawBuffer()
);
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
// pass information about type info:
const XMLCh *typeName = SchemaSymbols::fgATTVAL_ANYTYPE;
const XMLCh *typeURI = SchemaSymbols::fgURI_SCHEMAFORSCHEMA;
if(!fPSVIElemContext.fErrorOccurred)
{
if(fPSVIElemContext.fCurrentTypeInfo != 0)
{
if(fPSVIElemContext.fCurrentTypeInfo->getAnonymous())
typeName = XMLUni::fgZeroLenString;
else
typeName = fPSVIElemContext.fCurrentTypeInfo->getTypeLocalName();
typeURI = fPSVIElemContext.fCurrentTypeInfo->getTypeUri();
}
else
{
DatatypeValidator *actualDV = (psviMemberType)?psviMemberType:fPSVIElemContext.fCurrentDV;
if(actualDV)
{
if(actualDV->getAnonymous())
typeName = XMLUni::fgZeroLenString;
else
typeName = actualDV->getTypeLocalName();
typeURI = actualDV->getTypeUri();
}
}
}
else
{
// idiosyncratically, if there's an
// error but this element was simpleType-validated,
// the tests demand anySimpleType be returned
if(fPSVIElemContext.fCurrentDV)
typeName = SchemaSymbols::fgDT_ANYSIMPLETYPE;
}
fDocHandler->elementTypeInfo(typeName, typeURI);
// reset xsi:type ComplexTypeInfo
Gareth Reakes
committed
((SchemaElementDecl*)elemDecl)->reset();
if (!isRoot)
Gareth Reakes
committed
((SchemaElementDecl*)(fElemStack.topElement()->fThisElement))->
setXsiComplexTypeInfo(((SchemaValidator*)fValidator)->getCurrentTypeInfo());
// If the elem stack is empty, then it was an empty root
if (isRoot)
gotData = false;
else
{
// Restore the grammar
fGrammar = fElemStack.getCurrentGrammar();
fGrammarType = fGrammar->getGrammarType();
fValidator->setGrammar(fGrammar);
// Restore the validation flag
fValidate = fElemStack.getValidationFlag();
}
}
else // not empty
fErrorStack->push(fPSVIElemContext.fErrorOccurred);
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
return true;
}
unsigned int
SGXMLScanner::resolveQName(const XMLCh* const qName
, XMLBuffer& prefixBuf
, const short mode
, int& prefixColonPos)
{
// Lets split out the qName into a URI and name buffer first. The URI
// can be empty.
prefixColonPos = XMLString::indexOf(qName, chColon);
if (prefixColonPos == -1)
{
// Its all name with no prefix, so put the whole thing into the name
// buffer. Then map the empty string to a URI, since the empty string
// represents the default namespace. This will either return some
// explicit URI which the default namespace is mapped to, or the
// the default global namespace.
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: 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);
}
// Reset the reader manager to close all files, sockets, etc...
fReaderMgr.reset();