mirror of
https://github.com/webodf/WebODF.git
synced 2026-11-30 16:47:58 +01:00
Handle generation of nested elements in ab initio document.
This commit is contained in:
@@ -91,7 +91,8 @@ xmled.CrumbBar = function CrumbBar(htmlelement, root, validationModel) {
|
||||
function createMenu(element) {
|
||||
var menu = doc.createElementNS(htmlns, "div"),
|
||||
range = getRangeAroundElement(element),
|
||||
allowed = validationModel.getPossibleReplacements(root, range),
|
||||
docel = /**@type{!Element}*/(root.parentNode),
|
||||
allowed = validationModel.getPossibleReplacements(docel, range),
|
||||
i;
|
||||
range.detach();
|
||||
for (i = 0; i < allowed.length; i += 1) {
|
||||
|
||||
@@ -172,7 +172,8 @@ xmled.ValidationModel = function ValidationModel(grammarurl, onready) {
|
||||
xsd,
|
||||
targetNamespace = null,
|
||||
validateGroupUpToNode,
|
||||
validateComplexTypeUpToNode;
|
||||
validateComplexTypeUpToNode,
|
||||
fillElementWithDefaults;
|
||||
/**
|
||||
* @return {!xmled.ValidationModel.State}
|
||||
*/
|
||||
@@ -424,6 +425,7 @@ xmled.ValidationModel = function ValidationModel(grammarurl, onready) {
|
||||
}
|
||||
e = doc.createElementNS(targetNamespace,
|
||||
group.getAttribute("name"));
|
||||
fillElementWithDefaults(e, group);
|
||||
instance.appendChild(e);
|
||||
}
|
||||
}
|
||||
@@ -450,7 +452,7 @@ xmled.ValidationModel = function ValidationModel(grammarurl, onready) {
|
||||
}
|
||||
}
|
||||
}
|
||||
function fillElementWithDefaults(instance, definition) {
|
||||
fillElementWithDefaults = function (instance, definition) {
|
||||
forEachElement(definition, xsdns, "complexType", function (type) {
|
||||
forEachElement(type, xsdns, "attribute", function (att) {
|
||||
if (att.getAttribute("use") === "required") {
|
||||
@@ -467,7 +469,7 @@ xmled.ValidationModel = function ValidationModel(grammarurl, onready) {
|
||||
addChoice(instance, seq);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @param {!Document} doc
|
||||
* @param {!Element} elementDef
|
||||
@@ -533,14 +535,23 @@ xmled.ValidationModel = function ValidationModel(grammarurl, onready) {
|
||||
if (!def.hasAttribute("name")) {
|
||||
def = findElement(def.getAttribute("ref"));
|
||||
}
|
||||
if (def.getAttribute("name") === n.localName) {
|
||||
// do some stuff
|
||||
state.error = null;//r = valState(def, 0, currentNode);
|
||||
if (!state.checkDone()) {
|
||||
state.currentNode = n.nextElementSibling;
|
||||
}
|
||||
} else {
|
||||
if (def.getAttribute("name") !== n.localName) {
|
||||
state.error = "Unexpected element " + n.localName;
|
||||
return;
|
||||
}
|
||||
def = def.firstElementChild;
|
||||
if (def && def.localName === "annotation") {
|
||||
def = def.nextElementSibling;
|
||||
}
|
||||
if (def) {
|
||||
if (def.localName === "simpleType") {
|
||||
validateSimpleTypeUpToNode(state);
|
||||
} else {
|
||||
validateComplexTypeUpToNode(def, state);
|
||||
}
|
||||
}
|
||||
if (!state.checkDone()) {
|
||||
state.currentNode = n.nextElementSibling;
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -710,7 +721,7 @@ xmled.ValidationModel = function ValidationModel(grammarurl, onready) {
|
||||
state.pop();
|
||||
} else if (e.localName === "complexContent") {
|
||||
validateComplexContentUpToNode(e, state);
|
||||
} else if (e.localName !== "attribute") {
|
||||
} else if (e.localName !== "attribute" && e.localName !== "anyAttribute") {
|
||||
throw "Not implemented";
|
||||
}
|
||||
e = e.nextElementSibling;
|
||||
@@ -740,7 +751,9 @@ xmled.ValidationModel = function ValidationModel(grammarurl, onready) {
|
||||
return;
|
||||
}
|
||||
state.push(def);
|
||||
state.currentNode = documentElement;
|
||||
if (state.documentNode === state.targetNode) {
|
||||
state.checkDone();
|
||||
return;
|
||||
}
|
||||
def = def.firstElementChild;
|
||||
@@ -753,7 +766,6 @@ xmled.ValidationModel = function ValidationModel(grammarurl, onready) {
|
||||
}
|
||||
runtime.assert(def.localName === "simpleType"
|
||||
|| def.localName === "complexType", "Unexpected element");
|
||||
state.currentNode = documentElement;
|
||||
if (def.localName === "simpleType") {
|
||||
validateSimpleTypeUpToNode(state);
|
||||
} else {
|
||||
|
||||
@@ -182,13 +182,14 @@ xmled.ValidationModelTests = function ValidationModelTests(runner) {
|
||||
return [
|
||||
testRoot("xmled/empty.xsd", []),
|
||||
testRoot("xmled/simple.xsd", ["a", "b", "c"]),
|
||||
testRoot("xmled/complex01.xsd", ["a", "d", "e", "f", "ga"]),
|
||||
testRoot("xmled/complex01.xsd", ["a", "d", "e", "f", "ga", "ha"]),
|
||||
testReplace("xmled/simple.xsd", "a", [0], [1], ["a", "b", "c"]),
|
||||
testReplace("xmled/complex01.xsd", "d", [0, 0], [0, 1], ["a"]),
|
||||
testReplace("xmled/complex01.xsd", "g", [0, 0], [0, 1], ["a", "b", "c"]),
|
||||
testReplace("xmled/complex01.xsd", "gb", [0, 0], [0, 1], ["a", "b", "c"])
|
||||
testReplace("xmled/complex01.xsd", "gb", [0, 0], [0, 1], ["a", "b", "c"]),
|
||||
//testReplace("xmled/complex01.xsd", "gbb", [0, 0], [0, 1], ["empty", "b"]),
|
||||
//testReplace("xmled/complex01.xsd", "gbb", [0, 1], [0, 2], ["empty", "b"])
|
||||
testReplace("xmled/complex01.xsd", "h", [0, 1, 0], [0, 1, 1], ["a", "b", "c"])
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
@@ -32,5 +32,12 @@
|
||||
</xs:choice>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="h">
|
||||
<xs:complexType>
|
||||
<xs:choice>
|
||||
<xs:element ref="e:g" maxOccurs="3"/>
|
||||
</xs:choice>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
|
||||
|
||||
@@ -10,4 +10,6 @@
|
||||
<replacement id="ga"><e:g><e:a/></e:g></replacement>
|
||||
<replacement id="gb"><e:g><e:b/></e:g></replacement>
|
||||
<replacement id="gbb"><e:g><e:b/><e:b/></e:g></replacement>
|
||||
<replacement id="h"><e:h><e:g><e:a/></e:g><e:g><e:a/></e:g></e:h></replacement>
|
||||
<replacement id="ha"><e:h><e:g><e:a/></e:g></e:h></replacement>
|
||||
</replacements>
|
||||
|
||||
Reference in New Issue
Block a user