List of usage examples for org.springframework.util StringUtils replace
public static String replace(String inString, String oldPattern, @Nullable String newPattern)
From source file:org.springframework.integration.jdbc.store.JdbcMessageStore.java
/** * Replace patterns in the input to produce a valid SQL query. This implementation lazily initializes a * simple map-based cache, only replacing the table prefix on the first access to a named query. Further * accesses will be resolved from the cache. * * @param base the SQL query to be transformed * @return a transformed query with replacements *//*from w w w . j av a 2 s . c o m*/ protected String getQuery(Query base) { String query = this.queryCache.get(base); if (query == null) { query = StringUtils.replace(base.getSql(), "%PREFIX%", this.tablePrefix); this.queryCache.put(base, query); } return query; }
From source file:org.springframework.messaging.simp.user.DefaultUserDestinationResolver.java
private ParseResult parseMessage(MessageHeaders headers, String sourceDest) { int prefixEnd = this.prefix.length(); int userEnd = sourceDest.indexOf('/', prefixEnd); Assert.isTrue(userEnd > 0, "Expected destination pattern \"/user/{userId}/**\""); String actualDest = sourceDest.substring(userEnd); String subscribeDest = this.prefix.substring(0, prefixEnd - 1) + actualDest; String userName = sourceDest.substring(prefixEnd, userEnd); userName = StringUtils.replace(userName, "%2F", "/"); String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); Set<String> sessionIds; if (userName.equals(sessionId)) { userName = null;//from www . j ava2 s. c o m sessionIds = Collections.singleton(sessionId); } else { sessionIds = getSessionIdsByUser(userName, sessionId); } if (isRemoveLeadingSlash()) { actualDest = actualDest.substring(1); } return new ParseResult(sourceDest, actualDest, subscribeDest, sessionIds, userName); }
From source file:org.springframework.security.config.method.ProtectPointcutPostProcessor.java
/** * @see org.springframework.aop.aspectj.AspectJExpressionPointcut#replaceBooleanOperators *//*from w w w . j a va 2 s . com*/ private String replaceBooleanOperators(String pcExpr) { pcExpr = StringUtils.replace(pcExpr, " and ", " && "); pcExpr = StringUtils.replace(pcExpr, " or ", " || "); pcExpr = StringUtils.replace(pcExpr, " not ", " ! "); return pcExpr; }
From source file:org.springframework.session.jdbc.JdbcOperationsSessionRepository.java
private String getQuery(String base) { return StringUtils.replace(base, "%TABLE_NAME%", this.tableName); }
From source file:org.springframework.web.servlet.resource.ResourceUrlProvider.java
/** * Compare the given path against configured resource handler mappings and * if a match is found use the {@code ResourceResolver} chain of the matched * {@code ResourceHttpRequestHandler} to resolve the URL path to expose for * public use./*from w w w . ja v a2 s.co m*/ * <p>It is expected that the given path is what Spring MVC would use for * request mapping purposes, i.e. excluding context and servlet path portions. * <p>If several handler mappings match, the handler used will be the one * configured with the most specific pattern. * @param lookupPath the lookup path to check * @return the resolved public URL path, or {@code null} if unresolved */ @Nullable public final String getForLookupPath(String lookupPath) { // Clean duplicate slashes or pathWithinPattern won't match lookupPath String previous; do { previous = lookupPath; lookupPath = StringUtils.replace(lookupPath, "//", "/"); } while (!lookupPath.equals(previous)); if (logger.isTraceEnabled()) { logger.trace("Getting resource URL for lookup path \"" + lookupPath + "\""); } List<String> matchingPatterns = new ArrayList<>(); for (String pattern : this.handlerMap.keySet()) { if (getPathMatcher().match(pattern, lookupPath)) { matchingPatterns.add(pattern); } } if (!matchingPatterns.isEmpty()) { Comparator<String> patternComparator = getPathMatcher().getPatternComparator(lookupPath); Collections.sort(matchingPatterns, patternComparator); for (String pattern : matchingPatterns) { String pathWithinMapping = getPathMatcher().extractPathWithinPattern(pattern, lookupPath); String pathMapping = lookupPath.substring(0, lookupPath.indexOf(pathWithinMapping)); if (logger.isTraceEnabled()) { logger.trace("Invoking ResourceResolverChain for URL pattern \"" + pattern + "\""); } ResourceHttpRequestHandler handler = this.handlerMap.get(pattern); ResourceResolverChain chain = new DefaultResourceResolverChain(handler.getResourceResolvers()); String resolved = chain.resolveUrlPath(pathWithinMapping, handler.getLocations()); if (resolved == null) { continue; } if (logger.isTraceEnabled()) { logger.trace("Resolved public resource URL path \"" + resolved + "\""); } return pathMapping + resolved; } } if (logger.isDebugEnabled()) { logger.debug("No matching resource mapping for lookup path \"" + lookupPath + "\""); } return null; }
From source file:org.springmodules.validation.valang.parser.ValangParser.java
private String replace(String s) { String tmpS = s;//from w ww. j av a 2s . c o m tmpS = StringUtils.replace(tmpS, "\\'", "'"); tmpS = StringUtils.replace(tmpS, "\\n", "\n"); tmpS = StringUtils.replace(tmpS, "\\r", "\r"); tmpS = StringUtils.replace(tmpS, "\\t", "\t"); tmpS = StringUtils.replace(tmpS, "\\b", "\b"); tmpS = StringUtils.replace(tmpS, "\\f", "\f"); tmpS = StringUtils.replace(tmpS, "\\\\", "\\"); return tmpS; }