2019-01-24 11:47:03 +01:00
|
|
|
package org.gcube.socialnetworking.socialtoken;
|
2019-01-24 11:38:34 +01:00
|
|
|
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
public class SanitizedURL {
|
|
|
|
|
2019-01-25 15:27:32 +01:00
|
|
|
private static String FINAL_CHARACTERS_TO_REMOVE = "[\\.\\,\\;\\)\\:]";
|
2019-01-24 11:38:34 +01:00
|
|
|
|
|
|
|
protected String prefix;
|
|
|
|
protected String postfix;
|
|
|
|
protected final URL url;
|
|
|
|
|
|
|
|
public SanitizedURL(String urlString) throws MalformedURLException {
|
2019-01-24 12:07:06 +01:00
|
|
|
if(urlString==null || urlString.compareTo("")==0) {
|
|
|
|
throw new MalformedURLException();
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:38:34 +01:00
|
|
|
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);
|
2019-01-25 15:27:32 +01:00
|
|
|
if(postfix.matches(FINAL_CHARACTERS_TO_REMOVE)) {
|
2019-01-24 11:38:34 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|