1 58 package org.apache.ecs; 59 60 import java.io.OutputStream ; 61 import java.io.PrintWriter ; 62 import java.io.Serializable ; 63 import org.apache.ecs.xhtml.html; 64 import org.apache.ecs.xhtml.body; 65 import org.apache.ecs.xhtml.title; 66 import org.apache.ecs.xhtml.head; 67 import org.apache.ecs.Doctype; 68 69 77 public class XhtmlDocument implements Serializable ,Cloneable 78 { 79 80 private html html; 82 private head head; 83 84 private body body; 85 86 private title title; 87 88 private String codeset = null; 89 90 private Doctype doctype = null; 91 92 { 93 html = new html(); 94 head = new head(); 95 title = new title(); 96 body = new body(); 97 98 head.addElement("title",title); 99 html.addElement("head",head); 100 html.addElement("body",body); 101 } 102 103 106 public XhtmlDocument() 107 { 108 } 109 110 113 public XhtmlDocument(String codeset) 114 { 115 setCodeset(codeset); 116 } 117 118 121 public Doctype getDoctype() 122 { 123 return(doctype); 124 } 125 126 129 public XhtmlDocument setDoctype(Doctype set_doctype) 130 { 131 this.doctype = set_doctype; 132 return(this); 133 } 134 135 138 public html getHtml() 139 { 140 return(html); 141 } 142 143 146 public XhtmlDocument setHtml(html set_html) 147 { 148 this.html = set_html; 149 return(this); 150 } 151 152 155 public head getHead() 156 { 157 return(head); 158 } 159 160 163 public XhtmlDocument setHead(head set_head) 164 { 165 html.addElement("head",set_head); 166 return(this); 167 } 168 169 173 public XhtmlDocument appendHead(Element value) 174 { 175 head.addElement(value); 176 return(this); 177 } 178 179 183 public XhtmlDocument appendHead(String value) 184 { 185 head.addElement(value); 186 return(this); 187 } 188 189 192 public body getBody() 193 { 194 return(body); 195 } 196 197 200 public XhtmlDocument setBody(body set_body) 201 { 202 html.addElement("body",set_body); 203 return(this); 204 } 205 206 210 public XhtmlDocument appendBody(Element value) 211 { 212 body.addElement(value); 213 return(this); 214 } 215 216 220 public XhtmlDocument appendBody(String value) 221 { 222 body.addElement(value); 223 return(this); 224 } 225 226 229 public title getTitle() 230 { 231 return(title); 232 } 233 234 237 public XhtmlDocument setTitle(title set_title) 238 { 239 head.addElement("title",set_title); 240 return(this); 241 } 242 243 247 public XhtmlDocument appendTitle(Element value) 248 { 249 title.addElement(value); 250 return(this); 251 } 252 253 257 public XhtmlDocument appendTitle(String value) 258 { 259 title.addElement(value); 260 return(this); 261 } 262 263 266 public void setCodeset ( String codeset ) 267 { 268 this.codeset = codeset; 269 } 270 271 276 public String getCodeset() 277 { 278 return this.codeset; 279 } 280 281 284 public void output(OutputStream out) 285 { 286 if (doctype != null) 287 { 288 doctype.output(out); 289 try 290 { 291 out.write('\n'); 292 } 293 catch ( Exception e) 294 {} 295 } 296 html.output(out); 298 } 299 300 303 public void output(PrintWriter out) 304 { 305 if (doctype != null) 306 { 307 doctype.output(out); 308 try 309 { 310 out.write('\n'); 311 } 312 catch ( Exception e) 313 {} 314 } 315 html.output(out); 317 } 318 319 322 public final String toString() 323 { 324 StringBuffer sb = new StringBuffer (); 325 if ( getCodeset() != null ) 326 { 327 if (doctype != null) 328 sb.append (doctype.toString(getCodeset())); 329 sb.append (html.toString(getCodeset())); 330 return (sb.toString()); 331 } 332 else 333 { 334 if (doctype != null) 335 sb.append (doctype.toString()); 336 sb.append (html.toString()); 337 return(sb.toString()); 338 } 339 } 340 341 344 public final String toString(String codeset) 345 { 346 StringBuffer sb = new StringBuffer (); 347 if (doctype != null) 348 sb.append (doctype.toString(getCodeset())); 349 sb.append (html.toString(getCodeset())); 350 return(sb.toString()); 351 } 352 353 359 public Object clone() 360 { 361 return(html.clone()); 362 } 363 } 364 | Popular Tags |