1 Clazz.declarePackage ("javajs.util");
\r
2 Clazz.load (null, "javajs.util.XmlUtil", ["javajs.util.PT"], function () {
\r
3 c$ = Clazz.declareType (javajs.util, "XmlUtil");
\r
4 Clazz.makeConstructor (c$,
\r
7 c$.openDocument = Clazz.defineMethod (c$, "openDocument",
\r
9 data.append ("<?xml version=\"1.0\"?>\n");
\r
10 }, "javajs.util.SB");
\r
11 c$.openTag = Clazz.defineMethod (c$, "openTag",
\r
12 function (sb, name) {
\r
13 sb.append ("<").append (name).append (">\n");
\r
14 }, "javajs.util.SB,~S");
\r
15 c$.openTagAttr = Clazz.defineMethod (c$, "openTagAttr",
\r
16 function (sb, name, attributes) {
\r
17 javajs.util.XmlUtil.appendTagAll (sb, name, attributes, null, false, false);
\r
19 }, "javajs.util.SB,~S,~A");
\r
20 c$.closeTag = Clazz.defineMethod (c$, "closeTag",
\r
21 function (sb, name) {
\r
22 sb.append ("</").append (name).append (">\n");
\r
23 }, "javajs.util.SB,~S");
\r
24 c$.appendTagAll = Clazz.defineMethod (c$, "appendTagAll",
\r
25 function (sb, name, attributes, data, isCdata, doClose) {
\r
27 if (name.endsWith ("/")) {
\r
28 name = name.substring (0, name.length - 1);
\r
32 }}sb.append ("<").append (name);
\r
33 if (attributes != null) for (var i = 0; i < attributes.length; i++) {
\r
34 var o = attributes[i];
\r
35 if (o == null) continue;
\r
36 if (Clazz.instanceOf (o, Array)) for (var j = 0; j < (o).length; j += 2) javajs.util.XmlUtil.appendAttrib (sb, (o)[j], (o)[j + 1]);
\r
38 else javajs.util.XmlUtil.appendAttrib (sb, o, attributes[++i]);
\r
42 if (isCdata) data = javajs.util.XmlUtil.wrapCdata (data);
\r
44 }if (doClose) javajs.util.XmlUtil.closeTag (sb, name);
\r
45 }, "javajs.util.SB,~S,~A,~O,~B,~B");
\r
46 c$.wrapCdata = Clazz.defineMethod (c$, "wrapCdata",
\r
49 return (s.indexOf ("&") < 0 && s.indexOf ("<") < 0 ? (s.startsWith ("\n") ? "" : "\n") + s : "<![CDATA[" + javajs.util.PT.rep (s, "]]>", "]]]]><![CDATA[>") + "]]>");
\r
51 c$.unwrapCdata = Clazz.defineMethod (c$, "unwrapCdata",
\r
53 return (s.startsWith ("<![CDATA[") && s.endsWith ("]]>") ? javajs.util.PT.rep (s.substring (9, s.length - 3), "]]]]><![CDATA[>", "]]>") : s);
\r
55 c$.appendTagObj = Clazz.defineMethod (c$, "appendTagObj",
\r
56 function (sb, name, attributes, data) {
\r
57 javajs.util.XmlUtil.appendTagAll (sb, name, attributes, data, false, true);
\r
58 }, "javajs.util.SB,~S,~A,~O");
\r
59 c$.appendTag = Clazz.defineMethod (c$, "appendTag",
\r
60 function (sb, name, data) {
\r
61 if (Clazz.instanceOf (data, Array)) javajs.util.XmlUtil.appendTagAll (sb, name, data, null, false, true);
\r
62 else javajs.util.XmlUtil.appendTagAll (sb, name, null, data, false, true);
\r
63 }, "javajs.util.SB,~S,~O");
\r
64 c$.appendCdata = Clazz.defineMethod (c$, "appendCdata",
\r
65 function (sb, name, attributes, data) {
\r
66 javajs.util.XmlUtil.appendTagAll (sb, name, attributes, data, true, true);
\r
67 }, "javajs.util.SB,~S,~A,~S");
\r
68 c$.appendAttrib = Clazz.defineMethod (c$, "appendAttrib",
\r
69 function (sb, name, value) {
\r
70 if (value == null) return;
\r
71 sb.append (" ").appendO (name).append ("=\"").appendO (value).append ("\"");
\r
72 }, "javajs.util.SB,~O,~O");
\r