Java Code Examples for org.springframework.util.StringUtils#deleteAny()
The following examples show how to use
org.springframework.util.StringUtils#deleteAny() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringTrimmerEditor.java From blog_demos with Apache License 2.0 | 6 votes |
@Override public void setAsText(String text) { if (text == null) { setValue(null); } else { String value = text.trim(); if (this.charsToDelete != null) { value = StringUtils.deleteAny(value, this.charsToDelete); } if (this.emptyAsNull && "".equals(value)) { setValue(null); } else { setValue(value); } } }
Example 2
Source File: CssLinkResourceTransformerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void transformExtLinksNotAllowed() throws Exception { ResourceResolverChain resolverChain = Mockito.mock(DefaultResourceResolverChain.class); ResourceTransformerChain transformerChain = new DefaultResourceTransformerChain(resolverChain, Arrays.asList(new CssLinkResourceTransformer())); Resource externalCss = new ClassPathResource("test/external.css", getClass()); Resource resource = transformerChain.transform(this.request, externalCss); TransformedResource transformedResource = (TransformedResource) resource; String expected = "@import url(\"http://example.org/fonts/css\");\n" + "body { background: url(\"file:///home/spring/image.png\") }\n" + "figure { background: url(\"//example.org/style.css\")}"; String result = new String(transformedResource.getByteArray(), "UTF-8"); result = StringUtils.deleteAny(result, "\r"); assertEquals(expected, result); Mockito.verify(resolverChain, Mockito.never()) .resolveUrlPath("http://example.org/fonts/css", Arrays.asList(externalCss)); Mockito.verify(resolverChain, Mockito.never()) .resolveUrlPath("file:///home/spring/image.png", Arrays.asList(externalCss)); Mockito.verify(resolverChain, Mockito.never()) .resolveUrlPath("//example.org/style.css", Arrays.asList(externalCss)); }
Example 3
Source File: StringTrimmerEditor.java From java-technology-stack with MIT License | 6 votes |
@Override public void setAsText(@Nullable String text) { if (text == null) { setValue(null); } else { String value = text.trim(); if (this.charsToDelete != null) { value = StringUtils.deleteAny(value, this.charsToDelete); } if (this.emptyAsNull && "".equals(value)) { setValue(null); } else { setValue(value); } } }
Example 4
Source File: CssLinkResourceTransformerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void transformExtLinksNotAllowed() throws Exception { this.request = new MockHttpServletRequest("GET", "/static/external.css"); List<ResourceTransformer> transformers = Collections.singletonList(new CssLinkResourceTransformer()); ResourceResolverChain mockChain = Mockito.mock(DefaultResourceResolverChain.class); ResourceTransformerChain chain = new DefaultResourceTransformerChain(mockChain, transformers); Resource resource = getResource("external.css"); String expected = "@import url(\"http://example.org/fonts/css\");\n" + "body { background: url(\"file:///home/spring/image.png\") }\n" + "figure { background: url(\"//example.org/style.css\")}"; TransformedResource transformedResource = (TransformedResource) chain.transform(this.request, resource); String result = new String(transformedResource.getByteArray(), StandardCharsets.UTF_8); result = StringUtils.deleteAny(result, "\r"); assertEquals(expected, result); List<Resource> locations = Collections.singletonList(resource); Mockito.verify(mockChain, Mockito.never()).resolveUrlPath("http://example.org/fonts/css", locations); Mockito.verify(mockChain, Mockito.never()).resolveUrlPath("file:///home/spring/image.png", locations); Mockito.verify(mockChain, Mockito.never()).resolveUrlPath("//example.org/style.css", locations); }
Example 5
Source File: StringTrimmerEditor.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void setAsText(String text) { if (text == null) { setValue(null); } else { String value = text.trim(); if (this.charsToDelete != null) { value = StringUtils.deleteAny(value, this.charsToDelete); } if (this.emptyAsNull && "".equals(value)) { setValue(null); } else { setValue(value); } } }
Example 6
Source File: StringTrimmerEditor.java From spring-analysis-note with MIT License | 6 votes |
@Override public void setAsText(@Nullable String text) { if (text == null) { setValue(null); } else { String value = text.trim(); if (this.charsToDelete != null) { value = StringUtils.deleteAny(value, this.charsToDelete); } if (this.emptyAsNull && value.isEmpty()) { setValue(null); } else { setValue(value); } } }
Example 7
Source File: CssLinkResourceTransformerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void transform() throws Exception { Resource css = new ClassPathResource("test/main.css", getClass()); TransformedResource actual = (TransformedResource) this.transformerChain.transform(this.request, css); String expected = "\n" + "@import url(\"bar-11e16cf79faee7ac698c805cf28248d2.css\");\n" + "@import url('bar-11e16cf79faee7ac698c805cf28248d2.css');\n" + "@import url(bar-11e16cf79faee7ac698c805cf28248d2.css);\n\n" + "@import \"foo-e36d2e05253c6c7085a91522ce43a0b4.css\";\n" + "@import 'foo-e36d2e05253c6c7085a91522ce43a0b4.css';\n\n" + "body { background: url(\"images/image-f448cd1d5dba82b774f3202c878230b3.png\") }\n"; String result = new String(actual.getByteArray(), "UTF-8"); result = StringUtils.deleteAny(result, "\r"); assertEquals(expected, result); }
Example 8
Source File: StringTrimmerEditor.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public void setAsText(String text) { if (text == null) { setValue(null); } else { String value = text.trim(); if (this.charsToDelete != null) { value = StringUtils.deleteAny(value, this.charsToDelete); } if (this.emptyAsNull && "".equals(value)) { setValue(null); } else { setValue(value); } } }
Example 9
Source File: ErrorsTag.java From java-technology-stack with MIT License | 5 votes |
/** * Get the value for the HTML '{@code id}' attribute. * <p>Appends '{@code .errors}' to the value returned by {@link #getPropertyPath()} * or to the model attribute name if the {@code <form:errors/>} tag's * '{@code path}' attribute has been omitted. * @return the value for the HTML '{@code id}' attribute * @see #getPropertyPath() */ @Override protected String autogenerateId() throws JspException { String path = getPropertyPath(); if ("".equals(path) || "*".equals(path)) { path = (String) this.pageContext.getAttribute( FormTag.MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE); } return StringUtils.deleteAny(path, "[]") + ".errors"; }
Example 10
Source File: ErrorsTag.java From spring-analysis-note with MIT License | 5 votes |
/** * Get the value for the HTML '{@code id}' attribute. * <p>Appends '{@code .errors}' to the value returned by {@link #getPropertyPath()} * or to the model attribute name if the {@code <form:errors/>} tag's * '{@code path}' attribute has been omitted. * @return the value for the HTML '{@code id}' attribute * @see #getPropertyPath() */ @Override protected String autogenerateId() throws JspException { String path = getPropertyPath(); if ("".equals(path) || "*".equals(path)) { path = (String) this.pageContext.getAttribute( FormTag.MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE); } return StringUtils.deleteAny(path, "[]") + ".errors"; }
Example 11
Source File: FormFirstErrorsTag.java From bbs with GNU Affero General Public License v3.0 | 5 votes |
/** * Get the value for the HTML '<code>id</code>' attribute. * <p>Appends '<code>.errors</code>' to the value returned by {@link #getPropertyPath()} * or to the model attribute name if the <code><form:errors/></code> tag's * '<code>path</code>' attribute has been omitted. * @return the value for the HTML '<code>id</code>' attribute * @see #getPropertyPath() */ @Override protected String autogenerateId() throws JspException { String path = getPropertyPath(); if ("".equals(path) || "*".equals(path)) { path = (String) this.pageContext.getAttribute( FormTag.MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE); } return StringUtils.deleteAny(path, "[]") + ".errors"; }
Example 12
Source File: ErrorsTag.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Get the value for the HTML '{@code id}' attribute. * <p>Appends '{@code .errors}' to the value returned by {@link #getPropertyPath()} * or to the model attribute name if the {@code <form:errors/>} tag's * '{@code path}' attribute has been omitted. * @return the value for the HTML '{@code id}' attribute * @see #getPropertyPath() */ @Override protected String autogenerateId() throws JspException { String path = getPropertyPath(); if ("".equals(path) || "*".equals(path)) { path = (String) this.pageContext.getAttribute( FormTag.MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE); } return StringUtils.deleteAny(path, "[]") + ".errors"; }
Example 13
Source File: NamingHelper.java From springmvc-raml-plugin with Apache License 2.0 | 4 votes |
/** * Converts an http contentType into a qualifier that can be used within a * Java method * * @param contentType * The content type to convert application/json * @return qualifier, example V1Html */ public static String convertContentTypeToQualifier(String contentType) { // lets start off simple since qualifers are better if they are simple // :) // if we have simple standard types lets add some heuristics if (contentType.equals(MediaType.APPLICATION_JSON_VALUE)) { return "AsJson"; } if (contentType.equals(MediaType.APPLICATION_OCTET_STREAM_VALUE)) { return "AsBinary"; } if (contentType.equals(MediaType.TEXT_PLAIN_VALUE) || contentType.equals(MediaType.TEXT_HTML_VALUE)) { return "AsText"; } // we have a non standard type. lets see if we have a version Matcher versionMatcher = CONTENT_TYPE_VERSION.matcher(contentType); if (versionMatcher.find()) { String version = versionMatcher.group(1); if (version != null) { return StringUtils.capitalize(version).replace(".", "_"); } } // if we got here we have some sort of funky content type. deal with it int seperatorIndex = contentType.indexOf("/"); if (seperatorIndex != -1 && seperatorIndex < contentType.length()) { String candidate = contentType.substring(seperatorIndex + 1).toLowerCase(); String out = ""; if (candidate.contains("json")) { candidate = candidate.replace("json", ""); out += "AsJson"; } candidate = StringUtils.deleteAny(candidate, " ,.+=-'\"\\|~`#$%^&\n\t"); if (StringUtils.hasText(candidate)) { out = StringUtils.capitalize(candidate) + out; } return "_" + out; } return ""; }
Example 14
Source File: AbstractDataBoundFormElementTag.java From java-technology-stack with MIT License | 4 votes |
/** * Autogenerate the '{@code id}' attribute value for this tag. * <p>The default implementation simply delegates to {@link #getName()}, * deleting invalid characters (such as "[" or "]"). */ @Nullable protected String autogenerateId() throws JspException { String name = getName(); return (name != null ? StringUtils.deleteAny(name, "[]") : null); }
Example 15
Source File: AbstractDataBoundFormElementTag.java From spring-analysis-note with MIT License | 4 votes |
/** * Autogenerate the '{@code id}' attribute value for this tag. * <p>The default implementation simply delegates to {@link #getName()}, * deleting invalid characters (such as "[" or "]"). */ @Nullable protected String autogenerateId() throws JspException { String name = getName(); return (name != null ? StringUtils.deleteAny(name, "[]") : null); }
Example 16
Source File: LabelTag.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Autogenerate the '{@code for}' attribute value for this tag. * <p>The default implementation delegates to {@link #getPropertyPath()}, * deleting invalid characters (such as "[" or "]"). */ protected String autogenerateFor() throws JspException { return StringUtils.deleteAny(getPropertyPath(), "[]"); }
Example 17
Source File: AbstractDataBoundFormElementTag.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Autogenerate the '{@code id}' attribute value for this tag. * <p>The default implementation simply delegates to {@link #getName()}, * deleting invalid characters (such as "[" or "]"). */ protected String autogenerateId() throws JspException { return StringUtils.deleteAny(getName(), "[]"); }
Example 18
Source File: LabelTag.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Autogenerate the '{@code for}' attribute value for this tag. * <p>The default implementation delegates to {@link #getPropertyPath()}, * deleting invalid characters (such as "[" or "]"). */ protected String autogenerateFor() throws JspException { return StringUtils.deleteAny(getPropertyPath(), "[]"); }
Example 19
Source File: LabelTag.java From java-technology-stack with MIT License | 2 votes |
/** * Autogenerate the '{@code for}' attribute value for this tag. * <p>The default implementation delegates to {@link #getPropertyPath()}, * deleting invalid characters (such as "[" or "]"). */ protected String autogenerateFor() throws JspException { return StringUtils.deleteAny(getPropertyPath(), "[]"); }
Example 20
Source File: LabelTag.java From spring-analysis-note with MIT License | 2 votes |
/** * Autogenerate the '{@code for}' attribute value for this tag. * <p>The default implementation delegates to {@link #getPropertyPath()}, * deleting invalid characters (such as "[" or "]"). */ protected String autogenerateFor() throws JspException { return StringUtils.deleteAny(getPropertyPath(), "[]"); }