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();
82 return visitor.
visit(
this);
85 SleuthkitCase getSleuthkitCase() {
92 void updateShowCounts() {
102 }
catch (TskCoreException tskCoreException) {
104 logger.log(Level.SEVERE,
"Error counting files.", tskCoreException);
118 Lookups.singleton(NAME));
120 this.setDisplayName(NAME);
121 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/file_types.png");
131 return visitor.
visit(
this);
136 "FileTypes.createSheet.name.name=Name",
137 "FileTypes.createSheet.name.displayName=Name",
138 "FileTypes.createSheet.name.desc=no description"})
140 Sheet sheet = super.createSheet();
141 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
142 if (sheetSet == null) {
143 sheetSet = Sheet.createPropertiesSet();
147 sheetSet.put(
new NodeProperty<>(Bundle.FileTypes_createSheet_name_name(),
148 Bundle.FileTypes_createSheet_name_displayName(),
149 Bundle.FileTypes_createSheet_name_desc(),
157 return getClass().getName();
162 static class FileNodeCreationVisitor
extends ContentVisitor.Default<AbstractNode> {
164 FileNodeCreationVisitor() {
168 public FileNode visit(File f) {
169 return new FileNode(f,
false);
173 public DirectoryNode visit(Directory d) {
174 return new DirectoryNode(d);
178 public LayoutFileNode visit(LayoutFile lf) {
179 return new LayoutFileNode(lf);
183 public LocalFileNode visit(DerivedFile df) {
184 return new LocalFileNode(df);
188 public LocalFileNode visit(LocalFile lf) {
189 return new LocalFileNode(lf);
193 public SlackFileNode visit(SlackFile sf) {
194 return new SlackFileNode(sf,
false);
198 protected AbstractNode defaultVisit(Content di) {
199 throw new UnsupportedOperationException(NbBundle.getMessage(
this.getClass(),
"FileTypeChildren.exception.notSupported.msg", di.toString()));
203 static abstract class BGCountUpdatingNode
extends DisplayableItemNode implements Observer {
205 private long childCount = -1;
206 private FileTypes typesRoot;
208 BGCountUpdatingNode(FileTypes typesRoot, Children children) {
209 this(typesRoot, children, null);
212 BGCountUpdatingNode(FileTypes typesRoot, Children children, Lookup lookup) {
213 super(children, lookup);
214 this.typesRoot = typesRoot;
218 public void update(Observable o, Object arg) {
222 abstract String getDisplayNameBase();
231 abstract long calculateChildCount() throws TskCoreException;
237 @NbBundle.Messages("FileTypes.bgCounting.placeholder= (counting...)")
238 void updateDisplayName() {
239 if (typesRoot.showCounts) {
241 setDisplayName(getDisplayNameBase() + ((childCount < 0) ? Bundle.FileTypes_bgCounting_placeholder()
242 : (
"(" + childCount +
")")));
243 new SwingWorker<Long, Void>() {
245 protected Long doInBackground() throws Exception {
246 return calculateChildCount();
250 protected void done() {
253 setDisplayName(getDisplayNameBase() +
" (" + childCount +
")");
254 }
catch (InterruptedException | ExecutionException ex) {
255 setDisplayName(getDisplayNameBase());
256 logger.log(Level.WARNING,
"Failed to get count of files for " + getDisplayNameBase(), ex);
261 setDisplayName(getDisplayNameBase() + ((childCount < 0) ?
"" : (
" (" + childCount +
"+)")));
275 static class FileTypesKey
implements Content {
277 private final Content content;
279 public FileTypesKey(Content content) {
280 this.content = content;
284 public boolean equals(Object obj) {
288 if (getClass() != obj.getClass()) {
291 final FileTypesKey other = (FileTypesKey) obj;
293 return this.content.getId() == other.content.getId();
297 public int hashCode() {
299 hash = 101 * hash + (int)(this.content.getId() ^ (this.content.getId() >>> 32));
304 public <T> T accept(SleuthkitItemVisitor<T> v) {
305 return content.accept(v);
309 public int read(byte[] buf,
long offset,
long len)
throws TskCoreException {
310 return content.read(buf, offset, len);
314 public void close() {
319 public long getSize() {
320 return content.getSize();
324 public <T> T accept(ContentVisitor<T> v) {
325 return content.accept(v);
329 public String getName() {
330 return content.getName();
334 public String getUniquePath() throws TskCoreException {
335 return content.getUniquePath();
339 public long getId() {
340 return content.getId();
344 public Content getDataSource() throws TskCoreException {
345 return content.getDataSource();
349 public List<Content> getChildren() throws TskCoreException {
350 return content.getChildren();
354 public boolean hasChildren() throws TskCoreException {
355 return content.hasChildren();
359 public int getChildrenCount() throws TskCoreException {
360 return content.getChildrenCount();
364 public Content getParent() throws TskCoreException {
365 return content.getParent();
369 public List<Long> getChildrenIds() throws TskCoreException {
370 return content.getChildrenIds();
374 public BlackboardArtifact newArtifact(
int artifactTypeID)
throws TskCoreException {
375 return content.newArtifact(artifactTypeID);
379 public BlackboardArtifact newArtifact(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
380 return content.newArtifact(type);
384 public ArrayList<BlackboardArtifact> getArtifacts(String artifactTypeName)
throws TskCoreException {
385 return content.getArtifacts(artifactTypeName);
389 public BlackboardArtifact getGenInfoArtifact() throws TskCoreException {
390 return content.getGenInfoArtifact();
394 public BlackboardArtifact getGenInfoArtifact(
boolean create)
throws TskCoreException {
395 return content.getGenInfoArtifact(create);
399 public ArrayList<BlackboardAttribute> getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE attr_type) throws TskCoreException {
400 return content.getGenInfoAttributes(attr_type);
404 public ArrayList<BlackboardArtifact> getArtifacts(
int artifactTypeID)
throws TskCoreException {
405 return content.getArtifacts(artifactTypeID);
409 public ArrayList<BlackboardArtifact> getArtifacts(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
410 return content.getArtifacts(type);
414 public ArrayList<BlackboardArtifact> getAllArtifacts() throws TskCoreException {
415 return content.getAllArtifacts();
419 public Set<String> getHashSetNames() throws TskCoreException {
420 return content.getHashSetNames();
424 public long getArtifactsCount(String artifactTypeName)
throws TskCoreException {
425 return content.getArtifactsCount(artifactTypeName);
429 public long getArtifactsCount(
int artifactTypeID)
throws TskCoreException {
430 return content.getArtifactsCount(artifactTypeID);
434 public long getArtifactsCount(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
435 return content.getArtifactsCount(type);
439 public long getAllArtifactsCount() throws TskCoreException {
440 return content.getAllArtifactsCount();
static final int NODE_COUNT_FILE_TABLE_THRESHOLD
static final Logger logger
T visit(DataSourcesNode in)
final SleuthkitCase skCase
synchronized static Logger getLogger(String name)