streams.add(new FileInputStream(file));
obSourcePlugin
.setInputInfo(streams, file.getName());
}
} else {
throw new CancellationException();
}
}
break;
case URL:
// If the plug-in specifies a username and password, create and
// set an authenticator.
String userName = obSourcePlugin.getUsername();
String password = obSourcePlugin.getPassword();
if (userName != null && password != null) {
java.net.Authenticator.setDefault(new URLAuthenticator(
userName, password));
}
// Does the plug-in supply URLs? Or do we have to ask the user
// for a URL?
List<URL> urls = obSourcePlugin.getURLs();
if (urls != null) {
String urlStrs = "";
for (URL url : urls) {
streams.add(url.openStream());
urlStrs += url.getPath() + ", ";
}
urlStrs = urlStrs.substring(0, urlStrs.lastIndexOf(", "));
obSourcePlugin.setInputInfo(streams, urlStrs);
} else {
// Request a URL from the user.
TextField urlField = new TextField("URL");
Checkbox additiveLoadCheckbox = new Checkbox(
"Add to current?", false);
MultiEntryComponentDialog urlDialog = new MultiEntryComponentDialog(
"Enter URL", urlField, additiveLoadCheckbox);
if (!urlDialog.isCancelled()
&& !urlField.getValue().matches("^\\s*$")) {
String urlStr = urlField.getValue();
obSourcePlugin.setAdditive(additiveLoadCheckbox.getValue());
URL url = new URL(urlStr);
streams.add(url.openStream());
obSourcePlugin.setInputInfo(streams, urlStr);
} else {
throw new CancellationException();
}
}
break;