001package org.kuali.ole; 002 003import com.thoughtworks.xstream.XStream; 004import org.kuali.ole.pojo.OleBibRecord; 005import org.kuali.ole.pojo.OleOrderRecord; 006import org.kuali.ole.pojo.OleTxRecord; 007import org.kuali.ole.pojo.bib.BibliographicRecord; 008import org.kuali.ole.pojo.edi.EDIOrder; 009 010/** 011 * Created by IntelliJ IDEA. 012 * User: pvsubrah 013 * Date: 4/9/12 014 * Time: 7:20 AM 015 * To change this template use File | Settings | File Templates. 016 */ 017public class OleOrderRecordHandler { 018 019 public OleOrderRecords fromXML(String marcXMLContent) { 020 XStream xStream = new XStream(); 021 xStream.alias("records", OleOrderRecords.class); 022 xStream.alias("record", OleOrderRecord.class); 023 xStream.alias("oleBibRecord", OleBibRecord.class); 024 xStream.aliasField("bibRecord", OleOrderRecord.class, "oleBibRecord"); 025 xStream.aliasField("bibFileName", OleOrderRecord.class, "oleOriginalBibRecordFileName"); 026 xStream.aliasField("ediFileName", OleOrderRecord.class, "originalEDIFileName"); 027 xStream.alias("oleTxRecord", OleTxRecord.class); 028 xStream.aliasField("transactionRecord", OleOrderRecord.class, "oleTxRecord"); 029 xStream.alias("originalRecord", BibliographicRecord.class); 030 xStream.aliasField("bibliographicRecord", OleOrderRecord.class, "originalRecord"); 031 xStream.alias("originalEdi", EDIOrder.class); 032 xStream.aliasField("ediOrder", OleOrderRecord.class, "originalEdi"); 033 xStream.addImplicitCollection(OleOrderRecords.class, "records"); 034 return (OleOrderRecords) xStream.fromXML(marcXMLContent); 035 } 036 037 038 public String toXML(OleOrderRecords oleOrderRecords) { 039 StringBuffer stringBuffer = new StringBuffer(); 040 stringBuffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 041 stringBuffer.append("\n"); 042 XStream xStream = new XStream(); 043 xStream.alias("records", OleOrderRecords.class); 044 xStream.alias("record", OleOrderRecord.class); 045 xStream.alias("oleBibRecord", OleBibRecord.class); 046 xStream.aliasField("bibRecord", OleOrderRecord.class, "oleBibRecord"); 047 xStream.aliasField("bibFileName", OleOrderRecord.class, "oleOriginalBibRecordFileName"); 048 xStream.aliasField("ediFileName", OleOrderRecord.class, "originalEDIFileName"); 049 xStream.alias("oleTxRecord", OleTxRecord.class); 050 xStream.aliasField("transactionRecord", OleOrderRecord.class, "oleTxRecord"); 051 xStream.alias("originalRecord", BibliographicRecord.class); 052 xStream.aliasField("bibliographicRecord", OleOrderRecord.class, "originalRecord"); 053 xStream.alias("originalEdi", EDIOrder.class); 054 xStream.aliasField("ediOrder", OleOrderRecord.class, "originalEdi"); 055 xStream.addImplicitCollection(OleOrderRecords.class, "records"); 056 String xml = xStream.toXML(oleOrderRecords); 057 stringBuffer.append(xml); 058 stringBuffer.append("\n"); 059 return stringBuffer.toString(); 060 } 061}