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


Java Strings.isNullOrEmpty方法代码示例

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


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

示例1: setOrigin

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
private boolean setOrigin(final HttpResponse response) {
    final String origin = request.headers().get(HttpHeaderNames.ORIGIN);
    if (!Strings.isNullOrEmpty(origin)) {
        if ("null".equals(origin) && config.isNullOriginAllowed()) {
            setAnyOrigin(response);
            return true;
        }

        if (config.isAnyOriginSupported()) {
            if (config.isCredentialsAllowed()) {
                echoRequestOrigin(response);
                setVaryHeader(response);
            } else {
                setAnyOrigin(response);
            }
            return true;
        }
        if (config.isOriginAllowed(origin)) {
            setOrigin(response, origin);
            setVaryHeader(response);
            return true;
        }
    }
    return false;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:Netty4CorsHandler.java

示例2: RosetteApiWrapper

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
RosetteApiWrapper(String apiKey, String altUrl) {
    if (Strings.isNullOrEmpty(apiKey)) {
        apiKey = System.getenv("ROSETTE_API_KEY");
    }

    if (Strings.isNullOrEmpty(altUrl)) {
        altUrl = System.getenv("ROSETTE_API_URL");
    }

    if ((HttpRosetteAPI.DEFAULT_URL_BASE.equalsIgnoreCase(altUrl) || Strings.isNullOrEmpty(altUrl)) && Strings.isNullOrEmpty(apiKey)) {
        throw new ElasticsearchException("Rosette plugin requires setting an API Key either via the '" + RosetteTextAnalysisPlugin.ROSETTE_API_KEY.getKey() + "' setting, or the 'ROSETTE_API_KEY' environment variable.");
    }

    HttpRosetteAPI.Builder clientBuilder = new HttpRosetteAPI.Builder();
    clientBuilder.key(apiKey).additionalHeader("X-RosetteAPI-App", APP_HEADER);
    if (!Strings.isNullOrEmpty(altUrl)) {
        LOGGER.info("Using alternative URL for Rosette API at : " + altUrl);
        clientBuilder.url(altUrl);
    }
    httpRosetteAPI = clientBuilder.build();
}
 
开发者ID:rosette-api,项目名称:rosette-elasticsearch-plugin,代码行数:22,代码来源:RosetteApiWrapper.java

示例3: processDocument

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
@Override
public void processDocument(String inputText, IngestDocument ingestDocument) throws Exception {
    // call /sentiment endpoint and set the top result in the field
    DocumentRequest<SentimentOptions> request = new DocumentRequest.Builder<SentimentOptions>().content(inputText).build();
    SentimentResponse response;
    try {
        // RosApi client binding's Jackson needs elevated privilege
        response = AccessController.doPrivileged((PrivilegedAction<SentimentResponse>) () ->
                rosAPI.getHttpRosetteAPI().perform(HttpRosetteAPI.SENTIMENT_SERVICE_PATH, request, SentimentResponse.class)
        );
    } catch (HttpRosetteAPIException ex) {
        LOGGER.error(ex.getErrorResponse().getMessage());
        throw new ElasticsearchException(ex.getErrorResponse().getMessage(), ex);
    }

    if (response.getDocument() != null
            && !Strings.isNullOrEmpty(response.getDocument().getLabel())) {
        ingestDocument.setFieldValue(targetField, response.getDocument().getLabel());
    } else {
        throw new ElasticsearchException(TYPE + " ingest processor failed to determine sentiment of document.");
    }
}
 
开发者ID:rosette-api,项目名称:rosette-elasticsearch-plugin,代码行数:23,代码来源:SentimentProcessor.java

示例4: processDocument

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
@Override
public void processDocument(String inputText, IngestDocument ingestDocument) throws Exception {
    // call /categories endpoint and set the top result in the field
    DocumentRequest<CategoriesOptions> request = new DocumentRequest.Builder<CategoriesOptions>().content(inputText).build();
    CategoriesResponse response;
    try {
        // RosApi client binding's Jackson needs elevated privilege
        response = AccessController.doPrivileged((PrivilegedAction<CategoriesResponse>) () ->
                rosAPI.getHttpRosetteAPI().perform(HttpRosetteAPI.CATEGORIES_SERVICE_PATH, request, CategoriesResponse.class)
        );
    } catch (HttpRosetteAPIException ex) {
        LOGGER.error(ex.getErrorResponse().getMessage());
        throw new ElasticsearchException(ex.getErrorResponse().getMessage(), ex);
    }

    if (response.getCategories() != null
            && !response.getCategories().isEmpty()
            && response.getCategories().get(0) != null
            && !Strings.isNullOrEmpty(response.getCategories().get(0).getLabel())) {
        ingestDocument.setFieldValue(targetField, response.getCategories().get(0).getLabel());
    } else {
        throw new ElasticsearchException(TYPE + " ingest processor failed to categorize document.");
    }
}
 
开发者ID:rosette-api,项目名称:rosette-elasticsearch-plugin,代码行数:25,代码来源:CategoriesProcessor.java

示例5: setCorsResponseHeaders

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
public static void setCorsResponseHeaders(HttpRequest request, HttpResponse resp, CorsConfig config) {
    if (!config.isCorsSupportEnabled()) {
        return;
    }
    String originHeader = request.headers().get(ORIGIN);
    if (!Strings.isNullOrEmpty(originHeader)) {
        final String originHeaderVal;
        if (config.isAnyOriginSupported()) {
            originHeaderVal = ANY_ORIGIN;
        } else if (config.isOriginAllowed(originHeader) || isSameOrigin(originHeader, request.headers().get(HOST))) {
            originHeaderVal = originHeader;
        } else {
            originHeaderVal = null;
        }
        if (originHeaderVal != null) {
            resp.headers().add(ACCESS_CONTROL_ALLOW_ORIGIN, originHeaderVal);
        }
    }
    if (config.isCredentialsAllowed()) {
        resp.headers().add(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:CorsHandler.java

示例6: setOrigin

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
private boolean setOrigin(final HttpResponse response) {
    final String origin = request.headers().get(ORIGIN);
    if (!Strings.isNullOrEmpty(origin)) {
        if ("null".equals(origin) && config.isNullOriginAllowed()) {
            setAnyOrigin(response);
            return true;
        }
        if (config.isAnyOriginSupported()) {
            if (config.isCredentialsAllowed()) {
                echoRequestOrigin(response);
                setVaryHeader(response);
            } else {
                setAnyOrigin(response);
            }
            return true;
        }
        if (config.isOriginAllowed(origin)) {
            setOrigin(response, origin);
            setVaryHeader(response);
            return true;
        }
    }
    return false;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:CorsHandler.java

示例7: validateOrigin

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
private boolean validateOrigin() {
    if (config.isAnyOriginSupported()) {
        return true;
    }

    final String origin = request.headers().get(ORIGIN);
    if (Strings.isNullOrEmpty(origin)) {
        // Not a CORS request so we cannot validate it. It may be a non CORS request.
        return true;
    }

    if ("null".equals(origin) && config.isNullOriginAllowed()) {
        return true;
    }

    // if the origin is the same as the host of the request, then allow
    if (isSameOrigin(origin, request.headers().get(HOST))) {
        return true;
    }

    return config.isOriginAllowed(origin);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:CorsHandler.java

示例8: buildCorsConfig

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
static Netty4CorsConfig buildCorsConfig(Settings settings) {
    if (SETTING_CORS_ENABLED.get(settings) == false) {
        return Netty4CorsConfigBuilder.forOrigins().disable().build();
    }
    String origin = SETTING_CORS_ALLOW_ORIGIN.get(settings);
    final Netty4CorsConfigBuilder builder;
    if (Strings.isNullOrEmpty(origin)) {
        builder = Netty4CorsConfigBuilder.forOrigins();
    } else if (origin.equals(ANY_ORIGIN)) {
        builder = Netty4CorsConfigBuilder.forAnyOrigin();
    } else {
        Pattern p = RestUtils.checkCorsSettingForRegex(origin);
        if (p == null) {
            builder = Netty4CorsConfigBuilder.forOrigins(RestUtils.corsSettingAsArray(origin));
        } else {
            builder = Netty4CorsConfigBuilder.forPattern(p);
        }
    }
    if (SETTING_CORS_ALLOW_CREDENTIALS.get(settings)) {
        builder.allowCredentials();
    }
    String[] strMethods = Strings.tokenizeToStringArray(SETTING_CORS_ALLOW_METHODS.get(settings), ",");
    HttpMethod[] methods = Arrays.asList(strMethods)
        .stream()
        .map(HttpMethod::valueOf)
        .toArray(size -> new HttpMethod[size]);
    return builder.allowedRequestMethods(methods)
        .maxAge(SETTING_CORS_MAX_AGE.get(settings))
        .allowedRequestHeaders(Strings.tokenizeToStringArray(SETTING_CORS_ALLOW_HEADERS.get(settings), ","))
        .shortCircuit()
        .build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:Netty4HttpServerTransport.java

示例9: isSameOrigin

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
private static boolean isSameOrigin(final String origin, final String host) {
    if (Strings.isNullOrEmpty(host) == false) {
        // strip protocol from origin
        final String originDomain = SCHEME_PATTERN.matcher(origin).replaceFirst("");
        if (host.equals(originDomain)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:Netty4CorsHandler.java

示例10: parse

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
public static Type parse(String type) {
    if (Strings.isNullOrEmpty(type)) {
        return CONCURRENT;
    }
    try {
        return Type.valueOf(type.toUpperCase(Locale.ROOT));
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("no type support [" + type + "]");
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:11,代码来源:PageCacheRecycler.java

示例11: corsSettingAsArray

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
/**
 * Return the CORS setting as an array of origins.
 *
 * @param corsSetting the CORS allow origin setting as configured by the user;
 *                    should never pass null, but we check for it anyway.
 * @return an array of origins if set, otherwise {@code null}.
 */
public static String[] corsSettingAsArray(String corsSetting) {
    if (Strings.isNullOrEmpty(corsSetting)) {
        return new String[0];
    }
    return Arrays.asList(corsSetting.split(","))
                 .stream()
                 .map(String::trim)
                 .toArray(size -> new String[size]);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:RestUtils.java

示例12: openConnection

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
private URLConnection openConnection(URL aSource) throws IOException {

            // set up the URL connection
            URLConnection connection = aSource.openConnection();
            // modify the headers
            // NB: things like user authentication could go in here too.
            if (hasTimestamp) {
                connection.setIfModifiedSince(timestamp);
            }

            // in case the plugin manager is its own project, this can become an authenticator
            boolean isSecureProcotol = "https".equalsIgnoreCase(aSource.getProtocol());
            boolean isAuthInfoSet = !Strings.isNullOrEmpty(aSource.getUserInfo());
            if (isAuthInfoSet) {
                if (!isSecureProcotol) {
                    throw new IOException("Basic auth is only supported for HTTPS!");
                }
                String basicAuth = Base64.encodeBytes(aSource.getUserInfo().getBytes(StandardCharsets.UTF_8));
                connection.setRequestProperty("Authorization", "Basic " + basicAuth);
            }

            if (connection instanceof HttpURLConnection) {
                ((HttpURLConnection) connection).setInstanceFollowRedirects(false);
                connection.setUseCaches(true);
                connection.setConnectTimeout(5000);
            }
            connection.setRequestProperty("ES-Version", Version.CURRENT.toString());
            connection.setRequestProperty("ES-Build-Hash", Build.CURRENT.hashShort());
            connection.setRequestProperty("User-Agent", "elasticsearch-plugin-manager");

            // connect to the remote site (may take some time)
            connection.connect();

            // First check on a 301 / 302 (moved) response (HTTP only)
            if (connection instanceof HttpURLConnection) {
                HttpURLConnection httpConnection = (HttpURLConnection) connection;
                int responseCode = httpConnection.getResponseCode();
                if (responseCode == HttpURLConnection.HTTP_MOVED_PERM ||
                        responseCode == HttpURLConnection.HTTP_MOVED_TEMP ||
                        responseCode == HttpURLConnection.HTTP_SEE_OTHER) {
                    String newLocation = httpConnection.getHeaderField("Location");
                    URL newURL = new URL(newLocation);
                    if (!redirectionAllowed(aSource, newURL)) {
                        return null;
                    }
                    return openConnection(newURL);
                }
                // next test for a 304 result (HTTP only)
                long lastModified = httpConnection.getLastModified();
                if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED
                        || (lastModified != 0 && hasTimestamp && timestamp >= lastModified)) {
                    // not modified so no file download. just return
                    // instead and trace out something so the user
                    // doesn't think that the download happened when it
                    // didn't
                    return null;
                }
                // test for 401 result (HTTP only)
                if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
                    String message = "HTTP Authorization failure";
                    throw new IOException(message);
                }
            }

            //REVISIT: at this point even non HTTP connections may
            //support the if-modified-since behaviour -we just check
            //the date of the content and skip the write if it is not
            //newer. Some protocols (FTP) don't include dates, of
            //course.
            return connection;
        }
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:72,代码来源:HttpDownloadHelper.java

示例13: put

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
public Builder put(String tenantName, String key, String value) {
    if (Strings.isNullOrEmpty(tenantName)) {
        return put(key, value);
    }
    map.put(TenantMetadata.TENANT_SETTING_PREFIX + "." + tenantName + "." + key, value);
    return this;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:Settings.java

示例14: buildCorsConfig

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
private CorsConfig buildCorsConfig(Settings settings) {
    if (settings.getAsBoolean(SETTING_CORS_ENABLED, false) == false) {
        return CorsConfigBuilder.forOrigins().disable().build();
    }
    String origin = settings.get(SETTING_CORS_ALLOW_ORIGIN);
    final CorsConfigBuilder builder;
    if (Strings.isNullOrEmpty(origin)) {
        builder = CorsConfigBuilder.forOrigins();
    } else if (origin.equals(ANY_ORIGIN)) {
        builder = CorsConfigBuilder.forAnyOrigin();
    } else {
        Pattern p = RestUtils.checkCorsSettingForRegex(origin);
        if (p == null) {
            builder = CorsConfigBuilder.forOrigins(RestUtils.corsSettingAsArray(origin));
        } else {
            builder = CorsConfigBuilder.forPattern(p);
        }
    }
    if (settings.getAsBoolean(SETTING_CORS_ALLOW_CREDENTIALS, false)) {
        builder.allowCredentials();
    }
    String[] strMethods = settings.getAsArray(SETTING_CORS_ALLOW_METHODS, DEFAULT_CORS_METHODS);
    HttpMethod[] methods = new HttpMethod[strMethods.length];
    for (int i = 0; i < methods.length; i++) {
        methods[i] = HttpMethod.valueOf(strMethods[i]);
    }
    return builder.allowedRequestMethods(methods)
                  .maxAge(settings.getAsInt(SETTING_CORS_MAX_AGE, DEFAULT_CORS_MAX_AGE))
                  .allowedRequestHeaders(settings.getAsArray(SETTING_CORS_ALLOW_HEADERS, DEFAULT_CORS_HEADERS))
                  .shortCircuit()
                  .build();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:33,代码来源:NettyHttpServerTransport.java

示例15: parse

import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
public static Loading parse(String loading, Loading defaultValue) {
    if (Strings.isNullOrEmpty(loading)) {
        return defaultValue;
    } else if (EAGER_GLOBAL_ORDINALS_VALUE.equalsIgnoreCase(loading)) {
        return EAGER_GLOBAL_ORDINALS;
    } else if (EAGER_VALUE.equalsIgnoreCase(loading)) {
        return EAGER;
    } else if (LAZY_VALUE.equalsIgnoreCase(loading)) {
        return LAZY;
    } else {
        throw new MapperParsingException("Unknown [" + KEY + "] value: [" + loading + "]");
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:MappedFieldType.java


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