}
if (fieldName.equals("url")) { // html
try {
link = sanitizeUrl(link);
ExternalFileType fileType = Globals.prefs.getExternalFileTypeByExt("html");
if (Globals.ON_MAC) {
String[] cmd = ((fileType.getOpenWith() != null) && (fileType.getOpenWith().length() > 0)) ?
new String[] { "/usr/bin/open", "-a", fileType.getOpenWith(), link } :
new String[] { "/usr/bin/open", link };
Runtime.getRuntime().exec(cmd);
} else if (Globals.ON_WIN) {
if ((fileType.getOpenWith() != null) && (fileType.getOpenWith().length() > 0)) {
// Application is specified. Use it:
openFileWithApplicationOnWindows(link, fileType.getOpenWith());
} else
openFileOnWindows(link, true);
} else {
// Use the given app if specified, and the universal "xdg-open" otherwise:
String[] openWith;
if ((fileType.getOpenWith() != null) && (fileType.getOpenWith().length() > 0))
openWith = fileType.getOpenWith().split(" ");
else
openWith = new String[] {"xdg-open"};
String[] cmd = new String[openWith.length+1];
System.arraycopy(openWith, 0, cmd, 0, openWith.length);
cmd[cmd.length-1] = link;
Runtime.getRuntime().exec(cmd);
}
} catch (IOException e) {
System.err.println(Globals.lang("Error_opening_file_'%0'.", link));
e.printStackTrace();
}
} else if (fieldName.equals("ps")) {
try {
if (Globals.ON_MAC) {
ExternalFileType type = Globals.prefs.getExternalFileTypeByExt("ps");
String viewer = type != null ? type.getOpenWith() : Globals.prefs.get("psviewer");
String[] cmd = { "/usr/bin/open", "-a", viewer, link };
Runtime.getRuntime().exec(cmd);
} else if (Globals.ON_WIN) {
openFileOnWindows(link, true);
/*
* cmdArray[0] = Globals.prefs.get("psviewer"); cmdArray[1] =
* link; Process child = Runtime.getRuntime().exec(
* cmdArray[0] + " " + cmdArray[1]);
*/
} else {
ExternalFileType type = Globals.prefs.getExternalFileTypeByExt("ps");
String viewer = type != null ? type.getOpenWith() : "xdg-open";
String[] cmdArray = new String[2];
cmdArray[0] = viewer;
cmdArray[1] = link;
Runtime.getRuntime().exec(cmdArray);
}
} catch (IOException e) {
System.err.println("An error occured on the command: "
+ Globals.prefs.get("psviewer") + " " + link);
}
} else if (fieldName.equals("pdf")) {
try {
if (Globals.ON_MAC) {
ExternalFileType type = Globals.prefs.getExternalFileTypeByExt("pdf");
String viewer = type != null ? type.getOpenWith() : Globals.prefs.get("psviewer");
String[] cmd = { "/usr/bin/open", "-a", viewer, link };
Runtime.getRuntime().exec(cmd);
} else if (Globals.ON_WIN) {
openFileOnWindows(link, true);
/*
* String[] spl = link.split("\\\\"); StringBuffer sb = new
* StringBuffer(); for (int i = 0; i < spl.length; i++) { if
* (i > 0) sb.append("\\"); if (spl[i].indexOf(" ") >= 0)
* spl[i] = "\"" + spl[i] + "\""; sb.append(spl[i]); }
* //pr(sb.toString()); link = sb.toString();
*
* String cmd = "cmd.exe /c start " + link;
*
* Process child = Runtime.getRuntime().exec(cmd);
*/
} else {
ExternalFileType type = Globals.prefs.getExternalFileTypeByExt("pdf");
String viewer = type != null ? type.getOpenWith() : Globals.prefs.get("psviewer");
String[] cmdArray = new String[2];
cmdArray[0] = viewer;
cmdArray[1] = link;
// Process child = Runtime.getRuntime().exec(cmdArray[0]+"
// "+cmdArray[1]);