1 package org.apache.slide.projector.value; 2 3 import java.io.ByteArrayInputStream ; 4 import java.io.ByteArrayOutputStream ; 5 import java.io.IOException ; 6 import java.io.InputStream ; 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 getInputStream() throws IOException { 24 if ( bytes == null ) { 25 ByteArrayOutputStream outputStream = new ByteArrayOutputStream (); 26 xmlOutputter.output(element, outputStream); 27 bytes = outputStream.toByteArray(); 28 } 29 InputStream inputStream = new ByteArrayInputStream (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 getContentType() { 52 return CONTENT_TYPE; 53 } 54 55 public String getCharacterEncoding() { 56 return "UTF-8"; 57 } 58 } 59 | Popular Tags |