19 package org.sleuthkit.autopsy.report.modules.datasourcesummaryexport;
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;
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"
50 final class ExportRecentFiles {
52 private final RecentFilesSummary recentSummary;
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());
57 private static final List<ColumnModel<RecentFileDetails, DefaultCellModel<?>>> docsTemplate = Arrays.asList(
58 new ColumnModel<>(Bundle.ExportRecentFiles_col_header_path(),
60 return new DefaultCellModel<>(prog.getPath());
62 new ColumnModel<>(Bundle.ExportRecentFiles_col_head_date(),
66 private static final List<ColumnModel<RecentDownloadDetails, DefaultCellModel<?>>> downloadsTemplate = Arrays.asList(
67 new ColumnModel<>(Bundle.ExportRecentFiles_col_header_domain(),
69 return new DefaultCellModel<>(prog.getWebDomain());
71 new ColumnModel<>(Bundle.ExportRecentFiles_col_header_path(),
73 return new DefaultCellModel<>(prog.getPath());
75 new ColumnModel<>(Bundle.ExportRecentFiles_col_head_date(),
79 private static final List<ColumnModel<RecentAttachmentDetails, DefaultCellModel<?>>> attachmentsTemplate = Arrays.asList(
80 new ColumnModel<>(Bundle.ExportRecentFiles_col_header_path(),
82 return new DefaultCellModel<>(prog.getPath());
84 new ColumnModel<>(Bundle.ExportRecentFiles_col_head_date(),
87 new ColumnModel<>(Bundle.ExportRecentFiles_col_header_sender(),
89 return new DefaultCellModel<>(prog.getSender());
93 recentSummary =
new RecentFilesSummary();
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);
110 List<ExcelExport.ExcelSheetExport> getExports(DataSource dataSource) {
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);
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());