19 package org.sleuthkit.autopsy.datamodel;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24 import java.util.Observable;
25 import java.util.Observer;
27 import java.util.concurrent.ExecutionException;
28 import java.util.logging.Level;
29 import javax.swing.SwingWorker;
30 import org.openide.nodes.AbstractNode;
31 import org.openide.nodes.Children;
32 import org.openide.nodes.Sheet;
33 import org.openide.util.Lookup;
34 import org.openide.util.NbBundle;
35 import org.openide.util.lookup.Lookups;
57 @NbBundle.Messages(
"FileTypes.name.text=File Types")
58 private static final String
NAME = Bundle.FileTypes_name_text();
81 FileTypes(SleuthkitCase skCase,
long dsObjId) {
83 this.datasourceObjId = dsObjId;
88 public <T> T accept(AutopsyItemVisitor<T> visitor) {
89 return visitor.visit(
this);
92 SleuthkitCase getSleuthkitCase() {
96 long filteringDataSourceObjId() {
102 void updateShowCounts() {
112 }
catch (TskCoreException tskCoreException) {
114 logger.log(Level.SEVERE,
"Error counting files.", tskCoreException);
128 Lookups.singleton(NAME));
130 this.setDisplayName(NAME);
131 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/file_types.png");
141 return visitor.
visit(
this);
146 "FileTypes.createSheet.name.name=Name",
147 "FileTypes.createSheet.name.displayName=Name",
148 "FileTypes.createSheet.name.desc=no description"})
150 Sheet sheet = super.createSheet();
151 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
152 if (sheetSet == null) {
153 sheetSet = Sheet.createPropertiesSet();
157 sheetSet.put(
new NodeProperty<>(Bundle.FileTypes_createSheet_name_name(),
158 Bundle.FileTypes_createSheet_name_displayName(),
159 Bundle.FileTypes_createSheet_name_desc(),
167 return getClass().getName();
172 static class FileNodeCreationVisitor
extends ContentVisitor.Default<AbstractNode> {
174 FileNodeCreationVisitor() {
178 public FileNode visit(File f) {
179 return new FileNode(f,
false);
183 public DirectoryNode visit(Directory d) {
184 return new DirectoryNode(d);
188 public LayoutFileNode visit(LayoutFile lf) {
189 return new LayoutFileNode(lf);
193 public LocalFileNode visit(DerivedFile df) {
194 return new LocalFileNode(df);
198 public LocalFileNode visit(LocalFile lf) {
199 return new LocalFileNode(lf);
203 public SlackFileNode visit(SlackFile sf) {
204 return new SlackFileNode(sf,
false);
208 protected AbstractNode defaultVisit(Content di) {
209 throw new UnsupportedOperationException(NbBundle.getMessage(
this.getClass(),
"FileTypeChildren.exception.notSupported.msg", di.toString()));
213 static abstract class BGCountUpdatingNode
extends DisplayableItemNode implements Observer {
215 private long childCount = -1;
216 private FileTypes typesRoot;
218 BGCountUpdatingNode(FileTypes typesRoot, Children children) {
219 this(typesRoot, children, null);
222 BGCountUpdatingNode(FileTypes typesRoot, Children children, Lookup lookup) {
223 super(children, lookup);
224 this.typesRoot = typesRoot;
228 public void update(Observable o, Object arg) {
232 abstract String getDisplayNameBase();
241 abstract long calculateChildCount() throws TskCoreException;
247 @NbBundle.Messages("FileTypes.bgCounting.placeholder= (counting...)")
248 void updateDisplayName() {
249 if (typesRoot.showCounts) {
251 setDisplayName(getDisplayNameBase() + ((childCount < 0) ? Bundle.FileTypes_bgCounting_placeholder()
252 : (
" (" + childCount +
")")));
253 new SwingWorker<Long, Void>() {
255 protected Long doInBackground() throws Exception {
256 return calculateChildCount();
260 protected void done() {
263 setDisplayName(getDisplayNameBase() +
" (" + childCount +
")");
264 }
catch (InterruptedException | ExecutionException ex) {
265 setDisplayName(getDisplayNameBase());
266 logger.log(Level.WARNING,
"Failed to get count of files for " + getDisplayNameBase(), ex);
271 setDisplayName(getDisplayNameBase() + ((childCount < 0) ?
"" : (
" (" + childCount +
"+)")));
285 static class FileTypesKey
implements Content {
287 private final Content content;
289 public FileTypesKey(Content content) {
290 this.content = content;
294 public boolean equals(Object obj) {
298 if (getClass() != obj.getClass()) {
301 final FileTypesKey other = (FileTypesKey) obj;
303 return this.content.getId() == other.content.getId();
307 public int hashCode() {
309 hash = 101 * hash + (int)(this.content.getId() ^ (this.content.getId() >>> 32));
314 public <T> T accept(SleuthkitItemVisitor<T> v) {
315 return content.accept(v);
319 public int read(byte[] buf,
long offset,
long len)
throws TskCoreException {
320 return content.read(buf, offset, len);
324 public void close() {
329 public long getSize() {
330 return content.getSize();
334 public <T> T accept(ContentVisitor<T> v) {
335 return content.accept(v);
339 public String getName() {
340 return content.getName();
344 public String getUniquePath() throws TskCoreException {
345 return content.getUniquePath();
349 public long getId() {
350 return content.getId();
354 public Content getDataSource() throws TskCoreException {
355 return content.getDataSource();
359 public List<Content> getChildren() throws TskCoreException {
360 return content.getChildren();
364 public boolean hasChildren() throws TskCoreException {
365 return content.hasChildren();
369 public int getChildrenCount() throws TskCoreException {
370 return content.getChildrenCount();
374 public Content getParent() throws TskCoreException {
375 return content.getParent();
379 public List<Long> getChildrenIds() throws TskCoreException {
380 return content.getChildrenIds();
384 public BlackboardArtifact newArtifact(
int artifactTypeID)
throws TskCoreException {
385 return content.newArtifact(artifactTypeID);
389 public BlackboardArtifact newArtifact(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
390 return content.newArtifact(type);
394 public ArrayList<BlackboardArtifact> getArtifacts(String artifactTypeName)
throws TskCoreException {
395 return content.getArtifacts(artifactTypeName);
399 public BlackboardArtifact getGenInfoArtifact() throws TskCoreException {
400 return content.getGenInfoArtifact();
404 public BlackboardArtifact getGenInfoArtifact(
boolean create)
throws TskCoreException {
405 return content.getGenInfoArtifact(create);
409 public ArrayList<BlackboardAttribute> getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE attr_type) throws TskCoreException {
410 return content.getGenInfoAttributes(attr_type);
414 public ArrayList<BlackboardArtifact> getArtifacts(
int artifactTypeID)
throws TskCoreException {
415 return content.getArtifacts(artifactTypeID);
419 public ArrayList<BlackboardArtifact> getArtifacts(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
420 return content.getArtifacts(type);
424 public ArrayList<BlackboardArtifact> getAllArtifacts() throws TskCoreException {
425 return content.getAllArtifacts();
429 public Set<String> getHashSetNames() throws TskCoreException {
430 return content.getHashSetNames();
434 public long getArtifactsCount(String artifactTypeName)
throws TskCoreException {
435 return content.getArtifactsCount(artifactTypeName);
439 public long getArtifactsCount(
int artifactTypeID)
throws TskCoreException {
440 return content.getArtifactsCount(artifactTypeID);
444 public long getArtifactsCount(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
445 return content.getArtifactsCount(type);
449 public long getAllArtifactsCount() throws TskCoreException {
450 return content.getAllArtifactsCount();
static final int NODE_COUNT_FILE_TABLE_THRESHOLD
static final Logger logger
T visit(DataSourcesNode in)
final long datasourceObjId
final SleuthkitCase skCase
synchronized static Logger getLogger(String name)