List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:Controlador.Contr_Satisfaccion.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w .j ava2s.c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); //declaramos las variables necesarias para todo el proyecto String Mensaje, Comentario, Rating, CodigoEvento, CodigoUsuario; HttpSession session = request.getSession(true); Cls_Satisfaccion sat = new Cls_Satisfaccion(); //evaluamos las peticiones realizadas if (request.getParameter("RegistrarSatisfaccion") != null) { //incializamos las varaibles para codigo de evento y usuario CodigoEvento = request.getParameter("CodigoEvento"); CodigoUsuario = (String) session.getAttribute("Codigo"); //evaluamos el contendio de rating if ((request.getParameter("Rating") != null && !request.getParameter("Rating").equals("0")) && (request.getParameter("comentario") != null && !request.getParameter("comentario").equals(""))) { //gudardamos el contenido de rating y comentario Rating = request.getParameter("Rating"); Comentario = request.getParameter("comentario"); //realizamos los metodos necesarios para registar la calificacion if (sat.setRegistrarCalificacionYComentarioSatisfaccion(CodigoUsuario, CodigoEvento, Rating, Comentario)) { //guardamos el mensaje correspondiente session.setAttribute("Mensaje", "La crtica ha sido registrada correctamente."); session.setAttribute("TipoMensaje", "Dio"); } else { //guardamos el mensaje correspondiente session.setAttribute("Mensaje", sat.getMensaje()); session.setAttribute("TipoMensaje", "NODio"); } //retornamos a la vista response.sendRedirect("View/DetalleEvento.jsp?CodigoEvento=" + CodigoEvento); } else if (request.getParameter("Rating") != null && !request.getParameter("Rating").equals("0")) { //gudardamos el contenido de rating Rating = request.getParameter("Rating"); //realizamos los metodos necesarios para registar la calificacion if (sat.setRegistrarCalificacionSatisfaccion(CodigoUsuario, CodigoEvento, Rating)) { //guardamos el mensaje correspondiente session.setAttribute("Mensaje", "La crtica ha sido registrada correctamente."); session.setAttribute("TipoMensaje", "Dio"); } else { //guardamos el mensaje correspondiente session.setAttribute("Mensaje", sat.getMensaje()); session.setAttribute("TipoMensaje", "NODio"); } //retornamos a la vista response.sendRedirect("View/DetalleEvento.jsp?CodigoEvento=" + CodigoEvento); } else if (request.getParameter("comentario") != null && !request.getParameter("comentario").equals("")) { Comentario = request.getParameter("comentario"); //realizamos los metodos necesarios para registar la calificacion if (sat.setRegistrarComentarioSatisfaccion(CodigoUsuario, CodigoEvento, Comentario)) { //guardamos el mensaje correspondiente session.setAttribute("Mensaje", "La crtica ha sido registrada correctamente."); session.setAttribute("TipoMensaje", "Dio"); } else { //guardamos el mensaje correspondiente session.setAttribute("Mensaje", sat.getMensaje()); session.setAttribute("TipoMensaje", "NODio"); } //retornamos a la vista response.sendRedirect("View/DetalleEvento.jsp?CodigoEvento=" + CodigoEvento); } else { //guardamos el mensaje correspondiente session.setAttribute("Mensaje", "Debe seleccionar una puntuacin o escribir un comentario."); session.setAttribute("TipoMensaje", "NODio"); response.sendRedirect("View/DetalleEvento.jsp?CodigoEvento=" + CodigoEvento); } } else if (request.getParameter("accion").equals("comentarios_aleatorios")) { String Datos[][] = sat.BuscarComentariosAleatorios(); JSONObject obj = new JSONObject(); int i = 0; for (String row[] : Datos) { JSONObject ob = new JSONObject(); ob.put("usuario", row[0]); ob.put("evento", row[1]); ob.put("comentario", row[2]); obj.put(i, ob); i++; } /*Se imprime el resultado*/ PrintWriter out = response.getWriter(); out.print(obj); out.close(); } else if (request.getParameter("accion").equals("calificacion_evento")) { CodigoEvento = request.getParameter("id_evento"); int[] Datos = sat.getCalificacionEvento(CodigoEvento); JSONObject obj = new JSONObject(); JSONObject ob = new JSONObject(); ob.put("uno", Datos[0]); ob.put("dos", Datos[1]); ob.put("tres", Datos[2]); ob.put("cuatro", Datos[3]); ob.put("cinco", Datos[4]); obj.put(1, ob); PrintWriter out = response.getWriter(); out.print(obj); out.close(); } else if (request.getParameter("accion").equals("registrar_calificacion_evento_android")) { String codigoevento = request.getParameter("codigoevento"); String codigousuario = request.getParameter("codigousuario"); String comentario = request.getParameter("comentario"); String calificacion = request.getParameter("calificacion"); String fecha = request.getParameter("fecha"); sat.registrarSatisfaccionAndroid(codigoevento, codigousuario, fecha, comentario, calificacion); String dato = sat.getMensaje(); PrintWriter out = response.getWriter(); out.print(dato); out.close(); } else if (request.getParameter("accion").equals("consulta_calificar_evento_android")) { String codigoevento = request.getParameter("codigoevento"); String codigousuario = request.getParameter("codigousuario"); PrintWriter out = response.getWriter(); String[] Datos = sat.consultacalificarevento(codigoevento, codigousuario); if (Datos == null) { out.print("Comente"); } else { JSONObject ob = new JSONObject(); ob.put("Comentario", Datos[0]); ob.put("Calificacion", Datos[1]); out.print(ob); } out.close(); } else if (request.getParameter("accion").equals("consultar_comentarios_evento_android")) { String codigoevento = request.getParameter("codigoevento"); JSONObject obj = new JSONObject(); JSONObject ob = new JSONObject(); JSONArray list = new JSONArray(); PrintWriter out = response.getWriter(); String[][] Datos = sat.consultacomentarioseventoAndroid(codigoevento); for (String[] row : Datos) { ob.put("Nombre", row[0]); ob.put("Comentario", row[1]); ob.put("Fecha", row[2]); list.add(ob); } obj.put("comentarios", list); out.print(obj); out.close(); } else { /*Se redirecciona si no se realizo ninguna peticion*/ response.sendRedirect("View/ConsultaEvento.jsp"); } }
From source file:com.conwet.silbops.model.Subscription.java
@Override @SuppressWarnings("unchecked") public JSONObject toJSON() { JSONObject json = new JSONObject(); json.put("id", id); json.put("contextFunction", contextFunction.toJSON()); JSONObject jsonConstr = new JSONObject(); for (Entry<Attribute, Set<Constraint>> entry : constraints.entrySet()) { JSONArray jsonAttrConstraints = new JSONArray(); for (Constraint constr : entry.getValue()) { jsonAttrConstraints.add(constr.toJSON()); }/*ww w . j av a2s . c o m*/ jsonConstr.put(entry.getKey().toJSON(), jsonAttrConstraints); } json.put("constraints", jsonConstr); return json; }
From source file:modelo.ProcesoVertimientosManagers.ProcesoVertimientos.java
public JSONArray insertar(Double contrato, String nit, String fechaCreacion, String ciclo, String sector, String pozo, String consumo, String direccion, String usuario_creacion) throws Exception { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); Integer respError;/*from www . ja v a 2s . co m*/ Integer codigoProceso; InsertarProcesoVertimientos insert = new InsertarProcesoVertimientos(contrato, nit, fechaCreacion, ciclo, pozo, consumo, direccion, sector, usuario_creacion); insert.ejecutar(); respError = insert.getResultado(); codigoProceso = insert.getCodigoProceso(); jsonObject.put("error", respError); jsonObject.put("codigoProceso", codigoProceso); jsonArray.add(jsonObject); return jsonArray; }
From source file:au.edu.ausstage.networks.LookupManager.java
/** * A method to lookup the export options * * @return a JSON encoded object listing the options *///from www . jav a 2s .c om @SuppressWarnings("unchecked") public String getExportOptions() { // define helper variables JSONObject object = new JSONObject(); JSONArray list = new JSONArray(); for (int i = 0; i < ExportServlet.EXPORT_TYPES_UI.length; i++) { list.add(ExportServlet.EXPORT_TYPES_UI[i]); } object.put("tasks", list); list = new JSONArray(); for (int i = 0; i < ExportServlet.FORMAT_TYPES.length; i++) { list.add(ExportServlet.FORMAT_TYPES[i]); } object.put("formats", list); list = new JSONArray(); String[] radius = new String[ExportServlet.MAX_DEGREES]; for (int i = 0; i < ExportServlet.MAX_DEGREES; i++) { list.add(Integer.toString(i + 1)); } object.put("radius", list); return object.toString(); }
From source file:com.piusvelte.hydra.UnidataConnection.java
@SuppressWarnings("unchecked") @Override//from w w w .ja v a 2 s .com public JSONObject subroutine(String object, String[] arguments) { JSONObject response = new JSONObject(); try { UniSubroutine subr = mSession.subroutine(object, arguments.length); for (int i = 0, l = arguments.length; i < l; i++) subr.setArg(i, arguments[i]); subr.call(); JSONArray rows = new JSONArray(); int maxSize = 1; ArrayList<String[]> colArr = new ArrayList<String[]>(); for (int i = 0, l = arguments.length; i < l; i++) { String[] mvArr = subr.getArg(i).toString().split(UniTokens.AT_VM, -1); if (mvArr.length > maxSize) maxSize = mvArr.length; colArr.add(mvArr); } for (int row = 0; row < maxSize; row++) { JSONArray rowData = new JSONArray(); for (int col = 0; col < arguments.length; col++) { String[] mvArr = colArr.get(col); if (row < mvArr.length) rowData.add(mvArr[row]); else rowData.add(""); } rows.add(rowData); } response.put("result", rows); } catch (UniSessionException e) { e.printStackTrace(); } catch (UniSubroutineException e) { e.printStackTrace(); } if (!response.containsKey("result")) { JSONArray rows = new JSONArray(); JSONArray rowData = new JSONArray(); rows.add(rowData); response.put("result", rows); } return response; }
From source file:com.flaptor.indextank.api.resources.Search.java
@SuppressWarnings("unchecked") private void addResult(JSONArray ja, SearchResult result) { JSONObject document = new JSONObject(); document.putAll(result.getFields()); document.put("docid", result.getDocId()); document.put("query_relevance_score", result.getScore()); for (Entry<Integer, Double> entry : result.getVariables().entrySet()) { document.put("variable_" + entry.getKey(), entry.getValue()); }/*from w w w. j ava2 s . c o m*/ for (Entry<String, String> entry : result.getCategories().entrySet()) { document.put("category_" + entry.getKey(), entry.getValue()); } ja.add(document); }
From source file:mml.handler.get.MMLGetAnnotationsHandler.java
/** * Handle a request for options/* ww w.ja v a 2 s.c om*/ * @param request the http request * @param response the http response * @param urn the urn (ignored) * @throws MMLException */ @Override public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws MMLException { try { JSONArray annotations = new JSONArray(); docid = request.getParameter(Params.DOCID); version1 = request.getParameter(Params.VERSION1); if (docid != null && version1 != null) { Connection conn = Connector.getConnection(); String[] docids = conn.listDocuments(Database.SCRATCH, docid + ".*", JSONKeys.DOCID); if (docids != null && docids.length > 0) { for (int i = 0; i < docids.length; i++) { JSONObject jObj = fetchAnnotation(conn, Database.SCRATCH, docids[i]); if (jObj != null) annotations.add(jObj); } } if (annotations.isEmpty()) // nothing in SCRATCH space { docids = conn.listDocuments(Database.ANNOTATIONS, docid + ".*", JSONKeys.DOCID); if (docids != null && docids.length > 0) { for (int i = 0; i < docids.length; i++) { JSONObject jObj = fetchAnnotation(conn, Database.ANNOTATIONS, docids[i]); if (jObj != null) annotations.add(jObj); } } } } String res = annotations.toJSONString(); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); response.getWriter().write(res); } catch (Exception e) { throw new MMLException(e); } }
From source file:gwap.rest.User.java
@GET @Path("/highscore") public Response getHighscore() { Query query = entityManager.createNamedQuery("highscore.all"); query.setParameter("gametype", getGameType()); query.setMaxResults(10);// w ww . j a v a 2 s . c o m List<Highscore> highscoreList = query.getResultList(); JSONArray highscoreListJSON = new JSONArray(); for (int i = 0; i < highscoreList.size(); i++) { Highscore highscore = highscoreList.get(i); JSONObject highscoreJSON = new JSONObject(); highscoreJSON.put("rank", i + 1); Person person = entityManager.find(Person.class, highscore.getPersonId()); highscoreJSON.put("name", person.getExternalUsername()); highscoreJSON.put("score", highscore.getScore()); highscoreListJSON.add(highscoreJSON); } return Response.ok(highscoreListJSON.toString(), MediaType.APPLICATION_JSON).build(); }
From source file:com.rackspacecloud.blueflood.outputs.serializers.BatchedMetricsJSONOutputSerializer.java
@Override public JSONObject transformRollupData(Map<Locator, MetricData> metricData, Set<MetricStat> filterStats) throws SerializationException { final JSONObject globalJSON = new JSONObject(); final JSONArray metricsArray = new JSONArray(); for (Map.Entry<Locator, MetricData> one : metricData.entrySet()) { final JSONObject singleMetricJSON = new JSONObject(); singleMetricJSON.put("metric", one.getKey().getMetricName()); singleMetricJSON.put("unit", one.getValue().getUnit() == null ? Util.UNKNOWN : one.getValue().getUnit()); singleMetricJSON.put("type", one.getValue().getType()); Set<MetricStat> oneFilterStats = fixFilterStats(one.getValue(), filterStats); JSONArray values = transformDataToJSONArray(one.getValue(), oneFilterStats); singleMetricJSON.put("data", values); metricsArray.add(singleMetricJSON); }//w ww. ja v a 2 s . c om globalJSON.put("metrics", metricsArray); return globalJSON; }
From source file:eclserver.threads.EmergencyCallPush.java
private String getJsonString(String machineName, String confirmURL) { JSONObject m1 = new JSONObject(); m1.clear();/* w w w . j av a2 s. c o m*/ JSONArray list1 = new JSONArray(); try { m1.put("milliseconds", ecPanel.getCallDateTime()); m1.put("phonenumber", ecPanel.getCallBridge()); m1.put("details", ecPanel.getCallDescription()); m1.put("accepturl", confirmURL + "?MyMessage=EmergencyCallAccepted"); m1.put("declineurl", confirmURL + "?MyMessage=EmergencyCallDeclined"); list1.add(m1); } catch (Exception ex) { System.out.println("EXCEPTION GETTING JSON STRING: " + ex.getMessage()); } String jsonString = "{\"Source\":[{\"machinename\":\"" + machineName + "\"}],"; jsonString += "\"Confirmation\":[{\"url\":\"" + confirmURL + "\"}],"; jsonString += "\"EmergencyCall\":" + list1.toString() + "}"; // System.out.println("Call JSON STRING: " + jsonString); return jsonString; }