本文整理汇总了Java中org.apache.sling.commons.json.JSONArray类的典型用法代码示例。如果您正苦于以下问题:Java JSONArray类的具体用法?Java JSONArray怎么用?Java JSONArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSONArray类属于org.apache.sling.commons.json包,在下文中一共展示了JSONArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import org.apache.sling.commons.json.JSONArray; //导入依赖的package包/类
protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
threadLocal = new ThreadLocal<JSONArray>() {
@Override
protected JSONArray initialValue() {
return new JSONArray();
}
};
loadElements(request);
out.write(threadLocal.get().toString());
} catch (Exception e) {
throw new ServletException(e);
} finally {
out.flush();
threadLocal.remove();
}
}
示例2: generateResponse
import org.apache.sling.commons.json.JSONArray; //导入依赖的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: getJSON
import org.apache.sling.commons.json.JSONArray; //导入依赖的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();
}
示例4: getFormJSONObject
import org.apache.sling.commons.json.JSONArray; //导入依赖的package包/类
/**
* Get the JSON data to populate the Workflow Removal form.
*
* @param resourceResolver
* @return
* @throws WorkflowException
* @throws JSONException
*/
private JSONObject getFormJSONObject(final ResourceResolver resourceResolver) throws WorkflowException,
JSONException {
final JSONObject json = new JSONObject();
final WorkflowSession workflowSession = workflowService.getWorkflowSession(
resourceResolver.adaptTo(Session.class));
final WorkflowModel[] workflowModels = workflowSession.getModels();
for (final WorkflowModel workflowModel : workflowModels) {
final JSONObject jsonWorkflow = new JSONObject();
jsonWorkflow.put("title", workflowModel.getTitle());
jsonWorkflow.put("id", workflowModel.getId());
json.accumulate("workflowModels", jsonWorkflow);
}
json.put("statuses", new JSONArray(Arrays.asList(WORKFLOW_STATUSES)));
return json;
}
示例5: getSuccessJSON
import org.apache.sling.commons.json.JSONArray; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public String getSuccessJSON(final JcrPackage jcrPackage) throws JSONException, RepositoryException {
final JSONObject json = new JSONObject();
json.put(KEY_STATUS, "success");
json.put(KEY_PATH, jcrPackage.getNode().getPath());
json.put(KEY_FILTER_SETS, new JSONArray());
final List<PathFilterSet> filterSets = jcrPackage.getDefinition().getMetaInf().getFilter().getFilterSets();
for (final PathFilterSet filterSet : filterSets) {
final JSONObject jsonFilterSet = new JSONObject();
jsonFilterSet.put(KEY_IMPORT_MODE, filterSet.getImportMode().name());
jsonFilterSet.put(KEY_ROOT_PATH, filterSet.getRoot());
json.accumulate(KEY_FILTER_SETS, jsonFilterSet);
}
return json.toString();
}
示例6: getPathFilterSetPreviewJSON
import org.apache.sling.commons.json.JSONArray; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public String getPathFilterSetPreviewJSON(final Collection<PathFilterSet> pathFilterSets) throws JSONException {
final JSONObject json = new JSONObject();
json.put(KEY_STATUS, "preview");
json.put(KEY_PATH, "Not applicable (Preview)");
json.put(KEY_FILTER_SETS, new JSONArray());
for (final PathFilterSet pathFilterSet : pathFilterSets) {
final JSONObject tmp = new JSONObject();
tmp.put(KEY_IMPORT_MODE, "Not applicable (Preview)");
tmp.put(KEY_ROOT_PATH, pathFilterSet.getRoot());
json.accumulate("filterSets", tmp);
}
return json.toString();
}
示例7: getJSONResults
import org.apache.sling.commons.json.JSONArray; //导入依赖的package包/类
private JSONObject getJSONResults(Command cmd, SlingHttpServletRequest request, final Collection<Result> results) throws
JSONException {
final JSONObject json = new JSONObject();
json.put(KEY_RESULTS, new JSONArray());
final ValueMap requestConfig = new ValueMapDecorator(new HashMap<String, Object>());
// Collect all items collected from OSGi Properties
requestConfig.putAll(this.config);
// Add Request specific configurations
requestConfig.put(AuthoringUIMode.class.getName(),
authoringUIModeService.getAuthoringUIMode(request));
for (final Result result : results) {
final JSONObject tmp = resultBuilder.toJSON(cmd, result, requestConfig);
if (tmp != null) {
json.accumulate(KEY_RESULTS, tmp);
}
}
return json;
}
示例8: testGetSuccessJSON
import org.apache.sling.commons.json.JSONArray; //导入依赖的package包/类
@Test
public void testGetSuccessJSON() throws Exception {
final String actual = packageHelper.getSuccessJSON(packageOne);
final JSONObject json = new JSONObject(actual);
assertEquals("success", json.getString("status"));
assertEquals("/etc/packages/testGroup/testPackageName-1.0.0.zip", json.getString("path"));
final String[] expectedFilterSets = new String[]{
"/a/b/c",
"/d/e/f",
"/g/h/i"
};
JSONArray actualArray = json.getJSONArray("filterSets");
for(int i = 0; i < actualArray.length(); i++) {
JSONObject tmp = actualArray.getJSONObject(i);
assertTrue(ArrayUtils.contains(expectedFilterSets, tmp.get("rootPath")));
}
assertEquals(expectedFilterSets.length, actualArray.length());
}
示例9: repServers
import org.apache.sling.commons.json.JSONArray; //导入依赖的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);
}
}
示例10: respStacksInstanceName
import org.apache.sling.commons.json.JSONArray; //导入依赖的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);
}
}
示例11: respStacksResources
import org.apache.sling.commons.json.JSONArray; //导入依赖的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);
}
}
示例12: respServerDetail
import org.apache.sling.commons.json.JSONArray; //导入依赖的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);
}
}
示例13: addRawMessages
import org.apache.sling.commons.json.JSONArray; //导入依赖的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;
}
示例14: testGetArrayElement_withValueArrayAndNegativePosition
import org.apache.sling.commons.json.JSONArray; //导入依赖的package包/类
/**
* Test case for {@link JsonProcessingUtils#getArrayElement(org.apache.sling.commons.json.JSONArray, int)} being provided
* -1 as input to position parameter
*/
@Test(expected = NoSuchElementException.class)
public void testGetArrayElement_withValueArrayAndNegativePosition() throws Exception {
Collection<String> testCollection = new HashSet<>();
testCollection.add("value-1");
testCollection.add("value-2");
testCollection.add("value-3");
new JsonProcessingUtils().getArrayElement(new JSONArray(testCollection), -1);
}
示例15: testGetArrayElement_withValueArrayAndInvalidPosition
import org.apache.sling.commons.json.JSONArray; //导入依赖的package包/类
/**
* Test case for {@link JsonProcessingUtils#getArrayElement(org.apache.sling.commons.json.JSONArray, int)} being provided
* a position after max. allowed value
*/
@Test(expected = NoSuchElementException.class)
public void testGetArrayElement_withValueArrayAndInvalidPosition() throws Exception {
Collection<String> testCollection = new ArrayList<>();
testCollection.add("value-1");
testCollection.add("value-2");
testCollection.add("value-3");
new JsonProcessingUtils().getArrayElement(new JSONArray(testCollection), 3);
}