Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
Reports.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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.datamodel;
20 
21 import java.awt.event.ActionEvent;
22 import java.beans.PropertyChangeEvent;
23 import java.io.File;
24 import java.text.SimpleDateFormat;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collection;
28 import java.util.EnumSet;
29 import java.util.List;
30 import java.util.Set;
31 import java.util.logging.Level;
32 import javax.swing.AbstractAction;
33 import javax.swing.Action;
34 import javax.swing.JOptionPane;
35 import org.openide.nodes.ChildFactory;
36 import org.openide.nodes.Children;
37 import org.openide.nodes.Node;
38 import org.openide.nodes.Sheet;
39 import org.openide.util.NbBundle;
40 import org.openide.util.Utilities;
41 import org.openide.util.lookup.Lookups;
47 import org.sleuthkit.datamodel.Report;
48 import org.sleuthkit.datamodel.TskCoreException;
49 
53 public final class Reports implements AutopsyVisitableItem {
54 
55  private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
56 
57  @Override
58  public <T> T accept(AutopsyItemVisitor<T> visitor) {
59  // CreateAutopsyNodeVisitor.visit() constructs a ReportsListNode.
60  return visitor.visit(this);
61  }
62 
66  public static final class ReportsListNode extends DisplayableItemNode {
67 
68  private static final long serialVersionUID = 1L;
69  private static final String DISPLAY_NAME = NbBundle.getMessage(ReportsListNode.class, "ReportsListNode.displayName");
70  private static final String ICON_PATH = "org/sleuthkit/autopsy/images/report_16.png"; //NON-NLS
71 
72  public ReportsListNode() {
73  super(Children.create(new ReportNodeFactory(), true));
74  setName(DISPLAY_NAME);
75  setDisplayName(DISPLAY_NAME);
76  this.setIconBaseWithExtension(ICON_PATH);
77  }
78 
79  @Override
80  public boolean isLeafTypeNode() {
81  return true;
82  }
83 
84  @Override
85  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
86  // - GetPopupActionsDisplayableItemNodeVisitor.visit() returns null.
87  // - GetPreferredActionsDisplayableItemNodeVisitor.visit() returns null.
88  // - IsLeafItemVisitor.visit() returns false.
89  // - ShowItemVisitor.visit() returns true.
90  return visitor.visit(this);
91  }
92 
93  @Override
94  public String getItemType() {
95  return getClass().getName();
96  }
97  }
98 
103  private static final class ReportNodeFactory extends ChildFactory<Report> {
104 
106 
108  Case.addEventTypeSubscriber(CASE_EVENTS_OF_INTEREST, (PropertyChangeEvent evt) -> {
109  String eventType = evt.getPropertyName();
110  if (eventType.equals(Case.Events.REPORT_ADDED.toString()) || eventType.equals(Case.Events.REPORT_DELETED.toString())) {
117  try {
118  Case.getOpenCase();
119  ReportNodeFactory.this.refresh(true);
120  } catch (NoCurrentCaseException notUsed) {
124  }
125  }
126  });
127  }
128 
129  @Override
130  protected boolean createKeys(List<Report> keys) {
131  try {
132  keys.addAll(Case.getOpenCase().getAllReports());
133  } catch (TskCoreException | NoCurrentCaseException ex) {
134  Logger.getLogger(Reports.ReportNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get reports", ex); //NON-NLS
135  }
136  return true;
137  }
138 
139  @Override
140  protected Node createNodeForKey(Report key) {
141  return new ReportNode(key);
142  }
143  }
144 
149  public static final class ReportNode extends DisplayableItemNode {
150 
151  private static final long serialVersionUID = 1L;
152  private static final String ICON_PATH = "org/sleuthkit/autopsy/images/report_16.png"; //NON-NLS
153  private final Report report;
154 
155  ReportNode(Report report) {
156  super(Children.LEAF, Lookups.fixed(report));
157  this.report = report;
158  super.setName(this.report.getSourceModuleName());
159  super.setDisplayName(this.report.getSourceModuleName());
160  this.setIconBaseWithExtension(ICON_PATH);
161  }
162 
163  @Override
164  public boolean isLeafTypeNode() {
165  return true;
166  }
167 
168  @Override
169  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
170  // - GetPopupActionsDisplayableItemNodeVisitor.visit() calls getActions().
171  // - GetPreferredActionsDisplayableItemNodeVisitor.visit() calls getPreferredAction().
172  // - IsLeafItemVisitor.visit() returns true.
173  // - ShowItemVisitor.visit() returns true.
174  return visitor.visit(this);
175  }
176 
177  @Override
178  protected Sheet createSheet() {
179  Sheet sheet = super.createSheet();
180  Sheet.Set propertiesSet = sheet.get(Sheet.PROPERTIES);
181  if (propertiesSet == null) {
182  propertiesSet = Sheet.createPropertiesSet();
183  sheet.put(propertiesSet);
184  }
185  propertiesSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ReportNode.sourceModuleNameProperty.name"),
186  NbBundle.getMessage(this.getClass(), "ReportNode.sourceModuleNameProperty.displayName"),
187  NbBundle.getMessage(this.getClass(), "ReportNode.sourceModuleNameProperty.desc"),
188  this.report.getSourceModuleName()));
189  propertiesSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ReportNode.reportNameProperty.name"),
190  NbBundle.getMessage(this.getClass(), "ReportNode.reportNameProperty.displayName"),
191  NbBundle.getMessage(this.getClass(), "ReportNode.reportNameProperty.desc"),
192  this.report.getReportName()));
193  propertiesSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ReportNode.createdTimeProperty.name"),
194  NbBundle.getMessage(this.getClass(), "ReportNode.createdTimeProperty.displayName"),
195  NbBundle.getMessage(this.getClass(), "ReportNode.createdTimeProperty.desc"),
196  dateFormatter.format(new java.util.Date(this.report.getCreatedTime() * 1000))));
197  propertiesSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ReportNode.pathProperty.name"),
198  NbBundle.getMessage(this.getClass(), "ReportNode.pathProperty.displayName"),
199  NbBundle.getMessage(this.getClass(), "ReportNode.pathProperty.desc"),
200  this.report.getPath()));
201  return sheet;
202  }
203 
204  @Override
205  public Action[] getActions(boolean popup) {
206  List<Action> actions = new ArrayList<>();
207  actions.addAll(Arrays.asList(super.getActions(true)));
208  actions.add(new OpenReportAction());
209  actions.add(DeleteReportAction.getInstance());
210  return actions.toArray(new Action[actions.size()]);
211  }
212 
213  @Override
214  public AbstractAction getPreferredAction() {
215  return new OpenReportAction();
216  }
217 
218  @Override
219  public String getItemType() {
220  return getClass().getName();
221  }
222 
223  private static class DeleteReportAction extends AbstractAction {
224 
225  private static final long serialVersionUID = 1L;
226  private static DeleteReportAction instance;
227 
228  // This class is a singleton to support multi-selection of nodes,
229  // since org.openide.nodes.NodeOp.findActions(Node[] nodes) will
230  // only pick up an Action if every node in the array returns a
231  // reference to the same action object from Node.getActions(boolean).
232  private static DeleteReportAction getInstance() {
233  if (instance == null) {
234  instance = new DeleteReportAction();
235  }
236  if (Utilities.actionsGlobalContext().lookupAll(Report.class).size() == 1) {
237  instance.putValue(Action.NAME, NbBundle.getMessage(Reports.class, "DeleteReportAction.actionDisplayName.singleReport"));
238  } else {
239  instance.putValue(Action.NAME, NbBundle.getMessage(Reports.class, "DeleteReportAction.actionDisplayName.multipleReports"));
240  }
241  return instance;
242  }
243 
248  private DeleteReportAction() {
249  }
250 
251  @NbBundle.Messages({
252  "DeleteReportAction.showConfirmDialog.single.explanation=The report will remain on disk.",
253  "DeleteReportAction.showConfirmDialog.multiple.explanation=The reports will remain on disk.",
254  "DeleteReportAction.showConfirmDialog.errorMsg=An error occurred while deleting the reports."})
255  @Override
256  public void actionPerformed(ActionEvent e) {
257  Collection<? extends Report> selectedReportsCollection = Utilities.actionsGlobalContext().lookupAll(Report.class);
258  String message = selectedReportsCollection.size() > 1
259  ? NbBundle.getMessage(Reports.class, "DeleteReportAction.actionPerformed.showConfirmDialog.multiple.msg", selectedReportsCollection.size())
260  : NbBundle.getMessage(Reports.class, "DeleteReportAction.actionPerformed.showConfirmDialog.single.msg");
261  String explanation = selectedReportsCollection.size() > 1
262  ? Bundle.DeleteReportAction_showConfirmDialog_multiple_explanation()
263  : Bundle.DeleteReportAction_showConfirmDialog_single_explanation();
264  Object[] jOptionPaneContent = {message, explanation};
265  if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, jOptionPaneContent,
266  NbBundle.getMessage(Reports.class, "DeleteReportAction.actionPerformed.showConfirmDialog.title"),
267  JOptionPane.YES_NO_OPTION)) {
268  try {
269  Case.getOpenCase().deleteReports(selectedReportsCollection);
270  } catch (TskCoreException | NoCurrentCaseException ex) {
271  Logger.getLogger(DeleteReportAction.class.getName()).log(Level.SEVERE, "Error deleting reports", ex); // NON-NLS
272  MessageNotifyUtil.Message.error(Bundle.DeleteReportAction_showConfirmDialog_errorMsg());
273  }
274  }
275  }
276  }
277 
278  private final class OpenReportAction extends AbstractAction {
279 
280  private static final long serialVersionUID = 1L;
281 
282  private OpenReportAction() {
283  super(NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionDisplayName"));
284  }
285 
286  @Override
287  public void actionPerformed(ActionEvent e) {
288  String reportPath = ReportNode.this.report.getPath();
289 
290  if (reportPath.toLowerCase().startsWith("http")) {
291  ExternalViewerAction.openURL(reportPath);
292  }
293  else {
294  String extension = "";
295  int extPosition = reportPath.lastIndexOf('.');
296  if (extPosition != -1) {
297  extension = reportPath.substring(extPosition, reportPath.length()).toLowerCase();
298  }
299 
300  ExternalViewerAction.openFile("", extension, new File(reportPath));
301  }
302  }
303  }
304  }
305 }
static final Set< Case.Events > CASE_EVENTS_OF_INTEREST
Definition: Reports.java:105
static void openFile(String mimeType, String ext, File file)
void deleteReports(Collection<?extends Report > reports)
Definition: Case.java:1604
static final SimpleDateFormat dateFormatter
Definition: Reports.java:55
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:420

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.