package weaver.interfaces.htsc.util;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;

public class XmlUtils {
  
  private static final String UTF_8 = "UTF-8";
  
  @SuppressWarnings("rawtypes")
  public static String toXml(Object object, Class clazz, boolean isAnnotation) {
    return toXml(object, clazz, isAnnotation, UTF_8);
  }
  
  @SuppressWarnings("rawtypes")
  public static String toXml(Object object, Class clazz, boolean isAnnotation, String encode) {
    XStream xstream = new XStream(new DomDriver(encode, new XmlFriendlyNameCoder("-_", "_")));
    xstream.setMode(XStream.NO_REFERENCES);
    if (isAnnotation) {
      xstream.processAnnotations(clazz);
    }
    return xstream.toXML(object);
  }
}
