Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
topElem->fThisElement
, topElem->fChildren
, topElem->fChildCount
);
if (res >= 0)
{
// One of the elements is not valid for the content. NOTE that
// if no children were provided but the content model requires
// them, it comes back with a zero value. But we cannot use that
// to index the child array in this case, and have to put out a
// special message.
if (!topElem->fChildCount)
{
fValidator->emitError
(
XMLValid::EmptyNotValidForContent
, topElem->fThisElement->getFormattedContentModel()
);
}
else if ((unsigned int)res >= topElem->fChildCount)
{
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()
);
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
// 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
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
// 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();
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
// 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.)
bool isEmpty;
unsigned int attCount = rawAttrScan
(
fQNameBuf.getRawBuffer()
, *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;
}
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
}
// 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;
const XMLCh* qnameRawBuf = fQNameBuf.getRawBuffer();
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();
unsigned orgGrammarUri = fURIStringPool->getId(original_uriStr);
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 && (orgGrammarUri != 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);
}
if (!elemDecl && orgGrammarUri != fEmptyNamespaceId) {
//not found, switch grammar and try globalNS
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;
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
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
}
}
}
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);
}
Alberto Massari
committed
// clear the map used to detect duplicate attributes
fUndeclaredAttrRegistryNS->removeAll();
// 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);
// activate identity constraints
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()
);
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
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
// 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);
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
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
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);