use of net.sf.json.JSONArray in project compiler by boalang.
the class RepoMetadata method toBoaMetaDataJson.
public JSONObject toBoaMetaDataJson() {
JSONObject jsonRepo = new JSONObject();
jsonRepo.put(ID, id);
jsonRepo.put(NAME, name);
jsonRepo.put(CREATED_TIMESTAMP, created_timestamp);
jsonRepo.put(SUMMARY_PAGE, summaryPage);
jsonRepo.put(HOME_PAGE, homepage);
jsonRepo.put(DESCRIPTION, description);
if (programmingLanguages != null) {
JSONArray langs = new JSONArray();
for (String lang : programmingLanguages) langs.add(lang);
jsonRepo.put(PROGRAMMING_LANGUAGES, langs);
}
if (gitRepository != null) {
JSONObject jsonGit = new JSONObject();
jsonGit.put("location", gitRepository);
jsonRepo.put(GIT_REPO, jsonGit);
}
JSONObject jo = new JSONObject();
jo.put("Project", jsonRepo);
return jo;
}
use of net.sf.json.JSONArray in project compiler by boalang.
the class GetGithubRepoLanguagesMulti method getLanguages.
private static ArrayList<GithubLanguage> getLanguages(String content) {
ArrayList<GithubLanguage> languages = new ArrayList<GithubLanguage>();
JSONArray repos = null;
try {
repos = (JSONArray) JSONSerializer.toJSON(content);
} catch (JSONException e) {
}
if (repos == null) {
System.err.println("Error parsing file\n" + content);
return languages;
}
int status = 0, s = 0;
String name = null, count;
for (int i = 0; i < content.length(); i++) {
if (status == 0 && content.charAt(i) == '\"') {
status = 1;
s = i + 1;
} else if (status == 1 && content.charAt(i) == '\"') {
status = 2;
name = content.substring(s, i);
} else if (status == 2 && content.charAt(i) == ':') {
status = 3;
s = i + 1;
} else if (status == 3 && !Character.isDigit(content.charAt(i))) {
status = 0;
count = content.substring(s, i);
languages.add(new GithubLanguage(name, count));
}
}
return languages;
}
use of net.sf.json.JSONArray in project FilmGoGo by cajet.
the class ReaddataFromAPI method main.
public static void main(String[] args) {
initTable();
/*------------------------获取正在上映的电影列表的API,插入电影数据-----------------------*/
String url_movie = "http://m.maoyan.com/movie/list.json";
String json_movie = loadJson(url_movie);
JSONObject jsonObject = JSONObject.fromObject(json_movie);
JSONArray array = jsonObject.getJSONObject("data").getJSONArray("movies");
String insert_movie;
JSONObject subObject;
for (int i = 0; i < array.size(); i++) {
subObject = array.getJSONObject(i);
insert_movie = "insert into movie(name, type, description, image, apiid) values('" + subObject.get("nm") + "','" + subObject.get("cat") + "','" + subObject.get("scm") + "','" + subObject.get("img") + "','" + subObject.get("id") + "');";
loadDatatoDB(insert_movie);
}
/*------------------------获取正在上映的电影简介的API,插入电影简介数据-----------------------*/
String find_movies_id = "select * from movie";
try {
con = DriverManager.getConnection(dburl, user, pass);
con.setAutoCommit(false);
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(find_movies_id);
while (rs.next()) {
String url_description = "http://m.maoyan.com/movie/" + rs.getString(5) + ".json";
String json_description = loadJson(url_description);
jsonObject = JSONObject.fromObject(json_description);
String temp = (String) jsonObject.getJSONObject("data").getJSONObject("MovieDetailModel").get("dra");
//System.out.println(temp);
String insert_description = "update movie set description = ? where apiid= ?";
PreparedStatement pst = con.prepareStatement(insert_description);
pst.setString(1, temp);
pst.setString(2, rs.getString(5));
pst.executeUpdate();
con.commit();
}
} catch (Exception e) {
System.out.println(e);
}
/*------------------------获取获取周边影院的API,插入影院数据-----------------------*/
String url_cinema = "http://m.maoyan.com/cinemas.json";
String json_cinema = loadJson(url_cinema);
JSONObject jsonObject2 = JSONObject.fromObject(json_cinema);
JSONArray array2 = jsonObject2.getJSONObject("data").getJSONArray("番禺区");
String insert_cinema;
JSONObject subObject2;
for (int i = 0; i < array2.size(); i++) {
subObject2 = array2.getJSONObject(i);
insert_cinema = "insert into cinema(name, address, city, area, apiid) values('" + subObject2.get("nm") + "','" + subObject2.get("addr") + "','广州','" + subObject2.get("area") + "','" + subObject2.get("id") + "');";
loadDatatoDB(insert_cinema);
}
/*-------------------------获取场次的API,插入showtime数据库-----------------------*/
/*ArrayList<String> movies_array= getMoviesID();
ArrayList<String> cinema_array= getCinemasID();
for (int i= 0; i< movies_array.size(); i++) {
for (int j= 0; j< cinema_array.size(); j++) {
String url_showtime= "http://m.maoyan.com/showtime/wrap.json?cinemaid="+cinema_array.get(j)+"&movieid="+movies_array.get(i);
System.out.println(url_showtime);
String json_showtime= loadJson(url_showtime);
JSONObject jsonObject3= JSONObject.fromObject(json_showtime);
load_showtime_TodayandTomorrow(jsonObject3, movies_array.get(i), cinema_array.get(j));
}
}*/
/*------------------------获取座位情况的API,插入seat数据库--------------------------*/
/*ArrayList<String> showtimes_array= getShowtimeID();
//获取今天和明天的日期
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH)+1;
int day = c.get(Calendar.DAY_OF_MONTH)+1;
int day2= c.get(Calendar.DAY_OF_MONTH);
String day_str= "-"+day;
String day2_str= "-"+day2;
String month_str= "-"+month;
if (month< 10) month_str= "-0"+month;
if (day< 10) day_str= "-0"+day;
if (day2< 10) day2_str= "-0"+day2;
String tomorrow= year+month_str+day_str;
String today= year+month_str+day2_str;
//载入今天的座位
for (int i= 0; i< showtimes_array.size(); i++) {
String url_seat_today= "http://m.maoyan.com/show/seats?showId="+showtimes_array.get(i)+"&showDate="+today;
System.out.println(url_seat_today);
String json_seat= loadJson(url_seat_today);
JSONObject jsonObject4= JSONObject.fromObject(json_seat);
load_seat_TodayandTomorrow(jsonObject4, showtimes_array.get(i));
}
//载入明天的座位
for (int i= 0; i< showtimes_array.size(); i++) {
String url_seat_tomorrow= "http://m.maoyan.com/show/seats?showId="+showtimes_array.get(i)+"&showDate="+tomorrow;
System.out.println(url_seat_tomorrow);
String json_seat= loadJson(url_seat_tomorrow);
JSONObject jsonObject4= JSONObject.fromObject(json_seat);
load_seat_TodayandTomorrow(jsonObject4, showtimes_array.get(i));
}
*/
}
use of net.sf.json.JSONArray in project xwiki-platform by xwiki.
the class ExtensionPingDataProviderTest method provideData.
@Test
public void provideData() throws Exception {
ExtensionId extensionId = new ExtensionId("extensionid", "1.0");
InstalledExtension extension = mock(InstalledExtension.class);
when(extension.getId()).thenReturn(extensionId);
when(extension.getFeatures()).thenReturn(Arrays.asList("feature1", "feature2"));
InstalledExtensionRepository repository = this.mocker.getInstance(InstalledExtensionRepository.class);
when(repository.getInstalledExtensions()).thenReturn(Collections.singletonList(extension));
Map<String, Object> data = this.mocker.getComponentUnderTest().provideData();
assertEquals(1, data.size());
JSONObject[] extensions = (JSONObject[]) data.get("extensions");
assertEquals(1, extensions.length);
JSONObject propertiesData = extensions[0];
assertEquals(3, propertiesData.size());
assertEquals("extensionid", propertiesData.get("id"));
assertEquals("1.0", propertiesData.get("version"));
JSONArray features = (JSONArray) propertiesData.get("features");
assertEquals(2, features.size());
assertEquals("feature1", features.get(0));
assertEquals("feature2", features.get(1));
}
use of net.sf.json.JSONArray in project jaffa-framework by jaffa-projects.
the class DomainModelDocService method createTree.
/**
* @return JSONArray.
*/
private JSONArray createTree() {
JSONArray array = new JSONArray();
Map<String, TreeNode> rootNodeCache = new HashMap<String, TreeNode>();
Map<String, TreeNode> child1NodeCache = new HashMap<String, TreeNode>();
try {
Properties props = new Properties();
String[] classNames = RulesEngineFactory.getRulesEngine().getClassNamesByRuleName("domain-info");
if (classNames != null) {
for (String className : classNames) {
IObjectRuleIntrospector introspector = RulesEngineFactory.getRulesEngine().getObjectRuleIntrospector(className, null);
List<Properties> propList = introspector.getMetaDataByRule("domain-info");
for (Properties p : propList) {
if (p != null && p.size() > 0) {
StringBuilder sb = new StringBuilder();
String module = (String) p.get("module");
String subModule = (String) p.get("sub-module");
String domainName = (String) p.get("name");
String dbTable = (String) p.get("db-table");
if ((module != null && subModule != null) && (!"null".equals(module) && !"null".equals(subModule))) {
sb.append(module).append(".").append(subModule).append(".").append(domainName);
if (!props.containsKey(sb.toString())) {
if (dbTable != null && !"null".equals(dbTable)) {
StringBuilder value = new StringBuilder();
value.append(className).append("~").append(dbTable);
props.put(sb.toString(), value.toString());
} else {
props.put(sb.toString(), className);
}
}
}
if (log.isDebugEnabled()) {
log.debug("key :" + sb.toString());
log.debug("className :" + className);
}
}
}
}
}
Enumeration<String> enumeration = (Enumeration<String>) props.propertyNames();
int rootNodeCounter = 1;
TreeNode globalRoot = new TreeNode(0, "API Documentation");
globalRoot.setLeaf(false);
globalRoot.setIconCls("icon-docs");
while (enumeration.hasMoreElements()) {
String serviceName = enumeration.nextElement();
String[] treeNodeName = serviceName.split("\\.");
TreeNode root = null;
TreeNode child1 = null;
boolean hasRoot = false;
for (int i = 0; i < treeNodeName.length; i++) {
boolean hasChild1 = false;
if (i == 0) {
if (!rootNodeCache.containsKey(treeNodeName[i])) {
root = new TreeNode(rootNodeCounter, treeNodeName[i]);
root.setLeaf(false);
root.setIconCls("icon-pkg");
rootNodeCache.put(treeNodeName[i], root);
} else {
root = rootNodeCache.get(treeNodeName[i]);
hasRoot = true;
}
} else if (i == 1) {
if (!child1NodeCache.containsKey(treeNodeName[i - 1] + treeNodeName[i])) {
child1 = new TreeNode(Integer.parseInt(rootNodeCounter + "" + i), treeNodeName[i]);
child1.setLeaf(false);
child1.setIconCls("icon-pkg");
child1NodeCache.put(treeNodeName[i - 1] + treeNodeName[i], child1);
} else {
child1 = child1NodeCache.get(treeNodeName[i - 1] + treeNodeName[i]);
root.setIconCls("icon-pkg");
hasChild1 = true;
}
if (!hasChild1) {
root.addChild(child1);
}
} else if (i == 2) {
String[] nodeAtt = props.getProperty(serviceName).split("~");
String className = nodeAtt.length > 0 ? nodeAtt[0] : null;
String dbTable = nodeAtt.length > 1 ? nodeAtt[1] : null;
TreeNode child2 = new TreeNode(Integer.parseInt(rootNodeCounter + "" + i), treeNodeName[i]);
child2.setLeaf(true);
child2.setIconCls("icon-cls");
child2.setIsClass(true);
child2.setClassName(className);
child2.setServiceName(serviceName);
child2.setDbTableName(dbTable);
if (child1 != null) {
child1.addChild(child2);
}
}
}
if (!hasRoot) {
globalRoot.addChild(root);
}
rootNodeCounter++;
}
array.add(globalRoot.toJson());
} catch (RulesEngineException ex) {
log.error(ex);
ex.printStackTrace(System.out);
}
return array;
}
Aggregations