KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.apache.slide.projector.value;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.InputStream JavaDoc;
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 JavaDoc contentType = "text/plain";
14
15     public StringValue(String JavaDoc content) {
16         super(content);
17         contentType = ContentType.determineContentType(content);
18         isDocument = ContentType.determineIsDocument(content);
19     }
20
21     public StringValue(String JavaDoc content, boolean document) {
22         super(content);
23         isDocument = document;
24     }
25
26     public StringValue(String JavaDoc content, String JavaDoc contentType, boolean document) {
27         super(content);
28         isDocument = document;
29         this.contentType = contentType;
30     }
31
32     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
33       return new ByteArrayInputStream JavaDoc(((String JavaDoc)getObject()).getBytes("UTF-8"));
34     }
35
36     public String JavaDoc toString() {
37         return (String JavaDoc)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 JavaDoc getContentType() {
49         return contentType;
50     }
51
52     public String JavaDoc getCharacterEncoding() {
53         return "UTF-8";
54     }
55
56     public StringBuffer JavaDoc print(StringBuffer JavaDoc buffer) {
57         return buffer.append(getObject());
58     }
59 }
Popular Tags