Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes
nsXFormsSchemaValidator Class Reference

#include <nsXFormsSchemaValidator.h>

Collaboration diagram for nsXFormsSchemaValidator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsXFormsSchemaValidator ()
nsresult LoadSchema (nsISchema *aSchema)
 Loads a schema into the validator.
PRBool ValidateString (const nsAString &aValue, const nsAString &aType, const nsAString &aNamespace)
 Validates a string against a namespace and schema type.
PRBool Validate (nsIDOMNode *aElement)
 Validates a node and its subtree against the loaded schema(s)
PRBool GetType (const nsAString &aType, const nsAString &aNamespace, nsISchemaType **aSchemaType)
 Returns a nsISchemaType given an type and namespace.
PRBool ValidateXFormsTypeString (const nsAString &aValue, const nsAString &aType)
 Validates a string against an XForms Schema Type.
PRBool IsValidSchemaYearMonthDuration (const nsAString &aValue)
PRBool IsValidSchemaDayTimeDuration (const nsAString &aValue)
PRBool IsValidSchemaListItem (const nsAString &aValue)
PRBool IsValidSchemaListItems (const nsAString &aValue)
PRBool IsValidSchemaCardNumber (const nsAString &aValue)

Protected Attributes

nsCOMPtr< nsISchemaValidatormSchemaValidator

Detailed Description

Definition at line 42 of file nsXFormsSchemaValidator.h.


Constructor & Destructor Documentation

Definition at line 52 of file nsXFormsSchemaValidator.cpp.

Here is the call graph for this function:


Member Function Documentation

PRBool nsXFormsSchemaValidator::GetType ( const nsAString &  aType,
const nsAString &  aNamespace,
nsISchemaType **  aSchemaType 
)

Returns a nsISchemaType given an type and namespace.

Parameters:
aTypeType
aNamespaceNamespace
aSchemaTypeThe nsISchemaType is stored here.
Returns:
Whether a type was found or not

Definition at line 97 of file nsXFormsSchemaValidator.cpp.

{
  NS_ENSURE_TRUE(mSchemaValidator, PR_FALSE);

  nsresult rv = mSchemaValidator->GetType(aType, aNamespace, aSchemaType);

  return NS_SUCCEEDED(rv);
}

Definition at line 226 of file nsXFormsSchemaValidator.cpp.

{
  nsAutoString value(aValue);

  // A valid card-number is between 12 and 19 digits in length.
  PRInt32 len = value.Length();
  if ((len < 12) || (len > 19))
    return PR_FALSE;

  for (PRInt32 i = 0; i < len; ++i) {
    PRUnichar c = value.CharAt(i);
    if ((c > '9') || (c < '0'))
        return PR_FALSE;
  }

  return PR_TRUE;
}

Here is the caller graph for this function:

Definition at line 172 of file nsXFormsSchemaValidator.cpp.

{
  PRBool isValid = PR_FALSE;

  nsCOMPtr<nsISchemaDuration> duration;
  nsresult rv =
    mSchemaValidator->ValidateBuiltinTypeDuration(aValue,
                                                  getter_AddRefs(duration));

  if (NS_SUCCEEDED(rv)) {
    PRUint32 years, months;
    duration->GetYears(&years);
    duration->GetMonths(&months);

    // if years/months exist, invalid
    if ((years == 0) && (months == 0))
      isValid = PR_TRUE;
  }

  return isValid;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 195 of file nsXFormsSchemaValidator.cpp.

{
  PRBool isValid = PR_FALSE;

  // like a string, but no whitespace
  nsAutoString string(aValue);
  if (string.FindCharInSet(" \t\r\n") == kNotFound) {
    mSchemaValidator->ValidateString(aValue, NS_LITERAL_STRING("string"),
                                     NS_LITERAL_STRING("http://www.w3.org/1999/XMLSchema"),
                                     &isValid);
  }

  return isValid;
}

Here is the caller graph for this function:

Definition at line 211 of file nsXFormsSchemaValidator.cpp.

{
  PRBool isValid = PR_FALSE;

  // listItem is like a string, but no whitespace.  listItems is a whitespace
  // delimited list of listItem, so therefore just need to see if it is a valid
  // xsd:string
  mSchemaValidator->ValidateString(aValue, NS_LITERAL_STRING("string"),
                                   NS_LITERAL_STRING("http://www.w3.org/1999/XMLSchema"),
                                   &isValid);

  return isValid;
}

Here is the caller graph for this function:

Definition at line 135 of file nsXFormsSchemaValidator.cpp.

{
  PRBool isValid = PR_FALSE;

  nsCOMPtr<nsISchemaDuration> duration;
  nsresult rv =
    mSchemaValidator->ValidateBuiltinTypeDuration(aValue,
                                                  getter_AddRefs(duration));

  // valid duration
  if (NS_SUCCEEDED(rv)) {
    // check if no days/hours/minutes/seconds/fractionseconds were set
    PRUint32 temp;
    double dbltemp;
    duration->GetDays(&temp);

    if (temp == 0) {
      duration->GetHours(&temp);
      if (temp == 0) {
        duration->GetMinutes(&temp);
        if (temp == 0) {
          duration->GetSeconds(&temp);
          if (temp == 0) {
            duration->GetFractionSeconds(&dbltemp);
            if (dbltemp == 0) {
              isValid = PR_TRUE;
            }
          }
        }
      }
    }
  }

  return isValid;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Loads a schema into the validator.

Parameters:
aSchemaThe schema to load
Returns:
If it succeeded or not

Definition at line 58 of file nsXFormsSchemaValidator.cpp.

Validates a node and its subtree against the loaded schema(s)

Parameters:
aElementNode to validate
Returns:
Whether the string is valid or not

Definition at line 86 of file nsXFormsSchemaValidator.cpp.

{
  PRBool isValid = PR_FALSE;
  NS_ENSURE_TRUE(mSchemaValidator, isValid);

  mSchemaValidator->Validate(aElement, &isValid);

  return isValid;
}
PRBool nsXFormsSchemaValidator::ValidateString ( const nsAString &  aValue,
const nsAString &  aType,
const nsAString &  aNamespace 
)

Validates a string against a namespace and schema type.

Parameters:
aValueValue to validate
aTypeType
aNamespaceNamespace
Returns:
Whether the string is valid or not

Definition at line 66 of file nsXFormsSchemaValidator.cpp.

{
  PRBool isValid = PR_FALSE;

  NS_ENSURE_TRUE(mSchemaValidator, isValid);

  // if it is the XForms namespace, handle it internally, else delegate to
  // nsISchemaValidator
  if (aNamespace.EqualsLiteral(NS_NAMESPACE_XFORMS)) {
    isValid = ValidateXFormsTypeString(aValue, aType);
  } else {
    mSchemaValidator->ValidateString(aValue, aType, aNamespace, &isValid);
  }

  return isValid;
}

Here is the call graph for this function:

PRBool nsXFormsSchemaValidator::ValidateXFormsTypeString ( const nsAString &  aValue,
const nsAString &  aType 
)

Validates a string against an XForms Schema Type.

Parameters:
aValueValue to validate
aTypeType
Returns:
Whether the string is valid or not

Definition at line 110 of file nsXFormsSchemaValidator.cpp.

{
  if (aType.IsEmpty()) {
    return PR_FALSE;
  }

  PRBool isValid = PR_FALSE;

  if (aType.EqualsLiteral("yearMonthDuration")) {
    isValid = IsValidSchemaYearMonthDuration(aValue);
  } else if (aType.EqualsLiteral("dayTimeDuration")) {
    isValid = IsValidSchemaDayTimeDuration(aValue);
  } else if (aType.EqualsLiteral("listItem")) {
    isValid = IsValidSchemaListItem(aValue);
  } else if (aType.EqualsLiteral("listItems")) {
    isValid = IsValidSchemaListItems(aValue);
  } else if (aType.EqualsLiteral("card-number")) {
    isValid = IsValidSchemaCardNumber(aValue);
  }

  return isValid;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 111 of file nsXFormsSchemaValidator.h.


The documentation for this class was generated from the following files: