Example usage for org.springframework.util StringUtils startsWithIgnoreCase

List of usage examples for org.springframework.util StringUtils startsWithIgnoreCase

Introduction

In this page you can find the example usage for org.springframework.util StringUtils startsWithIgnoreCase.

Prototype

public static boolean startsWithIgnoreCase(@Nullable String str, @Nullable String prefix) 

Source Link

Document

Test if the given String starts with the specified prefix, ignoring upper/lower case.

Usage

From source file:org.fosstrak.ale.server.type.FileSubscriberOutputChannel.java

public FileSubscriberOutputChannel(String notificationURI) throws InvalidURIException {
    super(notificationURI);
    try {//from ww  w . j  a  va2  s  .com
        uri = new URI(notificationURI.replaceAll("\\\\", "/"));
        path = StringUtils.startsWithIgnoreCase(uri.getPath(), "/") ? uri.getPath().substring(1)
                : uri.getPath();
        if ("".equalsIgnoreCase(path) || StringUtils.endsWithIgnoreCase(path, "/")) {
            throw new InvalidURIException("missing filename");
        }
        host = (uri.getHost() == null) ? LOCALHOST.toLowerCase() : uri.getHost();
        if (!(LOCALHOST.equalsIgnoreCase(getHost()))) {
            throw new InvalidURIException("This implementation can not write reports to a remote file.");
        }
        if (!("FILE".equalsIgnoreCase(uri.getScheme()))) {
            LOG.error("invalid scheme: " + uri.getScheme());
            throw new InvalidURIException("invalid scheme: " + uri.getScheme());
        }
    } catch (Exception e) {
        LOG.error("malformed URI");
        throw new InvalidURIException("malformed URI: ", e);
    }
}

From source file:com.uimirror.image.form.UimImageFormParam.java

public boolean isPathSkipable() {
    return StringUtils.startsWithIgnoreCase(instructions, "ss");
}

From source file:org.mitre.openid.connect.config.ConfigurationPropertiesBean.java

/**
 * Endpoints protected by TLS must have https scheme in the URI.
 * @throws HttpsUrlRequiredException//from ww w  . j  a va 2s .c o  m
 */
@PostConstruct
public void checkConfigConsistency() {
    if (!StringUtils.startsWithIgnoreCase(issuer, "https")) {
        if (this.forceHttps) {
            logger.error("Configured issuer url is not using https scheme. Server will be shut down!");
            throw new BeanCreationException("Issuer is not using https scheme as required: " + issuer);
        } else {
            logger.warn("\n\n**\n** WARNING: Configured issuer url is not using https scheme.\n**\n\n");
        }
    }

    if (languageNamespaces == null || languageNamespaces.isEmpty()) {
        logger.error("No configured language namespaces! Text rendering will fail!");
    }
}

From source file:io.gravitee.policy.oauth2.Oauth2Policy.java

@OnRequest
public void onRequest(Request request, Response response, ExecutionContext executionContext,
        PolicyChain policyChain) {// w  ww .  ja  va  2  s . c om
    logger.debug("Read access_token from request {}", request.id());

    OAuth2Resource oauth2 = executionContext.getComponent(ResourceManager.class)
            .getResource(oAuth2PolicyConfiguration.getOauthResource(), OAuth2Resource.class);

    if (oauth2 == null) {
        policyChain.failWith(PolicyResult.failure(HttpStatusCode.UNAUTHORIZED_401,
                "No OAuth authorization server has been configured"));
        return;
    }

    List<String> authorizationHeaders = request.headers().get(HttpHeaders.AUTHORIZATION);

    if (authorizationHeaders == null || authorizationHeaders.isEmpty()) {
        sendError(response, policyChain, "invalid_request", "No OAuth authorization header was supplied");
        return;
    }

    Optional<String> optionalHeaderAccessToken = authorizationHeaders.stream()
            .filter(h -> StringUtils.startsWithIgnoreCase(h, BEARER_AUTHORIZATION_TYPE)).findFirst();
    if (!optionalHeaderAccessToken.isPresent()) {
        sendError(response, policyChain, "invalid_request", "No OAuth authorization header was supplied");
        return;
    }

    String accessToken = optionalHeaderAccessToken.get().substring(BEARER_AUTHORIZATION_TYPE.length()).trim();
    if (accessToken.isEmpty()) {
        sendError(response, policyChain, "invalid_request", "No OAuth access token was supplied");
        return;
    }

    // Set access_token in context
    executionContext.setAttribute(CONTEXT_ATTRIBUTE_OAUTH_ACCESS_TOKEN, accessToken);

    // Validate access token
    oauth2.introspect(accessToken, handleResponse(policyChain, request, response, executionContext));
}

From source file:com.excilys.ebi.bank.jdbc.SimpleBatchResourceDatabasePopulator.java

/**
 * Execute the given SQL script.//w w  w  .  ja va  2  s  .co m
 * <p>
 * The script will normally be loaded by classpath. There should be one
 * statement per line. Any {@link #setSeparator(String) statement
 * separators} will be removed.
 * <p>
 * <b>Do not use this method to execute DDL if you expect rollback.</b>
 *
 * @param connection
 *            the JDBC Connection with which to perform JDBC operations
 * @param resource
 *            the resource (potentially associated with a specific encoding)
 *            to load the SQL script from
 * @param continueOnError
 *            whether or not to continue without throwing an exception in
 *            the event of an error
 * @param ignoreFailedDrops
 *            whether of not to continue in the event of specifically an
 *            error on a <code>DROP</code>
 */
private void executeSqlScript(Connection connection, EncodedResource resource, boolean continueOnError,
        boolean ignoreFailedDrops) throws SQLException, IOException {

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Executing SQL script from " + resource);
    }

    long startTime = System.currentTimeMillis();
    Iterator<String> statements = IOUtils.lineIterator(resource.getReader());
    int lineNumber = 0;

    boolean initialAutoCommitState = connection.getAutoCommit();

    connection.setAutoCommit(false);
    Statement stmt = connection.createStatement();
    try {
        while (statements.hasNext()) {
            String statement = statements.next();
            lineNumber++;
            try {
                stmt.addBatch(statement);

                if (lineNumber % batchSize == 0) {
                    stmt.executeBatch();
                    connection.commit();
                }
            } catch (SQLException ex) {
                boolean dropStatement = StringUtils.startsWithIgnoreCase(statement.trim(), "drop");
                if (continueOnError || (dropStatement && ignoreFailedDrops)) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Failed to execute SQL script statement at line " + lineNumber
                                + " of resource " + resource + ": " + statement, ex);
                    }
                } else {
                    Exception nextException = ex.getNextException();
                    throw new ScriptStatementFailedException(statement, lineNumber, resource,
                            nextException != null ? nextException : ex);
                }
            }
        }
    } finally {
        stmt.executeBatch();
        connection.commit();

        connection.setAutoCommit(initialAutoCommitState);

        try {
            stmt.close();
        } catch (Throwable ex) {
            LOGGER.debug("Could not close JDBC Statement", ex);
        }
    }
    long elapsedTime = System.currentTimeMillis() - startTime;
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Done executing SQL script from " + resource + " in " + elapsedTime + " ms.");
    }
}

From source file:com.sfs.whichdoctor.beans.SearchHistoryBean.java

/**
 * Gets the search for a supplied type.//from w w  w  .  j  av  a2 s  . c  om
 *
 * @param type the type
 * @return the search
 */
public final SearchBean getSearch(final String type) {
    SearchBean search = null;

    if (StringUtils.startsWithIgnoreCase(type, "people")) {
        search = this.getPersonSearch();
    }
    if (StringUtils.startsWithIgnoreCase(type, "organisation")) {
        search = this.getOrganisationSearch();
    }
    if (StringUtils.startsWithIgnoreCase(type, "debit")) {
        search = this.getDebitSearch();
    }
    if (StringUtils.startsWithIgnoreCase(type, "credit")) {
        search = this.getCreditSearch();
    }
    if (StringUtils.startsWithIgnoreCase(type, "receipt")) {
        search = this.getReceiptSearch();
    }
    if (StringUtils.startsWithIgnoreCase(type, "reimbursement")) {
        search = this.getReimbursementSearch();
    }
    if (StringUtils.startsWithIgnoreCase(type, "group")) {
        search = this.getGroupSearch();
    }
    if (StringUtils.startsWithIgnoreCase(type, "rotation")) {
        search = this.getRotationSearch();
    }
    if (StringUtils.startsWithIgnoreCase(type, "isb")) {
        search = this.getIsbEntitySearch();
    }
    if (StringUtils.startsWithIgnoreCase(type, "addressverification")) {
        search = this.getAddressVerificationSearch();
    }

    return search;
}

From source file:com.mawujun.util.web.UrlPathHelper.java

/**
 * Return the path within the web application for the given request.
 * <p>Detects include request URL if called within a RequestDispatcher include.
 * @param request current HTTP request/*from ww  w .  j  a v a  2  s .  com*/
 * @return the path within the web application
 */
public String getPathWithinApplication(HttpServletRequest request) {
    String contextPath = getContextPath(request);
    String requestUri = getRequestUri(request);
    if (StringUtils.startsWithIgnoreCase(requestUri, contextPath)) {
        // Normal case: URI contains context path.
        String path = requestUri.substring(contextPath.length());
        return (StringUtils.hasText(path) ? path : "/");
    } else {
        // Special case: rather unusual.
        return requestUri;
    }
}

From source file:org.artifactory.storage.db.spring.DbConfigFactory.java

private DataSource getDataSourceFromBeanOrJndi(StorageProperties storageProperties, String suffix) {
    DataSource result = null;//from   w  w  w  .j  av  a2  s . c  o  m
    String connectionUrl = storageProperties.getConnectionUrl();
    if (StringUtils.startsWithIgnoreCase(connectionUrl, BEAN_PREFIX)) {
        result = beanFactory.getBean(connectionUrl.substring(BEAN_PREFIX.length()) + suffix, DataSource.class);
    } else if (StringUtils.startsWithIgnoreCase(connectionUrl, JNDI_PREFIX)) {
        String jndiName = connectionUrl.substring(JNDI_PREFIX.length());
        JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
        jndiObjectFactoryBean.setJndiName(jndiName + suffix);
        try {
            jndiObjectFactoryBean.afterPropertiesSet();
        } catch (NamingException e) {
            throw new RuntimeException(e);
        }
        result = (DataSource) jndiObjectFactoryBean.getObject();
    }
    return result;
}

From source file:org.flowable.common.rest.multipart.PutAwareStandardServletMultiPartResolver.java

/**
 * Utility method that determines whether the request contains multipart content.
 *
 * @param request//www . jav a2s  .c  om
 *     The servlet request to be evaluated. Must be non-null.
 * @return <code>true</code> if the request is multipart; {@code false} otherwise.
 * @see org.apache.commons.fileupload.servlet.ServletFileUpload#isMultipartContent(HttpServletRequest)
 */
public static final boolean isMultipartContent(HttpServletRequest request) {
    final String method = request.getMethod().toLowerCase();
    if (!method.equalsIgnoreCase("post") && !method.equalsIgnoreCase("put")) {
        return false;
    }

    String contentType = request.getContentType();
    return StringUtils.startsWithIgnoreCase(contentType, "multipart/");
}