Autopsy  3.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 2014 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.List;
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.lookup.Lookups;
45 
49 public final class Reports implements AutopsyVisitableItem {
50 
51  private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
52 
53  @Override
54  public <T> T accept(AutopsyItemVisitor<T> visitor) {
55  // CreateAutopsyNodeVisitor.visit() constructs a ReportsListNode.
56  return visitor.visit(this);
57  }
58 
62  public static final class ReportsListNode extends DisplayableItemNode {
63 
64  private static final String DISPLAY_NAME = NbBundle.getMessage(ReportsListNode.class, "ReportsListNode.displayName");
65  private static final String ICON_PATH = "org/sleuthkit/autopsy/images/report_16.png"; //NON-NLS
66 
67  public ReportsListNode() {
68  super(Children.create(new ReportNodeFactory(), true));
69  setName(DISPLAY_NAME);
70  setDisplayName(DISPLAY_NAME);
71  this.setIconBaseWithExtension(ICON_PATH);
72  }
73 
74  @Override
75  public boolean isLeafTypeNode() {
76  return true;
77  }
78 
79  @Override
80  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
81  // - GetPopupActionsDisplayableItemNodeVisitor.visit() returns null.
82  // - GetPreferredActionsDisplayableItemNodeVisitor.visit() returns null.
83  // - IsLeafItemVisitor.visit() returns false.
84  // - ShowItemVisitor.visit() returns true.
85  return visitor.visit(this);
86  }
87  }
88 
93  private static final class ReportNodeFactory extends ChildFactory<Report> {
94 
96  Case.addPropertyChangeListener(new PropertyChangeListener() {
97  @Override
98  public void propertyChange(PropertyChangeEvent evt) {
99  String eventType = evt.getPropertyName();
100  if (eventType.equals(Case.Events.REPORT_ADDED.toString())) {
101  ReportNodeFactory.this.refresh(true);
102  }
103  }
104  });
105  }
106 
107  @Override
108  protected boolean createKeys(List<Report> keys) {
109  try {
110  keys.addAll(Case.getCurrentCase().getAllReports());
111  } catch (TskCoreException ex) {
112  Logger.getLogger(Reports.ReportNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get reports", ex); //NON-NLS
113  }
114  return true;
115  }
116 
117  @Override
118  protected Node createNodeForKey(Report key) {
119  return new ReportNode(key);
120  }
121  }
122 
127  public static final class ReportNode extends DisplayableItemNode {
128 
129  private static final String ICON_PATH = "org/sleuthkit/autopsy/images/report_16.png"; //NON-NLS
130  private final Report report;
131 
132  ReportNode(Report report) {
133  super(Children.LEAF, Lookups.fixed(report));
134  this.report = report;
135  super.setName(this.report.getSourceModuleName());
136  super.setDisplayName(this.report.getSourceModuleName());
137  this.setIconBaseWithExtension(ICON_PATH);
138  }
139 
140  @Override
141  public boolean isLeafTypeNode() {
142  return true;
143  }
144 
145  @Override
146  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
147  // - GetPopupActionsDisplayableItemNodeVisitor.visit() calls getActions().
148  // - GetPreferredActionsDisplayableItemNodeVisitor.visit() calls getPreferredAction().
149  // - IsLeafItemVisitor.visit() returns true.
150  // - ShowItemVisitor.visit() returns true.
151  return visitor.visit(this);
152  }
153 
154  @Override
155  protected Sheet createSheet() {
156  Sheet sheet = super.createSheet();
157  Sheet.Set propertiesSet = sheet.get(Sheet.PROPERTIES);
158  if (propertiesSet == null) {
159  propertiesSet = Sheet.createPropertiesSet();
160  sheet.put(propertiesSet);
161  }
162  propertiesSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ReportNode.sourceModuleNameProperty.name"),
163  NbBundle.getMessage(this.getClass(), "ReportNode.sourceModuleNameProperty.displayName"),
164  NbBundle.getMessage(this.getClass(), "ReportNode.sourceModuleNameProperty.desc"),
165  this.report.getSourceModuleName()));
166  propertiesSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ReportNode.reportNameProperty.name"),
167  NbBundle.getMessage(this.getClass(), "ReportNode.reportNameProperty.displayName"),
168  NbBundle.getMessage(this.getClass(), "ReportNode.reportNameProperty.desc"),
169  this.report.getReportName()));
170  propertiesSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ReportNode.createdTimeProperty.name"),
171  NbBundle.getMessage(this.getClass(), "ReportNode.createdTimeProperty.displayName"),
172  NbBundle.getMessage(this.getClass(), "ReportNode.createdTimeProperty.desc"),
173  dateFormatter.format(new java.util.Date(this.report.getCreatedTime() * 1000))));
174  propertiesSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ReportNode.pathProperty.name"),
175  NbBundle.getMessage(this.getClass(), "ReportNode.pathProperty.displayName"),
176  NbBundle.getMessage(this.getClass(), "ReportNode.pathProperty.desc"),
177  this.report.getPath()));
178  return sheet;
179  }
180 
181  @Override
182  public Action[] getActions(boolean popup) {
183  List<Action> actions = new ArrayList<>();
184  actions.addAll(Arrays.asList(super.getActions(true)));
185  actions.add(new OpenReportAction());
186  return actions.toArray(new Action[actions.size()]);
187  }
188 
189  @Override
190  public AbstractAction getPreferredAction() {
191  return new OpenReportAction();
192  }
193 
194  private final class OpenReportAction extends AbstractAction {
195 
196  private OpenReportAction() {
197  super(NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionDisplayName"));
198  }
199  @Override
200  public void actionPerformed(ActionEvent e) {
201  File file = new File(ReportNode.this.report.getPath());
202  try {
203  Desktop.getDesktop().open(file);
204  } catch (IOException ex) {
205  JOptionPane.showMessageDialog(null,
206  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.NoAssociatedEditorMessage"),
207  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MessageBoxTitle"),
208  JOptionPane.ERROR_MESSAGE);
209  } catch (UnsupportedOperationException ex) {
210  JOptionPane.showMessageDialog(null,
211  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.NoOpenInEditorSupportMessage"),
212  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MessageBoxTitle"),
213  JOptionPane.ERROR_MESSAGE);
214  } catch (IllegalArgumentException ex) {
215  JOptionPane.showMessageDialog(null,
216  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MissingReportFileMessage"),
217  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MessageBoxTitle"),
218  JOptionPane.ERROR_MESSAGE);
219  } catch (SecurityException ex) {
220  JOptionPane.showMessageDialog(null,
221  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.ReportFileOpenPermissionDeniedMessage"),
222  NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MessageBoxTitle"),
223  JOptionPane.ERROR_MESSAGE);
224  }
225  }
226  }
227  }
228 }
static final SimpleDateFormat dateFormatter
Definition: Reports.java:51
static synchronized void addPropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:833
static Logger getLogger(String name)
Definition: Logger.java:131

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