use of org.json.JSONArray in project flux by eclipse.
the class RenameService method handleRenameInFileRequest.
protected void handleRenameInFileRequest(JSONObject message) {
try {
String username = message.getString("username");
String projectName = message.getString("project");
String resourcePath = message.getString("resource");
int callbackID = message.getInt("callback_id");
String liveEditID = projectName + "/" + resourcePath;
if (liveEditUnits.isLiveEditResource(username, liveEditID)) {
int offset = message.getInt("offset");
int length = message.getInt("length");
String sender = message.getString("requestSenderID");
JSONArray references = computeReferences(username, liveEditID, offset, length);
if (references != null) {
JSONObject responseMessage = new JSONObject();
responseMessage.put("username", username);
responseMessage.put("project", projectName);
responseMessage.put("resource", resourcePath);
responseMessage.put("callback_id", callbackID);
responseMessage.put("requestSenderID", sender);
responseMessage.put("references", references);
messagingConnector.send("renameinfileresponse", responseMessage);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.json.JSONArray in project flux by eclipse.
the class ContentAssistService method getPositions.
private JSONArray getPositions(List<Integer> positionsList, int initOffset) throws JSONException {
if (positionsList != null && positionsList.size() % 2 == 0) {
JSONArray jsonPositions = new JSONArray();
for (int i = 0; i < positionsList.size(); i += 2) {
JSONObject position = new JSONObject();
position.put("offset", positionsList.get(i) + initOffset);
position.put("length", positionsList.get(i + 1));
jsonPositions.put(position);
}
return jsonPositions;
} else {
return null;
}
}
use of org.json.JSONArray in project flux by eclipse.
the class InitializeServiceEnvironment method handleGetProjectsResponse.
protected void handleGetProjectsResponse(JSONObject message) {
try {
String username = message.getString("username");
if (repository.getUsername().equals(username)) {
JSONArray projects = message.getJSONArray("projects");
for (int i = 0; i < projects.length(); i++) {
JSONObject project = projects.getJSONObject(i);
String projectName = project.getString("name");
initializeProject(projectName);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.json.JSONArray in project flux by eclipse.
the class DownloadProject method getProjectResponse.
public void getProjectResponse(JSONObject response) {
try {
final String responseProject = response.getString("project");
final String responseUser = response.getString("username");
final JSONArray files = response.getJSONArray("files");
if (this.username.equals(responseUser)) {
Set<String> newFiles = new HashSet<String>();
for (int i = 0; i < files.length(); i++) {
JSONObject resource = files.getJSONObject(i);
String resourcePath = resource.getString("path");
long timestamp = resource.getLong("timestamp");
String type = resource.optString("type");
if (type.equals("folder")) {
if (!resourcePath.isEmpty()) {
IFolder folder = project.getFolder(new Path(resourcePath));
createFolder(folder);
folder.setLocalTimeStamp(timestamp);
}
} else if (type.equals("file")) {
boolean added = this.projectFiles.add(resourcePath);
if (added) {
newFiles.add(resourcePath);
}
}
}
for (Iterator<String> newFilesIterator = newFiles.iterator(); newFilesIterator.hasNext(); ) {
String resourcePath = (String) newFilesIterator.next();
this.requestedProjectFiles.add(resourcePath);
JSONObject message = new JSONObject();
message.put("callback_id", callbackID);
message.put("username", this.username);
message.put("project", responseProject);
message.put("resource", resourcePath);
messagingConnector.send("getResourceRequest", message);
}
}
} catch (Exception e) {
e.printStackTrace();
this.messagingConnector.removeMessageHandler(projectResponseHandler);
this.messagingConnector.removeMessageHandler(resourceResponseHandler);
this.completionCallback.downloadFailed();
}
}
use of org.json.JSONArray in project flux by eclipse.
the class RabbitMQFluxConfig method rabbitUrl.
public static String rabbitUrl() throws Exception {
String vcapServices = System.getenv("VCAP_SERVICES");
if (vcapServices != null) {
JSONObject svcInfo = JSON.parse(vcapServices);
console.log("VCAP_SERVICES = " + svcInfo);
for (String label : JSONObject.getNames(svcInfo)) {
JSONArray svcs = svcInfo.getJSONArray(label);
for (int index = 0; index < svcs.length(); index++) {
String uri = svcs.getJSONObject(index).getJSONObject("credentials").getString("uri");
if (uri.contains("amqp")) {
console.log("rabbit url = " + uri);
return uri;
}
}
}
throw new Error("Running on CF requires that you bind a amqp service to this app");
} else {
return "amqp://localhost";
}
}
Aggregations