• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JSONWriter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.sling.commons.json.io.JSONWriter的典型用法代码示例。如果您正苦于以下问题:Java JSONWriter类的具体用法?Java JSONWriter怎么用?Java JSONWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JSONWriter类属于org.apache.sling.commons.json.io包,在下文中一共展示了JSONWriter类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: doGet

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {

    try {
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");

        Page currentPage = request.getResource().adaptTo(Page.class);
        JSONWriter w = new JSONWriter(response.getWriter());

        w.object();
        w.key("name").value(currentPage.getTitle());

        w.endObject();
    } catch (Exception ex) {
        log.error("Request failed", ex);
        throw new ServletException(ex);
    }
}
 
开发者ID:AdobeAtAdobe,项目名称:aaa-aem-boilerplate,代码行数:20,代码来源:ThingJsonServlet.java


示例2: write

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
@Override
public final void write(Hit hit, JSONWriter jsonWriter, Query query) throws RepositoryException, JSONException {
    // This example assume the "hit" represents a [cq:Page] node (and not the [cq:Page]/jcr:content node)

    // The Resource that represents a Query "hit" (result); This can used to access other related resources in the JCR.
    final Resource resource = hit.getResource();
    
    // The Hit object contains the ValueMap representing the "hit" resource. 
    // This can be used to quickly get properties/relative properties from the hit to expose via the HitWriter.
    final ValueMap properties = hit.getProperties();

    // Write simple values like the node's path to the JSON result object
    jsonWriter.key("path").value(resource.getPath());

    // Write resource properties from the hit result node (or relative nodes) to the JSON result object
    // You have full control over the names/values of the JSON key/value pairs returned.
    // These do not have to match node names
    jsonWriter.key("key-to-use-in-json").value(properties.get("jcr:content/jcr:title", "") 
        + "(pulled from jcr:content node)");

    // Custom logic can be used to transform and/or retrieve data to be added to the resulting JSON object
    // Note: Keep this logic as light as possible. Complex logic can introduce performance issues that are
    // less visible (Will not appear in JMX Slow Query logs as this logic executes after the actual Query returns).
    String complexValue = sampleComplexLogic(resource);
    jsonWriter.key("complex").value(complexValue);
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-samples,代码行数:27,代码来源:SampleJsonHitWriter.java


示例3: getJSONWriter

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
@Override
public void getJSONWriter(PrintWriter writer)  {

    JSONWriter jsonWriter = new JSONWriter(writer);

    try {
        jsonWriter.array();
        for(String core: solrConfigurationService.getCores()) {
            jsonWriter.object();
            jsonWriter.key("text");
            jsonWriter.value(core);
            jsonWriter.key("value");
            jsonWriter.value(core);
            jsonWriter.endObject();
        }
        jsonWriter.endArray();

    } catch (JSONException e) {
        LOG.error("Error creating solr cores JSON", e);
    }
}
 
开发者ID:headwirecom,项目名称:aem-solr-search,代码行数:22,代码来源:SolrCoreServlet.java


示例4: getJSONWriter

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
@Override
public void getJSONWriter(PrintWriter writer) {

    JSONWriter jsonWriter = new JSONWriter(writer);

    try {
        jsonWriter.array();
        for(String field: solrConfigurationService.getStoredFields(getSolrCore())) {
            jsonWriter.object();
            jsonWriter.key("text");
            jsonWriter.value(field);
            jsonWriter.key("value");
            jsonWriter.value(field);
            jsonWriter.endObject();
        }
        jsonWriter.endArray();
    } catch (JSONException e) {
        LOG.error("Error creating stored fields JSON", e);
    }
}
 
开发者ID:headwirecom,项目名称:aem-solr-search,代码行数:21,代码来源:SolrSchemaStoredFieldsServlet.java


示例5: getJSONWriter

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
@Override
public void getJSONWriter(PrintWriter writer)  {

    JSONWriter jsonWriter = new JSONWriter(writer);

    try {
        jsonWriter.array();
        for(String field: solrConfigurationService.getIndexedFieldsFromLuke(getSolrCore())) {
            jsonWriter.object();
            jsonWriter.key("text");
            jsonWriter.value(field);
            jsonWriter.key("value");
            jsonWriter.value(field);
            jsonWriter.endObject();
        }
        jsonWriter.endArray();
    } catch (JSONException e) {
        LOG.error("Error creating indexed fields JSON", e);
    }
}
 
开发者ID:headwirecom,项目名称:aem-solr-search,代码行数:21,代码来源:SolrSchemaIndexedFieldsServlet.java


示例6: arrayToJson

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
/**
 * Converts an array into a JSON array.
 *
 * @param array
 * @return A compatible JSON array on success, and an empty JSON array otherwise.
 */
public static String arrayToJson(String[] array) {

    if (null == array) {return EMPTY_JSON_ARRAY;}

    StringWriter stringWriter = new StringWriter();
    JSONWriter jsonWriter = new JSONWriter(stringWriter);

    try {
        jsonWriter.array();
        for (String item: array) {
            jsonWriter.value(item);
        }
        jsonWriter.endArray();

    } catch (JSONException e) {
        LOG.error("Can't convert array '{}' to JSON", array, e);
        return EMPTY_JSON_ARRAY;
    }

    return stringWriter.toString();
}
 
开发者ID:headwirecom,项目名称:aem-solr-search,代码行数:28,代码来源:StringUtil.java


示例7: writeUseBeans

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
/**
 * write use beans
 * @return
 */
public void writeUseBeans(JSONWriter writer) throws JSONException {
    Collection<ClassInfo> sortedBeans = new TreeSet<ClassInfo>(beanComparator);
    sortedBeans.addAll(beans.values());
    writer.object();
    for (ClassInfo bean : sortedBeans){
        JSONObject classObject = new JSONObject();
        classObject.put("members", getMembers(bean.getClassName()));
        classObject.put("super", bean.getSuperClassName());
        writer.key(bean.getClassName()).value(classObject);
    }
    writer.endObject();
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-htl-ide-api,代码行数:17,代码来源:SightlyBeanFinderImpl.java


示例8: doGet

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException {
    try {
        response.setContentType("application/json");
        response.setCharacterEncoding("utf8");
        response.setHeader("Cache-Control", "no-cache");
        response.setStatus(HttpServletResponse.SC_OK);
        JSONWriter w = new JSONWriter(response.getWriter());
        sightlyBeanFinder.writeUseBeans(w);
    } catch (Exception e){
        throw new ServletException(e);
    }
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-htl-ide-api,代码行数:14,代码来源:SightlyUseListServlet.java


示例9: adaptTo

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
    if (type == InputStream.class) {
        StringWriter buffer = new StringWriter();
        try {
            JSONWriter writer = new JSONWriter(buffer);
            writer.object();
            writer.key("options");
            writer.array();
            for (Item item : list.getItems()) {
                writer.object();
                writer.key("text").value(item.getTitle());
                writer.key("value").value(item.getValue());
                writer.endObject();
            }
            writer.endArray();
            writer.endObject();
            return (AdapterType) new ByteArrayInputStream(buffer.toString().getBytes("UTF-8"));
        } catch (Exception e) {
            log.warn("Unable to generate JSON object.", e);
            return null;
        }
    } else {
        return super.adaptTo(type);
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:28,代码来源:GenericListJsonResourceProvider.java


示例10: write

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
@Override
public void write(Hit hit, JSONWriter jsonWriter, Query query) throws RepositoryException, JSONException {
    Map<String, Object> map = ContentFinderHitBuilder.buildGenericResult(hit);

    jsonWriter.object();

    for (final Map.Entry<String, Object> entry : map.entrySet()) {
        jsonWriter.key(entry.getKey()).value(entry.getValue());
    }

    jsonWriter.endObject();
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:13,代码来源:ContentFinderResultHitWriter.java


示例11: doGet

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {

    try {
        final ResourceResolver resolver = request.getResourceResolver();
        final String vanityPath = request.getParameter("vanityPath");
        final String pagePath = request.getParameter("pagePath");
        log.debug("vanity path parameter passed is {}; page path parameter passed is {}", vanityPath, pagePath);

        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");

        JSONWriter jsonWriter = new JSONWriter(response.getWriter());
        jsonWriter.array();

        if (StringUtils.isNotBlank(vanityPath)) {
            String xpath = "//element(*)[" + NameConstants.PN_SLING_VANITY_PATH + "='" + vanityPath + "']";
            @SuppressWarnings("deprecation")
            Iterator<Resource> resources = resolver.findResources(xpath, Query.XPATH);
            while (resources.hasNext()) {
                Resource resource = resources.next();
                String path = resource.getPath();
                if (path.startsWith("/content") && !path.equals(pagePath)) {
                    jsonWriter.value(path);
                }
            }

        }
        jsonWriter.endArray();
    } catch (JSONException e) {
        throw new ServletException("Unable to generate JSON result", e);
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:35,代码来源:VanityDuplicateCheckServlet.java


示例12: writeResult

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
private void writeResult(SlingHttpServletRequest req,
		SlingHttpServletResponse resp,
		Iterator<Map<String, Object>> result, String nodeType)
		throws IOException {

	try {

		resp.setContentType(req.getResponseContentType());
		resp.setCharacterEncoding("UTF-8");

		final JSONWriter w = new JSONWriter(resp.getWriter());
		w.setTidy(isTidy(req));

		w.array();

		// iterate through the result set and build the "json result"
		while (result.hasNext()) {
			Map<String, Object> row = result.next();

			w.object();

			// dump columns
			for (String colName : row.keySet()) {
				w.key(getColName(colName, nodeType));
				itemWriter.dumpValue(w, row.get(colName));
			}

			w.endObject();
		}
		w.endArray();
	} catch (JSONException je) {
		throw wrapException(je);
	}
}
 
开发者ID:hlta,项目名称:playweb,代码行数:35,代码来源:PlaywebJsonQueryServlet.java


示例13: write

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
@Deprecated
public void write(JSONWriter arg0) throws JSONException {
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:experiencemanager-java-msmrollout,代码行数:4,代码来源:ExampleLiveActionFactory.java


示例14: writeUseBeans

import org.apache.sling.commons.json.io.JSONWriter; //导入依赖的package包/类
public void writeUseBeans(JSONWriter writer) throws JSONException; 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-htl-ide-api,代码行数:2,代码来源:SightlyBeanFinder.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ForeignAttributesImpl类代码示例发布时间:2022-05-23
下一篇:
Java AbstractIDValueConverter类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap