Autopsy  4.6.0
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 
37 public class SQLiteTableRowFactory extends ChildFactory<Integer> {
38 
39  private final List<Map<String, Object>> rows;
40  private final List<Action> colActions;
41 
42  SQLiteTableRowFactory(List<Map<String, Object>> rows, List<Action> actions ) {
43  this.rows = rows;
44  this.colActions = actions;
45  }
46 
47  @Override
48  protected boolean createKeys(List<Integer> keys) {
49  if (rows != null) {
50  for (int i = 0; i < rows.size(); i++) {
51  keys.add(i);
52  }
53  }
54  return true;
55  }
56 
57  @Override
58  protected Node createNodeForKey(Integer key) {
59  if (Objects.isNull(rows) || rows.isEmpty() || key >= rows.size()) {
60  return null;
61  }
62 
63  return new SQLiteTableRowNode(rows.get(key), this.colActions );
64  }
65 
66 }
67 
72 class SQLiteTableRowNode extends AbstractNode {
73 
74  private final Map<String, Object> row;
75  private final List<Action> nodeActions;
76 
77  SQLiteTableRowNode(Map<String, Object> row, List<Action> actions) {
78  super(Children.LEAF);
79  this.row = row;
80  this.nodeActions = actions;
81  }
82 
83  @Override
84  protected Sheet createSheet() {
85 
86  Sheet sheet = super.createSheet();
87  Sheet.Set properties = sheet.get(Sheet.PROPERTIES);
88  if (properties == null) {
89  properties = Sheet.createPropertiesSet();
90  sheet.put(properties);
91  }
92 
93  for (Map.Entry<String, Object> col : row.entrySet()) {
94  String colName = col.getKey();
95  String colVal = col.getValue().toString();
96  properties.put(new NodeProperty<>(colName, colName, colName, colVal)); // NON-NLS
97  }
98 
99  return sheet;
100  }
101 
102  @Override
103  public Action[] getActions(boolean context) {
104  List<Action> actions = new ArrayList<>();
105 
106  actions.addAll(Arrays.asList(super.getActions(context)));
107  actions.addAll(nodeActions);
108 
109  return actions.toArray(new Action[actions.size()]);
110  }
111 
112 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.