KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > value > ElementValue


1 package org.apache.slide.projector.value;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.io.ByteArrayOutputStream JavaDoc;
5 import java.io.IOException JavaDoc;
6 import java.io.InputStream JavaDoc;
7
8 import org.jdom.DocType;
9 import org.jdom.Element;
10 import org.jdom.output.Format;
11 import org.jdom.output.XMLOutputter;
12
13 public class ElementValue extends AbstractStreamableValue implements XMLValue {
14     private final static XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
15
16     private Element element;
17     private byte[] bytes = null;
18
19     public ElementValue(Element element) {
20         this.element = element;
21     }
22
23     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
24         if ( bytes == null ) {
25             ByteArrayOutputStream JavaDoc outputStream = new ByteArrayOutputStream JavaDoc();
26             xmlOutputter.output(element, outputStream);
27             bytes = outputStream.toByteArray();
28         }
29         InputStream JavaDoc inputStream = new ByteArrayInputStream JavaDoc(bytes);
30         return inputStream;
31     }
32
33     public void enableMultipleStreaming() {}
34
35     public int getContentLength() {
36         return 1;
37     }
38
39     public boolean isDocument() {
40         return false;
41     }
42
43     public DocType getDocumentType() {
44         return new DocType(element.getName());
45     }
46
47     public Element getRootElement() {
48         return element;
49     }
50
51     public String JavaDoc getContentType() {
52         return CONTENT_TYPE;
53     }
54
55     public String JavaDoc getCharacterEncoding() {
56         return "UTF-8";
57     }
58 }
59
Popular Tags