mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 10:17:41 +00:00
move duplicated node creation visitors into FileTypes.java; make methods static so we don't need to instantiate throw away object.
This commit is contained in:
parent
13eebf191a
commit
abb8079b83
@ -1,15 +1,15 @@
|
||||
/*
|
||||
* Autopsy Forensic Browser
|
||||
*
|
||||
*
|
||||
* Copyright 2011-2016 Basis Technology Corp.
|
||||
* Contact: carrier <at> sleuthkit <dot> org
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -19,9 +19,18 @@
|
||||
package org.sleuthkit.autopsy.datamodel;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.openide.nodes.AbstractNode;
|
||||
import org.openide.nodes.Sheet;
|
||||
import org.openide.util.NbBundle;
|
||||
import org.openide.util.lookup.Lookups;
|
||||
import org.sleuthkit.datamodel.Content;
|
||||
import org.sleuthkit.datamodel.ContentVisitor;
|
||||
import org.sleuthkit.datamodel.DerivedFile;
|
||||
import org.sleuthkit.datamodel.Directory;
|
||||
import org.sleuthkit.datamodel.File;
|
||||
import org.sleuthkit.datamodel.LayoutFile;
|
||||
import org.sleuthkit.datamodel.LocalFile;
|
||||
import org.sleuthkit.datamodel.SlackFile;
|
||||
import org.sleuthkit.datamodel.SleuthkitCase;
|
||||
|
||||
/**
|
||||
@ -99,4 +108,45 @@ public final class FileTypes implements AutopsyVisitableItem {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class FileNodeCreationVisitor extends ContentVisitor.Default<AbstractNode> {
|
||||
|
||||
FileNodeCreationVisitor() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileNode visit(File f) {
|
||||
return new FileNode(f, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectoryNode visit(Directory d) {
|
||||
return new DirectoryNode(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LayoutFileNode visit(LayoutFile lf) {
|
||||
return new LayoutFileNode(lf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalFileNode visit(DerivedFile df) {
|
||||
return new LocalFileNode(df);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalFileNode visit(LocalFile lf) {
|
||||
return new LocalFileNode(lf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlackFileNode visit(SlackFile sf) {
|
||||
return new SlackFileNode(sf, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractNode defaultVisit(Content di) {
|
||||
throw new UnsupportedOperationException(NbBundle.getMessage(this.getClass(), "FileTypeChildren.exception.notSupported.msg", di.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.logging.Level;
|
||||
import org.openide.nodes.AbstractNode;
|
||||
import org.openide.nodes.ChildFactory;
|
||||
import org.openide.nodes.Children;
|
||||
import org.openide.nodes.Node;
|
||||
@ -38,12 +37,6 @@ import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
import org.sleuthkit.autopsy.ingest.IngestManager;
|
||||
import org.sleuthkit.datamodel.AbstractFile;
|
||||
import org.sleuthkit.datamodel.Content;
|
||||
import org.sleuthkit.datamodel.ContentVisitor;
|
||||
import org.sleuthkit.datamodel.DerivedFile;
|
||||
import org.sleuthkit.datamodel.Directory;
|
||||
import org.sleuthkit.datamodel.File;
|
||||
import org.sleuthkit.datamodel.LayoutFile;
|
||||
import org.sleuthkit.datamodel.LocalFile;
|
||||
import org.sleuthkit.datamodel.SleuthkitCase;
|
||||
import org.sleuthkit.datamodel.TskCoreException;
|
||||
import org.sleuthkit.datamodel.TskData;
|
||||
@ -51,7 +44,7 @@ import org.sleuthkit.datamodel.TskData;
|
||||
/**
|
||||
* Filters database results by file extension.
|
||||
*/
|
||||
public final class FileTypesByExtension implements AutopsyVisitableItem {
|
||||
public final class FileTypesByExtension implements AutopsyVisitableItem {
|
||||
|
||||
private final SleuthkitCase skCase;
|
||||
|
||||
@ -427,37 +420,7 @@ import org.sleuthkit.datamodel.TskData;
|
||||
|
||||
@Override
|
||||
protected Node createNodeForKey(Content key) {
|
||||
return key.accept(new ContentVisitor.Default<AbstractNode>() {
|
||||
@Override
|
||||
public FileNode visit(File f) {
|
||||
return new FileNode(f, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectoryNode visit(Directory d) {
|
||||
return new DirectoryNode(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LayoutFileNode visit(LayoutFile lf) {
|
||||
return new LayoutFileNode(lf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalFileNode visit(DerivedFile df) {
|
||||
return new LocalFileNode(df);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalFileNode visit(LocalFile lf) {
|
||||
return new LocalFileNode(lf);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractNode defaultVisit(Content di) {
|
||||
throw new UnsupportedOperationException(NbBundle.getMessage(this.getClass(), "FileTypeChildren.exception.notSupported.msg", di.toString()));
|
||||
}
|
||||
});
|
||||
return key.accept(new FileTypes.FileNodeCreationVisitor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ import java.util.Observer;
|
||||
import java.util.logging.Level;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openide.nodes.AbstractNode;
|
||||
import org.openide.nodes.ChildFactory;
|
||||
import org.openide.nodes.Children;
|
||||
import org.openide.nodes.Node;
|
||||
@ -42,13 +41,6 @@ import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
import org.sleuthkit.autopsy.ingest.IngestManager;
|
||||
import org.sleuthkit.datamodel.AbstractFile;
|
||||
import org.sleuthkit.datamodel.Content;
|
||||
import org.sleuthkit.datamodel.ContentVisitor;
|
||||
import org.sleuthkit.datamodel.DerivedFile;
|
||||
import org.sleuthkit.datamodel.Directory;
|
||||
import org.sleuthkit.datamodel.File;
|
||||
import org.sleuthkit.datamodel.LayoutFile;
|
||||
import org.sleuthkit.datamodel.LocalFile;
|
||||
import org.sleuthkit.datamodel.SlackFile;
|
||||
import org.sleuthkit.datamodel.SleuthkitCase;
|
||||
import org.sleuthkit.datamodel.TskCoreException;
|
||||
import org.sleuthkit.datamodel.TskData;
|
||||
@ -358,10 +350,9 @@ public final class FileTypesByMimeType extends Observable implements AutopsyVisi
|
||||
* results
|
||||
*/
|
||||
private void updateDisplayName(String mimeType) {
|
||||
final long count = new MediaSubTypeNodeChildren(mimeType).calculateItems(skCase, mimeType);
|
||||
String[] mimeTypeParts = mimeType.split("/");
|
||||
//joins up all remaining parts of the mimeType into one sub-type string
|
||||
super.setDisplayName(StringUtils.join(ArrayUtils.subarray(mimeTypeParts, 1, mimeTypeParts.length), "/") + " (" + count + ")");
|
||||
final long count = calculateItems(skCase, mimeType);
|
||||
//only the part of the mimeType after the media type
|
||||
super.setDisplayName(StringUtils.substringAfter(mimeType, "/") + " (" + count + ")");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -391,6 +382,48 @@ public final class FileTypesByMimeType extends Observable implements AutopsyVisi
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get children count without actually loading all nodes
|
||||
*
|
||||
* @return count(*) - the number of items that will be shown in this items
|
||||
* Directory Listing
|
||||
*/
|
||||
static private long calculateItems(SleuthkitCase sleuthkitCase, String mime_type) {
|
||||
try {
|
||||
return sleuthkitCase.countFilesWhere(createQuery(mime_type));
|
||||
} catch (TskCoreException ex) {
|
||||
LOGGER.log(Level.SEVERE, "Error getting file search view count", ex); //NON-NLS
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the portion of the query following WHERE for a query of the
|
||||
* database for each file which matches the complete MIME type represented
|
||||
* by this node. Matches against the mime_type column in tsk_files.
|
||||
*
|
||||
* @param mimeType - the complete mimetype of the file mediatype/subtype
|
||||
*
|
||||
* @return query.toString - portion of SQL query which will follow a WHERE
|
||||
* clause.
|
||||
*/
|
||||
static private String createQuery(String mimeType) {
|
||||
StringBuilder query = new StringBuilder();
|
||||
query.append("(dir_type = ").append(TskData.TSK_FS_NAME_TYPE_ENUM.REG.getValue()).append(")"); //NON-NLS
|
||||
query.append(" AND (type IN (").append(TskData.TSK_DB_FILES_TYPE_ENUM.FS.ordinal()).append(","); //NON-NLS
|
||||
query.append(TskData.TSK_DB_FILES_TYPE_ENUM.CARVED.ordinal()).append(",");
|
||||
query.append(TskData.TSK_DB_FILES_TYPE_ENUM.DERIVED.ordinal()).append(",");
|
||||
if (!UserPreferences.hideSlackFilesInViewsTree()) {
|
||||
query.append(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK.ordinal()).append(",");
|
||||
}
|
||||
query.append(TskData.TSK_DB_FILES_TYPE_ENUM.LOCAL.ordinal()).append("))");
|
||||
if (UserPreferences.hideKnownFilesInViewsTree()) {
|
||||
query.append(" AND (known IS NULL OR known != ").append(TskData.FileKnown.KNOWN.getFileKnownValue()).append(")"); //NON-NLS
|
||||
}
|
||||
query.append(" AND mime_type = '").append(mimeType).append("'"); //NON-NLS
|
||||
return query.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory for populating the contents of the Media Sub Type Node with the
|
||||
* files that match MimeType which is represented by this position in the
|
||||
@ -406,21 +439,6 @@ public final class FileTypesByMimeType extends Observable implements AutopsyVisi
|
||||
this.mimeType = mimeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get children count without actually loading all nodes
|
||||
*
|
||||
* @return count(*) - the number of items that will be shown in this
|
||||
* items Directory Listing
|
||||
*/
|
||||
private long calculateItems(SleuthkitCase sleuthkitCase, String mime_type) {
|
||||
try {
|
||||
return sleuthkitCase.countFilesWhere(createQuery(mime_type));
|
||||
} catch (TskCoreException ex) {
|
||||
LOGGER.log(Level.SEVERE, "Error getting file search view count", ex); //NON-NLS
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the createQuery method to complete the query, Select * from
|
||||
* tsk_files WHERE. The results from the database will contain the files
|
||||
@ -442,34 +460,6 @@ public final class FileTypesByMimeType extends Observable implements AutopsyVisi
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the portion of the query following WHERE for a query of the
|
||||
* database for each file which matches the complete MIME type
|
||||
* represented by this node. Matches against the mime_type column in
|
||||
* tsk_files.
|
||||
*
|
||||
* @param mimeType - the complete mimetype of the file mediatype/subtype
|
||||
*
|
||||
* @return query.toString - portion of SQL query which will follow a
|
||||
* WHERE clause.
|
||||
*/
|
||||
private String createQuery(String mimeType) {
|
||||
StringBuilder query = new StringBuilder();
|
||||
query.append("(dir_type = ").append(TskData.TSK_FS_NAME_TYPE_ENUM.REG.getValue()).append(")"); //NON-NLS
|
||||
query.append(" AND (type IN (").append(TskData.TSK_DB_FILES_TYPE_ENUM.FS.ordinal()).append(","); //NON-NLS
|
||||
query.append(TskData.TSK_DB_FILES_TYPE_ENUM.CARVED.ordinal()).append(",");
|
||||
query.append(TskData.TSK_DB_FILES_TYPE_ENUM.DERIVED.ordinal()).append(",");
|
||||
if (!UserPreferences.hideSlackFilesInViewsTree()) {
|
||||
query.append(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK.ordinal()).append(",");
|
||||
}
|
||||
query.append(TskData.TSK_DB_FILES_TYPE_ENUM.LOCAL.ordinal()).append("))");
|
||||
if (UserPreferences.hideKnownFilesInViewsTree()) {
|
||||
query.append(" AND (known IS NULL OR known != ").append(TskData.FileKnown.KNOWN.getFileKnownValue()).append(")"); //NON-NLS
|
||||
}
|
||||
query.append(" AND mime_type = '").append(mimeType).append("'"); //NON-NLS
|
||||
return query.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
refresh(true);
|
||||
@ -485,43 +475,9 @@ public final class FileTypesByMimeType extends Observable implements AutopsyVisi
|
||||
*/
|
||||
@Override
|
||||
protected Node createNodeForKey(Content key) {
|
||||
return key.accept(new ContentVisitor.Default<AbstractNode>() {
|
||||
@Override
|
||||
public FileNode visit(File f) {
|
||||
return new FileNode(f, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectoryNode visit(Directory d) {
|
||||
return new DirectoryNode(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LayoutFileNode visit(LayoutFile lf) {
|
||||
return new LayoutFileNode(lf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalFileNode visit(DerivedFile df) {
|
||||
return new LocalFileNode(df);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalFileNode visit(LocalFile lf) {
|
||||
return new LocalFileNode(lf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlackFileNode visit(SlackFile sf) {
|
||||
return new SlackFileNode(sf, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractNode defaultVisit(Content di) {
|
||||
throw new UnsupportedOperationException(NbBundle.getMessage(this.getClass(), "FileTypeChildren.exception.notSupported.msg", di.toString()));
|
||||
}
|
||||
});
|
||||
return key.accept(new FileTypes.FileNodeCreationVisitor());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user