View Javadoc
1   package org.kuali.ole.ncip.converter;
2   
3   import com.thoughtworks.xstream.XStream;
4   import org.apache.log4j.Logger;
5   import org.kuali.ole.ncip.bo.OLEAcceptItem;
6   
7   /**
8    * Created with IntelliJ IDEA.
9    * User: sheiksalahudeenm
10   * Date: 9/3/13
11   * Time: 9:07 PM
12   * To change this template use File | Settings | File Templates.
13   */
14  public class OLEAcceptItemConverter {
15      final Logger LOG = Logger.getLogger(OLEAcceptItemConverter.class);
16      public String generateAcceptItemXml(OLEAcceptItem oleAcceptItem){
17          XStream xStream = new XStream();
18          xStream.alias("acceptItem",OLEAcceptItem.class);
19          return xStream.toXML(oleAcceptItem);
20      }
21      public Object generateAcceptItemObject(String xml){
22          XStream xStream = new XStream();
23          xStream.alias("acceptItem",OLEAcceptItem.class);
24          return xStream.fromXML(xml);
25      }
26      public String generateAcceptItemJson(String xml) {
27          OLEAcceptItem oleAcceptItem = (OLEAcceptItem)generateAcceptItemObject(xml);
28          OleCirculationHandler xmlContentHandler = new OleCirculationHandler();
29          if(oleAcceptItem==null){
30              oleAcceptItem=new OLEAcceptItem();
31          }
32          try{
33              return xmlContentHandler.marshalToJSON(oleAcceptItem);
34          }catch(Exception e){
35              LOG.error(e,e);
36          }
37          return null;
38      }
39  }