1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.atom.transformers; |
12 | |
|
13 | |
import org.mule.api.MuleEvent; |
14 | |
import org.mule.api.transformer.TransformerException; |
15 | |
import org.mule.api.transport.OutputHandler; |
16 | |
import org.mule.transformer.AbstractDiscoverableTransformer; |
17 | |
import org.mule.transformer.types.DataTypeFactory; |
18 | |
|
19 | |
import java.io.IOException; |
20 | |
import java.io.OutputStream; |
21 | |
|
22 | |
import org.apache.abdera.model.Base; |
23 | |
import org.apache.abdera.parser.stax.FOMWriterOptions; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
public class BaseToOutputHandler extends AbstractDiscoverableTransformer |
29 | |
{ |
30 | |
public BaseToOutputHandler() |
31 | 0 | { |
32 | 0 | this.registerSourceType(DataTypeFactory.create(Base.class)); |
33 | 0 | setReturnDataType(DataTypeFactory.create(OutputHandler.class)); |
34 | 0 | } |
35 | |
|
36 | |
@Override |
37 | |
public Object doTransform(Object src, String outputEncoding) throws TransformerException |
38 | |
{ |
39 | |
try |
40 | |
{ |
41 | 0 | final Base e = (Base) src; |
42 | |
|
43 | 0 | return new OutputHandler() |
44 | 0 | { |
45 | |
public void write(MuleEvent event, OutputStream out) throws IOException |
46 | |
{ |
47 | 0 | FOMWriterOptions opts = new FOMWriterOptions(); |
48 | 0 | opts.setCharset(event.getEncoding()); |
49 | 0 | e.writeTo(out, opts); |
50 | 0 | } |
51 | |
}; |
52 | |
} |
53 | 0 | catch (Exception e) |
54 | |
{ |
55 | 0 | throw new TransformerException(this, e); |
56 | |
} |
57 | |
} |
58 | |
} |