List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:com.conwet.silbops.msg.UnsubscribeMsg.java
@Override @SuppressWarnings("unchecked") public JSONObject getPayloadAsJSON() { JSONObject json = new JSONObject(); json.put("subscription", subscription.toJSON()); JSONArray uncov = new JSONArray(); for (Subscription fil : uncovered) { uncov.add(fil.toJSON()); }//from w w w . j a va 2s. c o m json.put("uncovered", uncov); return json; }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.parser.Task.java
@SuppressWarnings("unchecked") @Override// w w w. j a v a2 s . co m public String toJSONString() { JSONObject obj = new JSONObject(); obj.put("point", getPosition()); obj.put("tolerance", getTolerance()); // TODO arrival time, delay, and lifetime in JSON string? JSONArray act = new JSONArray(); for (IAction a : getActionList()) { act.add(a); } obj.put("actions", act); return obj.toJSONString(); }
From source file:com.ibm.stocator.fs.swift.auth.PasswordScopeAccessProvider.java
/** * Authentication logic/* ww w . jav a 2 s . com*/ * * @return Access JOSS access object * @throws IOException if failed to parse the response */ public Access passwordScopeAuth() throws IOException { InputStreamReader reader = null; BufferedReader bufReader = null; try { JSONObject user = new JSONObject(); user.put("id", mUserId); user.put("password", mPassword); JSONObject password = new JSONObject(); password.put("user", user); JSONArray methods = new JSONArray(); methods.add("password"); JSONObject identity = new JSONObject(); identity.put("methods", methods); identity.put("password", password); JSONObject project = new JSONObject(); project.put("id", mProjectId); JSONObject scope = new JSONObject(); scope.put("project", project); JSONObject auth = new JSONObject(); auth.put("identity", identity); auth.put("scope", scope); JSONObject requestBody = new JSONObject(); requestBody.put("auth", auth); HttpURLConnection connection = (HttpURLConnection) new URL(mAuthUrl).openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Accept", "application/json"); connection.setRequestProperty("Content-Type", "application/json"); OutputStream output = connection.getOutputStream(); output.write(requestBody.toString().getBytes()); int status = connection.getResponseCode(); if (status != 201) { return null; } reader = new InputStreamReader(connection.getInputStream()); bufReader = new BufferedReader(reader); String res = bufReader.readLine(); JSONParser parser = new JSONParser(); JSONObject jsonResponse = (JSONObject) parser.parse(res); String token = connection.getHeaderField("X-Subject-Token"); PasswordScopeAccess access = new PasswordScopeAccess(jsonResponse, token, mPrefferedRegion); bufReader.close(); reader.close(); connection.disconnect(); return access; } catch (Exception e) { if (bufReader != null) { bufReader.close(); } if (reader != null) { reader.close(); } throw new IOException(e); } }
From source file:com.mobicage.rogerthat.MessageCallbackResult.java
@SuppressWarnings("unchecked") @Override/* w ww.ja va2 s. co m*/ public JSONObject toJSONObject() { final JSONObject result = new JSONObject(); result.put("message", message); final JSONArray answerArray = new JSONArray(); for (Answer answer : answers) { answerArray.add(answer.toJSONObject()); } result.put("answers", answerArray); result.put("flags", flags); result.put("branding", branding); result.put("tag", tag); result.put("alert_flags", alertFlags); result.put("dismiss_button_ui_flags", dismissButtonUiFlags); return result; }
From source file:c3.ops.priam.backup.MetaData.java
@SuppressWarnings("unchecked") public void set(List<AbstractBackupPath> bps, String snapshotName) throws Exception { File metafile = createTmpMetaFile(); FileWriter fr = new FileWriter(metafile); try {// w ww. j av a 2 s . co m JSONArray jsonObj = new JSONArray(); for (AbstractBackupPath filePath : bps) jsonObj.add(filePath.getRemotePath()); fr.write(jsonObj.toJSONString()); } finally { IOUtils.closeQuietly(fr); } AbstractBackupPath backupfile = pathFactory.get(); backupfile.parseLocal(metafile, BackupFileType.META); backupfile.time = backupfile.parseDate(snapshotName); try { upload(backupfile); addToRemotePath(backupfile.getRemotePath()); if (metaRemotePaths.size() > 0) { notifyObservers(); } } finally { FileUtils.deleteQuietly(metafile); } }
From source file:forumbox.PostingnewpostServlet.java
public void filewrite(String url, String username, String title, String description, HttpServletResponse response, String id) throws IOException { count++;// w w w .j a v a 2 s . co 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.erbjuder.logger.server.entity.impl.ApplicationFlowConfiguration.java
public JSONObject toJSON() { JSONArray nodeList = new JSONArray(); for (Node node : this.getNodes()) { nodeList.add(node.toJSON()); }//from w ww.ja v a 2s. co m JSONObject json = new JSONObject(); json.put("id", this.getId()); json.put("flowName", this.getName()); json.put("flowDescription", this.getDescription()); json.put("definedNodes", nodeList); // json.put("graph", this.getGraph() == null ? "null" : this.getGraph().toJSON()); return json; }
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])); }/*www. j a va 2 s. c om*/ // 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.opensoc.tagging.adapters.RegexTagger.java
/** * @param raw_message telemetry message to be tagged *///from w ww .j av a2 s . c o m @SuppressWarnings("unchecked") public JSONArray tag(JSONObject raw_message) { JSONArray ja = new JSONArray(); String message_as_string = raw_message.toString(); for (String rule : _rules.keySet()) { if (message_as_string.matches(rule)) { ja.add(_rules.get(rule)); } } return ja; }
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 . java 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), 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; }