Example usage for com.google.gson JsonObject toString

List of usage examples for com.google.gson JsonObject toString

Introduction

In this page you can find the example usage for com.google.gson JsonObject toString.

Prototype

@Override
public String toString() 

Source Link

Document

Returns a String representation of this element.

Usage

From source file:adminservlets_reports.BlockMessageJson.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*from  w  ww . j  a va 2  s .  c  om*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    AdminClass_ReportedItems art = new AdminClass_ReportedItems();
    AdminClass_ReportedMessages arm = new AdminClass_ReportedMessages();
    AdminClass_ReportedInquiries ari = new AdminClass_ReportedInquiries();
    AdminClass_Message am = new AdminClass_Message();
    String alert = null;

    if (request.getParameter("toBM") != null && request.getParameter("messageBM") != null) {

        AdminClass_BlockedMessages ab = new AdminClass_BlockedMessages();

        String inbox_content = "Hello,\n" + "\n" + "Your message \"" + request.getParameter("message_contentBM")
                + "\" in superb.lk is  disabled due to policy violations.\n\n"
                + "Policy violations cause accounts to be suspended.\n" + "\n\n" + "Regards,\n"
                + "The support team at Superb.lk\n";

        int inbox_result = am.sendMessage(inbox_content, request.getParameter("toBM"));
        int result = ab.blockMessage(request.getParameter("messageBM"));//blocking message
        int state = arm.updateViewState(request.getParameter("messageBM"));//updating report status

        if (result == 1 && state == 1) {

            alert = "<button class=\"btn btn-green\">" //returning notification of the success 
                    + "<i  class=\"glyphicon glyphicon-ok-sign\">"
                    + "</i></button><br><strong>Blocked !</strong>" + "  Message id "
                    + request.getParameter("messageBM") + "";

        } else {

            alert = "<button class=\"btn btn-red\">" //returning notification of the failure 
                    + "<i  class=\"glyphicon glyphicon-remove-circle\">"
                    + "</i></button><br><strong>Failed!</strong>" + " Message id "
                    + request.getParameter("messageBM") + " Try again.";

        }

    }
    PrintWriter out = response.getWriter();

    Gson gson = new Gson();
    JsonObject myObj = new JsonObject();

    myObj.addProperty("result", alert);

    out.write(myObj.toString());
    out.close();

}

From source file:adminservlets_reports.BlockMessageUserJson.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from   www .ja  v  a2  s .  c om
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    AdminClass_ReportedItems art = new AdminClass_ReportedItems();
    AdminClass_ReportedMessages arm = new AdminClass_ReportedMessages();
    AdminClass_ReportedInquiries ari = new AdminClass_ReportedInquiries();
    AdminClass_SendMail as = new AdminClass_SendMail();
    AdminClass_Links al = new AdminClass_Links();
    String alert = null;

    if (request.getParameter("toBMU") != null && request.getParameter("messageBMU") != null) {

        AdminClass_BlockedUsers ab = new AdminClass_BlockedUsers();

        String reciever = art.getUserEmail(request.getParameter("toBMU"));
        String subject = "About temporarily disabeling your account";

        String content = "Your account in Superb.lk is temporarily disabled due to invalid activity or policy violations.\n\n"
                + "Visit the link for common reasons and policy violations cause accounts to be suspended.\n";

        String link = "<a href='" + al.getPolicies()
                + "' target='blank'><p>Click here to view our privacy ploicies</p></a>";

        int result1 = ab.RemoveUser(request.getParameter("toBMU")); //removing user
        int result2 = ab.BlacklistUser(reciever); //blacklisting user
        int mail_result = as.mailClass(reciever, subject, content, link);//sending mail to the user

        if (result1 == 1 && result2 == 1) {

            alert = "<button class=\"btn btn-green\">" //returning notification of the success 
                    + "<i  class=\"glyphicon glyphicon-ok-sign\">"
                    + "</i></button><br><strong>Blocked !</strong>" + "  User " + reciever + "";

        } else {

            alert = "<button class=\"btn btn-red\">" //returning notification of the failure 
                    + "<i  class=\"glyphicon glyphicon-remove-circle\">"
                    + "</i></button><br><strong>Failed!</strong>" + " User " + reciever + " Try again.";

        }

    }
    PrintWriter out = response.getWriter();

    Gson gson = new Gson();
    JsonObject myObj = new JsonObject();

    myObj.addProperty("result", alert);

    out.write(myObj.toString());
    out.close();
}

From source file:adminservlets_reports.LoadAdReports.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//  w  w w.ja v  a2 s . c o m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    AdminClass_ReportedItems art = new AdminClass_ReportedItems();
    ArrayList ReportedItems = art.getItemReports();
    PrintWriter out = response.getWriter();

    Gson gson = new Gson();
    JsonObject myObj = new JsonObject();

    JsonElement x = gson.toJsonTree(ReportedItems);
    myObj.add("ReportedItems", x);

    out.write(myObj.toString());
    out.close();
}

From source file:adminservlets_reports.LoadInquiryReports.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*from  w  w  w .ja v  a 2  s . co  m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    AdminClass_ReportedInquiries ari = new AdminClass_ReportedInquiries();
    ArrayList ReportedInquiries = ari.getInquiryReports();
    PrintWriter out = response.getWriter();

    Gson gson = new Gson();
    JsonObject myObj = new JsonObject();

    JsonElement x = gson.toJsonTree(ReportedInquiries);
    myObj.add("ReportedInquiries", x);

    out.write(myObj.toString());
    out.close();
}

From source file:adminservlets_reports.LoadMessageReports.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*w  ww.  ja  v a  2  s .  co m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    AdminClass_ReportedMessages arm = new AdminClass_ReportedMessages();
    ArrayList ReportedMessages = arm.getMessageReports();
    PrintWriter out = response.getWriter();

    Gson gson = new Gson();
    JsonObject myObj = new JsonObject();

    JsonElement x = gson.toJsonTree(ReportedMessages);
    myObj.add("ReportedMessages", x);

    out.write(myObj.toString());
    out.close();
}

From source file:adminservlets_reports.LoadReportCountJson.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from   w w  w .  jav a2  s  .  c om
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    AdminClass_ReportedItems art = new AdminClass_ReportedItems();
    AdminClass_ReportedMessages arm = new AdminClass_ReportedMessages();
    AdminClass_ReportedInquiries ari = new AdminClass_ReportedInquiries();

    String reportCount = String.valueOf(art.getItemReportCount());
    if ("0".equals(reportCount)) {
        reportCount = "";
    }
    request.setAttribute("reportCount", reportCount);
    String message_report_count = String.valueOf(arm.getMessageReportCount());
    if ("0".equals(message_report_count)) {
        message_report_count = "";
    }
    request.setAttribute("message_report_count", message_report_count);
    String Inquiry_report_count = String.valueOf(ari.getInquiryReportCount());
    if ("0".equals(Inquiry_report_count)) {
        Inquiry_report_count = "";
    }
    request.setAttribute("Inquiry_report_count", Inquiry_report_count);
    PrintWriter out = response.getWriter();

    Gson gson = new Gson();
    JsonObject myObj = new JsonObject();

    myObj.addProperty("message_report_count", message_report_count);
    myObj.addProperty("Inquiry_report_count", Inquiry_report_count);
    myObj.addProperty("reportCount", reportCount);

    out.write(myObj.toString());
    out.close();
}

From source file:adminservlets_reports.RemoveAdReportJson.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*from w w  w  .j av  a2s .  c  o  m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    AdminClass_ReportedItems art = new AdminClass_ReportedItems();
    String alert = null;

    if (request.getParameter("removeReport") != null) {

        int result = art.updateViewState(request.getParameter("removeReport"));//updating report status

        if (result == 1) {

            alert = "<button class=\"btn btn-green\">" //returning notification of the success 
                    + "<i  class=\"glyphicon glyphicon-ok-sign\">"
                    + "</i></button><br><strong>Removed !</strong>" + "  report number "
                    + request.getParameter("removeReport") + "";

        } else {

            alert = "<button class=\"btn btn-red\">" //returning notification of the failure 
                    + "<i  class=\"glyphicon glyphicon-remove-circle\">"
                    + "</i></button><br><strong>Failed!</strong>" + " report number "
                    + request.getParameter("removeReport") + " Try again.";

        }
    }
    PrintWriter out = response.getWriter();

    Gson gson = new Gson();
    JsonObject myObj = new JsonObject();

    myObj.addProperty("result", alert);

    out.write(myObj.toString());
    out.close();
}

From source file:adminservlets_reports.RemoveInquiryReportJson.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*w  w  w .  ja v  a2 s .c  o  m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    AdminClass_ReportedItems art = new AdminClass_ReportedItems();
    AdminClass_ReportedMessages arm = new AdminClass_ReportedMessages();
    AdminClass_ReportedInquiries ari = new AdminClass_ReportedInquiries();
    String alert = null;

    if (request.getParameter("removeReport") != null) {

        int result = ari.updateViewState(request.getParameter("removeReport"));// removing inquiry report
        if (result == 1) {
            alert = "<button class=\"btn btn-green\">" //returning notification of the success 
                    + "<i  class=\"glyphicon glyphicon-ok-sign\">"
                    + "</i></button><br><strong>Removed !</strong>" + "  Inquiry report id "
                    + request.getParameter("removeReport") + "";

        } else {
            alert = "<button class=\"btn btn-red\">" //returning notification of the failure 
                    + "<i  class=\"glyphicon glyphicon-remove-circle\">"
                    + "</i></button><br><strong>Failed!</strong>" + " Inquiry report id "
                    + request.getParameter("removeReport") + " Try again.";

        }
    }
    PrintWriter out = response.getWriter();

    Gson gson = new Gson();
    JsonObject myObj = new JsonObject();

    myObj.addProperty("result", alert);

    out.write(myObj.toString());
    out.close();
}

From source file:adminservlets_reports.RemoveMessageReportJson.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*  w ww. j av  a 2 s . c om*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    AdminClass_ReportedItems art = new AdminClass_ReportedItems();
    AdminClass_ReportedMessages arm = new AdminClass_ReportedMessages();
    AdminClass_ReportedInquiries ari = new AdminClass_ReportedInquiries();
    String alert = null;

    if (request.getParameter("removeReport") != null) {

        int result = arm.updateViewState(request.getParameter("removeReport"));//updating report status

        if (result == 1) {

            alert = "<button class=\"btn btn-green\">" //returning notification of the success 
                    + "<i  class=\"glyphicon glyphicon-ok-sign\">"
                    + "</i></button><br><strong>Removed !</strong>" + "  Report id  "
                    + request.getParameter("removeReport") + "";

        } else {
            alert = "<button class=\"btn btn-red\">" //returning notification of the failure 
                    + "<i  class=\"glyphicon glyphicon-remove-circle\">"
                    + "</i></button><br><strong>Failed!</strong>" + " Report id "
                    + request.getParameter("removeReport") + " Try again.";

        }
    }
    PrintWriter out = response.getWriter();

    Gson gson = new Gson();
    JsonObject myObj = new JsonObject();

    myObj.addProperty("result", alert);

    out.write(myObj.toString());
    out.close();
}

From source file:app.abhijit.iter.data.source.remote.IterApi.java

License:Open Source License

public static String fetchStudentId(String registrationNumber) throws Exception {
    JsonObject request = new JsonObject();
    request.addProperty("sid", "validate");
    request.addProperty("instituteID", INSTITUTE_ID);
    request.addProperty("studentrollno", registrationNumber);
    return Http.post(API_ENDPOINT, "jdata=" + request.toString());
}