Guest User

Utility.java

a guest
Jul 9th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. package com.prgguru.jersey;
  2.  
  3. import org.codehaus.jettison.json.JSONException;
  4. import org.codehaus.jettison.json.JSONObject;
  5.  
  6. public class Utility {
  7.      /**
  8.      * Null check Method
  9.      *
  10.      * @param txt
  11.      * @return
  12.      */
  13.     public static boolean isNotNull(String txt) {
  14.         // System.out.println("Inside isNotNull");
  15.         return txt != null && txt.trim().length() >= 0 ? true : false;
  16.     }
  17.  
  18.     /**
  19.      * Method to construct JSON
  20.      *
  21.      * @param tag
  22.      * @param status
  23.      * @return
  24.      */
  25.     public static String constructJSON(String tag, boolean status) {
  26.         JSONObject obj = new JSONObject();
  27.         try {
  28.             obj.put("tag", tag);
  29.             obj.put("status", new Boolean(status));
  30.         } catch (JSONException e) {
  31.             // TODO Auto-generated catch block
  32.         }
  33.         return obj.toString();
  34.     }
  35.  
  36.     /**
  37.      * Method to construct JSON with Error Msg
  38.      *
  39.      * @param tag
  40.      * @param status
  41.      * @param err_msg
  42.      * @return
  43.      */
  44.     public static String constructJSON(String tag, boolean status,String err_msg) {
  45.         JSONObject obj = new JSONObject();
  46.         try {
  47.             obj.put("tag", tag);
  48.             obj.put("status", new Boolean(status));
  49.             obj.put("error_msg", err_msg);
  50.         } catch (JSONException e) {
  51.             // TODO Auto-generated catch block
  52.         }
  53.         return obj.toString();
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment