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.html.Html; 64 import org.apache.ecs.html.Body; 65 import org.apache.ecs.html.Title; 66 import org.apache.ecs.html.Head; 67 import org.apache.ecs.Doctype; 68 69 76 public class Document implements Serializable ,Cloneable 77 { 78 79 private Html html; 81 private Head head; 82 83 private Body body; 84 85 private Title title; 86 87 private String codeset = null; 88 89 private Doctype doctype = null; 90 91 { 92 html = new Html(); 93 head = new Head(); 94 title = new Title(); 95 body = new Body(); 96 97 head.addElement("title",title); 98 html.addElement("head",head); 99 html.addElement("body",body); 100 } 101 102 105 public Document() 106 { 107 } 108 109 112 public Document(String codeset) 113 { 114 setCodeset(codeset); 115 } 116 117 120 public Doctype getDoctype() 121 { 122 return(doctype); 123 } 124 125 128 public Document setDoctype(Doctype set_doctype) 129 { 130 this.doctype = set_doctype; 131 return(this); 132 } 133 134 137 public Html getHtml() 138 { 139 return(html); 140 } 141 142 145 public Document setHtml(Html set_html) 146 { 147 this.html = set_html; 148 return(this); 149 } 150 151 154 public Head getHead() 155 { 156 return(head); 157 } 158 159 162 public Document setHead(Head set_head) 163 { 164 html.addElement("head",set_head); 165 this.head = set_head; 166 return(this); 167 } 168 169 173 public Document appendHead(Element value) 174 { 175 head.addElement(value); 176 return(this); 177 } 178 179 183 public Document 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 Document setBody(Body set_body) 201 { 202 html.addElement("body",set_body); 203 this.body = set_body; 204 return(this); 205 } 206 207 211 public Document appendBody(Element value) 212 { 213 body.addElement(value); 214 return(this); 215 } 216 217 221 public Document appendBody(String value) 222 { 223 body.addElement(value); 224 return(this); 225 } 226 227 230 public Title getTitle() 231 { 232 return(title); 233 } 234 235 238 public Document setTitle(Title set_title) 239 { 240 head.addElement("title",set_title); 241 this.title = set_title; 242 return(this); 243 } 244 245 249 public Document appendTitle(Element value) 250 { 251 title.addElement(value); 252 return(this); 253 } 254 255 259 public Document appendTitle(String value) 260 { 261 title.addElement(value); 262 return(this); 263 } 264 265 268 public void setCodeset ( String codeset ) 269 { 270 this.codeset = codeset; 271 } 272 273 278 public String getCodeset() 279 { 280 return this.codeset; 281 } 282 283 286 public void output(OutputStream out) 287 { 288 if (doctype != null) 289 { 290 doctype.output(out); 291 try 292 { 293 out.write('\n'); 294 } 295 catch ( Exception e) 296 {} 297 } 298 html.output(out); 300 } 301 302 305 public void output(PrintWriter out) 306 { 307 if (doctype != null) 308 { 309 doctype.output(out); 310 try 311 { 312 out.write('\n'); 313 } 314 catch ( Exception e) 315 {} 316 } 317 html.output(out); 319 } 320 321 324 public final String toString() 325 { 326 StringBuffer sb = new StringBuffer (); 327 if ( getCodeset() != null ) 328 { 329 if (doctype != null) 330 sb.append (doctype.toString(getCodeset())); 331 sb.append (html.toString(getCodeset())); 332 return (sb.toString()); 333 } 334 else 335 { 336 if (doctype != null) 337 sb.append (doctype.toString()); 338 sb.append (html.toString()); 339 return(sb.toString()); 340 } 341 } 342 343 346 public final String toString(String codeset) 347 { 348 StringBuffer sb = new StringBuffer (); 349 if (doctype != null) 350 sb.append (doctype.toString(getCodeset())); 351 sb.append (html.toString(getCodeset())); 352 return(sb.toString()); 353 } 354 355 361 public Object clone() 362 { 363 return(html.clone()); 364 } 365 } 366 | Popular Tags |