@MayBeExcluded public static String objectToXml(Object obj, String _id) { String id = (_id != null ? " id=\"" + _id + "\"" : ""); if (StrictWeb.jsTypeOf(obj) == "undefined") return "<null" + id + "/>"; if (StrictWeb.jsTypeOf(obj) == "string") return "<s" + id + ">" + StrictWeb.toHTML((String) obj) + "</s>"; if (StrictWeb.jsTypeOf(obj) == "boolean") return ((Boolean) obj) ? "<b" + id + ">1</b>" : "<b" + id + ">0</b>"; if (StrictWeb.jsTypeOf(obj) == "number") return "<n" + id + ">" + obj + "</n>"; if (StrictWeb.jsTypeOf(obj) == "object") { if (obj == null) return "<null" + id + "/>"; if (StrictWeb.isEnum(obj)) return "<e" + id + ">" + obj.toString() + "</e>"; if (StrictWeb.isInstanceOfDate(obj)) return "<d" + id + ">" + StrictWeb.dateToStringSmart((Date) obj) + "</d>"; if (StrictWeb.isInstanceOfArray(obj)) return arrayToXml((Object[]) obj, id); if (StrictWeb.isInstanceOfNode(obj)) { return "<form" + id + ">" + formToXml((Node) obj) + "</form>"; } Map<String, String> map = (Map<String, String>) obj; String xml = "<o" + id + ">"; for (String key : map.keySet()) { String val = map.get(key); if (StrictWeb.jsTypeOf(val) != "function") xml += objectToXml(val, key); } return xml + "</o>"; } return "<" + StrictWeb.jsTypeOf(obj) + "/>"; }
@MayBeExcluded public static String formToXml(Node start) { String xml = ""; if (start.field == DOMBuilder.DISABLED) return xml; if (start.field != null) { if (StrictWeb.jsTypeOf(start.field) == "string") { xml = "<f id=\"" + start.field + "\">"; } else xml = "<f>"; } for (Node el : start.childNodes) { if (el.field == DOMBuilder.DISABLED) continue; if (((Boolean) (Object) el.id || (Boolean) (Object) el.name) && (el.tagName == "INPUT" || el.tagName == "SELECT" || el.tagName == "TEXTAREA")) { if (el.type == "radio" && !el.checked) continue; xml += "<f id=\"" + ((Boolean) (Object) el.id || (Boolean) (Object) el.name) + "\">"; if (el.type == "checkbox") xml += el.checked ? "1" : "0"; else xml += StrictWeb.toHTML((String) el.value); xml += "</f>"; } else if (el.className != null && el.className.indexOf(FIELD_MULTISELECT) >= 0) { final List<Object> val = new ArrayList<Object>(); NodeBuilder.wrap(el) .forEachSubchild( new CommonDelegate<Boolean, Node>() { public Boolean delegate(Node n) { if (n.field == DOMBuilder.DISABLED) return false; if (n.tagName == "INPUT" || n.tagName == "SELECT") { if (n.type == "checkbox") { if (n.checked) val.add((Boolean) (Object) n.id || (Boolean) (Object) n.name); } else { val.add((String) n.value); } } return true; } }); xml += "<ms id=\"" + el.field + "\">" + (val.size() > 0 ? "<q>" : "") + StrictWeb.jsJoinList(val, "</q><q>") + (val.size() > 0 ? "</q>" : "") + "</ms>"; } else xml += formToXml(el); } if (start.field != null) xml += "</f>"; return xml; }