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
10
11
12
13
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 }