r1697 - branches/bxe_2_0/relaxng
[email protected] Wed, 1 Aug 2007 18:56:56 +0200 (CEST)
| Newsgroups | gmane.editors.bitflux.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: chregu
Date: Wed Aug 1 18:56:56 2007
New Revision: 1697
Log:
Fix for first half of BXEB-1
'Grosser' Relax NG Bug
should fix issues with RNG validation, if there are no mandatory children of an element
Modified:
branches/bxe_2_0/relaxng/ElementVDOM.js
Modified: branches/bxe_2_0/relaxng/ElementVDOM.js
==============================================================================
--- branches/bxe_2_0/relaxng/ElementVDOM.js (original)
+++ branches/bxe_2_0/relaxng/ElementVDOM.js Wed Aug 1 18:56:56 2007
@@ -107,7 +107,6 @@
ElementVDOM.prototype.isValid = function(ctxt) {
-
if (ctxt.node._node.localName == this.localName && ctxt.node.namespaceURI == this.namespaceURI) {
@@ -117,54 +116,83 @@
// 8 means no attribute checking..
if (!(ctxt.wFValidityCheckLevel & 8)) {
- for(var i in _attr) {
- //choice attributes
- if(i == '__bxe_choices') {
- for (var j in _attr['__bxe_choices']) {
- var _choices = _attr['__bxe_choices'][j];
- //loop through all available attributes
- var _hasIt = 0;
- var _attrList = "";
- for (var k in _choices) {
- _attrList += ", " + _choices[k].name;
- //check if it's in the node
- // and if there is one, check it's validity
- if ( ctxt.node.getAttribute && ctxt.node.getAttribute(_choices[k].name)) {
- _choices[k].isValid(ctxt);
- // if we already found one attribute of the choices list -> alert
- _hasIt ++
+ for(var i in _attr) {
+ //choice attributes
+ if(i == '__bxe_choices') {
+ for (var j in _attr['__bxe_choices']) {
+ var _choices = _attr['__bxe_choices'][j];
+ //loop through all available attributes
+ var _hasIt = 0;
+ var _attrList = "";
+ for (var k in _choices) {
+ _attrList += ", " + _choices[k].name;
+ //check if it's in the node
+ // and if there is one, check it's validity
+ if ( ctxt.node.getAttribute && ctxt.node.getAttribute(_choices[k].name)) {
+ _choices[k].isValid(ctxt);
+ // if we already found one attribute of the choices list -> alert
+ _hasIt ++
+ }
+ _vdomAttr[_choices[k].name] = true;
+ }
+ if (_hasIt > 1) {
+ var errMsg = "Only one of the following attributes is allowed in " + ctxt.node.nodeName + ": ";
+ errMsg += _attrList.substring(1,_attrList.length);
+ ctxt.setErrorMessage(errMsg );
+ } else if (_hasIt == 0) {
+ var errMsg = ctxt.node.nodeName + " needs one of the following attributes : ";
+ errMsg += _attrList.substring(1,_attrList.length);
+ ctxt.setErrorMessage(errMsg );
}
- _vdomAttr[_choices[k].name] = true;
}
- if (_hasIt > 1) {
- var errMsg = "Only one of the following attributes is allowed in " + ctxt.node.nodeName + ": ";
- errMsg += _attrList.substring(1,_attrList.length);
- ctxt.setErrorMessage(errMsg );
- } else if (_hasIt == 0) {
- var errMsg = ctxt.node.nodeName + " needs one of the following attributes : ";
- errMsg += _attrList.substring(1,_attrList.length);
- ctxt.setErrorMessage(errMsg );
+ } else {
+ _attr[i].isValid(ctxt);
+ _vdomAttr[_attr[i].name] = true;
+ }
+ }
+
+
+ for(var i in _nodeAttr) {
+ if (typeof _vdomAttr[_nodeAttr[i].nodeName] == "undefined") {
+ var errMsg = "The attribute " + _nodeAttr[i].nodeName + " is not allowed in " + ctxt.node.nodeName;
+ if (ctxt.wFValidityCheckLevel & 2) {
+ if (confirm(errMsg + "\n Should it be removed?")) {
+ ctxt.node.removeAttribute(_nodeAttr[i].nodeName);
+ return this.isValid(ctxt);
+ }
}
+ ctxt.setErrorMessage(errMsg );
}
- } else {
- _attr[i].isValid(ctxt);
- _vdomAttr[_attr[i].name] = true;
}
}
+ // TRY TO CHECK HERE FOR NEEDED CHILDREN if there are any yet.
- for(var i in _nodeAttr) {
- if (typeof _vdomAttr[_nodeAttr[i].nodeName] == "undefined") {
- var errMsg = "The attribute " + _nodeAttr[i].nodeName + " is not allowed in " + ctxt.node.nodeName;
- if (ctxt.wFValidityCheckLevel & 2) {
- if (confirm(errMsg + "\n Should it be removed?")) {
- ctxt.node.removeAttribute(_nodeAttr[i].nodeName);
- return this.isValid(ctxt);
+ if(!ctxt.node.hasRealChildNodes() && !ctxt.node.canHaveText) {
+
+
+ var nctxt = new ContextVDOM(this.node, this);
+ if (nctxt.vdom) {
+ vdomLoop:
+ do {
+ switch(nctxt.vdom.type) {
+ case "RELAXNG_ELEMENT":
+ ctxt.setErrorMessage("The element '" + nctxt.vdom.bxeName + "' in '" + this.bxeName + "' is missing.") ;
+ break;
+ case "RELAXNG_ONEORMORE":
+ ctxt.setErrorMessage( "One or more Elements in '" + this.bxeName + "' are missing.");
+ break;
+
+ /*case "RELAXNG_TEXT":
+ errMsg = null;
+ break vdomLoop;
+ */
}
- }
- ctxt.setErrorMessage(errMsg );
+ nctxt.nextVDOM();
+ } while (nctxt.vdom);
+
}
- }
+
}
ctxt.node.vdom = this;
ctxt.nextVDOM();
--
Bx-editor-cvs mailing list
[email protected]
http://lists.bitflux.ch/cgi-bin/listinfo/bx-editor-cvs