List of usage examples for org.apache.commons.lang3 StringUtils prependIfMissing
public static String prependIfMissing(final String str, final CharSequence prefix, final CharSequence... prefixes)
From source file:com.labs64.utils.swid.support.SwidUtils.java
/** * <p>/*from w w w . ja v a 2 s . c o m*/ * Revert given URL according to the <a href="http://en.wikipedia.org/wiki/Reverse_domain_name_notation">Reverse * domain name notation</a> * </p> * <p> * * @see <a * href="http://en.wikipedia.org/wiki/Reverse_domain_name_notation">http://en.wikipedia.org/wiki/Reverse_domain_name_notation</a> * </p> * * @param domainName * the domain name to be reverted * @return reverted domain name */ public static String revertDomainName(final String domainName) { if (StringUtils.isBlank(domainName)) { throw new SwidException("domainName isn't defined"); } try { URI uri = new URI(StringUtils.prependIfMissing(domainName, "http://", "https://")); String hostName = StringUtils.removeStart(uri.getHost(), "www."); String[] domainNameSplit = StringUtils.split(hostName, "."); CollectionUtils.reverseArray(domainNameSplit); return StringUtils.join(domainNameSplit, "."); } catch (URISyntaxException e) { throw new SwidException("Cannot revert domain name"); } }