当前位置: 首页>>代码示例>>Java>>正文


Java JSONArray.put方法代码示例

本文整理汇总了Java中org.apache.sling.commons.json.JSONArray.put方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.put方法的具体用法?Java JSONArray.put怎么用?Java JSONArray.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.sling.commons.json.JSONArray的用法示例。


在下文中一共展示了JSONArray.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:shinesolutions,项目名称:aem-healthcheck,代码行数:23,代码来源:HealthCheckExecutorServlet.java

示例2: 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);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:34,代码来源:MockURLStreamHandler.java

示例3: 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);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:31,代码来源:MockURLStreamHandler.java

示例4: 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);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:28,代码来源:MockURLStreamHandler.java

示例5: 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);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:37,代码来源:MockURLStreamHandler.java

示例6: 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;		
}
 
开发者ID:ottogroup,项目名称:flink-operator-library,代码行数:23,代码来源:WindowedJsonContentAggregator.java

示例7: visitIteration

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
private void visitIteration(JSONArray jsonArray, List<Integer> toVisit, int headId,
		Map<Integer, Integer> edgeRemapings, JSONArray iterationInEdges) throws JSONException {

	Integer vertexID = toVisit.get(0);
	StreamNode vertex = streamGraph.getStreamNode(vertexID);
	toVisit.remove(vertexID);

	// Ignoring head and tail to avoid redundancy
	if (!streamGraph.vertexIDtoLoopTimeout.containsKey(vertexID)) {
		JSONObject obj = new JSONObject();
		jsonArray.put(obj);
		decorateNode(vertexID, obj);
		JSONArray inEdges = new JSONArray();
		obj.put(PREDECESSORS, inEdges);

		for (StreamEdge inEdge : vertex.getInEdges()) {
			int inputID = inEdge.getSourceId();

			if (edgeRemapings.keySet().contains(inputID)) {
				decorateEdge(inEdges, inEdge, inputID);
			} else if (!streamGraph.vertexIDtoLoopTimeout.containsKey(inputID)) {
				decorateEdge(iterationInEdges, inEdge, inputID);
			}
		}

		edgeRemapings.put(vertexID, headId);
		visitIteration(jsonArray, toVisit, headId, edgeRemapings, iterationInEdges);
	}

}
 
开发者ID:axbaretto,项目名称:flink,代码行数:31,代码来源:JSONGenerator.java

示例8: decorateEdge

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
private void decorateEdge(JSONArray inputArray, StreamEdge inEdge, int mappedInputID)
		throws JSONException {
	JSONObject input = new JSONObject();
	inputArray.put(input);
	input.put(ID, mappedInputID);
	input.put(SHIP_STRATEGY, inEdge.getPartitioner());
	input.put(SIDE, (inputArray.length() == 0) ? "first" : "second");
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:9,代码来源:JSONGenerator.java

示例9: doGet

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
/**
 * Return all comments on a GET request in order of newest to oldest.
 */
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {

    final PrintWriter writer = response.getWriter();

    response.setCharacterEncoding(CharEncoding.UTF_8);
    response.setContentType("application/json");

    List<Resource> comments = commentService.getComments(request);

    try {
        JSONArray jsonArray = new JSONArray();

        for (Resource comment : comments) {
            final JSONObject json = new JSONObject();
            final ValueMap properties = comment.getValueMap();
            final Resource post = commentService.getParentPost(comment);

            json.put(PublickConstants.COMMENT_PROPERTY_COMMENT,
                    properties.get(PublickConstants.COMMENT_PROPERTY_COMMENT, String.class));
            json.put(JSON_ID, properties.get(JcrConstants.JCR_UUID, String.class));
            json.put(JSON_EDITED, properties.get(PublickConstants.COMMENT_PROPERTY_EDITED, false));
            json.put(JSON_REPLIES, commentService.numberOfReplies(comment));
            json.put(JSON_SPAM, properties.get(PublickConstants.COMMENT_PROPERTY_SPAM, false));
            json.put(JSON_POST, new JSONObject()
                    .put(JSON_POST_TEXT, post.getValueMap().get(PublickConstants.COMMENT_PROPERTY_TITLE, String.class))
                    .put(JSON_POST_LINK, linkRewriter.rewriteLink(post.getPath(), request.getServerName())));

            jsonArray.put(json);
        }

        response.setStatus(SlingHttpServletResponse.SC_OK);
        writer.write(jsonArray.toString());
    } catch (JSONException e) {
        LOGGER.error("Could not write JSON", e);
        response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:43,代码来源:CommentServlet.java

示例10: doGet

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
/**
 * Return all packages on a GET request in order of newest to oldest.
 */
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {

    final PrintWriter writer = response.getWriter();

    response.setCharacterEncoding(CharEncoding.UTF_8);
    response.setContentType("application/json");

    List<JcrPackage> packages = packageService.getPackageList(request);

    try {
        JSONArray jsonArray = new JSONArray();

        for (JcrPackage jcrPackage : packages) {
            final JSONObject json = getJsonFromJcrPackage(jcrPackage);

            jsonArray.put(json);
        }

        response.setStatus(SlingHttpServletResponse.SC_OK);
        writer.write(jsonArray.toString());
    } catch (JSONException | RepositoryException e) {
        LOGGER.error("Could not write JSON", e);
        response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:31,代码来源:BackupServlet.java

示例11: writeDataSourceOptions

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
@Override
public void writeDataSourceOptions(final SlingHttpServletRequest slingRequest,
                                      final SlingHttpServletResponse slingResponse) throws
        JSONException, IOException {
    final DataSource datasource = (DataSource) slingRequest.getAttribute(DataSource.class.getName());
    final JSONArray jsonArray = new JSONArray();

    if (datasource != null) {
        final Iterator<Resource> iterator = datasource.iterator();

        if (iterator != null) {
            while (iterator.hasNext()) {
                final Resource dataResource = iterator.next();

                if (dataResource != null) {
                    final ValueMap dataProps = dataResource.adaptTo(ValueMap.class);

                    if (dataProps != null) {
                        final JSONObject json = new JSONObject();

                        json.put(TEXT, dataProps.get(TEXT, ""));
                        json.put(VALUE, dataProps.get(VALUE, ""));

                        jsonArray.put(json);
                    }
                }
            }
        }
    }

    slingResponse.setContentType("application/json; charset=UTF-8");
    slingResponse.setCharacterEncoding("UTF-8");

    slingResponse.getWriter().write(jsonArray.toString());
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:36,代码来源:DataSourceBuilderImpl.java

示例12: writeConfigResource

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
private void writeConfigResource(Resource resource, String propertyName,
        SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, JSONException,
        ServletException {
    JSONObject widget = createEmptyWidget(propertyName);

    RequestParameterMap map = request.getRequestParameterMap();
    for (Map.Entry<String, RequestParameter[]> entry : map.entrySet()) {
        String key = entry.getKey();
        RequestParameter[] params = entry.getValue();
        if (params != null) {
            if (params.length > 1) {
                JSONArray arr = new JSONArray();
                for (int i = 0; i < params.length; i++) {
                    arr.put(params[i].getString());
                }
                widget.put(key, arr);
            } else if (params.length == 1) {
                widget.put(key, params[0].getString());
            }
        }
    }

    widget = underlay(widget, resource);

    JSONObject parent = new JSONObject();
    parent.put("xtype", "dialogfieldset");
    parent.put("border", false);
    parent.put("padding", 0);
    parent.put("style", "padding: 0px");
    parent.accumulate("items", widget);
    parent.write(response.getWriter());
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:33,代码来源:TagWidgetConfigurationServlet.java

示例13: filter

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
@SuppressWarnings("squid:S3776")
private void filter(JSONObject typeObject, String resourcePath, ResourceResolver resourceResolver) throws JSONException {
    final JSONArray models = typeObject.getJSONArray(KEY_MODELS);
    final JSONArray newModels = new JSONArray();
    for (int i = 0; i < models.length(); i++) {
        final JSONObject modelObject = models.getJSONObject(i);
        final String path = modelObject.getString(KEY_MODEL_PATH);
        final Resource modelResource = resourceResolver.getResource(path);
        if (modelResource != null) {
            // we're looking for the appliesTo property on the jcr:content node, the wid value
            // is the path to the jcr:content/model node.
            final ValueMap properties = modelResource.getParent().getValueMap();
            final String[] allowedPaths = properties.get(PN_ALLOWED_PATHS, String[].class);
            if (allowedPaths == null) {
                newModels.put(modelObject);
            } else {
                for (final String allowedPath : allowedPaths) {
                    if (resourcePath.matches(allowedPath)) {
                        newModels.put(modelObject);
                        break;
                    }
                }
            }
        }
    }
    
    typeObject.put(KEY_MODELS, newModels);
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:29,代码来源:WorkflowModelFilterPageInfoProvider.java

示例14: doGet

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException,
        IOException {
    XSSAPI xssApi = request.adaptTo(XSSAPI.class);
    try {
        JSONObject result = new JSONObject();
        JSONArray list = new JSONArray();
        result.put("list", list);

        ServiceReference[] services = tracker.getServiceReferences();
        if (services != null) {
            for (ServiceReference service : services) {
                String displayName = PropertiesUtil.toString(service.getProperty("displayName"), null);
                String[] schemes = PropertiesUtil.toStringArray(service.getProperty(Importer.SCHEME_PROPERTY));
                if (displayName != null && schemes != null) {
                    for (String scheme : schemes) {
                        JSONObject obj = new JSONObject();
                        obj.put("qtip", "");
                        obj.put("text", displayName);
                        obj.put("text_xss", xssApi.encodeForJSString(displayName));
                        obj.put("value", scheme);
                        list.put(obj);
                    }
                }
            }
        }

        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json");
        result.write(response.getWriter());
    } catch (JSONException e) {
        throw new ServletException("Unable to generate importer list", e);
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:35,代码来源:CustomPollingImporterListServlet.java

示例15: doGet

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {
    String root = request.getParameter(PN_PATH);
    if (StringUtils.isNotBlank(root)) {
        TagManager tagManager = request.getResourceResolver().adaptTo(TagManager.class);
        Tag rootTag = tagManager.resolve(root);
        // cannot resolve root tag
        if (null == rootTag) {
            response.sendError(SlingHttpServletResponse.SC_NOT_FOUND);
        } else {
            JSONArray items = new JSONArray();
            Iterator<Tag> children = rootTag.listChildren();
            Tag child = null;
            // iterate over child tags
            while(children.hasNext()) {
                child = children.next();
                try {
                    items.put((Object)new JSONObject()
                            .put(PN_KEY, child.getTitle())
                            .put(PN_VALUE, child.getDescription()));
                } catch (JSONException e) {
                    LOG.debug(e.getMessage());
                }
                child = null;
            }
            
            byte[] jsonBytes = items.toString().getBytes("UTF-8");

            response.setContentType("application/json");
            response.setCharacterEncoding("UTF-8");
            response.setContentLength(jsonBytes.length);
            response.getOutputStream().write(jsonBytes);
        }
    } else {
        response.sendError(SlingHttpServletResponse.SC_NOT_FOUND);
    }
}
 
开发者ID:steeleforge,项目名称:ironsites,代码行数:39,代码来源:TagOptionsServlet.java


注:本文中的org.apache.sling.commons.json.JSONArray.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。