From 1249ab83761106f201dc398287526ba6fa9664c3 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Fri, 26 Sep 2014 10:20:45 -0400 Subject: [PATCH 1/4] Create keyword lists manager to establish an appropriate public interface --- .../keywordsearch/KeywordListsManager.java | 72 +++++++++++++++++++ .../keywordsearch/XmlKeywordSearchList.java | 47 ++++++------ 2 files changed, 95 insertions(+), 24 deletions(-) create mode 100644 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordListsManager.java diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordListsManager.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordListsManager.java new file mode 100644 index 0000000000..185b71a604 --- /dev/null +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordListsManager.java @@ -0,0 +1,72 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2014 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.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.List; +import java.util.Observable; + +/** + * A manager for keyword lists. + */ +// TODO (RC): This class is a first step towards a fully functional and public +// keyword list manager, establishing the beginning of a public API. It is +// motivated by a desire to not expose XmlKeywordSearchList to public clients. +// It should be futher developed as time constraints and needs dictate. +public class KeywordListsManager extends Observable { + + private static KeywordListsManager instance; + private final PropertyChangeListener listsChangeListener; + + /** + * Constructs a keyword lists manager. + */ + private KeywordListsManager() { + this.listsChangeListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + KeywordListsManager.this.setChanged(); + KeywordListsManager.this.notifyObservers(); + } + }; + XmlKeywordSearchList.getCurrent().addPropertyChangeListener(this.listsChangeListener); + } + + /** + * Gets the singleton instance of the keyword lists manager. + */ + public static synchronized KeywordListsManager getInstance() { + if (instance == null) { + instance = new KeywordListsManager(); + } + return instance; + } + + /** + * Gets the configured keyword lists. + * + * @return A collection of keyword list objects. + */ + public List getKeywordLists() { + return new ArrayList<>(XmlKeywordSearchList.getCurrent().getListsL()); + } + +} diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/XmlKeywordSearchList.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/XmlKeywordSearchList.java index 56a4077e82..91b7f82873 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/XmlKeywordSearchList.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/XmlKeywordSearchList.java @@ -38,15 +38,15 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** - * Manages reading and writing of keyword lists to user settings XML file keywords.xml - * or to any file provided in constructor + * Manages reading and writing of keyword lists to user settings XML file + * keywords.xml or to any file provided in constructor */ -public final class XmlKeywordSearchList extends KeywordSearchList { +final class XmlKeywordSearchList extends KeywordSearchList { private static final Logger xmlListslogger = Logger.getLogger(XmlKeywordSearchList.class.getName()); private static final String CUR_LISTS_FILE_NAME = "keywords.xml"; //NON-NLS - private static String CUR_LISTS_FILE = PlatformUtil.getUserConfigDirectory() + File.separator + CUR_LISTS_FILE_NAME; - private static final String XSDFILE = "KeywordsSchema.xsd"; //NON-NLS + private static final String CUR_LISTS_FILE = PlatformUtil.getUserConfigDirectory() + File.separator + CUR_LISTS_FILE_NAME; +// private static final String XSDFILE = "KeywordsSchema.xsd"; //NON-NLS private static final String ROOT_EL = "keyword_lists"; //NON-NLS private static final String LIST_EL = "keyword_list"; //NON-NLS private static final String LIST_NAME_ATTR = "name"; //NON-NLS @@ -59,8 +59,8 @@ public final class XmlKeywordSearchList extends KeywordSearchList { 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 - private static XmlKeywordSearchList currentInstance = null; - private DateFormat dateFormatter; + private static XmlKeywordSearchList currentInstance = null; + private final DateFormat dateFormatter; static synchronized XmlKeywordSearchList getCurrent() { if (currentInstance == null) { @@ -71,20 +71,21 @@ public final class XmlKeywordSearchList extends KeywordSearchList { } /** - * Constructor to obtain handle on other that the current keyword list - * (such as for import or export) + * Constructor to obtain handle on other that the current keyword list (such + * as for import or export) + * * @param xmlFile xmlFile to obtain XmlKeywordSearchList handle on */ XmlKeywordSearchList(String xmlFile) { super(xmlFile); dateFormatter = new SimpleDateFormat(DATE_FORMAT); } - + @Override public boolean save() { return save(false); } - + @Override public boolean save(boolean isExport) { boolean success = false; @@ -113,7 +114,7 @@ public final class XmlKeywordSearchList extends KeywordSearchList { listEl.setAttribute(LIST_NAME_ATTR, listName); listEl.setAttribute(LIST_CREATE_ATTR, created); listEl.setAttribute(LIST_MOD_ATTR, modified); - + // only write the 'useForIngest' and 'ingestMessages' attributes // if we're not exporting the list. if (!isExport) { @@ -123,7 +124,7 @@ public final class XmlKeywordSearchList extends KeywordSearchList { for (Keyword keyword : keywords) { Element keywordEl = doc.createElement(KEYWORD_EL); - String literal = keyword.isLiteral()?"true":"false"; //NON-NLS + String literal = keyword.isLiteral() ? "true" : "false"; //NON-NLS keywordEl.setAttribute(KEYWORD_LITERAL_ATTR, literal); BlackboardAttribute.ATTRIBUTE_TYPE selectorType = keyword.getType(); if (selectorType != null) { @@ -165,25 +166,23 @@ public final class XmlKeywordSearchList extends KeywordSearchList { final String name = listEl.getAttribute(LIST_NAME_ATTR); final String created = listEl.getAttribute(LIST_CREATE_ATTR); final String modified = listEl.getAttribute(LIST_MOD_ATTR); - + //set these bools to true by default, if they don't exist in XML Boolean useForIngestBool; - Boolean ingestMessagesBool; - - if (listEl.hasAttribute(LIST_USE_FOR_INGEST) ) { + Boolean ingestMessagesBool; + + if (listEl.hasAttribute(LIST_USE_FOR_INGEST)) { useForIngestBool = Boolean.parseBoolean(listEl.getAttribute(LIST_USE_FOR_INGEST)); - } - else { + } else { useForIngestBool = true; } if (listEl.hasAttribute(LIST_INGEST_MSGS)) { ingestMessagesBool = Boolean.parseBoolean(listEl.getAttribute(LIST_INGEST_MSGS)); - } - else { + } else { ingestMessagesBool = true; } - + Date createdDate = dateFormatter.parse(created); Date modDate = dateFormatter.parse(modified); @@ -199,12 +198,12 @@ public final class XmlKeywordSearchList extends KeywordSearchList { boolean isLiteral = literal.equals("true"); //NON-NLS Keyword keyword = new Keyword(wordEl.getTextContent(), isLiteral); String selector = wordEl.getAttribute(KEYWORD_SELECTOR_ATTR); - if (! selector.equals("")) { + if (!selector.equals("")) { BlackboardAttribute.ATTRIBUTE_TYPE selectorType = BlackboardAttribute.ATTRIBUTE_TYPE.fromLabel(selector); keyword.setType(selectorType); } words.add(keyword); - + } theLists.put(name, list); } From c50076b4208cb47a086670e12371f23dff19a209 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Fri, 26 Sep 2014 11:47:10 -0400 Subject: [PATCH 2/4] Rework initial API of new keyword lists manager class --- .../autopsy/keywordsearch/KeywordListsManager.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordListsManager.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordListsManager.java index 185b71a604..dea9423c7a 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordListsManager.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordListsManager.java @@ -61,12 +61,16 @@ public class KeywordListsManager extends Observable { } /** - * Gets the configured keyword lists. + * Gets the names of the configured keyword lists. * - * @return A collection of keyword list objects. + * @return The name strings. */ - public List getKeywordLists() { - return new ArrayList<>(XmlKeywordSearchList.getCurrent().getListsL()); + public List getKeywordLists() { + List names = new ArrayList<>(); + for (KeywordList list : XmlKeywordSearchList.getCurrent().getListsL()) { + names.add(list.getName()); + } + return names; } } From 9817a2f9a6b0085b4e383319e6d6e3d9f79759c1 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Fri, 26 Sep 2014 11:52:30 -0400 Subject: [PATCH 3/4] Rework initial API of new keyword lists manager class, part 2 --- .../sleuthkit/autopsy/keywordsearch/KeywordListsManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordListsManager.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordListsManager.java index dea9423c7a..b99bc289b7 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordListsManager.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordListsManager.java @@ -65,7 +65,7 @@ public class KeywordListsManager extends Observable { * * @return The name strings. */ - public List getKeywordLists() { + public List getKeywordListNames() { List names = new ArrayList<>(); for (KeywordList list : XmlKeywordSearchList.getCurrent().getListsL()) { names.add(list.getName()); From 0b60ada1bd5310ee765a5b56d9145bde0b730234 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Fri, 26 Sep 2014 12:19:34 -0400 Subject: [PATCH 4/4] Remove commented out code in XmlKeywordSearchList.java --- .../sleuthkit/autopsy/keywordsearch/XmlKeywordSearchList.java | 1 - 1 file changed, 1 deletion(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/XmlKeywordSearchList.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/XmlKeywordSearchList.java index 91b7f82873..2bef2852e9 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/XmlKeywordSearchList.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/XmlKeywordSearchList.java @@ -46,7 +46,6 @@ final class XmlKeywordSearchList extends KeywordSearchList { private static final Logger xmlListslogger = Logger.getLogger(XmlKeywordSearchList.class.getName()); private static final String CUR_LISTS_FILE_NAME = "keywords.xml"; //NON-NLS private static final String CUR_LISTS_FILE = PlatformUtil.getUserConfigDirectory() + File.separator + CUR_LISTS_FILE_NAME; -// private static final String XSDFILE = "KeywordsSchema.xsd"; //NON-NLS private static final String ROOT_EL = "keyword_lists"; //NON-NLS private static final String LIST_EL = "keyword_list"; //NON-NLS private static final String LIST_NAME_ATTR = "name"; //NON-NLS