Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestMessageTopComponent.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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.ingest;
20 
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.util.List;
24 import java.util.logging.Level;
25 import java.util.regex.Matcher;
26 import java.util.regex.Pattern;
28 import javax.swing.Action;
29 import javax.swing.BoxLayout;
30 import javax.swing.JOptionPane;
31 import org.openide.util.ImageUtilities;
32 import org.openide.util.NbBundle;
33 import org.openide.util.Utilities;
34 import org.openide.windows.Mode;
35 import org.openide.windows.TopComponent;
36 import org.openide.windows.WindowManager;
40 
44  final class IngestMessageTopComponent extends TopComponent {
45 
46  private static IngestMessageTopComponent instance;
47  private static final Logger logger = Logger.getLogger(IngestMessageTopComponent.class.getName());
48  private IngestMessageMainPanel messagePanel;
49  private IngestManager manager;
50  private static String PREFERRED_ID = "IngestMessageTopComponent"; //NON-NLS
51  private ActionListener showIngestInboxAction;
52  private static final Pattern tagRemove = Pattern.compile("<.+?>");
53 
54  public IngestMessageTopComponent() {
55  initComponents();
56  customizeComponents();
57  setName(NbBundle.getMessage(IngestMessageTopComponent.class, "CTL_IngestMessageTopComponent"));
58  setToolTipText(NbBundle.getMessage(IngestMessageTopComponent.class, "HINT_IngestMessageTopComponent"));
59  //putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE);
60 
61  showIngestInboxAction = new ActionListener() {
62  @Override
63  public void actionPerformed(ActionEvent e) {
64  IngestMessagesToolbar.getDefault().showIngestMessages();
65  }
66  };
67 
68  }
69 
70  private static synchronized IngestMessageTopComponent getDefault() {
71  if (instance == null) {
72  instance = new IngestMessageTopComponent();
73  }
74  return instance;
75  }
76 
77  public static synchronized IngestMessageTopComponent findInstance() {
78  TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
79  if (win == null) {
80  return getDefault();
81  }
82  if (win instanceof IngestMessageTopComponent) {
83  return (IngestMessageTopComponent) win;
84  }
85 
86  return getDefault();
87  }
88 
89  @Override
90  protected String preferredID() {
91  return PREFERRED_ID;
92  }
93 
99  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
100  private void initComponents() {
101 
102  setDisplayName(org.openide.util.NbBundle.getMessage(IngestMessageTopComponent.class, "IngestMessageTopComponent.displayName")); // NOI18N
103  setName(NbBundle.getMessage(this.getClass(), "IngestMessageTopComponent.initComponents.name")); // NOI18N
104 
105  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
106  this.setLayout(layout);
107  layout.setHorizontalGroup(
108  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
109  .addGap(0, 332, Short.MAX_VALUE)
110  );
111  layout.setVerticalGroup(
112  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
113  .addGap(0, 210, Short.MAX_VALUE)
114  );
115  }// </editor-fold>//GEN-END:initComponents
116  // Variables declaration - do not modify//GEN-BEGIN:variables
117  // End of variables declaration//GEN-END:variables
118 
119  @Override
120  public void componentOpened() {
121  //logger.log(Level.INFO, "OPENED");
122  super.componentOpened();
123  //create manager instance
124  if (manager == null) {
125  manager = IngestManager.getInstance();
126  }
127 
128  }
129 
130  @Override
131  public void componentClosed() {
132  //logger.log(Level.INFO, "CLOSED");
133  super.componentClosed();
134 
135  // mark all the messages as seen (this will make the 'New?' columen NOT
136  // show a ckeckmark)
137  messagePanel.markAllSeen();
138  }
139 
140  @Override
141  protected void componentShowing() {
142  //logger.log(Level.INFO, "SHOWING");
143  super.componentShowing();
144 
145  Mode mode = WindowManager.getDefault().findMode("floatingLeftBottom"); //NON-NLS
146  if (mode != null) {
147  TopComponent[] tcs = mode.getTopComponents();
148  for (int i = 0; i < tcs.length; ++i) {
149  if (tcs[i] == this) //already floating
150  {
151  this.open();
152  return;
153  }
154  }
155  mode.dockInto(this);
156  this.open();
157  }
158  }
159 
160  @Override
161  protected void componentHidden() {
162  //logger.log(Level.INFO, "HIDDEN");
163  super.componentHidden();
164 
165  }
166 
167  @Override
168  protected void componentActivated() {
169  //logger.log(Level.INFO, "ACTIVATED");
170  super.componentActivated();
171  }
172 
173  @Override
174  protected void componentDeactivated() {
175  //logger.log(Level.INFO, "DEACTIVATED");
176  super.componentDeactivated();
177  }
178 
179  @Override
180  public boolean canClose() {
181  return true;
182  }
183 
184  @Override
185  public int getPersistenceType() {
186  return TopComponent.PERSISTENCE_ALWAYS;
187  }
188 
189  @Override
190  public java.awt.Image getIcon() {
191  return ImageUtilities.loadImage(
192  "org/sleuthkit/autopsy/ingest/eye-icon.png"); //NON-NLS
193  }
194 
195  void writeProperties(java.util.Properties p) {
196  // better to version settings since initial version as advocated at
197  // http://wiki.apidesign.org/wiki/PropertyFiles
198  p.setProperty("version", "1.0");
199  // TODO store your settings
200  }
201 
202  void readProperties(java.util.Properties p) {
203  String version = p.getProperty("version");
204  // TODO read your settings according to their version
205  }
206 
207  private void customizeComponents() {
208  //custom GUI setup not done by builder
209  messagePanel = new IngestMessageMainPanel();
210  messagePanel.setOpaque(true);
211  //setLayout(new BorderLayout());
212  setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
213  add(messagePanel);
214  }
215 
219  public void displayReport(String ingestReport) {
220 
221  Object[] options = {NbBundle.getMessage(this.getClass(), "IngestMessageTopComponent.displayReport.option.OK"),
222  NbBundle.getMessage(this.getClass(),
223  "IngestMessageTopComponent.displayReport.option.GenRpt")};
224  final int choice = JOptionPane.showOptionDialog(null,
225  ingestReport,
226  NbBundle.getMessage(this.getClass(), "IngestMessageTopComponent.msgDlg.ingestRpt.text"),
227  JOptionPane.YES_NO_OPTION,
228  JOptionPane.INFORMATION_MESSAGE,
229  null,
230  options,
231  options[0]);
232 
233  final String reportActionName = "org.sleuthkit.autopsy.report.ReportAction"; //NON-NLS
234  Action reportAction = null;
235 
236  //find action by name from action lookup, without introducing cyclic dependency
237  if (choice == JOptionPane.NO_OPTION) {
238  List<? extends Action> actions = Utilities.actionsForPath("Toolbars/File"); //NON-NLS
239  for (Action a : actions) {
240  //separators are null actions
241  if (a != null) {
242  if (a.getClass().getCanonicalName().equals(reportActionName)) {
243  reportAction = a;
244  break;
245  }
246  }
247  }
248 
249  if (reportAction == null) {
250  logger.log(Level.SEVERE, "Could not locate Action: " + reportActionName); //NON-NLS
251  } else {
252  reportAction.actionPerformed(null);
253  }
254 
255  }
256 
257  }
258 
262  public void displayMessage(IngestMessage ingestMessage) {
263  messagePanel.addMessage(ingestMessage);
264 
265 
266  //post special messages to notification area
267  MessageType ingestMessageType = ingestMessage.getMessageType();
268  if (ingestMessageType.equals(MessageType.ERROR)
269  || ingestMessageType.equals(MessageType.WARNING)) {
270  MessageNotifyUtil.MessageType notifyMessageType =
271  ingestMessageType.equals(MessageType.ERROR)
272  ? MessageNotifyUtil.MessageType.ERROR
273  : MessageNotifyUtil.MessageType.WARNING;
274 
275  String subject = ingestMessage.getSubject();
276  String details = ingestMessage.getDetails();
277  if (details == null) {
278  details = "";
279  }
280  //strip html tags in case they are present in ingest message
281  details = stripHtmlTags(details);
282 
283  MessageNotifyUtil.Notify.show(subject, details,
284  notifyMessageType, showIngestInboxAction);
285  }
286  }
287 
288  public int getMessagesCount() {
289  return messagePanel.getMessagesCount();
290  }
291 
292  public void clearMessages() {
293  messagePanel.clearMessages();
294  }
295 
296  public void displayIngestDialog(final Content ingestDataSource) {
297  /*
298  final IngestDialog ingestDialog = new IngestDialog();
299  ingestDialog.setImage(image);
300  ingestDialog.display();
301  */
302  }
303 
304  public Action[] getActions() {
305  //disable TC toolbar actions
306  return new Action[0];
307  }
308 
309  private static String stripHtmlTags(String string) {
310  if (string == null || string.length() == 0) {
311  return string;
312  }
313 
314  Matcher m = tagRemove.matcher(string);
315  return m.replaceAll("");
316  }
317 }

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.