social-util-library/src/main/java/org/gcube/socialnetworking/socialtoken/SanitizedURL.java

52 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package org.gcube.socialnetworking.socialtoken;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;
public class SanitizedURL {
private static String FINAL_CHARACTERS_TO_REMOVE = "[\\.\\,\\;\\)\\:\\\"\\'\\\\]";
protected String prefix;
protected String postfix;
protected final URL url;
public SanitizedURL(String urlString) throws MalformedURLException {
if(Objects.isNull(urlString) || urlString.isEmpty()) {
throw new MalformedURLException();
}
prefix = "";
if(urlString.startsWith("(")) {
prefix = urlString.substring(0, 1);
urlString = urlString.substring(1);
}
if(urlString.startsWith("www.")) {
urlString = "http://" + urlString;
}
postfix = urlString.substring(urlString.length()-1);
if(postfix.matches(FINAL_CHARACTERS_TO_REMOVE)) {
urlString = urlString.substring(0, urlString.length()-1);
}else {
postfix = "";
}
url = new URL(urlString);
}
public String getPrefix() {
return prefix;
}
public String getPostfix() {
return postfix;
}
public URL getURL() {
return url;
}
}