Autopsy  4.5.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.List;
22 import java.util.Map;
23 import java.util.Objects;
24 import org.openide.nodes.AbstractNode;
25 import org.openide.nodes.ChildFactory;
26 import org.openide.nodes.Children;
27 import org.openide.nodes.Node;
28 import org.openide.nodes.Sheet;
30 
31 public class SQLiteTableRowFactory extends ChildFactory<Integer> {
32 
33  private final List<Map<String, Object>> rows;
34 
35  public SQLiteTableRowFactory(List<Map<String, Object>> rows) {
36  this.rows = rows;
37  }
38 
39  @Override
40  protected boolean createKeys(List<Integer> keys) {
41  if (rows != null) {
42  for (int i = 0; i < rows.size(); i++) {
43  keys.add(i);
44  }
45  }
46  return true;
47  }
48 
49  @Override
50  protected Node createNodeForKey(Integer key) {
51  if (Objects.isNull(rows) || rows.isEmpty() || key >= rows.size()) {
52  return null;
53  }
54 
55  return new SQLiteTableRowNode(rows.get(key));
56  }
57 
58 }
59 
60 class SQLiteTableRowNode extends AbstractNode {
61 
62  private final Map<String, Object> row;
63 
64  SQLiteTableRowNode(Map<String, Object> row) {
65  super(Children.LEAF);
66  this.row = row;
67  }
68 
69  @Override
70  protected Sheet createSheet() {
71 
72  Sheet s = super.createSheet();
73  Sheet.Set properties = s.get(Sheet.PROPERTIES);
74  if (properties == null) {
75  properties = Sheet.createPropertiesSet();
76  s.put(properties);
77  }
78 
79  for (Map.Entry<String, Object> col : row.entrySet()) {
80  String colName = col.getKey();
81  String colVal = col.getValue().toString();
82 
83  properties.put(new NodeProperty<>(colName, colName, colName, colVal)); // NON-NLS
84  }
85 
86  return s;
87  }
88 }

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