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

Copyright © 2012-2016 Basis Technology. Generated on: Tue Feb 20 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.