Autopsy  4.1
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-2016 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.Desktop;
22 import java.awt.event.ActionEvent;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import java.io.File;
26 import java.io.IOException;
27 import java.text.SimpleDateFormat;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.Collection;
31 import java.util.List;
32 import java.util.logging.Level;
33 import javax.swing.AbstractAction;
34 import javax.swing.Action;
35 import javax.swing.JCheckBox;
36 import javax.swing.JOptionPane;
37 import org.openide.nodes.ChildFactory;
38 import org.openide.nodes.Children;
39 import org.openide.nodes.Node;
40 import org.openide.nodes.Sheet;
41 import org.openide.util.NbBundle;
42 import org.openide.util.Utilities;
43 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  /*
94  * TODO (AUT-1849): Correct or remove peristent column reordering code
95  *
96  * Added to support this feature.
97  */
98 // @Override
99 // public String getItemType() {
100 // return "ReportsList"; //NON-NLS
101 // }
102  }
103 
108  private static final class ReportNodeFactory extends ChildFactory<Report> {
109 
111  Case.addPropertyChangeListener((PropertyChangeEvent evt) -> {
112  String eventType = evt.getPropertyName();
113  if (eventType.equals(Case.Events.REPORT_ADDED.toString()) || eventType.equals(Case.Events.REPORT_DELETED.toString())) {
120  try {
122  ReportNodeFactory.this.refresh(true);
123  } catch (IllegalStateException notUsed) {
127  }
128  }
129  });
130  }
131 
132  @Override
133  protected boolean createKeys(List<Report> keys) {
134  try {
135  keys.addAll(Case.getCurrentCase().getAllReports());
136  } catch (TskCoreException ex) {
137  Logger.getLogger(Reports.ReportNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get reports", ex); //NON-NLS
138  }
139  return true;
140  }
141 
142  @Override
143  protected Node createNodeForKey(Report key) {
144  return new ReportNode(key);
145  }
146  }
147 
152  public static final class ReportNode extends DisplayableItemNode {
153 
154  private static final long serialVersionUID = 1L;
155  private static final String ICON_PATH = "org/sleuthkit/autopsy/images/report_16.png"; //NON-NLS
156  private final Report report;
157 
158  ReportNode(Report report) {
159  super(Children.LEAF, Lookups.fixed(report));
160  this.report = report;
161  super.setName(this.report.getSourceModuleName());
162  super.setDisplayName(this.report.getSourceModuleName());
163  this.setIconBaseWithExtension(ICON_PATH);
164  }
165 
166  @Override
167  public boolean isLeafTypeNode() {
168  return true;
169  }
170 
171  @Override
172  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
173  // - GetPopupActionsDisplayableItemNodeVisitor.visit() calls getActions().
174  // - GetPreferredActionsDisplayableItemNodeVisitor.visit() calls getPreferredAction().
175  // - IsLeafItemVisitor.visit() returns true.
176  // - ShowItemVisitor.visit() returns true.
177  return visitor.visit(this);
178  }
179 
180  @Override
181  protected Sheet createSheet() {
182  Sheet sheet = super.createSheet();
183  Sheet.Set propertiesSet = sheet.get(Sheet.PROPERTIES);
184  if (propertiesSet == null) {
185  propertiesSet = Sheet.createPropertiesSet();
186  sheet.put(propertiesSet);
187  }
188  propertiesSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ReportNode.sourceModuleNameProperty.name"),
189  NbBundle.getMessage(this.getClass(), "ReportNode.sourceModuleNameProperty.displayName"),
190  NbBundle.getMessage(this.getClass(), "ReportNode.sourceModuleNameProperty.desc"),
191  this.report.getSourceModuleName()));
192  propertiesSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ReportNode.reportNameProperty.name"),
193  NbBundle.getMessage(this.getClass(), "ReportNode.reportNameProperty.displayName"),
194  NbBundle.getMessage(this.getClass(), "ReportNode.reportNameProperty.desc"),
195  this.report.getReportName()));
196  propertiesSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ReportNode.createdTimeProperty.name"),
197  NbBundle.getMessage(this.getClass(), "ReportNode.createdTimeProperty.displayName"),
198  NbBundle.getMessage(this.getClass(), "ReportNode.createdTimeProperty.desc"),
199  dateFormatter.format(new java.util.Date(this.report.getCreatedTime() * 1000))));
200  propertiesSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ReportNode.pathProperty.name"),
201  NbBundle.getMessage(this.getClass(), "ReportNode.pathProperty.displayName"),
202  NbBundle.getMessage(this.getClass(), "ReportNode.pathProperty.desc"),
203  this.report.getPath()));
204  return sheet;
205  }
206 
207  @Override
208  public Action[] getActions(boolean popup) {
209  List<Action> actions = new ArrayList<>();
210  actions.addAll(Arrays.asList(super.getActions(true)));
211  actions.add(new OpenReportAction());
212  actions.add(DeleteReportAction.getInstance());
213  return actions.toArray(new Action[actions.size()]);
214  }
215 
216  @Override
217  public AbstractAction getPreferredAction() {
218  return new OpenReportAction();
219  }
220 
221  /*
222  * TODO (AUT-1849): Correct or remove peristent column reordering code
223  *
224  * Added to support this feature.
225  */
226 // @Override
227 // public String getItemType() {
228 // return "Reports"; //NON-NLS
229 // }
230  private static class DeleteReportAction extends AbstractAction {
231 
232  private static final long serialVersionUID = 1L;
233  private static DeleteReportAction instance;
234 
235  // This class is a singleton to support multi-selection of nodes,
236  // since org.openide.nodes.NodeOp.findActions(Node[] nodes) will
237  // only pick up an Action if every node in the array returns a
238  // reference to the same action object from Node.getActions(boolean).
239  private static DeleteReportAction getInstance() {
240  if (instance == null) {
241  instance = new DeleteReportAction();
242  }
243  if (Utilities.actionsGlobalContext().lookupAll(Report.class).size() == 1) {
244  instance.putValue(Action.NAME, NbBundle.getMessage(Reports.class, "DeleteReportAction.actionDisplayName.singleReport"));
245  } else {
246  instance.putValue(Action.NAME, NbBundle.getMessage(Reports.class, "DeleteReportAction.actionDisplayName.multipleReports"));
247  }
248  return instance;
249  }
250 
255  private DeleteReportAction() {
256  }
257 
258  @NbBundle.Messages({
259  "DeleteReportAction.showConfirmDialog.single.explanation=The report will remain on disk.",
260  "DeleteReportAction.showConfirmDialog.multiple.explanation=The reports will remain on disk.",
261  "DeleteReportAction.showConfirmDialog.errorMsg=An error occurred while deleting the reports."})
262  @Override
263  public void actionPerformed(ActionEvent e) {
264  Collection<? extends Report> selectedReportsCollection = Utilities.actionsGlobalContext().lookupAll(Report.class);
265  String message = selectedReportsCollection.size() > 1
266  ? NbBundle.getMessage(Reports.class, "DeleteReportAction.actionPerformed.showConfirmDialog.multiple.msg", selectedReportsCollection.size())
267  : NbBundle.getMessage(Reports.class, "DeleteReportAction.actionPerformed.showConfirmDialog.single.msg");
268  String explanation = selectedReportsCollection.size() > 1
269  ? Bundle.DeleteReportAction_showConfirmDialog_multiple_explanation()
270  : Bundle.DeleteReportAction_showConfirmDialog_single_explanation();
271  Object[] jOptionPaneContent = {message, explanation};
272  if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, jOptionPaneContent,
273  NbBundle.getMessage(Reports.class, "DeleteReportAction.actionPerformed.showConfirmDialog.title"),
274  JOptionPane.YES_NO_OPTION)) {
275  try {
276  Case.getCurrentCase().deleteReports(selectedReportsCollection);
277  } catch (TskCoreException | IllegalStateException ex) {
278  Logger.getLogger(DeleteReportAction.class.getName()).log(Level.SEVERE, "Error deleting reports", ex); // NON-NLS
279  MessageNotifyUtil.Message.error(Bundle.DeleteReportAction_showConfirmDialog_errorMsg());
280  }
281  }
282  }
283  }
284 
285  private final class OpenReportAction extends AbstractAction {
286 
287  private static final long serialVersionUID = 1L;
288 
289  private OpenReportAction() {
290  super(NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionDisplayName"));
291  }
292 
293  @Override
294  public void actionPerformed(ActionEvent e) {
295  File file = new File(ReportNode.this.report.getPath());
296  try {
297  Desktop.getDesktop().open(file);
298  } catch (IOException ex) {
299  JOptionPane.showMessageDialog(null,
300  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.NoAssociatedEditorMessage"),
301  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MessageBoxTitle"),
302  JOptionPane.ERROR_MESSAGE);
303  } catch (UnsupportedOperationException ex) {
304  JOptionPane.showMessageDialog(null,
305  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.NoOpenInEditorSupportMessage"),
306  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MessageBoxTitle"),
307  JOptionPane.ERROR_MESSAGE);
308  } catch (IllegalArgumentException ex) {
309  JOptionPane.showMessageDialog(null,
310  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MissingReportFileMessage"),
311  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MessageBoxTitle"),
312  JOptionPane.ERROR_MESSAGE);
313  } catch (SecurityException ex) {
314  JOptionPane.showMessageDialog(null,
315  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.ReportFileOpenPermissionDeniedMessage"),
316  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MessageBoxTitle"),
317  JOptionPane.ERROR_MESSAGE);
318  }
319  }
320  }
321  }
322 }
static void addPropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:306
void deleteReports(Collection<?extends Report > reports)
Definition: Case.java:800
static final SimpleDateFormat dateFormatter
Definition: Reports.java:55
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

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