19 package org.sleuthkit.autopsy.directorytree;
 
   21 import java.awt.Desktop;
 
   22 import java.awt.event.ActionEvent;
 
   24 import java.io.IOException;
 
   26 import java.net.URISyntaxException;
 
   27 import java.util.logging.Level;
 
   28 import javax.swing.AbstractAction;
 
   29 import javax.swing.JOptionPane;
 
   30 import org.openide.nodes.Node;
 
   31 import org.openide.util.NbBundle.Messages;
 
   32 import org.openide.windows.WindowManager;
 
   50     final static String[] EXECUTABLE_EXT = {
".exe", 
".dll", 
".com", 
".bat", 
".msi", 
".reg", 
".scr", 
".cmd"}; 
 
   55         this.fileObject = file;
 
   57         long size = fileObject.getSize();
 
   58         String fileName = fileObject.getName();
 
   59         int extPos = fileName.lastIndexOf(
'.');
 
   63             String extension = fileName.substring(extPos, fileName.length()).toLowerCase();
 
   64             fileObjectExt = extension;
 
   65             for (
int i = 0; i < EXECUTABLE_EXT.length; ++i) {
 
   66                 if (EXECUTABLE_EXT[i].equals(extension)) {
 
   79         if (!(size > 0) || extPos == -1 || isExecutable || isSlackFile) {
 
   80             this.setEnabled(
false);
 
   96         "ExternalViewerAction.actionPerformed.failure.title=Open File Failure {0}",
 
   97         "ExternalViewerAction.actionPerformed.failure.exe.message=The file is an executable and will not be opened." 
  101             JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
 
  102                     Bundle.ExternalViewerAction_actionPerformed_failure_exe_message(),
 
  103                     Bundle.ExternalViewerAction_actionPerformed_failure_title(this.fileObject.getName()),
 
  104                     JOptionPane.ERROR_MESSAGE);
 
  113             logger.log(Level.WARNING, 
"Exception while getting open case.", ex); 
 
  117         tempPath = tempPath + File.separator + this.fileObject.getName();
 
  120         File tempFile = 
new File(tempPath);
 
  121         if (tempFile.exists()) {
 
  125             tempFile.createNewFile();
 
  127         } 
catch (IOException ex) {
 
  128             logger.log(Level.WARNING, 
"Can't save to temporary file.", ex); 
 
  134         tempFile.deleteOnExit();
 
  146         "ExternalViewerAction.actionPerformed.failure.IO.message=There is no associated editor for files of this type or the associated application failed to launch.",
 
  147         "ExternalViewerAction.actionPerformed.failure.support.message=This platform (operating system) does not support opening a file in an editor this way.",
 
  148         "ExternalViewerAction.actionPerformed.failure.missingFile.message=The file no longer exists.",
 
  149         "ExternalViewerAction.actionPerformed.failure.permission.message=Permission to open the file was denied.",
 
  150         "ExternalViewerAction.actionPerformed.failure.open.url=Cannot open URL"})
 
  151     public static void openFile(String mimeType, String ext, File file) {
 
  156         String exePath = ExternalViewerRulesManager.getInstance().getExePathForName(mimeType);
 
  157         if (exePath.equals(
"")) {
 
  158             exePath = ExternalViewerRulesManager.getInstance().getExePathForName(ext);
 
  160         if (!exePath.equals(
"")) {
 
  161             Runtime runtime = Runtime.getRuntime();
 
  162             String[] execArray = 
new String[]{exePath, file.getAbsolutePath()};
 
  164                 runtime.exec(execArray);
 
  165             } 
catch (IOException ex) {
 
  166                 logger.log(Level.WARNING, 
"Could not open the specified viewer for the given file: " + file.getName(), ex); 
 
  167                 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), Bundle.ExternalViewerAction_actionPerformed_failure_IO_message(), Bundle.ExternalViewerAction_actionPerformed_failure_title(file.getName()), JOptionPane.ERROR_MESSAGE);
 
  171                 String localpath = file.getPath();
 
  172                 if (localpath.toLowerCase().contains(
"http")) {
 
  173                     String url_path = file.getPath().replaceAll(
"\\\\", 
"/");
 
  174                     Desktop.getDesktop().browse(
new URI(url_path.replaceFirst(
"/", 
"//")));
 
  176                     Desktop.getDesktop().open(file);
 
  179             } 
catch (IOException ex) {
 
  180                 logger.log(Level.WARNING, 
"Could not find a viewer for the given file: " + file.getName(), ex); 
 
  181                 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
 
  182                         Bundle.ExternalViewerAction_actionPerformed_failure_IO_message(),
 
  183                         Bundle.ExternalViewerAction_actionPerformed_failure_title(file.getName()),
 
  184                         JOptionPane.ERROR_MESSAGE);
 
  185             } 
catch (UnsupportedOperationException ex) {
 
  186                 logger.log(Level.WARNING, 
"Platform cannot open " + file.getName() + 
" in the defined editor.", ex); 
 
  187                 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
 
  188                         Bundle.ExternalViewerAction_actionPerformed_failure_support_message(),
 
  189                         Bundle.ExternalViewerAction_actionPerformed_failure_title(file.getName()),
 
  190                         JOptionPane.ERROR_MESSAGE);
 
  191             } 
catch (IllegalArgumentException ex) {
 
  192                 logger.log(Level.WARNING, 
"Could not find the given file: " + file.getName(), ex); 
 
  193                 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
 
  194                         Bundle.ExternalViewerAction_actionPerformed_failure_missingFile_message(),
 
  195                         Bundle.ExternalViewerAction_actionPerformed_failure_title(file.getName()),
 
  196                         JOptionPane.ERROR_MESSAGE);
 
  197             } 
catch (SecurityException ex) {
 
  198                 logger.log(Level.WARNING, 
"Could not get permission to open the given file: " + file.getName(), ex); 
 
  199                 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
 
  200                         Bundle.ExternalViewerAction_actionPerformed_failure_permission_message(),
 
  201                         Bundle.ExternalViewerAction_actionPerformed_failure_title(file.getName()),
 
  202                         JOptionPane.ERROR_MESSAGE);
 
  203             } 
catch (URISyntaxException ex) {
 
  204                 logger.log(Level.WARNING, 
"Could not open URL provided: " + file.getPath(), ex);
 
  205                 JOptionPane.showMessageDialog(null,
 
  206                         Bundle.ExternalViewerAction_actionPerformed_failure_open_url(),
 
  207                         Bundle.ExternalViewerAction_actionPerformed_failure_title(file.getName()),
 
  208                         JOptionPane.ERROR_MESSAGE);
 
  219         "ExternalViewerAction.actionPerformed.urlFailure.title=Open URL Failure"})
 
  221         String url_path = path.replaceAll(
"\\\\", 
"/");
 
  223             Desktop.getDesktop().browse(
new URI(url_path.replaceFirst(
"/", 
"//")));
 
  224         } 
catch (IOException ex) {
 
  225             logger.log(Level.WARNING, 
"Could not find a viewer for the given URL: " + url_path, ex); 
 
  226             JOptionPane.showMessageDialog(null,
 
  227                     Bundle.ExternalViewerAction_actionPerformed_failure_IO_message(),
 
  228                     Bundle.ExternalViewerAction_actionPerformed_urlFailure_title(),
 
  229                     JOptionPane.ERROR_MESSAGE);
 
  230         } 
catch (UnsupportedOperationException ex) {
 
  231             logger.log(Level.WARNING, 
"Platform cannot open " + url_path + 
" in the defined editor.", ex); 
 
  232             JOptionPane.showMessageDialog(null,
 
  233                     Bundle.ExternalViewerAction_actionPerformed_failure_support_message(),
 
  234                     Bundle.ExternalViewerAction_actionPerformed_urlFailure_title(),
 
  235                     JOptionPane.ERROR_MESSAGE);
 
  236         } 
catch (IllegalArgumentException ex) {
 
  237             logger.log(Level.WARNING, 
"Could not find the given URL: " + url_path, ex); 
 
  238             JOptionPane.showMessageDialog(null,
 
  239                     Bundle.ExternalViewerAction_actionPerformed_failure_missingFile_message(),
 
  240                     Bundle.ExternalViewerAction_actionPerformed_urlFailure_title(),
 
  241                     JOptionPane.ERROR_MESSAGE);
 
  242         } 
catch (SecurityException ex) {
 
  243             logger.log(Level.WARNING, 
"Could not get permission to open the given URL: " + url_path, ex); 
 
  244             JOptionPane.showMessageDialog(null,
 
  245                     Bundle.ExternalViewerAction_actionPerformed_failure_permission_message(),
 
  246                     Bundle.ExternalViewerAction_actionPerformed_urlFailure_title(),
 
  247                     JOptionPane.ERROR_MESSAGE);
 
  248         } 
catch (URISyntaxException ex) {
 
  249             logger.log(Level.WARNING, 
"Could not open URL provided: " + url_path, ex);
 
  250             JOptionPane.showMessageDialog(null,
 
  251                     Bundle.ExternalViewerAction_actionPerformed_failure_open_url(),
 
  252                     Bundle.ExternalViewerAction_actionPerformed_urlFailure_title(),
 
  253                     JOptionPane.ERROR_MESSAGE);
 
static void openURL(String path)
 
String getTempDirectory()
 
static< T > long writeToFile(Content content, java.io.File outputFile, ProgressHandle progress, Future< T > worker, boolean source)
 
static final Logger logger
 
final AbstractFile fileObject
 
static void openFile(String mimeType, String ext, File file)
 
synchronized static Logger getLogger(String name)
 
static Case getCurrentCaseThrows()
 
ExternalViewerAction(String title, Node fileNode)
 
void actionPerformed(ActionEvent e)