19 package org.sleuthkit.autopsy.directorytree;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
30 class ExternalViewerRulesManager {
32 private static final String RULES_SETTINGS_NAME =
"ExternalViewerRules";
33 private static final String RULES_SETTINGS_KEY =
"Rules";
34 private static ExternalViewerRulesManager instance;
35 private List<ExternalViewerRule> userRules =
new ArrayList<>();
42 synchronized static ExternalViewerRulesManager getInstance() {
43 if (instance == null) {
44 instance =
new ExternalViewerRulesManager();
45 instance.loadUserDefinedRules();
50 private ExternalViewerRulesManager() {
56 private void loadUserDefinedRules() {
57 String setting = ModuleSettings.getConfigSetting(RULES_SETTINGS_NAME, RULES_SETTINGS_KEY);
58 if (setting != null && !setting.isEmpty()) {
59 List<String> ruleTuples = Arrays.asList(setting.split(
"\\|"));
60 for (String ruleTuple : ruleTuples) {
61 String[] ruleParts = ruleTuple.split(
">");
62 userRules.add(
new ExternalViewerRule(ruleParts[0], ruleParts[1],
63 ExternalViewerRule.RuleType.valueOf(ruleParts[2])));
74 synchronized void setUserRules(List<ExternalViewerRule> rules) {
75 StringBuilder setting =
new StringBuilder();
76 for (ExternalViewerRule rule : rules) {
77 if (setting.length() != 0) {
80 setting.append(rule.getName()).append(
">");
81 setting.append(rule.getExePath()).append(
">");
82 setting.append(rule.getRuleType().name());
84 ModuleSettings.setConfigSetting(RULES_SETTINGS_NAME, RULES_SETTINGS_KEY, setting.toString());
85 userRules =
new ArrayList<>(rules);
91 synchronized List<ExternalViewerRule> getUserRules() {
93 return new ArrayList<>(userRules);
102 synchronized String getExePathForName(String name) {
103 for (ExternalViewerRule rule : userRules) {
104 if (rule.getName().equals(name)) {
105 return rule.getExePath();