Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
LogicalEvidenceFilePanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.casemodule;
20 
21 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.Set;
25 import java.util.TreeSet;
26 import javax.swing.JFileChooser;
27 import org.openide.util.NbBundle;
30 import java.util.logging.Level;
31 import javax.swing.event.DocumentEvent;
32 import javax.swing.event.DocumentListener;
33 import org.apache.commons.io.FilenameUtils;
34 import org.apache.commons.lang3.StringUtils;
35 import org.openide.util.NbBundle.Messages;
38 
42 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
43 final class LogicalEvidenceFilePanel extends javax.swing.JPanel implements DocumentListener {
44 
45  private static final long serialVersionUID = 1L;
46 
47  private final Set<File> currentFiles = new TreeSet<>(); //keep currents in a set to disallow duplicates per add
48  private static final Logger logger = Logger.getLogger(LocalFilesPanel.class.getName());
49  private String displayName = "";
50 
54  private LogicalEvidenceFilePanel() {
55  initComponents();
56  logicalEvidenceFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
57  logicalEvidenceFileChooser.setAcceptAllFileFilterUsed(false);
58  logicalEvidenceFileChooser.setMultiSelectionEnabled(false);
59  logicalEvidenceFileChooser.setFileFilter(LocalFilesDSProcessor.getLogicalEvidenceFilter());
60  }
61 
67  static LogicalEvidenceFilePanel createInstance() {
68  synchronized (LogicalEvidenceFilePanel.class) {
69  final LogicalEvidenceFilePanel instance = new LogicalEvidenceFilePanel();
70  // post-constructor initialization of listener support without leaking references of uninitialized objects
71  instance.logicalEvidencePathField.getDocument().addDocumentListener(instance);
72  return instance;
73  }
74  }
75 
81  @SuppressWarnings("unchecked")
82  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
83  private void initComponents() {
84 
85  logicalEvidenceFileChooser = new javax.swing.JFileChooser();
86  selectButton = new javax.swing.JButton();
87  logicalEvidencePathField = new javax.swing.JTextField();
88  errorLabel = new javax.swing.JLabel();
89 
90  logicalEvidenceFileChooser.setApproveButtonText(org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class, "LogicalEvidenceFilePanel.logicalEvidenceFileChooser.approveButtonText")); // NOI18N
91  logicalEvidenceFileChooser.setApproveButtonToolTipText(org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class, "LogicalEvidenceFilePanel.logicalEvidenceFileChooser.approveButtonToolTipText")); // NOI18N
92  logicalEvidenceFileChooser.setDialogTitle(org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class, "LogicalEvidenceFilePanel.logicalEvidenceFileChooser.dialogTitle")); // NOI18N
93  logicalEvidenceFileChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
94 
95  org.openide.awt.Mnemonics.setLocalizedText(selectButton, org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class, "LogicalEvidenceFilePanel.selectButton.text")); // NOI18N
96  selectButton.setToolTipText(org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class, "LogicalEvidenceFilePanel.selectButton.toolTipText")); // NOI18N
97  selectButton.setActionCommand(org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class, "LogicalEvidenceFilePanel.selectButton.actionCommand")); // NOI18N
98  selectButton.setMaximumSize(new java.awt.Dimension(70, 23));
99  selectButton.setMinimumSize(new java.awt.Dimension(70, 23));
100  selectButton.setPreferredSize(new java.awt.Dimension(70, 23));
101  selectButton.addActionListener(new java.awt.event.ActionListener() {
102  public void actionPerformed(java.awt.event.ActionEvent evt) {
103  selectButtonActionPerformed(evt);
104  }
105  });
106 
107  logicalEvidencePathField.setText(org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class, "LogicalEvidenceFilePanel.logicalEvidencePathField.text")); // NOI18N
108  logicalEvidencePathField.setPreferredSize(new java.awt.Dimension(379, 20));
109 
110  errorLabel.setForeground(new java.awt.Color(255, 0, 0));
111  org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class, "LogicalEvidenceFilePanel.errorLabel.text")); // NOI18N
112 
113  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
114  this.setLayout(layout);
115  layout.setHorizontalGroup(
116  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
117  .addGroup(layout.createSequentialGroup()
118  .addContainerGap()
119  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
120  .addGroup(layout.createSequentialGroup()
121  .addComponent(errorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
122  .addContainerGap())
123  .addGroup(layout.createSequentialGroup()
124  .addComponent(logicalEvidencePathField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
125  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
126  .addComponent(selectButton, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
127  .addGap(4, 4, 4))))
128  );
129  layout.setVerticalGroup(
130  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
131  .addGroup(layout.createSequentialGroup()
132  .addGap(0, 0, 0)
133  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
134  .addComponent(selectButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
135  .addComponent(logicalEvidencePathField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
136  .addGap(18, 18, 18)
137  .addComponent(errorLabel)
138  .addContainerGap(105, Short.MAX_VALUE))
139  );
140  }// </editor-fold>//GEN-END:initComponents
141 
142 
143  private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
144  final int returnVal = logicalEvidenceFileChooser.showOpenDialog(this);
145 
146  if (returnVal == JFileChooser.APPROVE_OPTION) {
147  final File file = logicalEvidenceFileChooser.getSelectedFile();
148  final StringBuilder allPaths = new StringBuilder();
149  currentFiles.add(file);
150  allPaths.append(file.getAbsolutePath());
151  logicalEvidencePathField.setText(allPaths.toString());
152  logicalEvidencePathField.setToolTipText(allPaths.toString());
153  }
154  fireChange();
155  }//GEN-LAST:event_selectButtonActionPerformed
156 
157  /*
158  * Clear previously selected items on the panel.
159  */
160  void reset() {
161  currentFiles.clear();
162  logicalEvidencePathField.setText("");
163  logicalEvidencePathField.setToolTipText("");
164  }
165 
166  // Variables declaration - do not modify//GEN-BEGIN:variables
167  private javax.swing.JLabel errorLabel;
168  private javax.swing.JFileChooser logicalEvidenceFileChooser;
169  private javax.swing.JTextField logicalEvidencePathField;
170  private javax.swing.JButton selectButton;
171  // End of variables declaration//GEN-END:variables
172 
180  @Messages({
181  "LogicalEvidenceFilePanel.validatePanel.nonL01Error.text=Only files with the .l01 file extension are supported here.",
182  "LogicalEvidenceFilePanel.pathValidation.dataSourceOnCDriveError=Warning: Path to multi-user data source is on \"C:\" drive",
183  "LogicalEvidenceFilePanel.pathValidation.getOpenCase.Error=Warning: Exception while getting open case."
184  })
185  boolean validatePanel() {
186  errorLabel.setVisible(false);
187  // display warning if there is one (but don't disable "next" button)
188  final String path = logicalEvidencePathField.getText();
189  if (StringUtils.isBlank(path)) {
190  return false;
191  }
192  // display warning if there is one (but don't disable "next" button)
193  try {
194  if (!PathValidator.isValidForMultiUserCase(path, Case.getCurrentCaseThrows().getCaseType())) {
195  errorLabel.setVisible(true);
196  errorLabel.setText(Bundle.LogicalEvidenceFilePanel_pathValidation_dataSourceOnCDriveError());
197  return false;
198  }
199  } catch (NoCurrentCaseException ex) {
200  errorLabel.setVisible(true);
201  errorLabel.setText(Bundle.LogicalEvidenceFilePanel_pathValidation_getOpenCase_Error());
202  return false;
203  }
204  //check the extension incase the path was manually entered
205  if (!LocalFilesDSProcessor.getLogicalEvidenceFilter().accept(new File(path))) {
206  errorLabel.setVisible(true);
207  errorLabel.setText(Bundle.LogicalEvidenceFilePanel_validatePanel_nonL01Error_text());
208  return false;
209  }
210 
211  displayName = FilenameUtils.getName(path);
212  return new File(path).isFile();
213  }
214 
220  List<String> getContentPaths() {
221  final List<String> pathsList = new ArrayList<>();
222  if (currentFiles == null) {
223  return pathsList;
224  }
225  for (final File f : currentFiles) {
226  pathsList.add(f.getAbsolutePath());
227  }
228  return pathsList;
229  }
230 
236  String getFileSetName() {
237  return displayName;
238  }
239 
240  @Override
241  public void insertUpdate(final DocumentEvent docEvent) {
242  fireChange();
243  }
244 
245  @Override
246  public void removeUpdate(final DocumentEvent docEvent) {
247  fireChange();
248  }
249 
250  @Override
251  public void changedUpdate(final DocumentEvent docEvent) {
252  fireChange();
253  }
254 
255  @Messages({
256  "LogicalEvidenceFilePanel.moduleErr.name=Module Error",
257  "LogicalEvidenceFilePanel.moduleErr.msg=A module caused an error listening to LogicalEvidenceFilePanel updates. See log to determine which module. Some data could be incomplete."
258  })
259  private void fireChange() {
260  try {
261  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
262  } catch (Exception e) {
263  logger.log(Level.SEVERE, "LogicalEvidenceFilePanel listener threw exception", e); //NON-NLS
264  MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "LogicalEvidenceFilePanel.moduleErr"),
265  NbBundle.getMessage(this.getClass(), "LogicalEvidenceFilePanel.moduleErr.msg"),
266  MessageNotifyUtil.MessageType.ERROR);
267  }
268  }
269 }

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.