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   import org.kuali.ole.ncip.bo.OLECheckedOutItem;
7   import org.kuali.ole.ncip.bo.OLECheckedOutItems;
8   
9   /**
10   * Created with IntelliJ IDEA.
11   * User: sheiksalahudeenm
12   * Date: 8/19/13
13   * Time: 2:44 PM
14   * To change this template use File | Settings | File Templates.
15   */
16  public class OLECheckoutItemsConverter {
17      final Logger LOG = Logger.getLogger(OLECheckoutItemsConverter.class);
18      public String generateCheckOutItemXml(OLECheckedOutItems oLECheckedOutItems){
19          XStream xStream = new XStream();
20          xStream.alias("checkOutItems",OLECheckedOutItems.class);
21          xStream.alias("checkOutItem",OLECheckedOutItem.class);
22          xStream.addImplicitCollection(OLECheckedOutItems.class,"checkedOutItems");
23          return xStream.toXML(oLECheckedOutItems);
24      }
25  
26      public Object generateCheckoutItemObject(String xml){
27          XStream xStream = new XStream();
28          xStream.alias("checkOutItems",OLECheckedOutItems.class);
29          xStream.alias("checkOutItem",OLECheckedOutItem.class);
30          xStream.addImplicitCollection(OLECheckedOutItems.class,"checkedOutItems");
31          return xStream.fromXML(xml);
32      }
33  
34      public String generateGetCheckedOutItemsJson(String xml) {
35          OLECheckedOutItems oleCheckedOutItems = (OLECheckedOutItems)generateCheckoutItemObject(xml);
36          OleCirculationHandler xmlContentHandler = new OleCirculationHandler();
37          if(oleCheckedOutItems==null){
38              oleCheckedOutItems=new OLECheckedOutItems();
39          }
40          try{
41              return xmlContentHandler.marshalToJSON(oleCheckedOutItems);
42          }catch(Exception e){
43              LOG.error(e,e);
44          }
45          return null;
46      }
47  }