1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.core.support.transform.min;
17
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.io.OutputStream;
21 import java.io.Reader;
22 import java.io.Writer;
23 import java.nio.charset.Charset;
24 import java.nio.charset.StandardCharsets;
25
26 import javax.xml.transform.Result;
27 import javax.xml.transform.Source;
28 import javax.xml.transform.stream.StreamResult;
29 import javax.xml.transform.stream.StreamSource;
30
31 import org.apache.commons.io.IOUtils;
32 import org.openehealth.ipf.commons.core.modules.api.Converter;
33
34
35
36
37 public class TestConverter extends Converter<String, String> {
38
39 public String parse(String message, Object... params) {
40 return "string: " + message;
41 }
42
43 public String parse(Reader reader, Object... params) throws IOException {
44 return "reader: " + IOUtils.toString(reader);
45 }
46
47 public String parse(InputStream message, Object... params) throws IOException {
48 return "stream: " + IOUtils.toString(message, Charset.defaultCharset());
49 }
50
51 public String parse(Source source, Object... params) throws IOException {
52 return "source: " + toString(source);
53 }
54
55 public Result render(String model, Result result, Object... params) throws IOException {
56 StreamResult r = (StreamResult)result;
57 IOUtils.write(model, r.getWriter());
58 return r;
59 }
60
61 public OutputStream render(String model, OutputStream result, Object... params) throws IOException {
62 IOUtils.write(model, result, StandardCharsets.UTF_8);
63 return result;
64 }
65
66 public Writer render(String model, Writer result, Object... params) throws IOException {
67 IOUtils.write(model, result);
68 return result;
69 }
70
71 public String render(String model, Object... params) {
72 return model;
73 }
74
75 public String zap(String object, Object... params) {
76 return object;
77 }
78
79 private static String toString(Source source) throws IOException {
80 StreamSource s = (StreamSource)source;
81 return IOUtils.toString(s.getReader());
82 }
83
84 }