19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.io.InputStream;
22 import java.io.InputStreamReader;
23 import java.io.Reader;
24 import java.nio.charset.StandardCharsets;
25 import java.util.logging.Level;
26 import org.apache.commons.io.IOUtils;
42 class ArtifactTextExtractor
implements TextExtractor<BlackboardArtifact> {
44 static final private Logger logger = Logger.getLogger(ArtifactTextExtractor.class.getName());
57 static Content getDataSource(BlackboardArtifact artifact)
throws TskCoreException {
61 currentCase = Case.getCurrentCaseThrows();
62 }
catch (NoCurrentCaseException ignore) {
67 SleuthkitCase sleuthkitCase = currentCase.getSleuthkitCase();
68 if (sleuthkitCase == null) {
73 AbstractFile abstractFile = sleuthkitCase.getAbstractFileById(artifact.getObjectID());
74 if (abstractFile != null) {
75 dataSource = abstractFile.getDataSource();
77 dataSource = sleuthkitCase.getContentById(artifact.getObjectID());
80 if (dataSource == null) {
87 public boolean isDisabled() {
92 public void logWarning(
final String msg, Exception ex) {
93 logger.log(Level.WARNING, msg, ex);
96 private InputStream getInputStream(BlackboardArtifact artifact)
throws TextExtractorException {
99 StringBuilder artifactContents =
new StringBuilder();
101 Content dataSource = null;
103 dataSource = getDataSource(artifact);
104 }
catch (TskCoreException tskCoreException) {
105 throw new TextExtractorException(
"Unable to get datasource for artifact: " + artifact.toString(), tskCoreException);
107 if (dataSource == null) {
108 throw new TextExtractorException(
"Datasource was null for artifact: " + artifact.toString());
112 for (BlackboardAttribute attribute : artifact.getAttributes()) {
113 artifactContents.append(attribute.getAttributeType().getDisplayName());
114 artifactContents.append(
" : ");
120 switch (attribute.getValueType()) {
122 artifactContents.append(ContentUtils.getStringTime(attribute.getValueLong(), dataSource));
125 artifactContents.append(attribute.getDisplayString());
127 artifactContents.append(System.lineSeparator());
129 }
catch (TskCoreException tskCoreException) {
130 throw new TextExtractorException(
"Unable to get attributes for artifact: " + artifact.toString(), tskCoreException);
133 return IOUtils.toInputStream(artifactContents, StandardCharsets.UTF_8);
137 public Reader getReader(BlackboardArtifact source)
throws TextExtractorException {
138 return new InputStreamReader(getInputStream(source), StandardCharsets.UTF_8);
142 public long getID(BlackboardArtifact source) {
143 return source.getArtifactID();
147 public String getName(BlackboardArtifact source) {
148 return source.getDisplayName() +
"_" + source.getArtifactID();