mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-13 00:16:16 +00:00
Merge pull request #898 from rcordovano/keyword_search_manager
Cretae keyword lists manager
This commit is contained in:
commit
1be3b2bc13
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Autopsy Forensic Browser
|
||||||
|
*
|
||||||
|
* Copyright 2014 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;
|
||||||
|
|
||||||
|
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 names of the configured keyword lists.
|
||||||
|
*
|
||||||
|
* @return The name strings.
|
||||||
|
*/
|
||||||
|
public List<String> getKeywordListNames() {
|
||||||
|
List<String> names = new ArrayList<>();
|
||||||
|
for (KeywordList list : XmlKeywordSearchList.getCurrent().getListsL()) {
|
||||||
|
names.add(list.getName());
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -38,15 +38,14 @@ import org.w3c.dom.Element;
|
|||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages reading and writing of keyword lists to user settings XML file keywords.xml
|
* Manages reading and writing of keyword lists to user settings XML file
|
||||||
* or to any file provided in constructor
|
* 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 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_NAME = "keywords.xml"; //NON-NLS
|
||||||
private static String CUR_LISTS_FILE = PlatformUtil.getUserConfigDirectory() + File.separator + CUR_LISTS_FILE_NAME;
|
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 ROOT_EL = "keyword_lists"; //NON-NLS
|
||||||
private static final String LIST_EL = "keyword_list"; //NON-NLS
|
private static final String LIST_EL = "keyword_list"; //NON-NLS
|
||||||
private static final String LIST_NAME_ATTR = "name"; //NON-NLS
|
private static final String LIST_NAME_ATTR = "name"; //NON-NLS
|
||||||
@ -60,7 +59,7 @@ public final class XmlKeywordSearchList extends KeywordSearchList {
|
|||||||
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; //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 final String ENCODING = "UTF-8"; //NON-NLS
|
||||||
private static XmlKeywordSearchList currentInstance = null;
|
private static XmlKeywordSearchList currentInstance = null;
|
||||||
private DateFormat dateFormatter;
|
private final DateFormat dateFormatter;
|
||||||
|
|
||||||
static synchronized XmlKeywordSearchList getCurrent() {
|
static synchronized XmlKeywordSearchList getCurrent() {
|
||||||
if (currentInstance == null) {
|
if (currentInstance == null) {
|
||||||
@ -71,8 +70,9 @@ public final class XmlKeywordSearchList extends KeywordSearchList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor to obtain handle on other that the current keyword list
|
* Constructor to obtain handle on other that the current keyword list (such
|
||||||
* (such as for import or export)
|
* as for import or export)
|
||||||
|
*
|
||||||
* @param xmlFile xmlFile to obtain XmlKeywordSearchList handle on
|
* @param xmlFile xmlFile to obtain XmlKeywordSearchList handle on
|
||||||
*/
|
*/
|
||||||
XmlKeywordSearchList(String xmlFile) {
|
XmlKeywordSearchList(String xmlFile) {
|
||||||
@ -172,15 +172,13 @@ public final class XmlKeywordSearchList extends KeywordSearchList {
|
|||||||
|
|
||||||
if (listEl.hasAttribute(LIST_USE_FOR_INGEST)) {
|
if (listEl.hasAttribute(LIST_USE_FOR_INGEST)) {
|
||||||
useForIngestBool = Boolean.parseBoolean(listEl.getAttribute(LIST_USE_FOR_INGEST));
|
useForIngestBool = Boolean.parseBoolean(listEl.getAttribute(LIST_USE_FOR_INGEST));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
useForIngestBool = true;
|
useForIngestBool = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listEl.hasAttribute(LIST_INGEST_MSGS)) {
|
if (listEl.hasAttribute(LIST_INGEST_MSGS)) {
|
||||||
ingestMessagesBool = Boolean.parseBoolean(listEl.getAttribute(LIST_INGEST_MSGS));
|
ingestMessagesBool = Boolean.parseBoolean(listEl.getAttribute(LIST_INGEST_MSGS));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ingestMessagesBool = true;
|
ingestMessagesBool = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user