View Javadoc
1   package org.kuali.ole.converter;
2   
3   import com.thoughtworks.xstream.XStream;
4   import org.apache.log4j.Logger;
5   import org.kuali.ole.bo.OLECheckInItem;
6   
7   /**
8    * Created with IntelliJ IDEA.
9    * User: maheswarang
10   * Date: 7/29/13
11   * Time: 8:44 PM
12   * To change this template use File | Settings | File Templates.
13   */
14  public class OLECheckInItemConverter {
15      final Logger LOG = Logger.getLogger(OLECheckInItemConverter.class);
16  
17      public String generateCheckInItemXml(OLECheckInItem oleCheckInItem){
18          XStream xStream = new XStream();
19          xStream.alias("checkInItem",OLECheckInItem.class);
20          xStream.omitField(OLECheckInItem.class, "patronBarcode");
21          xStream.omitField(OLECheckInItem.class, "itemLocation");
22          return xStream.toXML(oleCheckInItem);
23      }
24  
25      public String generateCheckInItemXmlForSIP2(OLECheckInItem oleCheckInItem){
26           XStream xStream = new XStream();
27           xStream.alias("checkInItem",OLECheckInItem.class);
28           return xStream.toXML(oleCheckInItem);
29       }
30  
31      public Object generateCheckInItemObject(String xml){
32          XStream xStream = new XStream();
33          xStream.alias("checkInItem",OLECheckInItem.class);
34          return xStream.fromXML(xml);
35      }
36      public String generateCheckInItemJson(String xml) {
37          OLECheckInItem oleCheckedInItems = (OLECheckInItem)generateCheckInItemObject(xml);
38          OleCirculationHandler xmlContentHandler = new OleCirculationHandler();
39          try{
40              return xmlContentHandler.marshalToJSON(oleCheckedInItems);
41          }catch(Exception e){
42              LOG.error(e,e);
43          }
44          return null;
45      }
46  
47  }