зеркало из https://github.com/mozilla/gecko-dev.git
Not part of default build. Bug 279187 - Hook up Schema Validation to XForms. r=allan/arronr
This commit is contained in:
Родитель
803ae820e9
Коммит
2efd59b026
|
@ -88,5 +88,5 @@ interface nsIModelElementPrivate : nsIXFormsModelElement
|
|||
/**
|
||||
* Validates the instance node against the schemas loaded by the model.
|
||||
*/
|
||||
PRBool validateNode(in nsIDOMNode instanceNode);
|
||||
PRBool validateNode(in nsIDOMNode aInstanceNode);
|
||||
};
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "nsIDOMXPathExpression.h"
|
||||
#include "nsIDOMXPathResult.h"
|
||||
#include "nsDeque.h"
|
||||
#include "nsIModelElementPrivate.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
//# define DEBUG_XF_MDG
|
||||
|
@ -135,13 +136,15 @@ nsXFormsMDGEngine::~nsXFormsMDGEngine()
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsXFormsMDGEngine::Init()
|
||||
nsXFormsMDGEngine::Init(nsIModelElementPrivate *aModel)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
if (mNodeStates.Init() && mNodeToMDG.Init()) {
|
||||
rv = NS_OK;
|
||||
}
|
||||
|
||||
|
||||
mModel = aModel;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -330,7 +333,7 @@ nsXFormsMDGEngine::Recalculate(nsXFormsMDGSet* aChangedNodes)
|
|||
#ifdef DEBUG_XF_MDG
|
||||
nsAutoString domNodeName;
|
||||
g->mContextNode->GetNodeName(domNodeName);
|
||||
|
||||
|
||||
printf("\tNode #%d: This=%p, Dirty=%d, DynFunc=%d, Type=%d, Count=%d, Suc=%d, CSize=%d, CPos=%d, Next=%p, domnode=%s\n",
|
||||
i, (void*) g, g->IsDirty(), g->mDynFunc, g->mType,
|
||||
g->mCount, g->mSuc.Count(), g->mContextSize, g->mContextPosition,
|
||||
|
@ -379,17 +382,20 @@ nsXFormsMDGEngine::Recalculate(nsXFormsMDGSet* aChangedNodes)
|
|||
rv = BooleanExpression(g, constraint);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
///
|
||||
/// @todo Schema validity should be checked here (XXX)
|
||||
|
||||
|
||||
if (mModel && constraint) {
|
||||
mModel->ValidateNode(g->mContextNode, &constraint);
|
||||
}
|
||||
|
||||
if (ns->IsConstraint() != constraint) {
|
||||
ns->Set(eFlag_CONSTRAINT, constraint);
|
||||
ns->Set(eFlag_DISPATCH_VALID_CHANGED, PR_TRUE);
|
||||
NS_ENSURE_TRUE(aChangedNodes->AddNode(g->mContextNode),
|
||||
NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case eModel_readonly:
|
||||
if (g->HasExpr()) {
|
||||
rv = ComputeMIPWithInheritance(eFlag_READONLY,
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "nsXFormsTypes.h"
|
||||
#include "nsXFormsMDGSet.h"
|
||||
#include "nsXFormsNodeState.h"
|
||||
#include "nsIModelElementPrivate.h"
|
||||
|
||||
class nsIDOMXPathExpression;
|
||||
|
||||
|
@ -171,6 +172,9 @@ protected:
|
|||
|
||||
/** The actual MDG */
|
||||
nsVoidArray mGraph;
|
||||
|
||||
/** The model that created the MDG */
|
||||
nsIModelElementPrivate *mModel;
|
||||
|
||||
/**
|
||||
* Set of nodes that are marked as changed, and should be included in
|
||||
|
@ -322,8 +326,10 @@ public:
|
|||
|
||||
/**
|
||||
* Initializes the internal structures. Needs to be called before class is used!
|
||||
*
|
||||
* @param aModel The model that created this MDGEngine instance.
|
||||
*/
|
||||
nsresult Init();
|
||||
nsresult Init(nsIModelElementPrivate *aModel);
|
||||
|
||||
/**
|
||||
* Insert new MIP (Model Item Property) into graph.
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
#include "nsXFormsXPathAnalyzer.h"
|
||||
#include "nsIInstanceElementPrivate.h"
|
||||
#include "nsXFormsUtils.h"
|
||||
#include "nsXFormsSchemaValidator.h"
|
||||
|
||||
#include "nsISchemaLoader.h"
|
||||
#include "nsISchema.h"
|
||||
|
@ -392,7 +393,7 @@ nsXFormsModelElement::OnCreated(nsIXTFGenericElementWrapper *aWrapper)
|
|||
mElement = node;
|
||||
NS_ASSERTION(mElement, "Wrapper is not an nsIDOMElement, we'll crash soon");
|
||||
|
||||
nsresult rv = mMDG.Init();
|
||||
nsresult rv = mMDG.Init(this);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mSchemas = do_GetService(NS_SCHEMALOADER_CONTRACTID);
|
||||
|
@ -779,10 +780,46 @@ nsXFormsModelElement::GetMDG(nsXFormsMDGEngine **aMDG)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsModelElement::ValidateNode(nsIDOMNode *aInstanceNode,
|
||||
PRBool *aResult)
|
||||
nsXFormsModelElement::ValidateNode(nsIDOMNode *aInstanceNode, PRBool *aResult)
|
||||
{
|
||||
*aResult = PR_TRUE;
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
nsresult rv;
|
||||
|
||||
nsAutoString typeAttribute;
|
||||
nsCOMPtr<nsIDOMElement> nodeElem = do_QueryInterface(aInstanceNode, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nodeElem->GetAttributeNS(NS_LITERAL_STRING(NS_NAMESPACE_XML_SCHEMA_INSTANCE),
|
||||
NS_LITERAL_STRING("type"), typeAttribute);
|
||||
|
||||
// split type (ns:type) into namespace and type.
|
||||
PRUint32 separator = typeAttribute.FindChar(':');
|
||||
if ((separator == kNotFound) || (separator == typeAttribute.Length()))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsAutoString schemaTypeName;
|
||||
nsAutoString schemaTypePrefix;
|
||||
nsAutoString schemaTypeNamespace;
|
||||
|
||||
schemaTypePrefix.Assign(Substring(typeAttribute, 0, separator));
|
||||
schemaTypeName.Assign(Substring(typeAttribute, ++separator, typeAttribute.Length()));
|
||||
|
||||
// get the namespace url from the prefix
|
||||
nsCOMPtr<nsIDOM3Node> domNode3 = do_QueryInterface(mElement, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = domNode3->LookupNamespaceURI(schemaTypePrefix, schemaTypeNamespace);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsXFormsSchemaValidator validator;
|
||||
nsCOMPtr<nsISchema> schema = do_QueryInterface(mSchemas);
|
||||
validator.LoadSchema(schema);
|
||||
|
||||
nsAutoString value;
|
||||
nsXFormsUtils::GetNodeValue(aInstanceNode, value);
|
||||
PRBool isValid = validator.ValidateString(value, schemaTypeName, schemaTypeNamespace);
|
||||
|
||||
*aResult = isValid;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче