/** * If a pointcut expression has been specified in XML, the user cannot * write {@code and} as "&&" (though && will work). * We also allow {@code and} between two pointcut sub-expressions. * <p>This method converts back to {@code &&} for the AspectJ pointcut parser. */ private String replaceBooleanOperators(String pcExpr) { String result = StringUtils.replace(pcExpr, " and ", " && "); result = StringUtils.replace(result, " or ", " || "); result = StringUtils.replace(result, " not ", " ! "); return result; }
/** * Delete all occurrences of the given substring. * @param inString the original {@code String} * @param pattern the pattern to delete all occurrences of * @return the resulting {@code String} */ public static String delete(String inString, String pattern) { return replace(inString, pattern, ""); }
/** * If a type pattern has been specified in XML, the user cannot * write {@code and} as "&&" (though && will work). * We also allow {@code and} between two sub-expressions. * <p>This method converts back to {@code &&} for the AspectJ pointcut parser. */ private String replaceBooleanOperators(String pcExpr) { String result = StringUtils.replace(pcExpr," and "," && "); result = StringUtils.replace(result, " or ", " || "); return StringUtils.replace(result, " not ", " ! "); } }
@Override public String toString() { String result = this.content; if (result.length() > 80) { result = result.substring(0, 80) + "...(truncated)"; } result = StringUtils.replace(result, "\n", "\\n"); result = StringUtils.replace(result, "\r", "\\r"); return "SockJsFrame content='" + result + "'"; }
/** * Create a URI instance for the given location String, * replacing spaces with "%20" URI encoding first. * @param location the location String to convert into a URI instance * @return the URI instance * @throws URISyntaxException if the location wasn't a valid URI */ public static URI toURI(String location) throws URISyntaxException { return new URI(StringUtils.replace(location, " ", "%20")); }
/** * Replace the values in the comma-separated list (case insensitive) * with their index in the list. * @return a new String with the values from the list replaced */ private String replaceOrdinals(String value, String commaSeparatedList) { String[] list = StringUtils.commaDelimitedListToStringArray(commaSeparatedList); for (int i = 0; i < list.length; i++) { String item = list[i].toUpperCase(); value = StringUtils.replace(value.toUpperCase(), item, "" + i); } return value; }
public StringLiteral(String payload, int startPos, int endPos, String value) { super(payload, startPos, endPos); String valueWithinQuotes = value.substring(1, value.length() - 1); valueWithinQuotes = StringUtils.replace(valueWithinQuotes, "''", "'"); valueWithinQuotes = StringUtils.replace(valueWithinQuotes, "\"\"", "\""); this.value = new TypedValue(valueWithinQuotes); this.exitTypeDescriptor = "Ljava/lang/String"; }
/** * Apply transformation on a given class byte definition. * The method will always return a non-null byte array (if no transformation has taken place * the array content will be identical to the original one). * @param className the full qualified name of the class in dot format (i.e. some.package.SomeClass) * @param bytes class byte definition * @return (possibly transformed) class byte definition */ public byte[] transformIfNecessary(String className, byte[] bytes) { String internalName = StringUtils.replace(className, ".", "/"); return transformIfNecessary(className, internalName, bytes, null); }
@Override public void convertAndSendToUser(String user, String destination, Object payload, @Nullable Map<String, Object> headers, @Nullable MessagePostProcessor postProcessor) throws MessagingException { Assert.notNull(user, "User must not be null"); user = StringUtils.replace(user, "/", "%2F"); destination = destination.startsWith("/") ? destination : "/" + destination; super.convertAndSend(this.destinationPrefix + user + destination, payload, headers, postProcessor); }
private byte[] applyTransformers(String name, byte[] bytes) { String internalName = StringUtils.replace(name, ".", "/"); try { for (ClassFileTransformer transformer : this.classFileTransformers) { byte[] transformed = transformer.transform(this, internalName, null, null, bytes); bytes = (transformed != null ? transformed : bytes); } return bytes; } catch (IllegalClassFormatException ex) { throw new IllegalStateException(ex); } }
@Override public void setAsText(String text) throws java.lang.IllegalArgumentException { // Trim all whitespace String content = StringUtils.trimAllWhitespace(text); if (!StringUtils.hasText(content)) { // No content , ignore directly return; } // replace "=" to "," content = StringUtils.replace(content, "=", ","); // replace ":" to "," content = StringUtils.replace(content, ":", ","); // String[] to Map Map<String, String> parameters = CollectionUtils.toStringMap(commaDelimitedListToStringArray(content)); setValue(parameters); } });
@Override public void setAsText(String text) throws java.lang.IllegalArgumentException { // Trim all whitespace String content = StringUtils.trimAllWhitespace(text); if (!StringUtils.hasText(content)) { // No content , ignore directly return; } // replace "=" to "," content = StringUtils.replace(content, "=", ","); // replace ":" to "," content = StringUtils.replace(content, ":", ","); // String[] to Map Map<String, String> parameters = CollectionUtils.toStringMap(commaDelimitedListToStringArray(content)); setValue(parameters); } });
@Override public void setAsText(String text) throws java.lang.IllegalArgumentException { // Trim all whitespace String content = StringUtils.trimAllWhitespace(text); if (!StringUtils.hasText(content)) { // No content , ignore directly return; } // replace "=" to "," content = StringUtils.replace(content, "=", ","); // replace ":" to "," content = StringUtils.replace(content, ":", ","); // String[] to Map Map<String, String> parameters = CollectionUtils.toStringMap(commaDelimitedListToStringArray(content)); setValue(parameters); } });
@Override public void setAsText(String text) throws java.lang.IllegalArgumentException { // Trim all whitespace String content = StringUtils.trimAllWhitespace(text); if (!StringUtils.hasText(content)) { // No content , ignore directly return; } // replace "=" to "," content = StringUtils.replace(content, "=", ","); // replace ":" to "," content = StringUtils.replace(content, ":", ","); // String[] to Map Map<String, String> parameters = CollectionUtils.toStringMap(commaDelimitedListToStringArray(content)); setValue(parameters); } });
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; sessionIds = Collections.singleton(sessionId); } else { sessionIds = getSessionIdsByUser(userName, sessionId); } if (isRemoveLeadingSlash()) { actualDest = actualDest.substring(1); } return new ParseResult(sourceDest, actualDest, subscribeDest, sessionIds, userName); }
/** * Process the given resource path. * <p>The default implementation replaces: * <ul> * <li>Backslash with forward slash. * <li>Duplicate occurrences of slash with a single slash. * <li>Any combination of leading slash and control characters (00-1F and 7F) * with a single "/" or "". For example {@code " / // foo/bar"} * becomes {@code "/foo/bar"}. * </ul> * @since 3.2.12 */ protected String processPath(String path) { path = StringUtils.replace(path, "\\", "/"); path = cleanDuplicateSlashes(path); return cleanLeadingSlash(path); }
/** * Process the given resource path. * <p>The default implementation replaces: * <ul> * <li>Backslash with forward slash. * <li>Duplicate occurrences of slash with a single slash. * <li>Any combination of leading slash and control characters (00-1F and 7F) * with a single "/" or "". For example {@code " / // foo/bar"} * becomes {@code "/foo/bar"}. * </ul> * @since 3.2.12 */ protected String processPath(String path) { path = StringUtils.replace(path, "\\", "/"); path = cleanDuplicateSlashes(path); return cleanLeadingSlash(path); }
@Test public void testReplace() { String inString = "a6AazAaa77abaa"; String oldPattern = "aa"; String newPattern = "foo"; // Simple replace String s = StringUtils.replace(inString, oldPattern, newPattern); assertTrue("Replace 1 worked", s.equals("a6AazAfoo77abfoo")); // Non match: no change s = StringUtils.replace(inString, "qwoeiruqopwieurpoqwieur", newPattern); assertSame("Replace non-matched is returned as-is", inString, s); // Null new pattern: should ignore s = StringUtils.replace(inString, oldPattern, null); assertSame("Replace non-matched is returned as-is", inString, s); // Null old pattern: should ignore s = StringUtils.replace(inString, null, newPattern); assertSame("Replace non-matched is returned as-is", inString, s); }
@SuppressWarnings("unchecked") private <T> Flux<DataBuffer> encodeData(@Nullable T data, ResolvableType valueType, MediaType mediaType, DataBufferFactory factory, Map<String, Object> hints) { if (data == null) { return Flux.empty(); } if (data instanceof String) { String text = (String) data; return Flux.from(encodeText(StringUtils.replace(text, "\n", "\ndata:") + "\n", mediaType, factory)); } if (this.encoder == null) { return Flux.error(new CodecException("No SSE encoder configured and the data is not String.")); } return ((Encoder<T>) this.encoder) .encode(Mono.just(data), factory, valueType, mediaType, hints) .concatWith(encodeText("\n", mediaType, factory)); }
@Test public void handleMessageEncodedUserName() { String userName = "http://joe.openid.example.org/"; TestSimpUser simpUser = new TestSimpUser(userName); simpUser.addSessions(new TestSimpSession("openid123")); when(this.registry.getUser(userName)).thenReturn(simpUser); String destination = "/user/" + StringUtils.replace(userName, "/", "%2F") + "/queue/foo"; Message<?> message = createMessage(SimpMessageType.MESSAGE, new TestPrincipal("joe"), null, destination); UserDestinationResult actual = this.resolver.resolveDestination(message); assertEquals(1, actual.getTargetDestinations().size()); assertEquals("/queue/foo-useropenid123", actual.getTargetDestinations().iterator().next()); }