Autopsy  4.16.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-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.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 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
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 final String PREFERRED_ID = "IngestMessageTopComponent"; //NON-NLS
51  private final ActionListener showIngestInboxAction;
52  private static final Pattern TAG_REMOVE = 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  void writeProperties(java.util.Properties p) {
190  // better to version settings since initial version as advocated at
191  // http://wiki.apidesign.org/wiki/PropertyFiles
192  p.setProperty("version", "1.0");
193  // TODO store your settings
194  }
195 
196  void readProperties(java.util.Properties p) {
197  String version = p.getProperty("version");
198  // TODO read your settings according to their version
199  }
200 
201  private void customizeComponents() {
202  //custom GUI setup not done by builder
203  messagePanel = new IngestMessageMainPanel();
204  messagePanel.setOpaque(true);
205  //setLayout(new BorderLayout());
206  setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
207  add(messagePanel);
208  }
209 
213  public void displayReport(String ingestReport) {
214 
215  Object[] options = {NbBundle.getMessage(this.getClass(), "IngestMessageTopComponent.displayReport.option.OK"),
216  NbBundle.getMessage(this.getClass(),
217  "IngestMessageTopComponent.displayReport.option.GenRpt")};
218  final int choice = JOptionPane.showOptionDialog(null,
219  ingestReport,
220  NbBundle.getMessage(this.getClass(), "IngestMessageTopComponent.msgDlg.ingestRpt.text"),
221  JOptionPane.YES_NO_OPTION,
222  JOptionPane.INFORMATION_MESSAGE,
223  null,
224  options,
225  options[0]);
226 
227  final String reportActionName = "org.sleuthkit.autopsy.report.ReportAction"; //NON-NLS
228  Action reportAction = null;
229 
230  //find action by name from action lookup, without introducing cyclic dependency
231  if (choice == JOptionPane.NO_OPTION) {
232  List<? extends Action> actions = Utilities.actionsForPath("Toolbars/File"); //NON-NLS
233  for (Action a : actions) {
234  //separators are null actions
235  if (a != null) {
236  if (a.getClass().getCanonicalName().equals(reportActionName)) {
237  reportAction = a;
238  break;
239  }
240  }
241  }
242 
243  if (reportAction == null) {
244  logger.log(Level.SEVERE, "Could not locate Action: " + reportActionName); //NON-NLS
245  } else {
246  reportAction.actionPerformed(null);
247  }
248 
249  }
250 
251  }
252 
256  public void displayMessage(IngestMessage ingestMessage) {
257  messagePanel.addMessage(ingestMessage);
258 
259  //post special messages to notification area
260  MessageType ingestMessageType = ingestMessage.getMessageType();
261  if (ingestMessageType.equals(MessageType.ERROR)
262  || ingestMessageType.equals(MessageType.WARNING)) {
263  MessageNotifyUtil.MessageType notifyMessageType
264  = ingestMessageType.equals(MessageType.ERROR)
265  ? MessageNotifyUtil.MessageType.ERROR
266  : MessageNotifyUtil.MessageType.WARNING;
267 
268  String subject = ingestMessage.getSubject();
269  String details = ingestMessage.getDetails();
270  if (details == null) {
271  details = "";
272  }
273  //strip html tags in case they are present in ingest message
274  details = stripHtmlTags(details);
275 
276  MessageNotifyUtil.Notify.show(subject, details,
277  notifyMessageType, showIngestInboxAction);
278  }
279  }
280 
281  public int getMessagesCount() {
282  return messagePanel.getMessagesCount();
283  }
284 
285  public void clearMessages() {
286  messagePanel.clearMessages();
287  }
288 
289  public void displayIngestDialog(final Content ingestDataSource) {
290  /*
291  * final IngestDialog ingestDialog = new IngestDialog();
292  * ingestDialog.setImage(image); ingestDialog.display();
293  */
294  }
295 
296  @Override
297  public Action[] getActions() {
298  //disable TC toolbar actions
299  return new Action[0];
300  }
301 
302  private static String stripHtmlTags(String string) {
303  if (string == null || string.length() == 0) {
304  return string;
305  }
306 
307  Matcher m = TAG_REMOVE.matcher(string);
308  return m.replaceAll("");
309  }
310 }

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