Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
SQLiteTableRowFactory.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018 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.contentviewers;
20 
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Objects;
26 import javax.swing.Action;
27 import org.openide.nodes.AbstractNode;
28 import org.openide.nodes.ChildFactory;
29 import org.openide.nodes.Children;
30 import org.openide.nodes.Node;
31 import org.openide.nodes.Sheet;
33 
38 class SQLiteTableRowFactory extends ChildFactory<Integer> {
39 
40  private final List<Map<String, Object>> rows;
41  private final List<Action> colActions;
42 
43  SQLiteTableRowFactory(List<Map<String, Object>> rows, List<Action> actions ) {
44  this.rows = rows;
45  this.colActions = actions;
46  }
47 
48  @Override
49  protected boolean createKeys(List<Integer> keys) {
50  if (rows != null) {
51  for (int i = 0; i < rows.size(); i++) {
52  keys.add(i);
53  }
54  }
55  return true;
56  }
57 
58  @Override
59  protected Node createNodeForKey(Integer key) {
60  if (Objects.isNull(rows) || rows.isEmpty() || key >= rows.size()) {
61  return null;
62  }
63 
64  return new SQLiteTableRowNode(rows.get(key), this.colActions );
65  }
66 
67 }
68 
73 class SQLiteTableRowNode extends AbstractNode {
74 
75  private final Map<String, Object> row;
76  private final List<Action> nodeActions;
77 
78  SQLiteTableRowNode(Map<String, Object> row, List<Action> actions) {
79  super(Children.LEAF);
80  this.row = row;
81  this.nodeActions = actions;
82  }
83 
84  @Override
85  protected Sheet createSheet() {
86 
87  Sheet sheet = super.createSheet();
88  Sheet.Set properties = sheet.get(Sheet.PROPERTIES);
89  if (properties == null) {
90  properties = Sheet.createPropertiesSet();
91  sheet.put(properties);
92  }
93 
94  for (Map.Entry<String, Object> col : row.entrySet()) {
95  String colName = col.getKey();
96  String colVal = col.getValue().toString();
97  properties.put(new NodeProperty<>(colName, colName, colName, colVal)); // NON-NLS
98  }
99 
100  return sheet;
101  }
102 
103  @Override
104  public Action[] getActions(boolean context) {
105  List<Action> actions = new ArrayList<>();
106 
107  actions.addAll(nodeActions);
108  actions.add(null);
109  actions.addAll(Arrays.asList(super.getActions(context)));
110 
111  return actions.toArray(new Action[actions.size()]);
112  }
113 
114 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Jun 27 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.