19 package org.sleuthkit.autopsy.datasourceprocessors.xry;
21 import java.io.IOException;
22 import java.nio.file.Path;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.logging.Level;
34 abstract class AbstractSingleEntityParser
implements XRYFileParser {
38 protected static final String PARSER_NAME =
"XRY DSP";
41 public void parse(XRYFileReader reader, Content parent)
throws IOException, TskCoreException {
42 Path reportPath = reader.getReportPath();
43 logger.log(Level.INFO, String.format(
"[XRY DSP] Processing report at [ %s ]", reportPath.toString()));
45 while (reader.hasNextEntity()) {
46 String xryEntity = reader.nextEntity();
47 String[] xryLines = xryEntity.split(
"\n");
49 List<XRYKeyValuePair> keyValuePairs =
new ArrayList<>();
52 logger.log(Level.INFO, String.format(
"[XRY DSP] Processing [ %s ]", xryLines[0]));
54 String
namespace = "";
56 for (
int i = 1; i < xryLines.length; i++) {
57 String xryLine = xryLines[i];
59 String candidateNamespace = xryLine.trim();
62 if (isNamespace(candidateNamespace)) {
63 namespace = candidateNamespace;
68 if(!XRYKeyValuePair.isPair(xryLine)) {
69 logger.log(Level.WARNING, String.format(
"[XRY DSP] Expected a key value "
70 +
"pair on this line (in brackets) [ %s ], but one was not detected.",
75 XRYKeyValuePair pair = XRYKeyValuePair.from(xryLine,
namespace);
78 if (!canProcess(pair)) {
79 logger.log(Level.WARNING, String.format(
"[XRY DSP] The following key, "
80 +
"value pair (in brackets) [ %s ] was not recognized. Discarding...",
86 if (pair.getValue().isEmpty()) {
87 logger.log(Level.WARNING, String.format(
"[XRY DSP] The following key value pair"
88 +
"(in brackets) [ %s ] was recognized, but the value was empty. Discarding...",
93 keyValuePairs.add(pair);
96 if(!keyValuePairs.isEmpty()) {
97 makeArtifact(keyValuePairs, parent);
106 abstract boolean canProcess(XRYKeyValuePair pair);
123 abstract boolean isNamespace(String nameSpace);
128 abstract void makeArtifact(List<XRYKeyValuePair> keyValuePairs, Content parent)
throws TskCoreException;
synchronized static Logger getLogger(String name)