6 package org.sleuthkit.autopsy.casemodule.services;
8 import com.google.gson.Gson;
10 import java.io.FileWriter;
11 import java.io.IOException;
12 import java.nio.file.Path;
13 import java.nio.file.Paths;
14 import java.util.ArrayList;
15 import java.util.Collections;
16 import java.util.List;
17 import javax.annotation.concurrent.Immutable;
18 import java.io.FileFilter;
19 import java.io.FileReader;
35 if (name == null || name.isEmpty()) {
36 throw new IllegalArgumentException(
"Invalid parameter passed to TagSetDefinition constructor. TagSet name was null or empty.");
39 if (tagNameDefinitionList == null || tagNameDefinitionList.isEmpty()) {
40 throw new IllegalArgumentException(
"Invalid parameter passed to TagSetDefinition constructor. TagNameDefinition list was null or empty.");
62 return Collections.unmodifiableList(tagNameDefinitionList);
73 static synchronized void writeTagSetDefinition(
TagSetDefinition tagSetDefinition)
throws IOException {
75 File dir = TAGS_USER_CONFIG_DIR.toFile();
80 File file = Paths.get(TAGS_USER_CONFIG_DIR.toString(), tagSetDefinition.getFileName()).toFile();
85 try (FileWriter writer =
new FileWriter(file)) {
86 (
new Gson()).toJson(tagSetDefinition, writer);
96 static synchronized List<TagSetDefinition> readTagSetDefinitions() throws IOException {
97 List<TagSetDefinition> tagSetList =
new ArrayList<>();
98 File dir = TAGS_USER_CONFIG_DIR.toFile();
104 File[] fileList = dir.listFiles(
new TagSetJsonFileFilter());
105 Gson gson =
new Gson();
106 for (File file : fileList) {
107 try (FileReader reader =
new FileReader(file)) {
121 return String.format(FILE_NAME_TEMPLATE, name.replace(
" ",
"-"));
131 return file.getName().endsWith(
"tag-set.json");
boolean accept(File file)
static final String FILE_NAME_TEMPLATE
List< TagNameDefinition > getTagNameDefinitions()
TagSetDefinition(String name, List< TagNameDefinition > tagNameDefinitionList)
static final Path TAGS_USER_CONFIG_DIR
final List< TagNameDefinition > tagNameDefinitionList