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