1
2
3
4
5
6
7
8 package it.imolinfo.jbi4corba.jbi.processor.transform;
9
10 import java.io.ByteArrayInputStream;
11 import java.io.InputStream;
12 import java.io.Reader;
13 import java.io.Serializable;
14 import java.io.StringReader;
15 import java.io.UnsupportedEncodingException;
16
17 import javax.xml.transform.stream.StreamSource;
18
19
20
21
22 public class StringSource extends StreamSource implements Serializable {
23
24
25 private static final long serialVersionUID = -2965901682811246960L;
26
27
28 private final String text;
29
30
31 private String encoding = "UTF-8";
32
33
34
35
36
37
38
39 public StringSource(String text) {
40 if (text == null) {
41 throw new NullPointerException("text can not be null");
42 }
43 this.text = text;
44 }
45
46
47
48
49
50
51
52
53
54 public StringSource(String text, String systemId) {
55 this(text);
56 setSystemId(systemId);
57 }
58
59
60
61
62
63
64
65
66
67
68
69 public StringSource(String text, String systemId, String encoding) {
70 this.text = text;
71 this.encoding=encoding;
72 setSystemId(systemId);
73 }
74
75
76
77
78
79
80
81
82
83
84
85 public InputStream getInputStream() {
86 try {
87 return new ByteArrayInputStream(text.getBytes(encoding));
88 } catch (UnsupportedEncodingException e) {
89 throw new RuntimeException(e);
90 }
91 }
92
93
94
95
96
97
98 public Reader getReader() {
99 return new StringReader(text);
100 }
101
102
103
104
105
106
107 public String toString() {
108 return "StringSource[" + text + "]";
109 }
110
111
112
113
114
115
116 public String getText() {
117 return text;
118 }
119
120 }