1 10 11 package org.mule.transformers.codec; 12 13 import org.mule.config.i18n.Message; 14 import org.mule.config.i18n.Messages; 15 import org.mule.transformers.AbstractTransformer; 16 import org.mule.umo.transformer.TransformerException; 17 import org.mule.util.XMLEntityCodec; 18 19 22 public class XmlEntityDecoder extends AbstractTransformer 23 { 24 27 private static final long serialVersionUID = -3198566471610838679L; 28 29 public XmlEntityDecoder() 30 { 31 registerSourceType(String .class); 32 registerSourceType(byte[].class); 33 setReturnClass(String .class); 34 } 35 36 public Object doTransform(Object src, String encoding) throws TransformerException 37 { 38 try 39 { 40 String data; 41 42 if (src instanceof byte[]) 43 { 44 data = new String ((byte[])src, encoding); 45 } 46 else 47 { 48 data = (String )src; 49 } 50 51 return XMLEntityCodec.decodeString(data); 52 } 53 catch (Exception ex) 54 { 55 throw new TransformerException(new Message(Messages.TRANSFORM_FAILED_FROM_X_TO_X, src.getClass() 56 .getName(), "XML"), this, ex); 57 58 } 59 } 60 61 } 62 | Popular Tags |