Merge pull request #2406 from wishdasher/AUT-2250_keyword_list_substring

Add substring keyword option to keyword lists
This commit is contained in:
Richard Cordovano 2016-11-17 11:33:57 -05:00 committed by GitHub
commit 73f47588da
12 changed files with 333 additions and 150 deletions

View File

@ -29,6 +29,7 @@ KeywordSearchEditListPanel.pasteMenuItem.text=Paste
KeywordSearchEditListPanel.copyMenuItem.text=Copy
KeywordSearchEditListPanel.exportButton.text=Export List
KeywordSearchEditListPanel.deleteListButton.text=Delete List
KeywordSearchEditListPanel.emptyKeyword.text=Empty keyword
KeywordSearchListsManagementPanel.newListButton.text=New List
KeywordSearchListsManagementPanel.importButton.text=Import List
KeywordSearchListsViewerPanel.searchAddButton.text=Search
@ -101,7 +102,6 @@ KeywordSearchEditListPanel.exportButtonActionPerformed.fileFilterLabel=Keyword L
KeywordSearchEditListPanel.exportButtonActionPerformed.fileExistPrompt=File {0} exists, overwrite?
KeywordSearchEditListPanel.exportButtonActionPerformed.kwListExportedMsg=Keyword lists exported
KeywordSearchEditListPanel.kwColName=Keyword
KeywordSearchEditListPanel.exportButtonActionPerformed.regExColName=RegEx
KeywordSearchEditListPanel.addKeyword.message=Add a new word to the keyword search list\:
KeywordSearchEditListPanel.addKeyword.title=New keyword
KeywordSearchFilterNode.getFileActions.openExternViewActLbl=Open in External Viewer
@ -132,7 +132,7 @@ KeywordSearchListsViewerPanel.initIngest.ongoingIngestMsg=Files Indexed\: {0} (i
KeywordSearchListsViewerPanel.initIngest.fileIndexCtMsg=Files Indexed\: {0}
KeywordSearch.selectedColLbl=Selected
KeywordSearch.nameColLbl=Name
KeywordSearch.regExColLbl=RegEx
KeywordSearch.typeColLbl=Keyword Type
KeywordSearchQueryManager.execute.exeWinTitle=Keyword search {0} - {1}
KeywordSearch.newKeywordListMsg=New Keyword List
KeywordSearch.importListFileDialogMsg=Error importing keyword list from file {0}
@ -290,3 +290,8 @@ RawText.getText.error.msg=Error getting text
GlobalListsManagementPanel.newListButton.text=New List
GlobalListsManagementPanel.importButton.text=Import List
GlobalListsManagementPanel.keywordListsLabel.text=Keyword Lists:
NewKeywordPanel.regexButton.text=Regular Expression
NewKeywordPanel.exactButton.text=Exact Match
NewKeywordPanel.substringButton.text=Substring Match
NewKeywordPanel.keywordTextField.text=
NewKeywordPanel.newKeywordLabel.text=Enter a new keyword:

View File

@ -39,9 +39,6 @@ import org.openide.util.NbBundle;
import org.openide.util.actions.SystemAction;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.ingest.IngestManager;
import javax.swing.ImageIcon;
import static javax.swing.SwingConstants.CENTER;
import javax.swing.table.DefaultTableCellRenderer;
/**
* Viewer panel widget for keyword lists that is used in the ingest config and
@ -93,10 +90,9 @@ class DropdownListSearchPanel extends KeywordSearchPanel {
for (int i = 0; i < keywordsTable.getColumnCount(); i++) {
column = keywordsTable.getColumnModel().getColumn(i);
if (i == 0) {
column.setPreferredWidth(((int) (rightWidth * 0.78)));
column.setPreferredWidth(((int) (rightWidth * 0.60)));
} else {
column.setPreferredWidth(((int) (rightWidth * 0.20)));
column.setCellRenderer(new CheckBoxRenderer());
column.setPreferredWidth(((int) (rightWidth * 0.38)));
}
}
@ -123,12 +119,9 @@ class DropdownListSearchPanel extends KeywordSearchPanel {
public void propertyChange(PropertyChangeEvent evt) {
Object source = evt.getSource();
if (source instanceof String && ((String) source).equals("LOCAL")) { //NON-NLS
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
ingestRunning = IngestManager.getInstance().isIngestRunning();
updateComponents();
}
EventQueue.invokeLater(() -> {
ingestRunning = IngestManager.getInstance().isIngestRunning();
updateComponents();
});
}
}
@ -320,8 +313,8 @@ class DropdownListSearchPanel extends KeywordSearchPanel {
private class KeywordListsTableModel extends AbstractTableModel {
//data
private XmlKeywordSearchList listsHandle = XmlKeywordSearchList.getCurrent();
private List<ListTableEntry> listData = new ArrayList<>();
private final XmlKeywordSearchList listsHandle = XmlKeywordSearchList.getCurrent();
private final List<ListTableEntry> listData = new ArrayList<>();
@Override
public int getColumnCount() {
@ -496,7 +489,7 @@ class DropdownListSearchPanel extends KeywordSearchPanel {
ret = NbBundle.getMessage(this.getClass(), "KeywordSearch.nameColLbl");
break;
case 1:
ret = NbBundle.getMessage(this.getClass(), "KeywordSearch.regExColLbl");
ret = NbBundle.getMessage(this.getClass(), "KeywordSearch.typeColLbl");
break;
default:
break;
@ -519,7 +512,7 @@ class DropdownListSearchPanel extends KeywordSearchPanel {
ret = (Object) entry.name;
break;
case 1:
ret = (Object) entry.regex;
ret = (Object) entry.keywordType;
break;
default:
break;
@ -559,11 +552,11 @@ class DropdownListSearchPanel extends KeywordSearchPanel {
private class KeywordTableEntry implements Comparable<KeywordTableEntry> {
String name;
Boolean regex;
String keywordType;
KeywordTableEntry(Keyword keyword) {
this.name = keyword.getSearchTerm();
this.regex = !keyword.searchTermIsLiteral();
this.keywordType = keyword.getSearchTermType();
}
@Override
@ -598,33 +591,4 @@ class DropdownListSearchPanel extends KeywordSearchPanel {
return this;
}
}
/**
* A cell renderer for boolean cells that shows a center-aligned green check
* mark if true, nothing if false.
*/
private class CheckBoxRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = 1L;
final ImageIcon theCheck = new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/checkmark.png")); // NON-NLS
CheckBoxRenderer() {
setHorizontalAlignment(CENTER);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if ((value instanceof Boolean)) {
if ((Boolean) value) {
setIcon(theCheck);
setToolTipText(Bundle.IsRegularExpression());
} else {
setIcon(null);
setToolTipText(null);
}
}
return this;
}
}
}

View File

@ -52,6 +52,7 @@ public class DropdownSingleKeywordSearchPanel extends KeywordSearchPanel {
* Gets the default instance of a dropdown panel that provides GUI
* components that allow a user to do three types of ad hoc single keyword
* searches.
* @return the default instance of DropdownSingleKeywordSearchPanel
*/
public static synchronized DropdownSingleKeywordSearchPanel getDefault() {
if (null == defaultInstance) {

View File

@ -42,18 +42,7 @@ import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.corecomponents.OptionsPanel;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.ingest.IngestManager;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import static javax.swing.SwingConstants.CENTER;
import javax.swing.table.DefaultTableCellRenderer;
import org.openide.util.NbBundle.Messages;
/**
* GlobalEditListPanel widget to manage keywords in lists
@ -90,7 +79,6 @@ class GlobalEditListPanel extends javax.swing.JPanel implements ListSelectionLis
column.setPreferredWidth(((int) (width * 0.90)));
} else {
column.setPreferredWidth(((int) (width * 0.10)));
column.setCellRenderer(new CheckBoxRenderer());
}
}
keywordTable.setCellSelectionEnabled(false);
@ -110,18 +98,13 @@ class GlobalEditListPanel extends javax.swing.JPanel implements ListSelectionLis
setButtonStates();
setButtonStates();
IngestManager.getInstance().addIngestJobEventListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
Object source = evt.getSource();
if (source instanceof String && ((String) source).equals("LOCAL")) { //NON-NLS
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
setButtonStates();
}
EventQueue.invokeLater(() -> {
setButtonStates();
});
}
}
@ -351,30 +334,21 @@ class GlobalEditListPanel extends javax.swing.JPanel implements ListSelectionLis
}// </editor-fold>//GEN-END:initComponents
private void newWordButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newWordButtonActionPerformed
JCheckBox chRegex = new JCheckBox(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.chRegex.text"));
chRegex.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.kwReToolTip"));
JTextField addWordField = new JTextField(25);
addWordField.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.enterNewWordToolTip"));
NewKeywordPanel panel = new NewKeywordPanel();
JPanel addKeywordPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
addKeywordPanel.add(new JLabel(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.addKeyword.message")));
addKeywordPanel.add(addWordField);
addKeywordPanel.add(chRegex);
addKeywordPanel.setPreferredSize(new Dimension(250, 80));
int result = JOptionPane.showConfirmDialog(null, addKeywordPanel,
int result = JOptionPane.showConfirmDialog(null, panel,
NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.addKeyword.title"),
JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
String newWord = addWordField.getText().trim();
boolean isLiteral = !chRegex.isSelected();
final Keyword keyword = new Keyword(newWord, isLiteral);
if (newWord.equals("")) {
String newWord = panel.getKeywordText();
if (newWord.isEmpty()) {
KeywordSearchUtil.displayDialog(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.newKwTitle"),
NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.emptyKeyword.text"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
return;
} else if (currentKeywordList.hasKeyword(keyword)) {
}
final Keyword keyword = new Keyword(newWord, !panel.isKeywordRegex(), panel.isKeywordExact());
if (currentKeywordList.hasKeyword(keyword)) {
KeywordSearchUtil.displayDialog(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.newKwTitle"),
NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.addWordButtonAction.kwAlreadyExistsMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
return;
@ -401,8 +375,6 @@ class GlobalEditListPanel extends javax.swing.JPanel implements ListSelectionLis
firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
setFocusOnKeywordTextBox();
setButtonStates();
} else {
return;
}
}//GEN-LAST:event_newWordButtonActionPerformed
@ -563,11 +535,10 @@ class GlobalEditListPanel extends javax.swing.JPanel implements ListSelectionLis
colName = NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.kwColName");
break;
case 1:
colName = NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.regExColName");
colName = NbBundle.getMessage(this.getClass(), "KeywordSearch.typeColLbl");
break;
default:
;
}
return colName;
}
@ -581,10 +552,10 @@ class GlobalEditListPanel extends javax.swing.JPanel implements ListSelectionLis
Keyword word = currentKeywordList.getKeywords().get(rowIndex);
switch (columnIndex) {
case 0:
ret = (Object) word.getSearchTerm();
ret = word.getSearchTerm();
break;
case 1:
ret = (Object) !word.searchTermIsLiteral();
ret = word.getSearchTermType();
break;
default:
logger.log(Level.SEVERE, "Invalid table column index: {0}", columnIndex); //NON-NLS
@ -629,36 +600,6 @@ class GlobalEditListPanel extends javax.swing.JPanel implements ListSelectionLis
}
}
/**
* A cell renderer for boolean cells that shows a center-aligned green check
* mark if true, nothing if false.
*/
private class CheckBoxRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = 1L;
final ImageIcon theCheck = new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/checkmark.png")); // NON-NLS
CheckBoxRenderer() {
setHorizontalAlignment(CENTER);
}
@Override
@Messages("IsRegularExpression=Keyword is a regular expression")
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if ((value instanceof Boolean)) {
if ((Boolean) value) {
setIcon(theCheck);
setToolTipText(Bundle.IsRegularExpression());
} else {
setIcon(null);
setToolTipText(null);
}
}
return this;
}
}
/**
* Set the keyboard focus to new keyword textbox.
*/

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2014 Basis Technology Corp.
* Copyright 2011-2016 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -76,7 +76,7 @@ final class GlobalListSettingsPanel extends javax.swing.JPanel implements Option
JOptionPane.PLAIN_MESSAGE,
null,
null,
currentKeywordList != null ? currentKeywordList.getName() : "");
currentKeywordList.getName());
if (listName == null || listName.trim().equals("")) {
return;
}

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2014 Basis Technology Corp.
* Copyright 2011-2016 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -40,8 +40,8 @@ class GlobalListsManagementPanel extends javax.swing.JPanel implements OptionsPa
private static final long serialVersionUID = 1L;
private Logger logger = Logger.getLogger(GlobalListsManagementPanel.class.getName());
private KeywordListTableModel tableModel;
private final Logger logger = Logger.getLogger(GlobalListsManagementPanel.class.getName());
private final KeywordListTableModel tableModel;
private final org.sleuthkit.autopsy.keywordsearch.GlobalListSettingsPanel globalListSettingsPanel;
GlobalListsManagementPanel(org.sleuthkit.autopsy.keywordsearch.GlobalListSettingsPanel gsp) {
@ -345,7 +345,7 @@ class GlobalListsManagementPanel extends javax.swing.JPanel implements OptionsPa
private class KeywordListTableModel extends AbstractTableModel {
private XmlKeywordSearchList listsHandle = XmlKeywordSearchList.getCurrent();
private final XmlKeywordSearchList listsHandle = XmlKeywordSearchList.getCurrent();
@Override
public int getColumnCount() {

View File

@ -18,6 +18,7 @@
*/
package org.sleuthkit.autopsy.keywordsearch;
import org.openide.util.NbBundle;
import org.sleuthkit.datamodel.BlackboardAttribute;
/**
@ -119,6 +120,18 @@ class Keyword {
return isWholeWord;
}
String getSearchTermType() {
if (isLiteral) {
if (isWholeWord) {
return NbBundle.getMessage(NewKeywordPanel.class, "NewKeywordPanel.exactButton.text");
} else {
return NbBundle.getMessage(NewKeywordPanel.class, "NewKeywordPanel.substringButton.text");
}
} else {
return NbBundle.getMessage(NewKeywordPanel.class, "NewKeywordPanel.regexButton.text");
}
}
/**
* Sets the artifact attribute type associated with the keyword, if any.
*
@ -159,9 +172,9 @@ class Keyword {
return false;
}
Keyword other = (Keyword) obj;
return (this.searchTerm.equals(other.searchTerm)
&& this.isLiteral == other.isLiteral
&& this.isWholeWord == other.isWholeWord);
return (this.searchTerm.equals(other.getSearchTerm())
&& this.isLiteral == other.searchTermIsLiteral()
&& this.isWholeWord == other.searchTermIsWholeWord());
}
@Override

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2014 Basis Technology Corp.
* Copyright 2011-2016 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
<Component class="javax.swing.ButtonGroup" name="keywordTypeButtonGroup">
</Component>
</NonVisualComponents>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="exactButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="substringButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="regexButton" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="newKeywordLabel" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="keywordTextField" alignment="0" min="-2" pref="305" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="newKeywordLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="keywordTextField" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="exactButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="substringButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="regexButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JTextField" name="keywordTextField">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/keywordsearch/Bundle.properties" key="NewKeywordPanel.keywordTextField.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="ancestorAdded" listener="javax.swing.event.AncestorListener" parameters="javax.swing.event.AncestorEvent" handler="keywordTextFieldAncestorAdded"/>
</Events>
</Component>
<Component class="javax.swing.JRadioButton" name="exactButton">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="keywordTypeButtonGroup"/>
</Property>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/keywordsearch/Bundle.properties" key="NewKeywordPanel.exactButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JRadioButton" name="substringButton">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="keywordTypeButtonGroup"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/keywordsearch/Bundle.properties" key="NewKeywordPanel.substringButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JRadioButton" name="regexButton">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="keywordTypeButtonGroup"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/keywordsearch/Bundle.properties" key="NewKeywordPanel.regexButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="newKeywordLabel">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/keywordsearch/Bundle.properties" key="NewKeywordPanel.newKeywordLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,142 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2016 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> 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;
/**
* A panel that is contained in NewKeywordDialog used when the user wants to add
* a new keyword to a list via the options panel. This panel allows the user to
* indicate whether they want the keyword to be an exact match, a substring, or
* a regular expression.
*/
class NewKeywordPanel extends javax.swing.JPanel {
/**
* Creates new form NewKeywordPanel
*/
public NewKeywordPanel() {
initComponents();
}
/**
* @return the text for the new keyword
*/
String getKeywordText() {
return keywordTextField.getText();
}
/**
* @return true if the regular expression radio button is selected
*/
boolean isKeywordRegex() {
return regexButton.isSelected();
}
/**
* @return true if the exact match radio button is selected
*/
boolean isKeywordExact() {
return exactButton.isSelected();
}
/**
* 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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
keywordTypeButtonGroup = new javax.swing.ButtonGroup();
keywordTextField = new javax.swing.JTextField();
exactButton = new javax.swing.JRadioButton();
substringButton = new javax.swing.JRadioButton();
regexButton = new javax.swing.JRadioButton();
newKeywordLabel = new javax.swing.JLabel();
keywordTextField.setText(org.openide.util.NbBundle.getMessage(NewKeywordPanel.class, "NewKeywordPanel.keywordTextField.text")); // NOI18N
keywordTextField.addAncestorListener(new javax.swing.event.AncestorListener() {
public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
}
public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
keywordTextFieldAncestorAdded(evt);
}
public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
}
});
keywordTypeButtonGroup.add(exactButton);
exactButton.setSelected(true);
org.openide.awt.Mnemonics.setLocalizedText(exactButton, org.openide.util.NbBundle.getMessage(NewKeywordPanel.class, "NewKeywordPanel.exactButton.text")); // NOI18N
keywordTypeButtonGroup.add(substringButton);
org.openide.awt.Mnemonics.setLocalizedText(substringButton, org.openide.util.NbBundle.getMessage(NewKeywordPanel.class, "NewKeywordPanel.substringButton.text")); // NOI18N
keywordTypeButtonGroup.add(regexButton);
org.openide.awt.Mnemonics.setLocalizedText(regexButton, org.openide.util.NbBundle.getMessage(NewKeywordPanel.class, "NewKeywordPanel.regexButton.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(newKeywordLabel, org.openide.util.NbBundle.getMessage(NewKeywordPanel.class, "NewKeywordPanel.newKeywordLabel.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)
.addGroup(layout.createSequentialGroup()
.addComponent(exactButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(substringButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(regexButton))
.addComponent(newKeywordLabel)
.addComponent(keywordTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(newKeywordLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(keywordTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(exactButton)
.addComponent(substringButton)
.addComponent(regexButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void keywordTextFieldAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_keywordTextFieldAncestorAdded
evt.getComponent().requestFocusInWindow();
}//GEN-LAST:event_keywordTextFieldAncestorAdded
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JRadioButton exactButton;
private javax.swing.JTextField keywordTextField;
private javax.swing.ButtonGroup keywordTypeButtonGroup;
private javax.swing.JLabel newKeywordLabel;
private javax.swing.JRadioButton regexButton;
private javax.swing.JRadioButton substringButton;
// End of variables declaration//GEN-END:variables
}

View File

@ -55,6 +55,7 @@ final class XmlKeywordSearchList extends KeywordSearchList {
private static final String LIST_INGEST_MSGS = "ingest_messages"; //NON-NLS
private static final String KEYWORD_EL = "keyword"; //NON-NLS
private static final String KEYWORD_LITERAL_ATTR = "literal"; //NON-NLS
private static final String KEYWORD_WHOLE_ATTR = "whole"; //NON-NLS
private static final String KEYWORD_SELECTOR_ATTR = "selector"; //NON-NLS
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; //NON-NLS
private static final String ENCODING = "UTF-8"; //NON-NLS
@ -125,6 +126,8 @@ final class XmlKeywordSearchList extends KeywordSearchList {
Element keywordEl = doc.createElement(KEYWORD_EL);
String literal = keyword.searchTermIsLiteral() ? "true" : "false"; //NON-NLS
keywordEl.setAttribute(KEYWORD_LITERAL_ATTR, literal);
String whole = keyword.searchTermIsWholeWord() ? "true" : "false"; //NON-NLS
keywordEl.setAttribute(KEYWORD_WHOLE_ATTR, whole);
BlackboardAttribute.ATTRIBUTE_TYPE selectorType = keyword.getArtifactAttributeType();
if (selectorType != null) {
keywordEl.setAttribute(KEYWORD_SELECTOR_ATTR, selectorType.getLabel());
@ -195,14 +198,20 @@ final class XmlKeywordSearchList extends KeywordSearchList {
Element wordEl = (Element) wordsNList.item(j);
String literal = wordEl.getAttribute(KEYWORD_LITERAL_ATTR);
boolean isLiteral = literal.equals("true"); //NON-NLS
Keyword keyword = new Keyword(wordEl.getTextContent(), isLiteral);
Keyword keyword;
String whole = wordEl.getAttribute(KEYWORD_WHOLE_ATTR);
if (whole.equals("")) {
keyword = new Keyword(wordEl.getTextContent(), isLiteral);
} else {
boolean isWhole = whole.equals("true");
keyword = new Keyword(wordEl.getTextContent(), isLiteral, isWhole);
}
String selector = wordEl.getAttribute(KEYWORD_SELECTOR_ATTR);
if (!selector.equals("")) {
BlackboardAttribute.ATTRIBUTE_TYPE selectorType = BlackboardAttribute.ATTRIBUTE_TYPE.fromLabel(selector);
keyword.setArtifactAttributeType(selectorType);
}
words.add(keyword);
}
theLists.put(name, list);
}