Autopsy  4.7.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExternalViewerRulesManager.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.directorytree;
20 
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
25 
30 class ExternalViewerRulesManager {
31 
32  private static final String RULES_SETTINGS_NAME = "ExternalViewerRules"; //NON-NLS
33  private static final String RULES_SETTINGS_KEY = "Rules"; //NON-NLS
34  private static ExternalViewerRulesManager instance;
35  private List<ExternalViewerRule> userRules = new ArrayList<>();
36 
42  synchronized static ExternalViewerRulesManager getInstance() {
43  if (instance == null) {
44  instance = new ExternalViewerRulesManager();
45  instance.loadUserDefinedRules();
46  }
47  return instance;
48  }
49 
50  private ExternalViewerRulesManager() {
51  }
52 
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])));
64  }
65  }
66  }
67 
74  synchronized void setUserRules(List<ExternalViewerRule> rules) {
75  StringBuilder setting = new StringBuilder();
76  for (ExternalViewerRule rule : rules) {
77  if (setting.length() != 0) {
78  setting.append("|");
79  }
80  setting.append(rule.getName()).append(">");
81  setting.append(rule.getExePath()).append(">");
82  setting.append(rule.getRuleType().name());
83  }
84  ModuleSettings.setConfigSetting(RULES_SETTINGS_NAME, RULES_SETTINGS_KEY, setting.toString());
85  userRules = new ArrayList<>(rules);
86  }
87 
91  synchronized List<ExternalViewerRule> getUserRules() {
92  // ExternalViewerRule objects are immutable
93  return new ArrayList<>(userRules);
94  }
95 
102  synchronized String getExePathForName(String name) {
103  for (ExternalViewerRule rule : userRules) {
104  if (rule.getName().equals(name)) {
105  return rule.getExePath();
106  }
107  }
108  return "";
109  }
110 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.