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;
 
   41 class ArtifactTextExtractor 
implements TextExtractor<BlackboardArtifact> {
 
   43     static final private Logger logger = Logger.getLogger(ArtifactTextExtractor.class.getName());
 
   56     static Content getDataSource(BlackboardArtifact artifact) 
throws TskCoreException {
 
   60             currentCase = Case.getCurrentCase();
 
   61         } 
catch (IllegalStateException ignore) {
 
   66         SleuthkitCase sleuthkitCase = currentCase.getSleuthkitCase();
 
   67         if (sleuthkitCase == null) {
 
   72         AbstractFile abstractFile = sleuthkitCase.getAbstractFileById(artifact.getObjectID());
 
   73         if (abstractFile != null) {
 
   74             dataSource = abstractFile.getDataSource();
 
   76             dataSource = sleuthkitCase.getContentById(artifact.getObjectID());
 
   79         if (dataSource == null) {
 
   86     public boolean isDisabled() {
 
   91     public void logWarning(
final String msg, Exception ex) {
 
   92         logger.log(Level.WARNING, msg, ex); 
 
   95     private InputStream getInputStream(BlackboardArtifact artifact) 
throws TextExtractorException {
 
   98         StringBuilder artifactContents = 
new StringBuilder();
 
  100         Content dataSource = null;
 
  102             dataSource = getDataSource(artifact);
 
  103         } 
catch (TskCoreException tskCoreException) {
 
  104             throw new TextExtractorException(
"Unable to get datasource for artifact: " + artifact.toString(), tskCoreException);
 
  106         if (dataSource == null) {
 
  107             throw new TextExtractorException(
"Datasource was null for artifact: " + artifact.toString());
 
  111             for (BlackboardAttribute attribute : artifact.getAttributes()) {
 
  112                 artifactContents.append(attribute.getAttributeType().getDisplayName());
 
  113                 artifactContents.append(
" : ");
 
  119                 switch (attribute.getValueType()) {
 
  121                         artifactContents.append(ContentUtils.getStringTime(attribute.getValueLong(), dataSource));
 
  124                         artifactContents.append(attribute.getDisplayString());
 
  126                 artifactContents.append(System.lineSeparator());
 
  128         } 
catch (TskCoreException tskCoreException) {
 
  129             throw new TextExtractorException(
"Unable to get attributes for artifact: " + artifact.toString(), tskCoreException);
 
  132         return IOUtils.toInputStream(artifactContents, StandardCharsets.UTF_8);
 
  136     public Reader getReader(BlackboardArtifact source) 
throws TextExtractorException {
 
  137         return new InputStreamReader(getInputStream(source), StandardCharsets.UTF_8);
 
  141     public long getID(BlackboardArtifact source) {
 
  142         return source.getArtifactID();
 
  146     public String getName(BlackboardArtifact source) {
 
  147         return source.getDisplayName() + 
"_" + source.getArtifactID();