List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:hoot.services.controllers.ingest.RasterToTilesResourceTest.java
@Test @Category(UnitTest.class) public void TestIngestOSMResource() throws Exception { String processScriptName = RASTER_TO_TILES; Assert.assertNotNull(processScriptName); Assert.assertTrue(!processScriptName.isEmpty()); RasterToTilesService rts = new RasterToTilesService(); JSONObject oExpected = new JSONObject(); oExpected.put("caller", "RasterToTilesService"); oExpected.put("exec", processScriptName); JSONArray params = new JSONArray(); JSONObject param = new JSONObject(); param.put("RASTER_OUTPUT_DIR", tileServerPath); params.add(param);/*from www . ja v a 2s .c om*/ param = new JSONObject(); param.put("INPUT", "test"); params.add(param); param = new JSONObject(); param.put("ZOOM_LIST", "0-1 2-3"); params.add(param); param = new JSONObject(); param.put("RASTER_SIZE", "500"); params.add(param); param = new JSONObject(); param.put("MAP_ID", "1"); params.add(param); oExpected.put("params", params); oExpected.put("exectype", "make"); oExpected.put("erroraswarning", "true"); Method createCommandMethod = RasterToTilesService.class.getDeclaredMethod("createCommand", String.class, String.class, int.class, long.class); createCommandMethod.setAccessible(true); String actual = (String) createCommandMethod.invoke(rts, "test", "0-1 2-3", 500, 1); JSONParser parser = new JSONParser(); JSONObject actualObj = (JSONObject) parser.parse(actual); Assert.assertEquals(oExpected, actualObj); }
From source file:com.mapr.xml2json.MySaxParser.java
@Override public void endElement(String uri, String localName, String qName) throws SAXException { super.endElement(uri, localName, qName); String cleanQName = cleanQName(qName); if (stk.empty() == true) { //System.out.println("Stack empty"); stk.push(val); }//from w w w . ja v a2 s. c o m newVal = (JSONObject) stk.pop(); if (content != null) { newVal.put("value", content); content = null; } if (stk.empty() == false) { JSONObject parent = (JSONObject) stk.pop(); if (parent.containsKey(cleanQName) == true) { if (parent.get(cleanQName) instanceof JSONObject) { JSONObject old_val = (JSONObject) parent.get(cleanQName); if (newVal.size() > 0) { JSONArray new_array = new JSONArray(); if (old_val.size() == 1 && old_val.containsKey("value") && newVal.size() == 1 && newVal.containsKey("value")) { new_array.add(old_val.get("value")); new_array.add(newVal.get("value")); } else { new_array.add(old_val); new_array.add(newVal); } parent.put(cleanQName, new_array); } stk.push(parent); } else if (parent.get(cleanQName) instanceof JSONValue) { JSONValue old_val = (JSONValue) parent.get(cleanQName); JSONArray new_array = new JSONArray(); new_array.add(old_val); new_array.add(newVal); parent.put(cleanQName, new_array); stk.push(parent); } else if (parent.get(cleanQName) instanceof JSONArray) { JSONArray old_val = (JSONArray) parent.get(cleanQName); if (newVal.size() == 1 && newVal.containsKey("value")) { old_val.add(newVal.get("value")); } else { old_val.add(newVal); } stk.push(parent); } else { String old_val = (String) parent.get(cleanQName); JSONArray new_array = new JSONArray(); new_array.add(old_val); new_array.add(newVal); parent.put(cleanQName, new_array); stk.push(parent); } } else { parent.put(cleanQName, newVal); stk.push(parent); } } }
From source file:gwap.rest.PastTerminaSessionBean.java
@GET @Produces(MediaType.APPLICATION_JSON)/*ww w . j a v a 2s. com*/ @Path("userResults") /** * * @param termName The name of the term in question. * @param owr if wrong tags of the player should be appended to the response. * @param fwr if wrong tags of other players should be appended to the response. * @param mon the maximal number of player tags in the response. * @param mfn the maximal number of tags of other players in the response. * @return the tags that the current player gave to the current term, the tags of the other players, etc. */ public Response getTaggingData(@QueryParam("term") String termName, @QueryParam("owr") String owr, @QueryParam("fwr") String fwr, @QueryParam("mon") String mon, @QueryParam("mfn") String mfn) { JSONObject jsonObject = new JSONObject(); setTermName(termName); setWrongRequests(fwr, owr); setMaxNodes(mfn, mon); if (term != null) { jsonObject.put("term", term.getTag().getName()); //own tags JSONArray owns = new JSONArray(); Query t = entityManager.createNamedQuery("tagging.answersByPersonAndResource"); t.setParameter("resourceId", term.getId()); t.setParameter("person", this.person); // t.setMaxResults(10); List<Tag> ownTags = t.getResultList(); ArrayList<String> ownTagNames = new ArrayList<String>(); for (Tag tag : ownTags) { ownTagNames.add(tag.getName()); } //foreign tags JSONArray foreigns = new JSONArray(); int[] minMaxAppearences = new int[2]; addToJSONArray(owns, foreigns, ownTagNames, minMaxAppearences, "tagging.topCorrectAnswersGeneral", "directMatch"); addToJSONArray(owns, foreigns, ownTagNames, minMaxAppearences, "tagging.topUnknownAnswersGeneral", "indirectMatch"); addToJSONArray(owns, foreigns, ownTagNames, minMaxAppearences, "tagging.topWrongAnswersGeneral", "WRONG"); JSONArray topics = getTopicOfTerm(); jsonObject.put("foreigns", foreigns); jsonObject.put("owns", owns); jsonObject.put("maxApp", minMaxAppearences[1]); jsonObject.put("minApp", minMaxAppearences[0]); jsonObject.put("topics", topics); } else { return Response.status(Status.BAD_REQUEST).build(); } return Response.ok(jsonObject.toString(), MediaType.APPLICATION_JSON).build(); }
From source file:Castle.PDFNGTest.java
/** * Test of setKeywords method, of class PDF. * @throws java.io.IOException/* w w w . ja v a 2 s. c o m*/ */ @Test public void testSetKeywords() throws IOException, ParseException { System.out.println("setKeywords"); JSONArray data = new JSONArray(); PDF instance = new PDF(); String filePath = "src\\resources\\6dot1.pdf"; instance.load(filePath); instance.setKeywords(data); }
From source file:gr.iit.demokritos.cru.cps.api.CreateGroup.java
public JSONObject processRequest() throws IOException, Exception { String response_code = "e0"; long user_id = 0; String[] users = users_list.split(";"); ArrayList<Long> users_id = new ArrayList<Long>(); for (int i = 0; i < users.length; i++) { users_id.add(Long.parseLong(users[i])); }/* ww w . ja v a 2 s .c o m*/ // String filename = "/WEB-INF/configuration.properties"; String location = (String) properties.get("location"); String database_name = (String) properties.get("database_name"); String username = (String) properties.get("username"); String password = (String) properties.get("password"); MySQLConnector mysql = new MySQLConnector(location, database_name, username, password); try { UserManager um = new UserManager(Long.parseLong(application_key), users_id); boolean isvalid = false; isvalid = um.validateClientApplication(mysql); if (isvalid == true) { Iterator it = users_id.iterator(); while (it.hasNext()) { um.setUser_id((Long) it.next()); isvalid = um.validateUser(mysql); if (isvalid == false) { break; } } if (isvalid == true) { um.setUser_id(user_id); um.createGroup(mysql); user_id = um.getUser_id(); response_code = "OK"; } else { response_code = "e102"; } } else { response_code = "e101"; } } catch (NumberFormatException ex) { response_code = "e101"; Logger.getLogger(CreateUser.class.getName()).log(Level.SEVERE, null, ex); } JSONArray list = new JSONArray(); for (Long temp_user : users_id) { list.add(Long.toString(temp_user)); } JSONObject obj = new JSONObject(); obj.put("application_key", application_key); obj.put("group_id", Long.toString(user_id)); obj.put("users_id", list); obj.put("response_code", response_code); return obj; }
From source file:com.niles.excel2json.objects.ExcelFile.java
public void process() throws Exception { File excel = new File(path); FileInputStream fis = SystemTools.getFileInputStream(excel); XSSFWorkbook wb = null;/*from w w w .j a v a 2s . co m*/ try { wb = new XSSFWorkbook(fis); } catch (IOException ex) { logger.error("Unable to process file [{}]\r\n{}", path, ex.getMessage()); return; } this.fileName = excel.getName().replace(StringConstants.XLSX, ""); this.folderPath = fileName + " Files"; folderPath = SystemTools.createFolder(folderPath); int sheetCount = wb.getNumberOfSheets(); int currentSheetNumber = 0; int rowCount = 0; int columnCount = 0; HashMap<Integer, String> headers = new HashMap<Integer, String>(); /* * Itterate through the Excel sheets here and convert them to JSON */ while (currentSheetNumber < sheetCount) { XSSFSheet current = wb.getSheetAt(currentSheetNumber); sheetName = current.getSheetName(); // System.out.println(sheetName); if (current.getRow(0) == null) { // logger.error("[{}] Sheet contains no data", sheetName); } else { //logger.info("[{}] Processing sheet", sheetName); rowCount = current.getLastRowNum() + 1; columnCount = current.getRow(0).getPhysicalNumberOfCells(); // System.out.println("Col Count: " + columnCount); // System.out.println("Row Count: " + rowCount); JSONArray myJSONArray = new JSONArray(); JSONObject currentJSONObject = null; for (int a = 0; a < rowCount; a++) { XSSFRow currentRow = current.getRow(a); if (a == 0) { logger.info("[{}] Loading header information", sheetName); for (int currentCellNumber = 0; currentCellNumber < columnCount; currentCellNumber++) { XSSFCell currentCell = currentRow.getCell(currentCellNumber); String header = "Header" + currentCellNumber; if (currentCell != null) { if (currentCell.getCellType() == XSSFCell.CELL_TYPE_STRING) { header = currentCell.getStringCellValue(); } if (currentCell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) { header = currentCell.getNumericCellValue() + ""; } } headers.put(currentCellNumber, header.replaceAll(" ", "")); } } else { currentJSONObject = new JSONObject(); for (int currentCellNumber = 0; currentCellNumber < columnCount; currentCellNumber++) { XSSFCell currentCell = currentRow.getCell(currentCellNumber); String value = ""; if (currentCell != null) { if (currentCell.getCellType() != XSSFCell.CELL_TYPE_ERROR && currentCell.getCellType() != XSSFCell.CELL_TYPE_FORMULA) { if (currentCell.getCellType() == XSSFCell.CELL_TYPE_STRING) { value = currentCell.getStringCellValue(); } if (currentCell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) { value = currentCell.getNumericCellValue() + ""; } if (currentCell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) { value = currentCell.getBooleanCellValue() + ""; } if (value == null) { value = ""; } } } currentJSONObject.put(headers.get(currentCellNumber), value); } myJSONArray.add(currentJSONObject); } } writeToJson(myJSONArray); } currentSheetNumber++; } }
From source file:com.pingidentity.adapters.idp.mobileid.restservice.MssSignatureRequestJson.java
private JSONArray buildAdditionalServices() { JSONObject object = new JSONObject(); object.put("Description", "http://mss.ficom.fi/TS102204/v1.0.0#userLang"); object.put("UserLang", buildUserLang()); JSONArray list = new JSONArray(); list.add(object);/* ww w .ja v a 2 s.c om*/ return list; }
From source file:gr.iit.demokritos.cru.cps.api.DestroyGroup.java
public JSONObject processRequest() throws IOException, Exception { String response_code = "e0"; long user_id = 0; String[] groups = group_list.split(";"); ArrayList<Long> groups_id = new ArrayList<Long>(); for (int i = 0; i < groups.length; i++) { groups_id.add(Long.parseLong(groups[i])); }// w w w . j av a 2 s .co m // String filename = "/WEB-INF/configuration.properties"; String location = (String) properties.get("location"); String database_name = (String) properties.get("database_name"); String username = (String) properties.get("username"); String password = (String) properties.get("password"); MySQLConnector mysql = new MySQLConnector(location, database_name, username, password); try { UserManager um = new UserManager(Long.parseLong(application_key), groups_id); boolean isvalid = false; isvalid = um.validateClientApplication(mysql); if (isvalid == true) { Iterator it = groups_id.iterator(); while (it.hasNext()) { um.setUser_id((Long) it.next()); isvalid = um.validateUser(mysql); if (isvalid == false) { break; } } if (isvalid == true) { um.setUser_id(user_id); um.createGroup(mysql); user_id = um.getUser_id(); response_code = "OK"; } else { response_code = "e102"; } } else { response_code = "e101"; } } catch (NumberFormatException ex) { response_code = "e101"; Logger.getLogger(CreateUser.class.getName()).log(Level.SEVERE, null, ex); } JSONArray list = new JSONArray(); for (Long temp_user : groups_id) { list.add(Long.toString(temp_user)); } JSONObject obj = new JSONObject(); obj.put("application_key", application_key); obj.put("group_id", Long.toString(user_id)); obj.put("users_id", list); obj.put("response_code", response_code); return obj; }
From source file:modelo.ParametrizacionManagers.Consultores.java
public JSONArray getConsultor(int codigo) { SeleccionarConsultores seleccionar = new SeleccionarConsultores(); ResultSet rset = seleccionar.getConsultor(codigo); JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); try {//from w w w.ja va 2 s. co m while (rset.next()) { jsonObject.put("codigo", rset.getString("CODIGO")); jsonObject.put("nombre", rset.getString("NOMBRES")); jsonObject.put("apellidos", rset.getString("APELLIDOS")); jsonObject.put("direccion", rset.getString("DIRECCION")); jsonObject.put("telefono1", rset.getString("TELEFONO1")); jsonObject.put("telefono2", rset.getString("TELEFONO2")); jsonObject.put("correo", rset.getString("EMAIL")); jsonObject.put("identificacion", rset.getString("IDENTIFICACION")); jsonObject.put("descripcion", rset.getString("NOMBRES") + ' ' + rset.getString("APELLIDOS")); jsonArray.add(jsonObject.clone()); } seleccionar.desconectar(); } catch (SQLException ex) { // Logger.getLogger(Laboratorios.class.getName()).log(Level.SEVERE, null, ex); } return jsonArray; }
From source file:com.skelril.ShivtrAuth.AuthenticationCore.java
public synchronized JSONArray getFrom(String subAddress) { JSONArray objective = new JSONArray(); HttpURLConnection connection = null; BufferedReader reader = null; try {// ww w. j av a 2 s. co m JSONParser parser = new JSONParser(); for (int i = 1; true; i++) { try { // Establish the connection URL url = new URL(websiteURL + subAddress + "?page=" + i); connection = (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(1500); connection.setReadTimeout(1500); // Check response codes return if invalid if (connection.getResponseCode() < 200 || connection.getResponseCode() >= 300) return null; // Begin to read results reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder builder = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { builder.append(line); } // Parse Data JSONObject o = (JSONObject) parser.parse(builder.toString()); JSONArray ao = (JSONArray) o.get("characters"); if (ao.isEmpty()) break; Collections.addAll(objective, (JSONObject[]) ao.toArray(new JSONObject[ao.size()])); } catch (ParseException e) { break; } finally { if (connection != null) connection.disconnect(); if (reader != null) { try { reader.close(); } catch (IOException ignored) { } } } } } catch (IOException e) { return null; } return objective; }