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.OLECheckOutItem;
6   
7   /**
8    * Created with IntelliJ IDEA.
9    * User: maheswarang
10   * Date: 7/29/13
11   * Time: 8:54 PM
12   * To change this template use File | Settings | File Templates.
13   */
14  public class OLECheckOutItemConverter {
15      final Logger LOG = Logger.getLogger(OLECheckOutItemConverter.class);
16  
17      public String generateCheckOutItemXml(OLECheckOutItem oleCheckOutItem){
18          XStream xStream = new XStream();
19          xStream.alias("checkOutItem",OLECheckOutItem.class);
20          xStream.omitField(OLECheckOutItem.class, "titleIdentifier");
21          xStream.omitField(OLECheckOutItem.class, "feeAmount");
22          xStream.omitField(OLECheckOutItem.class, "feeType");
23          xStream.omitField(OLECheckOutItem.class, "transactionId");
24          xStream.omitField(OLECheckOutItem.class, "itemProperties");
25          return xStream.toXML(oleCheckOutItem);
26      }
27      
28      public String generateCheckOutItemXmlForSIP2(OLECheckOutItem oleCheckOutItem){
29          XStream xStream = new XStream();
30          xStream.alias("checkOutItem",OLECheckOutItem.class);
31          return xStream.toXML(oleCheckOutItem);
32      }
33  
34      public Object generateCheckoutItemObject(String xml){
35          XStream xStream = new XStream();
36          xStream.alias("checkOutItem",OLECheckOutItem.class);
37          return xStream.fromXML(xml);
38      }
39      public String generateCheckOutItemJson(String xml) {
40          OLECheckOutItem oleCheckOutItem = (OLECheckOutItem)generateCheckoutItemObject(xml);
41          OleCirculationHandler xmlContentHandler = new OleCirculationHandler();
42          try{
43              return xmlContentHandler.marshalToJSON(oleCheckOutItem);
44          }catch(Exception e){
45              LOG.error(e,e);
46          }
47          return null;
48      }
49  }