Java Code Examples for net.sf.json.JSONObject#size()

The following examples show how to use net.sf.json.JSONObject#size() . 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: DailyRollingLogAccess.java    From logsniffer with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public LogPointer getFromJSON(final String data) throws IOException {
	try {
		final JSONObject json = JSONObject.fromObject(data);
		if (json.size() > 0) {
			final RollingLogPointer rlp = new RollingLogPointer(json.getString("p"), new String[] {},
					new DefaultPointer(0, 0), json.getBoolean("f"), json.getBoolean("l"));
			rlp.allLogsHash = json.getInt("h");
			rlp.liveNext = json.optString("n", null);
			final PointerData spd = getLogIndex(rlp);
			if (spd.pointer != null) {
				rlp.filePointer = getPartLogAccess(parts[spd.index])
						.getFromJSON(json.getJSONObject("u").toString());
			}
			return createRelative(rlp, 0);
		} else {
			return createRelative(null, 0);
		}
	} catch (final JSONException e) {
		LOGGER.warn("Invalid JSON pointer: " + data, e);
		return createRelative(null, 0);
	}
}
 
Example 2
Source File: TemplateImplementationProperty.java    From ez-templates with Apache License 2.0 6 votes vote down vote up
@Override
public JobProperty<?> newInstance(StaplerRequest request, JSONObject formData) throws FormException {
    if (formData.size() > 0 && formData.has("useTemplate")) {
        JSONObject useTemplate = formData.getJSONObject("useTemplate");

        String templateJobName = useTemplate.getString("templateJobName");
        boolean syncMatrixAxis = useTemplate.getBoolean("syncMatrixAxis");
        boolean syncDescription = useTemplate.getBoolean("syncDescription");
        boolean syncBuildTriggers = useTemplate.getBoolean("syncBuildTriggers");
        boolean syncDisabled = useTemplate.getBoolean("syncDisabled");
        boolean syncSecurity = useTemplate.getBoolean("syncSecurity");
        boolean syncScm = useTemplate.getBoolean("syncScm");
        boolean syncOwnership = useTemplate.getBoolean("syncOwnership");
        boolean syncAssignedLabel = useTemplate.getBoolean("syncAssignedLabel");

        return new TemplateImplementationProperty(templateJobName, syncMatrixAxis, syncDescription, syncBuildTriggers, syncDisabled, syncSecurity, syncScm, syncOwnership, syncAssignedLabel);
    }

    return null;
}
 
Example 3
Source File: JiraHttpClient.java    From benten with MIT License 5 votes vote down vote up
private void handleJiraException(HttpResponse httpResponse) throws IOException {
    String json = EntityUtils.toString(httpResponse.getEntity());
    JiraError jiraError = JiraConverter.objectMapper.readValue(json, JiraError.class);
    JSONObject error = jiraError.getErrors();
    if(error.size()>0) {
        String firstKey = (String) error.keys().next();
        throw new BentenJiraException( error.getString(firstKey));
    }else{
        throw new BentenJiraException( jiraError.getErrorMessages().get(0));
    }

}
 
Example 4
Source File: SQSTrigger.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean configure(final StaplerRequest req, final JSONObject json) throws FormException {
    Object sqsQueues = json.get("sqsQueues");
    if (json.size() == 1) {
        String key = json.keys().next().toString();
        sqsQueues = json.getJSONObject(key).get("sqsQueues");
    }
    this.sqsQueues = req.bindJSONToList(SQSTriggerQueue.class, sqsQueues);
    this.initQueueMap();

    this.save();

    EventBroker.getInstance().post(new ConfigurationChangedEvent());
    return true;
}
 
Example 5
Source File: DataGridTag.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 生成扩展属性
 * @param field
 * @return
 */
private String extendAttribute(String field) {
	if(StringUtil.isEmpty(field)){
		return "";
	}
	field = dealSyscode(field,1);
	StringBuilder re = new StringBuilder();
	try{
		JSONObject obj = JSONObject.fromObject(field);
		Iterator it = obj.keys();
		while(it.hasNext()){
			String key = String.valueOf(it.next());
			JSONObject nextObj =((JSONObject)obj.get(key));
			Iterator itvalue =nextObj.keys();
			re.append(key+"="+"\"");
			if(nextObj.size()<=1){
				String onlykey = String.valueOf(itvalue.next());
				if("value".equals(onlykey)){
					re.append(nextObj.get(onlykey)+"");
				}else{
					re.append(onlykey+":"+nextObj.get(onlykey)+"");
				}
			}else{
				while(itvalue.hasNext()){
					String multkey = String.valueOf(itvalue.next());
					String multvalue = nextObj.getString(multkey);
					re.append(multkey+":"+multvalue+",");
				}
				re.deleteCharAt(re.length()-1);
			}
			re.append("\" ");
		}
	}catch (Exception e) {
		e.printStackTrace();
		return "";
	}
	return dealSyscode(re.toString(), 2);
}
 
Example 6
Source File: TemplateProperty.java    From ez-templates with Apache License 2.0 5 votes vote down vote up
@Override
public JobProperty<?> newInstance(StaplerRequest request, JSONObject formData) throws FormException {
    if (formData.size() > 0) {
        return new TemplateProperty();
    }
    return null;
}