Пример #1
0
  /**
   * @param jsontxt
   * @return Autor[] - Extract autorun entries from Json representation.
   */
  public static Autorun[] extractAutorun(String jsontxt) {

    JSONObject jsonAutorunlist = (JSONObject) JSONSerializer.toJSON(jsontxt);
    // JSONObject Offline = json.getJSONObject("hooked-browsers").getJSONObject("offline");
    Autorun Autorunlist[] = new Autorun[jsonAutorunlist.size()];
    if (jsonAutorunlist.isEmpty()) {
      System.out.println("No Autorun, may be list is empty !");
    } else {
      for (int i = 0; i < jsonAutorunlist.size(); i++) {

        try {
          Autorun Autor = new Autorun();
          JSONObject Autorid = jsonAutorunlist.getJSONObject("" + i);
          Autor.setId(Autorid.getString("id"));
          Autor.setName(Autorid.getString("name"));
          Autor.setCc(Autorid.getString("cc"));
          Autor.setBrowser(Autorid.getString("browser"));
          Autor.setParam(Autorid.getString("Param"));
          Autor.setCategory(Autorid.getString("category"));
          Autorunlist[i] = Autor;
        } catch (JSONException e) {
          System.out.println("ERROR: " + e);
        }
      }
    }
    return Autorunlist;
  }
 public static void destroyedSession(String siteSessionId) {
   synchronized ("") {
     // 获取siteSession
     MemcachedCli cli = MemcachedCli.getInstance();
     Object memCachedJsonData = cli.get(CACHED_KEY_SESSION_SITE + siteSessionId);
     JSONObject jsonData =
         JSONObject.fromObject(memCachedJsonData == null ? "{}" : memCachedJsonData);
     int size = jsonData.size();
     if (size == 0) {
       return;
     }
     String chchedSite = jsonData.getString("site");
     // 获取SESSION_ID
     memCachedJsonData = cli.get(CACHED_KEY_SESSION_ID + jsonData.getString("sessionId"));
     jsonData = JSONObject.fromObject(memCachedJsonData == null ? "{}" : memCachedJsonData);
     size = jsonData.size();
     if (size == 0) {
       return;
     }
     String[] sites = jsonData.getString("site").split(",");
     StringBuffer siteSb = new StringBuffer();
     // 清除SESSION_ID里面的site
     for (String site : sites) {
       if (!chchedSite.equals(site)) {
         siteSb.append(site).append(",");
       }
     }
     if (siteSb.length() > 0) {
       siteSb.delete(siteSb.length() - 1, siteSb.length());
     }
     if (siteSb.length() != 0) {
       LOGGER.info("删除 SESSION_ID site=" + chchedSite);
       jsonData.put("site", siteSb.toString());
       updateUserToSession(jsonData);
       cli.delete(CACHED_KEY_SESSION_SITE + siteSessionId);
     } else {
       LOGGER.info(
           "清除 CACHED_KEY_SESSION_ID and CACHED_KEY_SESSION_SITE "
               + jsonData.getString("sessionId")
               + "  "
               + siteSessionId);
       cli.delete(CACHED_KEY_SESSION_ID + jsonData.getString("sessionId"));
       cli.delete(CACHED_KEY_SESSION_SITE + siteSessionId);
     }
   }
 }
  public void testReadObject() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JsonLibModule());

    JSONObject ob =
        mapper.readValue(
            "{\"a\":{\"b\":3}, \"c\":[9, -4], \"d\":null, \"e\":true}", JSONObject.class);
    assertEquals(4, ob.size());
    JSONObject ob2 = ob.getJSONObject("a");
    assertEquals(1, ob2.size());
    assertEquals(3, ob2.getInt("b"));
    JSONArray array = ob.getJSONArray("c");
    assertEquals(2, array.size());
    assertEquals(9, array.getInt(0));
    assertEquals(-4, array.getInt(1));
    assertTrue(JSONUtils.isNull(ob.get("d")));
    assertTrue(ob.getBoolean("e"));
  }
Пример #4
0
  @Test
  public void getList() {
    long start = System.currentTimeMillis();

    for (int i = 0; i < json.size(); i++) {
      json.get(String.valueOf(i));
    }

    long end = System.currentTimeMillis();
    long result = end - start;
    System.out.println("JSON:GET) " + result + "_" + result / 1000);
  }
 private static String checkUser(String sessionId, String site) {
   synchronized ("") {
     MemcachedCli cli = MemcachedCli.getInstance();
     Object memCachedJsonData = cli.get(CACHED_KEY_SESSION_ID + sessionId);
     JSONObject jsonData =
         JSONObject.fromObject(memCachedJsonData == null ? "{}" : memCachedJsonData);
     int size = jsonData.size();
     if (size == 0) {
       jsonData.accumulate("exist", "false");
     } else {
       jsonData.accumulate("exist", "true");
     }
     return jsonData.toString();
   }
 }
  public void testReadArray() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JsonLibModule());

    JSONArray array =
        mapper.readValue("[null, 13, false, 1.25, \"abc\", {\"a\":13}, [ ] ]", JSONArray.class);
    assertEquals(7, array.size());
    assertTrue(JSONUtils.isNull(array.get(0)));
    assertEquals(13, array.getInt(1));
    assertFalse(array.getBoolean(2));
    assertEquals(Double.valueOf(1.25), array.getDouble(3));
    assertEquals("abc", array.getString(4));
    JSONObject ob = array.getJSONObject(5);
    assertEquals(1, ob.size());
    assertEquals(13, ob.getInt("a"));
    JSONArray array2 = array.getJSONArray(6);
    assertEquals(0, array2.size());
  }
 /** 缓存session 和登录用户信息绑定一起 */
 public static void addUserToSession(JSONObject json) {
   synchronized ("") {
     MemcachedCli cli = MemcachedCli.getInstance();
     Object memCachedJsonData = cli.get(CACHED_KEY_SESSION_ID + json.getString("sessionId"));
     JSONObject jsonData =
         JSONObject.fromObject(memCachedJsonData == null ? "{}" : memCachedJsonData);
     int size = jsonData.size();
     if (size == 0) {
       jsonData.accumulate("site", json.getString("site"));
     } else {
       // 判断当前登录站点
       if (jsonData.getString("site").indexOf(json.getString("site")) == -1) {
         String site = jsonData.getString("site") + "," + json.getString("site");
         jsonData.remove("site");
         jsonData.accumulate("site", site);
       }
     }
     jsonData.put("name", json.getString("name"));
     jsonData.put("passwd", json.getString("passwd"));
     jsonData.put("sessionId", json.getString("sessionId"));
     jsonData.put("lastTime", json.getString("lastTime"));
     cli.set(
         CACHED_KEY_SESSION_ID + json.getString("sessionId"),
         jsonData.toString(),
         new java.util.Date(System.currentTimeMillis() + 60 * 1000 * 120));
     // ------------------------------------------------------------
     Map<String, String> map = new HashMap<String, String>();
     map.put("sessionId", json.getString("sessionId"));
     map.put("siteSessionId", json.getString("siteSessionId"));
     map.put("site", json.getString("site"));
     cli.set(
         CACHED_KEY_SESSION_SITE + json.getString("siteSessionId"),
         JSONObject.fromObject(map).toString(),
         new java.util.Date(System.currentTimeMillis() + 60 * 1000 * 120));
     // ------------------------------------------------------------
   }
 }
	/**
	 * 
	 * @param sportsid
	 * @param sportname
	 * @param departname
	 * @param province
	 * @param itemtype
	 * @param item
	 * @param score1
	 * @param score2
	 * @param breakrecord
	 * @return	
	 * @throws SQLException
	 */
public JSONArray selectInQuestion(int sportsid,String playername,int departname,
		int province,String itemtype,int item,String score1,String score2,String breakrecord){
	Logger log = Logger.getLogger(GameQuerySelectInfDAO.class.getName());
	
	JSONArray jsonarray = new JSONArray();
	StringBuffer selectInf = new StringBuffer();
	/**
	 * if(breakrecord.equals("0")&&0 == item)判断前台页面单选框选择条件如果未选择项目和破纪录情况执行此语句
	 * */
	if( breakrecord.equals("0")&&0 == item && itemtype.equals("0")){
		selectInf.append(" SELECT  DISTINCT t_player.playername,t_player.playernum,t_group.groupname,t_department.departname"+
" FROM t_position"+ 
" JOIN t_player ON t_player.id = t_position.playerid"+
                " JOIN t_group ON t_player.groupid = t_group.id"+
                " JOIN t_sports2department ON t_player.sp2dpid = t_sports2department.id"+
                " JOIN t_department ON t_sports2department.departid = t_department.id"+
                " JOIN t_sports ON t_sports2department.sportsid = t_sports.id"+
                " JOIN t_finalitem ON t_finalitem.id = t_position.finalitemid"+
                " JOIN t_group2item ON t_finalitem.gp2itid = t_group2item.id"+
                " JOIN t_item ON t_group2item.itemid = t_item.id"+
		 " WHERE ");
		if(0 != sportsid){
			selectInf.append(" t_sports.id = "+ sportsid +" ");
		}
		if(!playername.equals("")){
			selectInf.append("and t_player.playername = '"+ playername +"' ");
		}
		if(0 != departname){
			selectInf.append("and t_department.id = "+ departname +" ");
		}
		if(0 != province){
			selectInf.append("and t_group.id = "+ province +" ");
		}
		if(!itemtype.equals("0")){
			selectInf.append("and itemtype = '"+ itemtype +"' ");
		}
		if(0 != item){
			selectInf.append("and t_item.id ="+ item +" ");
		}
		if(!score1.equals("") && !score2.equals("")){
			selectInf.append("and t_position.score >"+ score1 +" and t_position.score <"+score2+" ");

		}
		selectInf.append(";");
	String sql = selectInf.toString();
	QueryRegistitemToItems qrti = new QueryRegistitemToItems();
	log.debug(sql);
	conn = db.getConn();
	try{
		stmt = conn.createStatement();
		rs = stmt.executeQuery(sql);
		while( rs.next()){
			JSONObject jsonobj = new JSONObject();
			jsonobj.put("playername", rs.getString(1));
			jsonobj.put("playernum", rs.getString(2));
			jsonobj.put("groupname", rs.getString(3));
			jsonobj.put("departshortname", rs.getString(4));
			jsonobj.put("itemname", qrti.getItems(rs.getString(2)));
			jsonobj.put("score", qrti.getScores(rs.getString(2)));
			jsonobj.put("position", qrti.getPosition(rs.getString(2)));
			jsonobj.put("recordlevel",qrti.getRecordlevel(rs.getString(2)));
			jsonarray.add(jsonobj);
		}
		rs.close();
		stmt.close();
		db.freeConnection(conn);
	}catch( Exception e){
		e.getStackTrace();
	}
}else if(breakrecord.equals("1")){                      //如果选择了破纪录执行此语句
	selectInf.append("SELECT DISTINCT t_record.playername,t_player.playernum,t_group.groupname," +
			"t_record.departname,t_item.itemname,t_record.score,t_position.position,recordlevel,t_item.itemtype" +
			" FROM  t_record " +
			" JOIN t_item ON t_record.itemid = t_item.id" +
			" JOIN t_player ON  t_record.playername = t_player.playername" +
			" JOIN t_group ON (t_record.playername = t_player.playername AND t_player.groupid = t_group.id)" +
			" JOIN t_position ON (t_record.playername = t_player.playername AND t_player.id = t_position.playerid)" +
			" JOIN t_department ON t_department.departname = t_record.departname" +
			" JOIN t_sports ON t_sports.sportsname = t_record.sportsname " +
			" WHERE ");
	if(0 != sportsid){
		selectInf.append(" t_sports.id = "+ sportsid +" ");
	}
	if(!playername.equals("")){
		selectInf.append("and t_record.playername = '"+ playername +"' ");
	}
	if(0 != departname){
		selectInf.append("and t_department.id = "+ departname +" ");
	}
	if(0 != province){
		selectInf.append("and t_group.id = "+ province +" ");
	}
	if(!itemtype.equals("0")){
		selectInf.append("and itemtype = '"+ itemtype +"' ");
	}
	if(0 != item){
		selectInf.append("and t_record.itemid ="+ item +" ");
	}
	if(!score1.equals("") && !score2.equals("")){
		selectInf.append("and t_record.score >"+ score1 +" and t_record.score <"+score2+" ");

	}
	selectInf.append("and t_record.score = t_position.score");
	String sql = selectInf.toString();
	QueryRegistitemToItems qrti = new QueryRegistitemToItems();
	log.debug(sql);
	conn = db.getConn();
	try{
		stmt = conn.createStatement();
		rs = stmt.executeQuery(sql);
		UtilTools ut = new UtilTools();
		while( rs.next()){
			JSONObject jsonobj = new JSONObject();
			jsonobj.put("playername", rs.getString(1));
			jsonobj.put("playernum", rs.getString(2));
			jsonobj.put("groupname", rs.getString(3));
			jsonobj.put("departshortname", rs.getString(4));
			jsonobj.put("itemname", rs.getString(5));
			jsonobj.put("score", ut.coverToTrackScore(rs.getString(6), rs.getString(9)));
			jsonobj.put("position", rs.getString(7));
			String rec=null;
			if(rs.getString(8).equals("")){
				rec = "无";
			}else if(rs.getString(8).equals("0")){
				rec = "<font color='red'>院</font>";
			}else if(rs.getString(8).equals("1")){
				rec = "<font color='blue'>省</font>";
			}
			jsonobj.put("recordlevel",rec);
			jsonarray.add(jsonobj);
		}
		rs.close();
		stmt.close();
		db.freeConnection(conn);
	}catch( Exception e){
		e.getStackTrace();
	}
	}else if(breakrecord.equals("0")&&0 != item ||breakrecord.equals("0")&&!itemtype.equals("0")){//如果未选中破纪录选择了项目名称
		if(itemtype.equals("3")){
			//项目类型为接力的成绩
			selectInf.append("SELECT DISTINCT t_department.departshortname,t_finalitem.finalitemname,t_position.score,t_position.position,t_match.recordlevel,t_item.itemtype" +
					" FROM t_position" +
					" JOIN t_player ON t_position.playerid = t_player.id" +
					" JOIN t_group ON t_group.id = t_player.groupid" +
					" JOIN t_sports2department ON t_player.sp2dpid = t_sports2department.id" +
					" JOIN t_sports ON t_sports2department.sportsid = t_sports.id" +
					" JOIN t_department ON t_sports2department.departid = t_department.id" +
					" JOIN t_finalitem ON t_position.finalitemid = t_finalitem.id" +
					" JOIN t_group2item ON t_finalitem.gp2itid = t_group2item.id" +
					" JOIN t_match ON t_finalitem.id = t_match.finalitemid"+
					" JOIN t_item ON t_group2item.itemid = t_item.id"+
					" WHERE");
		}else{
		selectInf.append("SELECT DISTINCT t_player.playername,t_player.playernum,groupname,t_department.departshortname,t_finalitem.finalitemname,t_item.itemtype"+
				 " FROM t_position"+
				 " JOIN t_player ON t_position.playerid = t_player.id"+
				 " JOIN t_group ON t_group.id = t_player.groupid"+
				 " JOIN t_sports2department ON t_player.sp2dpid = t_sports2department.id"+
				 " JOIN t_sports ON t_sports2department.sportsid = t_sports.id"+
				 " JOIN t_department ON t_sports2department.departid = t_department.id"+
				 " JOIN t_finalitem ON t_position.finalitemid = t_finalitem.id"+
				 " JOIN t_group2item ON t_finalitem.gp2itid = t_group2item.id"+
				 " JOIN t_item ON t_group2item.itemid = t_item.id"+
				" WHERE");
		}
		if(0 != sportsid){
			selectInf.append(" t_sports.id = "+ sportsid +" ");
		}
		if(!playername.equals("")){
			selectInf.append("and t_player.playername = '"+ playername +"' ");
		}
		if(0 != departname){
			selectInf.append("and t_department.id = "+ departname +" ");
		}
		if(0 != province){
			selectInf.append("and t_group.id = "+ province +" ");
		}
		if(!itemtype.equals("0")){
			selectInf.append("and itemtype = '"+ itemtype +"' ");
		}
		if(0 != item){
			selectInf.append("and t_item.id ="+ item +" ");
		}
		if(!score1.equals("") && !score2.equals("")){
			selectInf.append(" and t_position.score >"+ score1 +" and t_position.score <"+score2+" ");
		}
		selectInf.append(";");
	String sql = selectInf.toString();
		conn = db.getConn();
	QueryRegistitemToItems qrti = new QueryRegistitemToItems();
	log.debug(sql);
	UtilTools ut = new UtilTools();
	try{
		stmt = conn.createStatement();
		rs = stmt.executeQuery(sql);
		if(itemtype.equals("3")){
			while(rs.next()){
				JSONObject jsonobj = new JSONObject();
				jsonobj.put("size", 5);
				jsonobj.put("departshortname", rs.getString(1));
				jsonobj.put("finalitemname", rs.getString(2));
				log.debug("接力的成绩查询:"+ut.coverToTrackScore(rs.getString(3), rs.getString(6)));
				jsonobj.put("score", ut.coverToTrackScore(rs.getString(3), rs.getString(6)));
				jsonobj.put("position", rs.getString(4));
				String rec = "";
				if(rs.getString(5).equals("2")){
					rec = "无";
				}else if(rs.getString(5).equals("0")){
					rec = "<font color='red'>院</font>";
				}else if(rs.getString(5).equals("1")){
					rec = "<font color='blue'>省</font>";
				}
				jsonobj.put("recordlevel",rec);//有无破纪录t_match表中的t_sport.id查询出recordlevel。
				log.debug(jsonobj.size());
				jsonarray.add(jsonobj);
			}
		}else{
		while( rs.next()){
			JSONObject jsonobj = new JSONObject();
			jsonobj.put("size", 7);
			jsonobj.put("playername", rs.getString(1));
			jsonobj.put("playernum", rs.getString(2));
			jsonobj.put("groupname", rs.getString(3));
			jsonobj.put("departshortname", rs.getString(4));
			jsonobj.put("itemname", qrti.getItem(rs.getString(2), rs.getString(5)));
			jsonobj.put("score", qrti.getScore(rs.getString(2),rs.getString(5)));
			jsonobj.put("position", qrti.getPosition1(rs.getString(2),rs.getString(5)));
			jsonobj.put("recordlevel",qrti.getRecordlevel2(rs.getString(2), rs.getString(5)));
			jsonarray.add(jsonobj);
		}
		}
		rs.close();
		stmt.close();
		db.freeConnection(conn);
	}catch( Exception e){
		e.getStackTrace();
		}
}
	return jsonarray;
}
Пример #9
0
 public void testJSONLeaseFields() {
   WorkspaceList.Lease dummyLease =
       WorkspaceList.Lease.createDummyLease(new FilePath(new File(".")));
   JSONObject json = JSONObject.fromObject(dummyLease);
   assertEquals(json.size(), 1);
 }