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.OLELookupUserResponse;
6   import org.kuali.ole.ncip.bo.OLEUserPrivilege;
7   
8   /**
9    * Created with IntelliJ IDEA.
10   * User: sheiksalahudeenm
11   * Date: 9/4/13
12   * Time: 12:05 PM
13   * To change this template use File | Settings | File Templates.
14   */
15  public class OLELookupUserResponseConverter {
16      final Logger LOG = Logger.getLogger(OLELookupUserResponseConverter.class);
17  
18      public String generateLookupUserResponseXml(OLELookupUserResponse lookupUser){
19          XStream xstream = new XStream();
20          xstream.alias("lookupUser",OLELookupUserResponse.class);
21          xstream.alias("userPrivilege",OLEUserPrivilege.class);
22          xstream.aliasField("userPrivileges", OLELookupUserResponse.class, "userPrivileges");
23          String response  =xstream.toXML(lookupUser);
24  
25          System.out.println(response);
26          return  response;
27      }
28  
29  
30  
31      public OLELookupUserResponse getLookupUser(String xml){
32          XStream xstream = new XStream();
33          xstream.alias("lookupUser",OLELookupUserResponse.class);
34          xstream.alias("userPrivilege",OLEUserPrivilege.class);
35          xstream.aliasField("userPrivileges", OLELookupUserResponse.class, "userPrivileges");
36          OLELookupUserResponse oleLookupUser   =(OLELookupUserResponse)xstream.fromXML(xml);
37          return oleLookupUser;
38      }
39  
40      public String generateLookupUserJson(String xml) {
41          OLELookupUserResponse oleLookupUser = (OLELookupUserResponse)getLookupUser(xml);
42          OleCirculationHandler xmlContentHandler = new OleCirculationHandler();
43          try{
44              return xmlContentHandler.marshalToJSON(oleLookupUser);
45          }catch(Exception e){
46              LOG.error(e,e);
47          }
48          return null;
49      }
50  
51  
52  
53  
54  }