backing out to fix bustage

This commit is contained in:
doronr%us.ibm.com 2006-01-26 22:18:55 +00:00
parent 50681711be
commit 9d1e215327
4 changed files with 16 additions and 431 deletions

View File

@ -334,8 +334,7 @@ nsSchemaValidator::ValidateSimpletype(const nsAString & aNodeValue,
case nsISchemaSimpleType::SIMPLE_TYPE_LIST: {
// handle lists
rv = ValidateListSimpletype(aNodeValue, aSchemaSimpleType, nsnull,
&isValid);
rv = ValidateListSimpletype(aNodeValue, aSchemaSimpleType, &isValid);
break;
}
@ -713,7 +712,6 @@ nsSchemaValidator::ValidateBuiltinType(const nsAString & aNodeValue,
#endif
PRBool isValid = PR_FALSE;
switch(builtinTypeValue) {
case nsISchemaBuiltinType::BUILTIN_TYPE_STRING: {
isValid = PR_TRUE;
@ -847,16 +845,8 @@ nsSchemaValidator::ValidateBuiltinType(const nsAString & aNodeValue,
nsresult
nsSchemaValidator::ValidateListSimpletype(const nsAString & aNodeValue,
nsISchemaSimpleType *aSchemaSimpleType,
nsSchemaDerivedSimpleType *aFacets,
PRBool *aResult)
{
/* When a datatype is derived from an list datatype, the following facets apply:
* length, maxLength, minLength, enumeration, pattern, whitespace
*
* The length facets apply to the whole list, ie the number of items in the list.
* Patterns are applied to the whole list as well.
*/
PRBool isValid = PR_FALSE;
nsresult rv;
@ -871,68 +861,16 @@ nsSchemaValidator::ValidateListSimpletype(const nsAString & aNodeValue,
nsCStringArray stringArray;
stringArray.ParseString(NS_ConvertUTF16toUTF8(aNodeValue).get(), " \t\r\n");
PRUint32 count = stringArray.Count();
PRInt32 count = stringArray.Count();
nsAutoString tmp;
// if facets have been provided, check them first
PRBool facetsValid = PR_TRUE;
if (aFacets) {
if (aFacets->length.isDefined) {
if (aFacets->length.value != count) {
facetsValid = PR_FALSE;
LOG((" Not valid: List is not the right length (%d)",
aFacets->length.value));
}
}
for (PRInt32 i=0; i < count; ++i) {
CopyUTF8toUTF16(stringArray[i]->get(), tmp);
LOG((" Validating List Item (%d): %s", i, NS_ConvertUTF16toUTF8(tmp).get()));
rv = ValidateSimpletype(tmp, listSimpleType, &isValid);
if (facetsValid && aFacets->maxLength.isDefined) {
if (aFacets->maxLength.value < count) {
facetsValid = PR_FALSE;
LOG((" Not valid: Length (%d) of the list is too large",
aFacets->maxLength.value));
}
}
if (facetsValid && aFacets->minLength.isDefined) {
if (aFacets->minLength.value > count) {
facetsValid = PR_FALSE;
LOG((" Not valid: Length (%d) of the list is too small",
aFacets->minLength.value));
}
}
if (facetsValid && aFacets->pattern.isDefined) {
// check if the pattern matches
nsCOMPtr<nsISchemaValidatorRegexp> regexp = do_GetService(kREGEXP_CID);
rv = regexp->RunRegexp(aNodeValue, aFacets->pattern.value, "g",
&facetsValid);
#ifdef PR_LOGGING
LOG((" Checking Regular Expression"));
if (facetsValid) {
LOG((" -- pattern validates!"));
} else {
LOG((" -- pattern does not validate!"));
}
#endif
}
if (facetsValid && aFacets->enumerationList.Count() > 0) {
facetsValid =
nsSchemaValidatorUtils::HandleEnumeration(aNodeValue,
aFacets->enumerationList);
}
}
// either no facets passed in or facets validated fine
if (facetsValid) {
nsAutoString tmp;
for (PRUint32 i=0; i < count; ++i) {
CopyUTF8toUTF16(stringArray[i]->get(), tmp);
LOG((" Validating List Item (%d): %s", i, NS_ConvertUTF16toUTF8(tmp).get()));
rv = ValidateSimpletype(tmp, listSimpleType, &isValid);
if (!isValid)
break;
}
if (!isValid)
break;
}
}
@ -949,8 +887,7 @@ nsSchemaValidator::ValidateUnionSimpletype(const nsAString & aNodeValue,
PRBool isValid = PR_FALSE;
nsresult rv;
nsCOMPtr<nsISchemaUnionType> unionType = do_QueryInterface(aSchemaSimpleType,
&rv);
nsCOMPtr<nsISchemaUnionType> unionType = do_QueryInterface(aSchemaSimpleType, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISchemaSimpleType> unionSimpleType;
@ -973,50 +910,6 @@ nsSchemaValidator::ValidateUnionSimpletype(const nsAString & aNodeValue,
return rv;
}
nsresult
nsSchemaValidator::ValidateDerivedUnionSimpletype(const nsAString & aNodeValue,
nsSchemaDerivedSimpleType *aDerived,
PRBool *aResult)
{
// This method is called when a simple type is derived from a union type
// via restrictions. So we walk all the possible types, and pass in the
// loaded restriction facets so that they will override the ones defined
// my the union type. We actually have to create a custom
// nsSchemaDerivedSimpleType for each type, since we need to change the basetype
// and to avoid any new restrictions being added to aDerived.
PRBool isValid = PR_FALSE;
nsresult rv;
nsCOMPtr<nsISchemaUnionType> unionType = do_QueryInterface(aDerived->mBaseType,
&rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISchemaSimpleType> unionSimpleType;
PRUint32 count;
unionType->GetUnionTypeCount(&count);
// compare against the union simpletypes in order until a match is found
for (PRUint32 i=0; i < count; ++i) {
rv = unionType->GetUnionType(i, getter_AddRefs(unionSimpleType));
NS_ENSURE_SUCCESS(rv, rv);
nsSchemaDerivedSimpleType derivedType;
nsSchemaValidatorUtils::CopyDerivedSimpleType(&derivedType, aDerived);
derivedType.mBaseType = unionSimpleType;
LOG((" Validating Union Type #%d", i));
rv = ValidateDerivedSimpletype(aNodeValue, &derivedType, &isValid);
if (isValid)
break;
}
*aResult = isValid;
return rv;
}
/* http://www.w3.org/TR/xmlschema-2/#string */
nsresult
nsSchemaValidator::ValidateBuiltinTypeString(const nsAString & aNodeValue,
@ -1050,8 +943,7 @@ nsSchemaValidator::ValidateBuiltinTypeString(const nsAString & aNodeValue,
}
if (isValid && aEnumerationList && (aEnumerationList->Count() > 0)) {
isValid = nsSchemaValidatorUtils::HandleEnumeration(aNodeValue,
*aEnumerationList);
isValid = nsSchemaValidatorUtils::HandleEnumeration(aNodeValue, *aEnumerationList);
}
#ifdef PR_LOGGING
@ -2760,9 +2652,10 @@ PRBool
nsSchemaValidator::IsValidSchemaAnyURI(const nsAString & aString)
{
PRBool isValid = PR_FALSE;
nsresult rv;
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aString);
rv = NS_NewURI(getter_AddRefs(uri), aString);
if (rv == NS_OK)
isValid = PR_TRUE;

View File

@ -48,7 +48,7 @@
/* eced2af3-fde9-4575-b5a4-e1c830b24611 */
#define NS_SCHEMAVALIDATOR_CID \
{ 0xeced2af3, 0xfde9, 0x4575, \
{0xb5, 0xa4, 0xe1, 0xc8, 0x30, 0xb2, 0x46, 0x11}}
{0xb5, 0xa4, 0xe1, 0xc8, 0x30, 0xb2, 0x46, 0x11}}
#define NS_SCHEMAVALIDATOR_CONTRACTID "@mozilla.org/schemavalidator;1"
@ -72,16 +72,10 @@ private:
nsresult ValidateSimpletype(const nsAString & aNodeValue,
nsISchemaSimpleType *aSchemaSimpleType,
PRBool *aResult);
nsresult ValidateDerivedSimpletype(const nsAString & aNodeValue,
nsSchemaDerivedSimpleType *aDerived,
PRBool *aResult);
nsresult ValidateRestrictionSimpletype(const nsAString & aNodeValue,
nsISchemaSimpleType *aSchemaSimpleType,
PRBool *aResult);
nsresult ValidateDerivedBuiltinType(const nsAString & aNodeValue,
nsSchemaDerivedSimpleType *aDerived,
PRBool *aResult);
nsresult ValidateBuiltinType(const nsAString & aNodeValue,
nsISchemaSimpleType *aSchemaSimpleType,
@ -89,15 +83,11 @@ private:
nsresult ValidateListSimpletype(const nsAString & aNodeValue,
nsISchemaSimpleType *aSchemaSimpleType,
nsSchemaDerivedSimpleType *aDerived,
PRBool *aResult);
nsresult ValidateUnionSimpletype(const nsAString & aNodeValue,
nsISchemaSimpleType *aSchemaSimpleType,
PRBool *aResult);
nsresult ValidateDerivedUnionSimpletype(const nsAString & aNodeValue,
nsSchemaDerivedSimpleType *aDerived,
PRBool *aResult);
// methods dealing with validation of built-in types
nsresult ValidateBuiltinTypeString(const nsAString & aNodeValue,
@ -272,6 +262,7 @@ private:
PRBool *aResult);
PRBool IsValidSchemaQName(const nsAString & aString);
// helper methods
void DumpBaseType(nsISchemaBuiltinType *aBuiltInType);

View File

@ -1305,7 +1305,6 @@ nsSchemaValidatorUtils::HandleEnumeration(const nsAString &aStrValue,
for (PRInt32 i = 0; i < count; ++i) {
if (aEnumerationList[i]->Equals(aStrValue)) {
isValid = PR_TRUE;
LOG((" Valid: Value matched enumeration #%d", i));
break;
}
}
@ -1348,15 +1347,7 @@ nsSchemaValidatorUtils::RemoveLeadingZeros(nsAString & aString)
aString.AssignLiteral("0");
} else {
// finally, remove the leading zeros
PRUint32 length = aString.Length();
// if the entire string is composed of zeros, set it to one zero
if (length == count) {
aString.AssignLiteral("0");
} else {
// finally, remove the leading zeros
aString.Cut(indexstart, count);
}
aString.Cut(indexstart, count);
}
}
@ -1387,243 +1378,3 @@ nsSchemaValidatorUtils::RemoveTrailingZeros(nsAString & aString)
aString.Cut(length - count, count);
}
// Walks the inheritance tree until it finds a type that isn't a restriction
// type. While it finds restriction types, it collects restriction facets and
// places them into the nsSchemaDerivedSimpleType. Once a facet has been found,
// it makes sure that it won't be overwritten by the same facet defined in one
// of the inherited types.
nsresult
nsSchemaValidatorUtils::GetDerivedSimpleType(nsISchemaSimpleType *aSimpleType,
nsSchemaDerivedSimpleType *aDerived)
{
PRBool done = PR_FALSE;
nsCOMPtr<nsISchemaSimpleType> simpleType(aSimpleType);
PRUint16 simpleTypeValue;
PRUint32 facetCount;
nsAutoString enumeration;
nsresult rv = NS_OK;
while(simpleType && !done) {
// get the type of the simpletype
rv = simpleType->GetSimpleType(&simpleTypeValue);
NS_ENSURE_SUCCESS(rv, rv);
switch (simpleTypeValue) {
case nsISchemaSimpleType::SIMPLE_TYPE_RESTRICTION: {
// handle the facets
nsCOMPtr<nsISchemaRestrictionType> restrictionType =
do_QueryInterface(simpleType);
nsCOMPtr<nsISchemaFacet> facet;
PRUint32 facetCounter;
PRUint16 facetType;
// get the amount of restriction facet defined.
rv = restrictionType->GetFacetCount(&facetCount);
NS_ENSURE_SUCCESS(rv, rv);
LOG((" %d facet(s) defined.", facetCount));
for (facetCounter = 0; facetCounter < facetCount; ++facetCounter) {
rv = restrictionType->GetFacet(facetCounter, getter_AddRefs(facet));
NS_ENSURE_SUCCESS(rv, rv);
facet->GetFacetType(&facetType);
switch (facetType) {
case nsISchemaFacet::FACET_TYPE_LENGTH: {
nsSchemaIntFacet *length = &aDerived->length;
if (!length->isDefined) {
length->isDefined = PR_TRUE;
facet->GetLengthValue(&length->value);
LOG((" - Length Facet found (value is %d)",
length->value));
}
break;
}
case nsISchemaFacet::FACET_TYPE_MINLENGTH: {
nsSchemaIntFacet *minLength = &aDerived->minLength;
if (!minLength->isDefined) {
minLength->isDefined = PR_TRUE;
facet->GetLengthValue(&minLength->value);
LOG((" - Min Length Facet found (value is %d)",
minLength->value));
}
break;
}
case nsISchemaFacet::FACET_TYPE_MAXLENGTH: {
nsSchemaIntFacet *maxLength = &aDerived->maxLength;
if (!maxLength->isDefined) {
maxLength->isDefined = PR_TRUE;
facet->GetLengthValue(&maxLength->value);
LOG((" - Max Length Facet found (value is %d)",
maxLength->value));
}
break;
}
case nsISchemaFacet::FACET_TYPE_PATTERN: {
nsSchemaStringFacet *pattern = &aDerived->pattern;
if (!pattern->isDefined) {
pattern->isDefined = PR_TRUE;
facet->GetValue(pattern->value);
LOG((" - Pattern Facet found (value is %s)",
NS_ConvertUTF16toUTF8(pattern->value).get()));
}
break;
}
case nsISchemaFacet::FACET_TYPE_ENUMERATION: {
facet->GetValue(enumeration);
aDerived->enumerationList.AppendString(enumeration);
LOG((" - Enumeration found (%s)",
NS_ConvertUTF16toUTF8(enumeration).get()));
break;
}
case nsISchemaFacet::FACET_TYPE_WHITESPACE: {
if (!aDerived->isWhitespaceDefined)
facet->GetWhitespaceValue(&aDerived->whitespace);
break;
}
case nsISchemaFacet::FACET_TYPE_MAXINCLUSIVE: {
nsSchemaStringFacet *maxInclusive = &aDerived->maxInclusive;
if (!maxInclusive->isDefined) {
maxInclusive->isDefined = PR_TRUE;
facet->GetValue(maxInclusive->value);
LOG((" - Max Inclusive Facet found (value is %s)",
NS_ConvertUTF16toUTF8(maxInclusive->value).get()));
}
break;
}
case nsISchemaFacet::FACET_TYPE_MININCLUSIVE: {
nsSchemaStringFacet *minInclusive = &aDerived->minInclusive;
if (!minInclusive->isDefined) {
minInclusive->isDefined = PR_TRUE;
facet->GetValue(minInclusive->value);
LOG((" - Min Inclusive Facet found (value is %s)",
NS_ConvertUTF16toUTF8(minInclusive->value).get()));
}
break;
}
case nsISchemaFacet::FACET_TYPE_MAXEXCLUSIVE: {
nsSchemaStringFacet *maxExclusive = &aDerived->maxExclusive;
if (!maxExclusive->isDefined) {
maxExclusive->isDefined = PR_TRUE;
facet->GetValue(aDerived->maxExclusive.value);
LOG((" - Max Exclusive Facet found (value is %s)",
NS_ConvertUTF16toUTF8(maxExclusive->value).get()));
}
break;
}
case nsISchemaFacet::FACET_TYPE_MINEXCLUSIVE: {
nsSchemaStringFacet *minExclusive = &aDerived->minExclusive;
if (!minExclusive->isDefined) {
minExclusive->isDefined = PR_TRUE;
facet->GetValue(minExclusive->value);
LOG((" - Min Exclusive Facet found (value is %s)",
NS_ConvertUTF16toUTF8(minExclusive->value).get()));
}
break;
}
case nsISchemaFacet::FACET_TYPE_TOTALDIGITS: {
nsSchemaIntFacet *totalDigits = &aDerived->totalDigits;
if (!totalDigits->isDefined) {
totalDigits->isDefined = PR_TRUE;
facet->GetDigitsValue(&totalDigits->value);
LOG((" - Totaldigits Facet found (value is %d)",
totalDigits->value));
}
break;
}
case nsISchemaFacet::FACET_TYPE_FRACTIONDIGITS: {
nsSchemaIntFacet *fractionDigits = &aDerived->fractionDigits;
if (!fractionDigits->isDefined) {
fractionDigits->isDefined = PR_TRUE;
facet->GetDigitsValue(&fractionDigits->value);
LOG((" - FractionDigits Facet found (value is %d)",
fractionDigits->value));
}
break;
}
}
}
// get base type
nsresult rv = restrictionType->GetBaseType(getter_AddRefs(simpleType));
NS_ENSURE_SUCCESS(rv, rv);
break;
}
case nsISchemaSimpleType::SIMPLE_TYPE_BUILTIN: {
// we are done
aDerived->mBaseType = simpleType;
done = PR_TRUE;
break;
}
case nsISchemaSimpleType::SIMPLE_TYPE_LIST: {
// set as base type
aDerived->mBaseType = simpleType;
done = PR_TRUE;
break;
}
case nsISchemaSimpleType::SIMPLE_TYPE_UNION: {
// set as base type
aDerived->mBaseType = simpleType;
done = PR_TRUE;
break;
}
}
}
return rv;
}
// copies the data from aDerivedSrc to aDerivedDest
void
nsSchemaValidatorUtils::CopyDerivedSimpleType(nsSchemaDerivedSimpleType *aDerivedDest,
nsSchemaDerivedSimpleType *aDerivedSrc)
{
aDerivedDest->mBaseType = aDerivedSrc->mBaseType;
aDerivedDest->length.value = aDerivedSrc->length.value;
aDerivedDest->length.isDefined = aDerivedSrc->length.isDefined;
aDerivedDest->minLength.value = aDerivedSrc->minLength.value;
aDerivedDest->minLength.isDefined = aDerivedSrc->minLength.isDefined;
aDerivedDest->maxLength.value = aDerivedSrc->maxLength.value;
aDerivedDest->maxLength.isDefined = aDerivedSrc->maxLength.isDefined;
aDerivedDest->pattern.value = aDerivedSrc->pattern.value;
aDerivedDest->pattern.isDefined = aDerivedSrc->pattern.isDefined;
aDerivedDest->isWhitespaceDefined = aDerivedSrc->isWhitespaceDefined;
aDerivedDest->whitespace = aDerivedSrc->whitespace;
aDerivedDest->maxInclusive.value = aDerivedSrc->maxInclusive.value;
aDerivedDest->maxInclusive.isDefined = aDerivedSrc->maxInclusive.isDefined;
aDerivedDest->minInclusive.value = aDerivedSrc->minInclusive.value;
aDerivedDest->minInclusive.isDefined = aDerivedSrc->minInclusive.isDefined;
aDerivedDest->maxExclusive.value = aDerivedSrc->maxExclusive.value;
aDerivedDest->maxExclusive.isDefined = aDerivedSrc->maxExclusive.isDefined;
aDerivedDest->minExclusive.value = aDerivedSrc->minExclusive.value;
aDerivedDest->minExclusive.isDefined = aDerivedSrc->minExclusive.isDefined;
aDerivedDest->totalDigits.value = aDerivedSrc->totalDigits.value;
aDerivedDest->totalDigits.isDefined = aDerivedSrc->totalDigits.isDefined;
aDerivedDest->fractionDigits.value = aDerivedSrc->fractionDigits.value;
aDerivedDest->fractionDigits.isDefined = aDerivedSrc->fractionDigits.isDefined;
aDerivedDest->enumerationList = aDerivedSrc->enumerationList;
}

View File

@ -40,8 +40,6 @@
#define __nsSchemaValidatorUtils_h__
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsISchema.h"
#include "nsISchemaDuration.h"
#include "nsCOMArray.h"
@ -96,50 +94,6 @@ const nsMonthShortHand monthShortHand[] = {
{ "12", "Dec" }
};
class nsSchemaStringFacet
{
public:
PRBool isDefined;
nsString value;
nsSchemaStringFacet() {
isDefined = PR_FALSE;
}
};
class nsSchemaIntFacet
{
public:
PRBool isDefined;
PRUint32 value;
nsSchemaIntFacet() {
isDefined = PR_FALSE;
value = 0;
}
};
struct nsSchemaDerivedSimpleType {
nsISchemaSimpleType* mBaseType;
nsSchemaIntFacet length;
nsSchemaIntFacet minLength;
nsSchemaIntFacet maxLength;
nsSchemaStringFacet pattern;
PRBool isWhitespaceDefined;
unsigned short whitespace;
nsSchemaStringFacet maxInclusive;
nsSchemaStringFacet minInclusive;
nsSchemaStringFacet maxExclusive;
nsSchemaStringFacet minExclusive;
nsSchemaIntFacet totalDigits;
nsSchemaIntFacet fractionDigits;
nsStringArray enumerationList;
};
class nsSchemaValidatorUtils
{
public:
@ -188,10 +142,6 @@ public:
static void RemoveLeadingZeros(nsAString & aString);
static void RemoveTrailingZeros(nsAString & aString);
static nsresult GetDerivedSimpleType(nsISchemaSimpleType *aSimpleType,
nsSchemaDerivedSimpleType *aDerived);
static void CopyDerivedSimpleType(nsSchemaDerivedSimpleType *aDerivedDest,
nsSchemaDerivedSimpleType *aDerivedSrc);
private:
nsSchemaValidatorUtils();
~nsSchemaValidatorUtils();