1 16 package org.apache.cocoon.components.source.impl; 17 18 import java.io.ByteArrayInputStream ; 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 22 import org.apache.cocoon.xml.XMLUtils; 23 import org.apache.excalibur.xml.sax.XMLizable; 24 import org.apache.excalibur.source.Source; 25 import org.apache.excalibur.source.SourceNotFoundException; 26 import org.apache.excalibur.source.SourceValidity; 27 import org.apache.excalibur.source.impl.validity.NOPValidity; 28 29 import org.xml.sax.ContentHandler ; 30 import org.xml.sax.SAXException ; 31 32 44 public class EmptySource implements XMLizable, Source { 45 46 protected String rootElementName; 47 protected String scheme; 48 protected String uri; 49 protected String xmlDocument; 50 51 public EmptySource(String location) { 52 this.uri = location; 53 final int pos = location.indexOf(':'); 54 this.scheme = location.substring(0, pos); 55 56 final String rootName = location.substring(pos + 1); 57 if (rootName != null && rootName.trim().length() > 0) { 58 this.rootElementName = rootName.trim(); 59 this.xmlDocument = '<' + this.rootElementName + "/>"; 60 } else { 61 this.xmlDocument = ""; 62 } 63 } 64 65 68 public void toSAX(ContentHandler handler) throws SAXException { 69 handler.startDocument(); 70 if (rootElementName != null) { 71 XMLUtils.createElement(handler, this.rootElementName); 72 } 73 handler.endDocument(); 74 } 75 76 79 public boolean exists() { 80 return true; 81 } 82 83 86 public long getContentLength() { 87 return this.xmlDocument.length(); 88 } 89 90 93 public InputStream getInputStream() throws IOException , SourceNotFoundException { 94 return new ByteArrayInputStream (this.xmlDocument.getBytes("utf-8")); 95 } 96 97 100 public long getLastModified() { 101 return 1; 103 } 104 105 108 public String getMimeType() { 109 return "text/xml"; 110 } 111 112 115 public String getScheme() { 116 return this.scheme; 117 } 118 119 122 public String getURI() { 123 return this.uri; 124 } 125 126 129 public SourceValidity getValidity() { 130 return NOPValidity.SHARED_INSTANCE; 131 } 132 133 136 public void refresh() { 137 } 139 } 140 | Popular Tags |