1 package org.joshy.html; 2 3 import java.util.HashMap ; 4 import org.w3c.dom.Node ; 5 import org.w3c.dom.Element ; 6 import org.joshy.u; 7 import org.joshy.html.forms.InputButton; 8 import org.joshy.html.forms.*; 9 10 19 public class LayoutFactory { 20 private static HashMap element_map = new HashMap (); 21 public static Layout getLayout(Node elem) { 22 if(elem.getNodeType() == elem.ELEMENT_NODE) { 25 if(elem.getNodeName().equals("div")) { return new InlineLayout(); } 26 if(elem.getNodeName().equals("p")) { return new InlineLayout(); } 27 if(elem.getNodeName().equals("span")) { return new InlineLayout(); } 28 if(elem.getNodeName().equals("u")) { return new InlineLayout(); } 29 32 if(elem.getNodeName().equals("pre")) { return new InlineLayout(); } 33 34 36 if(elem.getNodeName().equals("tt")) { return new InlineLayout(); } 37 if(elem.getNodeName().equals("b")) { return new InlineLayout(); } 38 if(elem.getNodeName().equals("i")) { return new InlineLayout(); } 39 if(elem.getNodeName().equals("big")) { return new InlineLayout(); } 40 if(elem.getNodeName().equals("small")) { return new InlineLayout(); } 41 if(elem.getNodeName().equals("em")) { return new InlineLayout(); } 42 if(elem.getNodeName().equals("strong")) { return new InlineLayout(); } 43 if(elem.getNodeName().equals("dfn")) { return new InlineLayout(); } 44 if(elem.getNodeName().equals("code")) { return new InlineLayout(); } 45 if(elem.getNodeName().equals("samp")) { return new InlineLayout(); } 46 if(elem.getNodeName().equals("kbd")) { return new InlineLayout(); } 47 if(elem.getNodeName().equals("var")) { return new InlineLayout(); } 48 if(elem.getNodeName().equals("cite")) { return new InlineLayout(); } 49 if(elem.getNodeName().equals("ins")) { return new InlineLayout(); } 50 if(elem.getNodeName().equals("del")) { return new InlineLayout(); } 51 if(elem.getNodeName().equals("sup")) { return new InlineLayout(); } 52 if(elem.getNodeName().equals("sub")) { return new InlineLayout(); } 53 54 if(elem.getNodeName().equals("a")) { return new InlineLayout(); } 55 if(elem.getNodeName().equals("h1")) { return new InlineLayout(); } 56 if(elem.getNodeName().equals("h2")) { return new InlineLayout(); } 57 if(elem.getNodeName().equals("h3")) { return new InlineLayout(); } 58 if(elem.getNodeName().equals("h4")) { return new InlineLayout(); } 59 if(elem.getNodeName().equals("h5")) { return new InlineLayout(); } 60 if(elem.getNodeName().equals("h6")) { return new InlineLayout(); } 61 62 if(elem.getNodeName().equals("ul")) { return new ListLayout(); } 63 if(elem.getNodeName().equals("li")) { return new InlineLayout(); } 64 if(elem.getNodeName().equals("img")) { return new ImageLayout(); } 65 66 if(elem.getNodeName().equals("table")) { return new TableLayout2(); } 67 if(elem.getNodeName().equals("td")) { return new TableCellLayout(); } 68 if(elem.getNodeName().equals("th")) { return new TableCellLayout(); } 69 70 if(elem.getNodeName().equals("br")) { return new InlineLayout(); } 71 if(elem.getNodeName().equals("font")) { return new InlineLayout(); } 72 if(elem.getNodeName().equals("hr")) { return new NullLayout(); } 73 if(elem.getNodeName().equals("form")) { return new InlineLayout(); } 74 if(elem.getNodeName().equals("input")) { 75 Element el = (Element )elem; 76 if(el.getAttribute("type").equals("text")) { 77 return new InputText(); 78 } 79 return new InputButton(); 80 } 81 } 82 83 if(elem.getNodeType() == elem.TEXT_NODE) { 85 if(elem.getNodeValue().trim().equals("")) { 86 return new NullLayout(); 88 } 89 } 90 91 if(elem.getNodeType() == elem.TEXT_NODE) { 92 return new AnonymousBoxLayout(); 94 } 95 96 97 if(elem.getNodeType() == elem.COMMENT_NODE) { 98 return new NullLayout(); 99 } 100 101 Layout lyt = getCustomLayout(elem); 102 if(lyt != null) { 103 return lyt; 104 } 105 u.p("error! returning null! type = " + elem.getNodeType()); 106 u.p("name = " + elem.getNodeName()); 107 122 return null; 123 } 124 125 126 public static void addCustomLayout(String elem_name, Layout layout) { 127 element_map.put(elem_name,layout); 128 } 129 130 private static Layout getCustomLayout(Node elem) { 131 if(element_map.containsKey(elem.getNodeName())) { 132 return (Layout) element_map.get(elem.getNodeName()); 133 } 134 return null; 135 } 136 137 138 139 140 141 142 143 144 145 146 147 } 148 149 | Popular Tags |