Added basic HTML generation and response handling.
[jrw.git] / src / jrw / sp / cons.java
CommitLineData
6e0043cc
FT
1package jrw.sp;
2
3import java.util.*;
4
5public class cons {
6 public static class Attribute {
7 public final Name name;
8 public final String value;
9
10 public Attribute(Name name, String value) {
11 this.name = name;
12 this.value = value;
13 }
14 }
15
16 public static Attribute $(Name name, String value) {
17 return(new Attribute(name, value));
18 }
19
20 public static Attribute $(String name, String value) {
21 return($(new Name(name), value));
22 }
23
24 public static Attribute $(Namespace ns, String local, String value) {
25 return($(new Name(ns, local), value));
26 }
27
28 private static void populate0(Element el, Iterable<?> contents) {
29 for(Object ob : contents) {
30 if(ob == null) {
31 } else if(ob instanceof Node) {
32 el.add((Node)ob);
33 } else if(ob instanceof Attribute) {
34 el.set(((Attribute)ob).name, ((Attribute)ob).value);
35 } else if(ob instanceof Populous) {
36 ((Populous)ob).populate(el);
37 } else if(ob instanceof Object[]) {
38 populate0(el, Arrays.asList((Object[])ob));
39 } else if(ob instanceof Iterable) {
40 populate0(el, (Iterable<?>)ob);
41 } else if(ob instanceof String) {
42 el.add(new Text((String)ob));
43 } else {
44 el.add(new Text(ob.toString()));
45 }
46 }
47 }
48
49 public static Element populate(Element el, Object... contents) {
50 populate0(el, Arrays.asList(contents));
51 return(el);
52 }
53}