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

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.