當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。