Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ContentChildren.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2019 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.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.logging.Level;
26 import org.sleuthkit.datamodel.Content;
27 import org.sleuthkit.datamodel.Directory;
28 import org.sleuthkit.datamodel.FileSystem;
29 import org.sleuthkit.datamodel.LocalDirectory;
30 import org.sleuthkit.datamodel.TskCoreException;
31 import org.sleuthkit.datamodel.VolumeSystem;
32 
37 class ContentChildren extends AbstractContentChildren<Content> {
38 
39  private static final Logger logger = Logger.getLogger(ContentChildren.class.getName());
40 
41  private final Content parent;
42 
43  ContentChildren(Content parent) {
44  super("content_" + Long.toString(parent.getId()));
45  this.parent = parent;
46  }
47 
58  private static List<Content> getDisplayChildren(Content parent) {
59  // what does the content think its children are?
60  List<Content> tmpChildren;
61  try {
62  tmpChildren = parent.getChildren();
63  } catch (TskCoreException ex) {
64  logger.log(Level.WARNING, "Error getting Content children.", ex); //NON-NLS
65  tmpChildren = Collections.emptyList();
66  }
67 
68  // Cycle through the list and make a new one based
69  // on what we actually want to display.
70  List<Content> children = new ArrayList<>();
71  for (Content c : tmpChildren) {
72  if (c instanceof VolumeSystem) {
73  children.addAll(getDisplayChildren(c));
74  } else if (c instanceof FileSystem) {
75  children.addAll(getDisplayChildren(c));
76  } else if (c instanceof Directory) {
77  Directory dir = (Directory) c;
78  /*
79  * For root directories, we want to return their contents.
80  * Special case though for '.' and '..' entries, because they
81  * should not have children (and in fact don't in the DB). Other
82  * drs get treated as files and added as is.
83  */
84  if ((dir.isRoot()) && (dir.getName().equals(".") == false)
85  && (dir.getName().equals("..") == false)) {
86  children.addAll(getDisplayChildren(dir));
87  } else {
88  children.add(c);
89  }
90  } else if (c instanceof LocalDirectory) {
91  LocalDirectory localDir = (LocalDirectory) c;
92  if (localDir.isRoot()) {
93  children.addAll(getDisplayChildren(localDir));
94  } else {
95  children.add(c);
96  }
97  } else {
98  children.add(c);
99  }
100  }
101  return children;
102  }
103 
104  @Override
105  protected List<Content> makeKeys() {
106  List<Content> contentList = getDisplayChildren(parent);
107 
108  // Call the getUniquePath method to cache the value for future use
109  // in the EDT
110  contentList.forEach(content->{
111  try {
112  content.getUniquePath();
113  } catch (TskCoreException ex) {
114  logger.log(Level.SEVERE, String.format("Failed attempt to cache the "
115  + "unique path of the abstract file instance. Name: %s (objID=%d)",
116  content.getName(), content.getId()), ex);
117  }
118  });
119 
120  return contentList;
121  }
122 
123  @Override
124  protected void onAdd() {
125  // No-op
126  }
127 
133  void refreshChildren() {
134  refresh(true);
135  }
136 
137  @Override
138  protected void onRemove() {
139  // No-op
140  }
141 }

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.