Add URL to report and Launch when opened

Ability to add a URL to a report.  When the report is opened then launch a browser to open the URL report.
This commit is contained in:
Mark McKinnon
2018-02-19 11:59:03 -08:00
parent 5a7820ae61
commit b54ce7f1b1
2 changed files with 22 additions and 3 deletions
@@ -1529,7 +1529,11 @@ public class Case {
public void addReport(String localPath, String srcModuleName, String reportName) throws TskCoreException {
String normalizedLocalPath;
try {
normalizedLocalPath = Paths.get(localPath).normalize().toString();
if (localPath.toLowerCase().contains("http:")) {
normalizedLocalPath = localPath;
} else {
normalizedLocalPath = Paths.get(localPath).normalize().toString();
}
} catch (InvalidPathException ex) {
String errorMsg = "Invalid local path provided: " + localPath; // NON-NLS
throw new TskCoreException(errorMsg, ex);
@@ -22,6 +22,8 @@ import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
@@ -112,7 +114,8 @@ public class ExternalViewerAction extends AbstractAction {
"ExternalViewerAction.actionPerformed.failure.IO.message=There is no associated editor for files of this type or the associated application failed to launch.",
"ExternalViewerAction.actionPerformed.failure.support.message=This platform (operating system) does not support opening a file in an editor this way.",
"ExternalViewerAction.actionPerformed.failure.missingFile.message=The file no longer exists.",
"ExternalViewerAction.actionPerformed.failure.permission.message=Permission to open the file was denied."})
"ExternalViewerAction.actionPerformed.failure.permission.message=Permission to open the file was denied.",
"ExternalViewerAction.actionPerformed.failure.open.url=Cannot open URL"})
public static void openFile(String mimeType, String ext, File file) {
/**
* Check if the file MIME type or extension exists in the user defined
@@ -133,7 +136,13 @@ public class ExternalViewerAction extends AbstractAction {
}
} else {
try {
Desktop.getDesktop().open(file);
if (file.getPath().toLowerCase().contains("http")) {
String url_path = file.getPath().replaceAll("\\\\","/");
Desktop.getDesktop().browse(new URI(url_path.replaceFirst("/","//")));
} else {
Desktop.getDesktop().open(file);
}
} catch (IOException ex) {
logger.log(Level.WARNING, "Could not find a viewer for the given file: " + file.getName(), ex); //NON-NLS
JOptionPane.showMessageDialog(null,
@@ -158,6 +167,12 @@ public class ExternalViewerAction extends AbstractAction {
Bundle.ExternalViewerAction_actionPerformed_failure_permission_message(),
Bundle.ExternalViewerAction_actionPerformed_failure_title(),
JOptionPane.ERROR_MESSAGE);
} catch (URISyntaxException ex) {
logger.log(Level.WARNING, "Could not open URL provided: " + file.getPath(), ex);
JOptionPane.showMessageDialog(null,
Bundle.ExternalViewerAction_actionPerformed_failure_open_url(),
Bundle.ExternalViewerAction_actionPerformed_failure_title(),
JOptionPane.ERROR_MESSAGE);
}
}
}