001package org.kuali.ole.handler;
002
003import com.thoughtworks.xstream.XStream;
004import org.kuali.ole.bo.diagnostics.OleSRUDiagnostic;
005
006/**
007 * Created with IntelliJ IDEA.
008 * User: ?
009 * Date: 7/16/12
010 * Time: 7:06 PM
011 * To change this template use File | Settings | File Templates.
012 */
013public class OleSRUDiagnosticsHandler {
014
015    /**
016     * this method is used to convert OleSRUDiagnostic object to an XML
017     *
018     * @param oleSRUDiagnostic object
019     * @return xml as a string
020     */
021    public String toXML(OleSRUDiagnostic oleSRUDiagnostic) {
022        StringBuffer stringBuffer = new StringBuffer();
023        stringBuffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<diagnostics>");
024        stringBuffer.append("\n");
025        XStream xStream = new XStream();
026        xStream.alias("diagnostic", OleSRUDiagnostic.class);
027        String xml = xStream.toXML(oleSRUDiagnostic);
028        xml = xml.replaceAll("<diagnostic>", "<diagnostic xmlns=\"http://www.loc.gov/zing/srw/diagnostic/\">");
029        xml += "\n</diagnostics>";
030        stringBuffer.append(xml);
031        return stringBuffer.toString();
032    }
033}