Example usage for org.json.simple JSONArray JSONArray

List of usage examples for org.json.simple JSONArray JSONArray

Introduction

In this page you can find the example usage for org.json.simple JSONArray JSONArray.

Prototype

JSONArray

Source Link

Usage

From source file:com.imagelake.android.downloadhistory.Servlet_downloadhistory.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    PrintWriter out = response.getWriter();

    String type_id = request.getParameter("type");
    JSONArray box_list = new JSONArray();
    if (type_id != null) {
        type = Integer.parseInt(type_id);
        String userId = request.getParameter("user_id");

        if (userId != null) {

            user_id = Integer.parseInt(userId);
            c = cdi.getCart(user_id);//  w w  w.j  a  va 2  s. c om

            if (c != null) {

                if (type == LOAD_DOWNLOAD_HISTORY) {

                    System.out.println("cart :" + c.getCart_id());
                    List<CartHasImages> list = new CartDAOImp().listUserCartHasImages(c.getCart_id(), 1);

                    if (!list.isEmpty()) {

                        for (CartHasImages ca : list) {

                            im = idi.getImageDetail(ca.getImg_id());
                            // ims=idi.getSubImage(ca.getSubimg_id());

                            if (im.getImage_state_image_state_id() == 1
                                    && im.getImage_state_image_state_id() != 3) {

                                JSONObject jo = new JSONObject();
                                jo.put("cart_id", ca.getCart_has_images_id());
                                jo.put("title", im.getTitle());
                                jo.put("sub_id", ca.getSubimg_id());
                                jo.put("date", ca.getDate());
                                jo.put("credits", ca.getCredits());
                                jo.put("state", im.getImage_state_image_state_id());
                                box_list.add(jo);

                            } else if (im.getImage_state_image_state_id() == 5
                                    && im.getImage_state_image_state_id() != 3) {

                                JSONObject jo = new JSONObject();
                                jo.put("cart_id", ca.getCart_has_images_id());
                                jo.put("title", im.getTitle());
                                jo.put("sub_id", ca.getSubimg_id());
                                jo.put("date", ca.getDate());
                                jo.put("credits", ca.getCredits());
                                jo.put("state", im.getImage_state_image_state_id());
                                box_list.add(jo);

                            }

                        }
                        System.out.println(box_list.toJSONString());
                        out.write("json=" + box_list.toJSONString());
                    } else {
                        out.write("msg=No item found.");
                    }

                } else if (type == LOAD_DATE) {

                    System.out.println("cart :" + c.getCart_id());

                    List<CartHasImages> list = new CartDAOImp().sortByDate(1, "DESC", c.getCart_id(), "date");

                    if (!list.isEmpty()) {

                        for (CartHasImages ca : list) {

                            im = idi.getImageDetail(ca.getImg_id());
                            // ims=idi.getSubImage(ca.getSubimg_id());

                            if (im.getImage_state_image_state_id() == 1
                                    && im.getImage_state_image_state_id() != 3) {

                                JSONObject jo = new JSONObject();
                                jo.put("cart_id", ca.getCart_has_images_id());
                                jo.put("title", im.getTitle());
                                jo.put("sub_id", ca.getSubimg_id());
                                jo.put("date", ca.getDate());
                                jo.put("credits", ca.getCredits());
                                jo.put("state", im.getImage_state_image_state_id());
                                box_list.add(jo);

                            } else if (im.getImage_state_image_state_id() == 5
                                    && im.getImage_state_image_state_id() != 3) {

                                JSONObject jo = new JSONObject();
                                jo.put("cart_id", ca.getCart_has_images_id());
                                jo.put("title", im.getTitle());
                                jo.put("sub_id", ca.getSubimg_id());
                                jo.put("date", ca.getDate());
                                jo.put("credits", ca.getCredits());
                                jo.put("state", im.getImage_state_image_state_id());
                                box_list.add(jo);

                            }

                        }
                        System.out.println(box_list.toJSONString());
                        out.write("json=" + box_list.toJSONString());
                    } else {
                        out.write("msg=No item found.");
                    }

                } else if (type == LOAD_SIZE) {

                    System.out.println("cart :" + c.getCart_id());

                    List<CartHasImages> list = new CartDAOImp().sortByDate(1, "ASC", c.getCart_id(), "credits");

                    if (!list.isEmpty()) {

                        for (CartHasImages ca : list) {

                            im = idi.getImageDetail(ca.getImg_id());
                            // ims=idi.getSubImage(ca.getSubimg_id());

                            if (im.getImage_state_image_state_id() == 1
                                    && im.getImage_state_image_state_id() != 3) {

                                JSONObject jo = new JSONObject();
                                jo.put("cart_id", ca.getCart_has_images_id());
                                jo.put("title", im.getTitle());
                                jo.put("sub_id", ca.getSubimg_id());
                                jo.put("date", ca.getDate());
                                jo.put("credits", ca.getCredits());
                                jo.put("state", im.getImage_state_image_state_id());
                                box_list.add(jo);

                            } else if (im.getImage_state_image_state_id() == 5
                                    && im.getImage_state_image_state_id() != 3) {

                                JSONObject jo = new JSONObject();
                                jo.put("cart_id", ca.getCart_has_images_id());
                                jo.put("title", im.getTitle());
                                jo.put("sub_id", ca.getSubimg_id());
                                jo.put("date", ca.getDate());
                                jo.put("credits", ca.getCredits());
                                jo.put("state", im.getImage_state_image_state_id());
                                box_list.add(jo);

                            }

                        }
                        System.out.println(box_list.toJSONString());
                        out.write("json=" + box_list.toJSONString());
                    } else {
                        out.write("msg=No item found.");
                    }

                }

            }
        } else {
            out.write("msg=Internal server error,please try agin later.");
        }
    } else {
        out.write("msg=Internal server error,please try agin later.");
    }
}

From source file:com.amindorost.searchalgorithms.MainSearch.java

public MainSearch(Topology topology, Node src, Node dst, int heuristicsType) {
    this.topology = null;
    this.topology = topology;
    this.src = src;
    this.dst = dst;
    this.heuristicsType = heuristicsType;
    this.nodesQueue = new ArrayList<Node>();
    if (heuristicsType == 0)
        this.src.setNodeValue(1);
    else/*www.j  a v a 2 s  .  c om*/
        this.src.setNodeValue(heuristics(this.src));
    this.nodesQueue.add(this.src);
    this.processedNodes = new ArrayList<Node>();
    this.resultJSON = new JSONObject();
    this.heuristicsType = heuristicsType;
    this.pathFound = new ArrayList<>();
    this.iterationJSONArray = new JSONArray();
    this.pathJSON = new JSONArray();
}

From source file:com.imagelake.android.imagemanagement.Servlet_ImageManagement.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    try {//from w  w  w  . j a  va2s.  c  om
        String type = request.getParameter("type");
        System.out.println(type);

        if (type != null && !type.equals("")) {

            if (type.equals("sort")) {

                ja = new JSONArray();

                String date = request.getParameter("date");
                String date2 = request.getParameter("date2");
                String cat = request.getParameter("cat");
                String usnm = request.getParameter("usnm");
                String key = request.getParameter("key");

                System.out.println("date: " + date);
                System.out.println("date2: " + date2);
                System.out.println("cat: " + cat);
                System.out.println("usnm: " + usnm);
                System.out.println("key: " + key);

                String dt = "dt" + date + "dt";
                String ct = "ct" + cat + "ct";
                String un = "un" + usnm + "un";
                String ky = "ky" + key + "ky";

                System.out.println("date: " + dt);
                //System.out.println("date2: "+ct);
                System.out.println("cat: " + ct);
                System.out.println("usnm: " + un);
                System.out.println("key: " + ky);

                String sql = "SELECT * FROM images ";

                sql += "WHERE ";

                if (!date.equals("") || !dt.equals("dtdt") && !dt.equals("dtnulldt") && !date2.equals("")) {
                    try {
                        String[] dtt = date.split("-");
                        String orDate = dtt[2] + "-" + dtt[1] + "-" + dtt[0];
                        String[] dtt2 = date2.split("-");
                        String orDate2 = dtt2[2] + "-" + dtt2[1] + "-" + dtt2[0];
                        System.out.println("date=" + orDate);
                        sql += "date BETWEEN '" + orDate + "' AND '" + orDate2 + "' AND ";

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
                if (!cat.equals("") || !ct.equals("ctct") && !ct.equals("ctnullct")) {
                    if (!ct.equals("ct0ct")) {
                        sql += "categories_category_id='" + cat + "' AND ";
                    }

                }
                if (!usnm.equals("") || !un.equals("unun") && !un.equals("unnullun")) {
                    if (!un.equals("un0un")) {
                        sql += "user_user_id='" + usnm + "' AND ";
                    }

                }
                if (!key.equals("") || !ky.equals("kyky") && !ky.equals("kynullky")) {
                    sql += "images_id IN(SELECT images_images_id FROM key_words WHERE key_word LIKE '%" + key
                            + "%') AND ";
                }

                sql += "image_state_image_state_id='1' OR ";

                if (!date.equals("") || !dt.equals("dtdt") && !dt.equals("dtnulldt") && !date2.equals("")) {
                    try {
                        String[] dtt = date.split("-");
                        String orDate = dtt[2] + "-" + dtt[1] + "-" + dtt[0];
                        String[] dtt2 = date2.split("-");
                        String orDate2 = dtt2[2] + "-" + dtt2[1] + "-" + dtt2[0];
                        System.out.println("date=" + orDate);
                        sql += "date BETWEEN '" + orDate + "' AND '" + orDate2 + "' AND ";

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
                if (!cat.equals("") || !ct.equals("ctct") && !ct.equals("ctnullct")) {
                    if (!ct.equals("ct0ct")) {
                        sql += "categories_category_id='" + cat + "' AND ";
                    }

                }
                if (!usnm.equals("") || !un.equals("unun") && !un.equals("unnullun")) {
                    if (!un.equals("un0un")) {
                        sql += "user_user_id='" + usnm + "' AND ";
                    }

                }
                if (!key.equals("") || !ky.equals("kyky") && !ky.equals("kynullky")) {
                    sql += "images_id IN(SELECT images_images_id FROM key_words WHERE key_word LIKE '%" + key
                            + "%') AND ";
                }

                sql += "image_state_image_state_id='5' ORDER BY images_id DESC";

                System.out.println(sql);

                try {

                    PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
                    ResultSet rs = ps.executeQuery();

                    while (rs.next()) {
                        System.out.println("" + rs.getInt(1));
                        if (rs.getInt(20) != 3) {

                            if (rs.getInt(20) == 1 || rs.getInt(20) == 5) {
                                JSONObject jo = new JSONObject();
                                jo.put("id", rs.getInt(1));
                                jo.put("url", rs.getString(15));
                                jo.put("title", rs.getString(2));
                                jo.put("date", rs.getString(16));
                                catt = cdi.getCategory(rs.getInt(19));
                                jo.put("cat", catt.getCategory());
                                us = udi.getUser(rs.getInt(18));
                                jo.put("sel", us.getUser_name());
                                jo.put("state", rs.getInt(20));
                                ja.add(jo);
                            }
                        }
                    }

                    System.out.println("-------" + ja.toJSONString());
                    out.write("json=" + ja.toJSONString());

                } catch (Exception e) {
                    e.printStackTrace();
                    out.write("msg=Internal server error,Please try again later.");
                }

            } else {
                out.write("msg=Internal server error,Please try again later.");
            }

        } else {
            out.write("msg=Internal server error,Please try again later.");
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.write("msg=Internal server error,Please try again later.");
    }

}

From source file:control.ParametrizacionServlets.EliminarDocumentacionRequerida.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*  w w w. ja v  a2 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 {
    try {

        //Obtenemos los datos enviados.

        Integer codigo = Integer.parseInt(request.getParameter("codigo"));

        JSONArray respError = new JSONArray(); // uno significa que no hay error

        //Creamos el manager para registrar la informacion
        DocumentacionRequerida manager = new DocumentacionRequerida();

        respError = manager.eliminar(codigo);

        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");

        for (Object jsonObject : respError) {

            response.getWriter().write(respError.toString());

        }

    } catch (Exception ex) {
        //Logger.getLogger(InsertarDocumentacionRequerida.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.imagelake.android.purchasemanagement.Servlet_purchaseVisePackages.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    try {/*from   w w w . ja va  2 s. c  om*/

        String type = request.getParameter("type");

        String sql = "SELECT SQL_CALC_FOUND_ROWS user_has_packages.purchase_date,user_has_packages.expire_date,user_has_packages.user_id,user_has_packages.state,admin_package_income.total"
                + " FROM user_has_packages,admin_package_income WHERE user_has_packages.uhp_id=admin_package_income.uhp_id ";
        if (type != null && !type.equals("")) {
            if (type.equals("all")) {

                sql += "ORDER BY user_has_packages.purchase_date DESC ";
                ja = new JSONArray();
                System.out.println("sql=" + sql);
                PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
                ResultSet rs = ps.executeQuery();
                if (rs.next()) {
                    rs.close();
                    rs = ps.executeQuery();
                    while (rs.next()) {
                        JSONObject jo = new JSONObject();
                        DecimalFormat df = new DecimalFormat();
                        jo.put("pur_date", rs.getString(1));
                        jo.put("exp_date", rs.getString(2));
                        jo.put("un", udi.getUn(rs.getInt(3)));
                        if (rs.getInt(4) == 1) {
                            jo.put("state", 1);
                        } else if (rs.getInt(4) == 2) {
                            jo.put("state", 2);
                        }
                        jo.put("income", df.format(rs.getDouble(5)));
                        ja.add(jo);

                    }
                    System.out.println(ja.toJSONString());
                    out.write("json=" + ja.toJSONString());
                } else {
                    out.write("msg=No item found.");
                }

            } else if (type.equals("sort")) {
                ja = new JSONArray();
                String from = request.getParameter("date");
                String to = request.getParameter("date2");
                String cat = request.getParameter("cat");
                String buy = request.getParameter("buy");

                System.out.println("date_pur:" + from);
                System.out.println("date_exp:" + to);
                System.out.println("cat:" + cat);
                System.out.println("buy:" + buy);

                if (cat.equals("0")) {
                    cat = "";
                }

                if (from != null && !from.trim().equals("") && to != null && !to.trim().equals("")) {
                    String[] dt = from.split("-");
                    String[] dt2 = to.split("-");
                    String orDate = dt[2] + "-" + dt[1] + "-" + dt[0];
                    String orDate2 = dt2[2] + "-" + dt2[1] + "-" + dt2[0];
                    System.out.println("date=" + orDate);

                    sql += " AND user_has_packages.purchase_date BETWEEN '" + orDate + "' AND '" + orDate2
                            + "' ";

                }
                if (cat != null && !cat.trim().equals("")) {
                    sql += " AND user_has_packages.package_type='" + cat + "' ";
                }
                if (buy != null && !buy.trim().equals("")) {
                    sql += " AND user_has_packages.user_id='" + buy + "' ";
                }

                sql += "ORDER BY user_has_packages.purchase_date DESC ";

                System.out.println("sql: " + sql);

                PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
                ResultSet rs = ps.executeQuery();
                DecimalFormat df = new DecimalFormat();
                if (rs.next()) {
                    rs.close();
                    rs = ps.executeQuery();
                    while (rs.next()) {
                        JSONObject jo = new JSONObject();

                        jo.put("pur_date", rs.getString(1));
                        jo.put("exp_date", rs.getString(2));
                        jo.put("un", udi.getUn(rs.getInt(3)));
                        if (rs.getInt(4) == 1) {
                            jo.put("state", 1);
                        } else if (rs.getInt(4) == 2) {
                            jo.put("state", 2);
                        }
                        jo.put("income", df.format(rs.getDouble(5)));
                        ja.add(jo);
                    }
                    System.out.println(ja.toJSONString());
                    out.write("json=" + ja.toJSONString());
                } else {
                    out.write("msg=No item found.");
                }

            }
        } else {
            out.write("msg=Internal server error,Please try again later.");
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.write("msg=Internal server error,Please try again later.");
    }

}

From source file:control.ProcesoVertimientosServlets.RegistrarSuperviciones.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 {

    JSONArray resp = new JSONArray();

    try {
        //Obtenemos la cadena con la informacion y la convertimos en un
        //JSONArray
        String monitoreos = request.getParameter("monitoreos");
        int tecnico = Integer.parseInt(request.getParameter("tecnico"));
        int resul;
        int codProceso;
        JSONObject jsonObject = new JSONObject();
        JSONArray jsonArray = new JSONArray();

        Object obj = JSONValue.parse(monitoreos);
        JSONArray monitoreosArray = new JSONArray();
        monitoreosArray = (JSONArray) obj;

        //Recorremos el JSONArray y obtenemos la informacion.
        for (int i = 0; i < monitoreosArray.size(); i++) {
            codProceso = Integer.parseInt(monitoreosArray.get(i).toString());

            ProgramarMonitoreo manager = new ProgramarMonitoreo();
            resul = manager.registrarSupervision(codProceso, tecnico);

            jsonObject.put("monitoreo", codProceso);
            jsonObject.put("resultado", resul);

            jsonArray.add(jsonObject.clone());

        }
        resp.add(jsonArray);
        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");

        for (Object jsonObjectResp : resp) {

            response.getWriter().write(jsonObjectResp.toString());

        }
    } catch (Exception ex) {

    }
}

From source file:control.ProcesoVertimientosServlets.SeleccionarArchivosInfoTec.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 {

    try {

        JSONArray jsonArray = new JSONArray();
        int codigoProceso = Integer.parseInt(request.getParameter("codigoProceso"));

        ManejoLodos manager = new ManejoLodos();
        jsonArray = manager.getArchivosLodos(codigoProceso);

        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");
        for (Object jsonObject : jsonArray) {

            response.getWriter().write(jsonObject.toString());

        }

    } catch (Exception e) {

    }
}

From source file:control.ParametrizacionServlets.EliminarLaboratorios.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from   w w  w. j  av  a2s .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 {

    try {

        int codigo = Integer.parseInt(request.getParameter("codigo"));
        JSONArray respError = new JSONArray();

        int resp = 0;
        //Obtenemos La informacion del manager
        AcreditacionParametros managerAcreditacion = new AcreditacionParametros();

        //Eliminamos lo parametros
        resp = managerAcreditacion.eliminar(codigo);

        Laboratorios manager = new Laboratorios();

        respError = manager.Eliminar(codigo);

        for (Object jsonObject : respError) {

            response.getWriter().write(respError.toString());
        }

    } catch (Exception ex) {
        // Logger.getLogger(EliminarLaboratorios.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:cc.pinel.mangue.storage.StateStorage.java

public void setChapter(String mangaId, String chapterNumber) throws IOException {
    JSONObject json = null;/*from   w w w.  j a  va  2  s  .  c o  m*/

    try {
        json = readJSON();
    } catch (Exception e) {
        // ignored
    }
    if (json == null)
        json = new JSONObject();

    JSONArray jsonMangas = (JSONArray) json.get("mangas");
    if (jsonMangas == null) {
        jsonMangas = new JSONArray();
        json.put("mangas", jsonMangas);
    }

    JSONObject jsonManga = findManga(jsonMangas, mangaId);
    if (jsonManga == null) {
        jsonManga = new JSONObject();
        jsonManga.put("id", mangaId);
        jsonMangas.add(jsonManga);
    }
    jsonManga.put("chapterNumber", chapterNumber);

    writeJSON(json);
}

From source file:kjscompiler.Settings.java

public Settings(String path) throws ParseException, FileNotFoundException, IOException {
    JSONParser parser = new JSONParser();
    File file = new File(path);
    String parent = file.exists() ? file.getParent() : null;
    File dir = new File(null == parent || parent.isEmpty() ? "." : parent);
    FileReader fr = new FileReader(file);
    char[] fileData = new char[(int) file.length()];
    fr.read(fileData);/*from   ww w .  j a  va2 s .co m*/
    String content = new String(fileData);
    JSONObject obj = (JSONObject) parser.parse(content);
    if (obj.get("basedir") instanceof JSONArray) {
        this.baseDir = (JSONArray) obj.get("basedir");
    } else {
        JSONArray arr = new JSONArray();
        arr.add(obj.get("basedir"));
        this.baseDir = arr;
    }
    this.output = (String) obj.get("output");
    this.level = (String) obj.get("level");
    this.pattern = (String) obj.get("pattern");
    this.wrapper = obj.get("wrapper") != null ? (String) obj.get("wrapper") : "";
    this.projectPath = dir.getCanonicalPath();

    dir = new File(this.projectPath, this.output);
    this.output = dir.getCanonicalPath();

    fr.close();
}