19 package org.sleuthkit.autopsy.filesearch;
21 import java.awt.event.ActionListener;
22 import org.openide.util.NbBundle;
23 import org.openide.util.NbBundle.Messages;
29 class HashSearchFilter
extends AbstractFileSearchFilter<HashSearchPanel> {
31 private static final String EMPTY_HASH_MESSAGE = NbBundle
32 .getMessage(HashSearchFilter.class,
"HashSearchPanel.emptyHashMsg.text");
34 public HashSearchFilter() {
35 this(
new HashSearchPanel());
38 public HashSearchFilter(HashSearchPanel component) {
43 public boolean isEnabled() {
44 return this.getComponent().getHashCheckBox().isSelected();
48 public String getPredicate() throws FilterValidationException {
49 String md5Hash = this.getComponent().getSearchTextField().getText();
51 if (md5Hash.isEmpty()) {
52 throw new FilterValidationException(EMPTY_HASH_MESSAGE);
55 return "md5 = '" + md5Hash.toLowerCase() +
"'";
59 public void addActionListener(ActionListener l) {
60 getComponent().addActionListener(l);
65 "HashSearchFilter.errorMessage.emptyHash=Hash data is empty.",
66 "# {0} - hash data length",
"HashSearchFilter.errorMessage.wrongLength=Input length({0}), doesn''t match the MD5 length(32).",
67 "HashSearchFilter.errorMessage.wrongCharacter=MD5 contains invalid hex characters."
69 public boolean isValid() {
70 String inputHashData = this.getComponent().getSearchTextField().getText();
71 if (inputHashData.isEmpty()) {
72 setLastError(Bundle.HashSearchFilter_errorMessage_emptyHash());
75 if (inputHashData.length() != 32) {
76 setLastError(Bundle.HashSearchFilter_errorMessage_wrongLength(inputHashData.length()));
79 if (!inputHashData.matches(
"[0-9a-fA-F]+")) {
80 setLastError(Bundle.HashSearchFilter_errorMessage_wrongCharacter());