19 package org.sleuthkit.autopsy.datamodel;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.Observable;
26 import java.util.Observer;
28 import java.util.concurrent.ExecutionException;
29 import java.util.logging.Level;
30 import javax.swing.SwingWorker;
31 import org.openide.nodes.AbstractNode;
32 import org.openide.nodes.Children;
33 import org.openide.nodes.Sheet;
34 import org.openide.util.Lookup;
35 import org.openide.util.NbBundle;
36 import org.openide.util.lookup.Lookups;
65 @NbBundle.Messages(
"FileTypes.name.text=File Types")
66 private static final String
NAME = Bundle.FileTypes_name_text();
85 this.datasourceObjId = dsObjId;
91 return visitor.
visit(
this);
94 long filteringDataSourceObjId() {
100 void updateShowCounts() {
110 }
catch (NoCurrentCaseException | TskCoreException tskCoreException) {
112 logger.log(Level.SEVERE,
"Error counting files.", tskCoreException);
126 Lookups.singleton(NAME));
128 this.setDisplayName(NAME);
129 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/file_types.png");
139 return visitor.
visit(
this);
144 "FileTypes.createSheet.name.name=Name",
145 "FileTypes.createSheet.name.displayName=Name",
146 "FileTypes.createSheet.name.desc=no description"})
148 Sheet sheet = super.createSheet();
149 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
150 if (sheetSet == null) {
151 sheetSet = Sheet.createPropertiesSet();
155 sheetSet.put(
new NodeProperty<>(Bundle.FileTypes_createSheet_name_name(),
156 Bundle.FileTypes_createSheet_name_displayName(),
157 Bundle.FileTypes_createSheet_name_desc(),
165 return getClass().getName();
170 static class FileNodeCreationVisitor
extends ContentVisitor.Default<AbstractNode> {
172 FileNodeCreationVisitor() {
176 public FileNode visit(File f) {
177 return new FileNode(f,
false);
181 public DirectoryNode visit(Directory d) {
182 return new DirectoryNode(d);
186 public LayoutFileNode visit(LayoutFile lf) {
187 return new LayoutFileNode(lf);
191 public LocalFileNode visit(DerivedFile df) {
192 return new LocalFileNode(df);
196 public LocalFileNode visit(LocalFile lf) {
197 return new LocalFileNode(lf);
201 public SlackFileNode visit(SlackFile sf) {
202 return new SlackFileNode(sf,
false);
206 protected AbstractNode defaultVisit(Content di) {
207 throw new UnsupportedOperationException(NbBundle.getMessage(
this.getClass(),
"FileTypeChildren.exception.notSupported.msg", di.toString()));
211 static abstract class BGCountUpdatingNode
extends DisplayableItemNode implements Observer {
213 private long childCount = -1;
214 private FileTypes typesRoot;
216 BGCountUpdatingNode(FileTypes typesRoot, Children children) {
217 this(typesRoot, children, null);
220 BGCountUpdatingNode(FileTypes typesRoot, Children children, Lookup lookup) {
221 super(children, lookup);
222 this.typesRoot = typesRoot;
226 public void update(Observable o, Object arg) {
230 abstract String getDisplayNameBase();
239 abstract long calculateChildCount() throws TskCoreException;
245 @NbBundle.Messages("FileTypes.bgCounting.placeholder= (counting...)")
246 void updateDisplayName() {
247 if (typesRoot.showCounts) {
249 setDisplayName(getDisplayNameBase() + ((childCount < 0) ? Bundle.FileTypes_bgCounting_placeholder()
250 : (
" (" + childCount +
")")));
251 new SwingWorker<Long, Void>() {
253 protected Long doInBackground() throws Exception {
254 return calculateChildCount();
258 protected void done() {
261 setDisplayName(getDisplayNameBase() +
" (" + childCount +
")");
262 }
catch (InterruptedException | ExecutionException ex) {
263 setDisplayName(getDisplayNameBase());
264 logger.log(Level.WARNING,
"Failed to get count of files for " + getDisplayNameBase(), ex);
269 setDisplayName(getDisplayNameBase() + ((childCount < 0) ?
"" : (
" (" + childCount +
"+)")));
283 static class FileTypesKey
implements Content {
285 private final Content content;
287 public FileTypesKey(Content content) {
288 this.content = content;
292 public boolean equals(Object obj) {
296 if (getClass() != obj.getClass()) {
299 final FileTypesKey other = (FileTypesKey) obj;
301 return this.content.getId() == other.content.getId();
305 public int hashCode() {
307 hash = 101 * hash + (int)(this.content.getId() ^ (this.content.getId() >>> 32));
312 public <T> T accept(SleuthkitItemVisitor<T> v) {
313 return content.accept(v);
317 public int read(byte[] buf,
long offset,
long len)
throws TskCoreException {
318 return content.read(buf, offset, len);
322 public void close() {
327 public long getSize() {
328 return content.getSize();
332 public <T> T accept(ContentVisitor<T> v) {
333 return content.accept(v);
337 public String getName() {
338 return content.getName();
342 public String getUniquePath() throws TskCoreException {
343 return content.getUniquePath();
347 public long getId() {
348 return content.getId();
352 public Content getDataSource() throws TskCoreException {
353 return content.getDataSource();
357 public List<Content> getChildren() throws TskCoreException {
358 return content.getChildren();
362 public boolean hasChildren() throws TskCoreException {
363 return content.hasChildren();
367 public int getChildrenCount() throws TskCoreException {
368 return content.getChildrenCount();
372 public Content getParent() throws TskCoreException {
373 return content.getParent();
377 public List<Long> getChildrenIds() throws TskCoreException {
378 return content.getChildrenIds();
382 @SuppressWarnings(
"deprecation")
384 public BlackboardArtifact newArtifact(
int artifactTypeID)
throws TskCoreException {
385 return content.newArtifact(artifactTypeID);
389 @SuppressWarnings(
"deprecation")
391 public BlackboardArtifact newArtifact(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
392 return content.newArtifact(type);
396 public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList, Long osAccountId)
throws TskCoreException {
397 return content.newDataArtifact(artifactType, attributesList, osAccountId);
401 public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList, Long osAccountId,
long dataSourceId)
throws TskCoreException {
402 return content.newDataArtifact(artifactType, attributesList, osAccountId, dataSourceId);
406 public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList)
throws TskCoreException {
407 return content.newDataArtifact(artifactType, attributesList);
411 public ArrayList<BlackboardArtifact> getArtifacts(String artifactTypeName)
throws TskCoreException {
412 return content.getArtifacts(artifactTypeName);
416 public BlackboardArtifact getGenInfoArtifact() throws TskCoreException {
417 return content.getGenInfoArtifact();
421 public BlackboardArtifact getGenInfoArtifact(
boolean create)
throws TskCoreException {
422 return content.getGenInfoArtifact(create);
426 public ArrayList<BlackboardAttribute> getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE attr_type) throws TskCoreException {
427 return content.getGenInfoAttributes(attr_type);
431 public ArrayList<BlackboardArtifact> getArtifacts(
int artifactTypeID)
throws TskCoreException {
432 return content.getArtifacts(artifactTypeID);
436 public ArrayList<BlackboardArtifact> getArtifacts(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
437 return content.getArtifacts(type);
441 public ArrayList<BlackboardArtifact> getAllArtifacts() throws TskCoreException {
442 return content.getAllArtifacts();
446 public Set<String> getHashSetNames() throws TskCoreException {
447 return content.getHashSetNames();
451 public long getArtifactsCount(String artifactTypeName)
throws TskCoreException {
452 return content.getArtifactsCount(artifactTypeName);
456 public long getArtifactsCount(
int artifactTypeID)
throws TskCoreException {
457 return content.getArtifactsCount(artifactTypeID);
461 public long getArtifactsCount(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
462 return content.getArtifactsCount(type);
466 public long getAllArtifactsCount() throws TskCoreException {
467 return content.getAllArtifactsCount();
471 public AnalysisResultAdded newAnalysisResult(BlackboardArtifact.Type type, Score score, String
string, String string1, String string2, Collection<BlackboardAttribute> clctn)
throws TskCoreException {
472 return content.newAnalysisResult(type, score,
string, string1, string2, clctn);
476 public AnalysisResultAdded newAnalysisResult(BlackboardArtifact.Type type, Score score, String
string, String string1, String string2, Collection<BlackboardAttribute> clctn,
long dataSourceId)
throws TskCoreException {
477 return content.newAnalysisResult(type, score,
string, string1, string2, clctn, dataSourceId);
481 public Score getAggregateScore() throws TskCoreException {
482 return content.getAggregateScore();
486 public List<AnalysisResult> getAnalysisResults(BlackboardArtifact.Type type) throws TskCoreException {
487 return content.getAnalysisResults(type);
491 public List<AnalysisResult> getAllAnalysisResults() throws TskCoreException {
492 return content.getAllAnalysisResults();
496 public List<DataArtifact> getAllDataArtifacts() throws TskCoreException {
497 return content.getAllDataArtifacts();
static final int NODE_COUNT_FILE_TABLE_THRESHOLD
static final Logger logger
final long datasourceObjId
T visit(DataSourceFilesNode in)
synchronized static Logger getLogger(String name)