Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourceFilesNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012-2021 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.datamodel;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.Collections;
26 import java.util.Comparator;
27 import java.util.EnumSet;
28 import java.util.List;
29 import java.util.logging.Level;
30 import org.openide.nodes.Children;
31 import org.openide.nodes.Sheet;
32 import org.openide.util.NbBundle;
33 import org.openide.util.lookup.Lookups;
37 import org.sleuthkit.datamodel.Content;
38 import org.sleuthkit.datamodel.TskCoreException;
39 import org.sleuthkit.datamodel.TskDataException;
40 
49 
50  private static final String NAME = NbBundle.getMessage(DataSourceFilesNode.class, "DataSourcesNode.name");
51 
55  public static String getNameIdentifier() {
56  return NAME;
57  }
58 
59  private final String displayName;
60 
61  // NOTE: The images passed in via argument will be ignored.
62  @Deprecated
63  public DataSourceFilesNode(List<Content> images) {
64  this(0);
65  }
66 
68  this(0);
69  }
70 
71  public DataSourceFilesNode(long dsObjId) {
72  super(Children.create(new DataSourcesNodeChildren(dsObjId), true), Lookups.singleton(NAME));
73  displayName = (dsObjId > 0) ? NbBundle.getMessage(DataSourceFilesNode.class, "DataSourcesNode.group_by_datasource.name") : NAME;
74  init();
75  }
76 
77  private void init() {
78  setName(NAME);
79  setDisplayName(displayName);
80  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/image.png"); //NON-NLS
81  }
82 
83  @Override
84  public String getItemType() {
85  return getClass().getName();
86  }
87 
88  /*
89  * Custom Keys implementation that listens for new data sources being added.
90  */
91  public static class DataSourcesNodeChildren extends AbstractContentChildren<Content> {
92 
93  private static final Logger logger = Logger.getLogger(DataSourcesNodeChildren.class.getName());
94  private final long datasourceObjId;
95 
96  List<Content> currentKeys;
97 
99  this(0);
100  }
101 
102  public DataSourcesNodeChildren(long dsObjId) {
103  super("ds_" + Long.toString(dsObjId));
104  this.currentKeys = new ArrayList<>();
105  this.datasourceObjId = dsObjId;
106  }
107 
108  private final PropertyChangeListener pcl = new PropertyChangeListener() {
109  @Override
110  public void propertyChange(PropertyChangeEvent evt) {
111  String eventType = evt.getPropertyName();
112  if (eventType.equals(Case.Events.DATA_SOURCE_ADDED.toString())) {
113  refresh(true);
114  }
115  }
116  };
117 
118  @Override
119  protected void onAdd() {
121  }
122 
123  @Override
124  protected void onRemove() {
126  currentKeys.clear();
127  }
128 
129  @Override
130  protected List<Content> makeKeys() {
131  try {
132  if (datasourceObjId == 0) {
133  currentKeys = Case.getCurrentCaseThrows().getDataSources();
134  } else {
135  Content content = Case.getCurrentCaseThrows().getSleuthkitCase().getDataSource(datasourceObjId);
136  currentKeys = new ArrayList<>(Arrays.asList(content));
137  }
138 
139  Collections.sort(currentKeys, new Comparator<Content>() {
140  @Override
141  public int compare(Content content1, Content content2) {
142  String content1Name = content1.getName().toLowerCase();
143  String content2Name = content2.getName().toLowerCase();
144  return content1Name.compareTo(content2Name);
145  }
146 
147  });
148 
149  } catch (TskCoreException | NoCurrentCaseException | TskDataException ex) {
150  logger.log(Level.SEVERE, "Error getting data sources: {0}", ex.getMessage()); // NON-NLS
151  }
152 
153  return currentKeys;
154  }
155  }
156 
157  @Override
158  public boolean isLeafTypeNode() {
159  return false;
160  }
161 
162  @Override
163  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
164  return visitor.visit(this);
165  }
166 
167  @Override
168  protected Sheet createSheet() {
169  Sheet sheet = super.createSheet();
170  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
171  if (sheetSet == null) {
172  sheetSet = Sheet.createPropertiesSet();
173  sheet.put(sheetSet);
174  }
175 
176  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.name"),
177  NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.displayName"),
178  NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.desc"),
179  NAME));
180  return sheet;
181  }
182 }
List< Content > getDataSources()
Definition: Case.java:1696
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:704
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:749

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.