本文整理汇总了Java中org.apache.sling.commons.json.JSONObject.put方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.put方法的具体用法?Java JSONObject.put怎么用?Java JSONObject.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sling.commons.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: respStacks
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
private static String respStacks() {
try {
JSONObject response = new JSONObject();
JSONObject state = new JSONObject();
state.put("label", "OK");
state.put("id", "OK");
response.put("state", state);
response.put("id", "1234");
response.put("stack", "1234");
response.put("name", "Appliance1");
response.put("projectUri",
"http://test.com/cloud/api/projects/54346");
JSONObject stack = new JSONObject();
stack.put("id", "idValue");
response.put("stack", stack);
return response.toString();
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
示例2: generateResponse
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
/**
* Creates a JSON representation of the given HealthCheckExecutionResult list.
* @param executionResults
* @param resultJson
* @return
* @throws JSONException
*/
private static JSONObject generateResponse(List<HealthCheckExecutionResult> executionResults,
JSONObject resultJson) throws JSONException {
JSONArray resultsJsonArr = new JSONArray();
resultJson.put("results", resultsJsonArr);
for (HealthCheckExecutionResult healthCheckResult : executionResults) {
JSONObject result = new JSONObject();
result.put("name", healthCheckResult.getHealthCheckMetadata() != null ?
healthCheckResult.getHealthCheckMetadata().getName() : "");
result.put("status", healthCheckResult.getHealthCheckResult().getStatus());
result.put("timeMs", healthCheckResult.getElapsedTimeInMs());
resultsJsonArr.put(result);
}
return resultJson;
}
示例3: addOptionalFields
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
/**
* Adds the requested set of optional fields to provided {@link JSONObject}
* @param jsonObject
* The {@link JSONObject} to add optional fields to
* @param optionalFields
* The optional fields along with the requested values to be added to the provided {@link JSONObject}
* @param dateFormatter
* The format to apply when adding time stamp values
* @param totalMessageCount
* The total number of messages received from the window
* @return
* The provided {@link JSONObject} enhanced by the requested values
* @throws JSONException
* Thrown in case anything fails during operations on the JSON object
*/
protected JSONObject addOptionalFields(final JSONObject jsonObject, final Map<String, String> optionalFields, final SimpleDateFormat dateFormatter, final int totalMessageCount) throws JSONException {
// step through the optional fields if any were provided
if(jsonObject != null && optionalFields != null && !optionalFields.isEmpty()) {
for(final String fieldName : optionalFields.keySet()) {
final String value = optionalFields.get(fieldName);
// check if the value references a pre-defined type and thus requests a special value or
// whether the field name must be added along with the value without any modifications
if(StringUtils.equalsIgnoreCase(value, OPTIONAL_FIELD_TYPE_TIMESTAMP))
jsonObject.put(fieldName, dateFormatter.format(new Date()));
else if(StringUtils.equalsIgnoreCase(value, OPTIONAL_FIELD_TYPE_TOTAL_MESSAGE_COUNT))
jsonObject.put(fieldName, totalMessageCount);
else
jsonObject.put(fieldName, value);
}
}
return jsonObject;
}
示例4: createReactProps
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
private JSONObject createReactProps(ReactComponentConfig config, SlingHttpServletRequest request, Resource resource) {
try {
int depth = config.getDepth();
JSONObject resourceAsJson = JsonObjectCreator.create(resource, depth);
JSONObject reactProps = new JSONObject();
reactProps.put("resource", resourceAsJson);
reactProps.put("component", config.getComponent());
reactProps.put("resourceType", resource.getResourceType());
// TODO remove depth and provide custom service to get the resource as
// json without spcifying the depth. This makes it possible to privde
// custom loader.
reactProps.put("depth", config.getDepth());
reactProps.put("wcmmode", getWcmMode(request));
reactProps.put("path", resource.getPath());
reactProps.put("root", true);
return reactProps;
} catch (JSONException e) {
throw new TechnicalException("cannot create react props", e);
}
}
示例5: getJSON
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
public String getJSON() throws JSONException {
JSONObject json = new JSONObject();
JSONArray nodes = new JSONArray();
json.put("nodes", nodes);
List<Integer> operatorIDs = new ArrayList<Integer>(streamGraph.getVertexIDs());
Collections.sort(operatorIDs, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
// put sinks at the back
if (streamGraph.getSinkIDs().contains(o1)) {
return 1;
} else if (streamGraph.getSinkIDs().contains(o2)) {
return -1;
} else {
return o1 - o2;
}
}
});
visit(nodes, operatorIDs, new HashMap<Integer, Integer>());
return json.toString();
}
示例6: decorateNode
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
private void decorateNode(Integer vertexID, JSONObject node) throws JSONException {
StreamNode vertex = streamGraph.getStreamNode(vertexID);
node.put(ID, vertexID);
node.put(TYPE, vertex.getOperatorName());
if (streamGraph.getSourceIDs().contains(vertexID)) {
node.put(PACT, "Data Source");
} else if (streamGraph.getSinkIDs().contains(vertexID)) {
node.put(PACT, "Data Sink");
} else {
node.put(PACT, "Operator");
}
StreamOperator<?> operator = streamGraph.getStreamNode(vertexID).getOperator();
node.put(CONTENTS, vertex.getOperatorName());
node.put(PARALLELISM, streamGraph.getStreamNode(vertexID).getParallelism());
}
示例7: wrapHtml
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
/**
* wrap the rendered react markup with the teaxtarea that contains the
* component's props.
*
* @param path
* @param reactProps
* @param component
* @param renderedHtml
* @param serverRendering
* @return
*/
private String wrapHtml(String path, Resource resource, String renderedHtml, boolean serverRendering, String wcmmode, String cache) {
JSONObject reactProps = new JSONObject();
try {
if (cache != null) {
reactProps.put("cache", new JSONObject(cache));
}
reactProps.put("resourceType", resource.getResourceType());
reactProps.put("path", resource.getPath());
reactProps.put("wcmmode", wcmmode);
} catch (JSONException e) {
throw new TechnicalException("cannot create react props", e);
}
String jsonProps = StringEscapeUtils.escapeHtml4(reactProps.toString());
String allHtml = "<div data-react-server=\"" + String.valueOf(serverRendering) + "\" data-react=\"app\" data-react-id=\"" + path + "_component\">"
+ renderedHtml + "</div>" + "<textarea id=\"" + path + "_component\" style=\"display:none;\">" + jsonProps + "</textarea>";
return allHtml;
}
示例8: addElement
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
protected final void addElement(String text, String value)
throws JSONException {
JSONObject obj = new JSONObject();
obj.put("value", value);
obj.put("text", text);
threadLocal.get().put(obj);
}
示例9: respFlavor
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
/**
* @param string
* @return
*/
public static String respFlavor(int id, String flavorName) {
try {
JSONObject response = new JSONObject();
JSONObject flavor = new JSONObject();
flavor.put("id", id);
flavor.put("name", flavorName);
response.put("flavor", flavor);
return response.toString();
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
示例10: repServers
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
/**
* @return
*/
private static String repServers(List<String> serverNames) {
try {
JSONObject response = new JSONObject();
JSONArray servers = new JSONArray();
for (int i = 0; i < serverNames.size(); i++) {
JSONObject server = new JSONObject();
JSONArray links = new JSONArray();
JSONObject linkSelf = new JSONObject();
JSONObject linkBookmark = new JSONObject();
String instanceId = Integer.toString(i) + "-Instance-"
+ serverNames.get(i);
server.put("id", instanceId);
linkSelf.put("href",
"http://novaendpoint/v2/servers/" + instanceId);
linkSelf.put("rel", "self");
links.put(linkSelf);
linkBookmark.put("href",
"http://novaendpoint/servers/" + instanceId);
linkBookmark.put("rel", "self");
links.put(linkBookmark);
server.put("links", links);
server.put("name", serverNames.get(i));
servers.put(server);
}
response.put("servers", servers);
return response.toString();
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
示例11: respStacksInstanceName
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
public static String respStacksInstanceName(StackStatus status,
boolean withStatusReason, String... stackStatusReason) {
String reason;
if (stackStatusReason == null || stackStatusReason.length == 0) {
reason = "SSR";
} else {
reason = Arrays.toString(stackStatusReason);
}
try {
JSONObject response = new JSONObject();
JSONObject stack = new JSONObject();
response.put("stack", stack);
stack.put("stack_name", "SN");
stack.put("id", "ID");
stack.put("stack_status",
status == null ? "bullshit" : status.name());
if (withStatusReason) {
stack.put("stack_status_reason", reason);
}
JSONArray outputs = new JSONArray();
JSONObject output = new JSONObject();
output.put("output_key", "OK");
output.put("output_value", "OV");
outputs.put(output);
stack.put("outputs", outputs);
return response.toString();
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
示例12: respStacksResources
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
public static String respStacksResources(List<String> serverNames,
String resourceType) {
try {
JSONObject response = new JSONObject();
JSONArray resources = new JSONArray();
response.put("resources", resources);
JSONObject volume = new JSONObject();
volume.put("resource_name", "sys-vol");
volume.put("physical_resource_id", "12345");
volume.put("resource_type", "OS::Cinder::Volume");
resources.put(volume);
for (int i = 0; i < serverNames.size(); i++) {
JSONObject server = new JSONObject();
server.put("resource_name", serverNames.get(i));
server.put("physical_resource_id", Integer.toString(i)
+ "-Instance-" + serverNames.get(i));
server.put("resource_type", resourceType);
resources.put(server);
}
return response.toString();
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
示例13: respServer
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
public static String respServer(String serverName, String serverId) {
try {
JSONObject response = new JSONObject();
JSONObject server = new JSONObject();
response.put("server", server);
server.put("name", serverName);
server.put("id", serverId);
return response.toString();
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
示例14: respServerDetail
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
public static String respServerDetail(String serverName, String serverId,
ServerStatus status, String tenant_id) {
try {
JSONObject response = new JSONObject();
JSONObject server = new JSONObject();
response.put("server", server);
server.put("name", serverName);
server.put("id", serverId);
server.put("status", status);
server.put("tenant_id", tenant_id);
server.put("accessIPv4", "192.0.2.0");
JSONObject flavor = new JSONObject();
flavor.put("id", 1);
server.put("flavor", flavor);
JSONObject addresses = new JSONObject();
JSONArray networkDetail = new JSONArray();
JSONObject fixedNetwork = new JSONObject();
JSONObject floatingNetwork = new JSONObject();
fixedNetwork.put("OS-EXT-IPS-MAC:mac_addr", "fa:16:3e:e5:b7:f8");
fixedNetwork.put("version", "4");
fixedNetwork.put("addr", "192.168.0.4");
fixedNetwork.put("OS-EXT-IPS:type", "fixed");
floatingNetwork.put("OS-EXT-IPS-MAC:mac_addr", "fa:16:3e:e5:b7:f8");
floatingNetwork.put("version", "4");
floatingNetwork.put("addr", "133.162.161.216");
floatingNetwork.put("OS-EXT-IPS:type", "floating");
networkDetail.put(fixedNetwork);
networkDetail.put(floatingNetwork);
addresses.put(serverName + "-network", networkDetail);
server.put("addresses", addresses);
return response.toString();
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
示例15: addRawMessages
import org.apache.sling.commons.json.JSONObject; //导入方法依赖的package包/类
/**
* Appends the raw messages received from the window to the resulting {@link JSONObject}
* @param jsonObject
* The {@link JSONObject} to add window messages to
* @param values
* The {@link JSONObject} values to be added
* @return
* The input {@link JSONObject} extended by {@link JSONObject} received from the window
* @throws JSONException
* Thrown in case moving the source events to the result
*/
protected JSONObject addRawMessages(final JSONObject jsonObject, Iterable<JSONObject> values) throws JSONException {
if(jsonObject != null && values != null) {
JSONArray rawMessagesArray = new JSONArray();
for(JSONObject jo : values) {
rawMessagesArray.put(jo);
}
jsonObject.put("raw", rawMessagesArray);
}
return jsonObject;
}