use of org.xdef.XDContainer in project xdef by Syntea.
the class MyTest_0 method kp.
public static XDParseResult kp(XXNode chkel, XDValue[] params) {
XDContainer c = XDFactory.createXDContainer((XDContainer) params[2]);
c.setXDNamedItem("minInclusive", params[0]);
c.setXDNamedItem("maxInclusive", params[1]);
try {
XSAbstractParser d = new XSParseDecimal();
d.setNamedParams(null, c);
return d.check(null, chkel.getXMLNode().getNodeValue());
} catch (Exception ex) {
XDParseResult x = XDFactory.createParseResult("");
x.error("", ex.toString());
return x;
}
}
use of org.xdef.XDContainer in project xdef by Syntea.
the class MyTest_0 method displayData.
private static void displayData(XMData x) {
System.out.println(x.getName());
System.out.println(x.getValueTypeName());
String s = x.getRefTypeName();
if (s != null) {
XMVariableTable xv = x.getXDPool().getVariableTable();
XMVariable v = xv.getVariable(s);
if (v == null) {
String xdName = x.getXMDefinition().getName();
v = xv.getVariable(xdName + "#" + s);
s = (v != null ? xdName + "#" : "UNDEFINED: ") + s;
}
}
System.out.println(s);
XDValue v = x.getParseMethod();
if (v instanceof XDParser) {
XDParser p = ((XDParser) v);
System.out.println("\t" + p.parserName());
XDContainer c = p.getNamedParams();
for (XDNamedValue n : c.getXDNamedItems()) {
String name = n.getName();
System.out.print("\t\t" + name + "=");
XDValue val = n.getValue();
if (val.getItemId() == XDValue.XD_CONTAINER) {
boolean first = true;
for (XDValue y : ((XDContainer) val).getXDItems()) {
if (first) {
first = false;
} else {
System.out.print(",");
}
System.out.print(y.toString());
}
System.out.println();
} else {
System.out.println("\t" + n.toString());
}
}
} else {
// null -> string()!
System.out.println("\t" + (v == null ? "string" : v.toString()));
}
}
use of org.xdef.XDContainer in project xdef by Syntea.
the class TestTypes method kp.
public static boolean kp(XXNode chkel, XDValue[] params) {
XDContainer c = XDFactory.createXDContainer((XDContainer) params[2]);
c.setXDNamedItem("minInclusive", params[0]);
c.setXDNamedItem("maxInclusive", params[1]);
try {
XSAbstractParser d = new XSParseDecimal();
d.setNamedParams(null, c);
return !d.check(null, chkel.getXMLNode().getNodeValue()).errors();
} catch (Exception ex) {
chkel.error("", ex.getMessage());
return false;
}
}
use of org.xdef.XDContainer in project xdef by Syntea.
the class TestTypes method test.
@Override
public /**
* Run test and print error information.
*/
void test() {
XDPool xp;
XDDocument xd;
Element el;
String xdef, xml, s;
ArrayReporter reporter = new ArrayReporter();
StringWriter strw;
String oldProp = getProperty(XDConstants.XDPROPERTY_WARNINGS);
try {
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root = 'a'>\n" + "<xd:declaration>\n" + " String s = null;\n" + " String t = null;\n" + " String u = null;\n" + " Element v = null;\n" + " Container w = null;\n" + " void x(Container c) {\n" + " if (t == null) t += 't';\n" + " if (v == null) t += 'u';\n" + " AnyValue a = c.getNamedItem('a');\n" + " if (a.valueType() == $INT) t += 'ID' + (int) a; else t += 'ERRID';\n" + " t+=c.getNamedItem('a').toString();\n" + " if (s == null) t += 'OK1'; else t += 'ERR1';\n" + " if (s != null) t += 'ERR2'; else t += 'OK2';\n" + " if (null == s) t += 'OK3'; else t += 'ERR3';\n" + " if (null != s) t += 'ERR4'; else t += 'OK4';\n" + " t += v != null ? null : '!=';\n" + " t += v == null ? '==' : null;\n" + " while (true) {\n" + " t += s;\n" + " break;\n" + " }\n" + " }\n" + " void y(Container c) {\n" + " AnyValue v = c.item(0);\n" + " t+= c.getItemType(0) == $STRING;\n" + " t+= (v.valueType() == $STRING);\n" + " t+= (String) v;\n" + " }\n" + "</xd:declaration>\n" + "<a xd:script='finally {x(%a=11); y([\"A\"])}'/>" + "</xd:def>\n";
xd = compile(xdef).createXDDocument();
xd.xparse("<a/>", reporter);
assertNoErrorwarnings(reporter);
assertEq("tuID1111OK1OK2OK3OK4!===truetrueA", xd.getVariable("t").toString());
assertTrue(xd.getVariable("u").isNull());
assertTrue(xd.getVariable("u").stringValue() == null);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root = 'a'>\n" + "<xd:declaration>\n" + " Decimal dc = null;\n" + " Datetime dt = null;\n" + " Duration du = null;\n" + " Element el = null;\n" + " String t = null;\n" + " void x() {\n" + " t += dc == null;\n" + " t += dt == null;\n" + " t += du == null;\n" + " t += el == null;\n" + " AnyValue a = el;\n" + " t += a.typeName();\n" + " a = 1;\n" + " t += a.typeName();\n" + " a = null;\n" + " t += a.typeName();\n" + " t += ((AnyValue) 1.5).typeName();\n" + " }\n" + "</xd:declaration>\n" + "<a xd:script='finally x();'/>" + "</xd:def>\n";
xd = compile(xdef).createXDDocument();
xd.xparse("<a/>", reporter);
assertNoErrorwarnings(reporter);
assertEq("truetruetruetrueElementintfloat", xd.getVariable("t").toString());
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root = 'a'>\n" + "<xd:declaration>\n" + " AnyValue a = null;\n" + " Decimal dc = null;\n" + " Datetime dt = null;\n" + " Duration du = null;\n" + " Element el = null;\n" + " String t = null;\n" + " void x() {\n" + " t += a;\n" + " t += dc;\n" + " t += dt;\n" + " t += du;\n" + " t += el;\n" + " }\n" + "</xd:declaration>\n" + "<a xd:script='finally x();'/>" + "</xd:def>\n";
xd = compile(xdef).createXDDocument();
xd.xparse("<a/>", reporter);
assertNoErrorwarnings(reporter);
assertEq("", xd.getVariable("t").toString());
// /////////// Check date limits ////////////////////////////////////////////////
setProperty(XDConstants.XDPROPERTY_MINYEAR, "1916");
setProperty(XDConstants.XDPROPERTY_MAXYEAR, "2216");
setProperty(XDConstants.XDPROPERTY_SPECDATES, "3000-12-31,3000-12-31T00:00:00,3000-12-31T23:59:59");
// test limits in datetime
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<a>\n" + " <b xd:script='+'\n" + " a=\"xdatetime('yyyyMMdd', 'd.M.y')\" b=\"xdatetime('yyyyMMddHHmmss')\" />\n" + "</a>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a><b a='22151201' b='22151201235959'/></a>";
assertEq("<a><b a=\"1.12.2215\" b=\"22151201235959\"/></a>", parse(xp, null, xml, reporter));
assertNoErrorwarnings(reporter);
xml = "<a><b a='25001231' b='25001231235959'/></a>";
parse(xp, null, xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
xml = "<a><b a='30001231' b='30001231235959'/></a>";
el = parse(xp, null, xml, reporter);
assertNoErrorwarnings(reporter);
assertEq(el, "<a><b a=\"31.12.3000\" b=\"30001231235959\"/></a>");
xml = "<a><b a='30001231' b='30001231000000'/></a>";
assertEq("<a><b a=\"31.12.3000\" b=\"30001231000000\"/></a>", parse(xp, null, xml, reporter));
assertNoErrorwarnings(reporter);
xml = "<a><b a='30001231' b='30001231100000'/></a>";
assertEq("<a><b a=\"31.12.3000\" b=\"30001231100000\"/></a>", parse(xp, null, xml, reporter));
assertTrue(reporter.errorWarnings(), "Error not reported");
resetProperties();
// //////////////////////////////////////////////////////////////////////////////
xp = compile(xdef);
xd = xp.createXDDocument();
xd.checkDateLegal(false);
xml = "<a><b a='20151201' b='20151201235959'/></a>";
assertEq("<a><b a=\"1.12.2015\" b=\"20151201235959\"/></a>", parse(xd, xml, reporter));
assertNoErrorwarnings(reporter);
xml = "<a><b a='25001231' b='25001231235959'/></a>";
xd = xp.createXDDocument();
xd.checkDateLegal(false);
parse(xd, xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a><b a='30001231' b='30001231235959'/></a>";
xd = xp.createXDDocument();
xd.checkDateLegal(false);
assertEq("<a><b a=\"31.12.3000\" b=\"30001231235959\"/></a>", parse(xd, xml, reporter));
assertNoErrorwarnings(reporter);
xp = compile(xdef);
xml = "<a><b a='20151201' b='20151201235959'/></a>";
assertEq("<a><b a=\"1.12.2015\" b=\"20151201235959\"/></a>", parse(xp, null, xml, reporter));
assertNoErrorwarnings(reporter);
xml = "<a><b a='30001231' b='30001231235959'/></a>";
assertEq("<a><b a=\"31.12.3000\" b=\"30001231235959\"/></a>", parse(xp, null, xml, reporter));
assertNoErrorwarnings(reporter);
// name of type equals to name of predefined validation method
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <xd:declaration scope='local'> type string string(1,2); </xd:declaration>\n" + "<a x='required string'>\n" + " required string;\n" + "</a>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a x='x'>x</a>";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a x='xxx'>xxx</a>";
parse(xp, "", xml, reporter);
assertErrors(reporter);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <xd:declaration> type int string(1,2); int i; </xd:declaration>\n" + "<a x='required int'>required int;</a>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a x='x'>x</a>";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a x='xxx'>xxx</a>";
parse(xp, "", xml, reporter);
assertErrors(reporter);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + " <xd:declaration scope='local'>\n" + " type Test_enum enum(\"A\", \"B\", \"C\");\n" + " type Test_int int(1, 10);\n" + " </xd:declaration>\n" + " <A>\n" + " <xd:choice xd:script=\"occurs *\">\n" + " <Test1>required list(%item=Test_int);</Test1>\n" + " <Test2>required list(%item=Test_int, %length='3');</Test2>\n" + " <Test3>required list(%item=Test_enum, %length='3');</Test3>\n" + " <Test4>required union(%item=[Test_enum, Test_int]);</Test4>\n" + " <Test5>required union(%item=[Test_enum]);</Test5>\n" + " <Test6>required union(%item=[Test_int]);</Test6>\n" + " </xd:choice>\n" + " </A>\n" + "</xd:def>";
xd = compile(xdef).createXDDocument();
xml = "<A>\n" + " <Test1>1</Test1>\n" + " <Test1>1 2 3 4 5 6 7 8 9 10</Test1>\n" + " <Test2>1 2 3</Test2>\n" + " <Test3>A B C</Test3>\n" + " <Test4>A</Test4>\n" + " <Test4>5</Test4>\n" + " <Test4>C</Test4>\n" + " <Test5>C</Test5>\n" + " <Test6>3</Test6>\n" + "</A>";
assertEq(xml, parse(xd, xml, reporter));
assertNoErrorwarnings(reporter);
} catch (Exception ex) {
fail(ex);
}
try {
// element type
xdef = "<xd:def root='a' xmlns:xd='" + _xdNS + "'>\n" + " <xd:declaration><![CDATA[\n" + " void x() {\n" + " Element e = xparse(\"<e xmlns:x='x' a='A' x:a='xA'><b/>t1</e>\");\n" + " Element f = new Element('f');\n" + " f.setAttribute('f', 'F');\n" + " f.setAttribute('x','x:f', 'xF');\n" + " e.addElement(f);\n" + " e.addText('t2');\n" + " outln(e.getAttribute('a'));\n" + " outln(e.getAttribute('x','a'));\n" + " outln(e.getAttribute('x','x:a'));\n" + " outln(e.getText());\n" + " }\n" + " ]]></xd:declaration>\n" + " <a xd:script='finally x();'/>\n" + "</xd:def>";
strw = new StringWriter();
parse(xdef, "", "<a/>", reporter, strw, null, null);
strw.close();
assertNoErrorwarnings(reporter);
assertEq("A\nxA\nxA\nt1t2\n", strw.toString());
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <xd:declaration>\n" + " <![CDATA[\n" + " Element $a;\n" + " Element e = xparse(\"<x a='A\nB'><y/>text<z/></x>\");\n" + " Element e1 = new Element('e1');\n" + " Element e2 = new Element('nsuri', 'e2');\n" + " Element e3 = new Element('nsuri', 'x:e2');\n" + " void test() {\n" + " outln(e.toString());\n" + " outln(e.toString(true));\n" + " outln(e.getText());\n" + " outln(e1.toString());\n" + " outln(e2.toString());\n" + " outln(e3.toString());\n" + " }\n" + " ]]>\n" + " </xd:declaration>\n" + " <a xd:script='onStartElement {$a=getElement(); outln($a.toString());}\n" + " finally test()'>\n" + " <b/>\n" + " </a>\n" + "</xd:def>";
// vytvořeni ze zdroju
xp = compile(xdef);
strw = new StringWriter();
parse(xp, "", "<a><b/></a>", reporter, strw, null, null);
assertNoErrorwarnings(reporter);
assertEq(strw.toString(), "<a/>\n" + "<x a=\"A B\"><y/>text<z/></x>\n" + "<x a=\"A B\">\n" + " <y/>\n" + " text\n" + " <z/>\n" + "</x>\n" + "text\n" + "<e1/>\n" + "<e2 xmlns=\"nsuri\"/>\n" + "<x:e2 xmlns:x=\"nsuri\"/>\n");
// Parse, ParseResult
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root = 'A'>\n" + "<xd:declaration>\n" + " void x() {\n" + " ParseResult t;\n" + " Parser s = decimal; \n" + " t = s.parse('2');\n" + " Decimal i = t.getValue();\n" + " if (2 != i) error('E01');\n" + " if (i != 2) error('E02');\n" + " if (i != (Decimal) 2) error('E03');\n" + " if ((Decimal) 2 != i) error('E04');\n" + " if ((Decimal) 2.0 != i) error('E05');\n" + " if (i != (Decimal) 2.0) error('E06');\n" + " Decimal j = 2;\n" + " if (i != j) error('E07');\n" + " j = 2.0;\n" + " if (i != j) error('E08');\n" + " if (!t.matches()) error('E09');\n" + " j = 2.0;\n" + " boolean b = t;\n" + " if (!b) error('E10');\n" + " t = boolean().parse('false');\n" + " if (!t) error('E11');\n" + " b = t.getValue();\n" + " if (b) error('E11');\n" + " t = int().parse('9');\n" + " int k = t.getValue();\n" + " if (9 != k) error('E12');\n" + " t = float().parse('3.14');\n" + " float f = t.getValue();\n" + " if (f != 3.14) error('E15');\n" + " t = dateTime().parse('2000-01-02T11:30:00Z');\n" + " Datetime dt = t.getValue();\n" + " if (dt != new Datetime('2000-01-02T11:30:00Z')) error('E16');\n" + " t = duration().parse('PT9999H');\n" + " Duration du = t.getValue();\n" + " if (du != new Duration('PT9999H')) error('E18');\n" + " }\n" + "</xd:declaration>\n" + "<A xd:script='finally x()'/>\n" + "</xd:def>";
parse(xdef, "", "<A/>", reporter);
assertNoErrorwarnings(reporter);
// uniqueSet
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <xd:declaration> uniqueSet id1 {key:int()}; </xd:declaration>\n" + " <a x='id1.key.ID' y='id1.key.ID'>\n" + " <b xd:script='+'>required id1.key.IDREF</b>\n" + " </a>\n" + "</xd:def>";
xml = "<a x='1' y='23'><b>1</b><b>23</b></a>";
parse(xdef, "", xml, reporter);
assertNoErrorwarnings(reporter);
// test getParserParams
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <a a='string(2,3)' b='int(2,3)' c='date(\"2000-01-01\",\"2010-01-01\")'>\n" + " xdatetime('y-M-d','d.M.y')\n" + " </a>\n" + "</xd:def>";
xp = compile(xdef);
XDContainer c = ((XMData) xp.findModel("#a/@a")).getParseParams();
assertEq(2, c.getXDNamedItemValue("minLength").intValue());
assertEq(3, c.getXDNamedItemValue("maxLength").intValue());
c = ((XMData) xp.findModel("#a/@b")).getParseParams();
assertEq(2, c.getXDNamedItemValue("minInclusive").intValue());
assertEq(3, c.getXDNamedItemValue("maxInclusive").intValue());
c = ((XMData) xp.findModel("#a/@c")).getParseParams();
assertEq("2000-01-01", c.getXDNamedItemValue("minInclusive").toString());
assertEq("2010-01-01", c.getXDNamedItemValue("maxInclusive").toString());
c = ((XMData) xp.findModel("#a/text()")).getParseParams();
assertEq("y-M-d", c.getXDNamedItemValue("format").stringValue());
assertEq("d.M.y", c.getXDNamedItemValue("outFormat").stringValue());
// external method with key params
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " external method boolean test.xdef.TestTypes.kp(XXNode, XDValue[]);" + "</xd:declaration>\n" + "<a a='kp(1,5,%totalDigits=1,%enumeration=1,%pattern=\"\\\\d\")'/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a a='1'/>";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='2'/>";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// decimal
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'><a a='decimal(0,1)'/></xd:def>";
compile(xdef).createXDDocument();
xml = "<a a='1'/>";
parse(compile(xdef), "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='2'/>";
parse(compile(xdef), "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// decimal, base decimal
xdef = "<xd:def xmlns:xd='" + _xdNS + "' name = 'test' root='a'>\n" + "<a a='decimal(%base=decimal(%minInclusive=0),%minInclusive=1," + " %maxInclusive=5,%totalDigits=1,%fractionDigits=0," + " %enumeration=[1,3],%pattern=[\"\\\\d\"])' />\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a a='1'/>";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='2'/>";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// union - declared type parser
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration> type t union(%item=[decimal,boolean]);</xd:declaration>\n" + " <a a='required t'/>\n" + "</xd:def>";
xml = "<a a='true' />";
parse(compile(xdef), "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='2' />";
parse(compile(xdef), "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='xyz' />";
parse(compile(xdef), "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
xml = "<a a=' 1 2' />";
parse(compile(xdef), "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// union - declared simplified version
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " type x union(%item = [int(1, 2), boolean]);\n" + " type t x;\n" + "</xd:declaration>\n" + " <a a='required t'/>\n" + "</xd:def>";
xml = "<a a='true'/>";
parse(compile(xdef), "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='2'/>";
parse(compile(xdef), "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='3'/>";
parse(compile(xdef), "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
xml = "<a a='xyz'/>";
parse(compile(xdef), "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
xml = "<a a=' 1 2'/>";
parse(compile(xdef), "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// union - declared parser
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " boolean x() {if (int(1, 2)) return true; return boolean();}\n" + " type t x;\n" + "</xd:declaration>\n" + " <a a='required t'/>\n" + "</xd:def>";
xml = "<a a='true'/>";
parse(compile(xdef), "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='2'/>";
parse(compile(xdef), "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='3'/>";
parse(compile(xdef), "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// union - declared parser
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " boolean t() { if (int(1, 2)) return true; return boolean(); }\n" + "</xd:declaration>\n" + " <a a='required t'/>\n" + "</xd:def>";
xml = "<a a='true'/>";
parse(compile(xdef), "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='2'/>";
parse(compile(xdef), "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='3'/>";
parse(compile(xdef), "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// union, declared items, base.
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " Parser s = string(%enumeration=['true', '2', 'xyz']); \n" + " Parser t = union(%base=s, %item=[decimal,boolean]); \n" + "</xd:declaration>\n" + " <a a='required t'/>\n" + "</xd:def>";
xml = "<a a='true' />";
xp = compile(xdef);
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='2' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='xyz' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
xml = "<a a=' 1 2' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
xml = "<a a=' 1 2' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// union with base
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " Parser s = string(%enumeration='xyz'); \n" + " Parser t = union(%item=[decimal, boolean, s ]); \n" + "</xd:declaration>\n" + " <a a='required t'/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a a='true' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='2' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='xyz' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a=' 1 2' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// model variable.
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<A xd:script='var type p union(%item = [int(1, 3), boolean]);'>\n" + " <a xd:script='occurs *;'><b x='p'/></a>\n" + "</A>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<A><a><b x='1'/></a><a><b x='3'/></a></A>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
// model variable.
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<A xd:script='var {Parser p = union(%item = [int(1, 3), boolean]);}'>\n" + " <a xd:script='occurs *;'><b x='p'/></a>\n" + "</A>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<A><a><b x='1'/></a><a><b x='3'/></a></A>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
// union with the a list of same items
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " Parser s = list(%item=eq('abc'), %minLength=1, %maxLength=2); \n" + "</xd:declaration>\n" + " <a a='required s'/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a a='abc' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a=' abc' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a=' abc ' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a=' abc abc ' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a=' abc abc abc' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), reporter.printToString());
xml = "<a a=' efg ' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
xml = "<a a='' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// union with the a list item
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " Parser s = list(%item=decimal, %enumeration=[1,2,[3,4]]); \n" + " Parser t = union(%item=[boolean, s]); \n" + "</xd:declaration>\n" + " <a a='required t'/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a a=' true' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a=' 1' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a=' 2 ' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='3 4' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a=' 7 ' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
xml = "<a a=' true 1 ' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// union with the sequence item
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " Parser s = sequence(%item=[boolean,decimal],\n" + " %enumeration=['true 1', 'false 2']); \n" + " Parser t = union(%item=[decimal,boolean, s]); \n" + "</xd:declaration>\n" + " <a a='required t; options preserveAttrWhiteSpaces,noTrimAttr'/>\n" + "</xd:def>";
xml = "<a a=' true ' />";
xp = compile(xdef);
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a=' 2 ' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a=' true 1 ' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a=' true 2 ' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
xml = "<a a=' xyz ' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
xml = "<a a=' 1 2' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// gYear - invoked in if command (see method "check")
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<a a = \"required gYear(%minInclusive='1999', %maxInclusive='2000');\"/>\n" + "</xd:def>";
xml = "<a a='1999'/>";
parse(xdef, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='2000'/>";
parse(xdef, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='2010'/>";
parse(xdef, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// sequence
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <a a=' sequence ( %item = [ decimal ( %maxInclusive = 5 ) ] ) '/>\n" + "</xd:def>";
xml = "<a a=' 1' />";
parse(xdef, "", xml, reporter);
assertNoErrorwarnings(reporter);
// sequence
xdef = "<xd:def xmlns:xd='" + _xdNS + "'\n" + " xmlns:xs='" + _xdNS + "' root='a'>\n" + " <a a='sequence(%item=[decimal(%maxInclusive=5), int(%minInclusive=0)])'/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a a=' 1 2 3' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
xml = "<a a=' 1 2' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
// sequence with enumeration
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " Parser s = sequence(%item=[boolean,decimal],\n" + " %enumeration=['true 1', 'false 2']); \n" + "</xd:declaration>\n" + " <a a='required s'/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a a='true 1' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='false 2' />";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='false 1' />";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
// string whiteSpace=preserve (option trimAttr)
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " Parser p = string(%minLength=1, %whiteSpace='preserve');\n" + "</xd:declaration>\n" + "<a a=\"optional p;\" b=\"optional string(0,100);\"/>\n" + "</xd:def>";
xml = "<a a=' ' b=' '/>";
el = parse(xdef, "", xml, reporter);
assertErrors(reporter);
assertEq(el, "<a a='' b=''/>");
// string whiteSpace=preserve (option noTrimAttr)
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a' xd:script='options noTrimAttr'>\n" + "<xd:declaration>\n" + " Parser p = string(%minLength=1, %whiteSpace='preserve');\n" + "</xd:declaration>\n" + "<a a=\"optional p;\" b=\"optional string(0,100);\"/>\n" + "</xd:def>";
el = parse(xdef, "", xml, reporter);
assertNoErrorwarnings(reporter);
assertEq(el, "<a a=' ' b=' '/>");
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a' xd:script='options noTrimAttr'>\n" + "<xd:declaration>\n" + " Parser p = string(%minLength=0, %whiteSpace='collapse');\n" + "</xd:declaration>\n" + "<a a=\"optional p;\" b=\"optional string(0,100);\"/>\n" + "</xd:def>";
el = parse(xdef, "", xml, reporter);
assertNoErrorwarnings(reporter);
assertEq(el, "<a a='' b=' '/>");
// Test of methods NCname(), QName(), QnameURI()
xdef = "<xd:def xmlns:xd='" + _xdNS + "' xmlns:ws='abc' root='ws:message'>\n" + " <xd:declaration>\n" + " external method String test.xdef.TestTypes.tst(XXElement, String);\n" + " </xd:declaration>\n" + " <ws:message xd:script='occurs 0..'\n" + " name='required NCName()'>" + " <xd:choice>" + " <ws:part xd:script=\"occurs 0..; match @element\"" + " name =\"required NCName();" + " finally {String t, s=getText(); t=getQnamePrefix(s); out(t+'/' +" + " getQnameLocalpart(s) + '/' + getNamespaceURI(t) + ';' +" + " getQnameURI(s) + ';' + tst(s));}\"" + " element =\"required QNameURI();" + " finally {String t, s=getText(); t=getQnamePrefix(s); out(t+'/' +" + " getQnameLocalpart(s) + '/' + getNamespaceURI(t) + ';' +" + " getQnameURI(s) + ';' + tst(s));}\"/>" + " <ws:part xd:script=\"occurs 0..; match @type\"" + " name=\"required NCName();\"" + " type=\"required QName();\"/>" + " </xd:choice>" + " </ws:message>" + "</xd:def>\n";
xp = compile(xdef);
strw = new StringWriter();
xml = "<message name=\"GetEndorsingBoarderRequest\"\n" + " xmlns='abc'\n" + " xmlns:esxsd =\"http://schemas.snowboard-info.com/EndorsementSearch.xsd\">" + " <part name=\"body\" element=\"esxsdX:GetEndorsingBoarder\"/>" + "</message>";
parse(xp, "", xml, reporter, strw, null, null);
s = strw.toString();
assertFalse(s.indexOf("/body/abc;abc;abc") < 0 || s.indexOf("/abc;abc;abc") < 0, s);
if (reporter.getErrorCount() == 0) {
fail("error not reported");
} else if (reporter.getErrorCount() != 1) {
fail(reporter.printToString());
} else if (!"XDEF554".equals(reporter.getReport().getMsgID()) && !"XDEF515".equals(reporter.getReport().getMsgID())) {
fail(reporter.getReport().toString());
}
strw = new StringWriter();
xml = "<message name=\"GetEndorsingBoarderRequest\"" + " xmlns='abc'" + " xmlns:esxsd =\"http://schemas.snowboard-info.com/EndorsementSearch.xsd\">" + " <part name=\"body\" element=\"esxsd:GetEndorsingBoarder\"/>" + "</message>";
parse(xp, "", xml, reporter, strw, null, null);
s = strw.toString();
assertFalse(s.indexOf("/body/abc;abc;abc") < 0 || s.indexOf("esxsd/GetEndorsingBoarder/" + "http://schemas.snowboard-info.com/EndorsementSearch.xsd;" + "http://schemas.snowboard-info.com/EndorsementSearch.xsd;" + "http://schemas.snowboard-info.com/EndorsementSearch.xsd") < 0, s);
assertNoErrorwarnings(reporter);
setChkSyntax(false);
// test GPS type
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " GPSPosition base = new GPSPosition(50.08, 14.42, 399.0, 'Prague');\n" + " GPSPosition town;\n" + " void pritDistance() {\n" + " printf('%s (%.2f,%.2f) distance to %s (%.2f,%.2f): %.1f km\\n',\n" + " base.name(), base.latitude(), base.longitude(),\n" + " town.name(), town.latitude(), town.longitude(),\n" + " base.distanceTo(town)/1000);\n" + " }\n" + "</xd:declaration>\n" + "<a>\n" + " <town xd:script=\"+; finally pritDistance();\"\n" + " GPS_position=\"gps(); onTrue town = getParsedValue();\"/>\n" + "</a>\n" + "</xd:def>";
xml = "<a>\n" + " <town GPS_position=\"g(48.2,16.37,151.0,Wien)\"/>\n" + " <town GPS_position=\"g(51.52,-0.09,London)\"/>\n" + "</a>";
strw = new StringWriter();
xd = compile(xdef).createXDDocument();
assertEq(xml, parse(xd, xml, reporter, strw, null, null));
assertNoErrorwarnings(reporter);
strw.close();
assertEq(strw.toString(), "Prague (50.08,14.42) distance to Wien (48.20,16.37): 252.5 km\n" + "Prague (50.08,14.42) distance to London (51.52,-0.09): 1029.9 km\n");
assertEq("Prague", ((XDGPSPosition) xd.getVariable("base")).name());
// test Price type
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='root'>\n" + " <xd:declaration>\n" + " final Container c = new Container();\n" + " external Price extValue;\n" + " void print() {\n" + " for(int i=0; i LT c.getLength(); i++) {\n" + " outln(((Price)c.item(i)).display());\n" + " }\n" + " outln('extValue: ' + extValue);\n" + " }\n" + " </xd:declaration>\n" + " <root xd:script=\"finally print();\">\n" + " <item xd:script=\"occurs +\">\n" + " price(); onTrue c.addItem(getParsedValue());\n" + " </item>\n" + " </root>\n" + "</xd:def>";
xml = "<root>\n" + " <item>p(1.5 CZK)</item>\n" + " <item>p(12.657 USD)</item>\n" + " <item>p(0.657 XAU)</item>\n" + "</root>";
strw = new StringWriter();
xd = compile(xdef).createXDDocument();
assertEq(xml, parse(xd, xml, reporter, strw, null, null));
assertNoErrorwarnings(reporter);
assertEq(strw.toString(), "1.50 CZK\n12.66 USD\n0.657 XAU\nextValue: null\n");
assertEq("null", ((XDPrice) xd.getVariable("extValue")).display());
xd.setVariable("extValue", new Price(2.3, "CZK"));
assertEq("2.30 CZK", ((XDPrice) xd.getVariable("extValue")).display());
assertEq(2, ((XDPrice) xd.getVariable("extValue")).fractionDigits());
// test IPAddr type
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='root'>\n" + " <xd:declaration>\n" + " final Container c = new Container();\n" + " external IPAddr x;\n" + " IPAddr y = new IPAddr(x.toString());\n" + " void print() {\n" + " for(int i=0; i LT c.getLength(); i++) {\n" + " out(c.item(i) + ',');\n" + " }\n" + " out('x: ' + getHostAddress(x) + ';' + x.equals(y));\n" + " }\n" + " </xd:declaration>\n" + " <root xd:script=\"finally print();\">\n" + " <item xd:script=\"occurs +\">\n" + " ipAddr(); onTrue c.addItem(getParsedValue());\n" + " </item>\n" + " </root>\n" + "</xd:def>";
xml = "<root>\n" + " <item>/129.144.52.38</item>\n" + " <item>/1080:0:0:0:8:800:200C:417A</item>\n" + "</root>";
strw = new StringWriter();
xd = compile(xdef).createXDDocument();
xd.setVariable("x", InetAddress.getByName("123.45.6.7"));
assertEq(xml, parse(xd, xml, reporter, strw, null, null));
assertNoErrorwarnings(reporter);
assertEq(strw.toString(), "129.144.52.38,1080:0:0:0:8:800:200c:417a,x: 123.45.6.7;true");
// expression in type validation
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " boolean x(){return int | string;}\n" + "</xd:declaration>\n" + "<A a=\"x()\"/>\n" + "<a a='x(); finally out(x());'/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a a='1'/>";
strw = new StringWriter();
parse(xp, null, xml, reporter, strw, null, null);
assertEq("true", strw.toString());
assertNoErrorwarnings(reporter);
xml = "<a a='x'/>";
strw = new StringWriter();
parse(xp, null, xml, reporter, strw, null, null);
assertEq("true", strw.toString());
assertNoErrorwarnings(reporter);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " boolean x(){return int AND string;}\n" + "</xd:declaration>\n" + "<a a='x(); finally out(x());'/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a a='1'/>";
strw = new StringWriter();
parse(xp, null, xml, reporter, strw, null, null);
assertEq("true", strw.toString());
assertNoErrorwarnings(reporter);
xml = "<a a='x'/>";
strw = new StringWriter();
parse(xp, null, xml, reporter, strw, null, null);
assertEq("false", strw.toString());
assertErrors(reporter);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " boolean x(){return int AAND string;}\n" + "</xd:declaration>\n" + "<a a='x(); finally out(x());'/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a a='1'/>";
strw = new StringWriter();
parse(xp, null, xml, reporter, strw, null, null);
assertEq("true", strw.toString());
assertNoErrorwarnings(reporter);
xml = "<a a='x'/>";
strw = new StringWriter();
parse(xp, null, xml, reporter, strw, null, null);
assertEq("false", strw.toString());
assertErrors(reporter);
// test enum
xdef = "<xd:def xmlns:xd='http://www.xdef.org/xdef/4.1' root='A'>\n" + "<xd:declaration>\n" + " type x enum('123', '456', '678');\n" + " type y enum('123');\n" + "</xd:declaration>\n" + " <A a='x();'>y();</A>\n" + "</xd:def>";
xp = XDFactory.compileXD(null, xdef);
xml = "<A a='456'>123</A>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrors(reporter);
// test output format of xdatetime
xdef = "<xd:def xmlns:xd='http://www.xdef.org/xdef/4.1' root='A'>\n" + " <A a=\"xdatetime('y-M-d','yyyyMMdd');\">xdatetime('y-M-d','yyyyMMdd')</A>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<A a='2022-5-8'>2022-5-8</A>";
assertEq("<A a='20220508'>20220508</A>", parse(xp, "", xml, reporter));
assertNoErrors(reporter);
// test output format of xdatetime in list
xdef = "<xd:def xmlns:xd='http://www.xdef.org/xdef/4.1' root='A'>\n" + "<xd:declaration>\n" + " type x list(xdatetime('y-M-d', 'yyyyMMdd'));\n" + "</xd:declaration>\n" + " <A a='? x();'>* x()</A>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<A a='2022-5-8'>2022-5-8</A>";
assertEq("<A a='20220508'>20220508</A>", parse(xp, "", xml, reporter));
assertNoErrors(reporter);
// test output format of xdatetime in union
xdef = "<xd:def xmlns:xd='http://www.xdef.org/xdef/4.1' root='A'>\n" + "<xd:declaration>\n" + " type x union(%item=[xdatetime('y-M-d', 'yyyyMMdd'), boolean()]);\n" + "</xd:declaration>\n" + " <A a='? x();'>* x()</A>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<A a='2022-5-8'>2022-5-8</A>";
assertEq("<A a='20220508'>20220508</A>", parse(xp, "", xml, reporter));
assertNoErrors(reporter);
xml = "<A a='true'>false</A>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrors(reporter);
// test asterisk as minimum and maximum
xdef = "<xd:def xmlns:xd='http://www.xdef.org/xdef/4.1' root='A'>\n" + " <A a='string(*,3);'>string(1,*);</A>\n" + "</xd:def>";
xp = XDFactory.compileXD(null, xdef);
xd = xp.createXDDocument();
xml = "<A a='abc'>def</A>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrors(reporter);
// test asterisk as minimum and maximum
xdef = "<xd:def xmlns:xd='http://www.xdef.org/xdef/4.1' root='A'>\n" + " <A a='string(*,3);'>string(1,*);</A>\n" + "</xd:def>";
xp = XDFactory.compileXD(null, xdef);
xd = xp.createXDDocument();
xml = "<A a='abc'>def</A>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrors(reporter);
// test asterisk as minimum and maximum
xdef = "<xd:def xmlns:xd='http://www.xdef.org/xdef/4.1' root='A'>\n" + " <A a='int(*,123);'>int(123,*);</A>\n" + "</xd:def>";
xp = XDFactory.compileXD(null, xdef);
xd = xp.createXDDocument();
xml = "<A a='123'>123</A>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrors(reporter);
// asterisk and variable
xdef = "<xd:def xmlns:xd ='" + _xdNS + "' name='a' root='a'>" + "<xd:declaration> Datetime d=new Datetime(\"2021-06-10\");</xd:declaration>\n" + " <a a=\"date(d, *)\"/>\n" + "</xd:def>\n";
xp = XDFactory.compileXD(null, xdef);
xml = "<a a='2021-06-11'></a>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrors(reporter);
xml = "<a a='2021-06-09'></a>";
parse(xp, "", xml, reporter);
assertErrors(reporter);
// asterisk and variable
xdef = "<xd:def xmlns:xd ='" + _xdNS + "' name='a' root='a'>" + "<xd:declaration> Datetime d=new Datetime(\"2021-06-10\");</xd:declaration>\n" + " <a a=\"date(*, d)\"/>\n" + "</xd:def>\n";
xp = XDFactory.compileXD(null, xdef);
xml = "<a a='2021-06-09'></a>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrors(reporter);
xml = "<a a='2021-06-11'></a>";
parse(xp, "", xml, reporter);
assertErrors(reporter);
// test combine seq and key params
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<a a=\"string(3,%pattern=['[a-d]+'])\"/>\n" + "</xd:def>";
parse(xdef, "", "<a a='abc'/>", reporter);
assertNoErrorwarnings(reporter);
parse(xdef, "", "<a a='abcd'/>", reporter);
assertTrue(reporter.errorWarnings(), "Error not reported");
try {
// test error of combination of seq and key params
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <a a='string(3,%maxLength=3)'/>\n" + "</xd:def>";
xp = compile(xdef);
fail("error not reported");
} catch (Exception ex) {
if (ex.getMessage().indexOf("XDEF442") < 0) {
fail(ex);
}
}
try {
// test error of combination of seq and key params
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <a a='int(3, %minInclusive=3)' />\n" + "</xd:def>";
xp = compile(xdef);
fail("error not reported");
} catch (Exception ex) {
if (ex.getMessage().indexOf("XDEF442") < 0) {
fail(ex);
}
}
try {
// test error of combination of seq and key params
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <a a='uri(*, 3)'/>\n" + "</xd:def>";
xp = compile(xdef);
fail("error not reported");
} catch (Exception ex) {
if (ex.getMessage().indexOf("XDEF216") < 0) {
fail(ex);
}
}
} catch (Exception ex) {
fail(ex);
}
try {
// test ListOf with XDEF_3.1
setProperty(XDConstants.XDPROPERTY_WARNINGS, XDConstants.XDPROPERTYVALUE_WARNINGS_FALSE);
// check Parser-combination of sequential and key parameters
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a' >\n" + " <a a='decimal(0,2,%totalDigits=3,%fractionDigits=2,%enumeration=[1.21])'\n" + " b='decimal(-2,2,%totalDigits=3,%fractionDigits=2)' c='dec(3,2)'/>\n" + "</xd:def>\n";
xp = compile(xdef);
xml = "<a a='+3.21' b='-1.21' c='+0.00'/>";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings());
xml = "<a a='+1.21' b='-3.21' c='+0.00'/>";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings());
xml = "<a a='+1.21' b='-1.21' c='+12.45'/>";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings());
xml = "<a a='+1.21' b='-1.21' c='+0.0'/>";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='+1.21' b='-1.21' c='+1.21'/>";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='+1.21' b='-1.21' c='-1.21'/>";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
} catch (Exception ex) {
fail(ex);
}
setProperty(XDConstants.XDPROPERTY_WARNINGS, oldProp);
try {
xdef = "<xd:def xmlns:xd = '" + _xdNS + "' root='a'>\n" + " <a x=\"list(string, %length = 2);\"/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a x='1 2'/>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
xml = "<a x='1'/>";
assertEq(xml, parse(xp, "", xml, reporter));
assertTrue(reporter.errorWarnings());
xml = "<a x='1 2 3'/>";
assertEq(xml, parse(xp, "", xml, reporter));
assertTrue(reporter.errorWarnings());
xdef = "<xd:def xmlns:xd = '" + _xdNS + "' root='a'>\n" + " <xd:declaration> Parser p = string; </xd:declaration>\n" + " <a x=\"list(p, %minLength = 2, %maxLength = 3);\"/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a x='1 2'/>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
xml = "<a x='1'/>";
assertEq(xml, parse(xp, "", xml, reporter));
assertTrue(reporter.errorWarnings());
xdef = "<xd:def xmlns:xd = '" + _xdNS + "' root='a'>\n" + " <xd:declaration>int i = 1, j = 2; Parser p = int(i,j);</xd:declaration>\n" + " <a x=\"list(p, %minLength = 2, %maxLength = 3);\"/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a x='1 2'/>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
xml = "<a x='1'/>";
assertEq(xml, parse(xp, "", xml, reporter));
assertTrue(reporter.errorWarnings());
xml = "<a x='1 9'/>";
assertEq(xml, parse(xp, "", xml, reporter));
assertTrue(reporter.errorWarnings());
// check element variable
xdef = "<xd:def xmlns:xd = '" + _xdNS + "' root='a'>\n" + " <a xd:script=\"var {String x;}\">\n" + " <b xd:script='+'" + " x=\"empty();\n" + " onTrue x = '1999';\n" + " finally {\n" + " Parser p = gYear(%minInclusive=1999);\n" + " ParseResult r = p.parse(x);\n" + " if (!r.matches()) {\n" + " error('E001','Check failed: &{p}', '&{p}' + x);\n" + " }\n" + " }\">\n" + " </b>\n" + " </a>\n" + "</xd:def>";
xml = "<a><b x=''></b></a>";
assertEq(xml, parse(xdef, "", xml, reporter));
assertNoErrorwarnings(reporter);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <a xd:script=\"var final String z='1999';\">\n" + " <b>\n" + " <c xd:script='+'\n" + " x=\"empty();\n" + " finally {\n" + " Parser p = gYear(%minInclusive=1999);\n" + " ParseResult r = p.parse(z);\n" + " if (!r.matches()) {\n" + " error('E001','Check failed: &{p}', '&{p}' + z);\n" + " }\n" + " }\">\n" + " </c>\n" + " </b>\n" + " </a>\n" + "</xd:def>";
xml = "<a><b><c x=''/></b></a>";
assertEq(xml, parse(xdef, "", xml, reporter));
assertNoErrorwarnings(reporter);
// parser type
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a' >\n" + " <xd:declaration>\n" + " external method XDParser test.xdef.TestTypes.getMyParser();\n" + " </xd:declaration>\n" + " <a a='getMyParser()'/>\n" + "</xd:def>\n";
xp = compile(xdef);
xml = "<a a='abc'/>";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='cde'/>";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings());
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a' >\n" + " <xd:declaration>\n" + " external method XDParser test.xdef.TestTypes.getMyParser();\n" + " Parser p = getMyParser();\n" + " </xd:declaration>\n" + " <a a='p'/>\n" + "</xd:def>\n";
xp = compile(xdef);
xml = "<a a='abc'/>";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a a='cde'/>";
parse(xp, "", xml, reporter);
assertTrue(reporter.errorWarnings());
// external variable
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a' >\n" + "<xd:declaration> external Parser p; </xd:declaration>\n" + " <a a='p'/>\n" + "</xd:def>\n";
xp = compile(xdef);
xml = "<a a='abc'/>";
xd = xp.createXDDocument();
xd.setVariable("p", getMyParser());
parse(xd, xml, reporter);
assertNoErrorwarnings(reporter);
xd = xp.createXDDocument();
xd.setVariable("p", getMyParser());
xml = "<a a='cde'/>";
parse(xd, xml, reporter);
assertTrue(reporter.errorWarnings());
int year = new GregorianCalendar().get(Calendar.YEAR);
setProperty("xdef.minyear", String.valueOf(year - 200));
setProperty("xdef.maxyear", String.valueOf(year + 200));
setProperty("xdef.specdates", "3000-12-31,3000-12-31T00:00:00,3000-12-31T23:59:59");
// imt - max values
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'><a a='int()' b='int()'/></xd:def>";
xp = compile(xdef);
xml = "<a a='2147483647' b='-2147483648' />";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
xml = "<a a='2147483648' b='-2147483649' />";
parse(xp, "", xml, reporter);
assertEq(2, reporter.getErrorCount());
// jlist
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<a>jlist(%item=gps());</a>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a>[ g(12.50, 1.2), g(2.5, 3.5, -0.1, xxx) ]</a>";
assertEq(xml, el = parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<a>jlist(%item=price());</a>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a>[ p(12.50 CZK), p(2.5 USD) ]</a>";
assertEq(xml, el = parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<a>jlist(%item=union(%item=[gps(), price()]));</a>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a>[ g(2.5, 3.5, -0.1, xxx), p(12.50 CZK), p(2.5 USD) ]</a>";
assertEq(xml, el = parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
xdef = "<xd:def xmlns:xd='http://www.xdef.org/xdef/4.1' root='A'>\n" + "<A a=\"string(%base=true);\"/>\n" + "</xd:def>";
xp = compile(xdef);
xd = xp.createXDDocument();
xml = "<A a='a'/>";
assertEq(xml, parse(xd, xml, reporter));
assertNoErrorwarnings(reporter);
xdef = "<xd:def xmlns:xd='http://www.xdef.org/xdef/4.1' root='A'>\n" + "<A a=\"string(%base=false);\"/>\n" + "</xd:def>";
xp = compile(xdef);
xd = xp.createXDDocument();
xml = "<A a='a'/>";
assertEq(xml, parse(xd, xml, reporter));
if (!reporter.errors()) {
fail("Error expected");
}
xdef = "<xd:def xmlns:xd='http://www.xdef.org/xdef/4.1' root='A|B|C|D'>\n" + "<xd:declaration>\n" + " external method boolean test.xdef.TestTypes.tab0(XXNode, String, String);\n" + " boolean tab1(String a, String b){return true;}\n" + " Parser parser;\n" + " boolean b = true;\n" + "</xd:declaration>\n" + "<A a=\"string(%base=parser);\"/>\n" + "<B a=\"string(%base=tab0('a', 'b'));\"/>\n" + "<C a=\"string(%base=tab1('a', 'b'));\"/>\n" + "<D a=\"union(%item=[b, string(%base=b), true]);\"/>\n" + "</xd:def>";
xp = compile(xdef);
xd = xp.createXDDocument();
xd.setVariable("parser", new BoolParser());
xml = "<A a='a'/>";
assertEq(xml, parse(xd, xml, reporter));
assertNoErrorwarnings(reporter);
xd = xp.createXDDocument();
xml = "<B a='a'/>";
assertEq(xml, parse(xd, xml, reporter));
assertNoErrorwarnings(reporter);
xd = xp.createXDDocument();
xml = "<C a='a'/>";
assertEq(xml, parse(xd, xml, reporter));
assertNoErrorwarnings(reporter);
xd = xp.createXDDocument();
xml = "<D a='a'/>";
assertEq(xml, parse(xd, xml, reporter));
assertNoErrorwarnings(reporter);
// check xml schema types
xdef = "<xd:collection xmlns:xd='" + _xdNS + "'>\n" + "<xd:def xd:name='SchemaTypes'>\n" + " <xd:declaration scope='global'>\n" + " type ID ID();\n" + " type normalizedString normalizedString();\n" + " type tokens NMTOKENS();\n" + " type language language();\n" + " type Qname QName();\n" + " type NCname NCName();\n" + " type duration duration();\n" + " type dateTime xdatetime('yyyy-M-dTH:m[:s][ Z]');\n" + " type date xdatetime('yyyy-M-d');\n" + " type time xdatetime('H:m[:s]');\n" + " type gYearMonth xdatetime('yyyy-M');\n" + " type gYear xdatetime('yyyy');\n" + " type gMonthDay xdatetime('M-d');\n" + " type gDay xdatetime('d');\n" + " type gMonth xdatetime('M');\n" + " type base64Binary base64Binary(4);\n" + " type hexBinary hexBinary(3);\n" + " </xd:declaration>\n" + "</xd:def>\n" + "<xd:def xd:script='options preserveAttrWhiteSpaces,noTrimAttr'\n" + " xd:name='a' xd:root='a'>\n" + "<a string = \"required string(); onFalse out('string');\"\n" + " normalizedString = \"required normalizedString();\n" + " onFalse out('normalizedString');\"\n" + " tokens = \"required tokens(); onFalse out('token');\"\n" + " language = \"required language(); onFalse out('language');\"\n" + " Qname = \"required Qname(); onFalse out('name');\"\n" + " NCName = \"required NCname(); onFalse out('NCName');\"\n" + " ID = \"required ID(); onFalse out('ID');\"\n" + " ID1 = \"required ID(); onFalse out('ID1');\"\n" + " IDREF = \"required IDREF(); onFalse out('IDREF');\"\n" + " IDREFS = \"required IDREFS(); onFalse out('IDREFS');\"\n" + " duration = \"required duration(); onFalse out('duration');\"\n" + " dateTime = \"required dateTime(); onFalse out('dateTime');\"\n" + " date = \"required date(); onFalse out('date');\"\n" + " time = \"required time(); onFalse out('time');\"\n" + " gYearMonth = \"required gYearMonth(); onFalse out('gYearMonth');\"\n" + " gYear = \"required gYear(); onFalse out('gYear');\"\n" + " gMonthDay = \"required gMonthDay(); onFalse out('gMonthDay');\"\n" + " gDay = \"required gDay(); onFalse out('gDay');\"\n" + " gMonth = \"required gMonth(); onFalse out('gMonth');\"\n" + " boolean = \"required boolean(); onFalse out('boolean');\"\n" + " base64Binary = \"required base64Binary(); onFalse out('base64Binary');\"\n" + " hexBinary = \"required hexBinary(); onFalse out('hexBinary');\"\n" + " float = \"required float(); onFalse out('float');\"\n" + "/>\n" + "</xd:def>\n" + "</xd:collection>";
xml = "<a\n" + " string = ' a b c '\n" + " normalizedString = ' a b c '\n" + " tokens = ' a b c '\n" + " language = ' cs '\n" + " Qname = ' cs '\n" + " NCName = ' cs '\n" + " ID = ' cs '\n" + " ID1 = ' cs1 '\n" + " IDREF = ' cs '\n" + " IDREFS = ' cs cs1 '\n" + " duration = 'T1H'\n" + " dateTime = '1998-1-1T19:30'\n" + " date = '1998-1-1'\n" + " time = '19:30:1'\n" + " gYearMonth = '1998-1'\n" + " gYear = '1998'\n" + " gMonthDay = '1-1'\n" + " gDay = '1'\n" + " gMonth = '1'\n" + " boolean = '0'\n" + " base64Binary = '01abcQ=='\n" + " hexBinary = '01abcd'\n" + " float = '1.5e-7'\n" + "/>\n";
xp = compile(xdef);
el = parse(xp, "a", xml, reporter, null);
assertNoErrorwarnings(reporter);
assertEq(el.getAttribute("string"), " a b c ");
assertEq(el.getAttribute("normalizedString"), " a b c ");
assertEq(el.getAttribute("tokens"), "a b c");
assertEq(el.getAttribute("language"), "cs");
assertEq(el.getAttribute("Qname"), "cs");
assertEq(el.getAttribute("NCName"), "cs");
assertEq(el.getAttribute("ID"), "cs");
assertEq(el.getAttribute("ID1"), "cs1");
assertEq(el.getAttribute("IDREF"), "cs");
assertEq("cs cs1", el.getAttribute("IDREFS"));
assertEq("1998-1-1T19:30", el.getAttribute("dateTime"));
// country, countries
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<A a=\"country()\" b=\"countries()\"/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<A a='cz' b='CZE gb US CA SK RUS IT LY GE FRA SE usa IL' />";
el = parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
assertEq(xml, el);
// test emailAddr
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration>\n" + " final EmailAddr x=new EmailAddr('=?UTF-8?Q?Pavel B=C3=BDk?= <p@s>');\n" + "</xd:declaration>\n" + "<a email='emailAddr(); onTrue {\n" + " EmailAddr e = (EmailAddr) getParsedValue();\n" + " outln(getEmailUserName(e));\n" + " outln(getEmailLocalPart(e));\n" + " outln(getEmailDomain(e));\n" + " outln(getEmailAddr(e));\n" + " outln(getEmailUserName(x));\n" + " outln(getEmailAddr(x));\n" + " }' />\n" + "</xd:def>";
xml = "<a email='(T. tr) a@b'/>";
strw = new StringWriter();
assertEq(xml, parse(xdef, "", xml, reporter, strw, null, null));
strw.close();
assertNoErrorwarnings(reporter);
assertEq(strw.toString(), "T. tr\na\nb\n(T. tr) a@b\nPavel Býk\n=?UTF-8?Q?Pavel B=C3=BDk?= <p@s>\n");
} catch (Exception ex) {
fail(ex);
}
resetTester();
}
use of org.xdef.XDContainer in project xdef by Syntea.
the class Test002 method test.
@Override
public /**
* Run tests.
*/
void test() {
String xdef;
String xml;
XDPool xp;
XDDocument xd;
StringWriter strw;
ArrayReporter reporter = new ArrayReporter();
Report rep;
Element el;
String s;
final String dataDir = getDataDir() + "test/";
try {
xp = compile(dataDir + "Test002_1.xdef");
xml = dataDir + "Test002_1.xml";
parse(xp, "BPEL_com", xml, reporter);
if (!reporter.errors()) {
fail("Error not reported");
} else {
if (reporter.getErrorCount() != 2) {
while ((rep = reporter.getReport()) != null) {
fail(rep.toString());
}
ReportPrinter.printListing(System.err, new File(xml), reporter, true);
} else {
rep = reporter.getReport();
if ("XDEF501".equals(rep.getMsgID())) {
rep = reporter.getReport();
if (!"XDEF539".equals(rep.getMsgID())) {
fail(rep.toString());
}
} else if ("XDEF539".equals(rep.getMsgID())) {
rep = reporter.getReport();
if (!"XDEF501".equals(rep.getMsgID())) {
fail(rep.toString());
}
} else {
fail(rep.toString());
}
}
}
xp = compile(dataDir + "Test002_3.xdef");
strw = new StringWriter();
xml = dataDir + "Test002_3.xml";
parse(xp, "Example", xml, reporter, strw, null, null);
assertNoErrorwarnings(reporter);
assertEq("Example - start\n" + "partnerLinks\n" + "{{if(true)if(false);\n" + "else if(false);else\n" + "while(false){if(false);else\n" + "{;;}\n" + ";}\n" + "\n" + ";}}Example - end\n", strw.toString());
xdef = dataDir + "Test002_4.xdef";
xp = compile(xdef);
xml = dataDir + "Test002_4_1.xml";
strw = new StringWriter();
parse(xp, "DefSystemStatistics", xml, reporter, strw, null, null);
assertNoErrorwarnings(reporter);
xml = dataDir + "Test002_4_2.xml";
strw = new StringWriter();
parse(xp, "DefSystemStatistics", xml, reporter, strw, null, null);
assertNoErrorwarnings(reporter);
xdef = dataDir + "Test002_5.xdef";
xml = dataDir + "Test002_5.xml";
strw = new StringWriter();
parse(xdef, "instance", xml, reporter, strw, null, null);
assertNoErrorwarnings(reporter);
assertEq("", strw.toString());
// reference to element with match expression.
xdef = "<xdef:def xmlns:xdef='" + _xdNS + "' xdef:root='Select'>\n" + " <Select> \n" + " <inetOrgPerson xdef:script=\"ref inetOrgPersonDef; occurs 1\" />\n" + " </Select>\n" + " <inetOrgPersonDef>\n" + " <user xdef:script=\"ref userCertificateDef; occurs 0..\" />\n" + " </inetOrgPersonDef>\n" + " <userCertificateDef i.SerialNum=\"optional hexBinary()\"\n" + " i.Issuer=\"optional string()\"\n" + " xdef:script=\"match @i.SerialNum AAND @i.Issuer\"/>\n" + "</xdef:def>";
xml = "<Select>\n" + " <inetOrgPerson>\n" + " <user i.SerialNum=\"198b11d13f9a8ffe69a0\"/>\n" + " </inetOrgPerson>\n" + "</Select>";
parse(xdef, "", xml, reporter);
if (reporter.errors()) {
if (!"XDEF501".equals(reporter.getReport().getMsgID())) {
fail(reporter.printToString());
}
} else {
fail("error not reported");
}
// boolean operators
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<xd:declaration>\n" + " boolean t1() {out('t1'); return false;}\n" + " boolean t2() {out('t2'); return true;}\n" + " boolean t3() {return t1() OR t2();}\n" + "</xd:declaration>\n" + " <A a='t3()'>list(int(1,10))</A>\n" + "</xd:def>";
xml = "<A a='99'>1 2</A>";
strw = new StringWriter();
el = parse(xdef, "", xml, reporter, strw, null, null);
assertEq(xml, el);
assertNoErrorwarnings(reporter);
strw.close();
assertEq("t1t2", strw.toString());
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<xd:declaration>\n" + " boolean t1() {out('t1'); return false;}\n" + " boolean t2() {out('t2'); return true;}\n" + " boolean t3() {return t1() OR t2;}\n" + "</xd:declaration>\n" + " <A a='t3()'>list(%item=int(1,10))</A>\n" + "</xd:def>";
xml = "<A a='99'>1 2</A>";
strw = new StringWriter();
assertEq(xml, parse(xdef, "", xml, reporter, strw, null, null));
assertNoErrorwarnings(reporter);
strw.close();
assertEq("t1t2", strw.toString());
String oldProp = getProperty(XDConstants.XDPROPERTY_WARNINGS);
try {
// test ListOf with XDEF_3.1
setProperty(XDConstants.XDPROPERTY_WARNINGS, XDConstants.XDPROPERTYVALUE_WARNINGS_FALSE);
xdef = "<xd:def xmlns:xd='" + XDConstants.XDEF31_NS_URI + "' root='A'>\n" + "<xd:declaration>\n" + " boolean t1() {out('t1'); return false;}\n" + " boolean t2() {out('t2'); return true;}\n" + "</xd:declaration>\n" + " <A a='t1() OR t2'>ListOf(int(1,10))</A>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<A a='99'>1 2</A>";
strw = new StringWriter();
el = parse(xp, "", xml, reporter, strw, null, null);
assertEq(xml, el);
assertNoErrorwarnings(reporter);
strw.close();
assertEq("t1t2", strw.toString());
setProperty(XDConstants.XDPROPERTY_WARNINGS, XDConstants.XDPROPERTYVALUE_WARNINGS_TRUE);
compile(xdef);
fail("Error not thrown");
} catch (Exception ex) {
s = ex.getMessage();
if (s == null || !s.contains("E XDEF443")) {
fail(ex);
}
}
setProperty(XDConstants.XDPROPERTY_WARNINGS, XDConstants.XDPROPERTYVALUE_WARNINGS_TRUE);
setProperty(XDConstants.XDPROPERTY_WARNINGS, oldProp);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<xd:declaration>\n" + " boolean t1() {out('t1'); return false;}\n" + " boolean t2() {out('t2'); return true;}\n" + " boolean t3() {return t1() OOR t2;}\n" + "</xd:declaration>\n" + " <A a='t3()'>list(%item=int(1,10))</A>\n" + "</xd:def>";
xml = "<A a='99'>1 2</A>";
strw = new StringWriter();
assertEq(xml, parse(xdef, "", xml, reporter, strw, null, null));
assertNoErrorwarnings(reporter);
strw.close();
assertEq("t1t2", strw.toString());
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<xd:declaration>\n" + " boolean t1() {out('t1'); return false;}\n" + " boolean t2() {out('t2'); return true;}\n" + " boolean t3() {return t1() AND t2();}\n" + " int i = 1, j = 10;\n" + "</xd:declaration>\n" + " <A a='t3()'>list(%item=int(i,j))</A>\n" + "</xd:def>";
xml = "<A a='99'>1 2</A>";
strw = new StringWriter();
assertEq(xml, parse(xdef, "", xml, reporter, strw, null, null));
assertErrors(reporter);
strw.close();
assertEq("t1t2", strw.toString());
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<xd:declaration>\n" + " boolean t1() {out('t1'); return false;}\n" + " boolean t2() {out('t2'); return true;}\n" + " boolean t3() {return t1() AAND t2();}\n" + "</xd:declaration>\n" + " <A a='t3()'>list(%item=int(1,10))</A>\n" + "</xd:def>";
xml = "<A a='99'>1 2</A>";
strw = new StringWriter();
assertEq(xml, parse(xdef, "", xml, reporter, strw, null, null));
assertErrors(reporter);
strw.close();
assertEq("t1", strw.toString());
xdef = "<xd:def xmlns:xd='" + _xdNS + "' name='A' root='a'>\n" + "<a atr=\"optional string(); default 'abcd'\">\n" + " <xd:choice ref='action'/>\n" + "</a>\n" + "<xd:choice name='action'>\n" + "<B xd:script='ref B'/>\n" + "<C xd:script='ref C'/>\n" + "</xd:choice>\n" + "<B xd:script=\"finally outln('B')\"/>\n" + "<C xd:script=\"finally outln('C')\"/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a><C/></a>\n";
strw = new StringWriter();
el = parse(xp, "A", xml, reporter, strw, null, null);
assertNoErrorwarnings(reporter);
if (!"C\n".equals(strw.toString())) {
fail(strw.toString());
}
if (!"abcd".equals(el.getAttribute("atr"))) {
fail(el.getAttribute("atr"));
}
xml = "<a atr='wxyz'><C/></a>\n";
strw = new StringWriter();
el = parse(xp, "A", xml, reporter, strw, null, null);
assertNoErrorwarnings(reporter);
assertEq("C\n", strw.toString());
if (!"wxyz".equals(el.getAttribute("atr"))) {
fail(el.getAttribute("atr"));
}
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <a>\n" + " <ZmenaPS xd:script=\"occurs 1..; finally " + " {int i=errors(); if (i==6) out('OK'); else out('ERROR: ' + i);}\"" + " IdentZaznamu='required int()'\n" + " CisloSmlouvy='required int()'\n" + " CisloDokladuPojisteni='required int()'\n" + " PoradiVozidla='required int()'\n" + " DatumZmeny='required int()' >\n" + " <b/>\n" + " </ZmenaPS>\n" + " </a>\n" + "</xd:def>\n";
xml = "<a><ZmenaPS>\n IdentZaznamu='1'\n" + "CisloSmlouvy='3000074848' CisloDokladuPojisteni='3000074848'\n" + " PoradiVozidla='1' DatumZmeny='20060101'>\n" + "<b/>" + "</ZmenaPS>" + "</a>";
strw = new StringWriter();
parse(xdef, "", xml, reporter, strw, null, null);
assertEq(6, reporter.getErrorCount());
assertTrue(reporter.printToString().indexOf("XDEF526") > 0 && reporter.printToString().indexOf("XDEF534") > 0, "Error not reported");
assertEq("OK", strw.toString());
xdef = "<xd:collection xmlns:xd='" + _xdNS + "'>\n" + "<xd:declaration>\n" + " external method void test.xdef.Test002.setHeaderEl();\n" + " external method void test.xdef.Test002.setRequestEl();\n" + " external method void test.xdef.Test002.setKodPartnera();\n" + "</xd:declaration>\n" + "<xd:def xmlns:s='http://www.w3c.org/2003/05/soap-envelope'\n" + " xmlns:p='http://ws.ckp.cz/pis/B1/2006/10'\n" + " impl-version='0.0.1' impl-date='18.9.2006' root='s:Envelope'>\n" + "<xd:macro\n" + "name=\"moreAll\">options moreAttributes,moreElements,moreText;</xd:macro>\n" + "<s:Envelope xd:script=\"occurs 1\"\n" + " s:encodingStyle=\"fixed 'http://www.syntea.cz/ckp/pis/encoding'\">\n" + " <s:Header xd:script=\"occurs 0..1; finally setHeaderEl()\">\n" + " <p:Request xd:script=\"occurs 1;\n" + " options moreAttributes,moreElements; finally setRequestEl()\"\n" + " KodPartnera=\"optional; onTrue setKodPartnera()\"\n" + " s:mustUnderstand=\"required enum('true','1')\"/>\n" + " </s:Header>\n" + " <s:Body xd:script=\"occurs 1\">\n" + " <xd:choice>\n" + " <p:Ping xd:script=\"occurs 1; ${moreAll}\"/>\n" + " <p:PingFlow xd:script=\"occurs 1; ${moreAll}\"/>\n" + " <p:Get_PSP xd:script=\"occurs 1; ${moreAll}\"/>\n" + " <p:Get_VolnePSP xd:script=\"occurs 1; ${moreAll}\"/>\n" + " <p:Get_NositelPSP xd:script=\"occurs 1; ${moreAll}\"/>\n" + " <p:Get_SmlouvyPSP xd:script=\"occurs 1; ${moreAll}\"/>\n" + " <p:Set_PrenosPSP xd:script=\"occurs 1; ${moreAll}\"/>\n" + " <p:Set_MultiPrenosPSP xd:script=\"occurs 1; ${moreAll}\"/>\n" + " <p:Set_BlokujPSP xd:script=\"occurs 1; ${moreAll}\"/>\n" + " <p:Set_UvolniPSP xd:script=\"occurs 1; ${moreAll}\"/>\n" + " </xd:choice>\n" + " </s:Body>\n" + "</s:Envelope>\n" + "</xd:def>\n" + "</xd:collection>";
xp = compile(xdef);
xml = "<?xml version=\"1.0\"?>\n" + "<s:Envelope xmlns:s=\"http://www.w3c.org/2003/05/soap-envelope\"\n" + " xmlns:p=\"http://ws.ckp.cz/pis/B1/2006/10\"\n" + " s:encodingStyle=\"http://www.syntea.cz/ckp/pis/encoding\">\n" + " <s:Header>\n" + " <p:Request KodPartnera=\"0001\" IdentZpravy=\"154\"\n" + " RefMsgID=\"123\" s:mustUnderstand=\"true\" />\n" + " </s:Header>\n" + " <s:Body>\n" + " <p:Ping/>\n" + " </s:Body>\n" + "</s:Envelope>";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<q:Envelope xmlns:q=\"http://www.w3c.org/2003/05/soap-envelope\"\n" + " xmlns:p=\"http://ws.ckp.cz/pis/B1/2006/10\"\n" + " q:encodingStyle=\"http://www.syntea.cz/ckp/pis/encoding\">\n" + " <p:Header>\n" + " <q:Request KodPartnera=\"0001\" IdentZpravy=\"154\"\n" + " RefMsgID=\"123\" q:mustUnderstand=\"true\" />\n" + " </p:Header>\n" + " <q:Body>\n" + " <q:Ping/>\n" + " </q:Body>\n" + "</q:Envelope>";
reporter = new ArrayReporter();
parse(xp, "", xml, reporter);
if (!reporter.errorWarnings()) {
fail("No errors reported!");
} else if ((rep = reporter.getReport()) == null || rep.getModification().indexOf("&{0}p:Header") < 0 || rep.getModification().indexOf("&{xpath}/q:Envelope") < 0 || (rep = reporter.getReport()) == null || rep.getModification().indexOf("&{xpath}/q:Envelope/q:Body") < 0 || (rep = reporter.getReport()) == null || rep.getModification().indexOf("&{0}q:Ping") < 0 || rep.getModification().indexOf("&{xpath}/q:Envelope/q:Body") < 0 || reporter.getReport() != null) {
reporter.reset();
fail(reporter.printToString());
}
xdef = "<xd:def xmlns:xd='" + _xdNS + "'>\n" + "<a a=\"required; create '1'\" >\n" + " <b xd:script=\"create from('/b')\"\n" + " y=\"required; create from('/b/@x')\">\n" + " <c xd:script = \"create from('c')\"\n" + // tady by melo vzit 3
" z=\"required; create from('@x')\"\n" + " c=\"required\"/>\n" + " </b>\n" + " </a>\n" + "</xd:def>";
xml = "<b x=\"2\"><c c=\"c\" x=\"3\"/></b>";
assertEq(create(xdef, "", "a", reporter, xml), "<a a=\"1\"><b y=\"2\"><c z=\"3\" c=\"c\"/></b></a>");
assertNoErrorwarnings(reporter);
xdef = "<xd:collection xmlns:xd='" + _xdNS + "'>\n" + "<xd:declaration>\n" + " external method String test.xdef.Test002.getIdPrace();\n" + "</xd:declaration>\n" + "<xd:def name='test' impl-version='2.4.1.0' impl-date='28.12.2006'>\n" + "<Set_BlokujPSP_\n" + " IdPrace=\"required int(); create getIdPrace()\" >\n" + " <Set_BlokujPSP xd:script=\"occurs 1; ref B1_common_#Set_BlokujPSP\" />\n" + "</Set_BlokujPSP_>\n" + "</xd:def>\n" + "\n" + "<xd:def xd:name= 'B1_common_'>\n" + "<Set_BlokujPSP xd:script=\"create from('/Set_BlokujPSP')\"\n" + " IdPojistitel =\"required; create from('@KodPojistitele')\" >\n" + " <ZdrojovaSmlouva xd:script=\"occurs 1; ref Id_Smlouva;\n" + " create from('ZdrojovaSmlouva')\" />\n" + "</Set_BlokujPSP>\n" + "<Id_Smlouva\n" + // tady by melo vzit 62
" IdPojistitel=\"required; create from('@KodPojistitele')\"\n" + " CisloSmlouvy=\"required\"\n" + " PoradiVozidla=\"required\"/>\n" + "</xd:def>\n" + "</xd:collection>\n";
reporter = new ArrayReporter();
xp = compile(xdef);
xml = "<Set_BlokujPSP KodPojistitele=\"0002\">" + "<ZdrojovaSmlouva PoradiVozidla=\"1\"" + " CisloSmlouvy=\"3060000030\"" + " KodPojistitele=\"0062\"/>" + "</Set_BlokujPSP>";
strw = new StringWriter();
el = create(xp, "test", "Set_BlokujPSP_", reporter, xml, strw, null);
assertNoErrorwarnings(reporter);
assertEq("", strw.toString());
s = ((Element) el.getChildNodes().item(0).getChildNodes().item(0)).getAttribute("IdPojistitel");
assertEq("0062", s, KXmlUtils.nodeToString(el, true));
// we try array of xdefinitions
String xdef0, xdef1, xdef2, xdef3, data;
xdef0 = "<x:declaration xmlns:x='" + _xdNS + "'>\n" + " external method boolean test.xdef.Test002.tab(String, String);\n" + " external method void test.xdef.Test002.setErr(XXNode, long);\n" + " external method boolean test.xdef.Test002.fil0(long);\n" + " external method String test.xdef.Test002.modelVozidlaNeuveden();\n" + " external method void test.xdef.Test002.setNullIfZero();\n" + " boolean myTest() {\n" + " return fil0(2) AND tab('CC_DruhVozidla','KodDruhuVozidla');\n" + " }\n" + "</x:declaration>";
xdef1 = "<x:def xmlns:x='" + _xdNS + "' name='P1_common'>\n" + "<Vozidlo\n" + " CisloTP =\"optional string(%pattern='[A-Z]{2}[0-9]{5,6}');\n" + " onFalse setErr(4208)\"\n" + " VIN =\"optional string(1,26); onFalse setErr(4208)\"\n" + " SPZ =\"optional string(2,12); onFalse setErr(4208)\"\n" + " DruhVozidla =\"required myTest();\n" + " onFalse setErr(4226); onAbsence setErr(4202)\"\n" + " ZnackaText =\"optional string(1,30); onFalse setErr(4208)\"\n" + " ModelText =\"optional string(1,40); onFalse setErr(4208)\"\n" + " KodModeluVozidla=\"required tab('CC_ModelVozidla','KodModeluVozidla');\n" + " onFalse setErr(4225);\n" + " onAbsence setText(modelVozidlaNeuveden())\"\n" + " RokDoProvozu =\"optional xdatetime('yyyy'); onFalse setErr(4208)\"\n" + " BarvaText =\"optional string(1,20); onFalse setErr(4208)\"\n" + " ZdvihovyObjem =\"optional int(0,99_999); onTrue setNullIfZero();\n" + " onFalse setErr(4208)\"\n" + " VykonMotoru =\"optional int(0,9_999); onTrue setNullIfZero();\n" + " onFalse setErr(4208)\"\n" + " CisloMotoru =\"optional string(1,26); onFalse setErr(4208)\"\n" + " CelkovaHmotnost =\"optional int(1,999_999); onFalse setErr(4208)\"\n" + " PocetMistCelkem =\"optional int(0,999); onTrue setNullIfZero();\n" + " onFalse setErr(4208)\"/>\n" + "</x:def>";
xdef2 = "<x:def xmlns:x='" + _xdNS + "' name='test' root='a'>\n" + "<a>\n" + "<Vozidlo x:script='occurs 0..1; ref P1_common#Vozidlo'\n" + " KodModeluVozidla=\"optional tab('CC_ModelVozidla','KodModeluVozidla');\n" + " onFalse setErr(4225)\" />\n" + "</a>\n" + "</x:def>";
xdef3 = "<x:def xmlns:x='" + _xdNS + "' name='test1' root='a'>\n" + "<a>\n" + " <Vozidlo x:script='occurs 0..1; ref P1_common#Vozidlo'\n" + " DruhVozidla=\"optional myTest(); onFalse setErr(4225)\"\n" + " KodModeluVozidla=\"optional tab('CC_ModelVozidla','KodModeluVozidla');\n" + " onFalse setErr(4225)\" />\n" + "</a>\n" + "</x:def>\n";
String[] xdefs = new String[] { xdef0, xdef1, xdef2, xdef3 };
data = "<a><Vozidlo SPZ=\"6A84013\" /></a>";
_errorCount = 0;
_errorCode = 0;
// should be reported 4202
if (test(xdefs, data, "test", 'P', "<a><Vozidlo SPZ=\"6A84013\" /></a>", "")) {
fail();
}
if (_errorCount != 1) {
fail("Errors: " + _errorCount);
}
if (_errorCode != 4202) {
fail("ErrorCode: " + _errorCode);
}
data = "<a><Vozidlo SPZ=\"6A84013\" /></a>";
_errorCount = 0;
_errorCode = 0;
if (test(xdefs, data, "test1", 'P', "<a><Vozidlo SPZ=\"6A84013\" /></a>", "")) {
fail();
}
if (_errorCount != 0) {
fail("Errors: " + _errorCount);
}
if (_errorCode != 0) {
fail("ErrorCode: " + _errorCode);
}
data = "<a><Vozidlo SPZ=\"6A84013\" /></a>";
_errorCount = 0;
_errorCode = 0;
if (test(xdefs, data, "test1", 'P', "<a><Vozidlo SPZ=\"6A84013\" /></a>", "")) {
fail();
}
if (_errorCount != 0) {
fail("Errors: " + _errorCount);
}
if (_errorCode != 0) {
fail("ErrorCode: " + _errorCode);
}
// ///////// now we check files and input stream
File[] files = SUtils.getFileGroup(dataDir + "test002_2_*.xdef");
InputStream data1 = new FileInputStream(dataDir + "test002_2.xml");
_errorCount = 0;
_errorCode = 0;
// should be reported 4202
test(files, data1, "SouborP1A", null, reporter, 'P');
if (_errorCount != 1 || _errorCode != 4202) {
fail("ErrorCount:" + _errorCount + ", errorCode:" + _errorCode);
}
_errorCount = 0;
_errorCode = 0;
xp = compile(dataDir + "test002_2a_1.xdef");
parse(xp, "SouborP1A", dataDir + "test002_2.xml", reporter);
// should be reported 4202
if (_errorCount != 1 || _errorCode != 4202) {
fail("ErrorCount:" + _errorCount + ", errorCode:" + _errorCode);
}
} catch (Exception ex) {
fail(ex);
}
try {
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<x:declaration xmlns:x='" + _xdNS + "'>\n" + " external method boolean test.xdef.Test002.unknown(XXData, XDValue[]);\n" + " external method boolean test.xdef.Test002.known(XXData);\n" + " boolean t1() {return unknown() OOR string(%pattern='[A-Z]{2}[0-9]{6}');}\n" + " boolean t2() {return NOT known() || string(%pattern='[A-Z]{2}[0-9]{6}');}\n" + "</x:declaration>\n" + " <a a1=\"optional t1(); onFalse out('ERR1')\"\n" + " a2=\"optional t2(); onFalse out('ERR2')\"/>\n" + "</xd:def>\n";
xml = "<a a1='???' a2='???'/>";
assertFalse(test(xdef, xml, "", 'P', xml, ""));
xml = "<a a1='AA999991' a2='AA999992'/>";
assertFalse(test(xdef, xml, "", 'P', xml, ""));
// test macros, errors etc.
xdef = dataDir + "Test002_6.xdef";
xml = dataDir + "Test002_6.xml";
strw = new StringWriter();
assertEq(xml, parse(xdef, "LDN", xml, reporter, strw, null, null));
assertEq(strw.toString(), "XDOUT: ISDN_LDN - ISDN4202/DnSearch/@KodNdnDuvodLustrace\n");
s = reporter.printToString("slk");
assertTrue(s.indexOf("ISDN4202:") > 0 && // s.indexOf("XDEF526:") > 0 && s.indexOf("riadok") > 0, s);
s.indexOf("XDEF526:") > 0, s);
// external methods
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<A xd:script=\"finally {out(tab('a', 'b')); pp()}\" />\n" + "<xd:declaration>\n" + " external method boolean test.xdef.Test002.tab(String, String);\n" + " void pp() {\n" + " out(',' + tab('a', 'b') + ',' + test.xdef.Test002.tab('a', 'b'));\n" + " }\n" + "</xd:declaration>\n" + "</xd:def>\n";
strw = new StringWriter();
assertEq("<A/>", parse(xdef, "", "<A/>", reporter, strw, null, null));
assertNoErrorwarnings(reporter);
assertEq(strw.toString(), "true,true,true");
// force compilation of test.xdef.TestExtenalMethods_1;
test.xdef.TestExtenalMethods_1.class.getClass();
// force compilation of test.xdef.Test002;
test.xdef.Test002.class.getClass();
// external methods in global declaration section
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration scope='global'>\n" + " external method {\n" + " void test.xdef.TestExtenalMethods_1.m00() as x;\n" + " void test.xdef.TestExtenalMethods_1.m00(long) as x;\n" + " boolean test.xdef.Test002.tab(String, String) as x;\n" + " }\n" + " void pp() {\n" + " x(); x(1);\n" + " out(x('a','b')+','+ x('a','b')+','+ test.xdef.Test002.tab('a','b'));\n" + " }\n" + "</xd:declaration>\n" + "<a xd:script=\"finally {x(); x(2); x('a','b'); pp()}\" />\n" + "</xd:def>\n";
strw = new StringWriter();
assertEq("<a/>", parse(xdef, "", "<a/>", reporter, strw, null, null));
assertNoErrorwarnings(reporter);
assertEq(strw.toString(), "true,true,true");
// external methods in local declaration section
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration scope='local'>\n" + " external method {\n" + " void test.xdef.TestExtenalMethods_1.m00() as x;\n" + " void test.xdef.TestExtenalMethods_1.m00(long) as x;\n" + " boolean test.xdef.Test002.tab(String, String) as x;\n" + " }\n" + " void pp() {\n" + " x(); x(1);\n" + " out(x('a','b')+','+x('a','b')+','+ test.xdef.Test002.tab('a','b'));\n" + " }\n" + "</xd:declaration>\n" + "<a xd:script=\"finally {x(); x(2); x('a','b'); pp()}\" />\n" + "</xd:def>\n";
strw = new StringWriter();
assertEq("<a/>", parse(xdef, "", "<a/>", reporter, strw, null, null));
assertNoErrorwarnings(reporter);
assertEq(strw.toString(), "true,true,true");
// xpos
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='root'>\n" + "<root>\n" + " <A b='required xdatetime(\"dd.MM.yyyy\")'/>\n" + " <A b='required xdatetime(\"yyyy\")' />\n" + " <A b='required xdatetime(\"yyyy.MM.dd\")' />\n" + "</root>\n" + "</xd:def>";
xml = "<root>\n" + " <A b='12.02.2011' />\n" + " <A b='12.02.2011' />\n" + " <A b='12.02.2011' />\n" + "</root>";
parse(xdef, "", xml, reporter);
assertTrue(reporter.errorWarnings());
assertEq(reporter.size(), 2);
if (reporter.size() == 2) {
String xpath = reporter.getReport().getParameter("xpath");
assertEq(xpath, "/root/A[2]/@b");
xpath = reporter.getReport().getParameter("xpath");
assertEq(xpath, "/root/A[3]/@b");
}
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='root'>\n" + "<root>\n" + " <B>" + " <A b='required xdatetime(\"yyyy.MM.dd\")' />\n" + " </B>" + " <B>" + " <A b='required xdatetime(\"yyyy.MM.dd\")' />\n" + " </B>" + "</root>\n" + "</xd:def>";
xml = "<root>\n" + " <B><A b='12.02.2011' /></B>\n" + " <B><A b='12.02.2011' /></B>\n" + "</root>";
parse(xdef, "", xml, reporter);
assertTrue(reporter.errorWarnings());
assertEq(reporter.size(), 2);
if (reporter.size() == 2) {
String xpath = reporter.getReport().getParameter("xpath");
assertEq(xpath, "/root/B[1]/A[1]/@b");
xpath = reporter.getReport().getParameter("xpath");
assertEq(xpath, "/root/B[2]/A[1]/@b");
}
// create mode
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='root'>\n" + "<root>\n" + " <A b='required xdatetime(\"dd.MM.yyyy\"); create \"12.02.2011\" '/>\n" + " <A b='required xdatetime(\"yyyy\"); create \"12.02.2011\"' />\n" + " <A b='required xdatetime(\"yyyy.MM.dd\"); create \"12.02.2011\"' />\n" + "</root>\n" + "</xd:def>";
create(xdef, "", "root", reporter, null);
assertTrue(reporter.errorWarnings());
assertEq(reporter.size(), 2);
if (reporter.size() == 2) {
String xpath = reporter.getReport().getParameter("xpath");
assertEq(xpath, "/root/A[2]/@b");
xpath = reporter.getReport().getParameter("xpath");
assertEq(xpath, "/root/A[3]/@b");
}
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='root'>\n" + "<root>\n" + " <B>" + " <A b='required xdatetime(\"yyyy.MM.dd\"); create \"12.02.2011\"' />\n" + " </B>" + " <B>" + " <A b='required xdatetime(\"yyyy.MM.dd\"); create \"12.02.2011\"' />\n" + " </B>" + "</root>\n" + "</xd:def>";
create(xdef, "", "root", reporter, null);
assertTrue(reporter.errorWarnings());
assertEq(reporter.size(), 2);
if (reporter.size() == 2) {
String xpath = reporter.getReport().getParameter("xpath");
assertEq(xpath, "/root/B[1]/A[1]/@b");
xpath = reporter.getReport().getParameter("xpath");
assertEq(xpath, "/root/B[2]/A[1]/@b");
}
} catch (Exception ex) {
fail(ex);
}
try {
// errors of missing external methods
xdef = "<xd:def xmlns:xd='" + _xdNS + "'>\n" + " <A i=\"int; onTrue oti(@i); onFalse ofi(1, '1', @i)\"\n" + " xd:script=\"onAbsence oaa(); onExcess oea()\"/>\n" + " <xd:declaration>\n" + " void oaa() {\n" + " Container c = [];\n" + " Element e = new Element('B');" + " ext(c, e);\n" + " }\n" + " </xd:declaration>\n" + "</xd:def>";
compile(xdef);
fail("Error not reported");
} catch (Exception ex) {
if ((s = ex.getMessage()) == null) {
fail(ex);
} else {
// parts of error messages that should be in the message
assertTrue(s.indexOf("oti(String)") >= 0, ex.getMessage());
assertTrue(s.indexOf("ofi(int,String,String)") >= 0);
assertTrue(s.indexOf("ext(Container,Element)") >= 0);
assertTrue(s.indexOf("oea()") >= 0);
}
}
try {
// XDef compilator error: Ambiguous
xml = "<a><A/><A/><A/><A/></a>";
assertEq(xml, parse("<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<a>\n" + " <A xd:script='2..2'/>\n" + " <A/>\n" + " <A/>\n" + "</a>\n" + "</xd:def>", "", xml, reporter));
assertNoErrorwarnings(reporter);
} catch (Exception ex) {
fail(ex);
}
try {
XDBuilder xb = XDFactory.getXDBuilder(null);
xb.setSource("<xd:def xmlns:xd='" + _xdNS + "' name='a' root='root'>\n" + "<root xd:script='init i = 1; finally out(i);'>\n" + " <a xd:script='1..2; ref b#A; finally {out(j); j = i; i = 2;}'>\n" + " </a>\n" + "</root>\n" + "</xd:def>");
xb.setSource("<xd:def xmlns:xd='" + _xdNS + "' name='b'>\n" + " <A xd:script='init j = 3;'/>\n" + "<xd:declaration scope='global'>\n" + " int i;\n" + " int j;\n" + "</xd:declaration>\n" + "</xd:def>");
xp = checkExtObjects(xb.compileXD());
strw = new StringWriter();
xml = "<root><a/><a/></root>";
assertEq(xml, parse(xp, "a", xml, reporter, strw, null, null));
assertNoErrorwarnings(reporter);
assertEq("332", strw.toString());
// check declaration sequence independence
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <xd:declaration> int j = k; </xd:declaration>\n" + " <xd:declaration>\n" + " int k = 1; int y = x, i = 0;\n" + " void h() {if (i != 0 || k != 1 || x != 1 || y != 1) outln('error');}\n" + " </xd:declaration>\n" + " <a xd:script = \"finally {h(); if (k != 1) outln('error');}\"/>\n" + " <xd:declaration> int x = 1; </xd:declaration>\n" + "</xd:def>";
strw = new StringWriter();
xml = "<a/>";
assertEq(xml, parse(xdef, "", xml, reporter, strw, null, null));
assertNoErrorwarnings(reporter);
assertEq("", strw.toString());
xdef = "<xd:collection xmlns:xd='" + _xdNS + "'>\n" + "<xd:def name='a'>\n" + " <xd:declaration scope='global'> int j = k; </xd:declaration>\n" + "</xd:def>\n" + "<xd:def name='b' root='a'>\n" + " <a xd:script = \"finally {h(); if (k != 1) outln('error');}\"/>\n" + " <xd:declaration scope='global'>\n" + " int k = 1, y = x, i = 0;\n" + " void h() {if (i != 0 || k != 1 || x != 1 || y != 1) outln('error');}\n" + " </xd:declaration>\n" + " <xd:declaration scope='global'> int x = 1; </xd:declaration>\n" + "</xd:def>\n" + "</xd:collection>\n";
strw = new StringWriter();
xml = "<a/>";
assertEq(xml, parse(xdef, "b", xml, reporter, strw, null, null));
assertNoErrorwarnings(reporter);
assertEq("", strw.toString());
// fixed
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root ='a'>\n" + " <a a=\"fixed 'abc'\" />\n" + "</xd:def>";
xp = compile(xdef);
assertEq("<a a='abc'/>", parse(xp, "", "<a/>", reporter));
assertNoErrorwarnings(reporter);
assertEq("<a a='abc'/>", parse(xp, "", "<a/>", reporter));
assertNoErrorwarnings(reporter);
assertEq("<a a='abc'/>", parse(xp, "", "<a a='123'/>", reporter));
s = reporter.printToString();
assertTrue(s.indexOf("XDEF515") > 0, s);
xdef = "<xd:def xmlns:xd = '" + _xdNS + "' root ='a'>\n" + " <a a='fixed xx;'/>\n" + " <xd:declaration>\n" + " String xx = 'abc';\n" + " </xd:declaration>\n" + "</xd:def>";
xp = compile(xdef);
assertEq("<a a='abc'/>", parse(xp, "", "<a/>", reporter));
assertNoErrorwarnings(reporter);
assertEq("<a a='abc'/>", parse(xp, "", "<a/>", reporter));
assertNoErrorwarnings(reporter);
assertEq("<a a='abc'/>", parse(xp, "", "<a a='123'/>", reporter));
s = reporter.printToString();
assertTrue(s.indexOf("XDEF515") > 0, s);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <a a='fixed xx;'/>\n" + " <xd:declaration>\n" + " String xx = 'abc';\n" + " </xd:declaration>\n" + "</xd:def>";
xp = compile(xdef);
assertEq("<a a='abc'/>", parse(xp, "", "<a/>", reporter));
assertNoErrorwarnings(reporter);
assertEq("<a a='abc'/>", parse(xp, "", "<a a='123'/>", reporter));
s = reporter.printToString();
assertTrue(s.indexOf("XDEF515") > 0, s);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root ='a'>\n" + " <a a=\"fixed {return 'abc';}\" />\n" + "</xd:def>";
xp = compile(xdef);
assertEq("<a a='abc'/>", parse(xp, "", "<a/>", reporter));
assertNoErrorwarnings(reporter);
assertEq("<a a='abc'/>", parse(xp, "", "<a a='123'/>", reporter));
s = reporter.printToString();
assertTrue(s.indexOf("XDEF515") > 0, s);
// test expression in validation section
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<a a='union(%item=[float, int, boolean]);'></a>" + "</xd:def>";
xp = compile(xdef);
parse(xp, "", "<a a='3.14'/>", reporter);
assertNoErrorwarnings(reporter);
parse(xp, "", "<a a='3'/>", reporter);
assertNoErrorwarnings(reporter);
parse(xp, "", "<a a='true'/>", reporter);
assertNoErrorwarnings(reporter);
parse(xp, "", "<a a='X'/>", reporter);
// E XDEF515: Chybná hodnota
assertTrue(reporter.errorWarnings());
// test getXPos
xdef = "<x:def xmlns:x='" + _xdNS + "' root='a'>\n" + "<a x = 'string; finally out(getXPos())'>\n" + " <b y = 'string; finally out(getXPos())'>\n" + " string; finally out(getXPos())\n" + " </b>\n" + "</a>\n" + "</x:def>";
xp = compile(xdef);
xml = "<a x='a'><b y='b'>c</b></a>";
strw = new StringWriter();
assertEq(xml, parse(xp, null, xml, reporter, strw, null, null));
assertNoErrorwarnings(reporter);
assertEq(strw.toString(), "/a/b[1]/text()/a/b[1]/@y/a/@x");
strw = new StringWriter();
assertEq(xml, create(xp, null, "a", reporter, xml, strw, null));
assertNoErrorwarnings(reporter);
assertEq(strw.toString(), "/a/b[1]/text()/a/b[1]/@y/a/@x");
xdef = "<x:def xmlns:x='" + _xdNS + "' root='a'>\n" + "<x:declaration>\n" + " external method String test.xdef.Test002.testGetXPos(XXNode);\n" + "</x:declaration>\n" + "<a x = 'string; finally out(testGetXPos())'>\n" + " <b y = 'string; finally out(testGetXPos())'>\n" + " string; finally out(testGetXPos())\n" + " </b>\n" + "</a>\n" + "</x:def>";
xp = compile(xdef);
xml = "<a x='a'><b y='b'>c</b></a>";
strw = new StringWriter();
assertEq(xml, parse(xp, null, xml, reporter, strw, null, null));
assertNoErrorwarnings(reporter);
assertEq(strw.toString(), "/a/b[1]/text()/a/b[1]/@y/a/@x");
// Create document from model of element.
xdef = "<xd:def xmlns:xd='" + _xdNS + "'>\n" + " <b><a x='required'>required;</a></b>\n" + "</xd:def>";
xp = compile(xdef);
XMDefinition xmd = xp.getXMDefinition();
XMElement xmel = (XMElement) xmd.getModel("", "b").getChildNodeModels()[0];
xd = xmel.createXDDocument();
xml = "<a x='x'>x</a>";
parse(xd, xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a x='xxx'>xxx</a>";
xd = xp.createXDDocument();
xd.setRootModel(xmel);
parse(xd, xml, reporter);
assertNoErrorwarnings(reporter);
// test MD5
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <a x='MD5'/>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a x='e4d909c290d0fb1ca068ffaddf22cbd0'/>";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a x=' e4d909c290d0fb1ca068ffaddf22cbd0 '/>";
parse(xp, "", xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a x='e4d909c290d0fb1c a068ffaddf22cbd0'/>";
parse(xp, "", xml, reporter);
assertErrors(reporter);
xml = "<a x='e4d909c290d0fb1ca 068ffaddf22cbd0'/>";
parse(xp, "", xml, reporter);
assertErrors(reporter);
xml = "<a x='e4d909c290d0fb1ca068ffaddf22cbd'/>";
parse(xp, "", xml, reporter);
assertErrors(reporter);
xml = "<a x='e4d909c290d0fb1c a068ffaddf22cbd'/>";
parse(xp, "", xml, reporter);
assertErrors(reporter);
xml = "<a x='e4d909c290d0fb1ca068ffaddf22cb'/>";
parse(xp, "", xml, reporter);
assertErrors(reporter);
xml = "<a x=''/>";
parse(xp, "", xml, reporter);
assertErrors(reporter);
// test hex
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <a><b xd:script='+' a=\"hexBinary()\" /></a>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a><b a='00' /></a>";
el = parse(xp, null, xml, reporter);
assertNoErrorwarnings(reporter);
assertEq(el, "<a><b a='00'/></a>");
xml = "<a><b a='01'/></a>";
parse(xp, null, xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a><b a='0012'/></a>";
parse(xp, null, xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a><b a='01 02'/></a>";
assertNoErrorwarnings(reporter);
xml = "<a><b a=' 000102 '/></a>";
parse(xp, null, xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a><b a=' 0aBc '/></a>";
parse(xp, null, xml, reporter);
assertNoErrorwarnings(reporter);
xml = "<a><b a='XX'/></a>";
parse(xp, null, xml, reporter);
assertErrors(reporter);
// test XMPool.findModel
xdef = "<xd:collection xmlns:xd='" + _xdNS + "'>\n" + "<xd:def root='a|b#b'>\n" + "<a a='int'>\n" + " int\n" + " <b b='int'>int<c/>int<d/><c/></b>\n" + " int\n" + " <b c='int'><c a='int'/>float</b>\n" + "</a>\n" + "</xd:def>\n" + "<xd:def name='b'>\n" + " <b c='int'>int<c/>int<d/><c/></b>\n" + "</xd:def>\n" + "<xd:def name='c'>\n" + " <b c='int'>\n" + " <b>string</b>\n" + " <b xd:script='match @a' a='?'/>\n" + " <xd:mixed>\n" + " <b xd:script='match @b' b='?'/>\n" + " <b>string</b>\n" + " <c>\n" + " <b xd:script='match @c' c='?'/>\n" + " <xd:mixed>\n" + " <b xd:script='match @d' d='?'/>\n" + " <b/>\n" + " <c/>\n" + " <xd:choice>\n" + " <d/>\n" + " <e/>\n" + " </xd:choice>\n" + " </xd:mixed>\n" + " </c>\n" + " </xd:mixed>\n" + " <b xd:script='match @e' e='?'/>\n" + " <xd:mixed>\n" + " <b xd:script='match @f' f='?'/>\n" + " <b>string</b>\n" + " <d/>\n" + " </xd:mixed>\n" + " <b xd:script='match @g' g='?'/>\n" + " </b>\n" + "</xd:def>\n" + "<xd:def name='d'>\n" + " <xd:mixed name='dd'>\n" + " <b xd:script='match @f' f='?'/>\n" + " <b>string</b>\n" + " <d/>\n" + " </xd:mixed>\n" + "</xd:def>\n" + "</xd:collection>";
xp = compile(xdef);
assertEq("#", xp.findModel("#").getXDPosition());
assertEq("#", xp.findModel("").getXDPosition());
assertEq("b#", xp.findModel("b#").getXDPosition());
assertEq("b#", xp.findModel("b").getXDPosition());
assertEq("c#", xp.findModel("c#").getXDPosition());
assertEq("#a", xp.findModel("#a").getXDPosition());
assertEq("#a", xp.findModel("#/a").getXDPosition());
assertEq("#a/$text", xp.findModel("#/a/$text").getXDPosition());
assertEq("#a/$text", xp.findModel("#/a/$text[1]").getXDPosition());
assertEq("#a/$text[2]", xp.findModel("#/a/$text[2]").getXDPosition());
assertEq("#a/b", xp.findModel("#/a/b").getXDPosition());
assertEq("#a/b", xp.findModel("#/a/b[1]").getXDPosition());
assertEq("#a/b/@b", xp.findModel("#/a/b/@b").getXDPosition());
assertEq("#a/b/@b", xp.findModel("#/a/b[1]/@b").getXDPosition());
assertEq("#a/b[2]/@c", xp.findModel("#/a/b[2]/@c").getXDPosition());
assertEq("#a/b/c", xp.findModel("#/a/b/c").getXDPosition());
assertEq("#a/b/c", xp.findModel("#/a[1]/b[1]/c[1]").getXDPosition());
assertEq("#a/b/c[2]", xp.findModel("#/a[1]/b/c[2]").getXDPosition());
assertEq("#a/b/$text", xp.findModel("#a/b/$text").getXDPosition());
assertEq("#a/b/$text", xp.findModel("#a/b/$text[1]").getXDPosition());
assertEq("#a/b/$text[2]", xp.findModel("#a/b/$text[2]").getXDPosition());
assertEq("b#b", xp.findModel("b#/b").getXDPosition());
assertEq("b#b/@c", xp.findModel("b#b/@c").getXDPosition());
assertEq("b#b/c", xp.findModel("b#/b/c").getXDPosition());
assertEq("b#b/c", xp.findModel("b#/b[1]/c[1]").getXDPosition());
assertEq("b#b/c[2]", xp.findModel("b#b/c[2]").getXDPosition());
assertEq("b#b/$text", xp.findModel("b#/b/$text").getXDPosition());
assertEq("c#b/b", xp.findModel("c#b/b").getXDPosition());
assertEq("c#b/b", xp.findModel("c#b/b").getXDPosition());
assertEq("c#b/b[2]", xp.findModel("c#b/b[2]").getXDPosition());
assertEq("c#b/b[3]", xp.findModel("c#b/b[3]").getXDPosition());
assertEq("c#b/b[4]", xp.findModel("c#b/b[4]").getXDPosition());
assertEq("c#b/$mixed/c", xp.findModel("c#b/$mixed/c").getXDPosition());
assertEq("c#b/$mixed/c/$mixed/$choice/d", xp.findModel("c#b/$mixed/c/$mixed/$choice/d").getXDPosition());
assertEq("c#b/$mixed/b", xp.findModel("c#b/$mixed/b").getXDPosition());
assertEq("c#b/$mixed/b[2]", xp.findModel("c#b/$mixed/b[2]").getXDPosition());
assertEq("c#b/b[3]", xp.findModel("c#b/b[3]").getXDPosition());
assertEq("c#b/b[4]", xp.findModel("c#b/b[4]").getXDPosition());
assertEq("c#b/$mixed", xp.findModel("c#b/$mixed").getXDPosition());
assertEq("c#b/$mixed[2]", xp.findModel("c#b/$mixed[2]").getXDPosition());
assertEq("c#b/$mixed[2]/b", xp.findModel("c#b/$mixed[2]/b").getXDPosition());
assertEq("c#b/$mixed[2]/b[2]", xp.findModel("c#b/$mixed[2]/b[2]").getXDPosition());
assertEq("c#b/$mixed[2]/d", xp.findModel("c#b/$mixed[2]/d").getXDPosition());
assertEq("c#b/b/$text", xp.findModel("c#/b/b[1]/$text").getXDPosition());
assertEq("c#b/b/$text", xp.findModel("c#b/b/$text").getXDPosition());
assertEq("c#b/b[2]/@a", xp.findModel("c#b/b[2]/@a").getXDPosition());
assertEq("d#dd$mixed", xp.findModel("d#dd").getXDPosition());
// assertEq("d#dd$mixed/$mixed",
// xp.findModel("d#dd/$mixed").getXDPosition());
assertEq("d#dd$mixed/$mixed/b[2]", xp.findModel("d#dd$mixed/$mixed/b[2]").getXDPosition());
assertEq("d#dd$mixed/$mixed/b[2]", xp.findModel("d#dd/b[2]").getXDPosition());
// ///////////////
xp = compile(dataDir + "TestXComponent_Z.xdef");
assertEq("SouborD1A#ZaznamPDN/$mixed/Protokol", xp.findModel("SouborD1A#ZaznamPDN/$mixed/Protokol").getXDPosition());
assertEq("SouborD1A#ZaznamPDN/$mixed/Protokol", xp.findModel("SouborD1A#SouborD1A/ZaznamPDN/$mixed/Protokol").getXDPosition());
assertEq("SouborD1A#ProtokolDN/@KodUtvaruPolicie", xp.findModel("SouborD1A#ProtokolDN/@KodUtvaruPolicie").getXDPosition());
assertEq("SouborD1A#ProtokolDN/@KodUtvaruPolicie", xp.findModel("SouborD1A#SouborD1A/ZaznamPDN/$mixed/Protokol/@KodUtvaruPolicie").getXDPosition());
// test xpointer to xd:any, mixed
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a | b | m/n | x'>\n" + " <xd:any xd:name='x' b='int()' />\n" + " <xd:mixed xd:name='m'>\n" + " <n/>\n" + " <o/>\n" + " </xd:mixed>\n" + " <a>\n" + " <xd:mixed xd:script='ref m' />\n" + " </a>\n" + " <b>\n" + " <xd:any xd:script='ref x' />\n" + " </b>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<a><o/><n/></a>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
xml = "<x b = '123'/>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
xml = "<b><q b = '123'/></b>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
xml = "<b><q b = 'aaa'/></b>";
assertEq(xml, parse(xp, "", xml, reporter));
// b has incorrect value (int expected)
assertErrors(reporter);
xml = "<n/>";
assertEq(xml, parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<a xd:script=\"finally out(from('b').getLength());\"><b xd:script='?'/></a>\n" + "</xd:def>";
xp = compile(xdef);
strw = new StringWriter();
xml = "<a><b/></a>";
assertEq(xml, parse(xp, "", xml, reporter, strw, null, null));
assertNoErrorwarnings(reporter);
assertEq("1", strw.toString());
strw = new StringWriter();
xml = "<a/>";
assertEq(xml, parse(xp, "", xml, reporter, strw, null, null));
assertNoErrorwarnings(reporter);
assertEq("0", strw.toString());
// should not throw null pointer exception!
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <xd:declaration> Element $e = null; </xd:declaration>\n" + " <a b=\"optional string; create from($e,'@b')\"/>\n" + "</xd:def>";
assertEq("<a/>", create(compile(xdef), null, reporter, "<a/>"));
xdef = "<xd:def xmlns:xd='" + _xdNS + "'\n" + " xmlns:wsdl='http://www' root='wsdl:portType'>\n" + "<wsdl:portType name =\"required string()\">\n" + " <wsdl:operation xd:script=\"occurs 1..;\"\n" + " name=\"required string()\">\n" + " <xd:choice>\n" + " <xd:sequence>\n" + " <wsdl:output name=\"optional NCName()\"\n" + " message=\"required string()\"/>\n" + " <wsdl:input xd:script=\"occurs 0..1\"\n" + " name=\"optional NCName()\"\n" + " message=\"required string()\"/>\n" + " <wsdl:fault xd:script=\"occurs 0..\"\n" + " name=\"required string()\"\n" + " message=\"required string()\"/>\n" + " </xd:sequence>\n" + " <xd:sequence>\n" + " <wsdl:input name=\"optional NCName()\"\n" + " message=\"required string()\"/>\n" + " <wsdl:output xd:script=\"occurs 0..1\"\n" + " name=\"optional NCName()\"\n" + " message=\"required string()\"/>\n" + " <wsdl:fault xd:script=\"occurs 0..\"\n" + " name=\"required string()\"\n" + " message=\"required string()\"/>\n" + " </xd:sequence>\n" + " </xd:choice>\n" + " </wsdl:operation>\n" + "</wsdl:portType>\n" + "</xd:def>";
xml = "<wsd:portType xmlns:wsd=\"http://www\" name=\"WlePt\">\n" + " <wsd:operation name=\"WLTaskInsertOp\">\n" + " <wsd:input name=\"WLTaskInsert\"\n" + " message=\"tns:WLTaskInsertMsg\"/>\n" + " <wsd:output name=\"WLTaskInsertResponse\"\n" + " message=\"tns:WLTaskInsertResponseMsg\"/>\n" + " </wsd:operation>\n" + " <wsd:operation name=\"WLTaskDoneOp\">\n" + " <wsd:input name=\"WLTaskDone\"\n" + " message=\"tns:WLTaskDoneMsg\"/>\n" + " <wsd:output name=\"WLTaskDoneResponse\"\n" + " message=\"tns:WLTaskDoneResponseMsg\"/>\n" + " </wsd:operation>\n" + " <wsd:operation name=\"WLTaskCancelOp\">\n" + " <wsd:input name=\"WLTaskCancel\"\n" + " message=\"tns:WLTaskCancelMsg\"/>\n" + " <wsd:output name=\"WLWLTaskCancelResponse\"\n" + " message=\"tns:WLTaskCancelResponseMsg\"/>\n" + " </wsd:operation>\n" + " <wsd:operation name=\"WLTaskEndOp\">\n" + " <wsd:output name=\"WLTaskEndResponse\"\n" + " message=\"tns:WLTaskEndResponseMsg\"/>\n" + " <wsd:input name=\"WLTaskEnd\"\n" + " message=\"tns:WLTaskEndMsg\"/>\n" + " </wsd:operation>\n" + "</wsd:portType>";
xp = compile(xdef);
strw = new StringWriter();
parse(xp, "", xml, reporter, strw);
assertNoErrorwarnings(reporter);
assertEq("", strw.toString());
xml = "<wsdl:portType xmlns:wsdl=\"http://www\" name=\"WlePt\">\n" + " <wsdl:operation name=\"WLTaskInsertOp\">\n" + " <wsdl:input name=\"WLTaskInsert\"\n" + " message=\"tns:WLTaskInsertMsg\"/>\n" + " <wsdl:output name=\"WLTaskInsertResponse\"\n" + " message=\"tns:WLTaskInsertResponseMsg\"/>\n" + " </wsdl:operation>\n" + " <wsdl:operation name=\"WLTaskDoneOp\">\n" + " <wsdl:input name=\"WLTaskDone\"\n" + " message=\"tns:WLTaskDoneMsg\"/>\n" + " <wsdl:output name=\"WLTaskDoneResponse\"\n" + " message=\"tns:WLTaskDoneResponseMsg\"/>\n" + " </wsdl:operation>\n" + " <wsdl:operation name=\"WLTaskCancelOp\">\n" + " <wsdl:input name=\"WLTaskCancel\"\n" + " message=\"tns:WLTaskCancelMsg\"/>\n" + " <wsdl:output name=\"WLWLTaskCancelResponse\"\n" + " message=\"tns:WLTaskCancelResponseMsg\"/>\n" + " </wsdl:operation>\n" + " <wsdl:operation name=\"WLTaskEndOp\">\n" + " <wsdl:output name=\"WLTaskEndResponse\"\n" + " message=\"tns:WLTaskEndResponseMsg\"/>\n" + " <wsdl:input name=\"WLTaskEnd\"\n" + " message=\"tns:WLTaskEndMsg\"/>\n" + " </wsdl:operation>\n" + " <!-- here should be error -->\n" + " <wsdl:operation name=\"WLTaskEndOp\" />\n" + "</wsdl:portType>";
xp = compile(xdef);
strw = new StringWriter();
parse(xp, "", xml, reporter, strw);
assertEq("", strw.toString());
if (!reporter.errors()) {
fail("error not reported");
} else {
if (reporter.getErrorCount() != 1) {
strw = new StringWriter();
ReportPrinter.printListing(strw, xml, reporter, true);
fail(strw.toString());
} else {
rep = reporter.getReport();
if (rep.getModification().indexOf("/wsdl:portType/wsdl:operation[5]") < 0) {
// Missing required element in a section in &{xpath}
fail(rep.toString() + "\n" + rep.getModification());
}
}
}
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='root'>\n" + " <root>\n" + " <xd:choice occurs = \"?\">\n" + " <xd:sequence>\n" + " <b/>\n" + " <c/>\n" + " <d xd:script = \"occurs 0..1\"/>\n" + " </xd:sequence>\n" + " <xd:sequence>\n" + " <b/>\n" + " </xd:sequence>\n" + " <xd:sequence>\n" + " <c/>\n" + " <b/>\n" + " <d xd:script = \"occurs 0..1\"/>\n" + " </xd:sequence>\n" + " <xd:sequence>\n" + " <c/>\n" + " </xd:sequence>\n" + " </xd:choice>\n" + " </root>\n" + "</xd:def>";
xml = "<root/>";
xp = compile(xdef);
strw = new StringWriter();
parse(xp, "", xml, reporter, strw);
assertEq("", strw.toString());
if (reporter.errors()) {
while ((rep = reporter.getReport()) != null) {
fail(rep.toString() + "\n" + rep.getModification());
}
reporter.reset();
strw = new StringWriter();
ReportPrinter.printListing(strw, xml, reporter, true);
fail(strw.toString());
}
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <a>\n" + " <xd:choice occurs = '?'>\n" + " <xd:sequence>\n" + " <b/>\n" + " <c/>\n" + " <d xd:script = \"occurs ?\"/>\n" + " </xd:sequence>\n" + " <xd:sequence>\n" + " <b/>\n" + " </xd:sequence>\n" + " <xd:sequence>\n" + " <c/>\n" + " <b/>\n" + " <d xd:script = \"occurs ?\"/>\n" + " </xd:sequence>\n" + " <xd:sequence>\n" + " <c/>\n" + " </xd:sequence>\n" + " </xd:choice>\n" + " </a>\n" + "</xd:def>";
xml = "<a><c/><b/><d/></a>";
xp = compile(xdef);
strw = new StringWriter();
parse(xp, "", xml, reporter, strw);
assertEq("", strw.toString());
assertNoErrorwarnings(reporter);
xml = "<a><c/><b/><xxx/></a>";
strw = new StringWriter();
parse(xp, "", xml, reporter, strw);
assertEq("", strw.toString());
if (!reporter.errors()) {
fail("error not reported");
} else {
if (!"XDEF501".equals((rep = reporter.getReport()).getMsgID())) {
fail(rep.toString() + "\n" + rep.getModification());
}
while ((rep = reporter.getReport()) != null) {
fail(rep.toString() + "\n" + rep.getModification());
}
}
xml = "<a><c/></a>";
strw = new StringWriter();
parse(xp, "", xml, reporter, strw);
assertEq("", strw.toString());
assertNoErrorwarnings(reporter);
if (reporter.errors()) {
while ((rep = reporter.getReport()) != null) {
fail(rep.toString() + "\n" + rep.getModification());
}
reporter.reset();
strw = new StringWriter();
ReportPrinter.printListing(strw, xml, reporter, true);
fail(strw.toString());
}
// test of reentrance (variable ids)
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + "<xd:declaration scope='global'>\n" + " Container ids=[];\n" + " void code(String result) {\n" + " ids.addItem(result);\n" + " }\n" + "</xd:declaration>\n" + "<a>\n" + " string; onTrue code(getText())\n" + " <b/>\n" + " string; onTrue code(getText())\n" + "</a>\n" + "</xd:def>";
xp = compile(xdef);
xd = xp.createXDDocument();
assertNull(((XDContainer) xd.getVariable("ids")));
xml = "<a>1<b/>2</a>";
assertEq(xml, parse(xd, xml, reporter));
assertEq(2, ((XDContainer) xd.getVariable("ids")).getXDItemsNumber());
assertEq("1", ((XDContainer) xd.getVariable("ids")).getXDItem(0).toString());
xd = xp.createXDDocument();
assertNull(((XDContainer) xd.getVariable("ids")));
xml = "<a>3<b/>4</a>";
assertEq(xml, parse(xd, xml, reporter));
assertEq(2, ((XDContainer) xd.getVariable("ids")).getXDItemsNumber());
assertEq("3", ((XDContainer) xd.getVariable("ids")).getXDItem(0).toString());
// test onAbsence
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<A a=\"? string; onAbsence out('A')\">\n" + " <B xd:script=\"occurs +; onAbsence out('B')\"/>\n" + // onAbsence called!!!
" <C xd:script=\"occurs *; onAbsence out('C')\"/>\n" + // onAbsence called!!!
" ? string; onAbsence out('D')\n" + "</A>\n" + "</xd:def>";
xp = compile(xdef);
strw = new StringWriter();
parse(xp, null, "<A/>", reporter, strw, null, null);
assertEq(strw.toString(), "ABCD");
assertNoErrorwarnings(reporter);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<A>\n" + " <xd:choice script=\"onAbsence out('B')\"><B/><C/></xd:choice>\n" + "</A>\n" + "</xd:def>";
xp = compile(xdef);
strw = new StringWriter();
parse(xp, null, "<A/>", reporter, strw, null, null);
assertEq(strw.toString(), "B");
assertNoErrorwarnings(reporter);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<A>\n" + " <xd:choice script=\"?; onAbsence out('B')\"><B/><C/></xd:choice>\n" + "</A>\n" + "</xd:def>";
xp = compile(xdef);
strw = new StringWriter();
parse(xp, null, "<A/>", reporter, strw, null, null);
assertEq(strw.toString(), "B");
assertNoErrorwarnings(reporter);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<A>\n" + " <xd:mixed script=\"onAbsence out('B')\"><B/><C/></xd:mixed>\n" + "</A>\n" + "</xd:def>";
xp = compile(xdef);
strw = new StringWriter();
parse(xp, null, "<A/>", reporter, strw, null, null);
assertEq(strw.toString(), "B");
assertNoErrorwarnings(reporter);
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='A'>\n" + "<A>\n" + " <xd:mixed script=\"?; onAbsence out('B')\"><B/><C/></xd:mixed>\n" + "</A>\n" + "</xd:def>";
xp = compile(xdef);
strw = new StringWriter();
parse(xp, null, "<A/>", reporter, strw, null, null);
assertEq(strw.toString(), "B");
assertNoErrorwarnings(reporter);
// variable x with leading "$"
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <xd:declaration scope='global'> String $x = 'xyz'; </xd:declaration>\n" + " <a xd:script = \"create from('b[@a=$x]')\">string</a>\n" + "</xd:def>";
xml = "<w><b a='x'/><b a='xyz'>zxy</b><b>xx</b></w>";
assertEq("<a>zxy</a>", create(xdef, "", "a", reporter, xml));
assertNoErrorwarnings(reporter);
// integer variable x without leading "$"
xdef = "<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <xd:declaration> int x = 123; </xd:declaration>\n" + " <a xd:script = \"create from('*[@a=\\\''+x+'\\\']')\"> string </a>\n" + "</xd:def>";
xp = compile(xdef);
xml = "<w><b a='x'/><b a='123'>zxy</b><b>xx</b></w>";
assertEq("<a>zxy</a>", create(xp, "", "a", reporter, xml));
assertNoErrorwarnings(reporter);
xp = compile("<xd:def xmlns:xd='" + _xdNS + "' root='a'>\n" + " <a a='int(); onAbsence setText(\"1\");'\n" + " b='int(); default 2;'\n" + " c='int(); onAbsence setText(\"0.1\");'\n" + " d='int(); default 0.2;'>\n" + " int(); onAbsence setText('3');\n" + " <b/>\n" + " int(); default 4;\n" + " <c/>\n" + " int(); onAbsence setText('0.3');\n" + " <d/>\n" + " int(); default 0.4;\n" + " </a>\n" + "</xd:def>");
xml = "<a>\n<b/>\n<c/>\n<d/>\n</a>";
assertEq("<a a='1' b='2' c='0.1' d='0.2'>3<b/>4<c/>0.3<d/>0.4</a>", parse(xp, "", xml, reporter));
s = reporter.printToString();
assertTrue(reporter.getErrorCount() == 4 && s.contains("E XDEF804:") && s.contains("=/a/@c") && s.contains("=/a/@d") && s.contains("=/a/text()[3]") && s.contains("=/a/text()[4]"), s);
xdef = "<xd:collection xmlns:xd=\"http://www.xdef.org/xdef/3.2\">\n" + " <xd:def xd:root=\"A\">\n" + " <A xd:script=\"ref RegistraceSU_RegistraceSU_cType\"/>\n" + " <RegistraceSU_RegistraceSU_cType\n" + " xd:script=\"ref L1_common_SU_cType\"/>\n" + " <L1_common_Misto_cType xd:text=\"? string()\">\n" + " <GPS xd:script=\"ref L1_common_GPS_cType; occurs ?\"/>\n" + " <Adresa xd:script=\"ref L1_common_Adresa_cType; occurs ?\"/>\n" + " <Vozovka xd:script=\"ref L1_common_Vozovka_cType; occurs ?\"/>\n" + " </L1_common_Misto_cType>\n" + " <L1_common_SU_cType>\n" + " <Misto xd:script=\"ref L1_common_Misto_cType\"/>\n" + " </L1_common_SU_cType>\n" + " <L1_common_Adresa_cType CisloDomu=\"optional string(1, 10)\"\n" + " Obec=\"optional string(1, 36)\"\n" + " Okres=\"optional string(1, 36)\"\n" + " PSC=\"optional string(1, 16)\"\n" + " Stat=\"required string()\"\n" + " Ulice=\"optional string(1, 36)\"/>\n" + " <L1_common_Vozovka_cType/>\n" + " <L1_common_GPS_cType/>\n" + " </xd:def>\n" + "</xd:collection>";
xd = compile(xdef).createXDDocument();
// "Testovací data OK\n" +
xml = "<A>\n" + " <Misto>\n" + // here
" awdad\n" + " <Adresa Okres=\"PRAHA 9\" Stat=\"CZ\"/>\n" + " </Misto>\n" + "</A>";
assertEq(xml, parse(xd, xml, reporter));
assertNoErrorwarnings(reporter);
// "Testovací data chyba\n" +
xd = XDFactory.compileXD(null, xdef).createXDDocument();
xml = "<A>\n" + " <Misto>\n" + " <Adresa Okres=\"PRAHA 9\" Stat=\"CZ\"/>\n" + " awdad\n" + " </Misto>\n" + "</A>";
assertEq(xml, parse(xd, xml, reporter));
assertNoErrorwarnings(reporter);
xp = compile("<xd:def xmlns:xd='" + _xdNS + "' xmlns:x='a.b.c' root='M'>\n" + "<M xd:script=\"var String s = '';\">\n" + " <Measurement xd:script=\"occurs 1..*;\n" + " var { int count = 0; float total = 0; }\n" + " finally s+=@x:date +';n=' +count+ ',average='+ (total/count)+' ';\"\n" + " x:date = \"required dateTime\" >\n" + " <Value xd:script = \"occurs 1..*; finally count++;\">\n" + " required double; onTrue total += (float) getParsedValue();\n" + " </Value>\n" + " </Measurement>\n" + " string; onAbsence addText(s);\n" + " </M>\n" + "</xd:def>");
xml = "<M>" + "<Measurement xmlns:x = \"a.b.c\" x:date=\"2017-08-10T11:31:05\">" + "<Value>10</Value><Value>11.8</Value><Value>9.4</Value>" + "</Measurement>" + "<Measurement xmlns:x = \"a.b.c\" x:date=\"2017-08-10T13:01:27\">" + "<Value>12.35</Value>" + "</Measurement>" + "</M>";
assertEq("<M>" + "<Measurement xmlns:x = \"a.b.c\" x:date=\"2017-08-10T11:31:05\">" + "<Value>10</Value><Value>11.8</Value><Value>9.4</Value>" + "</Measurement>" + "<Measurement xmlns:x = \"a.b.c\" x:date=\"2017-08-10T13:01:27\">" + "<Value>12.35</Value>" + "</Measurement>" + "2017-08-10T11:31:05;n=3,average=10.4 2017-08-10T13:01:27;n=1,average=12.35 " + "</M>", parse(xp, "", xml, reporter));
assertNoErrorwarnings(reporter);
} catch (Exception ex) {
fail(ex);
}
resetTester();
}
Aggregations