Java Code Examples for org.apache.commons.lang3.StringUtils.prependIfMissing()

The following are Jave code examples for showing how to use prependIfMissing() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: nixmash-blog   File: PostUtils.java   View Source Code Vote up 6 votes
public static String formatPostContent(Post post) {
    String content = post.getPostContent();
    String imageHtml = "<img alt=\"\" src=\"%s\"  class=\"%s-image\"/>\n";
    String thumbnail = String.format(imageHtml, post.getPostImage(), "thumbnail");
    String feature = String.format(imageHtml, post.getPostImage(), "feature");

    switch (post.getDisplayType()) {
        case LINK_SUMMARY:
            content = StringUtils.prependIfMissing(content, thumbnail);
            break;
        case LINK_FEATURE:
            content = StringUtils.appendIfMissing(content, feature);
            break;
        case LINK:
            break;
    }
    return content;
}
 
Example 2
Project: plugin-prov-aws   File: AWS4SignerBase.java   View Source Code Vote up 5 votes
/**
 * Returns the canonicalized resource path for the service endpoint.
 */
protected String getCanonicalizedResourcePath(final String path) {
	try {
		return StringUtils.prependIfMissing(urlCodec.encode(StringUtils.trimToEmpty(path)).replace("%2F", "/"), "/");
	} catch (final EncoderException e) {
		throw new TechnicalException("Error during resource path encoding", e);
	}
}
 
Example 3
Project: yadaframework   File: YadaSecurityEmailService.java   View Source Code Vote up 2 votes
/**
 * Convert a site-relative link to absolute, because in emails we can't use @{}.
 * Example: th:href="${beans.yadaEmailService.buildLink('/read/234')}"
 * @param relativeLink
 * @return absolute link
 */
public String buildLink(String relativeLink) {
	String myServerAddress = config.getServerAddress();
	String relative = StringUtils.prependIfMissing(relativeLink, "/");
	return myServerAddress + relative;
}
 
Example 4
Project: yadaframework   File: YadaEmailService.java   View Source Code Vote up 2 votes
/**
 * Convert a site-relative link to absolute, because in emails we can't use @{}.
 * Example: th:href="${beans.yadaEmailService.buildLink('/read/234')}"
 * @param relativeLink
 * @return absolute link
 */
public String buildLink(String relativeLink) {
	String myServerAddress = config.getServerAddress();
	String relative = StringUtils.prependIfMissing(relativeLink, "/");
	return myServerAddress + relative;
}