Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
PListRowFactory.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.Arrays;
22 import java.util.List;
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;
32 
37 class PListRowFactory extends ChildFactory<Integer> {
38 
39  private final List<PropKeyValue> rows;
40 
41  PListRowFactory(final List<PropKeyValue> rows) {
42  this.rows = rows;
43  }
44 
51  @Override
52  protected boolean createKeys(final List<Integer> keys) {
53  if (rows != null) {
54  for (int i = 0; i < rows.size(); i++) {
55  keys.add(i);
56  }
57  }
58  return true;
59  }
60 
66  @Override
67  protected Node createNodeForKey(final Integer key) {
68  if (Objects.isNull(rows) || rows.isEmpty() || key >= rows.size()) {
69  return null;
70  }
71  return new PListNode(rows.get(key));
72  }
73 }
74 
78 class PListNode extends AbstractNode {
79 
80  private final PropKeyValue propKeyVal;
81 
82  PListNode(final PropKeyValue propKeyVal) {
83 
84  super(propKeyVal.getChildren() == null ? Children.LEAF : new PListNodeChildren(propKeyVal.getChildren()));
85 
86  this.propKeyVal = propKeyVal;
87 
88  super.setName(propKeyVal.getKey());
89  super.setDisplayName(propKeyVal.getKey());
90  if (propKeyVal.getType() == PropertyType.ARRAY) {
91  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/keychain-16.png");
92  } else if (propKeyVal.getType() == PropertyType.DICTIONARY) {
93  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/keys-dict-16.png");
94  } else {
95  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/key-16.png");
96  }
97 
98  }
99 
103  @Override
104  protected Sheet createSheet() {
105 
106  final Sheet sheet = super.createSheet();
107  Sheet.Set properties = sheet.get(Sheet.PROPERTIES);
108  if (properties == null) {
109  properties = Sheet.createPropertiesSet();
110  sheet.put(properties);
111  }
112 
113  properties.put(new NodeProperty<>(Bundle.PListNode_TypeCol(),
114  Bundle.PListNode_TypeCol(),
115  Bundle.PListNode_TypeCol(),
116  propKeyVal.getType().name())); // NON-NLS
117 
118  properties.put(new NodeProperty<>(Bundle.PListNode_ValueCol(),
119  Bundle.PListNode_ValueCol(),
120  Bundle.PListNode_ValueCol(),
121  (propKeyVal.getChildren() == null) ? propKeyVal.getValue() : "")); // NON-NLS
122 
123  return sheet;
124  }
125 
129  private static class PListNodeChildren extends Children.Keys<PropKeyValue> {
130 
131  private final List<PropKeyValue> children;
132 
133  PListNodeChildren(final PropKeyValue... children) {
134  super();
135  this.children = Arrays.asList(children);
136  }
137 
138  @Override
139  protected void addNotify() {
140  super.setKeys(this.children);
141  }
142 
143  @Override
144  protected Node[] createNodes(final PropKeyValue propKeyVal) {
145  return new Node[]{new PListNode(propKeyVal)};
146  }
147 
148  }
149 
150 }

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