// This is one of those cases where a null value actually has a proper meaning.
if(path == null)
return getHomeFolder().getURL();
// Tries the specified path as-is.
AbstractFile file;
CredentialsMapping newCredentialsMapping;
while(true) {
try {
file = FileFactory.getFile(path, true);
if(!file.exists())
file = null;
break;
}
// If an AuthException occurred, gets login credential from the user.
catch(Exception e) {
if(e instanceof AuthException) {
// Prompts the user for a login and password.
AuthException authException = (AuthException)e;
FileURL url = authException.getURL();
AuthDialog authDialog = new AuthDialog(WindowManager.getCurrentMainFrame(), url, true, authException.getMessage());
authDialog.showDialog();
newCredentialsMapping = authDialog.getCredentialsMapping();
if(newCredentialsMapping !=null) {
// Use the provided credentials
CredentialsManager.authenticate(url, newCredentialsMapping);
path = url.toString(true);
}
// If the user cancels, we fall back to the default path.
else {
return getHomeFolder().getURL();
}
}
else {
file = null;
break;
}
}
}
// If the specified path does not work out,
if(file == null)
// Tries the specified path as a relative path.
if((file = FileFactory.getFile(new File(path).getAbsolutePath())) == null || !file.exists())
// Defaults to home.
return getHomeFolder().getURL();
// If the specified path is a non-browsable, uses its parent.
if(!file.isBrowsable())
// This is just playing things safe, as I doubt there might ever be a case of
// a file without a parent directory.
if((file = file.getParent()) == null)
return getHomeFolder().getURL();
return file.getURL();
}