001package org.kuali.ole.ncip.converter; 002 003import com.thoughtworks.xstream.XStream; 004import org.apache.log4j.Logger; 005import org.kuali.ole.ncip.bo.OLECheckInItem; 006 007/** 008 * Created with IntelliJ IDEA. 009 * User: maheswarang 010 * Date: 7/29/13 011 * Time: 8:44 PM 012 * To change this template use File | Settings | File Templates. 013 */ 014public class OLECheckInItemConverter { 015 final Logger LOG = Logger.getLogger(OLECheckInItemConverter.class); 016 017 public String generateCheckInItemXml(OLECheckInItem oleCheckInItem){ 018 XStream xStream = new XStream(); 019 xStream.alias("checkInItem",OLECheckInItem.class); 020 xStream.omitField(OLECheckInItem.class, "patronBarcode"); 021 xStream.omitField(OLECheckInItem.class, "itemLocation"); 022 return xStream.toXML(oleCheckInItem); 023 } 024 025 public String generateCheckInItemXmlForSIP2(OLECheckInItem oleCheckInItem){ 026 XStream xStream = new XStream(); 027 xStream.alias("checkInItem",OLECheckInItem.class); 028 return xStream.toXML(oleCheckInItem); 029 } 030 031 public Object generateCheckInItemObject(String xml){ 032 XStream xStream = new XStream(); 033 xStream.alias("checkInItem",OLECheckInItem.class); 034 return xStream.fromXML(xml); 035 } 036 public String generateCheckInItemJson(String xml) { 037 OLECheckInItem oleCheckedInItems = (OLECheckInItem)generateCheckInItemObject(xml); 038 OleCirculationHandler xmlContentHandler = new OleCirculationHandler(); 039 try{ 040 return xmlContentHandler.marshalToJSON(oleCheckedInItems); 041 }catch(Exception e){ 042 LOG.error(e,e); 043 } 044 return null; 045 } 046 047}