Java Code Examples for org.springframework.util.StringUtils#deleteAny()

The following examples show how to use org.springframework.util.StringUtils#deleteAny() . These examples are extracted from open source projects. 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
@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
@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 3
@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 4
@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
@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 6
@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 7
@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 8
Source Project: blog_demos   File: StringTrimmerEditor.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: spring-analysis-note   File: ErrorsTag.java    License: MIT License 5 votes vote down vote up
/**
 * 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 Project: java-technology-stack   File: ErrorsTag.java    License: MIT License 5 votes vote down vote up
/**
 * 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
/**
 * 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>&lt;form:errors/&gt;</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 Project: lams   File: ErrorsTag.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
/**
 * 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 14
/**
 * 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 15
/**
 * 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 Project: spring-analysis-note   File: LabelTag.java    License: MIT License 2 votes vote down vote up
/**
 * 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 Project: java-technology-stack   File: LabelTag.java    License: MIT License 2 votes vote down vote up
/**
 * 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 18
Source Project: spring4-understanding   File: LabelTag.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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 Project: lams   File: LabelTag.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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
/**
 * 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(), "[]");
}