Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExportRecentFiles.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2021 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.report.modules.datasourcesummaryexport;
20 
21 import java.text.DateFormat;
22 import java.text.SimpleDateFormat;
23 import java.util.Arrays;
24 import java.util.Date;
25 import java.util.List;
26 import java.util.Locale;
27 import java.util.function.Function;
28 import java.util.stream.Collectors;
29 import java.util.stream.Stream;
30 import org.openide.util.NbBundle.Messages;
36 import org.sleuthkit.datamodel.DataSource;
37 
41 @Messages({
42  "ExportRecentFiles_docsTable_tabName=Recently Opened Documents",
43  "ExportRecentFiles_downloadsTable_tabName=Recent Downloads",
44  "ExportRecentFiles_attachmentsTable_tabName=Recent Attachments",
45  "ExportRecentFiles_col_head_date=Date",
46  "ExportRecentFiles_col_header_domain=Domain",
47  "ExportRecentFiles_col_header_path=Path",
48  "ExportRecentFiles_col_header_sender=Sender"
49 })
50 final class ExportRecentFiles {
51 
52  private final RecentFilesSummary recentSummary;
53 
54  private static final String DATETIME_FORMAT_STR = "yyyy/MM/dd HH:mm:ss";
55  private static final DateFormat DATETIME_FORMAT = new SimpleDateFormat(DATETIME_FORMAT_STR, Locale.getDefault());
56 
57  private static final List<ColumnModel<RecentFileDetails, DefaultCellModel<?>>> docsTemplate = Arrays.asList(
58  new ColumnModel<>(Bundle.ExportRecentFiles_col_header_path(),
59  (prog) -> {
60  return new DefaultCellModel<>(prog.getPath());
61  }, 250),
62  new ColumnModel<>(Bundle.ExportRecentFiles_col_head_date(),
63  getDateFunct(),
64  80));
65 
66  private static final List<ColumnModel<RecentDownloadDetails, DefaultCellModel<?>>> downloadsTemplate = Arrays.asList(
67  new ColumnModel<>(Bundle.ExportRecentFiles_col_header_domain(),
68  (prog) -> {
69  return new DefaultCellModel<>(prog.getWebDomain());
70  }, 100),
71  new ColumnModel<>(Bundle.ExportRecentFiles_col_header_path(),
72  (prog) -> {
73  return new DefaultCellModel<>(prog.getPath());
74  }, 250),
75  new ColumnModel<>(Bundle.ExportRecentFiles_col_head_date(),
76  getDateFunct(),
77  80));
78 
79  private static final List<ColumnModel<RecentAttachmentDetails, DefaultCellModel<?>>> attachmentsTemplate = Arrays.asList(
80  new ColumnModel<>(Bundle.ExportRecentFiles_col_header_path(),
81  (prog) -> {
82  return new DefaultCellModel<>(prog.getPath());
83  }, 250),
84  new ColumnModel<>(Bundle.ExportRecentFiles_col_head_date(),
85  getDateFunct(),
86  80),
87  new ColumnModel<>(Bundle.ExportRecentFiles_col_header_sender(),
88  (prog) -> {
89  return new DefaultCellModel<>(prog.getSender());
90  }, 150));
91 
92  ExportRecentFiles() {
93  recentSummary = new RecentFilesSummary();
94  }
95 
103  private static <T extends RecentFileDetails> Function<T, DefaultCellModel<?>> getDateFunct() {
104  return (T lastAccessed) -> {
105  Function<Date, String> dateParser = (dt) -> dt == null ? "" : DATETIME_FORMAT.format(dt);
106  return new DefaultCellModel<>(new Date(lastAccessed.getDateAsLong() * 1000), dateParser, DATETIME_FORMAT_STR);
107  };
108  }
109 
110  List<ExcelExport.ExcelSheetExport> getExports(DataSource dataSource) {
111 
112  DataFetcher<DataSource, List<RecentFileDetails>> docsFetcher = (ds) -> recentSummary.getRecentlyOpenedDocuments(ds, 10);
113  DataFetcher<DataSource, List<RecentDownloadDetails>> downloadsFetcher = (ds) -> recentSummary.getRecentDownloads(ds, 10);
114  DataFetcher<DataSource, List<RecentAttachmentDetails>> attachmentsFetcher = (ds) -> recentSummary.getRecentAttachments(ds, 10);
115 
116  return Stream.of(
117  ExcelExportAction.getTableExport(docsFetcher, docsTemplate, Bundle.ExportRecentFiles_docsTable_tabName(), dataSource),
118  ExcelExportAction.getTableExport(downloadsFetcher, downloadsTemplate, Bundle.ExportRecentFiles_downloadsTable_tabName(), dataSource),
119  ExcelExportAction.getTableExport(attachmentsFetcher, attachmentsTemplate, Bundle.ExportRecentFiles_attachmentsTable_tabName(), dataSource))
120  .filter(sheet -> sheet != null)
121  .collect(Collectors.toList());
122  }
123 }

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.