Merge pull request #2256 from BasisOlivers/1843

Fixed error handling of ExternalViewerAction.
This commit is contained in:
Richard Cordovano 2016-06-29 15:29:42 -04:00 committed by GitHub
commit ac99dce76c

View File

@ -24,7 +24,9 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import org.openide.nodes.Node; import org.openide.nodes.Node;
import org.openide.util.NbBundle.Messages;
import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.datamodel.ContentUtils; import org.sleuthkit.autopsy.datamodel.ContentUtils;
@ -67,6 +69,8 @@ public class ExternalViewerAction extends AbstractAction {
} }
} }
@Messages({"ExternalViewerAction.actionPerformed.failure.message=Could not find a viewer for the given file.",
"ExternalViewerAction.actionPerformed.failure.title=Open Failure"})
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// Get the temp folder path of the case // Get the temp folder path of the case
@ -82,15 +86,14 @@ public class ExternalViewerAction extends AbstractAction {
tempFile.createNewFile(); tempFile.createNewFile();
ContentUtils.writeToFile(fileObject, tempFile); ContentUtils.writeToFile(fileObject, tempFile);
} catch (IOException ex) { } catch (IOException ex) {
// throw an error here
logger.log(Level.WARNING, "Can't save to temporary file.", ex); //NON-NLS logger.log(Level.WARNING, "Can't save to temporary file.", ex); //NON-NLS
} }
try { try {
Desktop.getDesktop().open(tempFile); Desktop.getDesktop().open(tempFile);
} catch (IOException ex) { } catch (IOException ex) {
// if can't open the file, throw the error saying: "File type not supported." logger.log(Level.WARNING, "Could not find a viewer for the given file: " + tempFile.getName(), ex); //NON-NLS
logger.log(Level.WARNING, "File type not supported.", ex); //NON-NLS JOptionPane.showMessageDialog(null, Bundle.ExternalViewerAction_actionPerformed_failure_message(), Bundle.ExternalViewerAction_actionPerformed_failure_title(), JOptionPane.ERROR_MESSAGE);
} }
// delete the file on exit // delete the file on exit