List of usage examples for org.springframework.util StringUtils startsWithIgnoreCase
public static boolean startsWithIgnoreCase(@Nullable String str, @Nullable String prefix)
From source file:org.kuali.kra.award.service.impl.AwardHierarchyUIServiceImpl.java
protected boolean canUseExistingTMSessionObject(String awardNumber) { String sessionObjectKey = GlobalVariables.getUserSession().getKualiSessionId() + Constants.TIME_AND_MONEY_DOCUMENT_STRING_FOR_SESSION; String prefix = null;/*from ww w . ja v a 2 s.c om*/ TimeAndMoneyDocument tmDocFromSession = (TimeAndMoneyDocument) GlobalVariables.getUserSession() .retrieveObject(sessionObjectKey); if (tmDocFromSession == null) { return false; } Map<String, AwardHierarchyNode> tmpNodes = tmDocFromSession.getAwardHierarchyNodes(); if (tmpNodes != null && CollectionUtils.isNotEmpty(tmpNodes.keySet())) { for (String tempAwardNumber : tmpNodes.keySet()) { prefix = tempAwardNumber.substring(0, tempAwardNumber.indexOf("-")); if (!StringUtils.startsWithIgnoreCase(awardNumber, prefix)) { return false; } } } return true; }
From source file:org.openmrs.module.emr.api.EmrServiceComponentTest.java
@Test public void testFindAPIPrivileges() throws Exception { UserService userService = Context.getUserService(); List<Role> roles = userService.getAllRoles(); if (roles != null && roles.size() > 0) { for (Role role : roles) { log.debug("roleName:" + role.getName()); }/*from w ww .ja va2 s .c o m*/ } Role fullRole = userService.getRole(EmrConstants.PRIVILEGE_LEVEL_FULL_ROLE); if (fullRole == null) { fullRole = new Role(); fullRole.setName(EmrConstants.PRIVILEGE_LEVEL_FULL_ROLE); fullRole.setRole(EmrConstants.PRIVILEGE_LEVEL_FULL_ROLE); fullRole.setDescription(EmrConstants.PRIVILEGE_LEVEL_FULL_ROLE); userService.saveRole(fullRole); } List<Privilege> allPrivileges = userService.getAllPrivileges(); if (allPrivileges != null && allPrivileges.size() > 0) { for (Privilege privilege : allPrivileges) { log.debug("" + privilege.getName()); String privilegeName = privilege.getName(); if (!fullRole.hasPrivilege(privilegeName)) { if (!StringUtils.startsWithIgnoreCase(privilegeName, EmrConstants.PRIVILEGE_PREFIX_APP) && !StringUtils.startsWithIgnoreCase(privilegeName, EmrConstants.PRIVILEGE_PREFIX_TASK)) { fullRole.addPrivilege(privilege); } } } } userService.saveRole(fullRole); assertEquals(fullRole.getName(), EmrConstants.PRIVILEGE_LEVEL_FULL_ROLE); }
From source file:org.springframework.cloud.stream.app.http.source.DefaultMixedCaseContentTypeHttpHeaderMapper.java
/** * Map from the integration MessageHeaders to an HttpHeaders instance. * Depending on which type of adapter is using this mapper, the HttpHeaders might be * for an HTTP request (outbound adapter) or for an HTTP response (inbound adapter). *//*from www.j a va 2 s. co m*/ @Override public void fromHeaders(MessageHeaders headers, HttpHeaders target) { if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("outboundHeaderNames={0}", CollectionUtils.arrayToList(this.outboundHeaderNames))); } for (Entry<String, Object> entry : headers.entrySet()) { String name = entry.getKey(); String lowerName = name.toLowerCase(); if (this.shouldMapOutboundHeader(lowerName)) { Object value = entry.getValue(); if (value != null) { if (!HTTP_REQUEST_HEADER_NAMES_LOWER.contains(lowerName) && !HTTP_RESPONSE_HEADER_NAMES_LOWER.contains(lowerName) && !MessageHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) { // prefix the user-defined header names if not already prefixed name = StringUtils.startsWithIgnoreCase(name, this.userDefinedHeaderPrefix) ? name : this.userDefinedHeaderPrefix + name; } if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value)); } this.setHttpHeader(target, name, value); } } } }
From source file:org.springframework.cloud.stream.app.http.source.DefaultMixedCaseContentTypeHttpHeaderMapper.java
/** * Map from an HttpHeaders instance to integration MessageHeaders. * Depending on which type of adapter is using this mapper, the HttpHeaders might be * from an HTTP request (inbound adapter) or from an HTTP response (outbound adapter). *//*ww w .ja va 2 s . c om*/ @Override public Map<String, Object> toHeaders(HttpHeaders source) { if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("inboundHeaderNames={0}", CollectionUtils.arrayToList(this.inboundHeaderNames))); } Map<String, Object> target = new HashMap<String, Object>(); Set<String> headerNames = source.keySet(); for (String name : headerNames) { String lowerName = name.toLowerCase(); if (this.shouldMapInboundHeader(lowerName)) { if (!HTTP_REQUEST_HEADER_NAMES_LOWER.contains(lowerName) && !HTTP_RESPONSE_HEADER_NAMES_LOWER.contains(lowerName)) { String prefixedName = StringUtils.startsWithIgnoreCase(name, this.userDefinedHeaderPrefix) ? name : this.userDefinedHeaderPrefix + name; Object value = source.containsKey(prefixedName) ? this.getHttpHeader(source, prefixedName) : this.getHttpHeader(source, name); if (value != null) { if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value)); } this.setMessageHeader(target, name, value); } } else { Object value = this.getHttpHeader(source, name); if (value != null) { if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value)); } if (CONTENT_TYPE.equalsIgnoreCase(name)) { name = MessageHeaders.CONTENT_TYPE; } this.setMessageHeader(target, name, value); } } } } return target; }
From source file:org.springframework.data.hadoop.store.support.OutputStoreObjectSupport.java
/** * Rename file using prefix and suffix settings. * * @param path the path to rename//from w w w . j av a 2 s . co m */ protected void renameFile(Path path) { // bail out if there's no in-writing settings if (!StringUtils.hasText(prefix) && !StringUtils.hasText(suffix)) { return; } String name = path.getName(); if (StringUtils.startsWithIgnoreCase(name, prefix)) { name = name.substring(prefix.length()); } if (StringUtils.endsWithIgnoreCase(name, suffix)) { name = name.substring(0, name.length() - suffix.length()); } Path toPath = new Path(path.getParent(), name); try { FileSystem fs = path.getFileSystem(getConfiguration()); boolean succeed; try { fs.delete(toPath, false); succeed = fs.rename(path, toPath); } catch (Exception e) { throw new StoreException("Failed renaming from " + path + " to " + toPath, e); } if (!succeed) { throw new StoreException( "Failed renaming from " + path + " to " + toPath + " because hdfs returned false"); } } catch (IOException e) { log.error("Error renaming file", e); throw new StoreException("Error renaming file", e); } }
From source file:org.springframework.integration.http.support.DefaultHttpHeaderMapper.java
/** * Map from the integration MessageHeaders to an HttpHeaders instance. * Depending on which type of adapter is using this mapper, the HttpHeaders might be * for an HTTP request (outbound adapter) or for an HTTP response (inbound adapter). */// ww w. ja v a2 s. c om public void fromHeaders(MessageHeaders headers, HttpHeaders target) { if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("outboundHeaderNames={0}", CollectionUtils.arrayToList(outboundHeaderNames))); } Set<String> headerNames = headers.keySet(); for (String name : headerNames) { if (this.shouldMapOutboundHeader(name)) { Object value = headers.get(name); if (value != null) { if (!this.containsElementIgnoreCase(HTTP_REQUEST_HEADER_NAMES, name) && !this.containsElementIgnoreCase(HTTP_RESPONSE_HEADER_NAMES, name)) { // prefix the user-defined header names if not already prefixed name = StringUtils.startsWithIgnoreCase(name, this.userDefinedHeaderPrefix) ? name : this.userDefinedHeaderPrefix + name; } if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value)); } this.setHttpHeader(target, name, value); } } } }
From source file:org.springframework.integration.http.support.DefaultHttpHeaderMapper.java
/** * Map from an HttpHeaders instance to integration MessageHeaders. * Depending on which type of adapter is using this mapper, the HttpHeaders might be * from an HTTP request (inbound adapter) or from an HTTP response (outbound adapter). *///from w w w. j a va 2s . c o m public Map<String, Object> toHeaders(HttpHeaders source) { if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("inboundHeaderNames={0}", CollectionUtils.arrayToList(inboundHeaderNames))); } Map<String, Object> target = new HashMap<String, Object>(); Set<String> headerNames = source.keySet(); for (String name : headerNames) { if (this.shouldMapInboundHeader(name)) { if (!ObjectUtils.containsElement(HTTP_REQUEST_HEADER_NAMES, name) && !ObjectUtils.containsElement(HTTP_RESPONSE_HEADER_NAMES, name)) { String prefixedName = StringUtils.startsWithIgnoreCase(name, this.userDefinedHeaderPrefix) ? name : this.userDefinedHeaderPrefix + name; Object value = source.containsKey(prefixedName) ? this.getHttpHeader(source, prefixedName) : this.getHttpHeader(source, name); if (value != null) { if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value)); } this.setMessageHeader(target, name, value); } } else { Object value = this.getHttpHeader(source, name); if (value != null) { if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value)); } this.setMessageHeader(target, name, value); } } } } return target; }
From source file:org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.java
/** * Execute the given SQL script./* w w w. j a v a 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} */ private void executeSqlScript(Connection connection, EncodedResource resource, boolean continueOnError, boolean ignoreFailedDrops) throws SQLException { if (logger.isInfoEnabled()) { logger.info("Executing SQL script from " + resource); } long startTime = System.currentTimeMillis(); List<String> statements = new LinkedList<String>(); String script; try { script = readScript(resource); } catch (IOException ex) { throw new CannotReadScriptException(resource, ex); } String delimiter = this.separator; if (delimiter == null) { delimiter = DEFAULT_STATEMENT_SEPARATOR; if (!containsSqlScriptDelimiters(script, delimiter)) { delimiter = "\n"; } } splitSqlScript(script, delimiter, this.commentPrefix, statements); int lineNumber = 0; Statement stmt = connection.createStatement(); try { for (String statement : statements) { lineNumber++; try { stmt.execute(statement); int rowsAffected = stmt.getUpdateCount(); if (logger.isDebugEnabled()) { logger.debug(rowsAffected + " returned as updateCount for SQL: " + statement); } } 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 { throw new ScriptStatementFailedException(statement, lineNumber, resource, ex); } } } } finally { 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:org.springframework.jdbc.datasource.init.ScriptUtils.java
/** * Execute the given SQL script.//w w w . ja va 2 s. co m * <p>Statement separators and comments will be removed before executing * individual statements within the supplied script. * <p><strong>Warning</strong>: this method does <em>not</em> release the * provided {@link Connection}. * @param connection the JDBC connection to use to execute the script; already * configured and ready to use * @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 or not to continue in the event of specifically * an error on a {@code DROP} statement * @param commentPrefix the prefix that identifies single-line comments in the * SQL script — typically "--" * @param separator the script statement separator; defaults to * {@value #DEFAULT_STATEMENT_SEPARATOR} if not specified and falls back to * {@value #FALLBACK_STATEMENT_SEPARATOR} as a last resort; may be set to * {@value #EOF_STATEMENT_SEPARATOR} to signal that the script contains a * single statement without a separator * @param blockCommentStartDelimiter the <em>start</em> block comment delimiter; never * {@code null} or empty * @param blockCommentEndDelimiter the <em>end</em> block comment delimiter; never * {@code null} or empty * @throws ScriptException if an error occurred while executing the SQL script * @see #DEFAULT_STATEMENT_SEPARATOR * @see #FALLBACK_STATEMENT_SEPARATOR * @see #EOF_STATEMENT_SEPARATOR * @see org.springframework.jdbc.datasource.DataSourceUtils#getConnection * @see org.springframework.jdbc.datasource.DataSourceUtils#releaseConnection */ public static void executeSqlScript(Connection connection, EncodedResource resource, boolean continueOnError, boolean ignoreFailedDrops, String commentPrefix, @Nullable String separator, String blockCommentStartDelimiter, String blockCommentEndDelimiter) throws ScriptException { try { if (logger.isInfoEnabled()) { logger.info("Executing SQL script from " + resource); } long startTime = System.currentTimeMillis(); String script; try { script = readScript(resource, commentPrefix, separator); } catch (IOException ex) { throw new CannotReadScriptException(resource, ex); } if (separator == null) { separator = DEFAULT_STATEMENT_SEPARATOR; } if (!EOF_STATEMENT_SEPARATOR.equals(separator) && !containsSqlScriptDelimiters(script, separator)) { separator = FALLBACK_STATEMENT_SEPARATOR; } List<String> statements = new LinkedList<>(); splitSqlScript(resource, script, separator, commentPrefix, blockCommentStartDelimiter, blockCommentEndDelimiter, statements); int stmtNumber = 0; Statement stmt = connection.createStatement(); try { for (String statement : statements) { stmtNumber++; try { stmt.execute(statement); int rowsAffected = stmt.getUpdateCount(); if (logger.isDebugEnabled()) { logger.debug(rowsAffected + " returned as update count for SQL: " + statement); SQLWarning warningToLog = stmt.getWarnings(); while (warningToLog != null) { logger.debug("SQLWarning ignored: SQL state '" + warningToLog.getSQLState() + "', error code '" + warningToLog.getErrorCode() + "', message [" + warningToLog.getMessage() + "]"); warningToLog = warningToLog.getNextWarning(); } } } catch (SQLException ex) { boolean dropStatement = StringUtils.startsWithIgnoreCase(statement.trim(), "drop"); if (continueOnError || (dropStatement && ignoreFailedDrops)) { if (logger.isDebugEnabled()) { logger.debug(ScriptStatementFailedException.buildErrorMessage(statement, stmtNumber, resource), ex); } } else { throw new ScriptStatementFailedException(statement, stmtNumber, resource, ex); } } } } finally { try { stmt.close(); } catch (Throwable ex) { logger.debug("Could not close JDBC Statement", ex); } } long elapsedTime = System.currentTimeMillis() - startTime; if (logger.isInfoEnabled()) { logger.info("Executed SQL script from " + resource + " in " + elapsedTime + " ms."); } } catch (Exception ex) { if (ex instanceof ScriptException) { throw (ScriptException) ex; } throw new UncategorizedScriptException( "Failed to execute database script from resource [" + resource + "]", ex); } }
From source file:org.springframework.web.multipart.support.StandardServletMultipartResolver.java
@Override public boolean isMultipart(HttpServletRequest request) { // Same check as in Commons FileUpload... if (!"post".equalsIgnoreCase(request.getMethod())) { return false; }/* w w w . j a v a2s .c o m*/ String contentType = request.getContentType(); return StringUtils.startsWithIgnoreCase(contentType, "multipart/"); }