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


Java XContentFactory.xContent方法代码示例

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


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

示例1: restContentBuilder

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
public static XContentBuilder restContentBuilder(RestRequest request)  
        throws IOException {
    XContentType contentType = XContentType  
            .fromRestContentType(request.header("Content-Type"));  
    if (contentType == null) {  
        // try and guess it from the body, if exists  
        if (request.hasContent()) {  
            contentType = XContentFactory.xContentType(request.content());  
        }  
    }  
    if (contentType == null) {  
        // default to JSON  
        contentType = XContentType.JSON;  
    }  
    BytesStreamOutput out = new BytesStreamOutput();  
    XContentBuilder builder = new XContentBuilder(  
            XContentFactory.xContent(contentType), out);  
  
    if (request.paramAsBoolean("pretty", false)) {  
        builder.prettyPrint();  
    }  
    String casing = request.param("case");  
    if (casing != null && "camelCase".equals(casing)) {  
        builder.fieldCaseConversion(  
                XContentBuilder.FieldCaseConversion.CAMELCASE);  
    } else {  
        builder.fieldCaseConversion(  
                XContentBuilder.FieldCaseConversion.NONE);  
    }  
    return builder;  
}
 
开发者ID:ghostboyzone,项目名称:ESAuthPlugin,代码行数:32,代码来源:ContentBuilder.java

示例2: newBuilder

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
/**
 * Creates a new {@link XContentBuilder} for a response to be sent using this channel. The builder's type is determined by the following
 * logic. If the request has a format parameter that will be used to attempt to map to an {@link XContentType}. If there is no format
 * parameter, the HTTP Accept header is checked to see if it can be matched to a {@link XContentType}. If this first attempt to map
 * fails, the request content type will be used if the value is not {@code null}; if the value is {@code null} the output format falls
 * back to JSON.
 */
@Override
public XContentBuilder newBuilder(@Nullable XContentType requestContentType, boolean useFiltering) throws IOException {
    // try to determine the response content type from the media type or the format query string parameter, with the format parameter
    // taking precedence over the Accept header
    XContentType responseContentType = XContentType.fromMediaTypeOrFormat(format);
    if (responseContentType == null) {
        if (requestContentType != null) {
            // if there was a parsed content-type for the incoming request use that since no format was specified using the query
            // string parameter or the HTTP Accept header
            responseContentType = requestContentType;
        } else {
            // default to JSON output when all else fails
            responseContentType = XContentType.JSON;
        }
    }

    Set<String> includes = Collections.emptySet();
    Set<String> excludes = Collections.emptySet();
    if (useFiltering) {
        Set<String> filters = Strings.splitStringByCommaToSet(filterPath);
        includes = filters.stream().filter(INCLUDE_FILTER).collect(toSet());
        excludes = filters.stream().filter(EXCLUDE_FILTER).map(f -> f.substring(1)).collect(toSet());
    }

    XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(responseContentType), bytesOutput(), includes, excludes);
    if (pretty) {
        builder.prettyPrint().lfAtEnd();
    }

    builder.humanReadable(human);
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:AbstractRestChannel.java

示例3: assertBinary

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
protected void assertBinary(XContentBuilder expected, XContentBuilder builder) {
    assertNotNull(builder);
    assertNotNull(expected);

    try {
        XContent xContent = XContentFactory.xContent(builder.contentType());
        XContentParser jsonParser = createParser(xContent, expected.bytes());
        XContentParser testParser = createParser(xContent, builder.bytes());

        while (true) {
            XContentParser.Token token1 = jsonParser.nextToken();
            XContentParser.Token token2 = testParser.nextToken();
            if (token1 == null) {
                assertThat(token2, nullValue());
                return;
            }
            assertThat(token1, equalTo(token2));
            switch (token1) {
                case FIELD_NAME:
                    assertThat(jsonParser.currentName(), equalTo(testParser.currentName()));
                    break;
                case VALUE_STRING:
                    assertThat(jsonParser.text(), equalTo(testParser.text()));
                    break;
                case VALUE_NUMBER:
                    assertThat(jsonParser.numberType(), equalTo(testParser.numberType()));
                    assertThat(jsonParser.numberValue(), equalTo(testParser.numberValue()));
                    break;
            }
        }
    } catch (Exception e) {
        fail("Fail to verify the result of the XContentBuilder: " + e.getMessage());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:AbstractFilteringJsonGeneratorTestCase.java

示例4: newBuilder

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
public XContentBuilder newBuilder(@Nullable BytesReference autoDetectSource, boolean useFiltering) throws IOException {
    XContentType contentType = XContentType.fromRestContentType(request.param("format", request.header("Content-Type")));
    if (contentType == null) {
        // try and guess it from the auto detect source
        if (autoDetectSource != null) {
            contentType = XContentFactory.xContentType(autoDetectSource);
        }
    }
    if (contentType == null) {
        // default to JSON
        contentType = XContentType.JSON;
    }

    String[] filters = useFiltering ? request.paramAsStringArrayOrEmptyIfAll("filter_path") :  null;
    XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(contentType), bytesOutput(), filters);
    if (request.paramAsBoolean("pretty", false)) {
        builder.prettyPrint().lfAtEnd();
    }

    builder.humanReadable(request.paramAsBoolean("human", builder.humanReadable()));

    String casing = request.param("case");
    if (casing != null) {
        String msg = "Parameter 'case' has been deprecated, all responses will use underscore casing in the future";
        DEPRECATION_LOGGER.deprecated(msg);
    }
    if (casing != null && "camelCase".equals(casing)) {
        builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.CAMELCASE);
    } else {
        // we expect all REST interfaces to write results in underscore casing, so
        // no need for double casing
        builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.NONE);
    }
    return builder;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:36,代码来源:RestChannel.java


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