X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fjrw%2Fsp%2Fcons.java;fp=src%2Fjrw%2Fsp%2Fcons.java;h=8c54288ba507c45d11de614496129bdceb6132c1;hb=6e0043cc3f99a31bac74d6d0c7399e4c0b60d3fb;hp=0000000000000000000000000000000000000000;hpb=ad84ba3b456f1a9858fcfe1fee28b81197654c8d;p=jrw.git diff --git a/src/jrw/sp/cons.java b/src/jrw/sp/cons.java new file mode 100644 index 0000000..8c54288 --- /dev/null +++ b/src/jrw/sp/cons.java @@ -0,0 +1,53 @@ +package jrw.sp; + +import java.util.*; + +public class cons { + public static class Attribute { + public final Name name; + public final String value; + + public Attribute(Name name, String value) { + this.name = name; + this.value = value; + } + } + + public static Attribute $(Name name, String value) { + return(new Attribute(name, value)); + } + + public static Attribute $(String name, String value) { + return($(new Name(name), value)); + } + + public static Attribute $(Namespace ns, String local, String value) { + return($(new Name(ns, local), value)); + } + + private static void populate0(Element el, Iterable contents) { + for(Object ob : contents) { + if(ob == null) { + } else if(ob instanceof Node) { + el.add((Node)ob); + } else if(ob instanceof Attribute) { + el.set(((Attribute)ob).name, ((Attribute)ob).value); + } else if(ob instanceof Populous) { + ((Populous)ob).populate(el); + } else if(ob instanceof Object[]) { + populate0(el, Arrays.asList((Object[])ob)); + } else if(ob instanceof Iterable) { + populate0(el, (Iterable)ob); + } else if(ob instanceof String) { + el.add(new Text((String)ob)); + } else { + el.add(new Text(ob.toString())); + } + } + } + + public static Element populate(Element el, Object... contents) { + populate0(el, Arrays.asList(contents)); + return(el); + } +}