Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
TagNameDefiniton.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.casemodule.services;
20 
21 import java.util.Arrays;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Objects;
25 import java.util.Set;
26 import javax.annotation.concurrent.Immutable;
28 import org.sleuthkit.datamodel.TagName;
29 
33 @Immutable
34 final class TagNameDefiniton implements Comparable<TagNameDefiniton> {
35 
36  private static final String TAGS_SETTINGS_NAME = "Tags"; //NON-NLS
37  private static final String TAG_NAMES_SETTING_KEY = "TagNames"; //NON-NLS
38  private final String displayName;
39  private final String description;
40  private final TagName.HTML_COLOR color;
41 
50  TagNameDefiniton(String displayName, String description, TagName.HTML_COLOR color) {
51  this.displayName = displayName;
52  this.description = description;
53  this.color = color;
54  }
55 
61  String getDisplayName() {
62  return displayName;
63  }
64 
70  String getDescription() {
71  return description;
72  }
73 
79  TagName.HTML_COLOR getColor() {
80  return color;
81  }
82 
94  @Override
95  public int compareTo(TagNameDefiniton other) {
96  return this.getDisplayName().toLowerCase().compareTo(other.getDisplayName().toLowerCase());
97  }
98 
104  @Override
105  public int hashCode() {
106  int hash = 7;
107  hash = 83 * hash + Objects.hashCode(this.displayName);
108  return hash;
109  }
110 
119  @Override
120  public boolean equals(Object obj) {
121  if (!(obj instanceof TagNameDefiniton)) {
122  return false;
123  }
124  TagNameDefiniton thatTagName = (TagNameDefiniton) obj;
125  return this.getDisplayName().equals(thatTagName.getDisplayName());
126  }
127 
133  @Override
134  public String toString() {
135  return displayName;
136  }
137 
142  private String toSettingsFormat() {
143  return displayName + "," + description + "," + color.name();
144  }
145 
151  static synchronized Set<TagNameDefiniton> getTagNameDefinitions() {
152  Set<TagNameDefiniton> tagNames = new HashSet<>();
153  String setting = ModuleSettings.getConfigSetting(TAGS_SETTINGS_NAME, TAG_NAMES_SETTING_KEY);
154  if (null != setting && !setting.isEmpty()) {
155  List<String> tagNameTuples = Arrays.asList(setting.split(";"));
156  for (String tagNameTuple : tagNameTuples) {
157  String[] tagNameAttributes = tagNameTuple.split(",");
158  tagNames.add(new TagNameDefiniton(tagNameAttributes[0], tagNameAttributes[1], TagName.HTML_COLOR.valueOf(tagNameAttributes[2])));
159  }
160  }
161  return tagNames;
162  }
163 
169  static synchronized void setTagNameDefinitions(Set<TagNameDefiniton> tagNames) {
170  StringBuilder setting = new StringBuilder();
171  for (TagNameDefiniton tagName : tagNames) {
172  if (setting.length() != 0) {
173  setting.append(";");
174  }
175  setting.append(tagName.toSettingsFormat());
176  }
177  ModuleSettings.setConfigSetting(TAGS_SETTINGS_NAME, TAG_NAMES_SETTING_KEY, setting.toString());
178  }
179 
180 }

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.