mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2023-12-13 20:50:18 +01:00
e872069093
Final improvements. Fixing reply mention. Do NOT use "instanceUrlRaw" as of now. Minor fixes Merge remote-tracking branch 'remotes/main/master' into login-fix URL parsing, label and other improvements. Co-authored-by: opyale <opyale@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/564 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
48 lines
831 B
Java
48 lines
831 B
Java
package org.mian.gitnex.helpers;
|
|
|
|
import java.net.URI;
|
|
import java.net.URISyntaxException;
|
|
|
|
/**
|
|
* Author M M Arif
|
|
*/
|
|
|
|
public class UrlHelper {
|
|
|
|
public static String cleanUrl(String url) {
|
|
|
|
URI uri = null;
|
|
try {
|
|
uri = new URI(url);
|
|
}
|
|
catch(URISyntaxException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
assert uri != null;
|
|
String urlProtocol = uri.getScheme();
|
|
String urlHost = uri.getHost();
|
|
int urlPort = uri.getPort();
|
|
|
|
String urlFinal = null;
|
|
if(urlPort > 0) {
|
|
urlFinal = urlProtocol + "://" + urlHost + ":" + urlPort;
|
|
}
|
|
else if(urlProtocol != null) {
|
|
urlFinal = urlProtocol + "://" + urlHost;
|
|
}
|
|
else {
|
|
urlFinal = urlHost;
|
|
}
|
|
|
|
return urlFinal;
|
|
|
|
}
|
|
|
|
public static String fixScheme(String url, String scheme) {
|
|
|
|
return !url.matches("^(http|https)://.+$") ? scheme + "://" + url : url;
|
|
}
|
|
|
|
}
|