From 870546fa2cad38a33d62083c2fea5f7de8a879f9 Mon Sep 17 00:00:00 2001 From: Kelly Kelly Date: Wed, 4 Dec 2019 11:51:38 -0500 Subject: [PATCH] Added mbtile test button --- .../autopsy/geolocation/Bundle.properties | 1 + .../geolocation/Bundle.properties-MERGED | 9 +++ .../geolocation/GeolocationSettingsPanel.form | 19 +++++- .../geolocation/GeolocationSettingsPanel.java | 64 ++++++++++++++++++- 4 files changed, 89 insertions(+), 4 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/geolocation/Bundle.properties b/Core/src/org/sleuthkit/autopsy/geolocation/Bundle.properties index 5f7678fa4e..6a5c3584a5 100755 --- a/Core/src/org/sleuthkit/autopsy/geolocation/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/geolocation/Bundle.properties @@ -34,3 +34,4 @@ GeolocationSettingsPanel.zipFilePathField.text= GeolocationSettingsPanel.serverTestBtn.text=Test GeolocationSettingsPanel.mbtilesBrowseBtn.text=Browse GeolocationSettingsPanel.zipFileBrowseBnt.text=Browse +GeolocationSettingsPanel.mbtileTestBtn.text=Test diff --git a/Core/src/org/sleuthkit/autopsy/geolocation/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/geolocation/Bundle.properties-MERGED index 528a2ff9cf..f0aaabcc6a 100755 --- a/Core/src/org/sleuthkit/autopsy/geolocation/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/geolocation/Bundle.properties-MERGED @@ -3,6 +3,14 @@ CTL_GeolocationTopComponentAction=GeolocationTopComponent CTL_GeolocationTopComponent=Geolocation GeoFilterPanel_DataSource_List_Title=Data Sources GeoFilterPanel_empty_dataSource=Data Source list is empty. +GeolocationSettings_mbtile_does_not_exist_message=The file supplied does not exist.\nPlease verify that the file exists and try again. +GeolocationSettings_mbtile_does_not_exist_title=File Not Found +GeolocationSettings_mbtile_not_valid_message=The supplied file is not a raster tile file. +GeolocationSettings_mbtile_not_valid_title=File Not Valid +GeolocationSettings_mbtile_test_success_message=The supplied file is a valid mbtile raster file. +GeolocationSettings_mbtile_test_success_title=Success +GeolocationSettings_path_not_valid_message=The supplied file path is empty.\nPlease supply a valid file path. +GeolocationSettings_path_not_valid_title=File Not Valid GeolocationSettingsPanel_malformed_url_message=The supplies OSM tile server address is invalid.\nPlease supply a well formed url prefixed with http:// GeolocationSettingsPanel_malformed_url_message_tile=Malformed URL GeolocationSettingsPanel_osm_server_test_fail_message=OSM tile server test failed.\nUnable to connect to server. @@ -58,4 +66,5 @@ GeolocationSettingsPanel.zipFilePathField.text= GeolocationSettingsPanel.serverTestBtn.text=Test GeolocationSettingsPanel.mbtilesBrowseBtn.text=Browse GeolocationSettingsPanel.zipFileBrowseBnt.text=Browse +GeolocationSettingsPanel.mbtileTestBtn.text=Test WaypointExtractAction_label=Extract Files(s) diff --git a/Core/src/org/sleuthkit/autopsy/geolocation/GeolocationSettingsPanel.form b/Core/src/org/sleuthkit/autopsy/geolocation/GeolocationSettingsPanel.form index 421eb626df..e2121d0772 100755 --- a/Core/src/org/sleuthkit/autopsy/geolocation/GeolocationSettingsPanel.form +++ b/Core/src/org/sleuthkit/autopsy/geolocation/GeolocationSettingsPanel.form @@ -61,7 +61,7 @@ - + @@ -145,7 +145,7 @@ - + @@ -215,6 +215,21 @@ + + + + + + + + + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/geolocation/GeolocationSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/geolocation/GeolocationSettingsPanel.java index a43917791b..62f8b7253f 100755 --- a/Core/src/org/sleuthkit/autopsy/geolocation/GeolocationSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/geolocation/GeolocationSettingsPanel.java @@ -20,7 +20,9 @@ package org.sleuthkit.autopsy.geolocation; import java.awt.Color; import java.io.File; +import java.sql.SQLException; import java.util.Arrays; +import java.util.logging.Level; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import org.apache.commons.validator.routines.UrlValidator; @@ -28,10 +30,12 @@ import org.jxmapviewer.OSMTileFactoryInfo; import org.jxmapviewer.viewer.TileFactoryInfo; import org.jxmapviewer.viewer.util.GeoUtil; import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.Exceptions; import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.casemodule.GeneralFilter; import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.corecomponents.OptionsPanel; +import org.sleuthkit.autopsy.coreutils.Logger; /** * A panel to allow the user to set the custom properties of the geolocation @@ -41,6 +45,8 @@ import org.sleuthkit.autopsy.corecomponents.OptionsPanel; final class GeolocationSettingsPanel extends javax.swing.JPanel implements OptionsPanel { private static final long serialVersionUID = 1L; + + private static final Logger logger = Logger.getLogger(GeolocationSettingsPanel.class.getName()); /** * Creates new GeolocationSettingsPanel @@ -92,6 +98,7 @@ final class GeolocationSettingsPanel extends javax.swing.JPanel implements Optio zipFileBrowseBnt.setEnabled(zipFileRBnt.isSelected()); mbtileFileField.setEnabled(mbtilesRBtn.isSelected()); mbtilesBrowseBtn.setEnabled(mbtilesRBtn.isSelected()); + mbtileTestBtn.setEnabled(mbtilesRBtn.isSelected()); } /** @@ -154,6 +161,7 @@ final class GeolocationSettingsPanel extends javax.swing.JPanel implements Optio mbtilesRBtn = new javax.swing.JRadioButton(); mbtileFileField = new javax.swing.JTextField(); mbtilesBrowseBtn = new javax.swing.JButton(); + mbtileTestBtn = new javax.swing.JButton(); setLayout(new java.awt.GridBagLayout()); @@ -171,7 +179,7 @@ final class GeolocationSettingsPanel extends javax.swing.JPanel implements Optio gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; - gridBagConstraints.gridwidth = 3; + gridBagConstraints.gridwidth = 4; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(9, 0, 9, 0); @@ -230,7 +238,6 @@ final class GeolocationSettingsPanel extends javax.swing.JPanel implements Optio gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 9, 9, 9); tilePane.add(zipFileBrowseBnt, gridBagConstraints); @@ -284,6 +291,20 @@ final class GeolocationSettingsPanel extends javax.swing.JPanel implements Optio gridBagConstraints.insets = new java.awt.Insets(0, 9, 9, 9); tilePane.add(mbtilesBrowseBtn, gridBagConstraints); + org.openide.awt.Mnemonics.setLocalizedText(mbtileTestBtn, org.openide.util.NbBundle.getMessage(GeolocationSettingsPanel.class, "GeolocationSettingsPanel.mbtileTestBtn.text")); // NOI18N + mbtileTestBtn.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + mbtileTestBtnActionPerformed(evt); + } + }); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 3; + gridBagConstraints.gridy = 3; + gridBagConstraints.ipadx = 20; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 1.0; + tilePane.add(mbtileTestBtn, gridBagConstraints); + gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; @@ -369,10 +390,49 @@ final class GeolocationSettingsPanel extends javax.swing.JPanel implements Optio } }//GEN-LAST:event_mbtilesBrowseBtnActionPerformed + @Messages({ + "GeolocationSettings_mbtile_does_not_exist_message=The file supplied does not exist.\nPlease verify that the file exists and try again.", + "GeolocationSettings_mbtile_does_not_exist_title=File Not Found", + "GeolocationSettings_mbtile_not_valid_message=The supplied file is not a raster tile file.", + "GeolocationSettings_mbtile_not_valid_title=File Not Valid", + "GeolocationSettings_path_not_valid_message=The supplied file path is empty.\nPlease supply a valid file path.", + "GeolocationSettings_path_not_valid_title=File Not Valid", + "GeolocationSettings_mbtile_test_success_message=The supplied file is a valid mbtile raster file.", + "GeolocationSettings_mbtile_test_success_title=Success", + }) + private void mbtileTestBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mbtileTestBtnActionPerformed + String mbtilePath = mbtileFileField.getText(); + + if(mbtilePath.isEmpty()) { + JOptionPane.showMessageDialog(this, Bundle.GeolocationSettings_path_not_valid_message(), Bundle.GeolocationSettings_path_not_valid__title(), JOptionPane.ERROR_MESSAGE); + return; + } + + File file = new File(mbtilePath); + if(!file.exists()) { + JOptionPane.showMessageDialog(this, Bundle.GeolocationSettings_mbtile_does_not_exist_message(), Bundle.GeolocationSettings_mbtile_does_not_exist_title(), JOptionPane.ERROR_MESSAGE); + return; + } + + try { + if(!MBTilesFileConnector.isValidMBTileRasterFile(mbtilePath)) { + JOptionPane.showMessageDialog(this, Bundle.GeolocationSettings_mbtile_not_valid_message(), Bundle.GeolocationSettings_mbtile_not_valid_title(), JOptionPane.ERROR_MESSAGE); + return; + } + } catch (SQLException ex) { + JOptionPane.showMessageDialog(this, Bundle.GeolocationSettings_mbtile_not_valid_message(), Bundle.GeolocationSettings_mbtile_not_valid_title(), JOptionPane.ERROR_MESSAGE); + logger.log(Level.WARNING, String.format("Exception thrown while testing mbtile file %s", mbtilePath), ex); + return; + } + + JOptionPane.showMessageDialog(this, Bundle.GeolocationSettings_mbtile_test_success_message(), Bundle.GeolocationSettings_mbtile_test_success_title(), JOptionPane.INFORMATION_MESSAGE); + }//GEN-LAST:event_mbtileTestBtnActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JRadioButton defaultDataSource; private javax.swing.JTextField mbtileFileField; + private javax.swing.JButton mbtileTestBtn; private javax.swing.JButton mbtilesBrowseBtn; private javax.swing.JRadioButton mbtilesRBtn; private javax.swing.JTextField osmServerAddressField;