List of usage examples for org.json.simple JSONArray get
public E get(int index)
From source file:importer.handler.post.stages.StageThreeXML.java
boolean verifyCorCode(String stil, String text) { JSONObject jObj = (JSONObject) JSONValue.parse(stil); JSONArray ranges = (JSONArray) jObj.get(JSONKeys.RANGES); int offset = 0; for (int i = 0; i < ranges.size(); i++) { JSONObject range = (JSONObject) ranges.get(i); offset += ((Number) range.get("reloff")).intValue(); int len = ((Number) range.get("len")).intValue(); if (offset + len > text.length()) return false; }// www . j a v a 2 s . c o m return true; }
From source file:edu.ucsd.sbrg.escher.utilities.EscherParser.java
/** * @param inputStream/*from w w w. ja v a 2s .co m*/ * @param defaultMapId * @return * @throws IOException * @throws ParseException */ public EscherMap parse(InputStream inputStream, String defaultMapId) throws IOException, ParseException { // Read JSON file JSONParser parser = new JSONParser(); Reader reader = new BufferedReader(new InputStreamReader(inputStream)); Object obj = parser.parse(reader); reader.close(); if (!(obj instanceof JSONArray)) { logger.warning(MessageFormat.format(bundle.getString("EscherParser.JSONObjectExpected"), obj, obj.getClass().getName(), JSONArray.class.getName())); return null; } JSONArray json = (JSONArray) obj; JSONObject map = (JSONObject) json.get(0); /* * Create the EscherMap object. */ EscherMap escherMap = new EscherMap(); Object id = map.get(EscherKeywords.map_id.name()); escherMap.setId(id != null ? id.toString() : defaultMapId); escherMap.setName(map.get(EscherKeywords.map_name.name()).toString()); escherMap.setDescription(map.get(EscherKeywords.map_description.name()).toString()); escherMap.setSchema(map.get(EscherKeywords.schema.name()).toString()); escherMap.setURL(map.get(EscherKeywords.homepage.name()).toString()); JSONObject parts = (JSONObject) json.get(1); Canvas canvas = parseCanvas((JSONObject) parts.get(EscherKeywords.canvas.name())); escherMap.setCanvas(canvas); /* * Nodes */ JSONObject mapNode = (JSONObject) parts.get(EscherKeywords.nodes.name()); if (mapNode != null) { for (Object object : mapNode.keySet()) { Node node = parseNode(object, (JSONObject) mapNode.get(object)); escherMap.addNode(node); if (node.isSetCompartment()) { try { EscherCompartment compartment = escherMap.getCompartment(node.getCompartment()); double x = node.getX(); // - node.getWidth()/2d; double y = node.getY(); // - node.getHeight()/2d; if (compartment == null) { compartment = new EscherCompartment(); compartment.setId(node.getCompartment()); compartment.setX(x); compartment.setY(y); compartment.setWidth(0d); //node.getWidth()); compartment.setHeight(0d); //node.getHeight()); escherMap.addCompartment(compartment); } else { if (x < compartment.getX()) { compartment.setX(x); } else if (x /*+ node.getWidth()*/ > compartment.getX() + compartment.getWidth()) { compartment.setWidth(x /* + node.getWidth()*/); } if (y < compartment.getY()) { compartment.setY(y); } else if (y /*+ node.getHeight()*/ > compartment.getY() + compartment.getHeight()) { compartment.setHeight(y /* + node.getHeight()*/); } } } catch (Throwable t) { t.printStackTrace(); } } } } /* * Reactions */ JSONObject mapReactions = (JSONObject) parts.get(EscherKeywords.reactions.name()); if (mapReactions != null) { for (Object object : mapReactions.keySet()) { for (EscherReaction reaction : parseReaction(object, (JSONObject) mapReactions.get(object), escherMap)) { escherMap.addReaction(reaction); } } } /* * Labels */ JSONObject mapText = (JSONObject) parts.get(EscherKeywords.text_labels.name()); if (mapText != null) { for (Object object : mapText.keySet()) { escherMap.addTextLabel(parseTextLabel(object, (JSONObject) mapText.get(object))); } } return escherMap; }
From source file:au.edu.uws.eresearch.cr8it.TransformationHandler.java
private String getJsonMapping(String jsonString) throws IOException, ParseException { String template = readFile("./template.json"); JSONParser parser = new JSONParser(); JSONObject original = (JSONObject) parser.parse(template); JSONObject manifest = (JSONObject) parser.parse(jsonString); JSONObject dataObject = (JSONObject) original.get("data"); JSONArray dataArray = (JSONArray) dataObject.get("data"); JSONArray creators = (JSONArray) manifest.get("creators"); JSONArray activities = (JSONArray) manifest.get("activities"); JSONArray vfs = (JSONArray) manifest.get("vfs"); LocalDate today = new LocalDate(); int creatorIndex = 1; int grantIndex = 1; for (Object data : dataArray) { ((JSONObject) data).put("datasetId", jsonString.hashCode()); JSONObject tfpackage = (JSONObject) ((JSONObject) data).get("tfpackage"); tfpackage.put("dc:created", today.toString()); Object root = vfs.get(0); if (root != null) { String crateName = (String) ((JSONObject) root).get("name"); tfpackage.put("dc:title", crateName); tfpackage.put("title", crateName); }//from w w w.j av a2 s . c om for (Object creator : creators) { //TODO we might need to split the name into first and last name String name = (String) ((JSONObject) creator).get("name"); tfpackage.put("dc:creator.foaf:Person." + creatorIndex + ".foaf:name", name); String identifier = (String) ((JSONObject) creator).get("identifier"); tfpackage.put("dc:creator.foaf:Person." + creatorIndex + ".dc:identifier", identifier); creatorIndex++; } for (Object activity : activities) { String identifier = (String) ((JSONObject) activity).get("identifier"); tfpackage.put("foaf:fundedBy.vivo:Grant." + grantIndex + ".dc:identifier", identifier); String grantNumber = (String) ((JSONObject) activity).get("grant_number"); tfpackage.put("foaf:fundedBy.vivo:Grant." + grantIndex + ".redbox:grantNumber", grantNumber); String title = (String) ((JSONObject) activity).get("title"); String repositoryName = (String) ((JSONObject) activity).get("repository_name"); tfpackage.put("foaf:fundedBy.vivo:Grant." + grantIndex + ".skos:prefLabel", "(" + repositoryName + ") " + title); grantIndex++; } } String updatedJson = original.toJSONString(); return updatedJson; }
From source file:Gui.Pantalla.java
/** * recibe el parametro i que sirve para verificar que tipo de operacion se va a * realizar, verfica si se valida el arbol que queremos. * @param i /*ww w . ja v a 2s .com*/ */ private void AddGraf() { arreglo.llenar(getCant()); arreglo.llenarPC(getCant()); JSONArray json = arreglo.crearJson(0); JSONArray jsonPC = arreglo.crearJson(1); Random rnd = new Random(); if (ABB == true) setTABB(json, jsonPC, 1, (int) json.get(rnd.nextInt(json.size() - 1)), (int) jsonPC.get(rnd.nextInt(jsonPC.size() - 1))); if (ASP == true) { setTASP(json, jsonPC, 3, (int) json.get(rnd.nextInt(json.size() - 1)), (int) jsonPC.get(rnd.nextInt(jsonPC.size() - 1))); } if (ARN == true) { setTARN(json, jsonPC, 4, (int) json.get(rnd.nextInt(json.size() - 1)), (int) jsonPC.get(rnd.nextInt(jsonPC.size() - 1))); } if (AVL == true) { setTAVL(json, jsonPC, 2, (int) json.get(rnd.nextInt(json.size() - 1)), (int) jsonPC.get(rnd.nextInt(jsonPC.size() - 1))); } }
From source file:interfaceTisseoWS.ST3.java
private void listResMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listResMouseClicked String x = (String) ((JSONObject) ((JSONArray) ((JSONObject) array.get("placesList")).get("place")) .get(listRes.getSelectedIndex())).get("x"); String y = (String) ((JSONObject) ((JSONArray) ((JSONObject) array.get("placesList")).get("place")) .get(listRes.getSelectedIndex())).get("y"); double distanceAParcourir = getDistance(1.46944, 43.561255, Double.valueOf(x), Double.valueOf(y)); double ax = Double.valueOf(x) - 0.005; double ay = Double.valueOf(y) - 0.003; double bx = Double.valueOf(x) + 0.005; double by = Double.valueOf(y) + 0.003; // x+-0.005 y+-0.003 boolean contientTisseo, contientVelib = false; try {//from www. j ava 2 s .co m //recherche lignes tisseo dans la zone RequestTisseo r = new RequestTisseo(); JSONParser parser = new JSONParser(); r.setPathURIB("/stopPointsList"); r.addParamURIB("srid", "4326"); r.addParamURIB("displayLines", "1"); r.addParamURIB("sortByDistance", "1"); String bbox = Double.toString(ax) + "," + Double.toString(ay) + "," + Double.toString(bx) + "," + Double.toString(by); r.addParamURIB("bbox", bbox); Object obj = parser.parse(r.request()); JSONObject array2 = (JSONObject) obj; contientTisseo = (((JSONArray) ((JSONObject) array2.get("physicalStops")).get("physicalStop")) .size()) > 0; //recherche stations velib dans la zone si point moins de 3 kilomtre if (distanceAParcourir < 3.0) { RequestJCDecaux r3 = new RequestJCDecaux(); JSONParser parser3 = new JSONParser(); r3.setPathURIB("/vls/v1/stations"); Object obj3 = parser3.parse(r3.request()); JSONArray array3 = (JSONArray) obj3; int nbStations = array3.size(); double X, Y; int i = 0; while (i < nbStations && !contientVelib) { X = (double) ((JSONObject) ((JSONObject) (JSONObject) array3.get(i)).get("position")) .get("lng"); Y = (double) ((JSONObject) ((JSONObject) (JSONObject) array3.get(i)).get("position")) .get("lat"); if (X > ax && X < bx && Y > ay && Y < by) { contientVelib = true; } i++; } } if (!contientTisseo && !contientVelib) { lblResultat.setText("Aucun rsultat"); } else { if (contientTisseo && !contientVelib) { lblResultat.setText("Utilisez le rseau Tisso"); } else { if (!contientTisseo && contientVelib) { lblResultat.setText("Utilisez VelToulouse"); } else { int nbArrivees = (((JSONArray) ((JSONObject) array2.get("physicalStops")) .get("physicalStop")).size()); int j = 0; while (j < nbArrivees) { if (estDeservieDepuisPS(((JSONArray) ((JSONObject) ((JSONArray) ((JSONObject) array2 .get("physicalStops")).get("physicalStop")).get(j)).get("destinations")))) { break; } j++; if (j == nbArrivees) { lblResultat.setText( "Aucun ligne Tisso ne dssert directement votre zone depuis \nPaul Sabatier, la distance est infrieure 3 km donc nous vous \nconseillons d'utiliser le service VelToulouse"); } } } } } } catch (ParseException ex) { Logger.getLogger(ST3.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ST3.class.getName()).log(Level.SEVERE, null, ex); } catch (URISyntaxException ex) { Logger.getLogger(ST3.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.acmeair.jmeter.functions.FlightsPostProcessor.java
public String processJSonString(String responseDataAsString) { try {//from w ww . j a v a 2s . c o m JSONObject json = (JSONObject) new JSONParser().parse(responseDataAsString); JSONArray tripFlights = (JSONArray) json.get("tripFlights"); if (tripFlights == null || tripFlights.size() == 0) { context.setIsFlightAvailable("false"); FlightsThreadLocal.set(context); return null; } for (int counter = 1; counter <= tripFlights.size(); counter++) { if (counter == 1) { JSONObject jsonTripFlight = (JSONObject) tripFlights.get(0); JSONArray jsonFlightOptions = (JSONArray) jsonTripFlight.get("flightsOptions"); String numFlightsAsString = jsonFlightOptions.size() + ""; context.setNumOfToFlights(numFlightsAsString); JMeterContextService.getContext().getVariables().put(FLIGHT_TO_COUNT, numFlightsAsString); if (jsonFlightOptions.size() > 0) { context.setIsFlightAvailable("true"); } else { context.setIsFlightAvailable("false"); } } else if (counter == 2) { JSONObject jsonTripFlight = (JSONObject) tripFlights.get(1); JSONArray jsonFlightOptions = (JSONArray) jsonTripFlight.get("flightsOptions"); String numFlightAsString = jsonFlightOptions.size() + ""; context.setNumOfRetFlights(numFlightAsString); JMeterContextService.getContext().getVariables().put(FLIGHT_RET_COUNT, numFlightAsString); if (jsonFlightOptions.size() > 0) { context.setONEWAY("false"); JMeterContextService.getContext().getVariables().put(ONE_WAY, "false"); } else { context.setONEWAY("true"); JMeterContextService.getContext().getVariables().put(ONE_WAY, "true"); } } JSONObject jsonTripFlight = (JSONObject) tripFlights.get(counter - 1); JSONArray jsonFlightOptions = (JSONArray) jsonTripFlight.get("flightsOptions"); for (int tripCounter = 1; tripCounter <= jsonFlightOptions.size(); tripCounter++) { if (counter == 1) { JSONObject flightOption0 = (JSONObject) jsonFlightOptions.get(tripCounter - 1); if (ExtractFlightsInfoFunction.pureIDs) { String id = (String) flightOption0.get("_id"); String fsId = (String) flightOption0.get("flightSegmentId"); context.setTOFLIGHT(id); context.setTOSEGMENTID(fsId); } else { JSONObject flightOption0Pkey = (JSONObject) flightOption0.get("pkey"); context.setTOFLIGHT((String) flightOption0Pkey.get("id")); context.setTOSEGMENTID((String) flightOption0Pkey.get("flightSegmentId")); } } else if (counter == 2) { JSONObject flightOption0 = (JSONObject) jsonFlightOptions.get(tripCounter - 1); if (ExtractFlightsInfoFunction.pureIDs) { String id = (String) flightOption0.get("_id"); String fsId = (String) flightOption0.get("flightSegmentId"); context.setRETFLIGHT(id); context.setRESEGMENTID(fsId); } else { JSONObject flightOption0Pkey = (JSONObject) flightOption0.get("pkey"); context.setRETFLIGHT((String) flightOption0Pkey.get("id")); context.setRESEGMENTID((String) flightOption0Pkey.get("flightSegmentId")); } } } } FlightsThreadLocal.set(context); return json.toJSONString(); } catch (ParseException e) { System.out.println("responseDataAsString = " + responseDataAsString); e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); System.out.println( "NullPointerException in FlightsPostProcessor - ResponseData =" + responseDataAsString); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.firmansyah.imam.sewa.kendaraan.FormUser.java
public void showDataUserById(int id) throws ParseException { try {/*from ww w . ja v a 2s . c o m*/ getDataURL dataurl = new getDataURL(); String url = Path.serverURL + "/user/show/" + id; String data = dataurl.getData(url); Object obj = JSONValue.parse(data); JSONArray dataArray = (JSONArray) obj; JSONObject getData = (JSONObject) dataArray.get(0); Object nama = getData.get("nama"); Object username = getData.get("username"); Object id_pelanggan = getData.get("id"); Object status = getData.get("status"); if (status.equals("0")) { btnAktif.setText("Aktifkan"); } else { btnAktif.setText("Non Aktifkan"); } inputNama.setText((String) nama); inputUsername.setText((String) username); inputIdUser.setText((String) id_pelanggan.toString()); btnTambah.setEnabled(false); btnUbah.setEnabled(true); btnHapus.setEnabled(true); btnAktif.setEnabled(true); } catch (IOException ex) { Logger.getLogger(FormUser.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.googlecode.fascinator.portal.security.FascinatorWebSecurityExpressionRoot.java
/** * get the workflow configuration of a digital object at the current stage * /* w w w.j av a2 s. com*/ * @param digitalObject * @throws StorageException * @throws IOException */ private JsonObject getWorkflowStageConfig(DigitalObject digitalObject) throws StorageException, IOException { JsonSimple workflowMetadata = getWorkflowMetadata(digitalObject); String workflowId = workflowMetadata.getString(null, "id"); JsonSimple workflowConfiguration = getWorkflowConfiguration(workflowId); JSONArray workflowStages = workflowConfiguration.getArray("stages"); JsonObject workflowStageConfiguration = null; for (int i = 0; i < workflowStages.size(); i++) { JsonObject workflowStage = (JsonObject) workflowStages.get(i); if (workflowMetadata.getJsonObject().get("step").equals(workflowStage.get("name"))) { workflowStageConfiguration = workflowStage; break; } } return workflowStageConfiguration; }
From source file:com.ls.zencat.ZenCat.java
protected String handleBuiltInCommand(String cmd, String sender) { String toks[] = cmd.split(" "); String method = toks[0];/* w ww . j a v a 2s . c o m*/ // JOIN A CHANNEL if (method.equals("join") && toks.length >= 2) { if (toks.length == 3) joinChannel(toks[1], toks[2]); else joinChannel(toks[1]); sendMessage(toks[1], "<" + sender + "> !" + cmd); return "Joining: " + toks[1]; } // PART A CHANNEL if (method.equals("part") && toks.length == 2) { sendMessage(toks[1], "<" + sender + "> !" + cmd); partChannel(toks[1]); return "Leaving: " + toks[1]; } // BROADCAST MSG TO ALL CHANNELS if (method.equals("spam")) { this.catStuffToAll("<" + sender + "> " + cmd.substring(5)); } // LIST CHANNELS THE BOT IS IN if (method.equals("channels")) { String[] c = getChannels(); StringBuffer sb = new StringBuffer("I am in " + c.length + " channels: "); for (int i = 0; i < c.length; ++i) sb.append(c[i] + " "); return sb.toString(); } // ACK A ZENOSS ALERT if (method.equals("ack") && toks.length == 2) { String evid = toks[1]; try { JSONObject json = ja.ackEvent(evid); String resultString = new String(); if (json.toString().indexOf("true") > 0) { resultString = "Successfully ACKed event: " + evid; } else { resultString = "Failed to ACK event: " + evid; } sendNotice(defaultChannel, resultString); } catch (Exception e) { return e.getMessage(); } } // UNACK A ZENOSS ALERT if (method.equals("unack") && toks.length == 2) { String evid = toks[1]; try { JSONObject json = ja.unAckEvent(evid); String resultString = new String(); if (json.toString().indexOf("true") > 0) { resultString = "Successfully un-ACKed event: " + evid; } else { resultString = "Failed to un-ACK event: " + evid; } sendNotice(defaultChannel, resultString); } catch (Exception e) { return e.getMessage(); } } // CLOSE AN EVENT if (method.equals("close") && toks.length == 2) { String evid = toks[1]; try { JSONObject json = ja.closeEvent(evid); sendNotice(defaultChannel, json.toString()); } catch (Exception e) { return e.getMessage(); } } // SHOW ALL EVENTS if (method.equals("events")) { sendMessage(defaultChannel, "ALL CURRENT ZENOSS EVENTS:"); sendMessage(defaultChannel, "severity | eventID | device: summary (state)"); try { JSONObject json = ja.getEvents(); // Loop through the array Long numEvents = (Long) json.get("totalCount"); if (numEvents > 0) { JSONArray events = (JSONArray) json.get("events"); for (int i = 0; i < numEvents; i++) { JSONObject event = (JSONObject) events.get(i); String summary = event.get("summary").toString(); String evid = event.get("id").toString(); JSONObject device = (JSONObject) event.get("device"); String deviceString = device.get("text").toString(); String severity = event.get("severity").toString(); String eventState = event.get("eventState").toString(); String eventSummary = severity + " | " + evid + " | " + deviceString + ": " + summary + " (" + eventState + ")"; sendMessage(defaultChannel, eventSummary); } } } catch (Exception e) { return e.getMessage(); } } if (method.equals("help")) { sendMessage(defaultChannel, "MEOW MEOW MEOW MEOW"); String helpText = new String(); helpText = "I am the zencat. I send messages to IRC from Zenoss. You can also interact with Zenoss through me. To see all events, type !events. To acknowledge an event, type !ack [eventID]. To set an event back to new, type !unAck [eventID]. To close an event, type !close [eventID]."; sendMessage(defaultChannel, helpText); } // EXIT() if (method.equals("exit")) System.exit(0); return ""; }
From source file:iaws_desktop.VelibDispoDialogFrame.java
/** * Creates new form VelibDispoDialogFrame *//*from w w w .j a va 2s . c o m*/ public VelibDispoDialogFrame(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); Document doc; JSONArray array; VelibWebRequest velibR = new VelibWebRequest("/vls/v1/stations"); velibR.addParameterGet("contract", "Toulouse"); try { array = (JSONArray) new JSONParser().parse(velibR.requestWithGet()); } catch (ParseException ex) { return; } listModel = new DefaultListModel<>(); JSONObject obj = null; for (int i = 0; i < array.size(); i++) { obj = (JSONObject) array.get(i); listModel.addElement(new VelibStation(obj.get("number").toString(), obj.get("name").toString())); } listVelib.setModel(listModel); }