1 16 package org.apache.cocoon.components.xscript; 17 18 import java.io.ByteArrayInputStream ; 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.io.StringReader ; 22 23 import org.xml.sax.ContentHandler ; 24 import org.xml.sax.InputSource ; 25 26 34 public class XScriptObjectInlineXML extends XScriptObject { 35 36 StringBuffer stringBuffer; 37 StringBufferContentHandler streamHandler; 38 39 public XScriptObjectInlineXML(XScriptManager manager) { 40 super(manager); 41 stringBuffer = new StringBuffer (); 42 stringBuffer.append("<?xml version=\"1.0\"?>\n\n"); 43 streamHandler = new StringBufferContentHandler(stringBuffer); 44 } 45 46 public XScriptObjectInlineXML(XScriptManager manager, StringBuffer stringBuffer) { 47 super(manager); 48 this.stringBuffer = stringBuffer; 49 streamHandler = new StringBufferContentHandler(stringBuffer); 50 } 51 52 public XScriptObjectInlineXML(XScriptManager manager, String string) { 53 super(manager); 54 this.stringBuffer = new StringBuffer (string); 55 streamHandler = new StringBufferContentHandler(stringBuffer); 56 } 57 58 public InputStream getInputStream() throws IOException { 59 return new ByteArrayInputStream (stringBuffer.toString().getBytes()); 63 } 64 65 public InputSource getInputSource() throws IOException { 66 InputSource is = new InputSource (new StringReader (stringBuffer.toString())); 67 is.setSystemId(getURI()); 68 return is; 69 } 70 71 public ContentHandler getContentHandler() { 72 return streamHandler; 73 } 74 75 public String toString() { 76 return stringBuffer.toString(); 77 } 78 79 public long getContentLength() { 80 return stringBuffer.length(); 81 } 82 83 public String getContent() { 84 return stringBuffer.toString(); 85 } 86 87 public String getURI() { 88 return "xscript:inline:" + System.identityHashCode(this); 91 } 92 } 93 | Popular Tags |