Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
TextReaders.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018-2018 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.textreaders;
20 
21 import java.io.Reader;
22 import java.util.Arrays;
23 import java.util.List;
24 import org.openide.util.Lookup;
26 import org.sleuthkit.datamodel.AbstractFile;
27 import org.sleuthkit.datamodel.BlackboardArtifact;
28 import org.sleuthkit.datamodel.Content;
29 import org.sleuthkit.datamodel.Report;
30 
39 public class TextReaders {
40 
59  public static Reader getReader(Content content,
60  Lookup context) throws NoTextReaderFound {
61  try {
62  if (content instanceof AbstractFile) {
63  String mimeType = ((AbstractFile) content).getMIMEType();
64  List<TextExtractor> extractors = Arrays.asList(
65  new HtmlTextExtractor(content),
66  new SqliteTextExtractor(content),
67  new TikaTextExtractor(content));
68  for (TextExtractor extractor : extractors) {
69  extractor.setExtractionSettings(context);
70  if (extractor.isEnabled() && extractor.isSupported(content, mimeType)) {
71  return extractor.getReader();
72  }
73  }
74  } else if (content instanceof BlackboardArtifact) {
75  TextExtractor artifactExtractor = new ArtifactTextExtractor((BlackboardArtifact) content);
76  artifactExtractor.setExtractionSettings(context);
77  return artifactExtractor.getReader();
78  } else if (content instanceof Report) {
79  TextExtractor reportExtractor = new TikaTextExtractor(content);
80  reportExtractor.setExtractionSettings(context);
81  return reportExtractor.getReader();
82  }
83  } catch (ExtractionException ex) {
84  throw new NoTextReaderFound("Error while getting reader", ex);
85  }
86 
87  throw new NoTextReaderFound(
88  String.format("Could not find a suitable reader for "
89  + "content with name [%s] and id=[%d]. Try using "
90  + "the default reader instead.",
91  content.getName(), content.getId())
92  );
93  }
94 
107  public static Reader getReader(Content content)
108  throws NoTextReaderFound {
109  return TextReaders.getReader(content, null);
110  }
111 
128  public static Reader getStringsReader(Content content, Lookup context) {
129  StringsTextExtractor stringsInstance = new StringsTextExtractor(content);
130  stringsInstance.setExtractionSettings(context);
131  return stringsInstance.getReader();
132  }
133 
138  public static class NoTextReaderFound extends Exception {
139 
140  public NoTextReaderFound(String msg) {
141  super(msg);
142  }
143 
144  public NoTextReaderFound(Throwable ex) {
145  super(ex);
146  }
147 
148  private NoTextReaderFound(String msg, Throwable ex) {
149  super(msg, ex);
150  }
151  }
152 }
static Reader getStringsReader(Content content, Lookup context)
static Reader getReader(Content content, Lookup context)
static Reader getReader(Content content)

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