From 9dc500579a11e66b2ba0732d28d153d7480563b1 Mon Sep 17 00:00:00 2001 From: adam-m Date: Fri, 9 Mar 2012 16:47:15 -0500 Subject: [PATCH 1/4] Ingest: when enumerating files to run ingest on, include also unknown files. It's up to service to decide. --- .../org/sleuthkit/autopsy/ingest/GetAllFilesContentVisitor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ingest/src/org/sleuthkit/autopsy/ingest/GetAllFilesContentVisitor.java b/Ingest/src/org/sleuthkit/autopsy/ingest/GetAllFilesContentVisitor.java index 44b4b20564..192cba5be2 100644 --- a/Ingest/src/org/sleuthkit/autopsy/ingest/GetAllFilesContentVisitor.java +++ b/Ingest/src/org/sleuthkit/autopsy/ingest/GetAllFilesContentVisitor.java @@ -57,7 +57,7 @@ class GetAllFilesContentVisitor extends GetFilesContentVisitor { String query = "SELECT * FROM tsk_files WHERE fs_obj_id = " + fs.getId() + " AND (meta_type = " + TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG.getMetaType() - + ") AND (known != " + FileKnown.KNOWN.toLong() + ") AND (size > 0)"; + + ") AND (size > 0)"; try { ResultSet rs = sc.runQuery(query); List contents = sc.resultSetToFsContents(rs); From 16ce7c851108475a22b65fac4265653e625bbbfb Mon Sep 17 00:00:00 2001 From: adam-m Date: Fri, 9 Mar 2012 16:47:35 -0500 Subject: [PATCH 2/4] Cleanup, remove obsolete keyword search code. --- .../GetAllFilesContentVisitor.java | 75 ----- .../keywordsearch/GetFilesContentVisitor.java | 105 ------ .../GetIngestableFilesContentVisitor.java | 101 ------ .../IndexContentFilesAction.java | 307 ------------------ .../keywordsearch/IndexProgressPanel.form | 62 ---- .../keywordsearch/IndexProgressPanel.java | 100 ------ 6 files changed, 750 deletions(-) delete mode 100755 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/GetAllFilesContentVisitor.java delete mode 100644 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/GetFilesContentVisitor.java delete mode 100755 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/GetIngestableFilesContentVisitor.java delete mode 100755 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexContentFilesAction.java delete mode 100644 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexProgressPanel.form delete mode 100644 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexProgressPanel.java diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/GetAllFilesContentVisitor.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/GetAllFilesContentVisitor.java deleted file mode 100755 index c13a291c83..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/GetAllFilesContentVisitor.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.datamodel.File; -import org.sleuthkit.datamodel.FileSystem; -import org.sleuthkit.datamodel.FsContent; -import org.sleuthkit.datamodel.SleuthkitCase; -import org.sleuthkit.datamodel.TskData; -import org.sleuthkit.datamodel.TskData.FileKnown; - -/** - * Visitor for getting all the files to try to index from any Content object. - * Currently gets all non-zero files. - * TODO should be moved to utility module (needs resolve cyclic deps) - */ -class GetAllFilesContentVisitor extends GetFilesContentVisitor { - - private static final Logger logger = Logger.getLogger(GetAllFilesContentVisitor.class.getName()); - - @Override - public Collection visit(File file) { - return Collections.singleton((FsContent) file); - } - - @Override - public Collection visit(FileSystem fs) { - // Files in the database have a filesystem field, so it's quick to - // get all the matching files for an entire filesystem with a query - - SleuthkitCase sc = Case.getCurrentCase().getSleuthkitCase(); - - String query = "SELECT * FROM tsk_files WHERE fs_obj_id = " + fs.getId() - + " AND (meta_type = " + TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG.getMetaType() - + ") AND (known != " + FileKnown.KNOWN.toLong() + ") AND (size > 0)"; - try { - ResultSet rs = sc.runQuery(query); - List contents = sc.resultSetToFsContents(rs); - Statement s = rs.getStatement(); - rs.close(); - if (s != null) { - s.close(); - } - return contents; - } catch (SQLException ex) { - logger.log(Level.WARNING, "Couldn't get all files in FileSystem", ex); - return Collections.EMPTY_SET; - } - } -} diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/GetFilesContentVisitor.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/GetFilesContentVisitor.java deleted file mode 100644 index 465a1319ba..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/GetFilesContentVisitor.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.ContentVisitor; -import org.sleuthkit.datamodel.Directory; -import org.sleuthkit.datamodel.File; -import org.sleuthkit.datamodel.FileSystem; -import org.sleuthkit.datamodel.FsContent; -import org.sleuthkit.datamodel.Image; -import org.sleuthkit.datamodel.TskException; -import org.sleuthkit.datamodel.Volume; -import org.sleuthkit.datamodel.VolumeSystem; - -/** - * Abstract visitor for getting all the files from content - * TODO should be moved to utility module (needs resolve cyclic deps) - */ -public abstract class GetFilesContentVisitor implements ContentVisitor> { - - private static final Logger logger = Logger.getLogger(GetFilesContentVisitor.class.getName()); - - @Override - public abstract Collection visit(File file); - - @Override - public abstract Collection visit(FileSystem fs); - - @Override - public Collection visit(Directory drctr) { - return getAllFromChildren(drctr); - } - - @Override - public Collection visit(Image image) { - return getAllFromChildren(image); - } - - @Override - public Collection visit(Volume volume) { - return getAllFromChildren(volume); - } - - @Override - public Collection visit(VolumeSystem vs) { - return getAllFromChildren(vs); - } - - /** - * Aggregate all the matches from visiting the children Content objects of the - * one passed - * @param parent - * @return - */ - protected Collection getAllFromChildren(Content parent) { - Collection all = new ArrayList(); - - try { - for (Content child : parent.getChildren()) { - all.addAll(child.accept(this)); - } - } catch (TskException ex) { - logger.log(Level.SEVERE, "Error getting Content children", ex); - } - - return all; - } - - /** - * Get the part of a file name after (not including) the last '.' and - * coerced to lowercase. - * @param fileName - * @return the file extension, or an empty string if there is none - */ - protected static String getExtension(String fileName) { - int lastDot = fileName.lastIndexOf("."); - - if (lastDot >= 0) { - return fileName.substring(lastDot + 1, fileName.length()).toLowerCase(); - } else { - return ""; - } - } -} diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/GetIngestableFilesContentVisitor.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/GetIngestableFilesContentVisitor.java deleted file mode 100755 index 30ac84c89f..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/GetIngestableFilesContentVisitor.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.datamodel.File; -import org.sleuthkit.datamodel.FileSystem; -import org.sleuthkit.datamodel.FsContent; -import org.sleuthkit.datamodel.SleuthkitCase; -import org.sleuthkit.datamodel.TskData.FileKnown; -import org.sleuthkit.datamodel.TskData; - -/** - * Visitor for getting all the files to try to index from any Content object. - * Currently gets all the non-zero sized files with a file extensions that match a list of - * document types that Tika/Solr-Cell supports. - */ -class GetIngestableFilesContentVisitor extends GetFilesContentVisitor { - - private static final Logger logger = Logger.getLogger(GetIngestableFilesContentVisitor.class.getName()); - - private static final String[] supportedExtensions = KeywordSearchIngestService.ingestibleExtensions; - // the full predicate of a SQLite statement to match supported extensions - private static final String extensionsLikePredicate; - - static { - // build the query fragment for matching file extensions - - StringBuilder likes = new StringBuilder("0"); - - for (String ext : supportedExtensions) { - likes.append(" OR (name LIKE '%."); - likes.append(ext); - likes.append("')"); - } - - extensionsLikePredicate = likes.toString(); - } - - @Override - public Collection visit(File file) { - String extension = getExtension(file.getName()); - if (Arrays.asList(supportedExtensions).contains(extension)) { - return Collections.singleton((FsContent) file); - } else { - return Collections.EMPTY_LIST; - } - } - - @Override - public Collection visit(FileSystem fs) { - // Files in the database have a filesystem field, so it's quick to - // get all the matching files for an entire filesystem with a query - - SleuthkitCase sc = Case.getCurrentCase().getSleuthkitCase(); - - String query = "SELECT * FROM tsk_files WHERE fs_obj_id = " + fs.getId() - + " AND (" + extensionsLikePredicate + ")" - + " AND (known != " + FileKnown.KNOWN.toLong() + ")" - + " AND (meta_type = " + TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG.getMetaType() + ")" - + " AND (size > 0)"; - try { - ResultSet rs = sc.runQuery(query); - List contents = sc.resultSetToFsContents(rs); - final Statement s = rs.getStatement(); - rs.close(); - if (s != null) { - s.close(); - } - return contents; - } catch (SQLException ex) { - logger.log(Level.WARNING, "Couldn't get all files in FileSystem", ex); - return Collections.EMPTY_SET; - } - } -} diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexContentFilesAction.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexContentFilesAction.java deleted file mode 100755 index daab674705..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexContentFilesAction.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.AbstractAction; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.SwingWorker; -import org.apache.solr.client.solrj.SolrServerException; -import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.casemodule.AddImageAction; -import org.sleuthkit.autopsy.keywordsearch.Ingester.IngesterException; -import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.FsContent; -import org.sleuthkit.datamodel.Image; -import org.sleuthkit.datamodel.TskException; - -/** - * Action adds all supported files from the given Content object and its - * children to the Solr index. - */ -public class IndexContentFilesAction extends AbstractAction { - - private static final Logger logger = Logger.getLogger(IndexContentFilesAction.class.getName()); - private static final int MAX_STRING_EXTRACT_SIZE = 10 * (1 << 10) * (1 << 10); - private Content c; - private String name; - private Server.Core solrCore; - - public enum IngestStatus { - - NOT_INGESTED, INGESTED, EXTRACTED_INGESTED, SKIPPED_EXTRACTION,}; - //keep track of ingest status for various types of content - //could also be useful for reporting - private Map ingestStatus; - private int problemFilesCount; - - /** - * New action - * @param c source Content object to get files from - * @param name name to refer to the source by when displaying progress - */ - public IndexContentFilesAction(Content c, String name) { - this(c, name, KeywordSearch.getServer().getCore()); - } - - IndexContentFilesAction(Content c, String name, Server.Core solrCore) { - super("Index files..."); - this.c = c; - this.name = name; - this.solrCore = solrCore; - ingestStatus = new HashMap(); - } - - @Override - public void actionPerformed(ActionEvent e) { - - // create the popUp window to display progress - String title = "Indexing files in " + name; - - final JFrame frame = new JFrame(title); - final JDialog popUpWindow = new JDialog(frame, title, true); // to make the popUp Window modal - - // initialize panel - final IndexProgressPanel panel = new IndexProgressPanel(); - - final SwingWorker task = new SwingWorker() { - - @Override - protected Integer doInBackground() throws Exception { - Ingester ingester = solrCore.getIngester(); - - this.publish("Categorizing files to index. "); - - GetFilesContentVisitor ingestableV = new GetIngestableFilesContentVisitor(); - GetFilesContentVisitor allV = new GetAllFilesContentVisitor(); - - Collection ingestableFiles = c.accept(ingestableV); - Collection allFiles = c.accept(allV); - - //calculate non ingestable Collection (complement of allFiles / ingestableFiles - //TODO implement a facility that selects different categories of FsContent - Collection nonIngestibleFiles = new LinkedHashSet(); - - for (FsContent fs : allFiles) { - if (! ingestableFiles.contains(fs) ) { - nonIngestibleFiles.add(fs); - } - } - - // track number complete or with errors - problemFilesCount = 0; - ingestStatus.clear(); - - //work on known files first - Collection ingestFailedFiles = processIngestible(ingester, ingestableFiles); - nonIngestibleFiles.addAll(ingestFailedFiles); - - //work on unknown files - //TODO should be an option somewhere in GUI (known vs unknown files) - processNonIngestible(ingester, nonIngestibleFiles); - - ingester.commit(); - - //signal a potential change in number of indexed files - try { - final int numIndexedFiles = KeywordSearch.getServer().getCore().queryNumIndexedFiles(); - KeywordSearch.changeSupport.firePropertyChange(KeywordSearch.NUM_FILES_CHANGE_EVT, null, new Integer(numIndexedFiles)); - } catch (SolrServerException se) { - logger.log(Level.SEVERE, "Error executing Solr query to check number of indexed files: ", se); - } - - return problemFilesCount; - } - - private Collection processIngestible(Ingester ingester, Collection fscc) { - Collection ingestFailedCol = new ArrayList(); - - setProgress(0); - int finishedFiles = 0; - final int totalFilesCount = fscc.size(); - for (FsContent f : fscc) { - if (isCancelled()) { - return ingestFailedCol; - } - this.publish("Indexing " + (finishedFiles + 1) + "/" + totalFilesCount + ": " + f.getName()); - try { - ingester.ingest(f); - ingestStatus.put(f.getId(), IngestStatus.INGESTED); - } catch (IngesterException ex) { - ingestFailedCol.add(f); - ingestStatus.put(f.getId(), IngestStatus.NOT_INGESTED); - logger.log(Level.INFO, "Ingester failed with file '" + f.getName() + "' (id: " + f.getId() + ").", ex); - } - setProgress(++finishedFiles * 100 / totalFilesCount); - } - return ingestFailedCol; - } - - private void processNonIngestible(Ingester ingester, Collection fscc) { - setProgress(0); - int finishedFiles = 0; - final int totalFilesCount = fscc.size(); - - for (FsContent f : fscc) { - if (isCancelled()) { - return; - } - this.publish("String extracting/Indexing " + (finishedFiles + 1) + "/" + totalFilesCount + ": " + f.getName()); - - if (f.getSize() < MAX_STRING_EXTRACT_SIZE) { - if (!extractAndIngest(ingester, f)) { - ingestStatus.put(f.getId(), IngestStatus.NOT_INGESTED); - problemFilesCount++; - logger.log(Level.INFO, "Failed to extract strings and ingest, file '" + f.getName() + "' (id: " + f.getId() + ")."); - } else { - ingestStatus.put(f.getId(), IngestStatus.EXTRACTED_INGESTED); - } - } else { - ingestStatus.put(f.getId(), IngestStatus.SKIPPED_EXTRACTION); - } - - setProgress(++finishedFiles * 100 / totalFilesCount); - } - } - - @Override - protected void done() { - int problemFiles = 0; - - try { - if (!this.isCancelled()) { - problemFiles = get(); - } - - } catch (InterruptedException ex) { - // shouldn't be interrupted except by cancel - throw new RuntimeException(ex); - } catch (ExecutionException ex) { - logger.log(Level.SEVERE, "Fatal error during ingest.", ex); - } finally { - popUpWindow.setVisible(false); - popUpWindow.dispose(); - - // notify user if there were problem files - if (problemFiles > 0) { - displayProblemFilesDialog(problemFiles); - } - } - } - - @Override - protected void process(List messages) { - - // display the latest message - if (!messages.isEmpty()) { - panel.setStatusText(messages.get(messages.size() - 1)); - } - - panel.setProgressBar(getProgress()); - } - }; - - panel.addCancelButtonActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - task.cancel(true); - } - }); - - popUpWindow.add(panel); - popUpWindow.pack(); - popUpWindow.setResizable(false); - - // set the location of the popUp Window on the center of the screen - Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); - double w = popUpWindow.getSize().getWidth(); - double h = popUpWindow.getSize().getHeight(); - popUpWindow.setLocation((int) ((screenDimension.getWidth() - w) / 2), (int) ((screenDimension.getHeight() - h) / 2)); - - popUpWindow.addWindowListener(new WindowAdapter() { - - @Override - public void windowClosing(WindowEvent e) { - // deal with being Xed out of - if (!task.isDone()) { - task.cancel(true); - } - } - }); - - - task.execute(); - // display the window - popUpWindow.setVisible(true); - } - - private boolean extractAndIngest(Ingester ingester, FsContent f) { - boolean success = false; - FsContentStringStream fscs = new FsContentStringStream(f, FsContentStringStream.Encoding.ASCII); - try { - fscs.convert(); - ingester.ingest(fscs); - success = true; - } catch (TskException tskEx) { - logger.log(Level.INFO, "Problem extracting string from file: '" + f.getName() + "' (id: " + f.getId() + ").", tskEx); - } catch (IngesterException ingEx) { - logger.log(Level.INFO, "Ingester had a problem with extracted strings from file '" + f.getName() + "' (id: " + f.getId() + ").", ingEx); - } - return success; - } - - private void displayProblemFilesDialog(int problemFiles) { - final Component parentComponent = null; // Use default window frame. - final String message = "Had trouble indexing " + problemFiles + " of the files. See the log for details."; - final String title = "Problem indexing some files"; - final int messageType = JOptionPane.WARNING_MESSAGE; - JOptionPane.showMessageDialog( - parentComponent, - message, - title, - messageType); - } - - @ServiceProvider(service = AddImageAction.IndexImageTask.class) - public static class IndexImageTask implements AddImageAction.IndexImageTask { - - @Override - public void runTask(Image newImage) { - (new IndexContentFilesAction(newImage, "new image")).actionPerformed(null); - } - } -} \ No newline at end of file diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexProgressPanel.form b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexProgressPanel.form deleted file mode 100644 index bed4cafbe3..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexProgressPanel.form +++ /dev/null @@ -1,62 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexProgressPanel.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexProgressPanel.java deleted file mode 100644 index 6150d17d3d..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexProgressPanel.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.awt.event.ActionListener; - -/** - * Displays progress as files are indexed - */ -class IndexProgressPanel extends javax.swing.JPanel { - - /** Creates new form IndexProgressPanel */ - IndexProgressPanel() { - initComponents(); - progressBar.setMinimum(0); - progressBar.setMaximum(100); - progressBar.setIndeterminate(true); - statusText.setText("Starting..."); - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - progressBar = new javax.swing.JProgressBar(); - statusText = new javax.swing.JLabel(); - cancelButton = new javax.swing.JButton(); - - statusText.setText(org.openide.util.NbBundle.getMessage(IndexProgressPanel.class, "IndexProgressPanel.statusText.text")); // NOI18N - - cancelButton.setText(org.openide.util.NbBundle.getMessage(IndexProgressPanel.class, "IndexProgressPanel.cancelButton.text")); // NOI18N - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(statusText) - .addComponent(progressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE) - .addComponent(cancelButton, javax.swing.GroupLayout.Alignment.TRAILING)) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(statusText) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - }// //GEN-END:initComponents - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton cancelButton; - private javax.swing.JProgressBar progressBar; - private javax.swing.JLabel statusText; - // End of variables declaration//GEN-END:variables - - /** - * Sets a listener for the Cancel button - * @param e The action listener - */ - void addCancelButtonActionListener(ActionListener e) { - this.cancelButton.addActionListener(e); - } - - void setProgressBar(int percent) { - progressBar.setIndeterminate(false); - progressBar.setValue(percent); - } - - void setStatusText(String text) { - statusText.setText(text); - } -} From f2edf87d93a09a337e5ceff547486b20f13ab02e Mon Sep 17 00:00:00 2001 From: adam-m Date: Fri, 9 Mar 2012 16:57:11 -0500 Subject: [PATCH 3/4] Remove obsolete keyword search top components --- .../KeywordSearchDataExplorer.java | 144 --- ...ordSearchListImportExportTopComponent.form | 152 --- ...ordSearchListImportExportTopComponent.java | 632 ---------- .../KeywordSearchListTopComponent.form | 383 ------ .../KeywordSearchListTopComponent.java | 1071 ----------------- .../KeywordSearchSimpleTopComponent.form | 232 ---- .../KeywordSearchSimpleTopComponent.java | 319 ----- .../KeywordSearchTabsTopComponent.form | 34 - .../KeywordSearchTabsTopComponent.java | 237 ---- .../KeywordSearchTopComponentInterface.java | 39 - 10 files changed, 3243 deletions(-) delete mode 100644 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchDataExplorer.java delete mode 100644 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListImportExportTopComponent.form delete mode 100644 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListImportExportTopComponent.java delete mode 100755 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListTopComponent.form delete mode 100755 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListTopComponent.java delete mode 100755 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSimpleTopComponent.form delete mode 100755 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSimpleTopComponent.java delete mode 100644 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchTabsTopComponent.form delete mode 100644 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchTabsTopComponent.java delete mode 100644 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchTopComponentInterface.java diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchDataExplorer.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchDataExplorer.java deleted file mode 100644 index 0f3d0c89f9..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchDataExplorer.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.awt.Cursor; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.List; -import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.corecomponentinterfaces.DataExplorer; -import org.sleuthkit.autopsy.keywordsearch.KeywordSearch.QueryType; -import org.sleuthkit.autopsy.keywordsearch.KeywordSearchQueryManager.Presentation; - -/** - * Provides a data explorer to perform Solr searches with - */ -public class KeywordSearchDataExplorer implements DataExplorer { - - private static KeywordSearchDataExplorer theInstance = null; - private KeywordSearchTabsTopComponent tc; - private int filesIndexed; - - private KeywordSearchDataExplorer() { - this.filesIndexed = 0; - this.tc = KeywordSearchTabsTopComponent.findInstance(); - - this.tc.addSearchButtonListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - if (filesIndexed == 0) - return; - - tc.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - - try { - search(); - } finally { - tc.setCursor(null); - } - } - }); - - KeywordSearch.changeSupport.addPropertyChangeListener(KeywordSearch.NUM_FILES_CHANGE_EVT, new IndexChangeListener()); - } - - public static synchronized KeywordSearchDataExplorer getDefault() { - if (theInstance == null) { - theInstance = new KeywordSearchDataExplorer(); - } - return theInstance; - } - - /** - * Executes a query and populates a DataResult tab with the results - * @param solrQuery - */ - private void search() { - KeywordSearchQueryManager man = null; - if (tc.isMultiwordQuery()) { - final List keywords = tc.getQueryList(); - if (keywords.isEmpty()) { - KeywordSearchUtil.displayDialog("Keyword Search Error", "Keyword list is empty, please add at least one keyword to the list", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR); - return; - } - man = new KeywordSearchQueryManager(keywords, Presentation.COLLAPSE); - } else { - QueryType queryType = null; - if (tc.isLuceneQuerySelected()) { - queryType = QueryType.WORD; - } else { - queryType = QueryType.REGEX; - } - final String queryText = tc.getQueryText(); - if (queryText == null || queryText.trim().equals("")) { - KeywordSearchUtil.displayDialog("Keyword Search Error", "Please enter a keyword to search for", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR); - return; - } - man = new KeywordSearchQueryManager(tc.getQueryText(), queryType, Presentation.COLLAPSE); - } - - if (man.validate()) { - man.execute(); - } else { - KeywordSearchUtil.displayDialog("Keyword Search Error", "Invalid query syntax.", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR); - } - - } - - @Override - public org.openide.windows.TopComponent getTopComponent() { - return this.tc; - } - - @Override - public boolean hasMenuOpenAction() { - return false; - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - } - - class IndexChangeListener implements PropertyChangeListener { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - - String changed = evt.getPropertyName(); - //Object oldValue = evt.getOldValue(); - Object newValue = evt.getNewValue(); - - if (newValue != null) { - if (changed.equals(KeywordSearch.NUM_FILES_CHANGE_EVT)) { - int newFilesIndexed = ((Integer) newValue).intValue(); - filesIndexed = newFilesIndexed; - tc.setFilesIndexed(newFilesIndexed); - - } else { - String msg = "Unsupported change event: " + changed; - throw new UnsupportedOperationException(msg); - } - } - } - } -} diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListImportExportTopComponent.form b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListImportExportTopComponent.form deleted file mode 100644 index 6acc9967ec..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListImportExportTopComponent.form +++ /dev/null @@ -1,152 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListImportExportTopComponent.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListImportExportTopComponent.java deleted file mode 100644 index b5ce55a481..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListImportExportTopComponent.java +++ /dev/null @@ -1,632 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.awt.Component; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import java.util.logging.Logger; -import javax.swing.JFileChooser; -import javax.swing.JOptionPane; -import javax.swing.JTable; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableColumn; -import org.openide.util.NbBundle; -import org.openide.windows.TopComponent; -import org.netbeans.api.settings.ConvertAsProperties; -import org.openide.awt.ActionID; -import org.openide.awt.ActionReference; - -/** - * Top component which displays something. - */ -//@ConvertAsProperties(dtd = "-//org.sleuthkit.autopsy.keywordsearch//KeywordSearchListImportExport//EN", -//autostore = false) -//@TopComponent.Description(preferredID = "KeywordSearchListImportExportTopComponent", -////iconBase="SET/PATH/TO/ICON/HERE", -//persistenceType = TopComponent.PERSISTENCE_NEVER) -//@TopComponent.Registration(mode = "explorer", openAtStartup = false) -//@ActionID(category = "Window", id = "org.sleuthkit.autopsy.keywordsearch.KeywordSearchListImportExportTopComponent") -//@ActionReference(path = "Menu/Window" /*, position = 333 */) -//@TopComponent.OpenActionRegistration(displayName = "#CTL_KeywordSearchListImportExportAction", -//preferredID = "KeywordSearchListImportExportTopComponent") -public final class KeywordSearchListImportExportTopComponent extends TopComponent { - - private Logger logger = Logger.getLogger(KeywordSearchListImportExportTopComponent.class.getName()); - private KeywordListTableModel tableModel; - - public KeywordSearchListImportExportTopComponent() { - tableModel = new KeywordListTableModel(); - initComponents(); - customizeComponents(); - setName(NbBundle.getMessage(KeywordSearchListImportExportTopComponent.class, "CTL_KeywordSearchListImportExportTopComponent")); - setToolTipText(NbBundle.getMessage(KeywordSearchListImportExportTopComponent.class, "HINT_KeywordSearchListImportExportTopComponent")); - - - } - - private void customizeComponents() { - - importButton.setToolTipText("Import list(s) of keywords from an external file."); - exportButton.setToolTipText("Export selected list(s) of keywords to an external file."); - deleteButton.setToolTipText("Delete selected list(s) of keywords."); - - - listsTable.setAutoscrolls(true); - //listsTable.setTableHeader(null); - listsTable.setShowHorizontalLines(false); - listsTable.setShowVerticalLines(false); - - listsTable.getParent().setBackground(listsTable.getBackground()); - - //customize column witdhs - listsTable.setSize(260, 200); - final int width = listsTable.getSize().width; - TableColumn column = null; - for (int i = 0; i < 4; i++) { - column = listsTable.getColumnModel().getColumn(i); - switch (i) { - case 0: - case 1: - case 2: - column.setCellRenderer(new CellTooltipRenderer()); - column.setPreferredWidth(((int) (width * 0.28))); - column.setResizable(true); - break; - case 3: - column.setPreferredWidth(((int) (width * 0.15))); - column.setResizable(false); - break; - default: - break; - - } - - } - listsTable.setCellSelectionEnabled(false); - tableModel.resync(); - if (KeywordSearchListsXML.getCurrent().getNumberLists() == 0) { - exportButton.setEnabled(false); - } - - KeywordSearchListsXML.getCurrent().addPropertyChangeListener(new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals(KeywordSearchListsXML.ListsEvt.LIST_ADDED.toString()) - || evt.getPropertyName().equals(KeywordSearchListsXML.ListsEvt.LIST_DELETED.toString())) { - tableModel.resync(); - - if (Integer.valueOf((Integer) evt.getNewValue()) == 0) { - exportButton.setEnabled(false); - deleteButton.setEnabled(false); - } - //else if (Integer.valueOf((Integer) evt.getOldValue()) == 0) { - // exportButton.setEnabled(true); - //} - } else if (evt.getPropertyName().equals(KeywordSearchListsXML.ListsEvt.LIST_UPDATED.toString())) { - tableModel.resync((String) evt.getNewValue()); //changed list name - } - } - }); - - initButtons(); - - } - - private void initButtons() { - if (tableModel.getSelectedLists().isEmpty()) { - deleteButton.setEnabled(false); - exportButton.setEnabled(false); - } else { - deleteButton.setEnabled(true); - exportButton.setEnabled(true); - } - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { - - mainScrollPane = new javax.swing.JScrollPane(); - mainPanel = new javax.swing.JPanel(); - importButton = new javax.swing.JButton(); - exportButton = new javax.swing.JButton(); - deleteButton = new javax.swing.JButton(); - jScrollPane1 = new javax.swing.JScrollPane(); - listsTable = new javax.swing.JTable(); - topLabel = new javax.swing.JLabel(); - - mainScrollPane.setPreferredSize(new java.awt.Dimension(349, 433)); - - mainPanel.setPreferredSize(new java.awt.Dimension(349, 433)); - - org.openide.awt.Mnemonics.setLocalizedText(importButton, org.openide.util.NbBundle.getMessage(KeywordSearchListImportExportTopComponent.class, "KeywordSearchListImportExportTopComponent.importButton.text")); // NOI18N - importButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - importButtonActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(exportButton, org.openide.util.NbBundle.getMessage(KeywordSearchListImportExportTopComponent.class, "KeywordSearchListImportExportTopComponent.exportButton.text")); // NOI18N - exportButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - exportButtonActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(deleteButton, org.openide.util.NbBundle.getMessage(KeywordSearchListImportExportTopComponent.class, "KeywordSearchListImportExportTopComponent.deleteButton.text")); // NOI18N - deleteButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - deleteButtonActionPerformed(evt); - } - }); - - listsTable.setModel(tableModel); - listsTable.setShowHorizontalLines(false); - listsTable.setShowVerticalLines(false); - listsTable.getTableHeader().setReorderingAllowed(false); - jScrollPane1.setViewportView(listsTable); - - topLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); - org.openide.awt.Mnemonics.setLocalizedText(topLabel, org.openide.util.NbBundle.getMessage(KeywordSearchListImportExportTopComponent.class, "KeywordSearchListImportExportTopComponent.topLabel.text")); // NOI18N - - javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(topLabel) - .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup() - .addComponent(importButton) - .addGap(33, 33, 33) - .addComponent(exportButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(deleteButton)) - .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(topLabel) - .addGap(34, 34, 34) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(importButton) - .addComponent(exportButton) - .addComponent(deleteButton)) - .addContainerGap(113, Short.MAX_VALUE)) - ); - - mainScrollPane.setViewportView(mainPanel); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE) - ); - }// //GEN-END:initComponents - - public void importButtonAction(java.awt.event.ActionEvent evt) { - importButtonActionPerformed(evt); - } - - private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importButtonActionPerformed - final String FEATURE_NAME = "Keyword List Import"; - - JFileChooser chooser = new JFileChooser(); - final String EXTENSION = "xml"; - FileNameExtensionFilter filter = new FileNameExtensionFilter( - "Keyword List XML file", EXTENSION); - chooser.setFileFilter(filter); - chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - - int returnVal = chooser.showOpenDialog(this); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File selFile = chooser.getSelectedFile(); - if (selFile == null) { - return; - } - - //force append extension if not given - String fileAbs = selFile.getAbsolutePath(); - - final KeywordSearchListsXML reader = new KeywordSearchListsXML(fileAbs); - if (!reader.load()) { - KeywordSearchUtil.displayDialog(FEATURE_NAME, "Error importing keyword list from file " + fileAbs, KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR); - return; - } - - List toImport = reader.getListsL(); - List toImportConfirmed = new ArrayList(); - - final KeywordSearchListsXML writer = KeywordSearchListsXML.getCurrent(); - - for (KeywordSearchList list : toImport) { - //check name collisions - if (writer.listExists(list.getName())) { - Object[] options = {"Yes, overwrite", - "No, skip", - "Cancel import"}; - int choice = JOptionPane.showOptionDialog(this, - "Keyword list <" + list.getName() + "> already exists locally, overwrite?", - "Import list conflict", - JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE, - null, - options, - options[0]); - if (choice == JOptionPane.OK_OPTION) { - toImportConfirmed.add(list); - } else if (choice == JOptionPane.CANCEL_OPTION) { - break; - } - - } else { - //no conflict - toImportConfirmed.add(list); - } - - } - - if (toImportConfirmed.isEmpty()) { - return; - } - - if (writer.writeLists(toImportConfirmed)) { - KeywordSearchUtil.displayDialog(FEATURE_NAME, "Keyword list imported", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO); - } - - initButtons(); - } - }//GEN-LAST:event_importButtonActionPerformed - - private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed - final String FEATURE_NAME = "Keyword List Export"; - - List toExport = tableModel.getSelectedLists(); - if (toExport.isEmpty()) { - KeywordSearchUtil.displayDialog(FEATURE_NAME, "Please select keyword lists to export", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR); - return; - } - - JFileChooser chooser = new JFileChooser(); - final String EXTENSION = "xml"; - FileNameExtensionFilter filter = new FileNameExtensionFilter( - "Keyword List XML file", EXTENSION); - chooser.setFileFilter(filter); - chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - - int returnVal = chooser.showSaveDialog(this); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File selFile = chooser.getSelectedFile(); - if (selFile == null) { - return; - } - - //force append extension if not given - String fileAbs = selFile.getAbsolutePath(); - if (!fileAbs.endsWith("." + EXTENSION)) { - fileAbs = fileAbs + "." + EXTENSION; - selFile = new File(fileAbs); - } - - boolean shouldWrite = true; - if (selFile.exists()) { - shouldWrite = KeywordSearchUtil.displayConfirmDialog(FEATURE_NAME, "File " + selFile.getName() + " exists, overwrite?", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN); - } - if (!shouldWrite) { - return; - } - - - final KeywordSearchListsXML reader = KeywordSearchListsXML.getCurrent(); - - List toWrite = new ArrayList(); - for (String listName : toExport) { - toWrite.add(reader.getList(listName)); - } - final KeywordSearchListsXML exporter = new KeywordSearchListsXML(fileAbs); - boolean written = exporter.writeLists(toWrite); - if (written) { - KeywordSearchUtil.displayDialog(FEATURE_NAME, "Keyword lists exported", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO); - return; - } - } - - }//GEN-LAST:event_exportButtonActionPerformed - - private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed - tableModel.deleteSelected(); - initButtons(); - }//GEN-LAST:event_deleteButtonActionPerformed - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton deleteButton; - private javax.swing.JButton exportButton; - private javax.swing.JButton importButton; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTable listsTable; - private javax.swing.JPanel mainPanel; - private javax.swing.JScrollPane mainScrollPane; - private javax.swing.JLabel topLabel; - // End of variables declaration//GEN-END:variables - - @Override - public void componentOpened() { - } - - @Override - public void componentClosed() { - } - - void writeProperties(java.util.Properties p) { - - p.setProperty("version", "1.0"); - - } - - void readProperties(java.util.Properties p) { - } - - - private class KeywordListTableModel extends AbstractTableModel { - //data - - private KeywordSearchListsXML listsHandle = KeywordSearchListsXML.getCurrent(); - private Set listData = new TreeSet(); - - @Override - public int getColumnCount() { - return 4; - } - - @Override - public int getRowCount() { - return listData.size(); - } - - @Override - public String getColumnName(int column) { - String colName = null; - switch (column) { - case 0: - colName = "Name"; - break; - case 1: - colName = "Created"; - break; - case 2: - colName = "Modified"; - break; - case 3: - colName = "Sel."; - break; - default: - ; - - } - return colName; - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - Object ret = null; - TableEntry entry = null; - //iterate until row - Iterator it = listData.iterator(); - for (int i = 0; i <= rowIndex; ++i) { - entry = it.next(); - } - switch (columnIndex) { - case 0: - ret = (Object) entry.name; - break; - case 1: - ret = (Object) entry.created; - break; - case 2: - ret = (Object) entry.modified; - break; - case 3: - ret = (Object) entry.isActive; - break; - default: - break; - } - return ret; - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - return columnIndex == 3 ? true : false; - } - - @Override - public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - if (columnIndex == 3) { - TableEntry entry = null; - //iterate until row - Iterator it = listData.iterator(); - for (int i = 0; i <= rowIndex && it.hasNext(); ++i) { - entry = it.next(); - } - if (entry != null) - entry.isActive = (Boolean) aValue; - - initButtons(); - } - } - - @Override - public Class getColumnClass(int c) { - return getValueAt(0, c).getClass(); - } - - List getAllLists() { - List ret = new ArrayList(); - for (TableEntry e : listData) { - ret.add(e.name); - } - return ret; - } - - List getSelectedLists() { - List ret = new ArrayList(); - for (TableEntry e : listData) { - if (e.isActive && !e.name.equals("")) { - ret.add(e.name); - } - } - return ret; - } - - boolean listExists(String list) { - List all = getAllLists(); - return all.contains(list); - } - - //delete selected from handle, events are fired from the handle - void deleteSelected() { - List toDel = new ArrayList(); - for (TableEntry e : listData) { - if (e.isActive && !e.name.equals("")) { - toDel.add(e); - } - } - for (TableEntry del : toDel) { - listsHandle.deleteList(del.name); - } - - } - - //resync model from handle, then update table - void resync() { - listData.clear(); - addLists(listsHandle.getListsL()); - fireTableDataChanged(); - } - - //resync single model entry from handle, then update table - void resync(String listName) { - TableEntry found = null; - for (TableEntry e : listData) { - if (e.name.equals(listName)) { - found = e; - break; - } - } - if (found != null) { - listData.remove(found); - addList(listsHandle.getList(listName)); - } - fireTableDataChanged(); - } - - //add list to the model - private void addList(KeywordSearchList list) { - if (!listExists(list.getName())) { - listData.add(new TableEntry(list)); - } - } - - //add lists to the model - private void addLists(List lists) { - for (KeywordSearchList list : lists) { - if (!listExists(list.getName())) { - listData.add(new TableEntry(list)); - } - } - } - - //single model entry - class TableEntry implements Comparable { - - private DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - String name; - String created; - String modified; - Boolean isActive; - - TableEntry(KeywordSearchList list, Boolean isActive) { - this.name = list.getName(); - this.created = dateFormatter.format(list.getDateCreated()); - this.modified = dateFormatter.format(list.getDateModified()); - this.isActive = isActive; - } - - TableEntry(KeywordSearchList list) { - this.name = list.getName(); - this.created = dateFormatter.format(list.getDateCreated()); - this.modified = dateFormatter.format(list.getDateModified()); - this.isActive = false; - } - - @Override - public int compareTo(Object o) { - return this.name.compareTo(((TableEntry) o).name); - } - } - } - - /** - * tooltips that show text - */ - private static class CellTooltipRenderer extends DefaultTableCellRenderer { - - @Override - public Component getTableCellRendererComponent( - JTable table, Object value, - boolean isSelected, boolean hasFocus, - int row, int column) { - - if (column < 3) { - String val = (String) table.getModel().getValueAt(row, column); - setToolTipText(val); - setText(val); - } - - return this; - } - } -} diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListTopComponent.form b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListTopComponent.form deleted file mode 100755 index 98588cd827..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListTopComponent.form +++ /dev/null @@ -1,383 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListTopComponent.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListTopComponent.java deleted file mode 100755 index 33dbfd49f4..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListTopComponent.java +++ /dev/null @@ -1,1071 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JTable; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableColumn; -import org.openide.util.NbBundle; -import org.openide.windows.TopComponent; -import org.openide.windows.WindowManager; - -/** - * Top component for Keyword List search - */ - -//@ConvertAsProperties(dtd = "-//org.sleuthkit.autopsy.keywordsearch//KeywordSearchList//EN", -//autostore = false) -//@TopComponent.Description(preferredID = "KeywordSearchListTopComponent", -////iconBase="SET/PATH/TO/ICON/HERE", -//persistenceType = TopComponent.PERSISTENCE_NEVER) -//@TopComponent.Registration(mode = "explorer", openAtStartup = false) -////@ActionID(category = "Window", id = "org.sleuthkit.autopsy.keywordsearch.KeywordSearchListTopComponent") -////@ActionReference(path = "Menu/Window" /*, position = 333 */) -////@TopComponent.OpenActionRegistration(displayName = "#CTL_KeywordSearchListAction", -////preferredID = "KeywordSearchListTopComponent") -public final class KeywordSearchListTopComponent extends TopComponent implements KeywordSearchTopComponentInterface { - - private static Logger logger = Logger.getLogger(KeywordSearchListTopComponent.class.getName()); - private KeywordTableModel tableModel; - private String currentKeywordList; - - public static final String PREFERRED_ID = "KeywordSearchListTopComponent"; - - private static KeywordSearchListTopComponent instance = null; - - private KeywordSearchListTopComponent() { - tableModel = new KeywordTableModel(); - initComponents(); - customizeComponents(); - setName(NbBundle.getMessage(KeywordSearchListTopComponent.class, "CTL_KeywordSearchListTopComponent")); - setToolTipText(NbBundle.getMessage(KeywordSearchListTopComponent.class, "HINT_KeywordSearchListTopComponent")); - - } - - @Override - public int getPersistenceType() { - return TopComponent.PERSISTENCE_NEVER; - } - - - - public static synchronized KeywordSearchListTopComponent getDefault() { - if (instance == null) { - instance = new KeywordSearchListTopComponent(); - } - return instance; - } - - public static synchronized KeywordSearchListTopComponent findInstance() { - TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID); - if (win == null) { - return getDefault(); - } - if (win instanceof KeywordSearchListTopComponent) { - return (KeywordSearchListTopComponent) win; - } - - return getDefault(); - } - - private void customizeComponents() { - chRegex.setToolTipText("Keyword is a regular expression"); - addWordButton.setToolTipText(("Add a new word to the keyword search list")); - addWordField.setToolTipText("Enter a new word or regex to search"); - - loadListButton.setToolTipText("Load a new keyword list from file or delete an existing list"); - importButton.setToolTipText("Import list(s) of keywords from an external file."); - saveListButton.setToolTipText("Save the current keyword list to a file"); - searchButton.setToolTipText("Execute the keyword list search using the current list"); - deleteWordButton.setToolTipText("Remove selected keyword(s) from the list"); - deleteAllWordsButton.setToolTipText("Remove all keywords from the list (clear it)"); - - searchButton.setEnabled(false); - - //keywordTable.setAutoscrolls(true); - //keywordTable.setTableHeader(null); - keywordTable.setShowHorizontalLines(false); - keywordTable.setShowVerticalLines(false); - - keywordTable.getParent().setBackground(keywordTable.getBackground()); - - //customize column witdhs - keywordTable.setSize(260, 200); - final int width = keywordTable.getSize().width; - TableColumn column = null; - for (int i = 0; i < 3; i++) { - column = keywordTable.getColumnModel().getColumn(i); - if (i > 0) { - column.setPreferredWidth(((int) (width * 0.15))); - //column.setCellRenderer(new CellTooltipRenderer()); - } - else { - column.setCellRenderer(new CellTooltipRenderer()); - column.setPreferredWidth(((int) (width * 0.68))); - } - } - keywordTable.setCellSelectionEnabled(false); - - //loadDefaultKeywords(); - - KeywordSearchListsXML.getCurrent().addPropertyChangeListener(new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals(KeywordSearchListsXML.ListsEvt.LIST_DELETED.toString())) { - //still keep keywords from deleted list in widgetm just disassociate the name - currentKeywordList = null; - curListValLabel.setText("-"); - if (Integer.valueOf((Integer) evt.getNewValue()) == 0) { - loadListButton.setEnabled(false); - } - } else if (evt.getPropertyName().equals(KeywordSearchListsXML.ListsEvt.LIST_ADDED.toString())) { - if (Integer.valueOf((Integer) evt.getOldValue()) == 0) { - loadListButton.setEnabled(true); - } - } - } - }); - - if (KeywordSearchListsXML.getCurrent().getNumberLists() == 0) { - loadListButton.setEnabled(false); - } - - initButtons(); - - addWordField.setComponentPopupMenu(rightClickMenu); - ActionListener actList = new ActionListener(){ - @Override - public void actionPerformed(ActionEvent e){ - JMenuItem jmi = (JMenuItem) e.getSource(); - if(jmi.equals(cutMenuItem)) - addWordField.cut(); - else if(jmi.equals(copyMenuItem)) - addWordField.copy(); - else if(jmi.equals(pasteMenuItem)) - addWordField.paste(); - else if(jmi.equals(selectAllMenuItem)) - addWordField.selectAll(); - } - }; - cutMenuItem.addActionListener(actList); - copyMenuItem.addActionListener(actList); - pasteMenuItem.addActionListener(actList); - selectAllMenuItem.addActionListener(actList); - } - - private void initButtons() { - //initialize remove buttons - if (getSelectedKeywords().isEmpty()) { - deleteWordButton.setEnabled(false); - } else { - deleteWordButton.setEnabled(true); - } - - if (getAllKeywords().isEmpty()) { - deleteAllWordsButton.setEnabled(false); - saveListButton.setEnabled(false); - } else { - deleteAllWordsButton.setEnabled(true); - saveListButton.setEnabled(true); - } - } - - private void loadDefaultKeywords() { - //some hardcoded keywords for testing - - //phone number - tableModel.addKeyword(new Keyword("\\d\\d\\d[\\.-]\\d\\d\\d[\\.-]\\d\\d\\d\\d", false)); - tableModel.addKeyword(new Keyword("\\d{8,10}", false)); - tableModel.addKeyword(new Keyword("phone|fax", false)); - //IP address - tableModel.addKeyword(new Keyword("(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])", false)); - //email - tableModel.addKeyword(new Keyword("[e\\-]{0,2}mail", false)); - tableModel.addKeyword(new Keyword("[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}", false)); - //URL - tableModel.addKeyword(new Keyword("ftp|sftp|ssh|http|https|www", false)); - //escaped literal word \d\d\d - tableModel.addKeyword(new Keyword("\\Q\\d\\d\\d\\E", false)); - tableModel.addKeyword(new Keyword("\\d\\d\\d\\d", true)); - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { - - mainScrollPane = new javax.swing.JScrollPane(); - mainPanel = new javax.swing.JPanel(); - rightClickMenu = new javax.swing.JPopupMenu(); - cutMenuItem = new javax.swing.JMenuItem(); - copyMenuItem = new javax.swing.JMenuItem(); - pasteMenuItem = new javax.swing.JMenuItem(); - selectAllMenuItem = new javax.swing.JMenuItem(); - filesIndexedNameLabel = new javax.swing.JLabel(); - filesIndexedValLabel = new javax.swing.JLabel(); - titleLabel = new javax.swing.JLabel(); - curListNameLabel = new javax.swing.JLabel(); - loadListButton = new javax.swing.JButton(); - tablePanel = new javax.swing.JPanel(); - saveListButton = new javax.swing.JButton(); - deleteWordButton = new javax.swing.JButton(); - deleteAllWordsButton = new javax.swing.JButton(); - chRegex = new javax.swing.JCheckBox(); - addWordButton = new javax.swing.JButton(); - addWordField = new javax.swing.JTextField(); - jScrollPane1 = new javax.swing.JScrollPane(); - keywordTable = new javax.swing.JTable(); - searchButton = new javax.swing.JButton(); - curListValLabel = new javax.swing.JLabel(); - importButton = new javax.swing.JButton(); - - setPreferredSize(new java.awt.Dimension(345, 534)); - org.openide.awt.Mnemonics.setLocalizedText(cutMenuItem, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.cutMenuItem.text")); // NOI18N - rightClickMenu.add(cutMenuItem); - - org.openide.awt.Mnemonics.setLocalizedText(copyMenuItem, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.copyMenuItem.text")); // NOI18N - rightClickMenu.add(copyMenuItem); - - org.openide.awt.Mnemonics.setLocalizedText(pasteMenuItem, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.pasteMenuItem.text")); // NOI18N - rightClickMenu.add(pasteMenuItem); - - org.openide.awt.Mnemonics.setLocalizedText(selectAllMenuItem, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.selectAllMenuItem.text")); // NOI18N - rightClickMenu.add(selectAllMenuItem); - - setPreferredSize(new java.awt.Dimension(400, 612)); - - mainScrollPane.setPreferredSize(new java.awt.Dimension(345, 534)); - - mainPanel.setPreferredSize(new java.awt.Dimension(345, 534)); - - org.openide.awt.Mnemonics.setLocalizedText(filesIndexedNameLabel, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.filesIndexedNameLabel.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(filesIndexedValLabel, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.filesIndexedValLabel.text")); // NOI18N - - titleLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); - org.openide.awt.Mnemonics.setLocalizedText(titleLabel, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.titleLabel.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(curListNameLabel, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.curListNameLabel.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(loadListButton, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.loadListButton.text")); // NOI18N - loadListButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - loadListButtonActionPerformed(evt); - } - }); - - tablePanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); - - org.openide.awt.Mnemonics.setLocalizedText(saveListButton, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.saveListButton.text")); // NOI18N - saveListButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - saveListButtonActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(deleteWordButton, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.deleteWordButton.text")); // NOI18N - deleteWordButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - deleteWordButtonActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(deleteAllWordsButton, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.deleteAllWordsButton.text")); // NOI18N - deleteAllWordsButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - deleteAllWordsButtonActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(chRegex, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.chRegex.text")); // NOI18N - chRegex.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - chRegexActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(addWordButton, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.addWordButton.text")); // NOI18N - addWordButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - addWordButtonActionPerformed(evt); - } - }); - - addWordField.setText(org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.addWordField.text")); // NOI18N - addWordField.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - addWordFieldActionPerformed(evt); - } - }); - - keywordTable.setModel(tableModel); - keywordTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF); - keywordTable.setShowHorizontalLines(false); - keywordTable.setShowVerticalLines(false); - keywordTable.getTableHeader().setReorderingAllowed(false); - jScrollPane1.setViewportView(keywordTable); - - org.openide.awt.Mnemonics.setLocalizedText(searchButton, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.searchButton.text")); // NOI18N - searchButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - searchButtonActionPerformed(evt); - } - }); - - javax.swing.GroupLayout tablePanelLayout = new javax.swing.GroupLayout(tablePanel); - tablePanel.setLayout(tablePanelLayout); - tablePanelLayout.setHorizontalGroup( - tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(tablePanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(tablePanelLayout.createSequentialGroup() - .addComponent(deleteWordButton) - .addGap(18, 18, 18) - .addComponent(deleteAllWordsButton) - .addGap(18, 18, 18) - .addComponent(saveListButton)) - .addGroup(tablePanelLayout.createSequentialGroup() - .addGap(35, 35, 35) - .addGroup(tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(addWordField, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGroup(tablePanelLayout.createSequentialGroup() - .addGap(10, 10, 10) - .addComponent(chRegex))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(addWordButton)) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(searchButton)) - .addContainerGap(21, Short.MAX_VALUE)) - ); - tablePanelLayout.setVerticalGroup( - tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(tablePanelLayout.createSequentialGroup() - .addGroup(tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(tablePanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(addWordButton) - .addComponent(addWordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(34, 34, 34)) - .addGroup(tablePanelLayout.createSequentialGroup() - .addContainerGap(31, Short.MAX_VALUE) - .addComponent(chRegex) - .addGap(14, 14, 14))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(deleteWordButton) - .addComponent(deleteAllWordsButton)) - .addComponent(saveListButton)) - .addGap(18, 18, 18) - .addComponent(searchButton) - .addContainerGap()) - ); - - org.openide.awt.Mnemonics.setLocalizedText(curListValLabel, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.curListValLabel.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(importButton, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.importButton.text")); // NOI18N - importButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - importButtonActionPerformed(evt); - } - }); - - javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addGap(16, 16, 16) - .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(titleLabel) - .addGroup(mainPanelLayout.createSequentialGroup() - .addGap(58, 58, 58) - .addComponent(loadListButton) - .addGap(27, 27, 27) - .addComponent(importButton)) - .addGroup(mainPanelLayout.createSequentialGroup() - .addGap(11, 11, 11) - .addComponent(curListNameLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(curListValLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)) - .addComponent(tablePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(filesIndexedNameLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(filesIndexedValLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGap(54, 54, 54)) - ); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addGap(21, 21, 21) - .addComponent(titleLabel) - .addGap(18, 18, 18) - .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(importButton) - .addComponent(loadListButton)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(tablePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(curListNameLabel) - .addComponent(curListValLabel)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(filesIndexedNameLabel) - .addComponent(filesIndexedValLabel)) - .addContainerGap(60, Short.MAX_VALUE)) - ); - - mainScrollPane.setViewportView(mainPanel); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 568, Short.MAX_VALUE) - ); - }// //GEN-END:initComponents - - private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed - }//GEN-LAST:event_searchButtonActionPerformed - - private void addWordButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addWordButtonActionPerformed - - String newWord = addWordField.getText().trim(); - boolean isLiteral = !chRegex.isSelected(); - final Keyword keyword = new Keyword(newWord, isLiteral); - - if (newWord.equals("")) { - return; - } else if (keywordExists(keyword)) { - KeywordSearchUtil.displayDialog("New Keyword Entry", "Keyword already exists in the list.", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO); - return; - } - - - //check if valid - boolean valid = true; - try { - Pattern.compile(newWord); - } catch (PatternSyntaxException ex1) { - valid = false; - } catch (IllegalArgumentException ex2) { - valid = false; - } - if (!valid) { - KeywordSearchUtil.displayDialog("New Keyword Entry", "Invalid keyword pattern. Use words or a correct regex pattern.", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR); - return; - } - - //add & reset checkbox - tableModel.addKeyword(keyword); - chRegex.setSelected(false); - addWordField.setText(""); - - if (deleteWordButton.isEnabled() == false) { - if (!getSelectedKeywords().isEmpty()) { - deleteWordButton.setEnabled(true); - } - } - - if (!getAllKeywords().isEmpty()) { - deleteAllWordsButton.setEnabled(true); - saveListButton.setEnabled(true); - } - - - }//GEN-LAST:event_addWordButtonActionPerformed - - private void saveListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveListButtonActionPerformed - final String FEATURE_NAME = "Save Keyword List"; - KeywordSearchListsXML writer = KeywordSearchListsXML.getCurrent(); - - List keywords = tableModel.getAllKeywords(); - if (keywords.isEmpty()) { - KeywordSearchUtil.displayDialog(FEATURE_NAME, "Keyword List is empty and cannot be saved", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO); - return; - } - - String listName = (String) JOptionPane.showInputDialog( - null, - "New keyword list name:", - FEATURE_NAME, - JOptionPane.PLAIN_MESSAGE, - null, - null, - currentKeywordList != null ? currentKeywordList : ""); - if (listName == null || listName.trim().equals("")) { - return; - } - - boolean shouldAdd = false; - if (writer.listExists(listName)) { - boolean replace = KeywordSearchUtil.displayConfirmDialog(FEATURE_NAME, "Keyword List <" + listName + "> already exists, do you want to replace it?", - KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN); - if (replace) { - shouldAdd = true; - } - - } else { - shouldAdd = true; - } - - if (shouldAdd) { - writer.addList(listName, keywords); - } - - currentKeywordList = listName; - curListValLabel.setText(listName); - KeywordSearchUtil.displayDialog(FEATURE_NAME, "Keyword List <" + listName + "> saved", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO); - - - }//GEN-LAST:event_saveListButtonActionPerformed - - private void chRegexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chRegexActionPerformed - }//GEN-LAST:event_chRegexActionPerformed - - private void deleteWordButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteWordButtonActionPerformed - tableModel.deleteSelected(); - - if (getSelectedKeywords().isEmpty()) { - deleteWordButton.setEnabled(false); - } - - if (getAllKeywords().isEmpty()) { - deleteAllWordsButton.setEnabled(false); - saveListButton.setEnabled(false); - } - - }//GEN-LAST:event_deleteWordButtonActionPerformed - - private void deleteAllWordsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteAllWordsButtonActionPerformed - tableModel.deleteAll(); - - deleteWordButton.setEnabled(false); - deleteAllWordsButton.setEnabled(false); - saveListButton.setEnabled(false); - }//GEN-LAST:event_deleteAllWordsButtonActionPerformed - - private void loadListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadListButtonActionPerformed - - final String FEATURE_NAME = "Load Keyword List"; - - KeywordSearchListsXML loader = KeywordSearchListsXML.getCurrent(); - - final String listName = showLoadDeleteListDialog(FEATURE_NAME, loader.getListNames().toArray(), currentKeywordList, true); - - if (listName == null || listName.equals("")) { - return; - } - currentKeywordList = listName; - tableModel.resync(currentKeywordList); - curListValLabel.setText(listName); - initButtons(); - KeywordSearchUtil.displayDialog(FEATURE_NAME, "Keyword List <" + listName + "> loaded", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO); - - - }//GEN-LAST:event_loadListButtonActionPerformed - - private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importButtonActionPerformed - //delegate to lists component - KeywordSearchListImportExportTopComponent lists = new KeywordSearchListImportExportTopComponent(); - if (lists != null) { - lists.importButtonAction(evt); - } - - }//GEN-LAST:event_importButtonActionPerformed - - private void addWordFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addWordFieldActionPerformed - addWordButtonActionPerformed(evt); - }//GEN-LAST:event_addWordFieldActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton addWordButton; - private javax.swing.JTextField addWordField; - private javax.swing.JCheckBox chRegex; - private javax.swing.JMenuItem copyMenuItem; - private javax.swing.JLabel curListNameLabel; - private javax.swing.JLabel curListValLabel; - private javax.swing.JMenuItem cutMenuItem; - private javax.swing.JButton deleteAllWordsButton; - private javax.swing.JButton deleteWordButton; - private javax.swing.JLabel filesIndexedNameLabel; - private javax.swing.JLabel filesIndexedValLabel; - private javax.swing.JButton importButton; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTable keywordTable; - private javax.swing.JButton loadListButton; - private javax.swing.JPanel mainPanel; - private javax.swing.JScrollPane mainScrollPane; - private javax.swing.JMenuItem pasteMenuItem; - private javax.swing.JPopupMenu rightClickMenu; - private javax.swing.JButton saveListButton; - private javax.swing.JButton searchButton; - private javax.swing.JMenuItem selectAllMenuItem; - private javax.swing.JPanel tablePanel; - private javax.swing.JLabel titleLabel; - // End of variables declaration//GEN-END:variables - private JComboBox loadListCombo; - - private JComboBox findDialogComponent(Component component) { - if (component instanceof JComboBox) { - loadListCombo = (JComboBox) component; - } else if (component instanceof JPanel) { - for (Component c : ((JPanel) component).getComponents()) { - findDialogComponent(c); - } - } else if (component instanceof JOptionPane) { - for (Component c : ((JOptionPane) component).getComponents()) { - findDialogComponent(c); - } - - } - return loadListCombo; - } - - private String showLoadDeleteListDialog(final String title, Object[] choices, Object initialChoice, boolean deleteOption) { - if (deleteOption) { - //custom JOptionPane with right click to delete list - //TODO custom component might be better, than customizing a prefab component - final JOptionPane loadPane = new JOptionPane("Keyword list to load (right-click to delete):", JOptionPane.PLAIN_MESSAGE, - JOptionPane.OK_CANCEL_OPTION, null, - null, null); - - loadPane.setWantsInput(true); - loadPane.setSelectionValues(choices); - loadPane.setInitialSelectionValue(initialChoice); - - final JDialog loadDialog = loadPane.createDialog(null, title); - final JPopupMenu rightClickMenu = new JPopupMenu(); - - final MouseListener rightClickListener = new MouseListener() { - - @Override - public void mouseClicked(MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON3) { - rightClickMenu.show(loadPane, e.getX(), e.getY()); - } - } - - @Override - public void mouseEntered(MouseEvent e) { - } - - @Override - public void mouseExited(MouseEvent e) { - } - - @Override - public void mousePressed(MouseEvent e) { - } - - @Override - public void mouseReleased(MouseEvent e) { - rightClickMenu.setVisible(false); - } - }; - JMenuItem delItem = new JMenuItem("Delete List"); - - delItem.addActionListener(new ActionListener() { - - JComboBox combo; - - @Override - public void actionPerformed(ActionEvent e) { - - String selList = null; - //there is no JOptionPane API to get current from combobox before OK is pressed - //workaround traversing the widgets - combo = findDialogComponent(loadPane); - - if (combo != null) { - selList = (String) combo.getSelectedItem(); - } - - if (selList != null && selList != JOptionPane.UNINITIALIZED_VALUE) { - KeywordSearchListsXML loader = KeywordSearchListsXML.getCurrent(); - boolean deleted = loader.deleteList(selList); - if (deleted) { - Object[] choices = loader.getListNames().toArray(); - loadPane.setSelectionValues(choices); - if (choices.length > 0) { - loadPane.setInitialSelectionValue(choices[0]); - } - loadPane.selectInitialValue(); - combo = findDialogComponent(loadPane); - combo.addMouseListener(rightClickListener); - KeywordSearchUtil.displayDialog(title, "Keyword List <" + selList + "> deleted", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO); - } - } - rightClickMenu.setVisible(false); - } - }); - - rightClickMenu.add(delItem); - - JComboBox combo = findDialogComponent(loadPane); - combo.addMouseListener(rightClickListener); - - loadPane.selectInitialValue(); - loadDialog.setVisible(true); - loadDialog.dispose(); - String retString = (String) loadPane.getInputValue(); - if (retString == JOptionPane.UNINITIALIZED_VALUE) //no choice was made - { - retString = null; - } - - return retString; - } else { - return (String) JOptionPane.showInputDialog( - null, - "Keyword list to load:", - title, - JOptionPane.PLAIN_MESSAGE, - null, - choices, - initialChoice); - - } - } - - @Override - public void componentOpened() { - } - - @Override - public void componentClosed() { - } - - void writeProperties(java.util.Properties p) { - p.setProperty("version", "1.0"); - } - - void readProperties(java.util.Properties p) { - } - - @Override - public boolean isMultiwordQuery() { - return true; - } - - @Override - public void addSearchButtonListener(ActionListener l) { - searchButton.addActionListener(l); - } - - @Override - public String getQueryText() { - return null; - } - - @Override - public List getQueryList() { - return getAllKeywords(); - } - - @Override - public boolean isLuceneQuerySelected() { - return false; - } - - @Override - public boolean isRegexQuerySelected() { - return true; - } - - @Override - public void setFilesIndexed(int filesIndexed) { - filesIndexedValLabel.setText(Integer.toString(filesIndexed)); - if (filesIndexed == 0) { - searchButton.setEnabled(false); - } else { - searchButton.setEnabled(true); - } - } - - List getAllKeywords() { - return tableModel.getAllKeywords(); - } - - List getSelectedKeywords() { - return tableModel.getSelectedKeywords(); - } - - private boolean keywordExists(Keyword keyword) { - return tableModel.keywordExists(keyword); - } - - private class KeywordTableModel extends AbstractTableModel { - //data - - private Set keywordData = new TreeSet(); - - @Override - public int getColumnCount() { - return 3; - } - - @Override - public int getRowCount() { - return keywordData.size(); - } - - @Override - public String getColumnName(int column) { - String colName = null; - - switch (column) { - case 0: - colName = "Keyword"; - break; - case 1: - colName = "RegEx."; - break; - case 2: - colName = "Sel."; - break; - default: - ; - - } - return colName; - } - - - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - Object ret = null; - TableEntry entry = null; - //iterate until row - Iterator it = keywordData.iterator(); - for (int i = 0; i <= rowIndex; ++i) { - entry = it.next(); - } - switch (columnIndex) { - case 0: - ret = (Object) entry.keyword; - break; - case 1: - ret = (Object) !entry.isLiteral; - break; - case 2: - ret = (Object) entry.isActive; - break; - default: - logger.log(Level.SEVERE, "Invalid table column index: " + columnIndex); - break; - } - return ret; - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - return columnIndex == 2 ? true : false; - } - - @Override - public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - if (columnIndex == 2) { - TableEntry entry = null; - //iterate until row - Iterator it = keywordData.iterator(); - for (int i = 0; i <= rowIndex && it.hasNext(); ++i) { - entry = it.next(); - } - if (entry != null) - entry.isActive = (Boolean) aValue; - if (getSelectedKeywords().isEmpty()) { - deleteWordButton.setEnabled(false); - } else { - deleteWordButton.setEnabled(true); - } - } - } - - @Override - public Class getColumnClass(int c) { - return getValueAt(0, c).getClass(); - } - - List getAllKeywords() { - List ret = new ArrayList(); - for (TableEntry e : keywordData) { - ret.add(new Keyword(e.keyword, e.isLiteral)); - } - return ret; - } - - List getSelectedKeywords() { - List ret = new ArrayList(); - for (TableEntry e : keywordData) { - if (e.isActive && !e.keyword.equals("")) { - ret.add(new Keyword(e.keyword, e.isLiteral)); - } - } - return ret; - } - - boolean keywordExists(Keyword keyword) { - List all = getAllKeywords(); - return all.contains(keyword); - } - - void addKeyword(Keyword keyword) { - if (!keywordExists(keyword)) { - keywordData.add(new TableEntry(keyword)); - } - fireTableDataChanged(); - } - - void addKeywords(List keywords) { - for (Keyword keyword : keywords) { - if (!keywordExists(keyword)) { - keywordData.add(new TableEntry(keyword)); - } - } - fireTableDataChanged(); - } - - void resync(String listName) { - KeywordSearchListsXML loader = KeywordSearchListsXML.getCurrent(); - KeywordSearchList list = loader.getList(listName); - List keywords = list.getKeywords(); - - deleteAll(); - addKeywords(keywords); - } - - void deleteAll() { - keywordData.clear(); - fireTableDataChanged(); - } - - void deleteSelected() { - List toDel = new ArrayList(); - - for (TableEntry e : keywordData) { - if (e.isActive && !e.keyword.equals("")) { - toDel.add(e); - } - } - for (TableEntry del : toDel) { - keywordData.remove(del); - } - fireTableDataChanged(); - - } - - class TableEntry implements Comparable { - - String keyword; - Boolean isLiteral; - Boolean isActive; - - TableEntry(Keyword keyword, Boolean isActive) { - this.keyword = keyword.getQuery(); - this.isLiteral = keyword.isLiteral(); - this.isActive = isActive; - } - - TableEntry(Keyword keyword) { - this.keyword = keyword.getQuery(); - this.isLiteral = keyword.isLiteral(); - this.isActive = false; - } - - TableEntry(String keyword, Boolean isLiteral) { - this.keyword = keyword; - this.isLiteral = isLiteral; - this.isActive = false; - } - - - - @Override - public int compareTo(Object o) { - int keywords = this.keyword.compareTo(((TableEntry) o).keyword); - if (keywords != 0) - return keywords; - else return this.isLiteral.compareTo(((TableEntry) o).isLiteral); - } - - } - } - - /** - * tooltips that show entire query string - */ - private static class CellTooltipRenderer extends DefaultTableCellRenderer { - - @Override - public Component getTableCellRendererComponent( - JTable table, Object value, - boolean isSelected, boolean hasFocus, - int row, int column) { - - if (column == 0) { - String val = (String) table.getModel().getValueAt(row, column); - setToolTipText(val); - setText(val); - } - - return this; - } - } -} diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSimpleTopComponent.form b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSimpleTopComponent.form deleted file mode 100755 index 4b192dd6ac..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSimpleTopComponent.form +++ /dev/null @@ -1,232 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSimpleTopComponent.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSimpleTopComponent.java deleted file mode 100755 index 4718c88a51..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSimpleTopComponent.java +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.List; -import java.util.logging.Logger; -import javax.swing.JMenuItem; -import org.openide.windows.TopComponent; -import org.openide.windows.WindowManager; - -/** - * Top component for Simple keyword search - * - */ -public class KeywordSearchSimpleTopComponent extends TopComponent implements KeywordSearchTopComponentInterface { - - private Logger logger = Logger.getLogger(KeywordSearchSimpleTopComponent.class.getName()); - private static KeywordSearchSimpleTopComponent instance = null; - - public static final String PREFERRED_ID = "KeywordSearchSimpleTopComponent"; - - /** Creates new form KeywordSearchSimpleTopComponent */ - private KeywordSearchSimpleTopComponent() { - initComponents(); - customizeComponents(); - setName("Simple"); - searchButton.setEnabled(false); - - putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE); - } - - public static synchronized KeywordSearchSimpleTopComponent getDefault() { - if (instance == null) { - instance = new KeywordSearchSimpleTopComponent(); - } - return instance; - } - - public static synchronized KeywordSearchSimpleTopComponent findInstance() { - TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID); - if (win == null) { - return getDefault(); - } - if (win instanceof KeywordSearchSimpleTopComponent) { - return (KeywordSearchSimpleTopComponent) win; - } - - return getDefault(); - } - - private void customizeComponents() { - searchButton.setToolTipText("Execute a keyword search using the query specified."); - chRegex.setToolTipText("Select if keyword is a regular expression"); - queryTextField.setToolTipText("For non-regex search enter one or more keywords separated by white-space.
" - + "For a regular expression search, enter a valid regular expression.
" - + "Examples (in double-quotes): \"\\d\\d\\d-\\d\\d\\d\" \\d{8,10} \"phone\" \"ftp|sftp|ssh|http|https|www\".
" - + "Note: a word can be also searched using a regex search.
Regex containing whitespace [ \\s] matches are currently not supported."); - - queryTextField.setComponentPopupMenu(rightClickMenu); - ActionListener actList = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - JMenuItem jmi = (JMenuItem) e.getSource(); - if (jmi.equals(cutMenuItem)) { - queryTextField.cut(); - } else if (jmi.equals(copyMenuItem)) { - queryTextField.copy(); - } else if (jmi.equals(pasteMenuItem)) { - queryTextField.paste(); - } else if (jmi.equals(selectAllMenuItem)) { - queryTextField.selectAll(); - } - } - }; - cutMenuItem.addActionListener(actList); - copyMenuItem.addActionListener(actList); - pasteMenuItem.addActionListener(actList); - selectAllMenuItem.addActionListener(actList); - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - mainScrollPane = new javax.swing.JScrollPane(); - mainPanel = new javax.swing.JPanel(); - filesIndexedValLabel = new javax.swing.JLabel(); - rightClickMenu = new javax.swing.JPopupMenu(); - cutMenuItem = new javax.swing.JMenuItem(); - copyMenuItem = new javax.swing.JMenuItem(); - pasteMenuItem = new javax.swing.JMenuItem(); - selectAllMenuItem = new javax.swing.JMenuItem(); - filesIndexedNameLabel = new javax.swing.JLabel(); - searchPanel = new javax.swing.JPanel(); - queryTextField = new javax.swing.JTextField(); - chRegex = new javax.swing.JCheckBox(); - searchButton = new javax.swing.JButton(); - titleLabel = new javax.swing.JLabel(); - - cutMenuItem.setText(org.openide.util.NbBundle.getMessage(KeywordSearchSimpleTopComponent.class, "KeywordSearchSimpleTopComponent.cutMenuItem.text")); // NOI18N - rightClickMenu.add(cutMenuItem); - - copyMenuItem.setText(org.openide.util.NbBundle.getMessage(KeywordSearchSimpleTopComponent.class, "KeywordSearchSimpleTopComponent.copyMenuItem.text")); // NOI18N - rightClickMenu.add(copyMenuItem); - - pasteMenuItem.setText(org.openide.util.NbBundle.getMessage(KeywordSearchSimpleTopComponent.class, "KeywordSearchSimpleTopComponent.pasteMenuItem.text")); // NOI18N - rightClickMenu.add(pasteMenuItem); - - selectAllMenuItem.setText(org.openide.util.NbBundle.getMessage(KeywordSearchSimpleTopComponent.class, "KeywordSearchSimpleTopComponent.selectAllMenuItem.text")); // NOI18N - rightClickMenu.add(selectAllMenuItem); - - setAutoscrolls(true); - - mainScrollPane.setPreferredSize(new java.awt.Dimension(351, 249)); - - mainPanel.setPreferredSize(new java.awt.Dimension(351, 249)); - - filesIndexedValLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchSimpleTopComponent.class, "KeywordSearchSimpleTopComponent.filesIndexedValLabel.text")); // NOI18N - - filesIndexedNameLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchSimpleTopComponent.class, "KeywordSearchSimpleTopComponent.filesIndexedNameLabel.text")); // NOI18N - - searchPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true)); - - queryTextField.setHorizontalAlignment(javax.swing.JTextField.LEFT); - queryTextField.setText(org.openide.util.NbBundle.getMessage(KeywordSearchSimpleTopComponent.class, "KeywordSearchSimpleTopComponent.queryTextField.text")); // NOI18N - queryTextField.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - queryTextFieldActionPerformed(evt); - } - }); - - chRegex.setText(org.openide.util.NbBundle.getMessage(KeywordSearchSimpleTopComponent.class, "KeywordSearchSimpleTopComponent.chRegex.text")); // NOI18N - chRegex.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - chRegexActionPerformed(evt); - } - }); - - searchButton.setText(org.openide.util.NbBundle.getMessage(KeywordSearchSimpleTopComponent.class, "KeywordSearchSimpleTopComponent.searchButton.text")); // NOI18N - - javax.swing.GroupLayout searchPanelLayout = new javax.swing.GroupLayout(searchPanel); - searchPanel.setLayout(searchPanelLayout); - searchPanelLayout.setHorizontalGroup( - searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(searchPanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(chRegex) - .addComponent(queryTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE) - .addComponent(searchButton)) - .addContainerGap()) - ); - searchPanelLayout.setVerticalGroup( - searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(searchPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(queryTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(chRegex) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(searchButton) - .addContainerGap()) - ); - - titleLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); - titleLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchSimpleTopComponent.class, "KeywordSearchSimpleTopComponent.titleLabel.text")); // NOI18N - - javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(filesIndexedNameLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(filesIndexedValLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(titleLabel) - .addGroup(mainPanelLayout.createSequentialGroup() - .addGap(10, 10, 10) - .addComponent(searchPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addGap(84, 84, 84)) - ); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(titleLabel) - .addGap(18, 18, 18) - .addComponent(searchPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(23, 23, 23) - .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(filesIndexedNameLabel) - .addComponent(filesIndexedValLabel)) - .addContainerGap(94, Short.MAX_VALUE)) - ); - - filesIndexedValLabel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(KeywordSearchSimpleTopComponent.class, "KeywordSearchTopComponent.filesIndexedValLabel.AccessibleContext.accessibleName")); // NOI18N - filesIndexedNameLabel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(KeywordSearchSimpleTopComponent.class, "KeywordSearchTopComponent.filesIndexedNameLabel.AccessibleContext.accessibleName")); // NOI18N - - mainScrollPane.setViewportView(mainPanel); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 370, Short.MAX_VALUE) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE) - ); - }// //GEN-END:initComponents - - private void chRegexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chRegexActionPerformed - }//GEN-LAST:event_chRegexActionPerformed - - private void queryTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_queryTextFieldActionPerformed - }//GEN-LAST:event_queryTextFieldActionPerformed - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JCheckBox chRegex; - private javax.swing.JMenuItem copyMenuItem; - private javax.swing.JMenuItem cutMenuItem; - private javax.swing.JLabel filesIndexedNameLabel; - private javax.swing.JLabel filesIndexedValLabel; - private javax.swing.JPanel mainPanel; - private javax.swing.JScrollPane mainScrollPane; - private javax.swing.JMenuItem pasteMenuItem; - private javax.swing.JTextField queryTextField; - private javax.swing.JPopupMenu rightClickMenu; - private javax.swing.JButton searchButton; - private javax.swing.JPanel searchPanel; - private javax.swing.JMenuItem selectAllMenuItem; - private javax.swing.JLabel titleLabel; - // End of variables declaration//GEN-END:variables - - @Override - protected void componentOpened() { - // clear old search - queryTextField.setText(""); - } - - @Override - public boolean isMultiwordQuery() { - return false; - } - - @Override - public void addSearchButtonListener(ActionListener l) { - searchButton.addActionListener(l); - queryTextField.addActionListener(l); - } - - @Override - public String getQueryText() { - return queryTextField.getText().trim(); - } - - @Override - public List getQueryList() { - return null; - } - - @Override - public boolean isLuceneQuerySelected() { - return !chRegex.isSelected(); - } - - @Override - public boolean isRegexQuerySelected() { - return chRegex.isSelected(); - } - - /** - * Overwrite when you want to change default persistence type. Default - * persistence type is PERSISTENCE_ALWAYS - * - * @return TopComponent.PERSISTENCE_NEVER - */ - @Override - public int getPersistenceType() { - return TopComponent.PERSISTENCE_NEVER; - } - - @Override - public void setFilesIndexed(int filesIndexed) { - filesIndexedValLabel.setText(Integer.toString(filesIndexed)); - if (filesIndexed == 0) { - searchButton.setEnabled(false); - } else { - searchButton.setEnabled(true); - } - } -} diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchTabsTopComponent.form b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchTabsTopComponent.form deleted file mode 100644 index 747df8cbdb..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchTabsTopComponent.form +++ /dev/null @@ -1,34 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchTabsTopComponent.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchTabsTopComponent.java deleted file mode 100644 index 105f60b6e2..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchTabsTopComponent.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.apache.solr.client.solrj.SolrServerException; -import org.openide.util.NbBundle; -import org.openide.windows.TopComponent; -import org.openide.windows.WindowManager; - -/** - * Keyword Search explorer top component, container for specific Keyword Search tabs - */ -//@ConvertAsProperties(dtd = "-//org.sleuthkit.autopsy.keywordsearch//KeywordSearchTabsTopComponent//EN", -//autostore = false) -//@TopComponent.Description(preferredID = "KeywordSearchTabsTopComponent", -////iconBase="SET/PATH/TO/ICON/HERE", -//persistenceType = TopComponent.PERSISTENCE_NEVER) -//@TopComponent.Registration(mode = "explorer", openAtStartup = false) -//@ActionID(category = "Window", id = "org.sleuthkit.autopsy.keywordsearch.KeywordSearchTabsTopComponentTopComponent") -//@ActionReference(path = "Menu/Window" /*, position = 333 */) -//@TopComponent.OpenActionRegistration(displayName = "#CTL_KeywordSearchTabsTopComponentAction", -//preferredID = "KeywordSearchTabsTopComponent") -public final class KeywordSearchTabsTopComponent extends TopComponent implements KeywordSearchTopComponentInterface { - - private Logger logger = Logger.getLogger(KeywordSearchTabsTopComponent.class.getName()); - private PropertyChangeListener serverChangeListener; - - private static KeywordSearchTabsTopComponent instance = null; - public static final String PREFERRED_ID = "KeywordSearchTabsTopComponent"; - - public enum TABS{Simple, List, History}; - - private KeywordSearchTabsTopComponent() { - initComponents(); - initTabs(); - setName(NbBundle.getMessage(KeywordSearchTabsTopComponent.class, "CTL_KeywordSearchTabsTopComponentTopComponent")); - setToolTipText(NbBundle.getMessage(KeywordSearchTabsTopComponent.class, "HINT_KeywordSearchTabsTopComponentTopComponent")); - - - putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE); - - //register with server Actions - serverChangeListener = new KeywordSearchServerListener(); - KeywordSearch.getServer().addServerActionListener(serverChangeListener); - } - - @Override - public int getPersistenceType() { - return TopComponent.PERSISTENCE_NEVER; - } - - public static synchronized KeywordSearchTabsTopComponent getDefault() { - if (instance == null) { - instance = new KeywordSearchTabsTopComponent(); - } - return instance; - } - - public static synchronized KeywordSearchTabsTopComponent findInstance() { - TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID); - if (win == null) { - return getDefault(); - } - if (win instanceof KeywordSearchTabsTopComponent) { - return (KeywordSearchTabsTopComponent) win; - } - - return getDefault(); - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { - - tabs = new javax.swing.JTabbedPane(); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(tabs, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(tabs, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE) - ); - }// //GEN-END:initComponents - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JTabbedPane tabs; - // End of variables declaration//GEN-END:variables - - private void initTabs() { - tabs.addTab(TABS.Simple.name(), null, KeywordSearchSimpleTopComponent.findInstance(), "Single keyword or regex search"); - tabs.addTab(TABS.List.name(), null, KeywordSearchListTopComponent.findInstance(), "Search for or load a saved list of keywords."); - //tabs.addTab(TABS.Lists.name(), null, new KeywordSearchListImportExportTopComponent(), "Manage (import, export, delete) lists of keywords."); - //tabs.addTab(TABS.History.name(), null, new KeywordSearchHistoryTopComponent(), "Review keyword search history and saved search results."); //TODO - } - - @Override - public void componentOpened() { - } - - @Override - public void componentClosed() { - } - - void writeProperties(java.util.Properties p) { - // better to version settings since initial version as advocated at - // http://wiki.apidesign.org/wiki/PropertyFiles - p.setProperty("version", "1.0"); - // store your settings - } - - void readProperties(java.util.Properties p) { - String version = p.getProperty("version"); - // read your settings according to their version - } - - @Override - public boolean isMultiwordQuery() { - KeywordSearchTopComponentInterface selected = (KeywordSearchTopComponentInterface) tabs.getSelectedComponent(); - if (selected == null) { - return false; - } - return selected.isMultiwordQuery(); - } - - @Override - public void addSearchButtonListener(ActionListener l) { - final int tabsCount = tabs.getTabCount(); - for (int i = 0; i < tabsCount; ++i) { - KeywordSearchTopComponentInterface ks = (KeywordSearchTopComponentInterface) tabs.getComponentAt(i); - ks.addSearchButtonListener(l); - } - } - - @Override - public String getQueryText() { - KeywordSearchTopComponentInterface selected = (KeywordSearchTopComponentInterface) tabs.getSelectedComponent(); - if (selected == null) { - return ""; - } - return selected.getQueryText(); - } - - @Override - public List getQueryList() { - KeywordSearchTopComponentInterface selected = (KeywordSearchTopComponentInterface) tabs.getSelectedComponent(); - if (selected == null) { - return null; - } - return selected.getQueryList(); - } - - - - @Override - public boolean isLuceneQuerySelected() { - KeywordSearchTopComponentInterface selected = (KeywordSearchTopComponentInterface) tabs.getSelectedComponent(); - if (selected == null) { - return false; - } - return selected.isLuceneQuerySelected(); - } - - @Override - public boolean isRegexQuerySelected() { - KeywordSearchTopComponentInterface selected = (KeywordSearchTopComponentInterface) tabs.getSelectedComponent(); - if (selected == null) { - return false; - } - return selected.isRegexQuerySelected(); - } - - @Override - public void setFilesIndexed(int filesIndexed) { - final int tabsCount = tabs.getTabCount(); - for (int i = 0; i < tabsCount; ++i) { - KeywordSearchTopComponentInterface ks = (KeywordSearchTopComponentInterface) tabs.getComponentAt(i); - ks.setFilesIndexed(filesIndexed); - } - - } - - class KeywordSearchServerListener implements PropertyChangeListener { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - String eventType = evt.getPropertyName(); - - if (eventType.equals(Server.CORE_EVT)) { - final Server.CORE_EVT_STATES state = (Server.CORE_EVT_STATES) evt.getNewValue(); - switch (state) { - case STARTED: - try { - final int numIndexedFiles = KeywordSearch.getServer().getCore().queryNumIndexedFiles(); - KeywordSearch.changeSupport.firePropertyChange(KeywordSearch.NUM_FILES_CHANGE_EVT, null, new Integer(numIndexedFiles)); - //setFilesIndexed(numIndexedFiles); - } catch (SolrServerException se) { - logger.log(Level.SEVERE, "Error executing Solr query, " + se.getMessage()); - } - break; - case STOPPED: - break; - default: - - } - } - } - } -} diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchTopComponentInterface.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchTopComponentInterface.java deleted file mode 100644 index baa545b32e..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchTopComponentInterface.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.awt.event.ActionListener; -import java.util.List; - - -/** - * common methods for the KeywordSearch TCs / tabs - * - */ -interface KeywordSearchTopComponentInterface { - - boolean isMultiwordQuery(); - boolean isLuceneQuerySelected(); - boolean isRegexQuerySelected(); - String getQueryText(); - List getQueryList(); - void setFilesIndexed(int filesIndexed); - void addSearchButtonListener(ActionListener l); - -} From 98536640cb5fed4662d5f9042b422ea3c4780062 Mon Sep 17 00:00:00 2001 From: adam-m Date: Fri, 9 Mar 2012 17:04:37 -0500 Subject: [PATCH 4/4] Keyword search regex result BB writes: fix if match has any special characters misinterpreted by Lucene --- .../org/sleuthkit/autopsy/keywordsearch/TermComponentQuery.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/TermComponentQuery.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/TermComponentQuery.java index 7dc9647cc7..062ab39792 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/TermComponentQuery.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/TermComponentQuery.java @@ -169,7 +169,7 @@ public class TermComponentQuery implements KeywordSearchQuery { //snippet String snippet = null; try { - snippet = LuceneQuery.querySnippet(regexMatch, newFsHit.getId()); + snippet = LuceneQuery.querySnippet(KeywordSearchUtil.escapeLuceneQuery(regexMatch, true, false), newFsHit.getId()); } catch (Exception e) { logger.log(Level.INFO, "Error querying snippet: " + regexMatch, e); continue;