List of usage examples for com.google.gson JsonObject addProperty
public void addProperty(String property, Character value)
From source file:adminservlets_Json.CheckPassJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//w w w . ja 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_LoginMethods lm = new AdminClass_LoginMethods(); boolean result = lm.checkPass(request.getParameter("username"), request.getParameter("password")); if (result == true) { HttpSession session = request.getSession(); session.setAttribute("login_change", "true"); } PrintWriter out = response.getWriter(); Gson gson = new Gson(); JsonObject myObj = new JsonObject(); myObj.addProperty("result", result); out.write(myObj.toString()); out.close(); }
From source file:adminservlets_Json.CustomDataAdsJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/* w w w . j av 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 { String fd = request.getParameter("fd"); String sd = request.getParameter("sd"); String result; AdminClass_Overviewstats ao = new AdminClass_Overviewstats(); boolean checkFD = ao.isValidDate(fd); boolean checkSD = ao.isValidDate(sd); if (checkFD == true && checkSD == true) { ArrayList al = ao.adsCustom(fd, sd); DecimalFormat twoDForm = new DecimalFormat("#.#"); if (al.get(1).equals("0")) { result = "Ads : " + (String) al.get(1) + " Percentage: 0%"; } else { result = "Ads: " + (String) al.get(1) + " Percentage: " + twoDForm.format( Float.parseFloat((String) al.get(1)) / Float.parseFloat((String) al.get(0)) * 100) + "%"; } } else { result = "Incorrect entry"; } PrintWriter out = response.getWriter(); Gson gson = new Gson(); JsonObject myObj = new JsonObject(); myObj.addProperty("result", result); out.write(myObj.toString()); out.close(); }
From source file:adminservlets_Json.CustomDataJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w w w. ja 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 { String fd = request.getParameter("fd"); String sd = request.getParameter("sd"); String result; AdminClass_Overviewstats ao = new AdminClass_Overviewstats(); boolean checkFD = ao.isValidDate(fd); boolean checkSD = ao.isValidDate(sd); if (checkFD == true && checkSD == true) { ArrayList al = ao.pagevisitCustom(fd, sd); DecimalFormat twoDForm = new DecimalFormat("#.#"); if (al.get(1).equals("0")) { result = "Site visit: " + (String) al.get(1) + " Percentage: 0%"; } else { result = "Site visit: " + (String) al.get(1) + " Percentage: " + twoDForm.format( Float.parseFloat((String) al.get(1)) / Float.parseFloat((String) al.get(0)) * 100) + "%"; } } else { result = "Incorrect entry"; } PrintWriter out = response.getWriter(); Gson gson = new Gson(); JsonObject myObj = new JsonObject(); myObj.addProperty("result", result); out.write(myObj.toString()); out.close(); }
From source file:adminservlets_Json.CustomDataUserJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w w w . j a v a2s . com * @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 { String fd = request.getParameter("fd"); String sd = request.getParameter("sd"); String result; AdminClass_Overviewstats ao = new AdminClass_Overviewstats(); boolean checkFD = ao.isValidDate(fd); boolean checkSD = ao.isValidDate(sd); if (checkFD == true && checkSD == true) { ArrayList al = ao.usersCustom(fd, sd); DecimalFormat twoDForm = new DecimalFormat("#.#"); if (al.get(1).equals("0")) { result = "Users : " + (String) al.get(1) + " Percentage: 0%"; } else { result = "Users: " + (String) al.get(1) + " Percentage: " + twoDForm.format( Float.parseFloat((String) al.get(1)) / Float.parseFloat((String) al.get(0)) * 100) + "%"; } } else { result = "Incorrect entry"; } PrintWriter out = response.getWriter(); Gson gson = new Gson(); JsonObject myObj = new JsonObject(); myObj.addProperty("result", result); out.write(myObj.toString()); out.close(); }
From source file:adminservlets_Json.DataCountsJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w ww . j a 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_NavbarTools an = new AdminClass_NavbarTools(); AdminClass_Overviewstats ao = new AdminClass_Overviewstats(); AdminClass_CurrentState ac = new AdminClass_CurrentState(); ac.updateState(); String messageCount = String.valueOf(an.messageCount()); if ("0".equals(messageCount)) { messageCount = ""; } String ads = ao.reviewAdsCount(); if ("0".equals(ads)) { ads = ""; } String reports = ao.reportCount(); if ("0".equals(reports)) { reports = ""; } PrintWriter out = response.getWriter(); Gson gson = new Gson(); JsonObject myObj = new JsonObject(); myObj.addProperty("messageCount", messageCount); myObj.addProperty("ads", ads); myObj.addProperty("reports", reports); myObj.addProperty("topads", "N/A"); out.write(myObj.toString()); out.close(); }
From source file:adminservlets_Json.DetailedViewJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w w 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 { String id = request.getParameter("id"); ArrayList al; AdminClass_DetailedView ad = new AdminClass_DetailedView(); PrintWriter out = response.getWriter(); Gson gson = new Gson(); JsonObject myObj = new JsonObject(); if ("U".equals(String.valueOf(id.charAt(0)))) { al = ad.userDetailedView(id.substring(1)); myObj.addProperty("username", (String) al.get(0)); myObj.addProperty("email", (String) al.get(1)); myObj.addProperty("tel", (String) al.get(2)); myObj.addProperty("reg", (String) al.get(3)); myObj.addProperty("status", (String) al.get(4)); myObj.addProperty("activation", (String) al.get(5)); myObj.addProperty("login", (String) al.get(6)); myObj.addProperty("ads", (String) al.get(7)); } else if ("M".equals(String.valueOf(id.charAt(0)))) { al = ad.messageDetailedView(id.substring(1)); myObj.addProperty("id", (String) al.get(0)); myObj.addProperty("sender", (String) al.get(1)); myObj.addProperty("reciever", (String) al.get(2)); myObj.addProperty("content", (String) al.get(3)); myObj.addProperty("time", (String) al.get(4)); } else if ("1".equals(String.valueOf(id.charAt(0)))) { al = ad.reportItemDetailedView(id.substring(1)); myObj.addProperty("id", (String) al.get(0)); myObj.addProperty("email", (String) al.get(1)); myObj.addProperty("reason", (String) al.get(2)); myObj.addProperty("message", (String) al.get(3)); myObj.addProperty("item", (String) al.get(4)); myObj.addProperty("title", (String) al.get(5)); } else if ("2".equals(String.valueOf(id.charAt(0)))) { al = ad.reportInquiryDetailedView(id.substring(1)); myObj.addProperty("id", (String) al.get(0)); myObj.addProperty("item", (String) al.get(1)); myObj.addProperty("message_to", (String) al.get(2)); myObj.addProperty("message_from", (String) al.get(3)); myObj.addProperty("message", (String) al.get(4)); myObj.addProperty("message_time", (String) al.get(5)); myObj.addProperty("response", (String) al.get(6)); myObj.addProperty("response_time", (String) al.get(7)); } else if ("3".equals(String.valueOf(id.charAt(0)))) { al = ad.reportMessageDetailedView(id.substring(1)); myObj.addProperty("id", (String) al.get(0)); myObj.addProperty("sender", (String) al.get(1)); myObj.addProperty("reciever", (String) al.get(2)); myObj.addProperty("content", (String) al.get(3)); myObj.addProperty("message_time", (String) al.get(4)); myObj.addProperty("reported_time", (String) al.get(5)); } else { String tilte = ad.itemDetailedView(String.valueOf(id.substring(1))); myObj.addProperty("id", tilte); } out.write(myObj.toString()); out.close(); }
From source file:adminservlets_Json.GetStateJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/* w w 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_CurrentState ac = new AdminClass_CurrentState(); String state = String.valueOf(ac.getState()); PrintWriter out = response.getWriter(); Gson gson = new Gson(); JsonObject myObj = new JsonObject(); myObj.addProperty("state", state); out.write(myObj.toString()); out.close(); }
From source file:adminservlets_Json.MsgJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from ww w . j a v a 2 s . com * @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_Message am = new AdminClass_Message(); String filter; if (request.getParameter("filter") == null) { filter = " "; } else { filter = request.getParameter("filter"); } ArrayList al = am.allMessages(filter); Iterator itr = al.iterator(); AdminClass_Message received = null; PrintWriter out = response.getWriter(); Gson gson = new Gson(); JsonObject myObj = new JsonObject(); out.write(myObj.toString()); out.close(); while (itr.hasNext()) { Object a = itr.next(); received = (AdminClass_Message) a; if (request.getParameter("sid") == null || "".equals(request.getParameter("sid"))) { String time = received.getTimeStamp(); if ("0".equals(received.getState())) { myObj.addProperty("sender", (String) received.getSender()); myObj.addProperty("content", (String) received.getContent()); myObj.addProperty("time", (String) time); myObj.addProperty("status", "style=\"background-color:#E2DEE3;\""); } else { myObj.addProperty("sender", (String) received.getSender()); myObj.addProperty("content", (String) received.getContent()); myObj.addProperty("time", (String) time); myObj.addProperty("status", ""); } } else { if (received.getSender().contains(request.getParameter("sid"))) { String time = am.timeDiff(received.getTimeStamp()); if ("0".equals(received.getState())) { myObj.addProperty("sender", (String) received.getSender()); myObj.addProperty("content", (String) received.getContent()); myObj.addProperty("time", (String) time); myObj.addProperty("status", "style=\"background-color:#E2DEE3;\""); } else { myObj.addProperty("sender", (String) received.getSender()); myObj.addProperty("content", (String) received.getContent()); myObj.addProperty("time", (String) time); myObj.addProperty("status", ""); } } } } }
From source file:adminservlets_Json.UserBlacklistJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from www . j a 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_BlacklistedEmails ab = new AdminClass_BlacklistedEmails(); AdminClass_SendMail as = new AdminClass_SendMail(); AdminClass_Links al = new AdminClass_Links(); String alert = null; if (request.getParameter("email_unblock") != null) { //checking blacklist action boolean exists = ab.getEnteredEmail(request.getParameter("email_unblock"));//checking exsistence if (exists == true) { int result = ab.unblockEmail(request.getParameter("email_unblock"));//unblacklist an email if (result == 1) { //returning notification of the success alert = "<button class=\"btn btn-green\"><i class=\"" + "glyphicon glyphicon-ok-sign\"></i></button><br><strong>" + "Unblocked !</strong> Email- " + request.getParameter("email_unblock") + ""; } else { alert = "<button class=\"btn btn-red\">" //returning notification of the failure + "<i class=\"glyphicon glyphicon-remove-circle\"></i></button><br><strong>" + "Failed !</strong> Email- " + request.getParameter("email_unblock") + ""; } } else { //returning notification of the failure alert = "<button class=\"btn btn-red\"><i class=\"" + "glyphicon glyphicon-remove-circle\"></i></button><br><strong>" + "Failed !</strong> Email- " + request.getParameter("email_unblock") + " " + "Does not exsist in the list"; } } else if (request.getParameter("email_block") != null) { //checking if the email is null boolean exists = ab.getEnteredEmail(request.getParameter("email_block"));//checking if the email is already blacklisted if (exists == true) { //returning notification of the failure alert = "<button class=\"btn btn-red\"><i class=\"" + "glyphicon glyphicon-remove-circle\"></i></button><br><strong>" + "Failed !</strong> Email- " + request.getParameter("email_block") + " " + "is already blacklisted"; } else { boolean exsist = ab.checkUserEmail(request.getParameter("email_block")); //check for current user if (exsist == true) { ab.RemoveUser(request.getParameter("email_block")); //remove current user content } int result = ab.blockEmail(request.getParameter("email_block")); //blacklisting an email 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(request.getParameter("email_block"), subject, content, link);//sending mail to the user if (result == 1) { //returning notification of the success alert = "<button class=\"btn btn-green\"><i class=\"" + "glyphicon glyphicon-ok-sign\"></i></button><br><strong>" + "Blocked !</strong> Email- " + request.getParameter("email_block") + ""; } else { alert = "<button class=\"btn btn-red\"><i class=\"" + "glyphicon glyphicon-remove-circle\"></i></button><br><strong>" + "Failed !</strong> Email- " + request.getParameter("email_block") + ""; } } } 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.BlockAdJson.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w ww .j a v 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 { String alert = null; if (request.getParameter("itemBA") != null && request.getParameter("reportBA") != null) { AdminClass_ReportedItems art = new AdminClass_ReportedItems(); AdminClass_SendMail as = new AdminClass_SendMail(); AdminClass_Message am = new AdminClass_Message(); AdminClass_BlockedItems ab = new AdminClass_BlockedItems(); AdminClass_Links al = new AdminClass_Links(); String reciever = art.getUserEmail(request.getParameter("toBA")); String subject = request.getParameter("subjectBA"); String edit_link = "<a href='" + al.getAdEdit() + "' target='blank'><p>Click here to Edit your advertisement</p></a>"; String content = request.getParameter("contentBA_header") + "<br/><br/>" + request.getParameter("contentBA_body"); String itemId = request.getParameter("itemBA"); String reason = "Blocked due to- " + request.getParameter("reasonBA"); String inbox_content = request.getParameter("contentBA_header") + request.getParameter("contentBA_body") + "\n\nPlease update your ad" + "\n" + "Regards,\n" + "The support team at Superb.lk\n" + "\n"; int result = ab.blockItem(itemId, reason); //blocking advertiesment int state = art.updateViewState(request.getParameter("reportBA"));//update report status int inbox_result = am.sendMessage(inbox_content, request.getParameter("toBA")); int result2 = as.mailClass(reciever, subject, content, edit_link);//sending mail to the user 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> Advertiesment number " + itemId + " "; } else { alert = "<button class=\"btn btn-red\">" //returning notification of the failure + "<i class=\"glyphicon glyphicon-remove-circle\">" + "</i></button><br><strong>Failed!</strong> Advertiesment number " + itemId + " Try again."; } } PrintWriter out = response.getWriter(); Gson gson = new Gson(); JsonObject myObj = new JsonObject(); myObj.addProperty("result", alert); out.write(myObj.toString()); out.close(); }