Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ArtifactsListPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2020 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.discovery.ui;
20 
21 import java.awt.Point;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.logging.Level;
25 import javax.swing.JPopupMenu;
26 import javax.swing.event.ListSelectionListener;
27 import javax.swing.table.AbstractTableModel;
28 import javax.swing.table.TableCellRenderer;
29 import org.apache.commons.io.FilenameUtils;
30 import org.apache.commons.lang.StringUtils;
31 import org.openide.util.NbBundle;
37 import org.sleuthkit.datamodel.BlackboardArtifact;
38 import org.sleuthkit.datamodel.BlackboardAttribute;
39 import org.sleuthkit.datamodel.TimeUtilities;
40 import org.sleuthkit.datamodel.TskCoreException;
41 
46 final class ArtifactsListPanel extends AbstractArtifactListPanel {
47 
48  private static final long serialVersionUID = 1L;
49  private static final Logger logger = Logger.getLogger(ArtifactsListPanel.class.getName());
50  private final DomainArtifactTableModel tableModel;
51 
57  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
58  ArtifactsListPanel(BlackboardArtifact.ARTIFACT_TYPE artifactType) {
59  tableModel = new DomainArtifactTableModel(artifactType);
60  initComponents();
61  // add the cell renderer to all columns
62  TableCellRenderer renderer = new SimpleTableCellRenderer();
63  for (int i = 0; i < tableModel.getColumnCount(); ++i) {
64  artifactsTable.getColumnModel().getColumn(i).setCellRenderer(renderer);
65  }
66  artifactsTable.getRowSorter().toggleSortOrder(0);
67  artifactsTable.getRowSorter().toggleSortOrder(0);
68  }
69 
70  @Override
71  void addMouseListener(java.awt.event.MouseAdapter mouseListener) {
72  artifactsTable.addMouseListener(mouseListener);
73  }
74 
75  @Override
76  void showPopupMenu(JPopupMenu popupMenu, Point point) {
77  popupMenu.show(artifactsTable, point.x, point.y);
78  }
79 
80  @Override
81  void addSelectionListener(ListSelectionListener listener) {
82  artifactsTable.getSelectionModel().addListSelectionListener(listener);
83  }
84 
85  @Override
86  void removeSelectionListener(ListSelectionListener listener) {
87  artifactsTable.getSelectionModel().removeListSelectionListener(listener);
88  }
89 
90  @Override
91  boolean selectAtPoint(Point point) {
92  boolean pointSelected = false;
93  int row = artifactsTable.rowAtPoint(point);
94  if (row < artifactsTable.getRowCount() && row >= 0) {
95  artifactsTable.clearSelection();
96  artifactsTable.addRowSelectionInterval(row, row);
97  pointSelected = true;
98  }
99  return pointSelected;
100  }
101 
102  @Override
103  BlackboardArtifact getSelectedArtifact() {
104  if (artifactsTable.getModel() instanceof DomainArtifactTableModel) {
105  int selectedIndex = artifactsTable.getSelectionModel().getLeadSelectionIndex();
106  if (selectedIndex < artifactsTable.getSelectionModel().getMinSelectionIndex() || artifactsTable.getSelectionModel().getMaxSelectionIndex() < 0 || selectedIndex > artifactsTable.getSelectionModel().getMaxSelectionIndex()) {
107  return null;
108  }
109  return tableModel.getArtifactByRow(artifactsTable.convertRowIndexToModel(selectedIndex));
110  } else {
111  return null;
112  }
113  }
114 
115  @Override
116  boolean isEmpty() {
117  return tableModel.getRowCount() <= 0;
118  }
119 
120  @Override
121  void selectFirst() {
122  if (!isEmpty()) {
123  artifactsTable.setRowSelectionInterval(0, 0);
124  } else {
125  artifactsTable.clearSelection();
126  }
127  }
128 
135  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
136  @Override
137  void addArtifacts(List<BlackboardArtifact> artifactList) {
138  if (!artifactList.isEmpty()) {
139  artifactsTable.setModel(tableModel);
140  tableModel.setContents(artifactList);
141  } else {
142  artifactsTable.setModel(new EmptyTableModel());
143  }
144  artifactsTable.validate();
145  artifactsTable.repaint();
146  tableModel.fireTableDataChanged();
147  }
148 
152  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
153  @Override
154  void clearList() {
155  tableModel.setContents(new ArrayList<>());
156  tableModel.fireTableDataChanged();
157  }
158 
164  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
165  private void initComponents() {
166 
167  javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
168  artifactsTable = new javax.swing.JTable();
169 
170  setOpaque(false);
171  setPreferredSize(new java.awt.Dimension(350, 10));
172 
173  jScrollPane1.setBorder(null);
174  jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
175  jScrollPane1.setMinimumSize(new java.awt.Dimension(0, 0));
176  jScrollPane1.setPreferredSize(new java.awt.Dimension(350, 10));
177 
178  artifactsTable.setAutoCreateRowSorter(true);
179  artifactsTable.setModel(tableModel);
180  artifactsTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
181  jScrollPane1.setViewportView(artifactsTable);
182 
183  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
184  this.setLayout(layout);
185  layout.setHorizontalGroup(
186  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
187  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
188  );
189  layout.setVerticalGroup(
190  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
191  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
192  );
193  }// </editor-fold>//GEN-END:initComponents
194 
199  private class DomainArtifactTableModel extends AbstractTableModel {
200 
201  private static final long serialVersionUID = 1L;
202  private final List<BlackboardArtifact> artifactList = new ArrayList<>();
203  private final BlackboardArtifact.ARTIFACT_TYPE artifactType;
204 
211  DomainArtifactTableModel(BlackboardArtifact.ARTIFACT_TYPE artifactType) {
212  this.artifactType = artifactType;
213  }
214 
222  void setContents(List<BlackboardArtifact> artifacts) {
223  artifactsTable.clearSelection();
224  artifactList.clear();
225  artifactList.addAll(artifacts);
226  }
227 
229  @Override
230  public int getRowCount() {
231  return artifactList.size();
232  }
233 
235  @Override
236  public int getColumnCount() {
237  if (artifactType == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE) {
238  return 3;
239  } else {
240  return 2;
241  }
242  }
243 
252  BlackboardArtifact getArtifactByRow(int rowIndex) {
253  return artifactList.get(rowIndex);
254  }
255 
257  @NbBundle.Messages({"ArtifactsListPanel.value.noValue=No value available."})
258  @Override
259  public Object getValueAt(int rowIndex, int columnIndex) {
260  if (columnIndex < 2 || artifactType == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE) {
261  final BlackboardArtifact artifact = getArtifactByRow(rowIndex);
262  try {
263  for (BlackboardAttribute bba : artifact.getAttributes()) {
264  if (!StringUtils.isBlank(bba.getDisplayString())) {
265  String stringFromAttribute = getStringForColumn(artifact, bba, columnIndex);
266  if (!StringUtils.isBlank(stringFromAttribute)) {
267  return stringFromAttribute;
268  }
269  }
270  }
271  return getFallbackValue(rowIndex, columnIndex);
272  } catch (TskCoreException ex) {
273  logger.log(Level.WARNING, "Error getting attributes for artifact " + artifact.getArtifactID(), ex);
274  }
275  }
276  return Bundle.ArtifactsListPanel_value_noValue();
277  }
278 
295  private String getStringForColumn(BlackboardArtifact artifact, BlackboardAttribute bba, int columnIndex) throws TskCoreException {
296  if (columnIndex == 0 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED.getTypeID()) {
297  return TimeUtilities.epochToTime(bba.getValueLong(), ContentUtils.getTimeZone(artifact));
298  } else if (columnIndex == 1) {
299  if (artifactType == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD || artifactType == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE) {
300  if (bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()) {
301  return Case.getCurrentCase().getSleuthkitCase().getAbstractFileById(bba.getValueLong()).getName();
302  } else if (bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH.getTypeID()) {
303  return FilenameUtils.getName(bba.getDisplayString());
304  }
305  } else if (bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE.getTypeID()) {
306  return bba.getDisplayString();
307  }
308  } else if (columnIndex == 2 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()) {
309  return Case.getCurrentCase().getSleuthkitCase().getAbstractFileById(bba.getValueLong()).getMIMEType();
310  }
311  return null;
312  }
313 
329  private String getFallbackValue(int rowIndex, int columnIndex) throws TskCoreException {
330  final BlackboardArtifact artifact = getArtifactByRow(rowIndex);
331  for (BlackboardAttribute bba : artifact.getAttributes()) {
332  if (columnIndex == 0 && bba.getAttributeType().getTypeName().startsWith("TSK_DATETIME") && !StringUtils.isBlank(bba.getDisplayString())) {
333  return TimeUtilities.epochToTime(bba.getValueLong(), ContentUtils.getTimeZone(artifact));
334  } else if (columnIndex == 1 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL.getTypeID() && !StringUtils.isBlank(bba.getDisplayString())) {
335  return bba.getDisplayString();
336  } else if (columnIndex == 1 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID() && !StringUtils.isBlank(bba.getDisplayString())) {
337  return bba.getDisplayString();
338  } else if (columnIndex == 1 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT.getTypeID() && !StringUtils.isBlank(bba.getDisplayString())) {
339  return bba.getDisplayString();
340  }
341  }
342  return Bundle.ArtifactsListPanel_value_noValue();
343  }
344 
346  @NbBundle.Messages({"ArtifactsListPanel.titleColumn.name=Title",
347  "ArtifactsListPanel.fileNameColumn.name=Name",
348  "ArtifactsListPanel.dateColumn.name=Date/Time",
349  "ArtifactsListPanel.urlColumn.name=URL",
350  "ArtifactsListPanel.termColumn.name=Term",
351  "ArtifactsListPanel.mimeTypeColumn.name=MIME Type"})
352  @Override
353  public String getColumnName(int column) {
354  switch (column) {
355  case 0:
356  return Bundle.ArtifactsListPanel_dateColumn_name();
357  case 1:
358  if (artifactType != null) {
359  switch (artifactType) {
360  case TSK_WEB_CACHE:
361  case TSK_WEB_DOWNLOAD:
362  return Bundle.ArtifactsListPanel_fileNameColumn_name();
363  case TSK_WEB_COOKIE:
364  return Bundle.ArtifactsListPanel_urlColumn_name();
365  case TSK_WEB_SEARCH_QUERY:
366  return Bundle.ArtifactsListPanel_termColumn_name();
367  default:
368  }
369  }
370  return Bundle.ArtifactsListPanel_titleColumn_name();
371  case 2:
372  return Bundle.ArtifactsListPanel_mimeTypeColumn_name();
373  default:
374  return "";
375  }
376  }
377  }
378 
382  private class EmptyTableModel extends AbstractTableModel {
383 
384  private static final long serialVersionUID = 1L;
385 
386  @Override
387  public int getRowCount() {
388  return 1;
389  }
390 
391  @Override
392  public int getColumnCount() {
393  return 1;
394  }
395 
396  @NbBundle.Messages({"ArtifactsListPanel.noResultsFound.text=No results found"})
397  @Override
398  public Object getValueAt(int rowIndex, int columnIndex) {
399  return Bundle.ArtifactsListPanel_noResultsFound_text();
400  }
401 
402  @Override
403  public String getColumnName(int column) {
404  switch (column) {
405  case 0:
406  return Bundle.ArtifactsListPanel_dateColumn_name();
407  case 1:
408  return Bundle.ArtifactsListPanel_titleColumn_name();
409  case 2:
410  return Bundle.ArtifactsListPanel_mimeTypeColumn_name();
411  default:
412  return "";
413  }
414  }
415 
416  }
417 
418  // Variables declaration - do not modify//GEN-BEGIN:variables
419  private javax.swing.JTable artifactsTable;
420  // End of variables declaration//GEN-END:variables
421 }
static TimeZone getTimeZone(Content content)
String getStringForColumn(BlackboardArtifact artifact, BlackboardAttribute bba, int columnIndex)

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