1 package org.apache.slide.projector.value; 2 3 import java.io.ByteArrayInputStream ; 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 7 import org.apache.slide.projector.ContentType; 8 9 public class StringValue extends ObjectValue implements StreamableValue, PrintableValue { 10 public static final StringValue EMPTY = new StringValue(""); 11 12 private boolean isDocument; 13 private String contentType = "text/plain"; 14 15 public StringValue(String content) { 16 super(content); 17 contentType = ContentType.determineContentType(content); 18 isDocument = ContentType.determineIsDocument(content); 19 } 20 21 public StringValue(String content, boolean document) { 22 super(content); 23 isDocument = document; 24 } 25 26 public StringValue(String content, String contentType, boolean document) { 27 super(content); 28 isDocument = document; 29 this.contentType = contentType; 30 } 31 32 public InputStream getInputStream() throws IOException { 33 return new ByteArrayInputStream (((String )getObject()).getBytes("UTF-8")); 34 } 35 36 public String toString() { 37 return (String )getObject(); 38 } 39 40 public boolean isDocument() { 41 return isDocument; 42 } 43 44 public int getContentLength() { 45 return toString().length(); 46 } 47 48 public String getContentType() { 49 return contentType; 50 } 51 52 public String getCharacterEncoding() { 53 return "UTF-8"; 54 } 55 56 public StringBuffer print(StringBuffer buffer) { 57 return buffer.append(getObject()); 58 } 59 } | Popular Tags |