Autopsy 4.22.1
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-2021 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 */
19package org.sleuthkit.autopsy.discovery.ui;
20
21import java.awt.Dimension;
22import java.awt.Point;
23import java.util.ArrayList;
24import java.util.List;
25import java.util.logging.Level;
26import javax.swing.JPopupMenu;
27import javax.swing.event.ListSelectionListener;
28import javax.swing.table.AbstractTableModel;
29import javax.swing.table.TableCellRenderer;
30import org.apache.commons.io.FilenameUtils;
31import org.apache.commons.lang.StringUtils;
32import org.openide.util.NbBundle;
33import org.sleuthkit.autopsy.casemodule.Case;
34import org.sleuthkit.autopsy.coreutils.Logger;
35import org.sleuthkit.autopsy.coreutils.ThreadConfined;
36import org.sleuthkit.autopsy.coreutils.TimeZoneUtils;
37import org.sleuthkit.autopsy.guiutils.SimpleTableCellRenderer;
38import org.sleuthkit.datamodel.BlackboardArtifact;
39import org.sleuthkit.datamodel.BlackboardAttribute;
40import org.sleuthkit.datamodel.TskCoreException;
41
46final 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 setMinimumSize(new Dimension(125, 20));
67 artifactsTable.getRowSorter().toggleSortOrder(0);
68 artifactsTable.getRowSorter().toggleSortOrder(0);
69 }
70
71 @Override
72 void addMouseListener(java.awt.event.MouseAdapter mouseListener) {
73 artifactsTable.addMouseListener(mouseListener);
74 }
75
76 @Override
77 void showPopupMenu(JPopupMenu popupMenu, Point point) {
78 popupMenu.show(artifactsTable, point.x, point.y);
79 }
80
81 @Override
82 void addSelectionListener(ListSelectionListener listener) {
83 artifactsTable.getSelectionModel().addListSelectionListener(listener);
84 }
85
89 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
90 void focusList() {
91 artifactsTable.grabFocus();
92 }
93
94 @Override
95 void removeSelectionListener(ListSelectionListener listener) {
96 artifactsTable.getSelectionModel().removeListSelectionListener(listener);
97 }
98
99 @Override
100 boolean selectAtPoint(Point point) {
101 boolean pointSelected = false;
102 int row = artifactsTable.rowAtPoint(point);
103 if (row < artifactsTable.getRowCount() && row >= 0) {
104 artifactsTable.clearSelection();
105 artifactsTable.addRowSelectionInterval(row, row);
106 pointSelected = true;
107 }
108 return pointSelected;
109 }
110
111 @Override
112 BlackboardArtifact getSelectedArtifact() {
113 if (artifactsTable.getModel() instanceof DomainArtifactTableModel) {
114 int selectedIndex = artifactsTable.getSelectionModel().getLeadSelectionIndex();
115 if (selectedIndex < artifactsTable.getSelectionModel().getMinSelectionIndex() || artifactsTable.getSelectionModel().getMaxSelectionIndex() < 0 || selectedIndex > artifactsTable.getSelectionModel().getMaxSelectionIndex()) {
116 return null;
117 }
118 return tableModel.getArtifactByRow(artifactsTable.convertRowIndexToModel(selectedIndex));
119 } else {
120 return null;
121 }
122 }
123
124 @Override
125 boolean isEmpty() {
126 return tableModel.getRowCount() <= 0;
127 }
128
129 @Override
130 void selectFirst() {
131 if (!isEmpty()) {
132 artifactsTable.setRowSelectionInterval(0, 0);
133 } else {
134 artifactsTable.clearSelection();
135 }
136 }
137
144 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
145 @Override
146 void addArtifacts(List<BlackboardArtifact> artifactList) {
147 if (!artifactList.isEmpty()) {
148 artifactsTable.setModel(tableModel);
149 tableModel.setContents(artifactList);
150 } else {
151 artifactsTable.setModel(new EmptyTableModel());
152 }
153 artifactsTable.validate();
154 artifactsTable.repaint();
155 tableModel.fireTableDataChanged();
156 }
157
161 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
162 @Override
163 void clearList() {
164 addArtifacts(new ArrayList<>());
165 }
166
172 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
173 private void initComponents() {
174
175 javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
176 artifactsTable = new javax.swing.JTable();
177
178 setOpaque(false);
179 setPreferredSize(new java.awt.Dimension(350, 10));
180
181 jScrollPane1.setBorder(null);
182 jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
183 jScrollPane1.setMinimumSize(new java.awt.Dimension(0, 0));
184 jScrollPane1.setPreferredSize(new java.awt.Dimension(350, 10));
185
186 artifactsTable.setAutoCreateRowSorter(true);
187 artifactsTable.setModel(tableModel);
188 artifactsTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
189 jScrollPane1.setViewportView(artifactsTable);
190
191 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
192 this.setLayout(layout);
193 layout.setHorizontalGroup(
194 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
195 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
196 );
197 layout.setVerticalGroup(
198 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
199 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
200 );
201 }// </editor-fold>//GEN-END:initComponents
202
207 private class DomainArtifactTableModel extends AbstractTableModel {
208
209 private static final long serialVersionUID = 1L;
210 private final List<BlackboardArtifact> artifactList = new ArrayList<>();
211 private final BlackboardArtifact.ARTIFACT_TYPE artifactType;
212
219 DomainArtifactTableModel(BlackboardArtifact.ARTIFACT_TYPE artifactType) {
220 this.artifactType = artifactType;
221 }
222
230 void setContents(List<BlackboardArtifact> artifacts) {
231 artifactsTable.clearSelection();
232 artifactList.clear();
233 artifactList.addAll(artifacts);
234 }
235
237 @Override
238 public int getRowCount() {
239 return artifactList.size();
240 }
241
243 @Override
244 public int getColumnCount() {
245 if (artifactType == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE) {
246 return 3;
247 } else {
248 return 2;
249 }
250 }
251
260 BlackboardArtifact getArtifactByRow(int rowIndex) {
261 return artifactList.get(rowIndex);
262 }
263
265 @NbBundle.Messages({"ArtifactsListPanel.value.noValue=No value available."})
266 @Override
267 public Object getValueAt(int rowIndex, int columnIndex) {
268 if (columnIndex < 2 || artifactType == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE) {
269 final BlackboardArtifact artifact = getArtifactByRow(rowIndex);
270 try {
271 for (BlackboardAttribute bba : artifact.getAttributes()) {
272 if (!StringUtils.isBlank(bba.getDisplayString())) {
273 String stringFromAttribute = getStringForColumn(artifact, bba, columnIndex);
274 if (!StringUtils.isBlank(stringFromAttribute)) {
275 return stringFromAttribute;
276 }
277 }
278 }
279 return getFallbackValue(rowIndex, columnIndex);
280 } catch (TskCoreException ex) {
281 logger.log(Level.WARNING, "Error getting attributes for artifact " + artifact.getArtifactID(), ex);
282 }
283 }
284 return Bundle.ArtifactsListPanel_value_noValue();
285 }
286
303 private String getStringForColumn(BlackboardArtifact artifact, BlackboardAttribute bba, int columnIndex) throws TskCoreException {
304 if (columnIndex == 0 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED.getTypeID()) {
305 return TimeZoneUtils.getFormattedTime(bba.getValueLong());
306 } else if (columnIndex == 1) {
307 if (artifactType == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD || artifactType == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE) {
308 if (bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()) {
309 return Case.getCurrentCase().getSleuthkitCase().getAbstractFileById(bba.getValueLong()).getName();
310 } else if (bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH.getTypeID()) {
311 return FilenameUtils.getName(bba.getDisplayString());
312 }
313 } else if (bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE.getTypeID()) {
314 return bba.getDisplayString();
315 }
316 } else if (columnIndex == 2 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()) {
317 return Case.getCurrentCase().getSleuthkitCase().getAbstractFileById(bba.getValueLong()).getMIMEType();
318 }
319 return null;
320 }
321
337 private String getFallbackValue(int rowIndex, int columnIndex) throws TskCoreException {
338 final BlackboardArtifact artifact = getArtifactByRow(rowIndex);
339 for (BlackboardAttribute bba : artifact.getAttributes()) {
340 if (columnIndex == 0 && bba.getAttributeType().getTypeName().startsWith("TSK_DATETIME") && !StringUtils.isBlank(bba.getDisplayString())) {
341 return TimeZoneUtils.getFormattedTime(bba.getValueLong());
342 } else if (columnIndex == 1 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL.getTypeID() && !StringUtils.isBlank(bba.getDisplayString())) {
343 return bba.getDisplayString();
344 } else if (columnIndex == 1 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID() && !StringUtils.isBlank(bba.getDisplayString())) {
345 return bba.getDisplayString();
346 } else if (columnIndex == 1 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT.getTypeID() && !StringUtils.isBlank(bba.getDisplayString())) {
347 return bba.getDisplayString();
348 }
349 }
350 return Bundle.ArtifactsListPanel_value_noValue();
351 }
352
354 @NbBundle.Messages({"ArtifactsListPanel.titleColumn.name=Title",
355 "ArtifactsListPanel.fileNameColumn.name=Name",
356 "ArtifactsListPanel.dateColumn.name=Date/Time",
357 "ArtifactsListPanel.urlColumn.name=URL",
358 "ArtifactsListPanel.termColumn.name=Term",
359 "ArtifactsListPanel.mimeTypeColumn.name=MIME Type"})
360 @Override
361 public String getColumnName(int column) {
362 switch (column) {
363 case 0:
364 return Bundle.ArtifactsListPanel_dateColumn_name();
365 case 1:
366 if (artifactType != null) {
367 switch (artifactType) {
368 case TSK_WEB_CACHE:
369 case TSK_WEB_DOWNLOAD:
370 return Bundle.ArtifactsListPanel_fileNameColumn_name();
371 case TSK_WEB_COOKIE:
372 return Bundle.ArtifactsListPanel_urlColumn_name();
373 case TSK_WEB_SEARCH_QUERY:
374 return Bundle.ArtifactsListPanel_termColumn_name();
375 default:
376 }
377 }
378 return Bundle.ArtifactsListPanel_titleColumn_name();
379 case 2:
380 return Bundle.ArtifactsListPanel_mimeTypeColumn_name();
381 default:
382 return "";
383 }
384 }
385 }
386
390 private class EmptyTableModel extends AbstractTableModel {
391
392 private static final long serialVersionUID = 1L;
393
394 @Override
395 public int getRowCount() {
396 return 1;
397 }
398
399 @Override
400 public int getColumnCount() {
401 return 1;
402 }
403
404 @NbBundle.Messages({"ArtifactsListPanel.noResultsFound.text=No results found"})
405 @Override
406 public Object getValueAt(int rowIndex, int columnIndex) {
407 return Bundle.ArtifactsListPanel_noResultsFound_text();
408 }
409
410 @Override
411 public String getColumnName(int column) {
412 switch (column) {
413 case 0:
414 return Bundle.ArtifactsListPanel_dateColumn_name();
415 case 1:
416 return Bundle.ArtifactsListPanel_titleColumn_name();
417 case 2:
418 return Bundle.ArtifactsListPanel_mimeTypeColumn_name();
419 default:
420 return "";
421 }
422 }
423
424 }
425
426 // Variables declaration - do not modify//GEN-BEGIN:variables
427 private javax.swing.JTable artifactsTable;
428 // End of variables declaration//GEN-END:variables
429}
static String getFormattedTime(long epochTime)
String getStringForColumn(BlackboardArtifact artifact, BlackboardAttribute bba, int columnIndex)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.