1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.xml.transformer;
12
13 import org.mule.api.MuleMessage;
14 import org.mule.api.transformer.DiscoverableTransformer;
15 import org.mule.api.transformer.TransformerException;
16 import org.mule.transformer.types.DataTypeFactory;
17
18
19
20
21 public class DomDocumentToXml extends AbstractXmlTransformer implements DiscoverableTransformer
22 {
23 private int priorityWeighting = DiscoverableTransformer.DEFAULT_PRIORITY_WEIGHTING;
24
25 public DomDocumentToXml()
26 {
27 setReturnDataType(DataTypeFactory.XML_STRING);
28 }
29
30 @Override
31 public Object transformMessage(MuleMessage message, String encoding) throws TransformerException
32 {
33 Object src = message.getPayload();
34 try
35 {
36
37
38 if (byte[].class.equals(returnType))
39 {
40 return convertToBytes(src, encoding);
41 }
42 else
43 {
44 return convertToText(src, encoding);
45 }
46 }
47 catch (Exception e)
48 {
49 throw new TransformerException(this, e);
50 }
51 }
52
53 public int getPriorityWeighting()
54 {
55 return priorityWeighting;
56 }
57
58 public void setPriorityWeighting(int priorityWeighting)
59 {
60 this.priorityWeighting = priorityWeighting;
61 }
62 }