Search in sources :

Example 16 with JSONArray

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();
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 17 with JSONArray

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;
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 18 with JSONArray

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();
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException)

Example 19 with JSONArray

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();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException) HashSet(java.util.HashSet) IFolder(org.eclipse.core.resources.IFolder)

Example 20 with JSONArray

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";
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Aggregations

JSONArray (org.json.JSONArray)1596 JSONObject (org.json.JSONObject)1121 JSONException (org.json.JSONException)690 ArrayList (java.util.ArrayList)303 IOException (java.io.IOException)232 Test (org.junit.Test)199 HashMap (java.util.HashMap)105 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)96 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)61 List (java.util.List)59 HashSet (java.util.HashSet)53 File (java.io.File)49 Query (org.b3log.latke.repository.Query)47 RandomString (edu.umass.cs.gnscommon.utils.RandomString)44 Date (java.util.Date)44 GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)43 Map (java.util.Map)40 FileNotFoundException (java.io.FileNotFoundException)37 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)36 VolleyError (com.android.volley.VolleyError)35