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());
}
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;
}
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();
}
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();
}
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();
}
Aggregations