Browse Source

Adding utility method for uri conversion

pull/46/head
Martin Stockhammer 6 years ago
parent
commit
3dc85427b3

+ 19
- 0
archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/PathUtil.java View File

import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;


import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;




return getRelative(basedir, Paths.get(child)); return getRelative(basedir, Paths.get(child));
} }

/**
* Returns a path object from the given URI. If the URI has no scheme, the path of the URI is used
* for creating the filesystem path.
*
* @param uri the uri to convert
* @return a path object with the given path
* @throws java.nio.file.FileSystemNotFoundException if the uri scheme is not known.
*/
public static Path getPathFromUri( URI uri) {
if (uri==null) {
return Paths.get("");
} else if (uri.getScheme()==null) {
return Paths.get(uri.getPath());
} else {
return Paths.get(uri);
}
}
} }

Loading…
Cancel
Save