List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:edu.ucsd.library.xdre.web.ExcelImportController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String ds = request.getParameter("ts"); String collectionId = request.getParameter("category"); String unit = request.getParameter("unit"); String message = request.getParameter("message"); String fileStore = request.getParameter("fs"); String licenseBeginDate = request.getParameter("licenseBeginDate"); String licenseEndDate = request.getParameter("licenseEndDate"); HttpSession session = request.getSession(); DAMSClient damsClient = null;//from w w w . j a va 2 s . co m Map dataMap = new HashMap(); try { // initiate column name and control values for validation String columns = request.getServletContext().getRealPath("files/valid_columns.xlsx"); String cvs = request.getServletContext().getRealPath("files/valid_cv_values.xlsx"); try { ExcelSource.initControlValues(new File(columns), new File(cvs)); } catch (Exception e) { e.printStackTrace(); } if (ds == null) ds = Constants.DEFAULT_TRIPLESTORE; damsClient = new DAMSClient(Constants.DAMS_STORAGE_URL); damsClient.setTripleStore(ds); Map<String, String> collectionMap = damsClient.listCollections(); Map<String, String> unitsMap = damsClient.listUnits(); List<String> tsSrcs = damsClient.listTripleStores(); List<String> fsSrcs = damsClient.listFileStores(); String fsDefault = damsClient.defaultFilestore(); if (fileStore == null || fileStore.length() == 0) fileStore = fsDefault; message = (!StringUtils.isBlank(message) || StringUtils.isBlank(collectionId)) ? message : (String) session.getAttribute("message"); session.removeAttribute("message"); JSONArray accessValues = new JSONArray(); accessValues.addAll(Arrays.asList(RecordUtil.ACCESS_VALUES)); Map<String, String> countryCodes = MarcModsImportController.getCountryCodes(request); dataMap.put("categories", collectionMap); dataMap.put("category", collectionId); dataMap.put("units", unitsMap); dataMap.put("unit", unit); dataMap.put("message", message); dataMap.put("triplestore", ds); dataMap.put("triplestores", tsSrcs); dataMap.put("filestores", fsSrcs); dataMap.put("filestore", fileStore); dataMap.put("filestoreDefault", fsDefault); dataMap.put("copyrightStatus", RecordUtil.COPYRIGHT_VALUES); dataMap.put("program", RecordUtil.PROGRAM_VALUES); dataMap.put("accessOverride", accessValues); dataMap.put("licenseBeginDate", licenseBeginDate); dataMap.put("licenseEndDate", licenseEndDate); dataMap.put("countryCodes", countryCodes); } catch (Exception e) { e.printStackTrace(); message += e.getMessage(); } finally { if (damsClient != null) damsClient.close(); } return new ModelAndView("excelImport", "model", dataMap); }
From source file:com.piusvelte.hydra.MSSQLConnection.java
private JSONArray getResult(ResultSet rs) throws SQLException { JSONArray rows = new JSONArray(); ResultSetMetaData rsmd = rs.getMetaData(); String[] columnsArr = new String[rsmd.getColumnCount()]; for (int c = 0, l = columnsArr.length; c < l; c++) columnsArr[c] = rsmd.getColumnName(c); while (rs.next()) { JSONArray rowData = new JSONArray(); for (String column : columnsArr) rowData.add((String) rs.getObject(column)); rows.add(rowData);/*www . j av a 2s .co m*/ } return rows; }
From source file:com.aerothai.database.jobevaluate.JobevaluateService.java
public JSONObject GetJobevaluateAt(int id) throws Exception { Connection dbConn = null;/*from w ww . j av a 2s . c om*/ JSONObject obj = new JSONObject(); JSONArray objList = new JSONArray(); int no = 1; //obj.put("draw", 2); obj.put("tag", "listat"); obj.put("msg", "error"); obj.put("status", false); try { dbConn = DBConnection.createConnection(); Statement stmt = dbConn.createStatement(); String query = "SELECT * FROM job_evaluate where idjob_evaluate = " + id; System.out.println(query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { JSONObject jsonData = new JSONObject(); jsonData.put("id", rs.getInt("idjob_evaluate")); jsonData.put("idjob", rs.getString("idjob")); jsonData.put("staff", rs.getString("staff")); jsonData.put("service", rs.getString("service")); jsonData.put("comment", rs.getString("comment")); jsonData.put("no", no); objList.add(jsonData); no++; } obj.put("msg", "done"); obj.put("status", true); obj.put("data", objList); } catch (SQLException sqle) { throw sqle; } catch (Exception e) { // TODO Auto-generated catch block if (dbConn != null) { dbConn.close(); } throw e; } finally { if (dbConn != null) { dbConn.close(); } } return obj; }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.json.VehicleDetailsQuery.java
@SuppressWarnings("unchecked") @Override/*from w ww . j av a2 s. c om*/ public String execute(IServletConfig config, String[] parameters) throws IOException { String vehicleId = parameters[3]; if (vehicleId == null || "".equals(vehicleId)) { return JSONValue.toJSONString("Invalid query!"); } IVirtualVehicle vehicle = vehicleMap.get(vehicleId); if (vehicle == null) { return JSONValue.toJSONString("Vehicle not found (anymore)!"); } JSONObject props = new JSONObject(); for (Entry<Object, Object> e : vehicle.getProperties().entrySet()) { props.put((String) e.getKey(), e.getValue()); } props.put(PROP_VEHICLE_LOCAL_NAME, vehicle.getWorkDir().getName()); if (vehicle.isProgramCorrupted()) { props.put(PROP_VEHICLE_STATE, "corrupt"); } else if (vehicle.isCompleted()) { props.put(PROP_VEHICLE_STATE, "completed"); } else if (vehicle.isActive()) { props.put(PROP_VEHICLE_STATE, "active"); } else { props.put(PROP_VEHICLE_STATE, "suspended"); } JSONArray tasks = new JSONArray(); for (ITask cmd : vehicle.getTaskList()) { tasks.add(cmd); } props.put(PROP_VEHICLE_TASKS, tasks); return JSONValue.toJSONString(props); }
From source file:com.Assignment4.Prod.java
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)//from www . j a v a 2s. c o m public String getproduct(@PathParam("id") int id) throws SQLException { if (connect == null) { return "not connected"; } else { String query = "Select * from product where product_id = ?"; PreparedStatement prepstmt = connect.prepareStatement(query); prepstmt.setInt(1, id); ResultSet rs = prepstmt.executeQuery(); String result = ""; JSONArray productArr = new JSONArray(); while (rs.next()) { Map pMap = new LinkedHashMap(); pMap.put("productID", rs.getInt("product_id")); pMap.put("name", rs.getString("name")); pMap.put("description", rs.getString("description")); pMap.put("quantity", rs.getInt("quantity")); productArr.add(pMap); } result = productArr.toString(); return result; } }
From source file:cpd4414.assign2.OrderQueue.java
String generateReport() { String output = ""; if (!(orderQueue.isEmpty() && ListOfOrder.isEmpty())) { JSONObject obj = new JSONObject(); JSONArray orders = new JSONArray(); for (Order o : ListOfOrder) { orders.add(o.tojsonconvert()); }//from w w w . j av a 2 s. c o m for (Order o : orderQueue) { orders.add(o.tojsonconvert()); } obj.put("orders", orders); output = obj.toJSONString(); } return output; }
From source file:com.aerothai.database.sparepart.SparepartService.java
public JSONObject GetSparepartAt(int id) throws Exception { Connection dbConn = null;//from w w w. ja va 2s . c o m JSONObject obj = new JSONObject(); JSONArray objList = new JSONArray(); int no = 1; //obj.put("draw", 2); obj.put("tag", "listat"); obj.put("msg", "error"); obj.put("status", false); try { dbConn = DBConnection.createConnection(); Statement stmt = dbConn.createStatement(); String query = "SELECT * FROM spare_part where idspare = " + id; System.out.println(query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { JSONObject jsonData = new JSONObject(); jsonData.put("id", rs.getInt("idspare")); jsonData.put("details", rs.getString("details")); jsonData.put("amount", rs.getString("amount")); jsonData.put("price", rs.getString("price")); jsonData.put("date", rs.getString("date")); jsonData.put("idunit", rs.getString("idunit")); jsonData.put("no", no); objList.add(jsonData); no++; } obj.put("msg", "done"); obj.put("status", true); obj.put("data", objList); } catch (SQLException sqle) { throw sqle; } catch (Exception e) { // TODO Auto-generated catch block if (dbConn != null) { dbConn.close(); } throw e; } finally { if (dbConn != null) { dbConn.close(); } } return obj; }
From source file:forumbox.PostingnewpostServlet.java
public void filewrite(String url, String username, String title, String description, HttpServletResponse response, String id) throws IOException { count++;/*from w w w .ja v a 2 s .c o m*/ /* BufferedWriter out ; out = new BufferedWriter(new FileWriter(url,true)); out.write(count+"/"+array[0]+"/"+array[1]+"/"+array[2]+";"); out.close(); }catch (Exception e) { System.out.println("Error: " + e.getMessage()); } */ JSONObject post = new JSONObject(); JSONArray comments = new JSONArray(); JSONArray toapprove = new JSONArray(); JSONParser parser = new JSONParser(); JSONObject list = null; post.put("title", title); post.put("description", description); post.put("id", id); post.put("username", username); // post.put("comments",comments); // post.put("toapprove",toapprove); try { Object obj = parser.parse(new FileReader(url + "list.json")); list = (JSONObject) obj; JSONArray msg = (JSONArray) list.get("list"); msg.add(id); list.remove("list"); list.put("list", msg); } catch (Exception e) { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("Adding new ID is unsuccessful"); out.println(e); out.println("......................"); } try { File file = new File(url + id + ".json"); file.createNewFile(); BufferedWriter out; out = new BufferedWriter(new FileWriter(file)); out.write(post.toJSONString()); out.close(); File fileList = new File(url + "list.json"); // fileList.createNewFile(); // BufferedWriter outin ; // outin = new BufferedWriter(new FileWriter(fileList)); // outin.write(post.toJSONString()); FileWriter listwrite = new FileWriter(fileList); listwrite.write(list.toJSONString()); listwrite.flush(); listwrite.close(); //outin.close(); } catch (IOException e) { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("adding new post is unsuccessful"); out.println(e); out.println("......................"); } }
From source file:com.saludtec.web.AnamnesisWeb.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String servicio = request.getRequestURI().replace("/HCEMed/Anamnesis/", ""); switch (servicio) { case "guardar": guardarAnamnesis(request).writeJSONString(out); break; case "traerUltimo": traerUltimoAnamnesis(request).writeJSONString(out); break; case "traerFecha": traerAnamnesisFecha(request).writeJSONString(out); break; default://from ww w . jav a 2 s . c om obj = new JSONObject(); objArray = new JSONArray(); obj.put("error", "404 - El servicio " + servicio + " no existe"); objArray.add(obj); objArray.writeJSONString(out); break; } } }
From source file:com.Assignment4.Assign.java
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)//from ww w . j a va 2 s . c o m public String getproduct(@PathParam("id") int id) throws SQLException { if (connected == null) { return "not connected"; } else { String query = "Select * from product where product_id = ?"; PreparedStatement pstmt = connected.prepareStatement(query); pstmt.setInt(1, id); ResultSet rs = pstmt.executeQuery(); String res = ""; JSONArray productArr = new JSONArray(); while (rs.next()) { Map proMap = new LinkedHashMap(); proMap.put("productID", rs.getInt("product_id")); proMap.put("name", rs.getString("name")); proMap.put("description", rs.getString("description")); proMap.put("quantity", rs.getInt("quantity")); productArr.add(proMap); } res = productArr.toString(); return res; } }