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