Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AttachmentsChildren.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 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 obt ain 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.communications.relationships;
20 
21 import java.util.Arrays;
22 import java.util.HashSet;
23 import java.util.Set;
24 import java.util.TreeSet;
25 import java.util.logging.Level;
26 import org.openide.nodes.Children;
27 import org.openide.nodes.Node;
28 import org.openide.nodes.Sheet;
29 import org.openide.util.NbBundle;
33 import org.sleuthkit.datamodel.AbstractFile;
34 import org.sleuthkit.datamodel.BlackboardArtifact;
35 import org.sleuthkit.datamodel.Content;
36 import org.sleuthkit.datamodel.TskCoreException;
37 
41 final class AttachmentsChildren extends Children.Keys<AbstractFile> {
42 
43  private static final Logger logger = Logger.getLogger(AttachmentsChildren.class.getName());
44 
45  private final Set<BlackboardArtifact> artifacts;
46 
47  /*
48  * Creates the list of thumbnails from the given list of
49  * BlackboardArtifacts.
50  *
51  * The thumbnails will be initialls sorted by size, then name so that they
52  * appear sorted by size by default.
53  */
54  AttachmentsChildren(Set<BlackboardArtifact> artifacts) {
55  super(false);
56 
57  this.artifacts = artifacts;
58 
59 
60  }
61 
62  @Override
63  protected Node[] createNodes(AbstractFile t) {
64  return new Node[]{new AttachementNode(t)};
65  }
66 
67  @Override
68  protected void addNotify() {
69  super.addNotify();
70 
71  Set<AbstractFile> thumbnails = new TreeSet<>((AbstractFile file1, AbstractFile file2) -> {
72  int result = Long.compare(file1.getSize(), file2.getSize());
73  if (result == 0) {
74  result = file1.getName().compareTo(file2.getName());
75  }
76 
77  return result;
78  });
79 
80  artifacts.forEach((bba) -> {
81  try {
82  for (Content childContent : bba.getChildren()) {
83  if (childContent instanceof AbstractFile) {
84  thumbnails.add((AbstractFile) childContent);
85  }
86  }
87  } catch (TskCoreException ex) {
88  logger.log(Level.WARNING, "Unable to get children from artifact.", ex); //NON-NLS
89  }
90  });
91 
92  setKeys(thumbnails);
93  }
94 
98  static class AttachementNode extends FileNode {
99 
100  AttachementNode(AbstractFile file) {
101  super(file, false);
102  }
103 
104  @Override
105  protected Sheet createSheet() {
106  Sheet sheet = super.createSheet();
107  Set<String> keepProps = new HashSet<>(Arrays.asList(
108  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.nameColLbl"),
109  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.score.name"),
110  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.comment.name"),
111  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.count.name"),
112  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.sizeColLbl"),
113  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.mimeType"),
114  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.knownColLbl")));
115 
116  //Remove all other props except for the ones above
117  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
118  for (Node.Property<?> p : sheetSet.getProperties()) {
119  if (!keepProps.contains(p.getName())) {
120  sheetSet.remove(p.getName());
121  }
122  }
123 
124  return sheet;
125  }
126  }
127 }

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