Autopsy  4.10.0
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-2014 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 
38 class ContentChildren extends AbstractContentChildren<Content> {
39 
40  private static final Logger logger = Logger.getLogger(ContentChildren.class.getName());
41  //private static final int MAX_CHILD_COUNT = 1000000;
42 
43  private final Content parent;
44 
45  ContentChildren(Content parent) {
46  super(); //initialize lazy behavior
47  this.parent = parent;
48  }
49 
60  private static List<Content> getDisplayChildren(Content parent) {
61  // what does the content think its children are?
62  List<Content> tmpChildren;
63  try {
64  tmpChildren = parent.getChildren();
65  } catch (TskCoreException ex) {
66  logger.log(Level.WARNING, "Error getting Content children.", ex); //NON-NLS
67  tmpChildren = Collections.emptyList();
68  }
69 
70  // Cycle through the list and make a new one based
71  // on what we actually want to display.
72  List<Content> children = new ArrayList<>();
73  for (Content c : tmpChildren) {
74  if (c instanceof VolumeSystem) {
75  children.addAll(getDisplayChildren(c));
76  } else if (c instanceof FileSystem) {
77  children.addAll(getDisplayChildren(c));
78  } else if (c instanceof Directory) {
79  Directory dir = (Directory) c;
80  /*
81  * For root directories, we want to return their contents.
82  * Special case though for '.' and '..' entries, because they
83  * should not have children (and in fact don't in the DB). Other
84  * drs get treated as files and added as is.
85  */
86  if ((dir.isRoot()) && (dir.getName().equals(".") == false)
87  && (dir.getName().equals("..") == false)) {
88  children.addAll(getDisplayChildren(dir));
89  } else {
90  children.add(c);
91  }
92  } else if (c instanceof LocalDirectory) {
93  LocalDirectory localDir = (LocalDirectory)c;
94  if (localDir.isRoot()) {
95  children.addAll(getDisplayChildren(localDir));
96  } else {
97  children.add(c);
98  }
99  } else {
100  children.add(c);
101  }
102  }
103  return children;
104  }
105 
106  @Override
107  protected void addNotify() {
108  super.addNotify();
109 
110  //TODO check global settings
111  //if above limit, query and return subrange
112  //StopWatch s2 = new StopWatch();
113  //s2.start();
114  //logger.log(Level.INFO, "GETTING CHILDREN CONTENT for parent: " + parent.getName());
115  List<Content> children = getDisplayChildren(parent);
116  //s2.stop();
117  //logger.log(Level.INFO, "GOT CHILDREN CONTENTS:" + children.size() + ", took: " + s2.getElapsedTime());
118 
119  //limit number children
120  //setKeys(children.subList(0, Math.min(children.size(), MAX_CHILD_COUNT)));
121  setKeys(children);
122  }
123 
124  @Override
125  protected void removeNotify() {
126  super.removeNotify();
127  setKeys(new ArrayList<>());
128  }
129 
135  void refreshChildren() {
136  List<Content> children = getDisplayChildren(parent);
137  setKeys(children);
138  }
139 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.