19 package org.sleuthkit.autopsy.ingest;
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;
43 @SuppressWarnings(
"PMD.SingularField")
44 final class IngestMessageTopComponent extends TopComponent {
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";
51 private final ActionListener showIngestInboxAction;
52 private static final Pattern TAG_REMOVE = Pattern.compile(
"<.+?>");
54 public IngestMessageTopComponent() {
56 customizeComponents();
57 setName(NbBundle.getMessage(IngestMessageTopComponent.class,
"CTL_IngestMessageTopComponent"));
58 setToolTipText(NbBundle.getMessage(IngestMessageTopComponent.class,
"HINT_IngestMessageTopComponent"));
61 showIngestInboxAction =
new ActionListener() {
63 public void actionPerformed(ActionEvent e) {
64 IngestMessagesToolbar.getDefault().showIngestMessages();
70 private static synchronized IngestMessageTopComponent getDefault() {
71 if (instance == null) {
72 instance =
new IngestMessageTopComponent();
77 public static synchronized IngestMessageTopComponent findInstance() {
78 TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
82 if (win instanceof IngestMessageTopComponent) {
83 return (IngestMessageTopComponent) win;
90 protected String preferredID() {
100 private void initComponents() {
102 setDisplayName(
org.openide.util.NbBundle.getMessage(IngestMessageTopComponent.class,
"IngestMessageTopComponent.displayName"));
103 setName(NbBundle.getMessage(
this.getClass(),
"IngestMessageTopComponent.initComponents.name"));
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)
111 layout.setVerticalGroup(
112 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
113 .addGap(0, 210, Short.MAX_VALUE)
120 public void componentOpened() {
122 super.componentOpened();
124 if (manager == null) {
125 manager = IngestManager.getInstance();
131 public void componentClosed() {
133 super.componentClosed();
137 messagePanel.markAllSeen();
141 protected void componentShowing() {
143 super.componentShowing();
145 Mode mode = WindowManager.getDefault().findMode(
"floatingLeftBottom");
147 TopComponent[] tcs = mode.getTopComponents();
148 for (
int i = 0; i < tcs.length; ++i) {
161 protected void componentHidden() {
163 super.componentHidden();
168 protected void componentActivated() {
170 super.componentActivated();
174 protected void componentDeactivated() {
176 super.componentDeactivated();
180 public boolean canClose() {
185 public int getPersistenceType() {
186 return TopComponent.PERSISTENCE_ALWAYS;
189 void writeProperties(java.util.Properties p) {
192 p.setProperty(
"version",
"1.0");
196 void readProperties(java.util.Properties p) {
197 String version = p.getProperty(
"version");
201 private void customizeComponents() {
203 messagePanel =
new IngestMessageMainPanel();
204 messagePanel.setOpaque(
true);
206 setLayout(
new BoxLayout(
this, BoxLayout.PAGE_AXIS));
213 public void displayReport(String ingestReport) {
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,
220 NbBundle.getMessage(
this.getClass(),
"IngestMessageTopComponent.msgDlg.ingestRpt.text"),
221 JOptionPane.YES_NO_OPTION,
222 JOptionPane.INFORMATION_MESSAGE,
227 final String reportActionName =
"org.sleuthkit.autopsy.report.ReportAction";
228 Action reportAction = null;
231 if (choice == JOptionPane.NO_OPTION) {
232 List<? extends Action> actions = Utilities.actionsForPath(
"Toolbars/File");
233 for (Action a : actions) {
236 if (a.getClass().getCanonicalName().equals(reportActionName)) {
243 if (reportAction == null) {
244 logger.log(Level.SEVERE,
"Could not locate Action: " + reportActionName);
246 reportAction.actionPerformed(null);
256 public void displayMessage(IngestMessage ingestMessage) {
257 messagePanel.addMessage(ingestMessage);
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;
268 String subject = ingestMessage.getSubject();
269 String details = ingestMessage.getDetails();
270 if (details == null) {
274 details = stripHtmlTags(details);
276 MessageNotifyUtil.Notify.show(subject, details,
277 notifyMessageType, showIngestInboxAction);
281 public int getMessagesCount() {
282 return messagePanel.getMessagesCount();
285 public void clearMessages() {
286 messagePanel.clearMessages();
289 public void displayIngestDialog(
final Content ingestDataSource) {
297 public Action[] getActions() {
299 return new Action[0];
302 private static String stripHtmlTags(String
string) {
303 if (
string == null ||
string.length() == 0) {
307 Matcher m = TAG_REMOVE.matcher(
string);
308 return m.replaceAll(
"");