Java Code Examples for net.sf.json.JSONArray#toString()

The following examples show how to use net.sf.json.JSONArray#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeoServerListStylesCommand.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public String computeResults(final OperationParams params) throws Exception {
  final Response listStylesResponse = geoserverClient.getStyles();

  if (listStylesResponse.getStatus() == Status.OK.getStatusCode()) {
    final JSONObject jsonResponse = JSONObject.fromObject(listStylesResponse.getEntity());
    final JSONArray styles = jsonResponse.getJSONArray("styles");
    return "\nGeoServer styles list: " + styles.toString(2);
  }
  final String errorMessage =
      "Error getting GeoServer styles list: "
          + listStylesResponse.readEntity(String.class)
          + "\nGeoServer Response Code = "
          + listStylesResponse.getStatus();
  return handleError(listStylesResponse, errorMessage);
}
 
Example 2
Source File: ConceptMapping.java    From Criteria2Query with Apache License 2.0 5 votes vote down vote up
public static String generateConceptSetByConcepts(List<Concept> concepts){
	//type 1 concept 1  VS. concept 1 and concept 2
	//[{"conceptId":201826,"isExcluded":0,"includeDescendants":1,"includeMapped":1},{"conceptId":316866,"isExcluded":0,"includeDescendants":1,"includeMapped":1}]
	JSONArray conceptSet=new JSONArray();
	for(Concept c:concepts){
		JSONObject jo=formatOneitem(c.getCONCEPT_ID());
		conceptSet.add(jo);		
	}
	//System.out.println("conceptSet="+conceptSet.toString());	
	return conceptSet.toString();
}
 
Example 3
Source File: PipelineActivityStatePreloader.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
    BluePipeline pipeline = getPipeline(blueUrl);

    if (pipeline != null) {
        // It's a pipeline page. Let's prefetch the pipeline activity and add them to the page,
        // saving the frontend the overhead of requesting them.

        Container<BlueRun> activitiesContainer = pipeline.getRuns();
        if(activitiesContainer==null){
            return null;
        }
        Iterator<BlueRun> activitiesIterator = activitiesContainer.iterator(0, DEFAULT_LIMIT);
        JSONArray activities = new JSONArray();

        while(activitiesIterator.hasNext()) {
            Resource blueActivity = activitiesIterator.next();
            try {
                activities.add(JSONObject.fromObject(Export.toJson(blueActivity)));
            } catch (IOException e) {
                LOGGER.log(Level.FINE, String.format("Unable to preload runs for Job '%s'. Activity serialization error.", pipeline.getFullName()), e);
                return null;
            }
        }

        return new FetchData(
            activitiesContainer.getLink().getHref() + "?start=0&limit=" + DEFAULT_LIMIT,
            activities.toString());
    }

    // Don't preload any data on the page.
    return null;
}
 
Example 4
Source File: BookAction.java    From sdudoc with MIT License 5 votes vote down vote up
@Action("checkStyle")
public String checkStyle(){
	styleList=bookService.checkStyle();
	JSONArray jsonArray = JSONArray.fromObject(styleList);
	//ajax返回客户端
	jsonArray.toString();
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/html;charset=UTF-8");
	try {
		response.getWriter().write(jsonArray.toString());
	} catch (IOException e) {
		e.printStackTrace();
	} 
	return null;
}
 
Example 5
Source File: FavoritesStatePreloader.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
    User jenkinsUser = User.current();
    if (jenkinsUser != null) {
        BlueOrganization organization = Iterables.getFirst(OrganizationFactory.getInstance().list(), null);
        if (organization != null) {
            String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);

            // don't need this list when at pipeline pages
            if (pipelineFullName != null) {
                return null;
            }

            UserImpl blueUser = new UserImpl(organization, jenkinsUser, organization.getUsers());
            BlueFavoriteContainer favoritesContainer = blueUser.getFavorites();

            if (favoritesContainer != null) {
                JSONArray favorites = new JSONArray();
                // Limit the number of favorites to return to a sane amount
                Iterator<BlueFavorite> favoritesIterator = favoritesContainer.iterator(0, DEFAULT_LIMIT);

                while (favoritesIterator.hasNext()) {
                    Reachable favorite = favoritesIterator.next();
                    try {
                        favorites.add(JSONObject.fromObject(Export.toJson(favorite)));
                    } catch (IOException e) {
                        LOGGER.log(Level.FINE, String.format("Unable to preload favorites for User '%s'. Serialization error.", jenkinsUser.getFullName()), e);
                        return null;
                    }
                }

                return new FetchData(favoritesContainer.getLink().getHref() + "?start=0&limit=" + DEFAULT_LIMIT, favorites.toString());
            }
        }
    }

    // Don't preload any data on the page.
    return null;
}
 
Example 6
Source File: AppController.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
/**
 * AppCommandGroup列表组装成json串
 */
private String assembleGroupJson(List<AppCommandGroup> appCommandGroupList) {
    if (appCommandGroupList == null || appCommandGroupList.isEmpty()) {
        return "[]";
    }
    List<SimpleChartData> list = new ArrayList<SimpleChartData>();
    for (AppCommandGroup appCommandGroup : appCommandGroupList) {
        SimpleChartData chartData = SimpleChartData
                .getFromAppCommandGroup(appCommandGroup);
        list.add(chartData);
    }
    JSONArray jsonArray = JSONArray.fromObject(list);
    return jsonArray.toString();
}
 
Example 7
Source File: MenuManagerController.java    From jeewx with Apache License 2.0 5 votes vote down vote up
@RequestMapping(params = "getSubMenu")
public void getSubMenu(HttpServletRequest request,
		HttpServletResponse response) {
	String accountid = ResourceUtil.getWeiXinAccountId();
	String msgType = request.getParameter("msgType");
	String resMsg = "";
	 JsonConfig config = new JsonConfig();
	 config.setJsonPropertyFilter(new PropertyFilter(){  
		    public boolean apply(Object source, String name, Object value) {  
		        if(name.equals("menuList")) { //要过滤的areas ,Map对象中的  
		            return true;  
		        } else {  
		            return false;  
		        }  
		    }  
		});
		List<MenuEntity> textList = this.weixinMenuService
				.findByQueryString("from MenuEntity t  where t.accountId = '"
						+  accountid+ "'");
		JSONArray json = JSONArray.fromObject(textList,config);
		resMsg = json.toString();

	try {
		response.setCharacterEncoding("utf-8");
		PrintWriter writer = response.getWriter();
		writer.write(resMsg);
		writer.flush();
		writer.close();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
Example 8
Source File: SQLinjectionByCrawler.java    From TrackRay with GNU General Public License v3.0 5 votes vote down vote up
private void dataScan(){
    JSONObject json = toJSON(get(server + "scan/" + taskid + "/data").body());
    if (json.containsKey("data")){
        JSONArray data = json.getJSONArray("data");
        if(data.size()>0){
            this.result = data.toString();
            log.info("存在注入:"+ this.result);
        }
    }
}
 
Example 9
Source File: GeoServerListCoveragesCommand.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public String computeResults(final OperationParams params) throws Exception {
  if (parameters.size() != 1) {
    throw new ParameterException("Requires argument: <coverage store name>");
  }

  if ((workspace == null) || workspace.isEmpty()) {
    workspace = geoserverClient.getConfig().getWorkspace();
  }

  csName = parameters.get(0);

  final Response getCvgStoreResponse = geoserverClient.getCoverages(workspace, csName);

  if (getCvgStoreResponse.getStatus() == Status.OK.getStatusCode()) {
    final JSONObject jsonResponse = JSONObject.fromObject(getCvgStoreResponse.getEntity());
    final JSONArray cvgArray = jsonResponse.getJSONArray("coverages");
    return "\nGeoServer coverage list for '" + csName + "': " + cvgArray.toString(2);
  }
  final String errorMessage =
      "Error getting GeoServer coverage list for '"
          + csName
          + "': "
          + getCvgStoreResponse.readEntity(String.class)
          + "\nGeoServer Response Code = "
          + getCvgStoreResponse.getStatus();
  return handleError(getCvgStoreResponse, errorMessage);
}
 
Example 10
Source File: SwarmNode.java    From docker-swarm-plugin with MIT License 5 votes vote down vote up
public String getMemoryUsageJson() {
    final ArrayList<Object> usage = new ArrayList<>();
    usage.add(Arrays.asList("type", "used"));
    usage.add(Arrays.asList("empty", getTotalMemory() - getReservedMemory()));
    usage.add(Arrays.asList("reserved", getReservedMemory()));
    final JSONArray mJSONArray = new JSONArray();
    mJSONArray.addAll(usage);
    return mJSONArray.toString();
}
 
Example 11
Source File: SwarmNode.java    From docker-swarm-plugin with MIT License 5 votes vote down vote up
public String getCpuUsageJson() {
    final ArrayList<Object> usage = new ArrayList<>();
    usage.add(Arrays.asList("type", "used"));
    usage.add(Arrays.asList("empty", getTotalCPUs() - getReservedCPUs()));
    usage.add(Arrays.asList("reserved", getReservedCPUs()));
    final JSONArray mJSONArray = new JSONArray();
    mJSONArray.addAll(usage);
    return mJSONArray.toString();
}
 
Example 12
Source File: SystemUtil.java    From jeewx-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 拼树:
 * @param allList 所有可用的权限
 * @return
 */
public static String listTreeToAuth(List<MenuFunction> allList,String authId) {
    if(allList!=null && allList.size()>0) {
        List<TreeNode> treeList = new ArrayList<TreeNode>();
        for(MenuFunction auth :allList) {
            TreeNode tn = new TreeNode();
            tn.setId(auth.getAuthId());
            String pId = "0";
            if(auth.getParentAuthId()!=null && !auth.getParentAuthId().equals("")){
                pId = auth.getParentAuthId();
            }
            tn.setpId(pId);
            tn.setName(auth.getAuthName());
            if("1".equals(auth.getAuthType())||"Y".equals(auth.getLeafInd())){
            	tn.setOpen(false); //设置所有打开或所有闭关
            }else{
            	tn.setOpen(true); //设置所有打开或所有闭关
            }
            tn.setChecked(false);
            tn.setDoCheck(false);
            tn.setHalfCheck(false);
            tn.setParent(false);
            tn.setChkDisabled(false);
            tn.setNocheck(false);
            //如果分类的ID不为空,并且等于自己,则设置不可选中
if(StringUtils.isNotEmpty(authId)&&auth.getAuthId().equals(authId)){
	tn.setChkDisabled(true);
}
            treeList.add(tn);
        }
        JSONArray jsonArray = JSONArray.fromObject(treeList);
        return jsonArray.toString();
    }
    return "";
}
 
Example 13
Source File: JSONHelper.java    From jeewx-api with Apache License 2.0 4 votes vote down vote up
/***
 * 将List对象序列化为JSON文本
 */
public static <T> String toJSONString(List<T> list) {
	JSONArray jsonArray = JSONArray.fromObject(list);

	return jsonArray.toString();
}
 
Example 14
Source File: JSONHelper.java    From jeewx-api with Apache License 2.0 4 votes vote down vote up
public static String array2json(Object object) {
	JSONArray jsonArray = JSONArray.fromObject(object);
	return jsonArray.toString();
}
 
Example 15
Source File: FormManagePluginController.java    From wangmarket with Apache License 2.0 4 votes vote down vote up
/**
 * 提交反馈信息,只限 post 提交
 * @param id 要删除的输入模型的id,对应 {@link InputModel}.id
 */
@RequestMapping(value="formAdd${url.suffix}", method = RequestMethod.POST)
@ResponseBody
public BaseVO formAdd(HttpServletRequest request, Model model,
		@RequestParam(value = "siteid", required = false , defaultValue="0") int siteid,
		@RequestParam(value = "title", required = false , defaultValue="") String title){
	String ip = IpUtil.getIpAddress(request);
	Frequency frequency = frequencyMap.get(ip);
	int currentTime = DateUtil.timeForUnix10();	//当前10位时间戳
	//今天尚未提交过,那么创建一个记录
	if(frequency == null){
		frequency = new Frequency();
		frequency.setIp(ip);
	}
	
	//判断当前是否允许提交反馈信息,如果不允许,需要记录,并返回不允许的提示。
	if(frequency.getForbidtime() > currentTime){
		//间隔时间太短,不允许提交反馈信息
		frequency.setErrorNumber(frequency.getErrorNumber()+1);
		frequencyMap.put(ip, frequency);	//临时存储,这个存储时间是一天,每天清除一次
		return error("距离上次提交时间太短,等会再试试吧");
	}
	
	/** 下面就是允许提交的逻辑处理了 **/
	frequency.setLasttime(currentTime);	//设置当前为最后一次提交的时间
	frequency.setForbidtime(currentTime + FeedbackTimeInterval);	//设置下次允许提交反馈的时间节点,这个时间节点之前是不允许在此提交的
	frequencyMap.put(ip, frequency);	//临时存储,这个存储时间是一天,每天清除一次
	
	
	title = StringUtil.filterXss(title);
	if(siteid <= 0){
		return error("请传入您的站点id(siteid),不然,怎么知道此反馈表单是属于哪个网站的呢?");
	}
	
	Form form = new Form();
	form.setAddtime(DateUtil.timeForUnix10());
	form.setSiteid(siteid);
	form.setState(Form.STATE_UNREAD);
	form.setTitle(title);
	sqlService.save(form);
	if(form.getId() != null && form.getId() > 0){
		//成功,进而存储具体内容。存储内容时,首先要从提交的数据中,便利出所有表单数据.这里是原始提交的结果,需要进行xss过滤
		Map<String, String[]> params = new HashMap<String, String[]>();
		params.putAll(request.getParameterMap());
		//删除掉siteid、title的参数
		params.remove("siteid");
		if(params.get("title") != null){
			params.remove("title");
		}
		
		JSONArray jsonArray = new JSONArray();	//text文本框所存储的内容
		for (Map.Entry<String, String[]> entry : params.entrySet()) { 
			JSONObject json = new JSONObject();
			JSONArray valueJsonArray = new JSONArray();
			
			for (int i = 0; i < entry.getValue().length; i++) {
				valueJsonArray.add(StringUtil.filterXss(entry.getValue()[i]));
			}
			json.put(StringUtil.filterXss(entry.getKey()), valueJsonArray);
			jsonArray.add(json);
		}
		String text = jsonArray.toString();
		if(text.length() > textMaxLength){
			return error("信息太长,非法提交!");
		}
		
		FormData formData = new FormData();
		formData.setId(form.getId());
		formData.setText(text);
		sqlService.save(formData);
		
		//记录日志
		AliyunLog.addActionLog(form.getId(), "提交表单反馈", form.getTitle());
		
		return success();
	}else{
		return error("保存失败");
	}
	
}
 
Example 16
Source File: JSONHelper.java    From jeewx with Apache License 2.0 4 votes vote down vote up
public static String array2json(Object object) {
	JSONArray jsonArray = JSONArray.fromObject(object);
	return jsonArray.toString();
}
 
Example 17
Source File: TweetServletTwo.java    From mytwitter with Apache License 2.0 4 votes vote down vote up
public String roll(List<Utweets> tweetsList, int uid) {
	JSONArray js = new JSONArray();
	for (Utweets utweets : tweetsList) {

		if (utweets.getTzhuan() > 0) {
			Forwards forward = forwardsDao.getForward(utweets.getTid(), utweets.getTtime());
			int id = forward.getStid();
			Utweets utweet = tweetsDao.getTweetsByTid(id);
			utweets.setUtweets(utweet);
		}

		int tid = utweets.getTid();
		boolean zhuaned = forwardsDao.selForward(uid, tid);
		if (zhuaned == true)
			utweets.setZhuaned(1);
		else
			utweets.setZhuaned(0);

		boolean zaned = likesDao.selLike(uid, tid);
		if (zaned == true)
			utweets.setZaned(1);
		else
			utweets.setZaned(0);

		Timestamp ttime = utweets.getTtime();
		SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
		SimpleDateFormat sdf3 = new SimpleDateFormat("HH:mm");
		Calendar cal = Calendar.getInstance();
		int day = cal.get(Calendar.DATE);
		int month = cal.get(Calendar.MONTH) + 1;
		int year = cal.get(Calendar.YEAR);

		String nowyear = year + "-01-01 00:00:00";
		Timestamp yeardate = Timestamp.valueOf(nowyear);

		String nowday = year + "-" + month + "-" + day + " 00:00:00";
		Timestamp date = Timestamp.valueOf(nowday);
		// 此处转换为毫秒数
		long millionSeconds = ttime.getTime();// 毫秒
		long nowSeconds = System.currentTimeMillis();
		long chazhi = nowSeconds - millionSeconds;

		if (chazhi < 60000) {
			utweets.setTime("现在");
		} else if (chazhi < 3600000) {
			long n = chazhi / 60000;
			utweets.setTime(n + "分钟");
		} else if (ttime.after(date)) {
			utweets.setTime(sdf3.format(ttime));
		} else if (ttime.after(yeardate)) {
			utweets.setTime(sdf.format(ttime));
		} else {
			utweets.setTime(sdf2.format(ttime));
		}
		js.add(getJsonObj(utweets.getTid(), utweets.getUid(), utweets.getTcontent(), utweets.getTpic(),
				utweets.getTvideo(), utweets.getTreply(), utweets.getTforward(), utweets.getTlike(),
				utweets.getUname(), utweets.getUpwd(), utweets.getUrealname(), utweets.getUaite(),
				utweets.getUonline(), utweets.getUabout(), utweets.getUlogo(), utweets.getUbg(), utweets.getUfans(),
				utweets.getUtweet(), utweets.getUfollow(), utweets.getUcolor(), utweets.getTime(),
				utweets.getUtweets(), utweets.getTzhuan(), utweets.getZaned(), utweets.getZhuaned()));
	}
	return js.toString();
}
 
Example 18
Source File: JSONHelper.java    From jeecg with Apache License 2.0 4 votes vote down vote up
/***
 * 将List对象序列化为JSON文本
 */
public static <T> String toJSONString(List<T> list) {
	JSONArray jsonArray = JSONArray.fromObject(list);

	return jsonArray.toString();
}
 
Example 19
Source File: JSONHelper.java    From jeecg with Apache License 2.0 2 votes vote down vote up
/***
 * 将JSON对象数组序列化为JSON文本
 * 
 * @param jsonArray
 * @return
 */
public static String toJSONString(JSONArray jsonArray) {
	return jsonArray.toString();
}