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

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.