Search in sources :

Example 76 with JSONObject

use of net.sf.json.JSONObject in project compiler by boalang.

the class GetGitHubRepoNames method main.

public static void main(String[] args) {
    File inDir = new File(Config.githubRepoListDir);
    StringBuilder sb = new StringBuilder();
    for (File file : inDir.listFiles()) {
        if (file.getName().endsWith(".json")) {
            String jsonTxt = "";
            try {
                BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
                byte[] bytes = new byte[(int) file.length()];
                in.read(bytes);
                in.close();
                jsonTxt = new String(bytes);
            } catch (Exception e) {
                System.err.println("Error reading file " + file.getAbsolutePath());
                continue;
            }
            if (jsonTxt.isEmpty()) {
                System.err.println("File is empty " + file.getAbsolutePath());
                continue;
            }
            //System.out.println(jsonTxt);
            JSONArray repos = null;
            try {
                repos = (JSONArray) JSONSerializer.toJSON(jsonTxt);
            } catch (JSONException e) {
            }
            if (repos == null) {
                System.err.println("Error parsing file " + file.getAbsolutePath());
                continue;
            }
            for (int i = 0; i < repos.size(); i++) {
                //System.out.println(repos.getJSONObject(i));
                JSONObject repo = repos.getJSONObject(i);
                String id = repo.getString("id");
                String name = repo.getString("full_name");
                System.out.println(id + ": " + name);
                sb.append(id + "," + name + "\n");
            //FileIO.writeFileContents(new File(Config.githubRepoMetadataDir + "/" + id + ".json"), repo.toString());
            }
        }
    }
    FileIO.writeFileContents(new File(inDir.getParentFile().getAbsolutePath() + "/list.csv"), sb.toString());
}
Also used : JSONObject(net.sf.json.JSONObject) BufferedInputStream(java.io.BufferedInputStream) JSONArray(net.sf.json.JSONArray) JSONException(net.sf.json.JSONException) File(java.io.File) FileInputStream(java.io.FileInputStream) JSONException(net.sf.json.JSONException)

Example 77 with JSONObject

use of net.sf.json.JSONObject in project compiler by boalang.

the class RepoMetadata method build.

public boolean build() {
    String jsonTxt = "";
    try {
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(metadataFile));
        byte[] bytes = new byte[(int) metadataFile.length()];
        in.read(bytes);
        in.close();
        jsonTxt = new String(bytes);
    } catch (Exception e) {
        System.err.println("Error reading file " + metadataFile.getAbsolutePath());
        return false;
    }
    if (jsonTxt.isEmpty()) {
        System.err.println("File is empty " + metadataFile.getAbsolutePath());
        return false;
    }
    // System.out.println(jsonTxt);
    JSONObject json = null;
    try {
        json = (JSONObject) JSONSerializer.toJSON(jsonTxt);
    } catch (JSONException e) {
    }
    if (json == null) {
        System.err.println("Error parsing file " + metadataFile.getAbsolutePath());
        return false;
    }
    JSONObject jsonProject = json;
    if (jsonProject.has(GIT_ID))
        this.id = jsonProject.getString(GIT_ID);
    if (jsonProject.has(GIT_NAME))
        this.name = jsonProject.getString(GIT_NAME);
    if (jsonProject.has(GIT_SHORT_DESCRIPTION))
        this.shortDescription = jsonProject.getString(GIT_SHORT_DESCRIPTION);
    if (jsonProject.has(GIT_HOME_PAGE)) {
        this.homepage = jsonProject.getString(GIT_HOME_PAGE);
    }
    if (jsonProject.has(GIT_SUMMARY_PAGE)) {
        this.summaryPage = jsonProject.getString(GIT_SUMMARY_PAGE);
    }
    if (jsonProject.has(GIT_CREATE)) {
        String time = jsonProject.getString(GIT_CREATE);
        // project.setCreatedDate(timestamp
        this.created_timestamp = getTimeStamp(time);
    // * 1000000);
    }
    if (jsonProject.has(GIT_DESCRIPTION))
        this.description = jsonProject.getString(GIT_DESCRIPTION);
    /*
		 * if (jsonProject.has("os")) { JSONArray jsonOSes =
		 * jsonProject.getJSONArray("os"); if (jsonOSes != null &&
		 * jsonOSes.isArray()) { for (int i = 0; i < jsonOSes.size(); i++)
		 * project.addOperatingSystems(jsonOSes.getString(i)); } }
		 */
    if (jsonProject.has(GIT_PROGRAMMING_LANGUAGES)) {
        buildProgrammingLanguages(metadataFile, id);
        if (this.programmingLanguages == null || this.programmingLanguages.length == 0)
            this.programmingLanguages = new String[] { jsonProject.getString(GIT_PROGRAMMING_LANGUAGES) };
    }
    /*
		 * if (jsonProject.has("trackers")) { ArrayList<BugRepository> bugs =
		 * new ArrayList<BugRepository>(); JSONArray trackers =
		 * jsonProject.getJSONArray("trackers"); if (trackers.isArray()) { for
		 * (int i = 0; i < trackers.size(); i++) { JSONObject tracker =
		 * trackers.getJSONObject(i); if (tracker.has("name") &&
		 * tracker.getString("name").equals("Bugs")) { if
		 * (tracker.has("location")) { BugRepository.Builder bug =
		 * BugRepository.newBuilder();
		 * bug.setUrl(tracker.getString("location")); bugs.add(bug.build()); }
		 * break; } } } if (!bugs.isEmpty())
		 * project.addAllBugRepositories(bugs); }
		 */
    if (jsonProject.has(GIT_GIT_REPO)) {
        this.gitRepository = jsonProject.getString(GIT_GIT_REPO);
    }
    return true;
}
Also used : JSONObject(net.sf.json.JSONObject) BufferedInputStream(java.io.BufferedInputStream) JSONException(net.sf.json.JSONException) FileInputStream(java.io.FileInputStream) ParseException(java.text.ParseException) JSONException(net.sf.json.JSONException)

Example 78 with JSONObject

use of net.sf.json.JSONObject in project FilmGoGo by cajet.

the class MovieRequest method getMovies.

@RequestMapping("/{cid}")
void getMovies(@PathVariable int cid, HttpServletResponse response) throws IOException {
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();
    JSONObject res = new JSONObject();
    res.put("movies", md.getMoviesViaCid(cid));
    out.print(res.toString());
    out.flush();
    out.close();
}
Also used : JSONObject(net.sf.json.JSONObject) PrintWriter(java.io.PrintWriter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 79 with JSONObject

use of net.sf.json.JSONObject in project FilmGoGo by cajet.

the class ShowtimeRequest method getShowtime.

@RequestMapping("/{cid}/{mid}")
void getShowtime(@PathVariable("cid") int cid, @PathVariable("mid") int mid, HttpServletResponse response) throws IOException {
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();
    JSONObject res = new JSONObject();
    res.put("showtimes", sd.getShowtimes(cid, mid));
    out.print(res.toString());
    out.flush();
    out.close();
}
Also used : JSONObject(net.sf.json.JSONObject) PrintWriter(java.io.PrintWriter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 80 with JSONObject

use of net.sf.json.JSONObject in project FilmGoGo by cajet.

the class CinemaRequest method getCinemas.

@RequestMapping("/{mid}")
void getCinemas(@PathVariable int mid, HttpServletResponse response) throws IOException {
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();
    JSONObject res = new JSONObject();
    res.put("cinemas", cd.getCinemasViaMid(mid));
    out.print(res.toString());
    out.flush();
    out.close();
}
Also used : JSONObject(net.sf.json.JSONObject) PrintWriter(java.io.PrintWriter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JSONObject (net.sf.json.JSONObject)493 Test (org.junit.Test)99 JSONArray (net.sf.json.JSONArray)94 IOException (java.io.IOException)49 HashMap (java.util.HashMap)48 ArrayList (java.util.ArrayList)36 JSON (net.sf.json.JSON)26 PrintWriter (java.io.PrintWriter)25 Map (java.util.Map)23 File (java.io.File)21 InputStream (java.io.InputStream)18 URISyntaxException (java.net.URISyntaxException)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 JsonConfig (net.sf.json.JsonConfig)14 FreeStyleBuild (hudson.model.FreeStyleBuild)13 URI (java.net.URI)13 URL (java.net.URL)13 JSONException (net.sf.json.JSONException)13 Context (org.zaproxy.zap.model.Context)12 Transactional (org.springframework.transaction.annotation.Transactional)11