List of usage examples for com.google.gson JsonObject addProperty
public void addProperty(String property, Character value)
From source file:adminservlets_reports.BlockAdUserJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*w w w . ja va 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_ReportedItems art = new AdminClass_ReportedItems(); AdminClass_SendMail as = new AdminClass_SendMail(); AdminClass_Links al = new AdminClass_Links(); String alert = null; if (request.getParameter("toBU") != null && request.getParameter("reportBU") != null) { AdminClass_BlockedUsers ab = new AdminClass_BlockedUsers(); String reciever = art.getUserEmail(request.getParameter("toBU")); 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("toBU")); //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.BlockInquiryJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/* w ww.j a v a2 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_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("toBI") != null && request.getParameter("inquiryBI") != null) { AdminClass_BlockedInquiries ab = new AdminClass_BlockedInquiries(); String inbox_content = "Hello,\n" + "\n" + "Your Inquiry \"" + request.getParameter("inquiry_contentBI") + "\" 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("toBI")); int result = ab.blockInquiries(request.getParameter("inquiryBI"));//blocking inquiry if (result == 1) { alert = "<button class=\"btn btn-green\">" //returning notification of the success + "<i class=\"glyphicon glyphicon-ok-sign\">" + "</i></button><br><strong>Blocked !</strong>" + " Inquiry id " + request.getParameter("inquiryBI") + ""; } 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 id " + request.getParameter("inquiryBI") + " 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.BlockInquiryUser.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from ww w .j a 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(); AdminClass_SendMail as = new AdminClass_SendMail(); AdminClass_Links al = new AdminClass_Links(); String alert = null; if (request.getParameter("toBIU") != null) { AdminClass_BlockedUsers ab = new AdminClass_BlockedUsers(); String reciever = art.getUserEmail(request.getParameter("toBIU")); 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 mail_result = as.mailClass(reciever, subject, content, link);//sending mail to the user int result1 = ab.RemoveUser(request.getParameter("toBIU")); //removing user int result2 = ab.BlacklistUser(reciever); //blacklisting 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.BlockMessageJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//w w w . ja v a2s . 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_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 w w w . j a v a 2 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(); 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.LoadReportCountJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from ww w . j a v a 2s .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 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 a va2 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(); 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//from w w w .j a v a 2 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 w w .j a v a 2s.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_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:ai.olami.cloudService.TextRecognizer.java
License:Apache License
private APIResponse sendRequest(String apiName, String text, NLIConfig nliConfig) throws NoSuchAlgorithmException, IOException { StringBuffer httpQueryStringBuffer = new StringBuffer(); if (apiName == APIConfiguration.API_NAME_SEG) { httpQueryStringBuffer.append("rq="); httpQueryStringBuffer.append(text); } else if (apiName == APIConfiguration.API_NAME_NLI) { JsonObject data = new JsonObject(); data.addProperty("input_type", mRqDataInputType); data.addProperty("text", text); JsonObject rq = new JsonObject(); rq.addProperty("data_type", "stt"); rq.add("data", data); if (nliConfig != null) { rq.add("nli_config", nliConfig.toJsonElement()); }// ww w.j av a2 s. c om httpQueryStringBuffer.append("rq="); httpQueryStringBuffer.append(mGson.toJson(rq)); } final URL url = new URL(getConfiguration().getBaseRequestURL(apiName)); final HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); httpConnection.setRequestMethod("POST"); httpConnection.setRequestProperty("contentType", "utf-8"); httpConnection.setConnectTimeout(getTimeout()); HttpClient httpClient = null; String response = null; try { httpClient = new HttpClient(httpConnection); httpClient.postQueryConnect(httpQueryStringBuffer.toString()); if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { response = httpClient.getResponseContent(); } else { throw new IOException(httpClient.getResponseMessage()); } } finally { httpClient.close(); } return APIResponseBuilder.create(response); }