From 55e33b147723d68223f31994125b6364cb808bb1 Mon Sep 17 00:00:00 2001 From: rudolf Date: Mon, 1 Dec 2003 10:42:06 +0000 Subject: added makeAbsoluteURI (RSCH) git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@66 d688527b-c9ab-4aba-bd8d-4036d912da1d --- .../src/at/gv/egovernment/moa/util/FileUtils.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/common/src/at/gv/egovernment/moa/util/FileUtils.java b/common/src/at/gv/egovernment/moa/util/FileUtils.java index f8941568d..bb21f4ca0 100644 --- a/common/src/at/gv/egovernment/moa/util/FileUtils.java +++ b/common/src/at/gv/egovernment/moa/util/FileUtils.java @@ -4,6 +4,8 @@ import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; /** @@ -84,4 +86,26 @@ public class FileUtils { byte[] content = readResource(name); return new String(content, encoding); } + + /** + * Returns the absolute URL of a given url which is relative to the parameter root + * @param url + * @param root + * @return String + */ + public static String makeAbsoluteURL(String url, String root) { + //if url is relative to rootConfigFileDirName make it absolute + try { + if(null == url) return null; + URI uri = new URI(url); + if (!uri.isAbsolute()) { // make it absolute to the config file + uri = new URI(root + url); + } + return uri.toString(); + } catch (URISyntaxException e) { + //if url string could not be converted to absolute URL return source url + return url; + } + } + } -- cgit v1.2.3