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