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.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;
 
   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 String PREFERRED_ID = 
"IngestMessageTopComponent"; 
 
   51     private ActionListener showIngestInboxAction;
 
   52     private static final Pattern tagRemove = 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;
 
  190     public java.awt.Image getIcon() {
 
  191         return ImageUtilities.loadImage(
 
  192                 "org/sleuthkit/autopsy/ingest/eye-icon.png"); 
 
  195     void writeProperties(java.util.Properties p) {
 
  198         p.setProperty(
"version", 
"1.0");
 
  202     void readProperties(java.util.Properties p) {
 
  203         String version = p.getProperty(
"version");
 
  207     private void customizeComponents() {
 
  209         messagePanel = 
new IngestMessageMainPanel();
 
  210         messagePanel.setOpaque(
true);
 
  212         setLayout(
new BoxLayout(
this, BoxLayout.PAGE_AXIS));
 
  219     public void displayReport(String ingestReport) {
 
  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,
 
  226                 NbBundle.getMessage(
this.getClass(), 
"IngestMessageTopComponent.msgDlg.ingestRpt.text"),
 
  227                 JOptionPane.YES_NO_OPTION,
 
  228                 JOptionPane.INFORMATION_MESSAGE,
 
  233         final String reportActionName = 
"org.sleuthkit.autopsy.report.ReportAction"; 
 
  234         Action reportAction = null;
 
  237         if (choice == JOptionPane.NO_OPTION) {
 
  238             List<? extends Action> actions = Utilities.actionsForPath(
"Toolbars/File"); 
 
  239             for (Action a : actions) {
 
  242                     if (a.getClass().getCanonicalName().equals(reportActionName)) {
 
  249             if (reportAction == null) {
 
  250                 logger.log(Level.SEVERE, 
"Could not locate Action: " + reportActionName); 
 
  252                 reportAction.actionPerformed(null);
 
  262     public void displayMessage(IngestMessage ingestMessage) {
 
  263         messagePanel.addMessage(ingestMessage);
 
  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;
 
  275             String subject = ingestMessage.getSubject();
 
  276             String details = ingestMessage.getDetails();
 
  277             if (details == null) {
 
  281             details  = stripHtmlTags(details);
 
  283             MessageNotifyUtil.Notify.show(subject, details,
 
  284                     notifyMessageType, showIngestInboxAction);
 
  288     public int getMessagesCount() {
 
  289         return messagePanel.getMessagesCount();
 
  292     public void clearMessages() {
 
  293         messagePanel.clearMessages();
 
  296     public void displayIngestDialog(
final Content ingestDataSource) {
 
  304     public Action[] getActions() {
 
  306         return new Action[0];
 
  309     private static String stripHtmlTags(String 
string) {
 
  310         if (
string == null || 
string.length() == 0) {
 
  314         Matcher m = tagRemove.matcher(
string);
 
  315         return m.replaceAll(
"");