23 package org.sleuthkit.autopsy.recentactivity;
25 import java.sql.ResultSet;
26 import java.sql.ResultSetMetaData;
27 import java.sql.SQLException;
29 import java.util.logging.Level;
30 import org.openide.util.NbBundle;
31 import org.openide.util.NbBundle.Messages;
42 abstract class Extract {
44 protected Case currentCase;
45 protected SleuthkitCase tskCase;
46 private final Logger logger = Logger.getLogger(this.getClass().getName());
47 private final ArrayList<String> errorMessages =
new ArrayList<>();
48 String moduleName =
"";
49 boolean dataFound =
false;
54 final void init() throws IngestModuleException {
56 currentCase = Case.getCurrentCaseThrows();
57 tskCase = currentCase.getSleuthkitCase();
58 }
catch (NoCurrentCaseException ex) {
59 throw new IngestModuleException(Bundle.Extract_indexError_message(), ex);
69 void configExtractor() throws IngestModuleException {
72 abstract void process(Content dataSource, IngestJobContext context);
82 List<String> getErrorMessages() {
91 protected void addErrorMessage(String message) {
92 errorMessages.add(message);
107 protected BlackboardArtifact addArtifact(BlackboardArtifact.ARTIFACT_TYPE type, AbstractFile content, Collection<BlackboardAttribute> bbattributes) {
109 BlackboardArtifact bbart = content.newArtifact(type);
110 bbart.addAttributes(bbattributes);
112 this.indexArtifact(bbart);
114 }
catch (TskException ex) {
115 logger.log(Level.SEVERE,
"Error while trying to add an artifact", ex);
125 @Messages({
"Extract.indexError.message=Failed to index artifact for keyword search.",
126 "Extract.noOpenCase.errMsg=No open case available."})
127 void indexArtifact(BlackboardArtifact bbart) {
129 Blackboard blackboard = Case.getCurrentCaseThrows().getServices().getBlackboard();
131 blackboard.indexArtifact(bbart);
132 }
catch (Blackboard.BlackboardException ex) {
133 logger.log(Level.SEVERE,
"Unable to index blackboard artifact " + bbart.getDisplayName(), ex);
134 MessageNotifyUtil.Notify.error(Bundle.Extract_indexError_message(), bbart.getDisplayName());
135 }
catch (NoCurrentCaseException ex) {
136 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
137 MessageNotifyUtil.Notify.error(Bundle.Extract_noOpenCase_errMsg(), bbart.getDisplayName());
152 protected List<HashMap<String, Object>> dbConnect(String path, String query) {
154 List<HashMap<String, Object>> list;
155 String connectionString =
"jdbc:sqlite:" + path;
157 SQLiteDBConnect tempdbconnect =
new SQLiteDBConnect(
"org.sqlite.JDBC", connectionString);
158 temprs = tempdbconnect.executeQry(query);
159 list = this.resultSetToArrayList(temprs);
160 tempdbconnect.closeConnection();
161 }
catch (SQLException ex) {
162 logger.log(Level.SEVERE,
"Error while trying to read into a sqlite db." + connectionString, ex);
163 errorMessages.add(NbBundle.getMessage(
this.getClass(),
"Extract.dbConn.errMsg.failedToQueryDb", getName()));
164 return Collections.<HashMap<String, Object>>emptyList();
176 private List<HashMap<String, Object>> resultSetToArrayList(ResultSet rs)
throws SQLException {
177 ResultSetMetaData md = rs.getMetaData();
178 int columns = md.getColumnCount();
179 List<HashMap<String, Object>> list =
new ArrayList<>(50);
181 HashMap<String, Object> row =
new HashMap<>(columns);
182 for (
int i = 1; i <= columns; ++i) {
183 if (rs.getObject(i) == null) {
184 row.put(md.getColumnName(i),
"");
186 row.put(md.getColumnName(i), rs.getObject(i));
200 protected String getName() {
204 public boolean foundData() {