Newer
Older
131, false, new (fMemoryManager)HashPtr(), fMemoryManager
);
fUndeclaredAttrRegistryNS = new (fMemoryManager) RefHash2KeysTableOf<unsigned int>
(
7, false, new (fMemoryManager)HashXMLCh(), fMemoryManager
fPSVIAttrList = new (fMemoryManager) PSVIAttributeList(fMemoryManager);
if (fValidator)
{
if (!fValidator->handlesSchema())
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Gen_NoSchemaValidator, fMemoryManager);
}
else
{
fValidator = fSchemaValidator;
}
fMemoryManager->deallocate(fElemState); //delete [] fElemState;
delete fSchemaGrammar;
delete fEntityTable;
delete fRawAttrList;
David Abram Cargill
committed
fMemoryManager->deallocate(fRawAttrColonList);
Neil Graham
committed
delete fElemNonDeclPool;
delete fAttDefRegistry;
delete fUndeclaredAttrRegistryNS;
if (fPSVIElement)
delete fPSVIElement;
if (fErrorStack)
delete fErrorStack;
}
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;
}
David Abram Cargill
committed
void SGXMLScanner::resizeRawAttrColonList() {
unsigned int newSize = fRawAttrColonListSize * 2;
int* newRawAttrColonList = (int*) fMemoryManager->allocate
(
newSize * sizeof(int)
); //new int[newSize];
// Copy the existing values
unsigned int index = 0;
for (; index < fRawAttrColonListSize; index++)
newRawAttrColonList[index] = fRawAttrColonList[index];
// Delete the old array and udpate our members
fMemoryManager->deallocate(fRawAttrColonList); //delete [] fRawAttrColonList;
fRawAttrColonList = newRawAttrColonList;
fRawAttrColonListSize = 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.
DatatypeValidator *currDV = 0;
ComplexTypeInfo *currType = 0;
if (fValidate)
{
currType = ((SchemaValidator*)fValidator)->getCurrentTypeInfo();
if (!currType) {
currDV = ((SchemaValidator*)fValidator)->getCurrentDatatypeValidator();
}
}
const bool hasDefs = (currType && fValidate)
? currType->hasAttDefs()
: elemDecl->hasAttDefs();
fElemCount++;
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
// 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;
// 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++)
{
PSVIItem::VALIDITY_STATE attrValid = PSVIItem::VALIDITY_VALID;
PSVIItem::ASSESSMENT_TYPE attrAssessed = PSVIItem::VALIDATION_FULL;
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];
David Abram Cargill
committed
const int colonInd = fRawAttrColonList[index];
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);
janName[colonInd] = chNull;
prefPtr = janName.get();
}
suffPtr = namePtr + colonInd + 1;
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
}
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;
PSVIAttribute *psviAttr = 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) {
if (currType) {
attDef = currType->getAttDef(suffPtr, uriId);
attWildCard = currType->getAttWildCard();
}
else if (!currDV) { // check explicitly-set wildcard
attWildCard = ((SchemaElementDecl*)elemDecl)->getAttWildCard();
}
// 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)) {
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 if (currType) {
// 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()
);
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()
);
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()
);
}
}
else
{
Alberto Massari
committed
if(!fUndeclaredAttrRegistryNS->containsKey(suffPtr, uriId))
fUndeclaredAttrRegistryNS->put((void *)suffPtr, uriId, 0);
else
{
emitError
(
XMLErrs::AttrAlreadyUsedInSTag
, namePtr
, elemDecl->getFullName()
);
}
}
// 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()
);
}
// 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) {
Khaled Noaman
committed
normalizeAttValue(
attDefForWildCard, namePtr, curPair->getValue(), normBuf
);
// If we found an attdef for this one, then lets validate it.
Khaled Noaman
committed
const XMLCh* xsNormalized = normBuf.getRawBuffer();
DatatypeValidator* tempDV = ((SchemaAttDef*) attDefForWildCard)->getDatatypeValidator();
if (tempDV && tempDV->getWSFacet() != DatatypeValidator::PRESERVE)
Khaled Noaman
committed
// normalize the attribute according to schema whitespace facet
((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, xsNormalized, fWSNormalizeBuf);
xsNormalized = fWSNormalizeBuf.getRawBuffer();
if (fNormalizeData && fValidate) {
normBuf.set(xsNormalized);
Neil Graham
committed
if (fValidate ) {
Khaled Noaman
committed
fValidator->validateAttrValue(
attDefForWildCard, xsNormalized, false, elemDecl
attrValidator = ((SchemaValidator *)fValidator)->getMostRecentAttrValidator();
if(((SchemaValidator *)fValidator)->getErrorOccurred())
{
fPSVIElemContext.fErrorOccurred = true;
if(getPSVIHandler())
attrValid = PSVIItem::VALIDITY_INVALID;
Khaled Noaman
committed
else { // no decl; default DOMTypeInfo to anySimpleType
attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYSIMPLETYPE);
Khaled Noaman
committed
}
// Save the type for later use
attType = attDefForWildCard->getType();
}
else {
Khaled Noaman
committed
normalizeAttValue(
attDef, namePtr, curPair->getValue(), normBuf
);
// If we found an attdef for this one, then lets validate it.
if (attDef)
Khaled Noaman
committed
const XMLCh* xsNormalized = normBuf.getRawBuffer();
if (fGrammarType == Grammar::SchemaGrammarType)
{
DatatypeValidator* tempDV = ((SchemaAttDef*) attDef)->getDatatypeValidator();
if (tempDV && tempDV->getWSFacet() != DatatypeValidator::PRESERVE)
{
// normalize the attribute according to schema whitespace facet
Khaled Noaman
committed
((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, xsNormalized, fWSNormalizeBuf);
xsNormalized = fWSNormalizeBuf.getRawBuffer();
if (fNormalizeData && fValidate && !skipThisOne) {
normBuf.set(xsNormalized);
}
Khaled Noaman
committed
fValidator->validateAttrValue(
attDef, xsNormalized, false, elemDecl
attrValidator = ((SchemaValidator *)fValidator)->getMostRecentAttrValidator();
if(((SchemaValidator *)fValidator)->getErrorOccurred())
{
fPSVIElemContext.fErrorOccurred = true;
if(getPSVIHandler())
attrValid = PSVIItem::VALIDITY_INVALID;
Khaled Noaman
committed
else {
attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYSIMPLETYPE);
Khaled Noaman
committed
}
Khaled Noaman
committed
else {
attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYSIMPLETYPE);
Khaled Noaman
committed
}
attType = (attDef)?attDef->getType():XMLAttDef::CData;
// now fill in the PSVIAttributes entry for this attribute:
if(getPSVIHandler())
{
psviAttr = fPSVIAttrList->getPSVIAttributeToFill(suffPtr, fURIStringPool->getValueForId(uriId));
SchemaAttDef *actualAttDef = 0;
if(attDef)
actualAttDef = (SchemaAttDef *)attDef;
else if (attDefForWildCard)
actualAttDef = (SchemaAttDef *)attDefForWildCard;
if(actualAttDef)
{
XSAttributeDeclaration *attrDecl = (XSAttributeDeclaration *)fModel->getXSObject(actualAttDef);
DatatypeValidator * attrDataType = actualAttDef->getDatatypeValidator();
XSSimpleTypeDefinition *validatingType = (XSSimpleTypeDefinition *)fModel->getXSObject(attrDataType);
if(attrValid != PSVIItem::VALIDITY_VALID)
{
fRootElemName
, attrValid
, attrAssessed
, validatingType
, 0
, actualAttDef->getValue()
, false
, attrDecl
, 0
);
}
else
{
XSSimpleTypeDefinition *memberType = 0;
if(validatingType->getVariety() == XSSimpleTypeDefinition::VARIETY_UNION)
memberType = (XSSimpleTypeDefinition *)fModel->getXSObject(attrValidator);
fRootElemName
, attrValid
, attrAssessed
, validatingType
, memberType
, actualAttDef->getValue()
, false
, attrDecl
, (memberType)?attrValidator:attrDataType
);
}
}
else
{
psviAttr->reset
(
fRootElemName
, attrValid
, attrAssessed
, 0
, 0
, 0
, false
, 0
, 0
);
}
}
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);
psviAttr = fPSVIAttrList->getPSVIAttributeToFill(suffPtr, fURIStringPool->getValueForId(uriId));
XSSimpleTypeDefinition *validatingType = 0;
if (attrValidator && fModel)
validatingType = (XSSimpleTypeDefinition *)fModel->getXSObject(attrValidator);
psviAttr->reset(
fRootElemName
, PSVIItem::VALIDITY_NOTKNOWN
, PSVIItem::VALIDATION_NONE
, 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
);
toFill.addElement(curAttr);
}
else
{
curAttr = toFill.elementAt(retCount);
curAttr->set
(
uriId
, suffPtr
, prefPtr
, normBuf.getRawBuffer()
, attType
);
curAttr->setSpecified(true);
}
if(psviAttr)
psviAttr->setValue(curAttr->getValue());
// 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
// 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()
}
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());
}
}
}
// 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++;
QName *attName = ((SchemaAttDef *)curDef)->getAttName();
PSVIAttribute *defAttrToFill = fPSVIAttrList->getPSVIAttributeToFill
(
attName->getLocalPart(), fURIStringPool->getValueForId( attName->getURI())
);
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
, defAttrType
, 0
, curDef->getValue()
, true
, defAttrDecl
);
}
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
, defAttrType
, defAttrMemberType
, curDef->getValue()
, true
, defAttrDecl
, (defAttrMemberType)?((SchemaValidator *)fValidator)->getMostRecentAttrValidator():attrDataType
defAttrToFill->setValue(curDef->getValue());
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()
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
}
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 attName
, const XMLCh* const value
, XMLBuffer& toFill)
{
// A simple state value for a whitespace processing state machine
enum States
{
InWhitespace
, InContent
};
// Get the type and name
const XMLAttDef::AttTypes type = (attDef)
?attDef->getType()
:XMLAttDef::CData;
// Assume its going to go fine, and empty the target buffer in preperation
bool retVal = true;
toFill.reset();
// Get attribute def - to check to see if it's declared externally or not
bool isAttExternal = (attDef)
?attDef->isExternal()
:false;
// Loop through the chars of the source value and normalize it according
// to the type.
States curState = InContent;
bool firstNonWS = false;
XMLCh nextCh;
const XMLCh* srcPtr = value;
if (type == XMLAttDef::CData || type > XMLAttDef::Notation) {
while (*srcPtr) {
// Get the next character from the source. We have to watch for
// escaped characters (which are indicated by a 0xFFFF value followed
// by the char that was escaped.)
nextCh = *srcPtr;
// Do we have an escaped character ?
if (nextCh == 0xFFFF)
nextCh = *++srcPtr;
}
else if ( (nextCh <= 0x0D) && (nextCh == 0x09 || nextCh == 0x0A || nextCh == 0x0D) ) {
// Check Validity Constraint for Standalone document declaration
// XML 1.0, Section 2.9
if (fStandalone && fValidate && isAttExternal)
// Can't have a standalone document declaration of "yes" if attribute
// values are subject to normalisation
fValidator->emitError(XMLValid::NoAttNormForStandalone, attName);
nextCh = chSpace;
}
else if (nextCh == chOpenAngle) {
// If its not escaped, then make sure its not a < character, which is
// not allowed in attribute values.
emitError(XMLErrs::BracketInAttrValue, attName);
retVal = false;
// Add this char to the target buffer
toFill.append(nextCh);
// And move up to the next character in the source
srcPtr++;
}
else {
while (*srcPtr)
// Get the next character from the source. We have to watch for
// escaped characters (which are indicated by a 0xFFFF value followed
// by the char that was escaped.)
nextCh = *srcPtr;
// Do we have an escaped character ?
if (nextCh == 0xFFFF)
{
nextCh = *++srcPtr;
}
else if (nextCh == chOpenAngle) {
// If its not escaped, then make sure its not a < character, which is
// not allowed in attribute values.
emitError(XMLErrs::BracketInAttrValue, attName);
retVal = false;
}
{
if (firstNonWS)
toFill.append(chSpace);
curState = InContent;
firstNonWS = true;
}
else
{
srcPtr++;
continue;
}
}
else if (curState == InContent)
{
{
curState = InWhitespace;
srcPtr++;
// Check Validity Constraint for Standalone document declaration
// XML 1.0, Section 2.9
if (fStandalone && fValidate && isAttExternal)
{
if (!firstNonWS || (nextCh != chSpace) || (!*srcPtr) || fReaderMgr.getCurrentReader()->isWhitespace(*srcPtr))
// Can't have a standalone document declaration of "yes" if attribute
// values are subject to normalisation
fValidator->emitError(XMLValid::NoAttNormForStandalone, attName);
}
}
continue;
}
firstNonWS = true;
}
// Add this char to the target buffer
toFill.append(nextCh);
// And move up to the next character in the source
srcPtr++;
}
Gareth Reakes
committed
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
return retVal;
}
// This method will just normalize the input value as CDATA without
// any standalone checking.
bool SGXMLScanner::normalizeAttRawValue( const XMLCh* const attrName
, const XMLCh* const value
, XMLBuffer& toFill)
{
// Assume its going to go fine, and empty the target buffer in preperation
bool retVal = true;
toFill.reset();
// Loop through the chars of the source value and normalize it according
// to the type.
bool escaped;
XMLCh nextCh;
const XMLCh* srcPtr = value;
while (*srcPtr)
{
// Get the next character from the source. We have to watch for
// escaped characters (which are indicated by a 0xFFFF value followed
// by the char that was escaped.)
nextCh = *srcPtr;
escaped = (nextCh == 0xFFFF);
if (escaped)
nextCh = *++srcPtr;
// If its not escaped, then make sure its not a < character, which is
// not allowed in attribute values.
if (!escaped && (*srcPtr == chOpenAngle))
{
emitError(XMLErrs::BracketInAttrValue, attrName);
retVal = false;
}
if (!escaped)
{
// NOTE: Yes this is a little redundant in that a 0x20 is
// replaced with an 0x20. But its faster to do this (I think)
// than checking for 9, A, and D separately.
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
nextCh = chSpace;
}
// Add this char to the target buffer
toFill.append(nextCh);
// And move up to the next character in the source
srcPtr++;
}
return retVal;
}
unsigned int
SGXMLScanner::resolvePrefix( const XMLCh* const prefix
, const ElemStack::MapModes mode)
{
// 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.)
if (XMLString::equals(prefix, XMLUni::fgXMLNSString))
return fXMLNSNamespaceId;
else if (XMLString::equals(prefix, XMLUni::fgXMLString))
return fXMLNamespaceId;
// Ask the element stack to search up itself for a mapping for the
// passed prefix.
bool unknown;
unsigned int uriId = fElemStack.mapPrefixToURI(prefix, mode, unknown);
// If it was unknown, then the URI was faked in but we have to issue an error
if (unknown)
emitError(XMLErrs::UnknownPrefix, prefix);
return uriId;
}
unsigned int
SGXMLScanner::resolvePrefix( const XMLCh* const prefix
, XMLBuffer& bufToFill
, const ElemStack::MapModes mode)
{
// 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.)
if (XMLString::equals(prefix, XMLUni::fgXMLNSString))
return fXMLNSNamespaceId;