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 final class IngestMessageTopComponent 
extends TopComponent {
 
   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"; 
 
   50     private final ActionListener showIngestInboxAction;
 
   51     private static final Pattern TAG_REMOVE = Pattern.compile(
"<.+?>");
 
   53     public IngestMessageTopComponent() {
 
   55         customizeComponents();
 
   56         setName(NbBundle.getMessage(IngestMessageTopComponent.class, 
"CTL_IngestMessageTopComponent"));
 
   57         setToolTipText(NbBundle.getMessage(IngestMessageTopComponent.class, 
"HINT_IngestMessageTopComponent"));
 
   60         showIngestInboxAction = 
new ActionListener() {
 
   62             public void actionPerformed(ActionEvent e) {
 
   63                 IngestMessagesToolbar.getDefault().showIngestMessages();
 
   69     private static synchronized IngestMessageTopComponent getDefault() {
 
   70         if (instance == null) {
 
   71             instance = 
new IngestMessageTopComponent();
 
   76     public static synchronized IngestMessageTopComponent findInstance() {
 
   77         TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
 
   81         if (win instanceof IngestMessageTopComponent) {
 
   82             return (IngestMessageTopComponent) win;
 
   89     protected String preferredID() {
 
   99     private void initComponents() {
 
  101         setDisplayName(
org.openide.util.NbBundle.getMessage(IngestMessageTopComponent.class, 
"IngestMessageTopComponent.displayName")); 
 
  102         setName(NbBundle.getMessage(
this.getClass(), 
"IngestMessageTopComponent.initComponents.name")); 
 
  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)
 
  110         layout.setVerticalGroup(
 
  111             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  112             .addGap(0, 210, Short.MAX_VALUE)
 
  119     public void componentOpened() {
 
  121         super.componentOpened();
 
  123         if (manager == null) {
 
  124             manager = IngestManager.getInstance();
 
  130     public void componentClosed() {
 
  132         super.componentClosed();
 
  136         messagePanel.markAllSeen();
 
  140     protected void componentShowing() {
 
  142         super.componentShowing();
 
  144         Mode mode = WindowManager.getDefault().findMode(
"floatingLeftBottom"); 
 
  146             TopComponent[] tcs = mode.getTopComponents();
 
  147             for (
int i = 0; i < tcs.length; ++i) {
 
  160     protected void componentHidden() {
 
  162         super.componentHidden();
 
  167     protected void componentActivated() {
 
  169         super.componentActivated();
 
  173     protected void componentDeactivated() {
 
  175         super.componentDeactivated();
 
  179     public boolean canClose() {
 
  184     public int getPersistenceType() {
 
  185         return TopComponent.PERSISTENCE_ALWAYS;
 
  188     void writeProperties(java.util.Properties p) {
 
  191         p.setProperty(
"version", 
"1.0");
 
  195     void readProperties(java.util.Properties p) {
 
  196         String version = p.getProperty(
"version");
 
  200     private void customizeComponents() {
 
  202         messagePanel = 
new IngestMessageMainPanel();
 
  203         messagePanel.setOpaque(
true);
 
  205         setLayout(
new BoxLayout(
this, BoxLayout.PAGE_AXIS));
 
  212     public void displayReport(String ingestReport) {
 
  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,
 
  219                 NbBundle.getMessage(
this.getClass(), 
"IngestMessageTopComponent.msgDlg.ingestRpt.text"),
 
  220                 JOptionPane.YES_NO_OPTION,
 
  221                 JOptionPane.INFORMATION_MESSAGE,
 
  226         final String reportActionName = 
"org.sleuthkit.autopsy.report.ReportAction"; 
 
  227         Action reportAction = null;
 
  230         if (choice == JOptionPane.NO_OPTION) {
 
  231             List<? extends Action> actions = Utilities.actionsForPath(
"Toolbars/File"); 
 
  232             for (Action a : actions) {
 
  235                     if (a.getClass().getCanonicalName().equals(reportActionName)) {
 
  242             if (reportAction == null) {
 
  243                 logger.log(Level.SEVERE, 
"Could not locate Action: " + reportActionName); 
 
  245                 reportAction.actionPerformed(null);
 
  255     public void displayMessage(IngestMessage ingestMessage) {
 
  256         messagePanel.addMessage(ingestMessage);
 
  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;
 
  267             String subject = ingestMessage.getSubject();
 
  268             String details = ingestMessage.getDetails();
 
  269             if (details == null) {
 
  273             details = stripHtmlTags(details);
 
  275             MessageNotifyUtil.Notify.show(subject, details,
 
  276                     notifyMessageType, showIngestInboxAction);
 
  280     public int getMessagesCount() {
 
  281         return messagePanel.getMessagesCount();
 
  284     public void clearMessages() {
 
  285         messagePanel.clearMessages();
 
  288     public void displayIngestDialog(
final Content ingestDataSource) {
 
  296     public Action[] getActions() {
 
  298         return new Action[0];
 
  301     private static String stripHtmlTags(String 
string) {
 
  302         if (
string == null || 
string.length() == 0) {
 
  306         Matcher m = TAG_REMOVE.matcher(
string);
 
  307         return m.replaceAll(
"");