23 package org.sleuthkit.autopsy.recentactivity;
26 import java.sql.ResultSet;
27 import java.sql.ResultSetMetaData;
28 import java.sql.SQLException;
30 import java.util.logging.Level;
32 import org.openide.util.NbBundle;
41 abstract class Extract {
43 protected Case currentCase = Case.getCurrentCase();
44 protected SleuthkitCase tskCase = currentCase.getSleuthkitCase();
45 private final Logger logger = Logger.getLogger(this.getClass().getName());
46 private final ArrayList<String> errorMessages =
new ArrayList<>();
47 String moduleName =
"";
48 boolean dataFound =
false;
53 void init() throws IngestModuleException {
56 abstract void process(Content dataSource, IngestJobContext context);
66 List<String> getErrorMessages() {
75 protected void addErrorMessage(String message) {
76 errorMessages.add(message);
90 protected void addArtifact(BlackboardArtifact.ARTIFACT_TYPE type, AbstractFile content, Collection<BlackboardAttribute> bbattributes) {
92 BlackboardArtifact bbart = content.newArtifact(type);
93 bbart.addAttributes(bbattributes);
95 this.indexArtifact(bbart);
96 }
catch (TskException ex) {
97 logger.log(Level.SEVERE,
"Error while trying to add an artifact", ex);
106 void indexArtifact(BlackboardArtifact bbart) {
107 Blackboard blackboard = Case.getCurrentCase().getServices().getBlackboard();
110 blackboard.indexArtifact(bbart);
111 }
catch (Blackboard.BlackboardException ex) {
112 logger.log(Level.SEVERE, NbBundle.getMessage(Blackboard.class,
"Blackboard.unableToIndexArtifact.error.msg", bbart.getDisplayName()), ex);
113 MessageNotifyUtil.Notify.error(
114 NbBundle.getMessage(Blackboard.class,
"Blackboard.unableToIndexArtifact.exception.msg"), bbart.getDisplayName());
129 protected List<HashMap<String, Object>> dbConnect(String path, String query) {
131 List<HashMap<String, Object>> list;
132 String connectionString =
"jdbc:sqlite:" + path;
134 SQLiteDBConnect tempdbconnect =
new SQLiteDBConnect(
"org.sqlite.JDBC", connectionString);
135 temprs = tempdbconnect.executeQry(query);
136 list = this.resultSetToArrayList(temprs);
137 tempdbconnect.closeConnection();
138 }
catch (SQLException ex) {
139 logger.log(Level.SEVERE,
"Error while trying to read into a sqlite db." + connectionString, ex);
140 errorMessages.add(NbBundle.getMessage(
this.getClass(),
"Extract.dbConn.errMsg.failedToQueryDb", getName()));
141 return Collections.<HashMap<String, Object>>emptyList();
153 private List<HashMap<String, Object>> resultSetToArrayList(ResultSet rs)
throws SQLException {
154 ResultSetMetaData md = rs.getMetaData();
155 int columns = md.getColumnCount();
156 List<HashMap<String, Object>> list =
new ArrayList<>(50);
158 HashMap<String, Object> row =
new HashMap<>(columns);
159 for (
int i = 1; i <= columns; ++i) {
160 if (rs.getObject(i) == null) {
161 row.put(md.getColumnName(i),
"");
163 row.put(md.getColumnName(i), rs.getObject(i));
177 protected String getName() {
181 public boolean foundData() {