19package org.sleuthkit.autopsy.report.modules.datasourcesummaryexport;
21import java.util.Collections;
23import java.util.Optional;
24import org.apache.poi.ss.usermodel.Row;
25import org.apache.poi.ss.usermodel.Sheet;
26import org.sleuthkit.autopsy.report.modules.datasourcesummaryexport.ExcelExport.ExcelExportException;
37 static class ItemDimensions {
39 private final int rowStart;
40 private final int rowEnd;
41 private final int colStart;
42 private final int colEnd;
52 ItemDimensions(
int rowStart,
int colStart,
int rowEnd,
int colEnd) {
53 this.rowStart = rowStart;
54 this.colStart = colStart;
103 ItemDimensions
write(Sheet sheet,
int rowStart,
int colStart, ExcelExport.WorksheetEnv env)
throws ExcelExportException;
118 SingleCellExportable(String key) {
119 this(
new DefaultCellModel<>(key));
132 public ItemDimensions write(Sheet sheet,
int rowStart,
int colStart, ExcelExport.WorksheetEnv env)
throws ExcelExportException {
133 Row row = sheet.createRow(rowStart);
134 ExcelExport.createCell(env, row, colStart, item, Optional.empty());
135 return new ItemDimensions(rowStart, colStart, rowStart, colStart);
143 static class KeyValueItemExportable
implements ExcelItemExportable {
145 private final CellModel key;
146 private final CellModel value;
154 KeyValueItemExportable(String key, CellModel value) {
155 this(
new DefaultCellModel<>(key), value);
164 KeyValueItemExportable(CellModel key, CellModel value) {
170 public ItemDimensions write(Sheet sheet,
int rowStart,
int colStart, ExcelExport.WorksheetEnv env)
throws ExcelExportException {
171 Row row = sheet.createRow(rowStart);
172 ExcelExport.createCell(env, row, colStart, key, Optional.of(env.getHeaderStyle()));
173 ExcelExport.createCell(env, row, colStart + 1, value, Optional.empty());
174 return new ItemDimensions(rowStart, colStart, rowStart, colStart + 1);
191 private static final int DEFAULT_INDENT = 1;
193 private final String title;
194 private final List<? extends ExcelItemExportable> children;
202 TitledExportable(String title, List<? extends ExcelItemExportable> children) {
204 this.children = children;
208 public ItemDimensions write(Sheet sheet,
int rowStart,
int colStart, ExcelExport.WorksheetEnv env)
throws ExcelExportException {
209 ExcelExport.createCell(env, sheet.createRow(rowStart), colStart,
new DefaultCellModel<>(title), Optional.of(env.getHeaderStyle()));
210 int curRow = rowStart + 1;
211 int maxCol = colStart;
212 for (ExcelItemExportable export : children) {
213 if (export ==
null) {
217 ItemDimensions thisItemDim = export.write(sheet, curRow, colStart + DEFAULT_INDENT, env);
218 curRow = thisItemDim.getRowEnd() + 1;
219 maxCol = Math.max(thisItemDim.getColEnd(), maxCol);
222 return new ItemDimensions(rowStart, colStart, curRow - 1, maxCol);
226 private final String sheetName;
227 private final List<ExcelItemExportable> exports;
235 ExcelSpecialFormatExport(String sheetName, List<ExcelItemExportable> exports) {
236 this.sheetName = sheetName;
237 this.exports = exports ==
null ? Collections.emptyList() : exports;
246 public void renderSheet(Sheet sheet, ExcelExport.WorksheetEnv env)
throws ExcelExportException {
250 if (export ==
null) {
254 ItemDimensions dimensions = export.write(sheet, rowStart, 0, env);
255 rowStart = dimensions.getRowEnd() + 1;
256 maxCol = Math.max(maxCol, dimensions.getColEnd());
260 for (
int i = 0; i <= maxCol; i++) {
261 sheet.autoSizeColumn(i);
ItemDimensions write(Sheet sheet, int rowStart, int colStart, ExcelExport.WorksheetEnv env)