From 483e5cddf54dc2a48342744f1463441d899959a5 Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Thu, 8 Dec 2011 16:03:45 -0500 Subject: [PATCH 01/21] Remove ContentNode.read() --- .../corecomponents/ThumbnailViewChildren.java | 2 +- .../corecomponents/ThumbnailViewNode.java | 38 ++++++++++--------- .../autopsy/datamodel/ContentFilterNode.java | 7 ---- .../autopsy/datamodel/ContentNode.java | 10 ----- .../directorytree/DataResultFilterNode.java | 5 --- .../filesearch/DataResultFilterNode.java | 5 --- .../autopsy/filesearch/SearchNode.java | 7 ---- 7 files changed, 22 insertions(+), 52 deletions(-) diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java index 42916ee103..9967d2aaf9 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java @@ -37,7 +37,7 @@ class ThumbnailViewChildren extends FilterNode.Children { @Override protected Node copyNode(Node arg0) { - return new ThumbnailViewNode((ContentNode) arg0); + return new ThumbnailViewNode(arg0); } @Override diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java index 304cdeea6c..57d87052f4 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java @@ -30,8 +30,8 @@ import javax.swing.ImageIcon; import javax.swing.JFrame; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.logging.Log; +import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.TskException; /** @@ -40,15 +40,13 @@ import org.sleuthkit.datamodel.TskException; */ class ThumbnailViewNode extends FilterNode { - private ContentNode currentNode; - // for error handling private SoftReference iconCache; - private static Image defaultIcon = new ImageIcon("/org/sleuthkit/autopsy/images/file-icon.png").getImage(); + + private static final Image defaultIcon = new ImageIcon("/org/sleuthkit/autopsy/images/file-icon.png").getImage(); /** the constructor */ - ThumbnailViewNode(ContentNode arg) { - super((Node) arg, Children.LEAF); - this.currentNode = arg; + ThumbnailViewNode(Node arg) { + super(arg, Children.LEAF); } @Override @@ -63,24 +61,30 @@ class ThumbnailViewNode extends FilterNode { if (iconCache != null) { icon = iconCache.get(); } - + if (icon == null) { - try { - System.out.println("generate"); - icon = generateIcon(); - iconCache = new SoftReference(icon); - } catch (TskException ex) { + Content content = this.getLookup().lookup(Content.class); + + if (content != null) { + try { + System.out.println("generate"); + icon = generateIcon(content); + } catch (TskException ex) { + icon = ThumbnailViewNode.defaultIcon; + } + } else { icon = ThumbnailViewNode.defaultIcon; } + + iconCache = new SoftReference(icon); } return icon; } - private Image generateIcon() throws TskException { - ContentNode temp = currentNode; - byte[] content = temp.read(0, temp.getContent().getSize()); - Image result = Toolkit.getDefaultToolkit().createImage(content); + static private Image generateIcon(Content content) throws TskException { + byte[] data = content.read(0, content.getSize()); + Image result = Toolkit.getDefaultToolkit().createImage(data); // scale the image MediaTracker mTracker = new MediaTracker(new JFrame()); diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java index 174f205ff2..c3e757827c 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java @@ -39,8 +39,6 @@ public class ContentFilterNode extends FilterNode implements ContentNode { super((Node) original, children, lookup); } - - @Override public long getID() { return ((ContentNode) super.getOriginal()).getID(); @@ -51,11 +49,6 @@ public class ContentFilterNode extends FilterNode implements ContentNode { return ((ContentNode) super.getOriginal()).getRowValues(rows); } - @Override - public byte[] read(long offset, long len) throws TskException { - return ((ContentNode) super.getOriginal()).read(offset, len); - } - @Override public Content getContent() { return ((ContentNode) super.getOriginal()).getContent(); diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java index b8d638a81d..ef27ec768e 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java @@ -55,16 +55,6 @@ public interface ContentNode { */ public Object[][] getRowValues(int rows) throws SQLException; - /** - * Reads the content of this node. - * - * @param offset the starting offset - * @param len the length - * @return the bytes - * @throws TskException - */ - public byte[] read(long offset, long len) throws TskException; - /** * Returns the content of this node. * diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java index d839be5bbb..707ed449dc 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java @@ -200,11 +200,6 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { return ((ContentNode) currentNode).getRowValues(rows); } - @Override - public byte[] read(long offset, long len) throws TskException { - return ((ContentNode) currentNode).read(offset, len); - } - @Override public Content getContent() { return ((ContentNode) currentNode).getContent(); diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java index b047739542..21f2dc59f9 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java @@ -106,11 +106,6 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { return ((ContentNode) currentNode).getRowValues(rows); } - @Override - public byte[] read(long offset, long len) throws TskException { - return ((ContentNode) currentNode).read(offset, len); - } - @Override public Content getContent() { return ((ContentNode) currentNode).getContent(); diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java index aeb4b78098..d1e5016b50 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java @@ -83,13 +83,6 @@ class SearchNode extends AbstractNode implements ContentNode { return objs; } - - @Override - public byte[] read(long offset, long len) throws TskException { - // change this in the future when needed - throw new UnsupportedOperationException("Not supported yet."); - } - @Override public Content getContent() { return null; From dfcf854109436e969de1b20e1a4706ba927fbbec Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Thu, 8 Dec 2011 16:35:58 -0500 Subject: [PATCH 02/21] Remove ContentNode.getName() and .getId() --- .../autopsy/datamodel/AbstractContentNode.java | 13 ++++--------- .../autopsy/datamodel/ContentFilterNode.java | 6 ------ .../autopsy/datamodel/ContentNode.java | 17 ----------------- .../directorytree/DataResultFilterNode.java | 6 ------ .../filesearch/DataResultFilterNode.java | 7 ------- .../autopsy/filesearch/SearchNode.java | 5 ----- 6 files changed, 4 insertions(+), 50 deletions(-) diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java index 6246f3402a..47f723b406 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java @@ -66,15 +66,6 @@ abstract class AbstractContentNode extends AbstractNode imple return super.getName(); } - /** - * Gets the ID of this node. - * - * @return ID the ID of this node - */ - public long getID() { - return content.getId(); - } - /** * Gets the row values for this node. The main purpose of this method is to * get the 'x' number of the row values for this node to set the width of each @@ -84,6 +75,7 @@ abstract class AbstractContentNode extends AbstractNode imple * @return rowValues the row values for this node. * @throws SQLException */ + @Override abstract public Object[][] getRowValues(int rows) throws SQLException; /** @@ -103,6 +95,7 @@ abstract class AbstractContentNode extends AbstractNode imple * * @return content the content of this node (can be image, volume, directory, or file) */ + @Override public Content getContent() { return content; } @@ -116,6 +109,7 @@ abstract class AbstractContentNode extends AbstractNode imple * * @return the path of this node */ + @Override public String[] getDisplayPath() { return content.accept(getDisplayPath).toArray(new String[]{}); } @@ -129,6 +123,7 @@ abstract class AbstractContentNode extends AbstractNode imple * * @return the path of this node */ + @Override public String[] getSystemPath() { return content.accept(getSystemPath).toArray(new String[]{}); } diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java index c3e757827c..28d8646259 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java @@ -23,7 +23,6 @@ import org.openide.nodes.FilterNode; import org.openide.nodes.Node; import org.openide.util.Lookup; import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.TskException; public class ContentFilterNode extends FilterNode implements ContentNode { @@ -38,11 +37,6 @@ public class ContentFilterNode extends FilterNode implements ContentNode { public ContentFilterNode(ContentNode original, Children children, Lookup lookup) { super((Node) original, children, lookup); } - - @Override - public long getID() { - return ((ContentNode) super.getOriginal()).getID(); - } @Override public Object[][] getRowValues(int rows) throws SQLException { diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java index ef27ec768e..ddac749e84 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java @@ -20,7 +20,6 @@ package org.sleuthkit.autopsy.datamodel; import java.sql.SQLException; import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.TskException; /** * Interface class that all Data nodes inherit from. @@ -28,22 +27,6 @@ import org.sleuthkit.datamodel.TskException; */ public interface ContentNode { - /** - * Returns the programmatic name for this node. This is NOT the name to - * display to users, or the plain name of the Content object - use - * Node.getDisplayName() for that. - * - * @return name the programmatic name for this node - */ - public String getName(); - - /** - * Gets the ID of this node. - * - * @return ID the ID of this node - */ - public long getID(); - /** * Gets the row values for this node. The main purpose of this method is to * get the 'x' number of the row values for this node to set the width of each diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java index 707ed449dc..b602d53c7d 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java @@ -39,7 +39,6 @@ import org.openide.nodes.Node; import org.openide.nodes.Sheet; import org.sleuthkit.autopsy.datamodel.ContentNodeVisitor; import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.TskException; /** * This class wraps nodes as they are passed to the DataResult viewers. It @@ -190,11 +189,6 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { return propertySets; } - @Override - public long getID() { - return ((ContentNode) currentNode).getID(); - } - @Override public Object[][] getRowValues(int rows) throws SQLException { return ((ContentNode) currentNode).getRowValues(rows); diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java index 21f2dc59f9..f2d82431e2 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java @@ -29,9 +29,7 @@ import javax.swing.Action; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.TskException; import org.sleuthkit.autopsy.directorytree.ChangeViewAction; -import org.sleuthkit.autopsy.directorytree.ExtractAction; /** * This class wraps nodes as they are passed to the DataResult viewers. It @@ -96,11 +94,6 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { return null; } - @Override - public long getID() { - return ((ContentNode) currentNode).getID(); - } - @Override public Object[][] getRowValues(int rows) throws SQLException { return ((ContentNode) currentNode).getRowValues(rows); diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java index d1e5016b50..b028299ddb 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java @@ -47,11 +47,6 @@ class SearchNode extends AbstractNode implements ContentNode { return "Search Result"; } - @Override - public long getID() { - return -1; // change this later when needed - } - @Override public Object[][] getRowValues(int rows) throws SQLException { int totalNodes = children.getNodesCount(); From c842c9a6b5606e3f18301ce73f13132fd19e7b96 Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Thu, 8 Dec 2011 17:46:58 -0500 Subject: [PATCH 03/21] Remove ContentNode.getContent() --- .../corecomponents/DataContentViewerHex.java | 11 +- .../DataContentViewerPicture.java | 6 +- .../DataContentViewerString.java | 11 +- .../corecomponents/DataResultViewerTable.java | 85 ++-- .../datamodel/AbstractContentNode.java | 10 - .../autopsy/datamodel/ContentFilterNode.java | 6 - .../autopsy/datamodel/ContentNode.java | 8 - .../directorytree/DataResultFilterNode.java | 20 +- .../DirectoryTreeFilterChildren.java | 7 +- .../directorytree/ExternalViewerAction.java | 16 +- .../autopsy/directorytree/ExtractAction.java | 439 +++++++++--------- .../filesearch/DataResultFilterNode.java | 9 +- .../autopsy/filesearch/SearchNode.java | 7 +- 13 files changed, 306 insertions(+), 329 deletions(-) diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java index c8995a7cfb..beb1b7f292 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java @@ -23,6 +23,7 @@ import java.awt.Cursor; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JTextPane; +import org.openide.nodes.Node; import org.openide.util.lookup.ServiceProvider; import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; @@ -274,10 +275,14 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont @Override public void setNode(ContentNode selectedNode) { if (selectedNode != null) { - this.setDataView(selectedNode.getContent(), 0, false); - } else { - this.setDataView(null, 0, true); + Content content = ((Node) selectedNode).getLookup().lookup(Content.class); + if (content != null) { + this.setDataView(content, 0, false); + return; + } } + + this.setDataView(null, 0, true); } @Override diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java index 5defaf15ef..8beb5dd796 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java @@ -31,6 +31,7 @@ import org.openide.nodes.Node; import org.openide.util.lookup.ServiceProvider; import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; +import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.TskException; /** @@ -90,7 +91,10 @@ public class DataContentViewerPicture extends javax.swing.JPanel implements Data if (selectedNode != null) { try { // read the byte of the image file - byte[] dataSource = selectedNode.getContent().read(0, selectedNode.getContent().getSize()); + + // TODO: ContentNode fix - get rid of cast to Node + Content content = ((Node) selectedNode).getLookup().lookup(Content.class); + byte[] dataSource = content.read(0, content.getSize()); // create the input stream for the content InputStream is = new ByteArrayInputStream(dataSource); diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java index 990ac9ac36..ef8d057895 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java @@ -22,6 +22,7 @@ import java.awt.Component; import java.awt.Cursor; import java.util.logging.Level; import java.util.logging.Logger; +import org.openide.nodes.Node; import org.openide.util.lookup.ServiceProvider; import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; @@ -268,10 +269,14 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC @Override public void setNode(ContentNode selectedNode) { if (selectedNode != null) { - this.setDataView(selectedNode.getContent(), 0, false); - } else { - this.setDataView(null, 0, true); + Content content = ((Node) selectedNode).getLookup().lookup(Content.class); + if (content != null) { + this.setDataView(content, 0, false); + return; + } } + + this.setDataView(null, 0, true); } @Override diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java index 834e2fea30..6fb2cfb202 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java @@ -49,7 +49,6 @@ public class DataResultViewerTable extends AbstractDataResultViewer { private transient ExplorerManager em = new ExplorerManager(); private String firstColumnLabel = "Name"; - private boolean isImageNode; /** Creates new form DataResultViewerTable */ public DataResultViewerTable() { @@ -59,11 +58,10 @@ public class DataResultViewerTable extends AbstractDataResultViewer { // only allow one item to be selected at a time ov.getOutline().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - + // don't show the root node ov.getOutline().setRootVisible(false); - this.isImageNode = false; this.em.addPropertyChangeListener(this); } @@ -98,13 +96,6 @@ public class DataResultViewerTable extends AbstractDataResultViewer { }// //GEN-END:initComponents private void tableScrollPanelComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_tableScrollPanelComponentResized - if (this.tableScrollPanel.getWidth() < 700 && isImageNode) { - ((OutlineView) this.tableScrollPanel).getOutline().setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - } else { - if (isImageNode) { - ((OutlineView) this.tableScrollPanel).getOutline().setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); - } - } }//GEN-LAST:event_tableScrollPanelComponentResized // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JScrollPane tableScrollPanel; @@ -211,53 +202,47 @@ public class DataResultViewerTable extends AbstractDataResultViewer { // show the horizontal scroll panel and show all the content & header - if (!(selectedNode.getContent() instanceof Image)) { - this.isImageNode = false; - int totalColumns = props.length; - //int scrollWidth = ttv.getWidth(); - int scrollWidth = ov.getWidth(); - int minWidth = scrollWidth / totalColumns; - int margin = 4; - int startColumn = 1; - ov.getOutline().setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + int totalColumns = props.length; - // get the fontmetrics - //FontMetrics metrics = ttv.getGraphics().getFontMetrics(); - FontMetrics metrics = ov.getGraphics().getFontMetrics(); + //int scrollWidth = ttv.getWidth(); + int scrollWidth = ov.getWidth(); + int minWidth = scrollWidth / totalColumns; + int margin = 4; + int startColumn = 1; + ov.getOutline().setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - // get first 100 rows values for the table - Object[][] content = null; - try { - content = selectedNode.getRowValues(100); - } catch (SQLException ex) { - // TODO: potential exception is being ignored (see below), should be handled + // get the fontmetrics + //FontMetrics metrics = ttv.getGraphics().getFontMetrics(); + FontMetrics metrics = ov.getGraphics().getFontMetrics(); + + // get first 100 rows values for the table + Object[][] content = null; + try { + content = selectedNode.getRowValues(100); + } catch (SQLException ex) { + // TODO: potential exception is being ignored (see below), should be handled + } + + + if (content != null) { + // for the "Name" column + int nodeColWidth = getMaxColumnWidth(0, metrics, margin, 40, firstColumnLabel, content); // Note: 40 is the width of the icon + node lines. Change this value if those values change! + ov.getOutline().getColumnModel().getColumn(0).setPreferredWidth(nodeColWidth); + + // get the max for each other column + for (int colIndex = startColumn; colIndex < totalColumns; colIndex++) { + int colWidth = getMaxColumnWidth(colIndex, metrics, margin, 8, props, content); + ov.getOutline().getColumnModel().getColumn(colIndex).setPreferredWidth(colWidth); } + } - - if (content != null) { - // for the "Name" column - int nodeColWidth = getMaxColumnWidth(0, metrics, margin, 40, firstColumnLabel, content); // Note: 40 is the width of the icon + node lines. Change this value if those values change! - ov.getOutline().getColumnModel().getColumn(0).setPreferredWidth(nodeColWidth); - - // get the max for each other column - for (int colIndex = startColumn; colIndex < totalColumns; colIndex++) { - int colWidth = getMaxColumnWidth(colIndex, metrics, margin, 8, props, content); - ov.getOutline().getColumnModel().getColumn(colIndex).setPreferredWidth(colWidth); - } - } - - // if there's no content just auto resize all columns - if (!(content.length > 0)) { - // turn on the auto resize - ov.getOutline().setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); - } - } else { - this.isImageNode = true; - // turn on the auto resize for image result - ov.getOutline().getColumnModel().getColumn(0).setPreferredWidth(175); + // if there's no content just auto resize all columns + if (!(content.length > 0)) { + // turn on the auto resize ov.getOutline().setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); } + } else { Node emptyNode = new AbstractNode(Children.LEAF); em.setRootContext(emptyNode); // make empty node diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java index 47f723b406..d3813d1cf8 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java @@ -90,16 +90,6 @@ abstract class AbstractContentNode extends AbstractNode imple return content.read(offset, len); } - /** - * Returns the content of this node. - * - * @return content the content of this node (can be image, volume, directory, or file) - */ - @Override - public Content getContent() { - return content; - } - private static final ShortNameVisitor shortName = new ShortNameVisitor(); private static final GetPathVisitor getDisplayPath = new GetPathVisitor(shortName); diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java index 28d8646259..218439d4e2 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java @@ -22,7 +22,6 @@ import java.sql.SQLException; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; import org.openide.util.Lookup; -import org.sleuthkit.datamodel.Content; public class ContentFilterNode extends FilterNode implements ContentNode { @@ -43,11 +42,6 @@ public class ContentFilterNode extends FilterNode implements ContentNode { return ((ContentNode) super.getOriginal()).getRowValues(rows); } - @Override - public Content getContent() { - return ((ContentNode) super.getOriginal()).getContent(); - } - @Override public String[] getDisplayPath() { return ((ContentNode) super.getOriginal()).getDisplayPath(); diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java index ddac749e84..8e780143a1 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java @@ -19,7 +19,6 @@ package org.sleuthkit.autopsy.datamodel; import java.sql.SQLException; -import org.sleuthkit.datamodel.Content; /** * Interface class that all Data nodes inherit from. @@ -38,13 +37,6 @@ public interface ContentNode { */ public Object[][] getRowValues(int rows) throws SQLException; - /** - * Returns the content of this node. - * - * @return content the content of this node (can be image, volume, directory, or file) - */ - public Content getContent(); - /** * Returns full path to this node. * diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java index b602d53c7d..b87f3dddba 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java @@ -74,27 +74,34 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { List actions = new ArrayList(); + // TODO: ContentNode fix - restore right-click actions + // TODO: ContentVisitor instead of instanceof + + Content nodeContent = this.currentNode.getLookup().lookup(Content.class); + // right click action(s) for image node if (this.currentNode instanceof ImageNode) { actions.add(new NewWindowViewAction("View in New Window", (ImageNode) this.currentNode)); - actions.addAll(ShowDetailActionVisitor.getActions(((ImageNode) this.currentNode).getContent())); + actions.addAll(ShowDetailActionVisitor.getActions(nodeContent)); } // right click action(s) for volume node else if (this.currentNode instanceof VolumeNode) { actions.add(new NewWindowViewAction("View in New Window", (VolumeNode) this.currentNode)); //new ShowDetailActionVisitor("Volume Details", this.currentNode.getName(), (VolumeNode) this.currentNode), - actions.addAll(ShowDetailActionVisitor.getActions(((VolumeNode) this.currentNode).getContent())); + actions.addAll(ShowDetailActionVisitor.getActions(nodeContent)); actions.add(new ChangeViewAction("View", 0, (ContentNode) currentNode)); } // right click action(s) for directory node else if (this.currentNode instanceof DirectoryNode) { actions.add(new NewWindowViewAction("View in New Window", (DirectoryNode) this.currentNode)); actions.add(new ChangeViewAction("View", 0, (ContentNode) currentNode)); - actions.add(new ExtractAction("Extract Directory", (DirectoryNode) this.currentNode)); + // TODO: ContentNode fix - reimplement ExtractAction + //actions.add(new ExtractAction("Extract Directory", (DirectoryNode) this.currentNode)); } // right click action(s) for the file node else if (this.currentNode instanceof FileNode) { actions.add(new ExternalViewerAction("Open File in External Viewer", (FileNode) this.currentNode)); actions.add(new NewWindowViewAction("View in New Window", (FileNode) this.currentNode)); - actions.add(new ExtractAction("Extract", (FileNode) this.currentNode)); + // TODO: ContentNode fix - reimplement ExtractAction + //actions.add(new ExtractAction("Extract", (FileNode) this.currentNode)); actions.add(new ChangeViewAction("View", 0, (ContentNode) currentNode)); } @@ -194,11 +201,6 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { return ((ContentNode) currentNode).getRowValues(rows); } - @Override - public Content getContent() { - return ((ContentNode) currentNode).getContent(); - } - @Override public String[] getDisplayPath() { return ((ContentNode) currentNode).getDisplayPath(); diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterChildren.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterChildren.java index 8f365354e4..e9464e3e94 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterChildren.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterChildren.java @@ -46,11 +46,14 @@ class DirectoryTreeFilterChildren extends FilterNode.Children { @Override protected Node[] createNodes(Node arg0) { + + //TODO: ContentNode fix - replace with ContentVisitor + // filter out the FileNode and the "." and ".." directories if (arg0 != null && (arg0 instanceof ImageNode || arg0 instanceof VolumeNode || (arg0 instanceof DirectoryNode - && !((Directory) ((DirectoryNode) arg0).getContent()).getName().equals(".") - && !((Directory) ((DirectoryNode) arg0).getContent()).getName().equals("..")))) { + && !((DirectoryNode) arg0).getDisplayName().equals(".")) + && !((DirectoryNode) arg0).getDisplayName().equals(".."))) { return new Node[]{this.copyNode(arg0)}; } else { return new Node[]{}; diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java index 8b149605d7..8051055ee2 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java @@ -30,8 +30,8 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import org.openide.nodes.Node; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.datamodel.FileNode; import org.sleuthkit.autopsy.logging.Log; +import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.TskException; /** @@ -41,7 +41,7 @@ import org.sleuthkit.datamodel.TskException; public class ExternalViewerAction extends AbstractAction { private byte[] content; - private FileNode fileNode; + private Content contentObject; private String fileName; private String extension; // for error handling @@ -49,12 +49,12 @@ public class ExternalViewerAction extends AbstractAction { private String className = this.getClass().toString(); /** the constructor */ - public ExternalViewerAction(String title, FileNode fileNode) { + public ExternalViewerAction(String title, Node fileNode) { super(title); - this.fileNode = fileNode; + this.contentObject = fileNode.getLookup().lookup(Content.class); - long size = fileNode.getContent().getSize(); - String fullFileName = ((Node)fileNode).getDisplayName(); + long size = contentObject.getSize(); + String fullFileName = fileNode.getDisplayName(); if (fullFileName.contains(".") && size > 0) { String tempFileName = fullFileName.substring(0, fullFileName.indexOf(".")); String tempExtension = fullFileName.substring(fullFileName.indexOf(".")); @@ -63,7 +63,7 @@ public class ExternalViewerAction extends AbstractAction { } else { this.fileName = fullFileName; this.extension = ""; - this.setEnabled(false); // fix this later (right now only extract a file with extension) + this.setEnabled(false); //TODO: fix this later (right now only extract a file with extension) } } @@ -77,7 +77,7 @@ public class ExternalViewerAction extends AbstractAction { // the menu should be disabled if we can't read the content (for example: on zero-sized file). // Therefore, it should never throw the TSKException. try { - this.content = fileNode.getContent().read(0, fileNode.getContent().getSize()); + this.content = contentObject.read(0, contentObject.getSize()); } catch (TskException ex) { Logger.getLogger(this.className).log(Level.WARNING, "Error: can't read the content of the file.", ex); } diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExtractAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExtractAction.java index d1c4adf529..546fe65d65 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExtractAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExtractAction.java @@ -1,218 +1,225 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.directorytree; - -import org.sleuthkit.autopsy.datamodel.FileNode; -import java.io.*; -import java.awt.event.ActionEvent; -import javax.swing.JFileChooser; -import java.io.File; -import java.awt.Component; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.AbstractAction; -import javax.swing.JPanel; -import javax.swing.filechooser.FileFilter; -import org.openide.nodes.Node; -import org.sleuthkit.autopsy.casemodule.GeneralFilter; -import org.sleuthkit.autopsy.datamodel.ContentNode; -import org.sleuthkit.autopsy.datamodel.DirectoryNode; -import org.sleuthkit.autopsy.logging.Log; -import org.sleuthkit.datamodel.TskException; - -/** - * This is an action class to extract and save the bytes given as a file. - * - * @author jantonius - */ -public final class ExtractAction extends AbstractAction { - - private JFileChooser fc = new JFileChooser(); - private byte[] source; - private ContentNode contentNode; - private String fileName; - private String extension; - // for error handling - private JPanel caller; - private String className = this.getClass().toString(); - - /** the constructor */ - public ExtractAction(String title, ContentNode contentNode) { - super(title); - - String fullFileName = ((Node)contentNode).getDisplayName(); - - if (fullFileName.equals(".")) { - // . folders are not associated with their children in the database, - // so get original - Node parentNode = ((Node) contentNode).getParentNode(); - this.contentNode = (ContentNode) parentNode; - fullFileName = parentNode.getDisplayName(); - } else { - this.contentNode = contentNode; - } - long size = contentNode.getContent().getSize(); - +// TODO: ContentNode fix - reimplement ExtractAction - /** - * Checks first if the the selected it file or directory. If it's a file, - * check if the file size is bigger than 0. If it's a directory, check - * if it's not referring to the parent directory. Disables the menu otherwise. - */ - if ((contentNode instanceof FileNode && size > 0) || (contentNode instanceof DirectoryNode && !fullFileName.equals(".."))) { - if (contentNode instanceof FileNode && fullFileName.contains(".")) { - String tempFileName = fullFileName.substring(0, fullFileName.indexOf(".")); - String tempExtension = fullFileName.substring(fullFileName.indexOf(".")); - this.fileName = tempFileName; - this.extension = tempExtension; - } else { - this.fileName = fullFileName; - this.extension = ""; - } - } else { - this.fileName = fullFileName; - this.extension = ""; - this.setEnabled(false); // can't extract zero-sized file or ".." directory - } - - } - - /** - * Converts and saves the bytes into the file. - * - * @param e the action event - */ - @Override - public void actionPerformed(ActionEvent e) { - Log.noteAction(this.getClass()); - - // set the filter for FileNode - if (contentNode instanceof FileNode && !extension.equals("")) { - //FileFilter filter = new ExtensionFileFilter(extension.substring(1).toUpperCase() + " File (*" + extension + ")", new String[]{extension.substring(1)}); - String[] fileExt = {extension}; - FileFilter filter = new GeneralFilter(fileExt, extension.substring(1).toUpperCase() + " File (*" + extension + ")", false); - fc.setFileFilter(filter); - } - - - fc.setSelectedFile(new File(this.fileName)); - - int returnValue = fc.showSaveDialog((Component) e.getSource()); - if (returnValue == JFileChooser.APPROVE_OPTION) { - String path = fc.getSelectedFile().getPath() + extension; - - try { - // file extraction - if (contentNode instanceof FileNode) { - extractFile(path, (FileNode) contentNode); - } - - // directory extraction - if (contentNode instanceof DirectoryNode) { - extractDirectory(path, (DirectoryNode) contentNode); - } - } catch (Exception ex) { - Logger.getLogger(this.className).log(Level.WARNING, "Error: Couldn't extract file/directory.", ex); - } - - } - - } - - /** - * Extracts the content of the given fileNode into the given path. - * - * @param givenPath the path to extract the file - * @param fileNode the file node that contain the file - */ - private void extractFile(String givenPath, FileNode fileNode) throws Exception { - try { - if (fileNode.getContent().getSize() > 0) { - try { - this.source = fileNode.getContent().read(0, fileNode.getContent().getSize()); - } catch (TskException ex) { - throw new Exception("Error: can't read the content of the file.", ex); - } - } else { - this.source = new byte[0]; - } - - String path = givenPath; - - File file = new File(path); - if (file.exists()) { - file.delete(); - } - file.createNewFile(); - // convert char to byte - byte[] dataSource = new byte[source.length]; - for (int i = 0; i < source.length; i++) { - dataSource[i] = (byte) source[i]; - } - FileOutputStream fos = new FileOutputStream(file); - //fos.write(dataSource); - fos.write(dataSource); - fos.close(); - } catch (IOException ex) { - throw new Exception("Error while trying to extract the file.", ex); - } - } - - /** - * Extracts the content of the given directoryNode into the given path. - * - * @param givenPath the path to extract the directory - * @param dirNode the directory node that contain the directory - */ - private void extractDirectory(String givenPath, DirectoryNode dirNode) throws Exception { - String path = givenPath; - File dir = new File(path); - if (!dir.exists()) { - dir.mkdir(); - } - - int totalChildren = dirNode.getChildren().getNodesCount(); - for (int i = 0; i < totalChildren; i++) { - Node childNode = dirNode.getChildren().getNodeAt(i); - - if (childNode instanceof FileNode) { - FileNode fileNode = (FileNode) childNode; - String tempPath = path + File.separator + ((Node)fileNode).getDisplayName(); - try { - extractFile(tempPath, fileNode); - } catch (Exception ex) { - throw ex; - } - } - - if (childNode instanceof DirectoryNode) { - DirectoryNode dirNode2 = (DirectoryNode) childNode; - String dirNode2Name = ((Node)dirNode2).getDisplayName(); - - if (!dirNode2Name.trim().equals(".") && !dirNode2Name.trim().equals("..")) { - String tempPath = path + File.separator + dirNode2Name; - extractDirectory(tempPath, dirNode2); - } - } - } - - - } -} +///* +// * Autopsy Forensic Browser +// * +// * Copyright 2011 Basis Technology Corp. +// * Contact: carrier sleuthkit 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. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// */ +//package org.sleuthkit.autopsy.directorytree; +// +//import org.sleuthkit.autopsy.datamodel.FileNode; +//import java.io.*; +//import java.awt.event.ActionEvent; +//import javax.swing.JFileChooser; +//import java.io.File; +//import java.awt.Component; +//import java.util.logging.Level; +//import java.util.logging.Logger; +//import javax.swing.AbstractAction; +//import javax.swing.JPanel; +//import javax.swing.filechooser.FileFilter; +//import org.openide.nodes.Node; +//import org.sleuthkit.autopsy.casemodule.GeneralFilter; +//import org.sleuthkit.autopsy.datamodel.DirectoryNode; +//import org.sleuthkit.autopsy.logging.Log; +//import org.sleuthkit.datamodel.Content; +//import org.sleuthkit.datamodel.TskException; +// +///** +// * This is an action class to extract and save the bytes given as a file. +// * +// * @author jantonius +// */ +//public final class ExtractAction extends AbstractAction { +// +// private JFileChooser fc = new JFileChooser(); +// private byte[] source; +// private Content content; +// private String fileName; +// private String extension; +// // for error handling +// private JPanel caller; +// private String className = this.getClass().toString(); +// +// /** the constructor */ +// public ExtractAction(String title, Node contentNode) { +// super(title); +// +// String fullFileName = contentNode.getDisplayName(); +// +// +// if (fullFileName.equals(".")) { +// // . folders are not associated with their children in the database, +// // so get original +// Node parentNode = contentNode.getParentNode(); +// contentNode = parentNode; +// fullFileName = parentNode.getDisplayName(); +// } +// +// +// this.content = contentNode.getLookup().lookup(Content.class); +// +// long size = content.getSize(); +// +// +// +// /** +// * Checks first if the the selected it file or directory. If it's a file, +// * check if the file size is bigger than 0. If it's a directory, check +// * if it's not referring to the parent directory. Disables the menu otherwise. +// */ +// if ((contentNode instanceof FileNode && size > 0) || (contentNode instanceof DirectoryNode && !fullFileName.equals(".."))) { +// if (contentNode instanceof FileNode && fullFileName.contains(".")) { +// String tempFileName = fullFileName.substring(0, fullFileName.indexOf(".")); +// String tempExtension = fullFileName.substring(fullFileName.indexOf(".")); +// this.fileName = tempFileName; +// this.extension = tempExtension; +// } else { +// this.fileName = fullFileName; +// this.extension = ""; +// } +// } else { +// this.fileName = fullFileName; +// this.extension = ""; +// this.setEnabled(false); // can't extract zero-sized file or ".." directory +// } +// +// } +// +// /** +// * Converts and saves the bytes into the file. +// * +// * @param e the action event +// */ +// @Override +// public void actionPerformed(ActionEvent e) { +// Log.noteAction(this.getClass()); +// +// // set the filter for File +// if (content instanceof org.sleuthkit.datamodel.File && !extension.equals("")) { +// //FileFilter filter = new ExtensionFileFilter(extension.substring(1).toUpperCase() + " File (*" + extension + ")", new String[]{extension.substring(1)}); +// String[] fileExt = {extension}; +// FileFilter filter = new GeneralFilter(fileExt, extension.substring(1).toUpperCase() + " File (*" + extension + ")", false); +// fc.setFileFilter(filter); +// } +// +// fc.setSelectedFile(new File(this.fileName)); +// +// int returnValue = fc.showSaveDialog((Component) e.getSource()); +// if (returnValue == JFileChooser.APPROVE_OPTION) { +// String path = fc.getSelectedFile().getPath() + extension; +// +// +// // TODO: convert this to a Content Visitor +// try { +// // file extraction +// if (content instanceof org.sleuthkit.datamodel.File) { +// extractFile(path, (org.sleuthkit.datamodel.File) content); +// } +// +// // directory extraction +// if (content instanceof org.sleuthkit.datamodel.File) { +// extractDirectory(path, (org.sleuthkit.datamodel.Directory) content); +// } +// } catch (Exception ex) { +// Logger.getLogger(this.className).log(Level.WARNING, "Error: Couldn't extract file/directory.", ex); +// } +// +// } +// +// } +// +// /** +// * Extracts the content of the given fileNode into the given path. +// * +// * @param givenPath the path to extract the file +// * @param file the file node that contain the file +// */ +// private void extractFile(String givenPath, org.sleuthkit.datamodel.File file) throws Exception { +// try { +// if (file.getSize() > 0) { +// try { +// this.source = file.read(0, file.getSize()); +// } catch (TskException ex) { +// throw new Exception("Error: can't read the content of the file.", ex); +// } +// } else { +// this.source = new byte[0]; +// } +// +// String path = givenPath; +// +// File outputFile = new File(path); +// if (outputFile.exists()) { +// outputFile.delete(); +// } +// outputFile.createNewFile(); +// // convert char to byte +// byte[] dataSource = new byte[source.length]; +// for (int i = 0; i < source.length; i++) { +// dataSource[i] = (byte) source[i]; +// } +// FileOutputStream fos = new FileOutputStream(outputFile); +// //fos.write(dataSource); +// fos.write(dataSource); +// fos.close(); +// } catch (IOException ex) { +// throw new Exception("Error while trying to extract the file.", ex); +// } +// } +// +// /** +// * Extracts the content of the given directoryNode into the given path. +// * +// * @param givenPath the path to extract the directory +// * @param dirNode the directory node that contain the directory +// */ +// private void extractDirectory(String givenPath, DirectoryNode dirNode) throws Exception { +// String path = givenPath; +// File dir = new File(path); +// if (!dir.exists()) { +// dir.mkdir(); +// } +// +// int totalChildren = dirNode.getChildren().getNodesCount(); +// for (int i = 0; i < totalChildren; i++) { +// Node childNode = dirNode.getChildren().getNodeAt(i); +// +// if (childNode instanceof FileNode) { +// FileNode fileNode = (FileNode) childNode; +// String tempPath = path + File.separator + ((Node)fileNode).getDisplayName(); +// try { +// extractFile(tempPath, fileNode); +// } catch (Exception ex) { +// throw ex; +// } +// } +// +// if (childNode instanceof DirectoryNode) { +// DirectoryNode dirNode2 = (DirectoryNode) childNode; +// String dirNode2Name = ((Node)dirNode2).getDisplayName(); +// +// if (!dirNode2Name.trim().equals(".") && !dirNode2Name.trim().equals("..")) { +// String tempPath = path + File.separator + dirNode2Name; +// extractDirectory(tempPath, dirNode2); +// } +// } +// } +// +// +// } +//} diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java index f2d82431e2..61bf67f917 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java @@ -28,7 +28,6 @@ import java.sql.SQLException; import javax.swing.Action; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; -import org.sleuthkit.datamodel.Content; import org.sleuthkit.autopsy.directorytree.ChangeViewAction; /** @@ -74,7 +73,8 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { } // right click action(s) for the file node else if (this.currentNode instanceof FileNode) { return new Action[]{ - new ExtractAction("Extract", (FileNode) this.currentNode), + // TODO: ContentNode fix - reimplement ExtractAction + // new ExtractAction("Extract", (FileNode) this.currentNode), new ChangeViewAction("View", 0, (ContentNode) currentNode), new OpenParentFolderAction("Open Parent Directory", ((ContentNode) currentNode).getSystemPath()) }; @@ -99,11 +99,6 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { return ((ContentNode) currentNode).getRowValues(rows); } - @Override - public Content getContent() { - return ((ContentNode) currentNode).getContent(); - } - @Override public String[] getDisplayPath() { return ((ContentNode) currentNode).getDisplayPath(); diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java index b028299ddb..867ec67e41 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java @@ -77,12 +77,7 @@ class SearchNode extends AbstractNode implements ContentNode { } return objs; } - - @Override - public Content getContent() { - return null; - } - + @Override public String[] getDisplayPath() { return new String[]{"KeyWord Search Result:"}; From f66d92ff331b7133638493f0106b890540326293 Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Thu, 8 Dec 2011 18:46:43 -0500 Subject: [PATCH 04/21] Remove ContentNode.getRowValues(), .getDisplayPath(), and .getSystemPath() --- .../DataContentTopComponent.java | 5 +- .../DataResultTopComponent.java | 4 +- .../corecomponents/DataResultViewerTable.java | 37 +++- .../datamodel/AbstractContentNode.java | 151 +-------------- .../datamodel/AbstractFsContentNode.java | 2 +- .../autopsy/datamodel/ContentFilterNode.java | 16 -- .../autopsy/datamodel/ContentNode.java | 27 --- .../autopsy/datamodel/ContentUtils.java | 173 ++++++++++++++++++ .../autopsy/datamodel/DirectoryNode.java | 34 ---- .../sleuthkit/autopsy/datamodel/FileNode.java | 52 +++--- .../autopsy/datamodel/ImageNode.java | 28 --- .../autopsy/datamodel/VolumeNode.java | 35 ---- .../directorytree/DataResultFilterNode.java | 16 -- .../directorytree/NewWindowViewAction.java | 5 +- .../filesearch/DataResultFilterNode.java | 22 +-- .../autopsy/filesearch/SearchNode.java | 45 ----- 16 files changed, 245 insertions(+), 407 deletions(-) create mode 100644 DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java index 080a354f73..774a89235d 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java @@ -26,6 +26,7 @@ import java.util.logging.Logger; import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import org.openide.nodes.Node; import org.openide.util.NbBundle; import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; @@ -34,7 +35,9 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContent; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; +import org.sleuthkit.autopsy.datamodel.ContentUtils; import org.sleuthkit.autopsy.datamodel.DataConversion; +import org.sleuthkit.datamodel.Content; /** * Top component that organizes all of the data content viewers. Doing a lookup on this class will @@ -227,7 +230,7 @@ public final class DataContentTopComponent extends TopComponent implements DataC if (selectedNode == null) { setName(NbBundle.getMessage(DataContentTopComponent.class, "CTL_DataContentTopComponent")); } else { - String path = DataConversion.getformattedPath(selectedNode.getDisplayPath(), 0); + String path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(((Node) selectedNode).getLookup().lookup(Content.class)), 0); setName(path); } diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java index f893aa22c6..db4dd7a754 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java @@ -34,7 +34,9 @@ import org.openide.util.Lookup; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataResultViewer; +import org.sleuthkit.autopsy.datamodel.ContentUtils; import org.sleuthkit.autopsy.datamodel.DataConversion; +import org.sleuthkit.datamodel.Content; /** * Top component which displays something. @@ -287,7 +289,7 @@ public final class DataResultTopComponent extends TopComponent implements DataRe this.rootNode = selectedNode; String path = ""; if (selectedNode != null) { - path = DataConversion.getformattedPath(selectedNode.getDisplayPath(), 0); + path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(((Node) selectedNode).getLookup().lookup(Content.class)), 0); int childrenCount = ((Node) selectedNode).getChildren().getNodesCount(true); this.numberMatchLabel.setText(Integer.toString(childrenCount)); diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java index 6fb2cfb202..94b3f2f1ec 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java @@ -22,7 +22,7 @@ import java.awt.Component; import java.awt.Cursor; import java.awt.FontMetrics; import java.io.IOException; -import java.sql.SQLException; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -33,13 +33,13 @@ import org.openide.explorer.view.OutlineView; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; +import org.openide.nodes.Node.Property; import org.openide.nodes.Node.PropertySet; import org.openide.nodes.Sheet; import org.openide.util.lookup.ServiceProvider; import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataResultViewer; // TODO We should not have anything specific to Image in here... -import org.sleuthkit.datamodel.Image; /** * DataResult sortable table viewer @@ -218,11 +218,8 @@ public class DataResultViewerTable extends AbstractDataResultViewer { // get first 100 rows values for the table Object[][] content = null; - try { - content = selectedNode.getRowValues(100); - } catch (SQLException ex) { - // TODO: potential exception is being ignored (see below), should be handled - } + //TODO: ContentNode fix - remove cast to node + content = getRowValues((Node) selectedNode, 100); if (content != null) { @@ -253,6 +250,32 @@ public class DataResultViewerTable extends AbstractDataResultViewer { this.setCursor(null); } } + + + private static Object[][] getRowValues(Node node, int rows) { + // how many rows are we returning + int maxRows = Math.min(rows, node.getChildren().getNodesCount()); + + Object[][] objs = new Object[maxRows][]; + + for (int i = 0; i < maxRows; i++) { + PropertySet[] props = node.getChildren().getNodeAt(i).getPropertySets(); + Property[] property = props[0].getProperties(); + objs[i] = new Object[property.length]; + + + for (int j = 0; j < property.length; j++) { + try { + objs[i][j] = property[j].getValue(); + } catch (IllegalAccessException ignore) { + objs[i][j] = "n/a"; + } catch (InvocationTargetException ignore) { + objs[i][j] = "n/a"; + } + } + } + return objs; + } @Override public String getTitle() { diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java index d3813d1cf8..07c437892f 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java @@ -20,20 +20,10 @@ package org.sleuthkit.autopsy.datamodel; -import java.sql.SQLException; -import java.util.LinkedList; -import java.util.List; import org.openide.nodes.AbstractNode; import org.openide.util.lookup.Lookups; import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.ContentVisitor; -import org.sleuthkit.datamodel.Directory; -import org.sleuthkit.datamodel.File; -import org.sleuthkit.datamodel.FileSystem; -import org.sleuthkit.datamodel.Image; import org.sleuthkit.datamodel.TskException; -import org.sleuthkit.datamodel.Volume; -import org.sleuthkit.datamodel.VolumeSystem; /** * Interface class that all Data nodes inherit from. @@ -53,7 +43,7 @@ abstract class AbstractContentNode extends AbstractNode imple AbstractContentNode(T content) { super(new ContentChildren(content), Lookups.singleton(content)); this.content = content; - super.setName(content.accept(systemName)); + super.setName(ContentUtils.getSystemName(content)); } @Override @@ -66,18 +56,6 @@ abstract class AbstractContentNode extends AbstractNode imple return super.getName(); } - /** - * Gets the row values for this node. The main purpose of this method is to - * get the 'x' number of the row values for this node to set the width of each - * column of the DataResult Table. Row values is the children and it's properties. - * - * @param rows the number of rows we want to show - * @return rowValues the row values for this node. - * @throws SQLException - */ - @Override - abstract public Object[][] getRowValues(int rows) throws SQLException; - /** * Reads the content of this node. * @@ -89,131 +67,4 @@ abstract class AbstractContentNode extends AbstractNode imple public byte[] read(long offset, long len) throws TskException { return content.read(offset, len); } - - private static final ShortNameVisitor shortName = new ShortNameVisitor(); - - private static final GetPathVisitor getDisplayPath = new GetPathVisitor(shortName); - - /** - * Returns full path to this node. - * - * @return the path of this node - */ - @Override - public String[] getDisplayPath() { - return content.accept(getDisplayPath).toArray(new String[]{}); - } - - private static final SystemNameVisitor systemName = new SystemNameVisitor(); - - private static final GetPathVisitor getSystemPath = new GetPathVisitor(systemName); - - /** - * Returns full path to this node. - * - * @return the path of this node - */ - @Override - public String[] getSystemPath() { - return content.accept(getSystemPath).toArray(new String[]{}); - } - - private static class SystemNameVisitor extends ContentVisitor.Default { - SystemNameVisitor() {} - - @Override - protected String defaultVisit(Content cntnt) { - return cntnt.accept(shortName) + ":" + Long.toString(cntnt.getId()); - } - } - - private static class ShortNameVisitor extends ContentVisitor.Default { - ShortNameVisitor() {} - - @Override - protected String defaultVisit(Content cntnt) { - throw new UnsupportedOperationException("Can't get short name for given content type:" + cntnt.getClass()); - } - - @Override - public String visit(Directory dir) { - return DirectoryNode.nameForDirectory(dir); - } - - @Override - public String visit(File f) { - return FileNode.nameForFile(f); - } - - @Override - public String visit(Volume v) { - return VolumeNode.nameForVolume(v); - } - - @Override - public String visit(Image i) { - return ImageNode.nameForImage(i); - } - } - - private static class GetPathVisitor implements ContentVisitor> { - ContentVisitor toString; - - GetPathVisitor(ContentVisitor toString) { - this.toString = toString; - } - - @Override - public List visit(Directory dir) { - List path; - - if (dir.isRoot()) { - path = dir.getFileSystem().accept(this); - } else { - try { - path = dir.getParentDirectory().accept(this); - path.add(toString.visit(dir)); - } catch (TskException ex) { - throw new RuntimeException("Couldn't get directory path.", ex); - } - } - - return path; - } - - @Override - public List visit(File file) { - try { - List path = file.getParentDirectory().accept(this); - path.add(toString.visit(file)); - return path; - } catch (TskException ex) { - throw new RuntimeException("Couldn't get file path.", ex); - } - } - - @Override - public List visit(FileSystem fs) { - return fs.getParent().accept(this); - } - - @Override - public List visit(Image image) { - List path = new LinkedList(); - path.add(toString.visit(image)); - return path; - } - - @Override - public List visit(Volume volume) { - List path = volume.getParent().accept(this); - path.add(toString.visit(volume)); - return path; - } - - @Override - public List visit(VolumeSystem vs) { - return vs.getParent().accept(this); - } - } } diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractFsContentNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractFsContentNode.java index 4ab314bb2b..0cd4d2bca5 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractFsContentNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractFsContentNode.java @@ -51,7 +51,7 @@ abstract class AbstractFsContentNode extends AbstractConten // Note: this order matters for the search result, changed it if the order of property headers on the "KeywordSearchNode"changed ss.put(new NodeProperty(PROPERTY_NAME, "Name", "no description", content.getName())); - ss.put(new NodeProperty(PROPERTY_LOCATION, "Location", "no description", DataConversion.getformattedPath(this.getDisplayPath(), 0))); + ss.put(new NodeProperty(PROPERTY_LOCATION, "Location", "no description", DataConversion.getformattedPath(ContentUtils.getDisplayPath(content), 0))); ss.put(new NodeProperty("Modified Time", "Modified Time", "no description", content.getMtimeAsDate())); ss.put(new NodeProperty("Changed Time", "Changed Time", "no description", content.getCtimeAsDate())); ss.put(new NodeProperty("Access Time", "Access Time", "no description", content.getAtimeAsDate())); diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java index 218439d4e2..b3070beea6 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.datamodel; -import java.sql.SQLException; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; import org.openide.util.Lookup; @@ -37,21 +36,6 @@ public class ContentFilterNode extends FilterNode implements ContentNode { super((Node) original, children, lookup); } - @Override - public Object[][] getRowValues(int rows) throws SQLException { - return ((ContentNode) super.getOriginal()).getRowValues(rows); - } - - @Override - public String[] getDisplayPath() { - return ((ContentNode) super.getOriginal()).getDisplayPath(); - } - - @Override - public String[] getSystemPath() { - return ((ContentNode) super.getOriginal()).getSystemPath(); - } - @Override public T accept(ContentNodeVisitor v) { return ((ContentNode) super.getOriginal()).accept(v); diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java index 8e780143a1..967ef63aef 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java @@ -18,39 +18,12 @@ */ package org.sleuthkit.autopsy.datamodel; -import java.sql.SQLException; - /** * Interface class that all Data nodes inherit from. * Provides basic information such as ID, parent ID, etc. */ public interface ContentNode { - /** - * Gets the row values for this node. The main purpose of this method is to - * get the 'x' number of the row values for this node to set the width of each - * column of the DataResult Table. Row values is the children and it's properties. - * - * @param rows the number of rows we want to show - * @return rowValues the row values for this node. - * @throws SQLException - */ - public Object[][] getRowValues(int rows) throws SQLException; - - /** - * Returns full path to this node. - * - * @return the path of this node - */ - public String[] getDisplayPath(); - - /** - * Returns full path to this node. - * - * @return the path of this node - */ - public String[] getSystemPath(); - /** * Visitor pattern support. * diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java new file mode 100644 index 0000000000..d4d9d23a2a --- /dev/null +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java @@ -0,0 +1,173 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2011 Basis Technology Corp. + * Contact: carrier sleuthkit 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.sleuthkit.autopsy.datamodel; + +import java.util.LinkedList; +import java.util.List; +import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.ContentVisitor; +import org.sleuthkit.datamodel.Directory; +import org.sleuthkit.datamodel.File; +import org.sleuthkit.datamodel.FileSystem; +import org.sleuthkit.datamodel.Image; +import org.sleuthkit.datamodel.TskException; +import org.sleuthkit.datamodel.Volume; +import org.sleuthkit.datamodel.VolumeSystem; + +/** + * Static class of + */ +public final class ContentUtils { + + // don't instantiate + private ContentUtils() { + throw new AssertionError(); + } + + private static final ShortNameVisitor shortName = new ShortNameVisitor(); + + private static final GetPathVisitor getDisplayPath = new GetPathVisitor(shortName); + + /** + * Returns full path to this node. + * + * @return the path of this node + */ + public static String[] getDisplayPath(Content content) { + return content.accept(getDisplayPath).toArray(new String[]{}); + } + + private static final SystemNameVisitor systemName = new SystemNameVisitor(); + + private static final GetPathVisitor getSystemPath = new GetPathVisitor(systemName); + + /** + * Returns full path to this node. + * + * @return the path of this node + */ + public static String[] getSystemPath(Content content) { + return content.accept(getSystemPath).toArray(new String[]{}); + } + + static String getSystemName(Content content) { + return content.accept(systemName); + } + + private static class SystemNameVisitor extends ContentVisitor.Default { + SystemNameVisitor() {} + + @Override + protected String defaultVisit(Content cntnt) { + return cntnt.accept(shortName) + ":" + Long.toString(cntnt.getId()); + } + } + + private static class ShortNameVisitor extends ContentVisitor.Default { + ShortNameVisitor() {} + + @Override + protected String defaultVisit(Content cntnt) { + throw new UnsupportedOperationException("Can't get short name for given content type:" + cntnt.getClass()); + } + + @Override + public String visit(Directory dir) { + return DirectoryNode.nameForDirectory(dir); + } + + @Override + public String visit(File f) { + return FileNode.nameForFile(f); + } + + @Override + public String visit(Volume v) { + return VolumeNode.nameForVolume(v); + } + + @Override + public String visit(Image i) { + return ImageNode.nameForImage(i); + } + } + + private static class GetPathVisitor implements ContentVisitor> { + ContentVisitor toString; + + GetPathVisitor(ContentVisitor toString) { + this.toString = toString; + } + + @Override + public List visit(Directory dir) { + List path; + + if (dir.isRoot()) { + path = dir.getFileSystem().accept(this); + } else { + try { + path = dir.getParentDirectory().accept(this); + path.add(toString.visit(dir)); + } catch (TskException ex) { + throw new RuntimeException("Couldn't get directory path.", ex); + } + } + + return path; + } + + @Override + public List visit(File file) { + try { + List path = file.getParentDirectory().accept(this); + path.add(toString.visit(file)); + return path; + } catch (TskException ex) { + throw new RuntimeException("Couldn't get file path.", ex); + } + } + + @Override + public List visit(FileSystem fs) { + return fs.getParent().accept(this); + } + + @Override + public List visit(Image image) { + List path = new LinkedList(); + path.add(toString.visit(image)); + return path; + } + + @Override + public List visit(Volume volume) { + List path = volume.getParent().accept(this); + path.add(toString.visit(volume)); + return path; + } + + @Override + public List visit(VolumeSystem vs) { + return vs.getParent().accept(this); + } + } + +} diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/DirectoryNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/DirectoryNode.java index 38d8622a0d..5c58b674a7 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/DirectoryNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/DirectoryNode.java @@ -66,40 +66,6 @@ public class DirectoryNode extends AbstractFsContentNode { return new Action[]{}; } - @Override - public Object[][] getRowValues(int rows) { - - // how many rows are we returning - int maxRows = rows; - if (this.getChildren().getNodesCount() < maxRows) { - maxRows = this.getChildren().getNodesCount(); - } - Object[][] objs = new Object[maxRows][]; - - for (int i = 0; i < maxRows; i++) { - PropertySet[] props = this.getChildren().getNodeAt(i).getPropertySets(); - Property[] property = props[0].getProperties(); - objs[i] = new Object[property.length - 1]; // - 1 because we don't want to show the location property - - // name property - try { - objs[i][0] = property[0].getValue(); - } catch (Exception ex) { - objs[i][0] = "n/a"; - } - - // the rest of the properties(not including the location property) - for (int j = 1; j < property.length - 1; j++) { - try { - objs[i][j] = property[j + 1].getValue(); - } catch (Exception ex) { - objs[i][j] = "n/a"; - } - } - } - return objs; - } - @Override public T accept(ContentNodeVisitor v) { return v.visit(this); diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/FileNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/FileNode.java index 0d7605d88c..1ee0e17ec8 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/FileNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/FileNode.java @@ -18,11 +18,8 @@ */ package org.sleuthkit.autopsy.datamodel; -import java.sql.SQLException; -import java.util.Arrays; import javax.swing.Action; import org.sleuthkit.datamodel.File; -import org.sleuthkit.datamodel.FsContent; import org.sleuthkit.datamodel.TskData; /** @@ -70,30 +67,31 @@ public class FileNode extends AbstractFsContentNode { return new Action[]{}; } - @Override - public Object[][] getRowValues(int rows) throws SQLException { - FsContent con = content; - Object[][] objs = new Object[1][16]; - Arrays.fill(objs, 0, 1, new Object[]{ - con.getName(), - con.getMtimeAsDate(), - con.getCtimeAsDate(), - con.getAtimeAsDate(), - con.getCrtimeAsDate(), - con.getSize(), - con.getDirFlagsAsString(), - con.getMetaFlagsAsString(), - con.getModeAsString(), - con.getUid(), - con.getGid(), - con.getMeta_addr(), - con.getAttr_type() + "-" + con.getAttr_id(), - con.getDirTypeAsString(), - con.getMetaTypeAsString(), - con.getKnown().getName() - }); - return objs; - } +// TODO: check if there's anything important in here +// @Override +// public Object[][] getRowValues(int rows) throws SQLException { +// FsContent con = content; +// Object[][] objs = new Object[1][16]; +// Arrays.fill(objs, 0, 1, new Object[]{ +// con.getName(), +// con.getMtimeAsDate(), +// con.getCtimeAsDate(), +// con.getAtimeAsDate(), +// con.getCrtimeAsDate(), +// con.getSize(), +// con.getDirFlagsAsString(), +// con.getMetaFlagsAsString(), +// con.getModeAsString(), +// con.getUid(), +// con.getGid(), +// con.getMeta_addr(), +// con.getAttr_type() + "-" + con.getAttr_id(), +// con.getDirTypeAsString(), +// con.getMetaTypeAsString(), +// con.getKnown().getName() +// }); +// return objs; +// } @Override public T accept(ContentNodeVisitor v) { diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ImageNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ImageNode.java index 9b5d85812c..8b8b0c9a71 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ImageNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ImageNode.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.datamodel; -import java.sql.SQLException; import javax.swing.Action; import org.openide.nodes.Children; import org.openide.nodes.Sheet; @@ -52,33 +51,6 @@ public class ImageNode extends AbstractContentNode { this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/hard-drive-icon.jpg"); } - @Override - public Object[][] getRowValues(int rows) throws SQLException { - // how many rows are we returning - int maxRows = rows; - if (this.getChildren().getNodesCount() < maxRows) { - maxRows = this.getChildren().getNodesCount(); - } - Object[][] objs = new Object[maxRows][]; - - for (int i = 0; i < maxRows; i++) { - PropertySet[] props = this.getChildren().getNodeAt(i).getPropertySets(); - Property[] property = props[0].getProperties(); - objs[i] = new Object[property.length]; - - - // the rest of the properties(not including the location property) - for (int j = 0; j < property.length; j++) { - try { - objs[i][j] = property[j].getValue(); - } catch (Exception ex) { - objs[i][j] = "n/a"; - } - } - } - return objs; - } - @Override public Cookie getCookie(Class clazz) { Children ch = getChildren(); diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/VolumeNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/VolumeNode.java index c231d6d901..200ed8f1da 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/VolumeNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/VolumeNode.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.datamodel; -import java.sql.SQLException; import javax.swing.Action; import org.openide.nodes.Sheet; import org.sleuthkit.datamodel.Volume; @@ -56,40 +55,6 @@ public class VolumeNode extends AbstractContentNode { this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/vol-icon.png"); } - @Override - public Object[][] getRowValues(int rows) throws SQLException { - - // how many rows are we returning - int maxRows = rows; - if (this.getChildren().getNodesCount() < maxRows) { - maxRows = this.getChildren().getNodesCount(); - } - Object[][] objs = new Object[maxRows][]; - - for (int i = 0; i < maxRows; i++) { - PropertySet[] props = this.getChildren().getNodeAt(i).getPropertySets(); - Property[] property = props[0].getProperties(); - objs[i] = new Object[property.length - 1]; // - 1 because we don't want to show the location property - - // name property - try { - objs[i][0] = property[0].getValue(); - } catch (Exception ex) { - objs[i][0] = "n/a"; - } - - // the rest of the properties(not including the location property) - for (int j = 1; j < property.length - 1; j++) { - try { - objs[i][j] = property[j + 1].getValue(); - } catch (Exception ex) { - objs[i][j] = "n/a"; - } - } - } - return objs; - } - /** * Right click action for volume node * diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java index b87f3dddba..698a09db66 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java @@ -20,7 +20,6 @@ package org.sleuthkit.autopsy.directorytree; import java.awt.event.ActionEvent; import java.beans.PropertyVetoException; -import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import org.sleuthkit.autopsy.datamodel.ImageNode; @@ -196,24 +195,9 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { return propertySets; } - @Override - public Object[][] getRowValues(int rows) throws SQLException { - return ((ContentNode) currentNode).getRowValues(rows); - } - - @Override - public String[] getDisplayPath() { - return ((ContentNode) currentNode).getDisplayPath(); - } - @Override public T accept(ContentNodeVisitor v) { // TODO: Figure out how visitors should be delegated throw new UnsupportedOperationException("Not supported yet."); } - - @Override - public String[] getSystemPath() { - return ((ContentNode) currentNode).getSystemPath(); - } } diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java index 81d40916e7..59e81afb55 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java @@ -22,12 +22,15 @@ package org.sleuthkit.autopsy.directorytree; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import javax.swing.AbstractAction; +import org.openide.nodes.Node; import org.openide.windows.Mode; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.datamodel.DataConversion; import org.sleuthkit.autopsy.corecomponents.DataContentTopComponent; +import org.sleuthkit.autopsy.datamodel.ContentUtils; import org.sleuthkit.autopsy.logging.Log; +import org.sleuthkit.datamodel.Content; /** * Opens new ContentViewer pane in a detached window @@ -45,7 +48,7 @@ class NewWindowViewAction extends AbstractAction{ public void actionPerformed(ActionEvent e) { Log.noteAction(this.getClass()); - String[] filePaths = this.contentNode.getDisplayPath(); + String[] filePaths = ContentUtils.getDisplayPath(((Node) contentNode).getLookup().lookup(Content.class)); String filePath = DataConversion.getformattedPath(filePaths, 0); DataContentTopComponent dctc = DataContentTopComponent.createUndocked(filePath, this.contentNode); diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java index 61bf67f917..c824bf0c16 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java @@ -24,11 +24,12 @@ import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.datamodel.VolumeNode; import org.sleuthkit.autopsy.datamodel.FileNode; import org.sleuthkit.autopsy.datamodel.DirectoryNode; -import java.sql.SQLException; import javax.swing.Action; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; +import org.sleuthkit.autopsy.datamodel.ContentUtils; import org.sleuthkit.autopsy.directorytree.ChangeViewAction; +import org.sleuthkit.datamodel.Content; /** * This class wraps nodes as they are passed to the DataResult viewers. It @@ -68,7 +69,7 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { else if (this.currentNode instanceof DirectoryNode) { return new Action[]{ new ChangeViewAction("View", 0, (ContentNode) currentNode), - new OpenParentFolderAction("Open Parent Directory", ((ContentNode) currentNode).getSystemPath()) + new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath((currentNode).getLookup().lookup(Content.class))) }; } // right click action(s) for the file node else if (this.currentNode instanceof FileNode) { @@ -76,7 +77,7 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { // TODO: ContentNode fix - reimplement ExtractAction // new ExtractAction("Extract", (FileNode) this.currentNode), new ChangeViewAction("View", 0, (ContentNode) currentNode), - new OpenParentFolderAction("Open Parent Directory", ((ContentNode) currentNode).getSystemPath()) + new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath((currentNode).getLookup().lookup(Content.class))) }; } else { return new Action[]{}; @@ -94,24 +95,9 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { return null; } - @Override - public Object[][] getRowValues(int rows) throws SQLException { - return ((ContentNode) currentNode).getRowValues(rows); - } - - @Override - public String[] getDisplayPath() { - return ((ContentNode) currentNode).getDisplayPath(); - } - @Override public T accept(ContentNodeVisitor v) { //TODO: figure out how to deal with visitors throw new UnsupportedOperationException("Not supported yet."); } - - @Override - public String[] getSystemPath() { - return ((ContentNode) currentNode).getSystemPath(); - } } diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java index 867ec67e41..27493b3d02 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java @@ -19,15 +19,11 @@ package org.sleuthkit.autopsy.filesearch; -import java.sql.SQLException; import java.util.ArrayList; import org.openide.nodes.AbstractNode; -import org.openide.nodes.Node.Property; import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.datamodel.ContentNodeVisitor; -import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.FsContent; -import org.sleuthkit.datamodel.TskException; /** * @@ -46,52 +42,11 @@ class SearchNode extends AbstractNode implements ContentNode { public String getName() { return "Search Result"; } - - @Override - public Object[][] getRowValues(int rows) throws SQLException { - int totalNodes = children.getNodesCount(); - - Object[][] objs; - int maxRows = 0; - if(totalNodes > rows){ - objs = new Object[rows][]; - maxRows = rows; - } - else{ - objs = new Object[totalNodes][]; - maxRows = totalNodes; - } - - for(int i = 0; i < maxRows; i++){ - PropertySet[] props = children.getNodeAt(i).getPropertySets(); - Property[] property = props[0].getProperties(); - objs[i] = new Object[property.length]; - - for(int j = 0; j < property.length; j++){ - try { - objs[i][j] = property[j].getValue(); - } catch (Exception ex) { - objs[i][j] = "n/a"; - } - } - } - return objs; - } - @Override - public String[] getDisplayPath() { - return new String[]{"KeyWord Search Result:"}; - } @Override public T accept(ContentNodeVisitor v) { //TODO: figure out how to deal with visitors throw new UnsupportedOperationException("Not supported yet."); } - - @Override - public String[] getSystemPath() { - // Shouldn't be used - throw new UnsupportedOperationException("Not supported yet."); - } } From 124ed5dfdde78caf0c76c1da929a5c550909ae07 Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Mon, 12 Dec 2011 16:06:40 -0500 Subject: [PATCH 05/21] Clear out ContentNode & subclasses from CoreComponents --- .../corecomponentinterfaces/DataContent.java | 4 +- .../DataContentViewer.java | 8 +-- .../corecomponentinterfaces/DataResult.java | 4 +- .../DataResultViewer.java | 4 +- .../AbstractDataResultViewer.java | 20 +++--- .../DataContentTopComponent.java | 15 ++--- .../corecomponents/DataContentViewerHex.java | 5 +- .../DataContentViewerPicture.java | 8 +-- .../DataContentViewerString.java | 5 +- .../DataResultTopComponent.java | 21 +++--- .../corecomponents/DataResultViewerTable.java | 15 ++--- .../DataResultViewerThumbnail.java | 18 +---- .../corecomponents/TableFilterNode.java | 5 -- .../corecomponents/ThumbnailViewChildren.java | 34 +++++++--- .../corecomponents/ThumbnailViewNode.java | 5 -- .../autopsy/datamodel/ContentFilterNode.java | 43 ------------ .../autopsy/datamodel/ContentNode.java | 5 +- .../autopsy/datamodel/ContentNodeVisitor.java | 4 +- .../sleuthkit/autopsy/datamodel/FileNode.java | 26 -------- .../directorytree/ChangeViewAction.java | 6 +- .../DataResultFilterChildren.java | 13 ++-- .../directorytree/DataResultFilterNode.java | 65 ++++++++----------- .../DirectoryTreeFilterNode.java | 34 ++++++---- .../DirectoryTreeTopComponent.java | 41 ++++-------- .../directorytree/NewWindowViewAction.java | 5 +- .../filesearch/DataResultFilterNode.java | 23 ++----- .../autopsy/filesearch/SearchNode.java | 11 +--- 27 files changed, 155 insertions(+), 292 deletions(-) delete mode 100644 DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java diff --git a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContent.java b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContent.java index ee8e1c78fb..a277680ce4 100644 --- a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContent.java +++ b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContent.java @@ -19,8 +19,8 @@ package org.sleuthkit.autopsy.corecomponentinterfaces; -import org.sleuthkit.autopsy.datamodel.ContentNode; import java.beans.PropertyChangeListener; +import org.openide.nodes.Node; import org.openide.windows.TopComponent; /** @@ -34,7 +34,7 @@ public interface DataContent extends PropertyChangeListener { * Sets the "selected" node in this class * @param selectedNode node to use */ - public void setNode(ContentNode selectedNode); + public void setNode(Node selectedNode); /** * Get the TopComponent that is used when displaying this DataContent diff --git a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContentViewer.java b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContentViewer.java index 3cd4fbcf98..5601d9fd13 100644 --- a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContentViewer.java +++ b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContentViewer.java @@ -19,19 +19,19 @@ package org.sleuthkit.autopsy.corecomponentinterfaces; -import org.sleuthkit.autopsy.datamodel.ContentNode; import java.awt.Component; +import org.openide.nodes.Node; /** * Responsible for a tab in the {@link DataContent} component. Displays the - * contents of the node passed to {@link setNode(ContentNode)}. + * contents of the node passed to {@link setNode(Node)}. */ public interface DataContentViewer { /** * Sets the node to display in the viewer. When called with null, must * clear all references to previous nodes. */ - public void setNode(ContentNode selectedNode); + public void setNode(Node selectedNode); /** * Returns the title of this viewer. @@ -62,6 +62,6 @@ public interface DataContentViewer { * @param node Node to check for support * @return True if supported, else false */ - public boolean isSupported(ContentNode node); + public boolean isSupported(Node node); } diff --git a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResult.java b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResult.java index 743666df89..699d409e36 100644 --- a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResult.java +++ b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResult.java @@ -18,7 +18,7 @@ */ package org.sleuthkit.autopsy.corecomponentinterfaces; -import org.sleuthkit.autopsy.datamodel.ContentNode; +import org.openide.nodes.Node; /** * The interface for the "top right component" window. @@ -30,7 +30,7 @@ public interface DataResult { /** * Sets the "selected" node in this class. */ - public void setNode(ContentNode selectedNode); + public void setNode(Node selectedNode); /** * Gets the unique TopComponent ID of this class. diff --git a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResultViewer.java b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResultViewer.java index 6ef241e890..0e9b73df79 100644 --- a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResultViewer.java +++ b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResultViewer.java @@ -20,8 +20,8 @@ package org.sleuthkit.autopsy.corecomponentinterfaces; -import org.sleuthkit.autopsy.datamodel.ContentNode; import java.awt.Component; +import org.openide.nodes.Node; /** * Interface for the different viewers that show a set of nodes in the DataResult area. @@ -34,7 +34,7 @@ public interface DataResultViewer { * Set the root node to display in this viewer. When called with null, must * clear all references to previous nodes. */ - public void setNode(ContentNode selectedNode); + public void setNode(Node selectedNode); /** * Gets the title of this viewer diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/AbstractDataResultViewer.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/AbstractDataResultViewer.java index 2b85a8fb9e..b2771c413e 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/AbstractDataResultViewer.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/AbstractDataResultViewer.java @@ -6,7 +6,7 @@ * * 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 + * You may obt ain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -28,15 +28,16 @@ import org.openide.nodes.Node; import org.openide.util.Lookup; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContent; import org.sleuthkit.autopsy.corecomponentinterfaces.DataResultViewer; -import org.sleuthkit.autopsy.datamodel.ContentNode; /** * Holds commonalities between all DataResultViewers */ -public abstract class AbstractDataResultViewer extends JPanel implements DataResultViewer, Provider, PropertyChangeListener { +public abstract class AbstractDataResultViewer extends JPanel implements + DataResultViewer, Provider, PropertyChangeListener { /** - * Propagates changes in the current select node from the DataResultViewer to the DataContentTopComponent + * Propagates changes in the current select node from the DataResultViewer + * to the DataContentTopComponent * * @param evt */ @@ -53,14 +54,14 @@ public abstract class AbstractDataResultViewer extends JPanel implements DataRes // change the cursor to "waiting cursor" for this operation this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { - Node originalSelectedNode = this.getOriginalSelectedNode(); + Node selectedNode = this.getSelectedNode(); // DataContent is designed to return only the default viewer DataContent dataContent = Lookup.getDefault().lookup(DataContent.class); - if (originalSelectedNode != null && originalSelectedNode instanceof ContentNode) { + if (selectedNode != null) { // there's a new/changed node to display - ContentNode newSelectedNode = (ContentNode) originalSelectedNode; // get the selected Node on the table + Node newSelectedNode = selectedNode; // get the selected Node on the table // push the node to default "DataContent" dataContent.setNode(newSelectedNode); } else { @@ -74,9 +75,8 @@ public abstract class AbstractDataResultViewer extends JPanel implements DataRes } /** - * Gets the current node, stripping off any FilterNode that this class might - * have wrapped it in. + * Gets the current node selected node * @return */ - public abstract Node getOriginalSelectedNode(); + public abstract Node getSelectedNode(); } diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java index 774a89235d..b29194460c 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java @@ -32,7 +32,6 @@ import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; import org.openide.util.Lookup; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContent; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; import org.sleuthkit.autopsy.datamodel.ContentUtils; @@ -48,7 +47,7 @@ public final class DataContentTopComponent extends TopComponent implements DataC // reference to the "default" TC that always stays open private static DataContentTopComponent defaultInstance; - private ContentNode currentNode; + private Node currentNode; // set to true if this is the TC that always stays open and is the default place to display content private boolean isDefault; // Different DataContentViewers @@ -81,7 +80,7 @@ public final class DataContentTopComponent extends TopComponent implements DataC this.outdated = true; } - void setNode(ContentNode selectedNode) { + void setNode(Node selectedNode) { this.wrapped.setNode(selectedNode); this.outdated = false; } @@ -95,7 +94,7 @@ public final class DataContentTopComponent extends TopComponent implements DataC return this.outdated; } - boolean isSupported(ContentNode node) { + boolean isSupported(Node node) { return this.wrapped.isSupported(node); } } @@ -107,7 +106,7 @@ public final class DataContentTopComponent extends TopComponent implements DataC * @param givenNode node to view content of * @return newly undocked instance */ - public static DataContentTopComponent createUndocked(String filePath, ContentNode givenNode) { + public static DataContentTopComponent createUndocked(String filePath, Node givenNode) { DataContentTopComponent dctc = new DataContentTopComponent(false, filePath); dctc.componentOpened(); @@ -222,7 +221,7 @@ public final class DataContentTopComponent extends TopComponent implements DataC } @Override - public void setNode(ContentNode selectedNode) { + public void setNode(Node selectedNode) { // change the cursor to "waiting cursor" for this operation this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { @@ -230,7 +229,7 @@ public final class DataContentTopComponent extends TopComponent implements DataC if (selectedNode == null) { setName(NbBundle.getMessage(DataContentTopComponent.class, "CTL_DataContentTopComponent")); } else { - String path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(((Node) selectedNode).getLookup().lookup(Content.class)), 0); + String path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(selectedNode.getLookup().lookup(Content.class)), 0); setName(path); } @@ -284,7 +283,7 @@ public final class DataContentTopComponent extends TopComponent implements DataC * * @param selectedNode the selected content Node */ - public void resetTabs(ContentNode selectedNode) { + public void resetTabs(Node selectedNode) { int totalTabs = dataContentTabbedPane.getTabCount(); diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java index beb1b7f292..5f65c777b8 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java @@ -25,7 +25,6 @@ import java.util.logging.Logger; import javax.swing.JTextPane; import org.openide.nodes.Node; import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; import org.sleuthkit.autopsy.datamodel.DataConversion; import org.sleuthkit.datamodel.Content; @@ -273,7 +272,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont } @Override - public void setNode(ContentNode selectedNode) { + public void setNode(Node selectedNode) { if (selectedNode != null) { Content content = ((Node) selectedNode).getLookup().lookup(Content.class); if (content != null) { @@ -322,7 +321,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont } @Override - public boolean isSupported(ContentNode node) { + public boolean isSupported(Node node) { return true; } diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java index 8beb5dd796..61a11c020b 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java @@ -29,7 +29,6 @@ import javax.imageio.ImageIO; import javax.swing.JPanel; import org.openide.nodes.Node; import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.TskException; @@ -84,7 +83,7 @@ public class DataContentViewerPicture extends javax.swing.JPanel implements Data // End of variables declaration//GEN-END:variables @Override - public void setNode(ContentNode selectedNode) { + public void setNode(Node selectedNode) { // change the cursor to "waiting cursor" for this operation this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { @@ -92,8 +91,7 @@ public class DataContentViewerPicture extends javax.swing.JPanel implements Data try { // read the byte of the image file - // TODO: ContentNode fix - get rid of cast to Node - Content content = ((Node) selectedNode).getLookup().lookup(Content.class); + Content content = selectedNode.getLookup().lookup(Content.class); byte[] dataSource = content.read(0, content.getSize()); // create the input stream for the content @@ -133,7 +131,7 @@ public class DataContentViewerPicture extends javax.swing.JPanel implements Data } @Override - public boolean isSupported(ContentNode cNode) { + public boolean isSupported(Node cNode) { Node node = (Node) cNode; if (node != null) { diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java index ef8d057895..e30633e055 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java @@ -24,7 +24,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.openide.nodes.Node; import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; import org.sleuthkit.autopsy.datamodel.DataConversion; import org.sleuthkit.datamodel.Content; @@ -267,7 +266,7 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC } @Override - public void setNode(ContentNode selectedNode) { + public void setNode(Node selectedNode) { if (selectedNode != null) { Content content = ((Node) selectedNode).getLookup().lookup(Content.class); if (content != null) { @@ -301,7 +300,7 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC } @Override - public boolean isSupported(ContentNode node) { + public boolean isSupported(Node node) { return true; } diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java index db4dd7a754..e30c36ff5e 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java @@ -32,18 +32,14 @@ import org.openide.windows.TopComponent; import org.openide.nodes.Node; import org.openide.util.Lookup; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataResultViewer; -import org.sleuthkit.autopsy.datamodel.ContentUtils; -import org.sleuthkit.autopsy.datamodel.DataConversion; -import org.sleuthkit.datamodel.Content; /** * Top component which displays something. */ public final class DataResultTopComponent extends TopComponent implements DataResult, ChangeListener { - private ContentNode rootNode; + private Node rootNode; private PropertyChangeSupport pcs = new PropertyChangeSupport(this); private boolean isMain; /** path to the icon used by the component and its open action */ @@ -77,7 +73,7 @@ public final class DataResultTopComponent extends TopComponent implements DataRe this.outdated = true; } - void setNode(ContentNode selectedNode) { + void setNode(Node selectedNode) { this.wrapped.setNode(selectedNode); this.outdated = false; } @@ -114,7 +110,7 @@ public final class DataResultTopComponent extends TopComponent implements DataRe newDataResult.open(); // open it first so the component can be initialized // set the tree table view - newDataResult.setNode((ContentNode) givenNode); + newDataResult.setNode(givenNode); newDataResult.directoryTablePath.setText(pathText); return newDataResult; @@ -285,20 +281,19 @@ public final class DataResultTopComponent extends TopComponent implements DataRe } @Override - public void setNode(ContentNode selectedNode) { + public void setNode(Node selectedNode) { this.rootNode = selectedNode; - String path = ""; if (selectedNode != null) { - path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(((Node) selectedNode).getLookup().lookup(Content.class)), 0); + //path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(selectedNode.getLookup().lookup(Content.class)), 0); - int childrenCount = ((Node) selectedNode).getChildren().getNodesCount(true); + int childrenCount = selectedNode.getChildren().getNodesCount(true); this.numberMatchLabel.setText(Integer.toString(childrenCount)); } this.numberMatchLabel.setVisible(true); this.matchLabel.setVisible(true); - this.directoryTablePath.setText(path); // set the node path + this.directoryTablePath.setText("TEST"); // set the node path resetTabs(selectedNode); @@ -351,7 +346,7 @@ public final class DataResultTopComponent extends TopComponent implements DataRe * * @param selectedNode the selected content Node */ - public void resetTabs(ContentNode selectedNode) { + public void resetTabs(Node selectedNode) { for (UpdateWrapper drv : this.viewers) { drv.resetComponent(); diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java index 94b3f2f1ec..7eef046120 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java @@ -37,7 +37,6 @@ import org.openide.nodes.Node.Property; import org.openide.nodes.Node.PropertySet; import org.openide.nodes.Sheet; import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataResultViewer; // TODO We should not have anything specific to Image in here... @@ -107,14 +106,11 @@ public class DataResultViewerTable extends AbstractDataResultViewer { } @Override - public Node getOriginalSelectedNode() { + public Node getSelectedNode() { Node result = null; Node[] selectedNodes = this.getExplorerManager().getSelectedNodes(); if (selectedNodes.length > 0) { result = selectedNodes[0]; - if (result != null && result instanceof TableFilterNode) { - result = ((TableFilterNode) result).getOriginal(); - } } return result; } @@ -141,7 +137,7 @@ public class DataResultViewerTable extends AbstractDataResultViewer { } @Override - public void setNode(ContentNode selectedNode) { + public void setNode(Node selectedNode) { // change the cursor to "waiting cursor" for this operation this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { @@ -157,9 +153,7 @@ public class DataResultViewerTable extends AbstractDataResultViewer { if (hasChildren) { Node root = (Node) selectedNode; - if (root instanceof TableFilterNode) { - root = ((TableFilterNode) root).getOriginal(); - } else { + if (!(root instanceof TableFilterNode)) { root = new TableFilterNode(root, true); } @@ -218,8 +212,7 @@ public class DataResultViewerTable extends AbstractDataResultViewer { // get first 100 rows values for the table Object[][] content = null; - //TODO: ContentNode fix - remove cast to node - content = getRowValues((Node) selectedNode, 100); + content = getRowValues(selectedNode, 100); if (content != null) { diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java index c0fdc0ea6b..b9a1d156ca 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java @@ -29,7 +29,6 @@ import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataResultViewer; /** @@ -82,34 +81,23 @@ public class DataResultViewerThumbnail extends AbstractDataResultViewer { } @Override - public Node getOriginalSelectedNode() { + public Node getSelectedNode() { Node result = null; Node[] selectedNodes = this.getExplorerManager().getSelectedNodes(); if (selectedNodes.length > 0) { result = selectedNodes[0]; - if (result != null && result instanceof ThumbnailViewNode) { - result = ((ThumbnailViewNode) result).getOriginal(); - } } return result; } @Override - public void setNode(ContentNode givenNode) { + public void setNode(Node givenNode) { // change the cursor to "waiting cursor" for this operation this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { if (givenNode != null) { - Node root = (Node) givenNode; - - if (root instanceof ThumbnailViewNode) { - root = ((ThumbnailViewNode) root).getOriginal(); - } else { - Node temp = new AbstractNode(new ThumbnailViewChildren((ContentNode) root)); - root = temp; - } - + Node root = new AbstractNode(new ThumbnailViewChildren(givenNode)); em.setRootContext(root); } else { Node emptyNode = new AbstractNode(Children.LEAF); diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/TableFilterNode.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/TableFilterNode.java index 33236fc791..4db898654d 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/TableFilterNode.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/TableFilterNode.java @@ -37,11 +37,6 @@ class TableFilterNode extends FilterNode { this.createChild = crChild; } - @Override - public Node getOriginal() { - return super.getOriginal(); - } - /** * Override the display name / header for the first (tree) column on the * "TreeTableView". diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java index 9967d2aaf9..d094396b45 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java @@ -20,17 +20,21 @@ package org.sleuthkit.autopsy.corecomponents; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; -import org.sleuthkit.autopsy.datamodel.ContentNode; +import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.ContentVisitor; +import org.sleuthkit.datamodel.File; /** * Complementary class to ThumbnailViewNode */ class ThumbnailViewChildren extends FilterNode.Children { + + private static final IsSupportedContentVisitor isSupportedVisitor = new IsSupportedContentVisitor(); private int totalChildren; /** the constructor */ - ThumbnailViewChildren(ContentNode arg) { + ThumbnailViewChildren(Node arg) { super((Node) arg); this.totalChildren = 1; } @@ -42,9 +46,7 @@ class ThumbnailViewChildren extends FilterNode.Children { @Override protected Node[] createNodes(Node arg0) { - // filter out the FileNode and the "." and ".." directories - if (arg0 != null && //(arg0 instanceof FileNode && - isSupported(arg0)) { + if (arg0 != null && isSupported(arg0)) { totalChildren++; return new Node[]{this.copyNode(arg0)}; } else { @@ -58,7 +60,20 @@ class ThumbnailViewChildren extends FilterNode.Children { public static boolean isSupported(Node node) { if (node != null) { - String lowerName = node.getDisplayName().toLowerCase(); + Content content = node.getLookup().lookup(Content.class); + if (content != null) { + return content.accept(isSupportedVisitor); + } + } + return false; + } + + + private static class IsSupportedContentVisitor extends ContentVisitor.Default { + + @Override + public Boolean visit(File f) { + String lowerName = f.getName().toLowerCase(); // Note: only supports JPG, GIF, and PNG for now // TODO: replace giant OR with check if in list return lowerName.endsWith(".jpg") @@ -71,8 +86,11 @@ class ThumbnailViewChildren extends FilterNode.Children { //node.getName().toLowerCase().endsWith(".tiff") || //node.getName().toLowerCase().endsWith(".tga") || lowerName.endsWith(".png"); - } else { + } + + @Override + protected Boolean defaultVisit(Content cntnt) { return false; } - } + } } diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java index 57d87052f4..c356ed3823 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java @@ -49,11 +49,6 @@ class ThumbnailViewNode extends FilterNode { super(arg, Children.LEAF); } - @Override - public Node getOriginal() { - return super.getOriginal(); - } - @Override public Image getIcon(int type) { Image icon = null; diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java deleted file mode 100644 index b3070beea6..0000000000 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.datamodel; - -import org.openide.nodes.FilterNode; -import org.openide.nodes.Node; -import org.openide.util.Lookup; - -public class ContentFilterNode extends FilterNode implements ContentNode { - - public ContentFilterNode(ContentNode original) { - super((Node) original); - } - - public ContentFilterNode(ContentNode original, Children children) { - super((Node) original, children); - } - - public ContentFilterNode(ContentNode original, Children children, Lookup lookup) { - super((Node) original, children, lookup); - } - - @Override - public T accept(ContentNodeVisitor v) { - return ((ContentNode) super.getOriginal()).accept(v); - } -} diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java index 967ef63aef..d4a504a77e 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java @@ -22,7 +22,8 @@ package org.sleuthkit.autopsy.datamodel; * Interface class that all Data nodes inherit from. * Provides basic information such as ID, parent ID, etc. */ -public interface ContentNode { + +interface ContentNode { /** * Visitor pattern support. @@ -31,5 +32,5 @@ public interface ContentNode { * @param v visitor * @return visitor return value */ - public T accept(ContentNodeVisitor v); + T accept(ContentNodeVisitor v); } diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNodeVisitor.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNodeVisitor.java index e31782487f..d95d92d817 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNodeVisitor.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNodeVisitor.java @@ -22,7 +22,7 @@ package org.sleuthkit.autopsy.datamodel; * Interface for visitor pattern on ContentNodes * @param visit method return type */ -public interface ContentNodeVisitor { +interface ContentNodeVisitor { T visit(DirectoryNode dn); @@ -37,7 +37,7 @@ public interface ContentNodeVisitor { * specific visit types to not use the default behavior. * @param */ - static abstract public class Default implements ContentNodeVisitor { + static abstract class Default implements ContentNodeVisitor { /** * Default visit for all types diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/FileNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/FileNode.java index 1ee0e17ec8..fc255c2714 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/FileNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/FileNode.java @@ -67,32 +67,6 @@ public class FileNode extends AbstractFsContentNode { return new Action[]{}; } -// TODO: check if there's anything important in here -// @Override -// public Object[][] getRowValues(int rows) throws SQLException { -// FsContent con = content; -// Object[][] objs = new Object[1][16]; -// Arrays.fill(objs, 0, 1, new Object[]{ -// con.getName(), -// con.getMtimeAsDate(), -// con.getCtimeAsDate(), -// con.getAtimeAsDate(), -// con.getCrtimeAsDate(), -// con.getSize(), -// con.getDirFlagsAsString(), -// con.getMetaFlagsAsString(), -// con.getModeAsString(), -// con.getUid(), -// con.getGid(), -// con.getMeta_addr(), -// con.getAttr_type() + "-" + con.getAttr_id(), -// con.getDirTypeAsString(), -// con.getMetaTypeAsString(), -// con.getKnown().getName() -// }); -// return objs; -// } - @Override public T accept(ContentNodeVisitor v) { return v.visit(this); diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ChangeViewAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ChangeViewAction.java index 6242d633bc..028c1e2e0b 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ChangeViewAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ChangeViewAction.java @@ -18,11 +18,11 @@ */ package org.sleuthkit.autopsy.directorytree; -import org.sleuthkit.autopsy.datamodel.ContentNode; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JMenu; import javax.swing.JMenuItem; +import org.openide.nodes.Node; import org.openide.util.actions.Presenter; import org.sleuthkit.autopsy.corecomponents.DataContentTopComponent; import org.sleuthkit.autopsy.corecomponents.DataContentViewerHex; @@ -37,10 +37,10 @@ import org.sleuthkit.autopsy.logging.Log; public class ChangeViewAction extends AbstractAction implements Presenter.Popup { private int type; // type 1 = hex view, 2 = string view - private ContentNode node; + private Node node; /** the constructor */ - public ChangeViewAction(String title, int viewType, ContentNode node) { + public ChangeViewAction(String title, int viewType, Node node) { super(title); this.type = viewType; this.node = node; diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterChildren.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterChildren.java index 128889a499..0179322bff 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterChildren.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterChildren.java @@ -18,6 +18,7 @@ */ package org.sleuthkit.autopsy.directorytree; +import org.openide.explorer.ExplorerManager; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; @@ -28,19 +29,17 @@ import org.openide.nodes.Node; * @author jantonius */ public class DataResultFilterChildren extends FilterNode.Children { + + ExplorerManager sourceEm; /** the constructor */ - public DataResultFilterChildren(Node arg) { + public DataResultFilterChildren(Node arg, ExplorerManager sourceEm) { super(arg); + this.sourceEm = sourceEm; } @Override protected Node copyNode(Node arg0) { - return new DataResultFilterNode(arg0); - } - - @Override - protected Node[] createNodes(Node arg0) { - return new Node[]{this.copyNode(arg0)}; + return new DataResultFilterNode(arg0, sourceEm); } } \ No newline at end of file diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java index 698a09db66..42532e493a 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java @@ -23,7 +23,6 @@ import java.beans.PropertyVetoException; import java.util.ArrayList; import java.util.List; import org.sleuthkit.autopsy.datamodel.ImageNode; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.datamodel.VolumeNode; import org.sleuthkit.autopsy.datamodel.FileNode; import org.sleuthkit.autopsy.datamodel.DirectoryNode; @@ -31,34 +30,24 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Action; -import javax.swing.JPanel; import org.openide.explorer.ExplorerManager; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; import org.openide.nodes.Sheet; -import org.sleuthkit.autopsy.datamodel.ContentNodeVisitor; import org.sleuthkit.datamodel.Content; /** * This class wraps nodes as they are passed to the DataResult viewers. It * defines the actions that the node should have. */ -public class DataResultFilterNode extends FilterNode implements ContentNode { +public class DataResultFilterNode extends FilterNode{ - private Node currentNode; - // for error handling - private JPanel caller; - private String className = this.getClass().toString(); + private ExplorerManager sourceEm; /** the constructor */ - public DataResultFilterNode(Node arg) { - super(arg, new DataResultFilterChildren(arg)); - this.currentNode = arg; - } - - @Override - public Node getOriginal() { - return super.getOriginal(); + public DataResultFilterNode(Node arg, ExplorerManager em) { + super(arg, new DataResultFilterChildren(arg, em)); + this.sourceEm = em; } /** @@ -66,7 +55,7 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { * table and the output view. * * @param popup - * @return actionss + * @return actions */ @Override public Action[] getActions(boolean popup) { @@ -76,32 +65,33 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { // TODO: ContentNode fix - restore right-click actions // TODO: ContentVisitor instead of instanceof - Content nodeContent = this.currentNode.getLookup().lookup(Content.class); + Content nodeContent = this.getOriginal().getLookup().lookup(Content.class); + Node originalNode = this.getOriginal(); // right click action(s) for image node - if (this.currentNode instanceof ImageNode) { - actions.add(new NewWindowViewAction("View in New Window", (ImageNode) this.currentNode)); + if (originalNode instanceof ImageNode) { + actions.add(new NewWindowViewAction("View in New Window", (ImageNode) originalNode)); actions.addAll(ShowDetailActionVisitor.getActions(nodeContent)); } // right click action(s) for volume node - else if (this.currentNode instanceof VolumeNode) { - actions.add(new NewWindowViewAction("View in New Window", (VolumeNode) this.currentNode)); + else if (originalNode instanceof VolumeNode) { + actions.add(new NewWindowViewAction("View in New Window", (VolumeNode) originalNode)); //new ShowDetailActionVisitor("Volume Details", this.currentNode.getName(), (VolumeNode) this.currentNode), actions.addAll(ShowDetailActionVisitor.getActions(nodeContent)); - actions.add(new ChangeViewAction("View", 0, (ContentNode) currentNode)); + actions.add(new ChangeViewAction("View", 0, this.getOriginal())); } // right click action(s) for directory node - else if (this.currentNode instanceof DirectoryNode) { - actions.add(new NewWindowViewAction("View in New Window", (DirectoryNode) this.currentNode)); - actions.add(new ChangeViewAction("View", 0, (ContentNode) currentNode)); + else if (originalNode instanceof DirectoryNode) { + actions.add(new NewWindowViewAction("View in New Window", (DirectoryNode) originalNode)); + actions.add(new ChangeViewAction("View", 0, originalNode)); // TODO: ContentNode fix - reimplement ExtractAction //actions.add(new ExtractAction("Extract Directory", (DirectoryNode) this.currentNode)); } // right click action(s) for the file node - else if (this.currentNode instanceof FileNode) { - actions.add(new ExternalViewerAction("Open File in External Viewer", (FileNode) this.currentNode)); - actions.add(new NewWindowViewAction("View in New Window", (FileNode) this.currentNode)); + else if (originalNode instanceof FileNode) { + actions.add(new ExternalViewerAction("Open File in External Viewer", (FileNode) originalNode)); + actions.add(new NewWindowViewAction("View in New Window", (FileNode) originalNode)); // TODO: ContentNode fix - reimplement ExtractAction //actions.add(new ExtractAction("Extract", (FileNode) this.currentNode)); - actions.add(new ChangeViewAction("View", 0, (ContentNode) currentNode)); + actions.add(new ChangeViewAction("View", 0, originalNode)); } return actions.toArray(new Action[actions.size()]); @@ -116,9 +106,12 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { @Override public Action getPreferredAction() { // double click action(s) for volume node or directory node - if (this.currentNode instanceof VolumeNode || (this.currentNode instanceof DirectoryNode && !this.currentNode.getDisplayName().equals("."))) { + + final Node originalNode = this.getOriginal(); + + if (originalNode instanceof VolumeNode || (originalNode instanceof DirectoryNode && !originalNode.getDisplayName().equals("."))) { - if (this.currentNode instanceof DirectoryNode && this.currentNode.getDisplayName().equals("..")) { + if (originalNode instanceof DirectoryNode && originalNode.getDisplayName().equals("..")) { ExplorerManager em = DirectoryTreeTopComponent.findInstance().getExplorerManager(); Node[] selectedNode = em.getSelectedNodes(); Node selectedContext = selectedNode[0]; @@ -149,7 +142,7 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { ExplorerManager em = DirectoryTreeTopComponent.findInstance().getExplorerManager(); for (int i = 0; i < parentContext.getChildren().getNodesCount(); i++) { Node selectedNode = parentContext.getChildren().getNodeAt(i); - if (selectedNode != null && selectedNode.getName().equals(currentNode.getName())) { + if (selectedNode != null && selectedNode.getName().equals(originalNode.getName())) { try { em.setExploredContextAndSelection(selectedNode, new Node[]{selectedNode}); } catch (PropertyVetoException ex) { @@ -194,10 +187,4 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { return propertySets; } - - @Override - public T accept(ContentNodeVisitor v) { - // TODO: Figure out how visitors should be delegated - throw new UnsupportedOperationException("Not supported yet."); - } } diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java index 13d2b4e907..61d72ef610 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java @@ -23,29 +23,24 @@ import java.util.List; import javax.swing.Action; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; -import org.sleuthkit.autopsy.casemodule.Case; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.SleuthkitCase; -import org.sleuthkit.datamodel.Volume; /** * This class sets the actions for the nodes in the directory tree and creates * the children filter so that files and such are hidden from the tree. * */ -public class DirectoryTreeFilterNode extends FilterNode { +class DirectoryTreeFilterNode extends FilterNode { private static final Action collapseAll = new CollapseAction("Collapse All"); /** the constructor */ - public DirectoryTreeFilterNode(Node arg) { - super(arg, DirectoryTreeFilterChildren.createInstance(arg)); - } - - // TODO This seems bad. We should have this return the real original and modify code somewhere else to wrap it - @Override - public Node getOriginal() { - return new DataResultFilterNode(super.getOriginal()); + DirectoryTreeFilterNode(Node arg) { + super(arg, DirectoryTreeFilterChildren.createInstance(arg), + new ProxyLookup(Lookups.singleton(new OriginalNode(arg)), + arg.getLookup())); } /** @@ -58,7 +53,7 @@ public class DirectoryTreeFilterNode extends FilterNode { public Action[] getActions(boolean popup) { List actions = new ArrayList(); - Content content = super.getOriginal().getLookup().lookup(Content.class); + Content content = this.getLookup().lookup(Content.class); if (content != null) { actions.addAll(DirectoryTreeFilterNode.getActions(content)); actions.add(collapseAll); @@ -74,4 +69,17 @@ public class DirectoryTreeFilterNode extends FilterNode { return actions; } + + static class OriginalNode { + + private Node original; + + private OriginalNode(Node original) { + this.original = original; + } + + Node getNode() { + return original; + } + } } diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java index f691f39e65..58879d6205 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java @@ -44,9 +44,9 @@ import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent; import org.sleuthkit.autopsy.datamodel.RootContentChildren; +import org.sleuthkit.autopsy.directorytree.DirectoryTreeFilterNode.OriginalNode; /** * Top component which displays something. @@ -332,24 +332,10 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat }; } }; - /*try { + root = new DirectoryTreeFilterNode(root); - } catch (SQLException ex) { - JOptionPane.showMessageDialog(caller, "Error: problem making directory filter node.\n \nDetail: \n" + ex.getMessage() + " (at " + className + ").", "Error", JOptionPane.ERROR_MESSAGE); - }*/ - // TODO It seems that we can get rid of the first condition. root is an abstract node - if (root instanceof DirectoryTreeFilterNode) { - root = ((DirectoryTreeFilterNode) root).getOriginal(); - } else { -// try { - root = new DirectoryTreeFilterNode(root); -// } catch (SQLException ex) { -// JOptionPane.showMessageDialog(caller, "Error: problem making directory filter node.\n \nDetail: \n" + ex.getMessage() + " (at " + className + ").", "Error", JOptionPane.ERROR_MESSAGE); -// } - } - em.setRootContext(root); em.getRootContext().setName(currentCase.getName()); em.getRootContext().setDisplayName(currentCase.getName()); @@ -460,16 +446,12 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat * * @return node the original selected Node */ - // TODO Rename or get rid of it entirely. - public Node getOriginalSelectedNode() { + public Node getSelectedNode() { Node result = null; Node[] selectedNodes = this.getExplorerManager().getSelectedNodes(); if (selectedNodes.length > 0) { result = selectedNodes[0]; - if (result != null && result instanceof DirectoryTreeFilterNode) { - result = ((DirectoryTreeFilterNode) result).getOriginal(); - } } return result; } @@ -500,10 +482,10 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat em.getRootContext().setDisplayName(newCaseName); } } - + // changed current case if (changed.equals(Case.CASE_CURRENT_CASE)) { - + // case opened if (newValue != null) { resetHistoryListAndButtons(); @@ -546,8 +528,7 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat // change in node selection if (changed.equals(ExplorerManager.PROP_SELECTED_NODES)) { - - // Some lock that prevents certian Node operations is set during the + // Some lock that prevents certain Node operations is set during the // ExplorerManager selection-change, so we must handle changes after the // selection-change event is processed. EventQueue.invokeLater(new Runnable() { @@ -561,18 +542,18 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat // make sure dataResult is open dataResult.open(); - ContentNode node = (ContentNode) DirectoryTreeTopComponent.this.getOriginalSelectedNode(); - if (node != null) { + Node treeNode = DirectoryTreeTopComponent.this.getSelectedNode(); + if (treeNode != null) { + Node originNode = treeNode.getLookup().lookup(DirectoryTreeFilterNode.OriginalNode.class).getNode(); - //pcs.firePropertyChange(DataExplorer.EXPLORER_NODE_SELECTION_CHANGED, "", node); - int count = ((Node) node).getChildren().getNodesCount(true); + int count = originNode.getChildren().getNodesCount(true); if (count > 1000) { DirectoryTreeTopComponent.this.setCursor(null); JOptionPane.showMessageDialog(caller, "Note: The selected directory contains " + count + " child files and folders. It may take some time to display them.\n\nAlso note that in the current version of Autopsy this will also make certain functions very slow (thumbnail view in particular, should be fixed in a future version)", "Large Data", JOptionPane.INFORMATION_MESSAGE); DirectoryTreeTopComponent.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); } DirectoryTreeTopComponent.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - DirectoryTreeTopComponent.this.dataResult.setNode(node); + DirectoryTreeTopComponent.this.dataResult.setNode(new DataResultFilterNode(originNode, DirectoryTreeTopComponent.this.em)); } // set the directory listing to be active diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java index 59e81afb55..fb436a16cd 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java @@ -25,7 +25,6 @@ import javax.swing.AbstractAction; import org.openide.nodes.Node; import org.openide.windows.Mode; import org.openide.windows.WindowManager; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.datamodel.DataConversion; import org.sleuthkit.autopsy.corecomponents.DataContentTopComponent; import org.sleuthkit.autopsy.datamodel.ContentUtils; @@ -37,9 +36,9 @@ import org.sleuthkit.datamodel.Content; */ class NewWindowViewAction extends AbstractAction{ - private ContentNode contentNode ; + private Node contentNode ; - NewWindowViewAction(String title, ContentNode contentNode){ + NewWindowViewAction(String title, Node contentNode){ super(title); this.contentNode = contentNode; } diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java index c824bf0c16..7f687bcb2a 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java @@ -18,9 +18,7 @@ */ package org.sleuthkit.autopsy.filesearch; -import org.sleuthkit.autopsy.datamodel.ContentNodeVisitor; import org.sleuthkit.autopsy.datamodel.ImageNode; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.datamodel.VolumeNode; import org.sleuthkit.autopsy.datamodel.FileNode; import org.sleuthkit.autopsy.datamodel.DirectoryNode; @@ -35,7 +33,7 @@ import org.sleuthkit.datamodel.Content; * This class wraps nodes as they are passed to the DataResult viewers. It * defines the actions that the node should have. */ -public class DataResultFilterNode extends FilterNode implements ContentNode { +public class DataResultFilterNode extends FilterNode { private Node currentNode; @@ -45,11 +43,6 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { this.currentNode = arg; } - @Override - public Node getOriginal() { - return super.getOriginal(); - } - /** * Right click action for the nodes that we want to pass to the directory * table and the output view. @@ -68,16 +61,16 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { } // right click action(s) for directory node else if (this.currentNode instanceof DirectoryNode) { return new Action[]{ - new ChangeViewAction("View", 0, (ContentNode) currentNode), - new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath((currentNode).getLookup().lookup(Content.class))) + new ChangeViewAction("View", 0, currentNode), + new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath(currentNode.getLookup().lookup(Content.class))) }; } // right click action(s) for the file node else if (this.currentNode instanceof FileNode) { return new Action[]{ // TODO: ContentNode fix - reimplement ExtractAction // new ExtractAction("Extract", (FileNode) this.currentNode), - new ChangeViewAction("View", 0, (ContentNode) currentNode), - new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath((currentNode).getLookup().lookup(Content.class))) + new ChangeViewAction("View", 0, currentNode), + new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath(currentNode.getLookup().lookup(Content.class))) }; } else { return new Action[]{}; @@ -94,10 +87,4 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { public Action getPreferredAction() { return null; } - - @Override - public T accept(ContentNodeVisitor v) { - //TODO: figure out how to deal with visitors - throw new UnsupportedOperationException("Not supported yet."); - } } diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java index 27493b3d02..6c088a166e 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java @@ -21,15 +21,13 @@ package org.sleuthkit.autopsy.filesearch; import java.util.ArrayList; import org.openide.nodes.AbstractNode; -import org.sleuthkit.autopsy.datamodel.ContentNode; -import org.sleuthkit.autopsy.datamodel.ContentNodeVisitor; import org.sleuthkit.datamodel.FsContent; /** * * @author jantonius */ -class SearchNode extends AbstractNode implements ContentNode { +class SearchNode extends AbstractNode { private SearchChildren children; @@ -42,11 +40,4 @@ class SearchNode extends AbstractNode implements ContentNode { public String getName() { return "Search Result"; } - - - @Override - public T accept(ContentNodeVisitor v) { - //TODO: figure out how to deal with visitors - throw new UnsupportedOperationException("Not supported yet."); - } } From 522b2bf0f7d8f57795210e062ff5576e44b862fb Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Mon, 12 Dec 2011 16:54:44 -0500 Subject: [PATCH 06/21] Add writeToFile method to ContentUtils --- .../autopsy/datamodel/ContentUtils.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java index d4d9d23a2a..89166b0828 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java @@ -19,6 +19,9 @@ package org.sleuthkit.autopsy.datamodel; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.LinkedList; import java.util.List; import org.sleuthkit.datamodel.Content; @@ -32,7 +35,7 @@ import org.sleuthkit.datamodel.Volume; import org.sleuthkit.datamodel.VolumeSystem; /** - * Static class of + * Static class of utility methods for Content objects */ public final class ContentUtils { @@ -170,4 +173,32 @@ public final class ContentUtils { } } + + private static final int TO_FILE_BUFFER_SIZE = 8192; + + /** + * Reads all the data from any content object and writes it to a file. + * @param content Any content object. + * @param outputFile Will be created if it doesn't exist, and overwritten if + * it does + * @throws IOException + */ + public static void writeToFile(Content content, java.io.File outputFile) throws IOException { + + InputStream in = new ReadContentInputStream(content); + + boolean append = false; + FileOutputStream out = new FileOutputStream(outputFile, append); + + try { + byte[] buffer = new byte[TO_FILE_BUFFER_SIZE]; + int len = in.read(buffer); + while (len != -1) { + out.write(buffer, 0, len); + len = in.read(buffer); + } + } finally { + out.close(); + } + } } From f6e029935d3706b4d19f9250efc3204421cab164 Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Tue, 13 Dec 2011 11:08:36 -0500 Subject: [PATCH 07/21] Forgot to add ReadContentInputStream --- .../datamodel/ReadContentInputStream.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 DataModel/src/org/sleuthkit/autopsy/datamodel/ReadContentInputStream.java diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ReadContentInputStream.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ReadContentInputStream.java new file mode 100644 index 0000000000..82ef86fb3d --- /dev/null +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ReadContentInputStream.java @@ -0,0 +1,90 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2011 Basis Technology Corp. + * Contact: carrier sleuthkit 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.datamodel; + +import java.io.IOException; +import java.io.InputStream; +import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.TskException; + +/** + * InputStream to read bytes from a Content object's data + */ +class ReadContentInputStream extends InputStream { + + private long position; + private long length; + private Content content; + + ReadContentInputStream(Content content) { + this.content = content; + this.position = 0; + this.length = content.getSize(); + } + + @Override + public int read() throws IOException { + byte[] buff = new byte[1]; + return (read(buff) != -1) ? buff[0] : -1; + } + + @Override + public int read(byte[] b) throws IOException { + return read(b, 0, b.length); + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + + // must return 0 for zero-length arrays + if (b.length == 0) { + return 0; + } + + // will get an error from TSK if we try to read an empty file + if (this.length == 0) { + return -1; + } + + if (position < length) { + // data remains to be read + + int lenToRead = (int) Math.min(len, length - position); + + try { + byte[] buff = content.read(position, lenToRead); + int lenRead = buff.length; + + if (lenRead == 0) { + // TSK could not read the whole file, ending partway + return -1; + } else { + System.arraycopy(buff, 0, b, off, lenRead); + position += lenRead; + return lenRead; + } + } catch (TskException ex) { + throw new IOException(ex); + } + } else { + // at end of file + return -1; + } + } +} \ No newline at end of file From 2bad9d1603fe27ee3a0c15c132b9adc1fab1cf35 Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Tue, 13 Dec 2011 13:14:59 -0500 Subject: [PATCH 08/21] KeyValue classes added to DataModel --- .../autopsy/datamodel/KeyValueNode.java | 36 +++++++++++++++++++ .../autopsy/datamodel/KeyValueThing.java | 33 +++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java create mode 100644 DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueThing.java diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java new file mode 100644 index 0000000000..6bbfb4bdcb --- /dev/null +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java @@ -0,0 +1,36 @@ + +package org.sleuthkit.autopsy.datamodel; + +import java.util.Map; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Sheet; + +public class KeyValueNode extends AbstractNode { + + KeyValueThing thing; + + public KeyValueNode(KeyValueThing thing, Children children) { + super(children); + this.setName(thing.getName()); + this.thing = thing; + } + + @Override + protected Sheet createSheet() { + Sheet s = super.createSheet(); + Sheet.Set ss = s.get(Sheet.PROPERTIES); + if (ss == null) { + ss = Sheet.createPropertiesSet(); + s.put(ss); + } + + for (Map.Entry entry : thing.getMap().entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + ss.put(new NodeProperty(key, key, "n/a", value)); + } + + return s; + } +} diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueThing.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueThing.java new file mode 100644 index 0000000000..2c439db15f --- /dev/null +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueThing.java @@ -0,0 +1,33 @@ +package org.sleuthkit.autopsy.datamodel; + +import java.util.Map; + +public class KeyValueThing { + Map map; + int id; + String name; + + /** + * + * @param map must iterate it keys and values in a consistent order + * (use of LinkedHashMap is recommended) + * @param id an arbitrary id representing the type of the thing + */ + public KeyValueThing(String name, Map map, int id) { + this.name = name; + this.map = map; + this.id = id; + } + + public int getId() { + return id; + } + + public Map getMap() { + return map; + } + + public String getName() { + return name; + } +} \ No newline at end of file From 15f4fe0592c96af518e532d584677b107a9b4aa5 Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Tue, 13 Dec 2011 13:16:14 -0500 Subject: [PATCH 09/21] Example project added --- Example/build.xml | 8 ++ ...topsy.corecomponentinterfaces.DataExplorer | 1 + .../autopsy/example/Bundle.properties | 2 + .../autopsy/example/ExampleDataExplorer.class | Bin 0 -> 3099 bytes .../example/ExampleKeyValueChildFactory.class | Bin 0 -> 1834 bytes .../autopsy/example/ExampleModel.class | Bin 0 -> 377 bytes .../example/ExampleTopComponent$1.class | Bin 0 -> 941 bytes .../autopsy/example/ExampleTopComponent.class | Bin 0 -> 2762 bytes Example/build/no-license.txt | 1 + Example/manifest.mf | 5 + Example/nbproject/build-impl.xml | 45 ++++++++ Example/nbproject/genfiles.properties | 8 ++ Example/nbproject/platform.properties | 99 ++++++++++++++++++ Example/nbproject/project.properties | 2 + Example/nbproject/project.xml | 72 +++++++++++++ Example/nbproject/suite.properties | 1 + .../autopsy/example/Bundle.properties | 2 + .../autopsy/example/ExampleDataExplorer.java | 71 +++++++++++++ .../example/ExampleKeyValueChildFactory.java | 28 +++++ .../autopsy/example/ExampleModel.java | 15 +++ .../autopsy/example/ExampleTopComponent.form | 48 +++++++++ .../autopsy/example/ExampleTopComponent.java | 72 +++++++++++++ nbproject/project.properties | 4 +- 23 files changed, 483 insertions(+), 1 deletion(-) create mode 100644 Example/build.xml create mode 100644 Example/build/classes/META-INF/services/org.sleuthkit.autopsy.corecomponentinterfaces.DataExplorer create mode 100644 Example/build/classes/org/sleuthkit/autopsy/example/Bundle.properties create mode 100644 Example/build/classes/org/sleuthkit/autopsy/example/ExampleDataExplorer.class create mode 100644 Example/build/classes/org/sleuthkit/autopsy/example/ExampleKeyValueChildFactory.class create mode 100644 Example/build/classes/org/sleuthkit/autopsy/example/ExampleModel.class create mode 100644 Example/build/classes/org/sleuthkit/autopsy/example/ExampleTopComponent$1.class create mode 100644 Example/build/classes/org/sleuthkit/autopsy/example/ExampleTopComponent.class create mode 100644 Example/build/no-license.txt create mode 100644 Example/manifest.mf create mode 100644 Example/nbproject/build-impl.xml create mode 100644 Example/nbproject/genfiles.properties create mode 100644 Example/nbproject/platform.properties create mode 100644 Example/nbproject/project.properties create mode 100644 Example/nbproject/project.xml create mode 100644 Example/nbproject/suite.properties create mode 100644 Example/src/org/sleuthkit/autopsy/example/Bundle.properties create mode 100644 Example/src/org/sleuthkit/autopsy/example/ExampleDataExplorer.java create mode 100644 Example/src/org/sleuthkit/autopsy/example/ExampleKeyValueChildFactory.java create mode 100644 Example/src/org/sleuthkit/autopsy/example/ExampleModel.java create mode 100644 Example/src/org/sleuthkit/autopsy/example/ExampleTopComponent.form create mode 100644 Example/src/org/sleuthkit/autopsy/example/ExampleTopComponent.java diff --git a/Example/build.xml b/Example/build.xml new file mode 100644 index 0000000000..066cace4ee --- /dev/null +++ b/Example/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project org.sleuthkit.autopsy.example. + + diff --git a/Example/build/classes/META-INF/services/org.sleuthkit.autopsy.corecomponentinterfaces.DataExplorer b/Example/build/classes/META-INF/services/org.sleuthkit.autopsy.corecomponentinterfaces.DataExplorer new file mode 100644 index 0000000000..82bea797ae --- /dev/null +++ b/Example/build/classes/META-INF/services/org.sleuthkit.autopsy.corecomponentinterfaces.DataExplorer @@ -0,0 +1 @@ +org.sleuthkit.autopsy.example.ExampleDataExplorer diff --git a/Example/build/classes/org/sleuthkit/autopsy/example/Bundle.properties b/Example/build/classes/org/sleuthkit/autopsy/example/Bundle.properties new file mode 100644 index 0000000000..3bba77cab7 --- /dev/null +++ b/Example/build/classes/org/sleuthkit/autopsy/example/Bundle.properties @@ -0,0 +1,2 @@ +OpenIDE-Module-Name=Example +ExampleTopComponent.makeNodesButton.text=Make Nodes diff --git a/Example/build/classes/org/sleuthkit/autopsy/example/ExampleDataExplorer.class b/Example/build/classes/org/sleuthkit/autopsy/example/ExampleDataExplorer.class new file mode 100644 index 0000000000000000000000000000000000000000..96b9c07cf04231551df406bd3ae227c8234865db GIT binary patch literal 3099 zcmb7GZBr9h6n-uQHmpG~DuRXzYAY{dYJI7KVi7^9fL0KS)#{QgWFhRv%?60tceUEu z*FWHN`k{XCLp#%gN~bgRV}FvD$ZeK4My>H5Mx1{58@pK7ZhAnQH??QcsGbk z^7pcQXr;h+VHH&vUxOIp3Un29m{2i^gaSiF1XDpw2a%NXGb&72DpI(jz*dk};0TmB zF@e4PmOU9wC-sbzm^PfKmT|09IvdsJwV6~>kM?-K!&a)>nn_uvZaN(TRfFdSj`f_q zG<>pe@WiFQ;{u{jpt9RC(~f33BU&<}3zQ!=OvC9EC~ayU5eRf!aaybT4O1V?%#7>y zur{8gCERbtwB(3p8*-d82AqVEe&O{U*Bq^9K9#g=-InW{)E)nl1$HzwyOmlg-8ABQ zbj~p2)?7O3_hR7MluZxY$#y3+bCPS@-qb&(&1%tcT{F|sGexsKvyu&2TB$xuLL2_e zRiI)R`2)KM+y!v&*`(A9-m_U9i3dq313`+m&5K_ zmMc0=iOjITWb~AtbrtFo=OR@OIa+L*xn1!o$Ox!IR>qF$y@ph1ZSENOWwu-DB7|1# z64>*<50MO<4dE5+6j<*n%vC^_ZEM+nBTecz6|6il(|Y`*mQHYq6vw=Rxe(@&Rd6+g zYq(BZmV!!WW&{*UIG%|Sp>5?=twKaTqi?T|WvCq84&gn#FHqK?nehfW_#lK2@sTXy zV{#S3C%7SSXyt6rHIh8{t|)u8m}A*l33OAztq?xNZGo30Q2v~H67CvLJ2suAK&AH` z7CT{CJg>x?v+Q_-C&>^#!{-X_hVTWxRPa>@U%&YF_%~Oe+NIwm!;_pq`^pu@*mPp~ z=4hCXZck`2p1Wea4TbG2XjR}q(<*X(jyFG;+j7b6w6?Zig>Ccjo+vITO2-mSRhd3q*=jdfg(YASQ0}r^vMu zKj8EJLC5k;0vp)73)SXg1zuhO(bo}JUPqtXoV7TYx6$vNFX+5LUC!>L(YwK4s zdfMsY#W$;?ksnbzKmqWJ3bKXrS&Jq#)7HZG64W5TceZ9e+i2-_$H2OlMTnLql#KDE z^cMtva@}|HxfcAU!WKG4_<>cAC`TcNGYGF@4}S%}=Jw_Qqx_X~Wi3A=@FQPJAVJDq zW1}y)>{;+W?9T=7cl`-i$nFL1bOUSLvP3RW<~@MdUEqWHf*4uOKj6s{%ElH^-XAy; zsaC(o%|K_p{GD5ZLVK`1P!|YSL>@wYgf*oYHH+Bv2(={`y-_ND_~*`z5C{o5t{=Kv1MQhk+EHi zs2>c!)E)?LtqZiZK0<@QLo~LR)s-z^o8%zilGjV7!3u*MRg;NYGSEooqvZVvnIFJD zTqGB_Xt_(DZ_$B!=)`>-#RGKVR~*Oh=y5r`fC|RyID~ehhjEp@&D>!Xw{e(nQaDd? z3Hq)$ literal 0 HcmV?d00001 diff --git a/Example/build/classes/org/sleuthkit/autopsy/example/ExampleKeyValueChildFactory.class b/Example/build/classes/org/sleuthkit/autopsy/example/ExampleKeyValueChildFactory.class new file mode 100644 index 0000000000000000000000000000000000000000..6efdcf2936c8de10bf6f43e6822e8aec8a208ede GIT binary patch literal 1834 zcmb7ETTc@~6#ix@t=q1pf>c37y!Qeu;uVWT0@SDtN+6B;Hnfwnxa>CDT|@tq4{B7R zCdOxfl<~}VDGO;E`qJr{J?HzrbD8t^-_PFw=CK$@92pfVvI*pnk6~KH3})kqK#yTA zPG9cCFdxHRhN!z^ShWU2y0ptbaNTnaQ(v)7Q&e2Twh9dDrctxF>p6nqSx2YElI_&= zhABLE=e^~oEwj^0$iBO}9hGn=*3}cy&n1yVaA+kcz z3_~Tu66@aHws5xiwn;a`CA-4SGItDV2bU2_g%T-rQ6u*GUfmS>TI)QNw6bHE)grIB zw$mhC>Ep=F`XTy@&N}`XkDq z_X)``9pq-_MD0+8gihgdQ9c4 z6r^DY_cSD+#c*H413aYkPW$X+A!B%?VF8aN5EXUiw6Xq^)i8-G3=5ruPVurBCS~mL z{)Q{aFp!ZiBYCui5Uu9&e-QhQGbf=EAt<#CrQ$kn5QGv`{w8ku5^nzoDHZL2 literal 0 HcmV?d00001 diff --git a/Example/build/classes/org/sleuthkit/autopsy/example/ExampleModel.class b/Example/build/classes/org/sleuthkit/autopsy/example/ExampleModel.class new file mode 100644 index 0000000000000000000000000000000000000000..207e180d44a0dd6e09be253a0f7061ed01ab453b GIT binary patch literal 377 zcma)2yH3ME5S(>POpHSwJQ^yx#6p}z3!*_pie#Vwxj&mza^Ye}_8EoGqKG0<@Bw@j zVog#|qSM~)%*~8+`}O_t3E%=pK3sHLXrSkz@8N(zORh1Yd8IRLuL@w40G=jqi@WVAIJXyhcXXL==d!N0)9{U5|ujM(>^%KKz> H?d$vih`>+1 literal 0 HcmV?d00001 diff --git a/Example/build/classes/org/sleuthkit/autopsy/example/ExampleTopComponent$1.class b/Example/build/classes/org/sleuthkit/autopsy/example/ExampleTopComponent$1.class new file mode 100644 index 0000000000000000000000000000000000000000..b1b74e1999056588db7619102f7888a3c69253d7 GIT binary patch literal 941 zcmbVLTWb?R6#gdJcHMPtV0?Zqg$h}(F3sR$)R5MmWAd7o^K$<)nE*qucES%RYY z;1BReiD%ZJFQt$!?71=Xo!d9Re*gFh-~sLi@NhH45;j6y$EJ^4KDK;p3oP4_%By<< z54$EC#(7FpJ9@8dET`5?@=q~+l;cTCap$i-GLyC$PmCsQ_xbu$rImdq@T7Kz`}LlH z*ERzZSnVoJhtqMNvLo3~IdZ9M5}Ed7rkp%Zw$CPm4 zn9<}xs$R5)Vm*)rvbA+Jr z1)}*K<^KR-0o~-Z_X?1;!Vl&ku8b?V$}nZDF=z?bu+G}!H+TaTwp@`OYySQKbi(;I literal 0 HcmV?d00001 diff --git a/Example/build/classes/org/sleuthkit/autopsy/example/ExampleTopComponent.class b/Example/build/classes/org/sleuthkit/autopsy/example/ExampleTopComponent.class new file mode 100644 index 0000000000000000000000000000000000000000..808349eab93c6ad103b168cf0b1b505e5e70ae04 GIT binary patch literal 2762 zcmbVOds7=#6#v}-*|1&SQeJ&QsSSx`q194LE$;#~L@bD+^>ImV!8Cr^bOJwc5aHq?jXIl)Nndf|)S9EvBunPL)fK15v1H&@BhYWX<|3lNz8bkdI z=^>RF!xGtYaYHz(e8VJ4d&bUjbB#NO+=s+^Z_{wk?bfPYnz4%|+Y**X#x_e^4+$iu zE-5XDn|#+Udkj6toSb*;aw+3~BHk+}LNb-}4BJ{3&NJI7iaf*Bq|dGM9ZwhAq)-na zb8@ztG!wJ|7f+#&A7Bab_5(aXbzXK4Vt|G-F#Hr=H;WUmD5U;4Cuq zMNk24iCYwn0NGz7e}hw|QLu`17#SKPYb7%`HM^LdXSnW%>7d6&Qh&rsji4jv2=0kx z?r_r-rVnFiId%zZ!<5YP5}hEQ5_VUHiAYusdu&*Gr@44S0~vEGxw!Z?#^0!A{ITdUB*;)dO$vTs zXb3a5P&-3D;tbP|$tT0xsW=yG$9O4A_8>K3!Jp=OD4&j4D{-y~$1~`r3+*~z_l#cH zRL_TtP~-P~VM*QU9ix?(>DXuM9lEFmPOIkksaD*YODw5b1u zC@~Du*iLw$o5mhAq8Cl*!wsTb47l(vZqknUeJyn1$ZI2%{WraFr0iFzeKf4^A^sXl z>NhAINVGTp4z-F4a=Q<0os>3J(Y%iqxopj((p9vj)4!s5&vF={@unhQb?0u zF?mad{!RLOAVHSZRnd2(MfLrjhJu-hw8UYw5*Q}EtTjQJM?-1%iAP2&o=We59m$H* zcc3F8Cr%azQIF$}ltX;)6DEcaNFT`326|!!zeRd2<|ljT_1J< + + + + + + + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/nbproject/genfiles.properties b/Example/nbproject/genfiles.properties new file mode 100644 index 0000000000..ec4f808a44 --- /dev/null +++ b/Example/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=9a4a6521 +build.xml.script.CRC32=8c5f554c +build.xml.stylesheet.CRC32=a56c6a5b@1.46.2 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=9a4a6521 +nbproject/build-impl.xml.script.CRC32=ae819cf0 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.46.2 diff --git a/Example/nbproject/platform.properties b/Example/nbproject/platform.properties new file mode 100644 index 0000000000..38ecd5a92e --- /dev/null +++ b/Example/nbproject/platform.properties @@ -0,0 +1,99 @@ +cluster.path=\ + ${nbplatform.active.dir}/java:\ + ${nbplatform.active.dir}/platform +disabled.modules=\ + org.apache.tools.ant.module,\ + org.netbeans.api.debugger.jpda,\ + org.netbeans.api.java,\ + org.netbeans.libs.cglib,\ + org.netbeans.libs.javacapi,\ + org.netbeans.libs.javacimpl,\ + org.netbeans.libs.jsr223,\ + org.netbeans.libs.springframework,\ + org.netbeans.modules.ant.browsetask,\ + org.netbeans.modules.ant.debugger,\ + org.netbeans.modules.ant.freeform,\ + org.netbeans.modules.ant.grammar,\ + org.netbeans.modules.ant.kit,\ + org.netbeans.modules.beans,\ + org.netbeans.modules.classfile,\ + org.netbeans.modules.dbschema,\ + org.netbeans.modules.debugger.jpda,\ + org.netbeans.modules.debugger.jpda.ant,\ + org.netbeans.modules.debugger.jpda.projects,\ + org.netbeans.modules.debugger.jpda.ui,\ + org.netbeans.modules.form,\ + org.netbeans.modules.form.j2ee,\ + org.netbeans.modules.form.kit,\ + org.netbeans.modules.hibernate,\ + org.netbeans.modules.hibernatelib,\ + org.netbeans.modules.hudson.ant,\ + org.netbeans.modules.hudson.maven,\ + org.netbeans.modules.i18n,\ + org.netbeans.modules.i18n.form,\ + org.netbeans.modules.j2ee.core.utilities,\ + org.netbeans.modules.j2ee.eclipselink,\ + org.netbeans.modules.j2ee.eclipselinkmodelgen,\ + org.netbeans.modules.j2ee.jpa.refactoring,\ + org.netbeans.modules.j2ee.jpa.verification,\ + org.netbeans.modules.j2ee.metadata,\ + org.netbeans.modules.j2ee.metadata.model.support,\ + org.netbeans.modules.j2ee.persistence,\ + org.netbeans.modules.j2ee.persistence.kit,\ + org.netbeans.modules.j2ee.persistenceapi,\ + org.netbeans.modules.j2ee.toplinklib,\ + org.netbeans.modules.java.api.common,\ + org.netbeans.modules.java.debug,\ + org.netbeans.modules.java.editor,\ + org.netbeans.modules.java.editor.lib,\ + org.netbeans.modules.java.examples,\ + org.netbeans.modules.java.freeform,\ + org.netbeans.modules.java.guards,\ + org.netbeans.modules.java.helpset,\ + org.netbeans.modules.java.hints,\ + org.netbeans.modules.java.hints.processor,\ + org.netbeans.modules.java.j2seplatform,\ + org.netbeans.modules.java.j2seproject,\ + org.netbeans.modules.java.kit,\ + org.netbeans.modules.java.lexer,\ + org.netbeans.modules.java.navigation,\ + org.netbeans.modules.java.platform,\ + org.netbeans.modules.java.preprocessorbridge,\ + org.netbeans.modules.java.project,\ + org.netbeans.modules.java.source,\ + org.netbeans.modules.java.source.ant,\ + org.netbeans.modules.java.sourceui,\ + org.netbeans.modules.javadoc,\ + org.netbeans.modules.javawebstart,\ + org.netbeans.modules.jellytools,\ + org.netbeans.modules.jellytools.java,\ + org.netbeans.modules.junit,\ + org.netbeans.modules.maven,\ + org.netbeans.modules.maven.coverage,\ + org.netbeans.modules.maven.embedder,\ + org.netbeans.modules.maven.grammar,\ + org.netbeans.modules.maven.graph,\ + org.netbeans.modules.maven.hints,\ + org.netbeans.modules.maven.indexer,\ + org.netbeans.modules.maven.junit,\ + org.netbeans.modules.maven.kit,\ + org.netbeans.modules.maven.model,\ + org.netbeans.modules.maven.osgi,\ + org.netbeans.modules.maven.persistence,\ + org.netbeans.modules.maven.repository,\ + org.netbeans.modules.maven.search,\ + org.netbeans.modules.maven.spring,\ + org.netbeans.modules.projectimport.eclipse.core,\ + org.netbeans.modules.projectimport.eclipse.j2se,\ + org.netbeans.modules.refactoring.java,\ + org.netbeans.modules.spellchecker.bindings.java,\ + org.netbeans.modules.spring.beans,\ + org.netbeans.modules.swingapp,\ + org.netbeans.modules.websvc.jaxws21,\ + org.netbeans.modules.websvc.jaxws21api,\ + org.netbeans.modules.websvc.saas.codegen.java,\ + org.netbeans.modules.xml.jaxb,\ + org.netbeans.modules.xml.tools.java,\ + org.openide.compat,\ + org.openide.util.enumerations +nbplatform.active=default diff --git a/Example/nbproject/project.properties b/Example/nbproject/project.properties new file mode 100644 index 0000000000..17255bac6b --- /dev/null +++ b/Example/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.6 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/Example/nbproject/project.xml b/Example/nbproject/project.xml new file mode 100644 index 0000000000..05fc6646ef --- /dev/null +++ b/Example/nbproject/project.xml @@ -0,0 +1,72 @@ + + + org.netbeans.modules.apisupport.project + + + org.sleuthkit.autopsy.example + + + + org.openide.nodes + + + + 7.21.1 + + + + org.openide.util + + + + 8.15.1 + + + + org.openide.util.lookup + + + + 8.8.1 + + + + org.openide.windows + + + + 6.40.1 + + + + org.sleuthkit.autopsy.corecomponentinterfaces + + + + 1 + 1.0 + + + + org.sleuthkit.autopsy.corecomponents + + + + 1 + 1.0 + + + + org.sleuthkit.autopsy.datamodel + + + + 1 + 1.0 + + + + + + + diff --git a/Example/nbproject/suite.properties b/Example/nbproject/suite.properties new file mode 100644 index 0000000000..29d7cc9bd6 --- /dev/null +++ b/Example/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/Example/src/org/sleuthkit/autopsy/example/Bundle.properties b/Example/src/org/sleuthkit/autopsy/example/Bundle.properties new file mode 100644 index 0000000000..3bba77cab7 --- /dev/null +++ b/Example/src/org/sleuthkit/autopsy/example/Bundle.properties @@ -0,0 +1,2 @@ +OpenIDE-Module-Name=Example +ExampleTopComponent.makeNodesButton.text=Make Nodes diff --git a/Example/src/org/sleuthkit/autopsy/example/ExampleDataExplorer.java b/Example/src/org/sleuthkit/autopsy/example/ExampleDataExplorer.java new file mode 100644 index 0000000000..5797470aea --- /dev/null +++ b/Example/src/org/sleuthkit/autopsy/example/ExampleDataExplorer.java @@ -0,0 +1,71 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.sleuthkit.autopsy.example; + +import java.beans.PropertyChangeEvent; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.lookup.ServiceProvider; +import org.openide.windows.TopComponent; +import org.sleuthkit.autopsy.corecomponentinterfaces.DataExplorer; +import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent; +import org.sleuthkit.autopsy.datamodel.KeyValueThing; + + +@ServiceProvider(service = DataExplorer.class) +public class ExampleDataExplorer implements DataExplorer { + + ExampleTopComponent tc; + + public ExampleDataExplorer() { + tc = new ExampleTopComponent(this); + tc.setName("Example"); + } + + @Override + public org.openide.windows.TopComponent getTopComponent() { + return tc; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + // nothing to do in simple example + } + + static final int NUMBER_THING_ID = 41234; + + void makeNodes() { + Collection things = new ArrayList(); + + for (int i = 1; i <= 10; i++) { + for (int j = 1; j <= 10; j++) { + Map kvs = new LinkedHashMap(); + kvs.put("x", i); + kvs.put("y", j); + kvs.put("sum", i+j); + kvs.put("product", i*j); + + things.add(new KeyValueThing(i + " and " + j, kvs, + NUMBER_THING_ID)); + } + } + + Children childThingNodes = + Children.create(new ExampleKeyValueChildFactory(things), true); + + Node rootNode = new AbstractNode(childThingNodes); + String pathText = "foo"; + + TopComponent searchResultWin = + DataResultTopComponent.createInstance("Keyword search", + pathText, rootNode, things.size()); + searchResultWin.requestActive(); // make it the active top component + } +} diff --git a/Example/src/org/sleuthkit/autopsy/example/ExampleKeyValueChildFactory.java b/Example/src/org/sleuthkit/autopsy/example/ExampleKeyValueChildFactory.java new file mode 100644 index 0000000000..5dab6d6139 --- /dev/null +++ b/Example/src/org/sleuthkit/autopsy/example/ExampleKeyValueChildFactory.java @@ -0,0 +1,28 @@ +package org.sleuthkit.autopsy.example; + +import java.util.Collection; +import java.util.List; +import org.openide.nodes.ChildFactory; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.sleuthkit.autopsy.datamodel.KeyValueNode; +import org.sleuthkit.autopsy.datamodel.KeyValueThing; + +public class ExampleKeyValueChildFactory extends ChildFactory { + + private Collection things; + + public ExampleKeyValueChildFactory(Collection things) { + this.things = things; + } + + @Override + protected boolean createKeys(List toPopulate) { + return toPopulate.addAll(things); + } + + @Override + protected Node createNodeForKey(KeyValueThing thing) { + return new KeyValueNode(thing, Children.LEAF); + } +} diff --git a/Example/src/org/sleuthkit/autopsy/example/ExampleModel.java b/Example/src/org/sleuthkit/autopsy/example/ExampleModel.java new file mode 100644 index 0000000000..e9c1af3c89 --- /dev/null +++ b/Example/src/org/sleuthkit/autopsy/example/ExampleModel.java @@ -0,0 +1,15 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.sleuthkit.autopsy.example; + +public class ExampleModel { + + int x; + + ExampleModel(int x) { + this.x = x; + } + +} diff --git a/Example/src/org/sleuthkit/autopsy/example/ExampleTopComponent.form b/Example/src/org/sleuthkit/autopsy/example/ExampleTopComponent.form new file mode 100644 index 0000000000..63d3073671 --- /dev/null +++ b/Example/src/org/sleuthkit/autopsy/example/ExampleTopComponent.form @@ -0,0 +1,48 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/Example/src/org/sleuthkit/autopsy/example/ExampleTopComponent.java b/Example/src/org/sleuthkit/autopsy/example/ExampleTopComponent.java new file mode 100644 index 0000000000..73a4304b8c --- /dev/null +++ b/Example/src/org/sleuthkit/autopsy/example/ExampleTopComponent.java @@ -0,0 +1,72 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/* + * ExampleTopComponent.java + * + * Created on Dec 12, 2011, 1:55:46 PM + */ +package org.sleuthkit.autopsy.example; + +import org.openide.windows.TopComponent; + +/** + * + * @author pmartel + */ +public class ExampleTopComponent extends TopComponent { + + ExampleDataExplorer edx; + + /** Creates new form ExampleTopComponent */ + public ExampleTopComponent(ExampleDataExplorer edx) { + this.edx = edx; + initComponents(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + makeNodesButton = new javax.swing.JButton(); + + makeNodesButton.setText(org.openide.util.NbBundle.getMessage(ExampleTopComponent.class, "ExampleTopComponent.makeNodesButton.text")); // NOI18N + makeNodesButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + makeNodesButtonActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(makeNodesButton) + .addContainerGap(299, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(makeNodesButton) + .addContainerGap(266, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + private void makeNodesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_makeNodesButtonActionPerformed + edx.makeNodes(); + }//GEN-LAST:event_makeNodesButtonActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton makeNodesButton; + // End of variables declaration//GEN-END:variables +} diff --git a/nbproject/project.properties b/nbproject/project.properties index d78ab488e8..7bd51a49ed 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -17,11 +17,13 @@ modules=\ ${project.org.sleuthkit.autopsy.filesearch}:\ ${project.org.sleuthkit.autopsy.datamodel}:\ ${project.org.sleuthkit.autopsy.logging}:\ - ${project.org.sleuthkit.autopsy.casemodule} + ${project.org.sleuthkit.autopsy.casemodule}:\ + ${project.org.sleuthkit.autopsy.example} project.org.sleuthkit.autopsy.casemodule=Case project.org.sleuthkit.autopsy.corecomponentinterfaces=CoreComponentInterfaces project.org.sleuthkit.autopsy.corecomponents=CoreComponents project.org.sleuthkit.autopsy.directorytree=DirectoryTree +project.org.sleuthkit.autopsy.example=Example project.org.sleuthkit.autopsy.filesearch=FileSearch project.org.sleuthkit.autopsy.logging=Logging project.org.sleuthkit.autopsy.menuactions=MenuActions From 987465cc6bb8fb5486d8b4b060e3fc628293399d Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Tue, 13 Dec 2011 14:00:38 -0500 Subject: [PATCH 10/21] Example project added --- .gitignore | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 659adb6a24..53f67fc0b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,6 @@ -/Case/build/ -/CoreComponentInterfaces/build/ -/DirectoryTree/build/ -/CoreComponents/build/ /dist/ /build/ -/DataModel/build/ -/MenuActions/build/ -/Logging/build/ -/FileSearch/build/ +/*/build/ */nbproject/private/* /nbproject/private/* /DataModel/release/modules/lib/libewf.dll From ad841ccffc82054b0a2db4cfb41e8b0d823f279e Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Tue, 13 Dec 2011 14:04:04 -0500 Subject: [PATCH 11/21] Fix DataContent bug --- .../corecomponents/DataContentTopComponent.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java index b29194460c..9a50602602 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java @@ -225,12 +225,20 @@ public final class DataContentTopComponent extends TopComponent implements DataC // change the cursor to "waiting cursor" for this operation this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { + + + String defaultName = NbBundle.getMessage(DataContentTopComponent.class, "CTL_DataContentTopComponent"); // set the file path if (selectedNode == null) { - setName(NbBundle.getMessage(DataContentTopComponent.class, "CTL_DataContentTopComponent")); + setName(defaultName); } else { - String path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(selectedNode.getLookup().lookup(Content.class)), 0); - setName(path); + Content content = selectedNode.getLookup().lookup(Content.class); + if (content != null) { + String path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(selectedNode.getLookup().lookup(Content.class)), 0); + setName(path); + } else { + setName(defaultName); + } } currentNode = selectedNode; From 8776ab2bb73e52bff06b264cec5e6b7ca3dc57ac Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Tue, 13 Dec 2011 14:11:13 -0500 Subject: [PATCH 12/21] Remove cleaned files --- ....autopsy.corecomponentinterfaces.DataExplorer | 1 - .../sleuthkit/autopsy/example/Bundle.properties | 2 -- .../autopsy/example/ExampleDataExplorer.class | Bin 3099 -> 0 bytes .../example/ExampleKeyValueChildFactory.class | Bin 1834 -> 0 bytes .../sleuthkit/autopsy/example/ExampleModel.class | Bin 377 -> 0 bytes .../autopsy/example/ExampleTopComponent$1.class | Bin 941 -> 0 bytes .../autopsy/example/ExampleTopComponent.class | Bin 2762 -> 0 bytes Example/build/no-license.txt | 1 - 8 files changed, 4 deletions(-) delete mode 100644 Example/build/classes/META-INF/services/org.sleuthkit.autopsy.corecomponentinterfaces.DataExplorer delete mode 100644 Example/build/classes/org/sleuthkit/autopsy/example/Bundle.properties delete mode 100644 Example/build/classes/org/sleuthkit/autopsy/example/ExampleDataExplorer.class delete mode 100644 Example/build/classes/org/sleuthkit/autopsy/example/ExampleKeyValueChildFactory.class delete mode 100644 Example/build/classes/org/sleuthkit/autopsy/example/ExampleModel.class delete mode 100644 Example/build/classes/org/sleuthkit/autopsy/example/ExampleTopComponent$1.class delete mode 100644 Example/build/classes/org/sleuthkit/autopsy/example/ExampleTopComponent.class delete mode 100644 Example/build/no-license.txt diff --git a/Example/build/classes/META-INF/services/org.sleuthkit.autopsy.corecomponentinterfaces.DataExplorer b/Example/build/classes/META-INF/services/org.sleuthkit.autopsy.corecomponentinterfaces.DataExplorer deleted file mode 100644 index 82bea797ae..0000000000 --- a/Example/build/classes/META-INF/services/org.sleuthkit.autopsy.corecomponentinterfaces.DataExplorer +++ /dev/null @@ -1 +0,0 @@ -org.sleuthkit.autopsy.example.ExampleDataExplorer diff --git a/Example/build/classes/org/sleuthkit/autopsy/example/Bundle.properties b/Example/build/classes/org/sleuthkit/autopsy/example/Bundle.properties deleted file mode 100644 index 3bba77cab7..0000000000 --- a/Example/build/classes/org/sleuthkit/autopsy/example/Bundle.properties +++ /dev/null @@ -1,2 +0,0 @@ -OpenIDE-Module-Name=Example -ExampleTopComponent.makeNodesButton.text=Make Nodes diff --git a/Example/build/classes/org/sleuthkit/autopsy/example/ExampleDataExplorer.class b/Example/build/classes/org/sleuthkit/autopsy/example/ExampleDataExplorer.class deleted file mode 100644 index 96b9c07cf04231551df406bd3ae227c8234865db..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3099 zcmb7GZBr9h6n-uQHmpG~DuRXzYAY{dYJI7KVi7^9fL0KS)#{QgWFhRv%?60tceUEu z*FWHN`k{XCLp#%gN~bgRV}FvD$ZeK4My>H5Mx1{58@pK7ZhAnQH??QcsGbk z^7pcQXr;h+VHH&vUxOIp3Un29m{2i^gaSiF1XDpw2a%NXGb&72DpI(jz*dk};0TmB zF@e4PmOU9wC-sbzm^PfKmT|09IvdsJwV6~>kM?-K!&a)>nn_uvZaN(TRfFdSj`f_q zG<>pe@WiFQ;{u{jpt9RC(~f33BU&<}3zQ!=OvC9EC~ayU5eRf!aaybT4O1V?%#7>y zur{8gCERbtwB(3p8*-d82AqVEe&O{U*Bq^9K9#g=-InW{)E)nl1$HzwyOmlg-8ABQ zbj~p2)?7O3_hR7MluZxY$#y3+bCPS@-qb&(&1%tcT{F|sGexsKvyu&2TB$xuLL2_e zRiI)R`2)KM+y!v&*`(A9-m_U9i3dq313`+m&5K_ zmMc0=iOjITWb~AtbrtFo=OR@OIa+L*xn1!o$Ox!IR>qF$y@ph1ZSENOWwu-DB7|1# z64>*<50MO<4dE5+6j<*n%vC^_ZEM+nBTecz6|6il(|Y`*mQHYq6vw=Rxe(@&Rd6+g zYq(BZmV!!WW&{*UIG%|Sp>5?=twKaTqi?T|WvCq84&gn#FHqK?nehfW_#lK2@sTXy zV{#S3C%7SSXyt6rHIh8{t|)u8m}A*l33OAztq?xNZGo30Q2v~H67CvLJ2suAK&AH` z7CT{CJg>x?v+Q_-C&>^#!{-X_hVTWxRPa>@U%&YF_%~Oe+NIwm!;_pq`^pu@*mPp~ z=4hCXZck`2p1Wea4TbG2XjR}q(<*X(jyFG;+j7b6w6?Zig>Ccjo+vITO2-mSRhd3q*=jdfg(YASQ0}r^vMu zKj8EJLC5k;0vp)73)SXg1zuhO(bo}JUPqtXoV7TYx6$vNFX+5LUC!>L(YwK4s zdfMsY#W$;?ksnbzKmqWJ3bKXrS&Jq#)7HZG64W5TceZ9e+i2-_$H2OlMTnLql#KDE z^cMtva@}|HxfcAU!WKG4_<>cAC`TcNGYGF@4}S%}=Jw_Qqx_X~Wi3A=@FQPJAVJDq zW1}y)>{;+W?9T=7cl`-i$nFL1bOUSLvP3RW<~@MdUEqWHf*4uOKj6s{%ElH^-XAy; zsaC(o%|K_p{GD5ZLVK`1P!|YSL>@wYgf*oYHH+Bv2(={`y-_ND_~*`z5C{o5t{=Kv1MQhk+EHi zs2>c!)E)?LtqZiZK0<@QLo~LR)s-z^o8%zilGjV7!3u*MRg;NYGSEooqvZVvnIFJD zTqGB_Xt_(DZ_$B!=)`>-#RGKVR~*Oh=y5r`fC|RyID~ehhjEp@&D>!Xw{e(nQaDd? z3Hq)$ diff --git a/Example/build/classes/org/sleuthkit/autopsy/example/ExampleKeyValueChildFactory.class b/Example/build/classes/org/sleuthkit/autopsy/example/ExampleKeyValueChildFactory.class deleted file mode 100644 index 6efdcf2936c8de10bf6f43e6822e8aec8a208ede..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1834 zcmb7ETTc@~6#ix@t=q1pf>c37y!Qeu;uVWT0@SDtN+6B;Hnfwnxa>CDT|@tq4{B7R zCdOxfl<~}VDGO;E`qJr{J?HzrbD8t^-_PFw=CK$@92pfVvI*pnk6~KH3})kqK#yTA zPG9cCFdxHRhN!z^ShWU2y0ptbaNTnaQ(v)7Q&e2Twh9dDrctxF>p6nqSx2YElI_&= zhABLE=e^~oEwj^0$iBO}9hGn=*3}cy&n1yVaA+kcz z3_~Tu66@aHws5xiwn;a`CA-4SGItDV2bU2_g%T-rQ6u*GUfmS>TI)QNw6bHE)grIB zw$mhC>Ep=F`XTy@&N}`XkDq z_X)``9pq-_MD0+8gihgdQ9c4 z6r^DY_cSD+#c*H413aYkPW$X+A!B%?VF8aN5EXUiw6Xq^)i8-G3=5ruPVurBCS~mL z{)Q{aFp!ZiBYCui5Uu9&e-QhQGbf=EAt<#CrQ$kn5QGv`{w8ku5^nzoDHZL2 diff --git a/Example/build/classes/org/sleuthkit/autopsy/example/ExampleModel.class b/Example/build/classes/org/sleuthkit/autopsy/example/ExampleModel.class deleted file mode 100644 index 207e180d44a0dd6e09be253a0f7061ed01ab453b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 377 zcma)2yH3ME5S(>POpHSwJQ^yx#6p}z3!*_pie#Vwxj&mza^Ye}_8EoGqKG0<@Bw@j zVog#|qSM~)%*~8+`}O_t3E%=pK3sHLXrSkz@8N(zORh1Yd8IRLuL@w40G=jqi@WVAIJXyhcXXL==d!N0)9{U5|ujM(>^%KKz> H?d$vih`>+1 diff --git a/Example/build/classes/org/sleuthkit/autopsy/example/ExampleTopComponent$1.class b/Example/build/classes/org/sleuthkit/autopsy/example/ExampleTopComponent$1.class deleted file mode 100644 index b1b74e1999056588db7619102f7888a3c69253d7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 941 zcmbVLTWb?R6#gdJcHMPtV0?Zqg$h}(F3sR$)R5MmWAd7o^K$<)nE*qucES%RYY z;1BReiD%ZJFQt$!?71=Xo!d9Re*gFh-~sLi@NhH45;j6y$EJ^4KDK;p3oP4_%By<< z54$EC#(7FpJ9@8dET`5?@=q~+l;cTCap$i-GLyC$PmCsQ_xbu$rImdq@T7Kz`}LlH z*ERzZSnVoJhtqMNvLo3~IdZ9M5}Ed7rkp%Zw$CPm4 zn9<}xs$R5)Vm*)rvbA+Jr z1)}*K<^KR-0o~-Z_X?1;!Vl&ku8b?V$}nZDF=z?bu+G}!H+TaTwp@`OYySQKbi(;I diff --git a/Example/build/classes/org/sleuthkit/autopsy/example/ExampleTopComponent.class b/Example/build/classes/org/sleuthkit/autopsy/example/ExampleTopComponent.class deleted file mode 100644 index 808349eab93c6ad103b168cf0b1b505e5e70ae04..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2762 zcmbVOds7=#6#v}-*|1&SQeJ&QsSSx`q194LE$;#~L@bD+^>ImV!8Cr^bOJwc5aHq?jXIl)Nndf|)S9EvBunPL)fK15v1H&@BhYWX<|3lNz8bkdI z=^>RF!xGtYaYHz(e8VJ4d&bUjbB#NO+=s+^Z_{wk?bfPYnz4%|+Y**X#x_e^4+$iu zE-5XDn|#+Udkj6toSb*;aw+3~BHk+}LNb-}4BJ{3&NJI7iaf*Bq|dGM9ZwhAq)-na zb8@ztG!wJ|7f+#&A7Bab_5(aXbzXK4Vt|G-F#Hr=H;WUmD5U;4Cuq zMNk24iCYwn0NGz7e}hw|QLu`17#SKPYb7%`HM^LdXSnW%>7d6&Qh&rsji4jv2=0kx z?r_r-rVnFiId%zZ!<5YP5}hEQ5_VUHiAYusdu&*Gr@44S0~vEGxw!Z?#^0!A{ITdUB*;)dO$vTs zXb3a5P&-3D;tbP|$tT0xsW=yG$9O4A_8>K3!Jp=OD4&j4D{-y~$1~`r3+*~z_l#cH zRL_TtP~-P~VM*QU9ix?(>DXuM9lEFmPOIkksaD*YODw5b1u zC@~Du*iLw$o5mhAq8Cl*!wsTb47l(vZqknUeJyn1$ZI2%{WraFr0iFzeKf4^A^sXl z>NhAINVGTp4z-F4a=Q<0os>3J(Y%iqxopj((p9vj)4!s5&vF={@unhQb?0u zF?mad{!RLOAVHSZRnd2(MfLrjhJu-hw8UYw5*Q}EtTjQJM?-1%iAP2&o=We59m$H* zcc3F8Cr%azQIF$}ltX;)6DEcaNFT`326|!!zeRd2<|ljT_1J< Date: Wed, 14 Dec 2011 14:44:57 -0500 Subject: [PATCH 13/21] DataResultFilterNode cleanup - actions generated from ContentVisitor - use passed-in exploremanager instead of looking up the DirectoryTreeTopComponent --- .../directorytree/DataResultFilterNode.java | 123 ++++++++++++------ .../DirectoryTreeTopComponent.java | 1 - 2 files changed, 83 insertions(+), 41 deletions(-) diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java index 42532e493a..6d56da242a 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java @@ -21,8 +21,8 @@ package org.sleuthkit.autopsy.directorytree; import java.awt.event.ActionEvent; import java.beans.PropertyVetoException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import org.sleuthkit.autopsy.datamodel.ImageNode; import org.sleuthkit.autopsy.datamodel.VolumeNode; import org.sleuthkit.autopsy.datamodel.FileNode; import org.sleuthkit.autopsy.datamodel.DirectoryNode; @@ -35,6 +35,11 @@ import org.openide.nodes.FilterNode; import org.openide.nodes.Node; import org.openide.nodes.Sheet; import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.ContentVisitor; +import org.sleuthkit.datamodel.Directory; +import org.sleuthkit.datamodel.File; +import org.sleuthkit.datamodel.Image; +import org.sleuthkit.datamodel.Volume; /** * This class wraps nodes as they are passed to the DataResult viewers. It @@ -43,11 +48,14 @@ import org.sleuthkit.datamodel.Content; public class DataResultFilterNode extends FilterNode{ private ExplorerManager sourceEm; + private final ContentVisitor> getActionsCV; + /** the constructor */ public DataResultFilterNode(Node arg, ExplorerManager em) { super(arg, new DataResultFilterChildren(arg, em)); this.sourceEm = em; + getActionsCV = new GetActionsContentVisitor(); } /** @@ -61,41 +69,84 @@ public class DataResultFilterNode extends FilterNode{ public Action[] getActions(boolean popup) { List actions = new ArrayList(); + + + actions.add(new NewWindowViewAction("View in New Window", getOriginal())); // TODO: ContentNode fix - restore right-click actions // TODO: ContentVisitor instead of instanceof Content nodeContent = this.getOriginal().getLookup().lookup(Content.class); + actions.addAll(nodeContent.accept(getActionsCV)); - Node originalNode = this.getOriginal(); - // right click action(s) for image node - if (originalNode instanceof ImageNode) { - actions.add(new NewWindowViewAction("View in New Window", (ImageNode) originalNode)); - actions.addAll(ShowDetailActionVisitor.getActions(nodeContent)); - } // right click action(s) for volume node - else if (originalNode instanceof VolumeNode) { - actions.add(new NewWindowViewAction("View in New Window", (VolumeNode) originalNode)); - //new ShowDetailActionVisitor("Volume Details", this.currentNode.getName(), (VolumeNode) this.currentNode), - actions.addAll(ShowDetailActionVisitor.getActions(nodeContent)); - actions.add(new ChangeViewAction("View", 0, this.getOriginal())); - } // right click action(s) for directory node - else if (originalNode instanceof DirectoryNode) { - actions.add(new NewWindowViewAction("View in New Window", (DirectoryNode) originalNode)); - actions.add(new ChangeViewAction("View", 0, originalNode)); - // TODO: ContentNode fix - reimplement ExtractAction - //actions.add(new ExtractAction("Extract Directory", (DirectoryNode) this.currentNode)); - } // right click action(s) for the file node - else if (originalNode instanceof FileNode) { - actions.add(new ExternalViewerAction("Open File in External Viewer", (FileNode) originalNode)); - actions.add(new NewWindowViewAction("View in New Window", (FileNode) originalNode)); - // TODO: ContentNode fix - reimplement ExtractAction - //actions.add(new ExtractAction("Extract", (FileNode) this.currentNode)); - actions.add(new ChangeViewAction("View", 0, originalNode)); - } +// // right click action(s) for image node +// if (originalNode instanceof ImageNode) { +// actions.add(new NewWindowViewAction("View in New Window", (ImageNode) originalNode)); +// actions.addAll(ShowDetailActionVisitor.getActions(nodeContent)); +// } // right click action(s) for volume node +// else if (originalNode instanceof VolumeNode) { +// actions.add(new NewWindowViewAction("View in New Window", (VolumeNode) originalNode)); +// //new ShowDetailActionVisitor("Volume Details", this.currentNode.getName(), (VolumeNode) this.currentNode), +// actions.addAll(ShowDetailActionVisitor.getActions(nodeContent)); +// actions.add(new ChangeViewAction("View", 0, this.getOriginal())); +// } // right click action(s) for directory node +// else if (originalNode instanceof DirectoryNode) { +// actions.add(new NewWindowViewAction("View in New Window", (DirectoryNode) originalNode)); +// actions.add(new ChangeViewAction("View", 0, originalNode)); +// // TODO: ContentNode fix - reimplement ExtractAction +// //actions.add(new ExtractAction("Extract Directory", (DirectoryNode) this.currentNode)); +// } // right click action(s) for the file node +// else if (originalNode instanceof FileNode) { +// actions.add(new ExternalViewerAction("Open File in External Viewer", (FileNode) originalNode)); +// actions.add(new NewWindowViewAction("View in New Window", (FileNode) originalNode)); +// // TODO: ContentNode fix - reimplement ExtractAction +// //actions.add(new ExtractAction("Extract", (FileNode) this.currentNode)); +// actions.add(new ChangeViewAction("View", 0, originalNode)); +// } return actions.toArray(new Action[actions.size()]); } + + private class GetActionsContentVisitor extends ContentVisitor.Default> { + + @Override + public List visit(Image img) { + return ShowDetailActionVisitor.getActions(img); + } + + @Override + public List visit(Volume vol) { + List actions = new ArrayList(); + actions.addAll(ShowDetailActionVisitor.getActions(vol)); + actions.add(new ChangeViewAction("View", 0, getOriginal())); + return actions; + } + + @Override + public List visit(Directory dir) { + List actions = new ArrayList(); + actions.add(new ChangeViewAction("View", 0, getOriginal())); + // TODO: ContentNode fix - reimplement ExtractAction + //actions.add(new ExtractAction("Extract Directory", (DirectoryNode) this.currentNode)); + return actions; + } + + @Override + public List visit(File f) { + List actions = new ArrayList(); + actions.add(new ExternalViewerAction("Open File in External Viewer", getOriginal())); + // TODO: ContentNode fix - reimplement ExtractAction + //actions.add(new ExtractAction("Extract", (FileNode) this.currentNode)); + return actions; + } + + @Override + protected List defaultVisit(Content cntnt) { + return Collections.EMPTY_LIST; + } + + } /** * Double click action for the nodes that we want to pass to the directory @@ -112,8 +163,7 @@ public class DataResultFilterNode extends FilterNode{ if (originalNode instanceof VolumeNode || (originalNode instanceof DirectoryNode && !originalNode.getDisplayName().equals("."))) { if (originalNode instanceof DirectoryNode && originalNode.getDisplayName().equals("..")) { - ExplorerManager em = DirectoryTreeTopComponent.findInstance().getExplorerManager(); - Node[] selectedNode = em.getSelectedNodes(); + Node[] selectedNode = sourceEm.getSelectedNodes(); Node selectedContext = selectedNode[0]; final Node parentNode = selectedContext.getParentNode(); @@ -122,7 +172,7 @@ public class DataResultFilterNode extends FilterNode{ @Override public void actionPerformed(ActionEvent e) { try { - DirectoryTreeTopComponent.findInstance().getExplorerManager().setSelectedNodes(new Node[]{parentNode}); + sourceEm.setSelectedNodes(new Node[]{parentNode}); } catch (PropertyVetoException ex) { Logger logger = Logger.getLogger(DataResultFilterNode.class.getName()); logger.log(Level.WARNING, "Error: can't open the parent directory.", ex); @@ -130,8 +180,7 @@ public class DataResultFilterNode extends FilterNode{ } }; } else { - ExplorerManager em = DirectoryTreeTopComponent.findInstance().getExplorerManager(); - final Node[] parentNode = em.getSelectedNodes(); + final Node[] parentNode = sourceEm.getSelectedNodes(); final Node parentContext = parentNode[0]; return new AbstractAction() { @@ -139,12 +188,11 @@ public class DataResultFilterNode extends FilterNode{ @Override public void actionPerformed(ActionEvent e) { if (parentContext != null) { - ExplorerManager em = DirectoryTreeTopComponent.findInstance().getExplorerManager(); for (int i = 0; i < parentContext.getChildren().getNodesCount(); i++) { Node selectedNode = parentContext.getChildren().getNodeAt(i); if (selectedNode != null && selectedNode.getName().equals(originalNode.getName())) { try { - em.setExploredContextAndSelection(selectedNode, new Node[]{selectedNode}); + sourceEm.setExploredContextAndSelection(selectedNode, new Node[]{selectedNode}); } catch (PropertyVetoException ex) { // throw an error here Logger logger = Logger.getLogger(DataResultFilterNode.class.getName()); @@ -156,12 +204,7 @@ public class DataResultFilterNode extends FilterNode{ } }; } - - } // // right click action(s) for the file node - // if(this.currentNode instanceof FileNode){ - // // .. put the code here - // } - else { + } else { return null; } } @@ -187,4 +230,4 @@ public class DataResultFilterNode extends FilterNode{ return propertySets; } -} +} \ No newline at end of file diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java index 58879d6205..e0a407e588 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java @@ -46,7 +46,6 @@ import org.openide.nodes.Node; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent; import org.sleuthkit.autopsy.datamodel.RootContentChildren; -import org.sleuthkit.autopsy.directorytree.DirectoryTreeFilterNode.OriginalNode; /** * Top component which displays something. From c903011f7a1ab4f39bb60b984e002fbf8b183bd7 Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Thu, 15 Dec 2011 18:01:37 -0500 Subject: [PATCH 14/21] Cleanup ExtractAction - extract File/Folder export to ExtractFscContentVisitor in ContentUtils --- .../autopsy/datamodel/ContentUtils.java | 119 +++++++ .../directorytree/DataResultFilterNode.java | 36 +- .../autopsy/directorytree/ExtractAction.java | 332 ++++++------------ 3 files changed, 230 insertions(+), 257 deletions(-) diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java index 89166b0828..9750d9489c 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java @@ -24,11 +24,14 @@ import java.io.IOException; import java.io.InputStream; import java.util.LinkedList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentVisitor; import org.sleuthkit.datamodel.Directory; import org.sleuthkit.datamodel.File; import org.sleuthkit.datamodel.FileSystem; +import org.sleuthkit.datamodel.FsContent; import org.sleuthkit.datamodel.Image; import org.sleuthkit.datamodel.TskException; import org.sleuthkit.datamodel.Volume; @@ -39,6 +42,8 @@ import org.sleuthkit.datamodel.VolumeSystem; */ public final class ContentUtils { + private final static Logger logger = Logger.getLogger(ContentUtils.class.getName()); + // don't instantiate private ContentUtils() { throw new AssertionError(); @@ -201,4 +206,118 @@ public final class ContentUtils { out.close(); } } + + /** + * Helper to ignore the '.' and '..' directories + */ + public static boolean isDotDirectory(Directory dir) { + String name = dir.getName(); + return name.equals(".") || name.equals(".."); + } + + + /** + * Extracts file/folder as given destination file, recursing into folders. + * Assumes there will be no collisions with existing directories/files, and + * that the directory to contain the destination file already exists. + */ + public static class ExtractFscContentVisitor extends ContentVisitor.Default { + + java.io.File dest; + + /** + * Make new extractor for a specific destination + * @param dest The file/folder visited will be extracted as this file + */ + public ExtractFscContentVisitor(java.io.File dest) { + this.dest = dest; + } + + /** + * Convenience method to make a new instance for given destination + * and extract given content + */ + public static void extract(Content cntnt, java.io.File dest) { + cntnt.accept(new ExtractFscContentVisitor(dest)); + } + + public Void visit(File f) { + try { + ContentUtils.writeToFile(f, dest); + } catch (IOException ex) { + logger.log(Level.SEVERE, + "Trouble extracting file to " + dest.getAbsolutePath(), + ex); + } + return null; + } + + @Override + public Void visit(Directory dir) { + + // don't extract . and .. directories + if (isDotDirectory(dir)) { + return null; + } + + dest.mkdir(); + + // member visitor to generate destination files for children + DestFileContentVisitor destFileCV = new DestFileContentVisitor(); + + try { + // recurse on children + for (Content child : dir.getChildren()) { + java.io.File childFile = child.accept(destFileCV); + ExtractFscContentVisitor childVisitor = + new ExtractFscContentVisitor(childFile); + child.accept(childVisitor); + } + } catch (TskException ex) { + logger.log(Level.SEVERE, + "Trouble fetching children to extract.", ex); + } + + return null; + } + + @Override + protected Void defaultVisit(Content cntnt) { + throw new UnsupportedOperationException("Can't extract a " + + cntnt.getClass().getSimpleName()); + } + + /** + * Helper visitor to get the destination file for a child Content object + */ + private class DestFileContentVisitor extends + ContentVisitor.Default { + + /** + * Get destination file by adding File/Directory name to the path + * of parent + */ + private java.io.File getFsContentDest(FsContent fsc) { + String path = dest.getAbsolutePath() + java.io.File.separator + + fsc.getName(); + return new java.io.File(path); + } + + @Override + public java.io.File visit(File f) { + return getFsContentDest(f); + } + + @Override + public java.io.File visit(Directory dir) { + return getFsContentDest(dir); + } + + @Override + protected java.io.File defaultVisit(Content cntnt) { + throw new UnsupportedOperationException("Can't get destination file for a " + + cntnt.getClass().getSimpleName()); + } + } + } } diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java index 6d56da242a..588df9b53a 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java @@ -70,40 +70,10 @@ public class DataResultFilterNode extends FilterNode{ List actions = new ArrayList(); - actions.add(new NewWindowViewAction("View in New Window", getOriginal())); - // TODO: ContentNode fix - restore right-click actions - // TODO: ContentVisitor instead of instanceof - Content nodeContent = this.getOriginal().getLookup().lookup(Content.class); actions.addAll(nodeContent.accept(getActionsCV)); - - -// // right click action(s) for image node -// if (originalNode instanceof ImageNode) { -// actions.add(new NewWindowViewAction("View in New Window", (ImageNode) originalNode)); -// actions.addAll(ShowDetailActionVisitor.getActions(nodeContent)); -// } // right click action(s) for volume node -// else if (originalNode instanceof VolumeNode) { -// actions.add(new NewWindowViewAction("View in New Window", (VolumeNode) originalNode)); -// //new ShowDetailActionVisitor("Volume Details", this.currentNode.getName(), (VolumeNode) this.currentNode), -// actions.addAll(ShowDetailActionVisitor.getActions(nodeContent)); -// actions.add(new ChangeViewAction("View", 0, this.getOriginal())); -// } // right click action(s) for directory node -// else if (originalNode instanceof DirectoryNode) { -// actions.add(new NewWindowViewAction("View in New Window", (DirectoryNode) originalNode)); -// actions.add(new ChangeViewAction("View", 0, originalNode)); -// // TODO: ContentNode fix - reimplement ExtractAction -// //actions.add(new ExtractAction("Extract Directory", (DirectoryNode) this.currentNode)); -// } // right click action(s) for the file node -// else if (originalNode instanceof FileNode) { -// actions.add(new ExternalViewerAction("Open File in External Viewer", (FileNode) originalNode)); -// actions.add(new NewWindowViewAction("View in New Window", (FileNode) originalNode)); -// // TODO: ContentNode fix - reimplement ExtractAction -// //actions.add(new ExtractAction("Extract", (FileNode) this.currentNode)); -// actions.add(new ChangeViewAction("View", 0, originalNode)); -// } return actions.toArray(new Action[actions.size()]); } @@ -127,8 +97,7 @@ public class DataResultFilterNode extends FilterNode{ public List visit(Directory dir) { List actions = new ArrayList(); actions.add(new ChangeViewAction("View", 0, getOriginal())); - // TODO: ContentNode fix - reimplement ExtractAction - //actions.add(new ExtractAction("Extract Directory", (DirectoryNode) this.currentNode)); + actions.add(new ExtractAction("Extract Directory", getOriginal())); return actions; } @@ -136,8 +105,7 @@ public class DataResultFilterNode extends FilterNode{ public List visit(File f) { List actions = new ArrayList(); actions.add(new ExternalViewerAction("Open File in External Viewer", getOriginal())); - // TODO: ContentNode fix - reimplement ExtractAction - //actions.add(new ExtractAction("Extract", (FileNode) this.currentNode)); + actions.add(new ExtractAction("Extract", getOriginal())); return actions; } diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExtractAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExtractAction.java index 546fe65d65..3ea8aa522f 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExtractAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExtractAction.java @@ -1,225 +1,111 @@ -// TODO: ContentNode fix - reimplement ExtractAction +/* + * Autopsy Forensic Browser + * + * Copyright 2011 Basis Technology Corp. + * Contact: carrier sleuthkit 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.directorytree; +import java.awt.event.ActionEvent; +import javax.swing.JFileChooser; +import java.io.File; +import java.awt.Component; +import javax.swing.AbstractAction; +import javax.swing.JOptionPane; +import org.openide.nodes.Node; +import org.sleuthkit.autopsy.datamodel.ContentUtils; +import org.sleuthkit.autopsy.datamodel.ContentUtils.ExtractFscContentVisitor; +import org.sleuthkit.autopsy.logging.Log; +import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.ContentVisitor; +import org.sleuthkit.datamodel.Directory; +import org.sleuthkit.datamodel.FsContent; -///* -// * Autopsy Forensic Browser -// * -// * Copyright 2011 Basis Technology Corp. -// * Contact: carrier sleuthkit 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. -// * See the License for the specific language governing permissions and -// * limitations under the License. -// */ -//package org.sleuthkit.autopsy.directorytree; -// -//import org.sleuthkit.autopsy.datamodel.FileNode; -//import java.io.*; -//import java.awt.event.ActionEvent; -//import javax.swing.JFileChooser; -//import java.io.File; -//import java.awt.Component; -//import java.util.logging.Level; -//import java.util.logging.Logger; -//import javax.swing.AbstractAction; -//import javax.swing.JPanel; -//import javax.swing.filechooser.FileFilter; -//import org.openide.nodes.Node; -//import org.sleuthkit.autopsy.casemodule.GeneralFilter; -//import org.sleuthkit.autopsy.datamodel.DirectoryNode; -//import org.sleuthkit.autopsy.logging.Log; -//import org.sleuthkit.datamodel.Content; -//import org.sleuthkit.datamodel.TskException; -// -///** -// * This is an action class to extract and save the bytes given as a file. -// * -// * @author jantonius -// */ -//public final class ExtractAction extends AbstractAction { -// -// private JFileChooser fc = new JFileChooser(); -// private byte[] source; -// private Content content; -// private String fileName; -// private String extension; -// // for error handling -// private JPanel caller; -// private String className = this.getClass().toString(); -// -// /** the constructor */ -// public ExtractAction(String title, Node contentNode) { -// super(title); -// -// String fullFileName = contentNode.getDisplayName(); -// -// -// if (fullFileName.equals(".")) { -// // . folders are not associated with their children in the database, -// // so get original -// Node parentNode = contentNode.getParentNode(); -// contentNode = parentNode; -// fullFileName = parentNode.getDisplayName(); -// } -// -// -// this.content = contentNode.getLookup().lookup(Content.class); -// -// long size = content.getSize(); -// -// -// -// /** -// * Checks first if the the selected it file or directory. If it's a file, -// * check if the file size is bigger than 0. If it's a directory, check -// * if it's not referring to the parent directory. Disables the menu otherwise. -// */ -// if ((contentNode instanceof FileNode && size > 0) || (contentNode instanceof DirectoryNode && !fullFileName.equals(".."))) { -// if (contentNode instanceof FileNode && fullFileName.contains(".")) { -// String tempFileName = fullFileName.substring(0, fullFileName.indexOf(".")); -// String tempExtension = fullFileName.substring(fullFileName.indexOf(".")); -// this.fileName = tempFileName; -// this.extension = tempExtension; -// } else { -// this.fileName = fullFileName; -// this.extension = ""; -// } -// } else { -// this.fileName = fullFileName; -// this.extension = ""; -// this.setEnabled(false); // can't extract zero-sized file or ".." directory -// } -// -// } -// -// /** -// * Converts and saves the bytes into the file. -// * -// * @param e the action event -// */ -// @Override -// public void actionPerformed(ActionEvent e) { -// Log.noteAction(this.getClass()); -// -// // set the filter for File -// if (content instanceof org.sleuthkit.datamodel.File && !extension.equals("")) { -// //FileFilter filter = new ExtensionFileFilter(extension.substring(1).toUpperCase() + " File (*" + extension + ")", new String[]{extension.substring(1)}); -// String[] fileExt = {extension}; -// FileFilter filter = new GeneralFilter(fileExt, extension.substring(1).toUpperCase() + " File (*" + extension + ")", false); -// fc.setFileFilter(filter); -// } -// -// fc.setSelectedFile(new File(this.fileName)); -// -// int returnValue = fc.showSaveDialog((Component) e.getSource()); -// if (returnValue == JFileChooser.APPROVE_OPTION) { -// String path = fc.getSelectedFile().getPath() + extension; -// -// -// // TODO: convert this to a Content Visitor -// try { -// // file extraction -// if (content instanceof org.sleuthkit.datamodel.File) { -// extractFile(path, (org.sleuthkit.datamodel.File) content); -// } -// -// // directory extraction -// if (content instanceof org.sleuthkit.datamodel.File) { -// extractDirectory(path, (org.sleuthkit.datamodel.Directory) content); -// } -// } catch (Exception ex) { -// Logger.getLogger(this.className).log(Level.WARNING, "Error: Couldn't extract file/directory.", ex); -// } -// -// } -// -// } -// -// /** -// * Extracts the content of the given fileNode into the given path. -// * -// * @param givenPath the path to extract the file -// * @param file the file node that contain the file -// */ -// private void extractFile(String givenPath, org.sleuthkit.datamodel.File file) throws Exception { -// try { -// if (file.getSize() > 0) { -// try { -// this.source = file.read(0, file.getSize()); -// } catch (TskException ex) { -// throw new Exception("Error: can't read the content of the file.", ex); -// } -// } else { -// this.source = new byte[0]; -// } -// -// String path = givenPath; -// -// File outputFile = new File(path); -// if (outputFile.exists()) { -// outputFile.delete(); -// } -// outputFile.createNewFile(); -// // convert char to byte -// byte[] dataSource = new byte[source.length]; -// for (int i = 0; i < source.length; i++) { -// dataSource[i] = (byte) source[i]; -// } -// FileOutputStream fos = new FileOutputStream(outputFile); -// //fos.write(dataSource); -// fos.write(dataSource); -// fos.close(); -// } catch (IOException ex) { -// throw new Exception("Error while trying to extract the file.", ex); -// } -// } -// -// /** -// * Extracts the content of the given directoryNode into the given path. -// * -// * @param givenPath the path to extract the directory -// * @param dirNode the directory node that contain the directory -// */ -// private void extractDirectory(String givenPath, DirectoryNode dirNode) throws Exception { -// String path = givenPath; -// File dir = new File(path); -// if (!dir.exists()) { -// dir.mkdir(); -// } -// -// int totalChildren = dirNode.getChildren().getNodesCount(); -// for (int i = 0; i < totalChildren; i++) { -// Node childNode = dirNode.getChildren().getNodeAt(i); -// -// if (childNode instanceof FileNode) { -// FileNode fileNode = (FileNode) childNode; -// String tempPath = path + File.separator + ((Node)fileNode).getDisplayName(); -// try { -// extractFile(tempPath, fileNode); -// } catch (Exception ex) { -// throw ex; -// } -// } -// -// if (childNode instanceof DirectoryNode) { -// DirectoryNode dirNode2 = (DirectoryNode) childNode; -// String dirNode2Name = ((Node)dirNode2).getDisplayName(); -// -// if (!dirNode2Name.trim().equals(".") && !dirNode2Name.trim().equals("..")) { -// String tempPath = path + File.separator + dirNode2Name; -// extractDirectory(tempPath, dirNode2); -// } -// } -// } -// -// -// } -//} +/** + * Exports files and folders + */ +public final class ExtractAction extends AbstractAction { + + private static final InitializeContentVisitor initializeCV = new InitializeContentVisitor(); + private FsContent fsContent; + + public ExtractAction(String title, Node contentNode) { + super(title); + Content tempContent = contentNode.getLookup().lookup(Content.class); + + this.fsContent = tempContent.accept(initializeCV); + this.setEnabled(fsContent != null); + } + + /** + * Returns the FsContent if it is supported, otherwise null + */ + private static class InitializeContentVisitor extends ContentVisitor.Default { + + @Override + public FsContent visit(org.sleuthkit.datamodel.File f) { + return f; + } + + @Override + public FsContent visit(Directory dir) { + return ContentUtils.isDotDirectory(dir) ? null : dir; + } + + @Override + protected FsContent defaultVisit(Content cntnt) { + return null; + } + } + + /** + * Asks user to choose destination, then extracts file/directory to + * destination (recursing on directories) + * @param e the action event + */ + @Override + public void actionPerformed(ActionEvent e) { + Log.noteAction(this.getClass()); + + JFileChooser fc = new JFileChooser(); + fc.setSelectedFile(new File(this.fsContent.getName())); + int returnValue = fc.showSaveDialog((Component) e.getSource()); + + if (returnValue == JFileChooser.APPROVE_OPTION) { + File destination = fc.getSelectedFile(); + + // check that it's okay to overwrite existing file + if (destination.exists()) { + int choice = JOptionPane.showConfirmDialog( + (Component) e.getSource(), + "Destination file already exists, it will be overwritten.", + "Destination already exists!", + JOptionPane.OK_CANCEL_OPTION); + + if (choice != JOptionPane.OK_OPTION) { + return; + } + + if (!destination.delete()) { + JOptionPane.showMessageDialog( + (Component) e.getSource(), + "Couldn't delete existing file."); + } + } + + ExtractFscContentVisitor.extract(fsContent, destination); + } + } +} From 53142025da8ca1418f7cb49ed56187fa6c7bec03 Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Thu, 15 Dec 2011 18:58:12 -0500 Subject: [PATCH 15/21] Miscellaneous trival cleanup --- .../autopsy/casemodule/AddImageWizardIterator.java | 1 - Case/src/org/sleuthkit/autopsy/casemodule/Case.java | 5 ++--- .../sleuthkit/autopsy/casemodule/CaseOpenAction.java | 3 ++- .../autopsy/casemodule/NewCaseWizardAction.java | 1 - .../autopsy/casemodule/OpenRecentCasePanel.java | 1 - .../corecomponentinterfaces/DataContentViewer.java | 3 +-- .../autopsy/corecomponents/DataContentViewerHex.java | 2 +- .../corecomponents/DataContentViewerPicture.java | 4 +--- .../corecomponents/DataContentViewerString.java | 2 +- .../corecomponents/DataResultViewerTable.java | 7 +++---- .../corecomponents/ProductInformationPanel.java | 2 +- .../corecomponents/ThumbnailViewChildren.java | 2 +- .../autopsy/directorytree/ExternalViewerAction.java | 4 +++- .../autopsy/directorytree/NewWindowViewAction.java | 2 +- .../directorytree/ShowDetailActionVisitor.java | 12 ++++-------- .../autopsy/filesearch/DateSearchPanel.java | 1 - .../org/sleuthkit/autopsy/filesearch/FilterArea.java | 6 ++++-- 17 files changed, 25 insertions(+), 33 deletions(-) diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIterator.java b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIterator.java index c571a43787..e3b2a929b1 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIterator.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIterator.java @@ -60,7 +60,6 @@ class AddImageWizardIterator implements WizardDescriptor.Iterator= 7.8, can use WizardDescriptor.PROP_*: jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // Sets steps names for a panel jc.putClientProperty("WizardPanel_contentData", steps); diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/Case.java b/Case/src/org/sleuthkit/autopsy/casemodule/Case.java index 6f169581bd..ebc3ae8a29 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -54,7 +54,7 @@ import org.sleuthkit.datamodel.SleuthkitJNI.CaseDbHandle.AddImageProcess; */ public class Case { // change the CTL_MainWindow_Title in Bundle.properties as well if you change this value - private static final String autopsyVer = "3.0.0b2"; // current version of autopsy. Changed it when the version is changed + private static final String autopsyVer = "3.0.0b2"; // current version of autopsy. Change it when the version is changed private static final String appName = "Autopsy " + autopsyVer; /** @@ -150,8 +150,7 @@ public class Case { currentCase = newCase; pcs.firePropertyChange(CASE_CURRENT_CASE, null, currentCase); - //TODO: This will fire off a bunch of stuff in CaseListener.propertyChange() - // that should probably be migrated into here + // TODO: This will fire off a bunch of stuff in CaseListener.propertyChange() that should probably be migrated into here pcs.firePropertyChange(CASE_NAME, "", currentCase.name); RecentCases.getInstance().addRecentCase(currentCase.name, currentCase.configFilePath); // update the recent cases diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java b/Case/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java index 48ebfeb639..295a01cfc2 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java @@ -37,6 +37,7 @@ import org.sleuthkit.autopsy.logging.Log; */ @ServiceProvider(service = CaseOpenAction.class) public final class CaseOpenAction implements ActionListener { + private static final Logger logger = Logger.getLogger(CaseOpenAction.class.getName()); JFileChooser fc = new JFileChooser(); GeneralFilter autFilter = new GeneralFilter(new String[]{".aut"}, "AUTOPSY File (*.aut)", false); @@ -73,7 +74,7 @@ public final class CaseOpenAction implements ActionListener { StartupWindow.getInstance().close(); } catch (Exception ex) { // no need to show the error message to the user. - // TODO: But maybe put the error message in the log in the future. + logger.log(Level.INFO, "Error closing startup window.", ex); } try { Case.open(path); // open the case diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java b/Case/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java index 8e07f6fbd2..9475e1e547 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java @@ -119,7 +119,6 @@ public final class NewCaseWizardAction extends CallableSystemAction { if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent) c; // Sets step number of a component - // TODO if using org.openide.dialogs >= 7.8, can use WizardDescriptor.PROP_*: jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // Sets steps names for a panel jc.putClientProperty("WizardPanel_contentData", steps); diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/OpenRecentCasePanel.java b/Case/src/org/sleuthkit/autopsy/casemodule/OpenRecentCasePanel.java index 4f0fc0903f..eaefdf7b1f 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/OpenRecentCasePanel.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/OpenRecentCasePanel.java @@ -191,7 +191,6 @@ class OpenRecentCasePanel extends javax.swing.JPanel { }// //GEN-END:initComponents private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed - // TODO add your handling code here: }//GEN-LAST:event_cancelButtonActionPerformed diff --git a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContentViewer.java b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContentViewer.java index 5601d9fd13..4ee9f424cd 100644 --- a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContentViewer.java +++ b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContentViewer.java @@ -43,8 +43,7 @@ public interface DataContentViewer { * instance returned by the Lookup as a factory for the instances that * are actually used.) */ - // TODO: extract the factory method out into a seperate interface that - // is used for the Lookup. + // TODO: extract the factory method out into a seperate interface that is used for the Lookup. public DataContentViewer getInstance(); /** diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java index 5f65c777b8..40c5549a2c 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java @@ -274,7 +274,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont @Override public void setNode(Node selectedNode) { if (selectedNode != null) { - Content content = ((Node) selectedNode).getLookup().lookup(Content.class); + Content content = (selectedNode).getLookup().lookup(Content.class); if (content != null) { this.setDataView(content, 0, false); return; diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java index 61a11c020b..3a7aeaddc4 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java @@ -131,9 +131,7 @@ public class DataContentViewerPicture extends javax.swing.JPanel implements Data } @Override - public boolean isSupported(Node cNode) { - Node node = (Node) cNode; - + public boolean isSupported(Node node) { if (node != null) { // Note: only supports JPG, GIF, and PNG for now return node.getDisplayName().toLowerCase().endsWith(".jpg") diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java index e30633e055..29f4a6e69f 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java @@ -268,7 +268,7 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC @Override public void setNode(Node selectedNode) { if (selectedNode != null) { - Content content = ((Node) selectedNode).getLookup().lookup(Content.class); + Content content = selectedNode.getLookup().lookup(Content.class); if (content != null) { this.setDataView(content, 0, false); return; diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java index 7eef046120..bedf96df7c 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java @@ -38,7 +38,6 @@ import org.openide.nodes.Node.PropertySet; import org.openide.nodes.Sheet; import org.openide.util.lookup.ServiceProvider; import org.sleuthkit.autopsy.corecomponentinterfaces.DataResultViewer; -// TODO We should not have anything specific to Image in here... /** * DataResult sortable table viewer @@ -145,13 +144,13 @@ public class DataResultViewerTable extends AbstractDataResultViewer { if (selectedNode != null) { - hasChildren = ((Node) selectedNode).getChildren().getNodesCount() > 0; + hasChildren = selectedNode.getChildren().getNodesCount() > 0; } // if there's no selection node, do nothing if (hasChildren) { - Node root = (Node) selectedNode; + Node root = selectedNode; if (!(root instanceof TableFilterNode)) { root = new TableFilterNode(root, true); @@ -161,7 +160,7 @@ public class DataResultViewerTable extends AbstractDataResultViewer { OutlineView ov = ((OutlineView) this.tableScrollPanel); - List tempProps = new ArrayList(Arrays.asList(getChildPropertyHeaders((Node) selectedNode))); + List tempProps = new ArrayList(Arrays.asList(getChildPropertyHeaders(selectedNode))); tempProps.remove(0); diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ProductInformationPanel.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ProductInformationPanel.java index d29e1ea8f3..49a71ce744 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ProductInformationPanel.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ProductInformationPanel.java @@ -170,7 +170,7 @@ private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:eve } catch (MalformedURLException ex) { //ignore } - url = null; // TODO add your handling code here: + url = null; }//GEN-LAST:event_jLabel1MouseClicked private void activateVerboseLogging(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_activateVerboseLogging diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java index d094396b45..d06c7510d1 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java @@ -35,7 +35,7 @@ class ThumbnailViewChildren extends FilterNode.Children { /** the constructor */ ThumbnailViewChildren(Node arg) { - super((Node) arg); + super(arg); this.totalChildren = 1; } diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java index 8051055ee2..5c7ff513f6 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java @@ -34,12 +34,14 @@ import org.sleuthkit.autopsy.logging.Log; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.TskException; +// TODO: clean up external viewer action + + /** * * @author jantonius */ public class ExternalViewerAction extends AbstractAction { - private byte[] content; private Content contentObject; private String fileName; diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java index fb436a16cd..60f0ff1718 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java @@ -47,7 +47,7 @@ class NewWindowViewAction extends AbstractAction{ public void actionPerformed(ActionEvent e) { Log.noteAction(this.getClass()); - String[] filePaths = ContentUtils.getDisplayPath(((Node) contentNode).getLookup().lookup(Content.class)); + String[] filePaths = ContentUtils.getDisplayPath((contentNode).getLookup().lookup(Content.class)); String filePath = DataConversion.getformattedPath(filePaths, 0); DataContentTopComponent dctc = DataContentTopComponent.createUndocked(filePath, this.contentNode); diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ShowDetailActionVisitor.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ShowDetailActionVisitor.java index 84e678cb1e..d4fa64a89c 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ShowDetailActionVisitor.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ShowDetailActionVisitor.java @@ -84,8 +84,7 @@ class ShowDetailActionVisitor extends ContentVisitor.Default Date: Fri, 16 Dec 2011 11:17:59 -0500 Subject: [PATCH 16/21] Clean up FileSearch DataResultFilterNode --- .../filesearch/DataResultFilterNode.java | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java index 7f687bcb2a..e0b5a813f4 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java @@ -18,16 +18,16 @@ */ package org.sleuthkit.autopsy.filesearch; -import org.sleuthkit.autopsy.datamodel.ImageNode; -import org.sleuthkit.autopsy.datamodel.VolumeNode; -import org.sleuthkit.autopsy.datamodel.FileNode; -import org.sleuthkit.autopsy.datamodel.DirectoryNode; import javax.swing.Action; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; import org.sleuthkit.autopsy.datamodel.ContentUtils; import org.sleuthkit.autopsy.directorytree.ChangeViewAction; +import org.sleuthkit.autopsy.directorytree.ExtractAction; import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.ContentVisitor; +import org.sleuthkit.datamodel.Directory; +import org.sleuthkit.datamodel.File; /** * This class wraps nodes as they are passed to the DataResult viewers. It @@ -35,12 +35,10 @@ import org.sleuthkit.datamodel.Content; */ public class DataResultFilterNode extends FilterNode { - private Node currentNode; /** the constructor */ public DataResultFilterNode(Node arg) { super(arg, new DataResultFilterChildren(arg)); - this.currentNode = arg; } /** @@ -52,30 +50,35 @@ public class DataResultFilterNode extends FilterNode { */ @Override public Action[] getActions(boolean popup) { - // right click action(s) for image node - if (this.currentNode instanceof ImageNode) { - return new Action[]{}; - } // right click action(s) for volume node - else if (this.currentNode instanceof VolumeNode) { - return new Action[]{}; - } // right click action(s) for directory node - else if (this.currentNode instanceof DirectoryNode) { + + Content content = getOriginal().getLookup().lookup(Content.class); + return content.accept(new GetActionContentVisitor()); + } + + private class GetActionContentVisitor extends ContentVisitor.Default { + @Override + public Action[] visit(Directory dir) { return new Action[]{ - new ChangeViewAction("View", 0, currentNode), - new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath(currentNode.getLookup().lookup(Content.class))) - }; - } // right click action(s) for the file node - else if (this.currentNode instanceof FileNode) { + new ChangeViewAction("View", 0, getOriginal()), + new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath(dir)) + }; + } + + @Override + public Action[] visit(File f) { return new Action[]{ - // TODO: ContentNode fix - reimplement ExtractAction - // new ExtractAction("Extract", (FileNode) this.currentNode), - new ChangeViewAction("View", 0, currentNode), - new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath(currentNode.getLookup().lookup(Content.class))) - }; - } else { + new ExtractAction("Extract", getOriginal()), + new ChangeViewAction("View", 0, getOriginal()), + new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath(f)) + }; + } + + @Override + protected Action[] defaultVisit(Content cntnt) { return new Action[]{}; } } + /** * Double click action for the nodes that we want to pass to the directory From b4ab34e03ad43bfce846c960413994c2416cfe4e Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Fri, 16 Dec 2011 12:17:50 -0500 Subject: [PATCH 17/21] Cleanup ExternalViewerAction --- .../directorytree/DataResultFilterNode.java | 2 +- .../directorytree/ExternalViewerAction.java | 111 ++++++------------ .../filesearch/DataResultFilterNode.java | 2 + 3 files changed, 39 insertions(+), 76 deletions(-) diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java index 588df9b53a..34b0dbbeba 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java @@ -104,7 +104,7 @@ public class DataResultFilterNode extends FilterNode{ @Override public List visit(File f) { List actions = new ArrayList(); - actions.add(new ExternalViewerAction("Open File in External Viewer", getOriginal())); + actions.add(new ExternalViewerAction("Open in External Viewer", getOriginal())); actions.add(new ExtractAction("Extract", getOriginal())); return actions; } diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java index 5c7ff513f6..e3a8e1bc31 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java @@ -21,51 +21,31 @@ package org.sleuthkit.autopsy.directorytree; import java.awt.Desktop; import java.awt.event.ActionEvent; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractAction; -import javax.swing.JOptionPane; -import javax.swing.JPanel; import org.openide.nodes.Node; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.datamodel.ContentUtils; import org.sleuthkit.autopsy.logging.Log; -import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.TskException; - -// TODO: clean up external viewer action - /** - * - * @author jantonius + * Extracts a File object to a temporary file in the case directory, and then + * tries to open it in the user's system with the default associated + * application. */ public class ExternalViewerAction extends AbstractAction { - private byte[] content; - private Content contentObject; - private String fileName; - private String extension; - // for error handling - private JPanel caller; - private String className = this.getClass().toString(); - /** the constructor */ + private final static Logger logger = Logger.getLogger(ExternalViewerAction.class.getName()); + private org.sleuthkit.datamodel.File fileObject; + public ExternalViewerAction(String title, Node fileNode) { super(title); - this.contentObject = fileNode.getLookup().lookup(Content.class); - - long size = contentObject.getSize(); - String fullFileName = fileNode.getDisplayName(); - if (fullFileName.contains(".") && size > 0) { - String tempFileName = fullFileName.substring(0, fullFileName.indexOf(".")); - String tempExtension = fullFileName.substring(fullFileName.indexOf(".")); - this.fileName = tempFileName; - this.extension = tempExtension; - } else { - this.fileName = fullFileName; - this.extension = ""; - this.setEnabled(false); //TODO: fix this later (right now only extract a file with extension) + this.fileObject = fileNode.getLookup().lookup(org.sleuthkit.datamodel.File.class); + long size = fileObject.getSize(); + if (!(size > 0)) { + this.setEnabled(false); } } @@ -73,54 +53,35 @@ public class ExternalViewerAction extends AbstractAction { public void actionPerformed(ActionEvent e) { Log.noteAction(this.getClass()); + + // the menu should be disabled if we can't read the content (for example: on zero-sized file). + // Therefore, it should never throw the TSKException. + + // Get the temp folder path of the case + String tempPath = Case.getCurrentCase().getTempDirectory(); + tempPath = tempPath + File.separator + this.fileObject.getName(); + + // create the temporary file + File tempFile = new File(tempPath); + if (tempFile.exists()) { + tempFile.delete(); + } try { - // @@@ Thing to do: maybe throw confirmation first??? - - // the menu should be disabled if we can't read the content (for example: on zero-sized file). - // Therefore, it should never throw the TSKException. - try { - this.content = contentObject.read(0, contentObject.getSize()); - } catch (TskException ex) { - Logger.getLogger(this.className).log(Level.WARNING, "Error: can't read the content of the file.", ex); - } - - // Get the temp folder path of the case - String tempPath = Case.getCurrentCase().getTempDirectory(); - tempPath = tempPath + File.separator + this.fileName + this.extension; - - // create the temporary file - File file = new File(tempPath); - if (file.exists()) { - file.delete(); - } - - file.createNewFile(); - - // convert char to byte - byte[] dataSource = new byte[content.length]; - for (int i = 0; i < content.length; i++) { - dataSource[i] = (byte) content[i]; - } - - FileOutputStream fos = new FileOutputStream(file); - //fos.write(dataSource); - fos.write(dataSource); - fos.close(); - - try { - Desktop.getDesktop().open(file); - } catch (IOException ex) { - // if can't open the file, throw the error saying: "File type not supported." - JOptionPane.showMessageDialog(caller, "Error: File type not supported.\n \nDetail: \n" + ex.getMessage() + " (at " + className + ").", "Error", JOptionPane.ERROR_MESSAGE); - } - - // delete the file on exit - file.deleteOnExit(); - + tempFile.createNewFile(); + ContentUtils.writeToFile(fileObject, tempFile); } catch (IOException ex) { // throw an error here - Logger.getLogger(this.className).log(Level.WARNING, "Error: can't open the external viewer for this file.", ex); + logger.log(Level.WARNING, "Can't save to temporary file.", ex); } + try { + Desktop.getDesktop().open(tempFile); + } catch (IOException ex) { + // if can't open the file, throw the error saying: "File type not supported." + logger.log(Level.WARNING, "File type not supported.", ex); + } + + // delete the file on exit + tempFile.deleteOnExit(); } } diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java index e0b5a813f4..a2fc84d708 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DataResultFilterNode.java @@ -23,6 +23,7 @@ import org.openide.nodes.FilterNode; import org.openide.nodes.Node; import org.sleuthkit.autopsy.datamodel.ContentUtils; import org.sleuthkit.autopsy.directorytree.ChangeViewAction; +import org.sleuthkit.autopsy.directorytree.ExternalViewerAction; import org.sleuthkit.autopsy.directorytree.ExtractAction; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentVisitor; @@ -67,6 +68,7 @@ public class DataResultFilterNode extends FilterNode { @Override public Action[] visit(File f) { return new Action[]{ + new ExternalViewerAction("Open in External Viewer", getOriginal()), new ExtractAction("Extract", getOriginal()), new ChangeViewAction("View", 0, getOriginal()), new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath(f)) From 3b61d897879a2a216cad79cf20638f31e8776073 Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Fri, 16 Dec 2011 12:42:10 -0500 Subject: [PATCH 18/21] Tweak ExternalViewerAction to require file extensions --- .../autopsy/directorytree/ExternalViewerAction.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java index e3a8e1bc31..f772b4528b 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java @@ -43,8 +43,14 @@ public class ExternalViewerAction extends AbstractAction { public ExternalViewerAction(String title, Node fileNode) { super(title); this.fileObject = fileNode.getLookup().lookup(org.sleuthkit.datamodel.File.class); + long size = fileObject.getSize(); - if (!(size > 0)) { + String fileName = fileObject.getName(); + int extPos = fileName.lastIndexOf('.'); + + // no point opening a file if it's empty, and java doesn't know how to + // find an application for files without an extension + if (!(size > 0) || extPos == -1) { this.setEnabled(false); } } @@ -53,10 +59,6 @@ public class ExternalViewerAction extends AbstractAction { public void actionPerformed(ActionEvent e) { Log.noteAction(this.getClass()); - - // the menu should be disabled if we can't read the content (for example: on zero-sized file). - // Therefore, it should never throw the TSKException. - // Get the temp folder path of the case String tempPath = Case.getCurrentCase().getTempDirectory(); tempPath = tempPath + File.separator + this.fileObject.getName(); From e8588b0be79df8042e00069162465fe750594c01 Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Fri, 16 Dec 2011 13:22:36 -0500 Subject: [PATCH 19/21] Add "Name" property to KeyValueNode --- .../src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java index 6bbfb4bdcb..ec440b9fb7 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java @@ -25,6 +25,10 @@ public class KeyValueNode extends AbstractNode { s.put(ss); } + // table view drops first column of properties under assumption + // that it contains the node's property + ss.put(new NodeProperty("Name", "Name", "n/a", thing.getName())); + for (Map.Entry entry : thing.getMap().entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); From be10a4bb4152611a37ea01833b32e16fc4d1b55c Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Fri, 16 Dec 2011 16:11:33 -0500 Subject: [PATCH 20/21] Add setPath to DataResult --- .../corecomponentinterfaces/DataResult.java | 7 +++++++ .../corecomponents/DataResultTopComponent.java | 17 +++++++++-------- .../DirectoryTreeTopComponent.java | 6 ++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResult.java b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResult.java index 699d409e36..4d5bf473e3 100644 --- a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResult.java +++ b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResult.java @@ -45,6 +45,13 @@ public interface DataResult { * @param title the given title (String) */ public void setTitle(String title); + + + /** + * Sets the descriptive context text at the top of the pane. + * @param pathText Descriptive text giving context for the current results + */ + public void setPath(String pathText); /** * Checks if this is the main (uncloseable) instance of DataResult diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java index e30c36ff5e..b57fa60a43 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java @@ -42,9 +42,9 @@ public final class DataResultTopComponent extends TopComponent implements DataRe private Node rootNode; private PropertyChangeSupport pcs = new PropertyChangeSupport(this); private boolean isMain; - /** path to the icon used by the component and its open action */ -// static final String ICON_PATH = "SET/PATH/TO/ICON/HERE"; + private static String PREFERRED_ID = "NodeTableTopComponent"; + /** * Name of property change fired when a file search result is closed */ @@ -111,7 +111,7 @@ public final class DataResultTopComponent extends TopComponent implements DataRe // set the tree table view newDataResult.setNode(givenNode); - newDataResult.directoryTablePath.setText(pathText); + newDataResult.setPath(pathText); return newDataResult; } @@ -284,17 +284,13 @@ public final class DataResultTopComponent extends TopComponent implements DataRe public void setNode(Node selectedNode) { this.rootNode = selectedNode; if (selectedNode != null) { - //path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(selectedNode.getLookup().lookup(Content.class)), 0); - int childrenCount = selectedNode.getChildren().getNodesCount(true); this.numberMatchLabel.setText(Integer.toString(childrenCount)); } this.numberMatchLabel.setVisible(true); this.matchLabel.setVisible(true); - - this.directoryTablePath.setText("TEST"); // set the node path - + resetTabs(selectedNode); // set the display on the current active tab @@ -309,6 +305,11 @@ public final class DataResultTopComponent extends TopComponent implements DataRe public void setTitle(String title) { setName(title); } + + @Override + public void setPath(String pathText) { + this.directoryTablePath.setText(pathText); + } @Override public boolean isMain() { diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java index e0a407e588..3e87fd6531 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java @@ -45,7 +45,10 @@ import org.openide.nodes.Children; import org.openide.nodes.Node; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent; +import org.sleuthkit.autopsy.datamodel.ContentUtils; +import org.sleuthkit.autopsy.datamodel.DataConversion; import org.sleuthkit.autopsy.datamodel.RootContentChildren; +import org.sleuthkit.datamodel.Content; /** * Top component which displays something. @@ -553,6 +556,9 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat } DirectoryTreeTopComponent.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); DirectoryTreeTopComponent.this.dataResult.setNode(new DataResultFilterNode(originNode, DirectoryTreeTopComponent.this.em)); + + String path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(originNode.getLookup().lookup(Content.class)), 0); + DirectoryTreeTopComponent.this.dataResult.setPath(path); } // set the directory listing to be active From 25673930f34f51455a9e12e40524ae2cd7ad2ed7 Mon Sep 17 00:00:00 2001 From: "Peter J. Martel" Date: Fri, 16 Dec 2011 16:12:19 -0500 Subject: [PATCH 21/21] Misc. trivia --- DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java | 2 +- .../sleuthkit/autopsy/filesearch/FileSearchTopComponent.java | 2 +- .../src/org/sleuthkit/autopsy/menuactions/SearchResultMenu.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java index ec440b9fb7..028cdedb48 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java @@ -26,7 +26,7 @@ public class KeyValueNode extends AbstractNode { } // table view drops first column of properties under assumption - // that it contains the node's property + // that it contains the node's name ss.put(new NodeProperty("Name", "Name", "n/a", thing.getName())); for (Map.Entry entry : thing.getMap().entrySet()) { diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/FileSearchTopComponent.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/FileSearchTopComponent.java index e77b364823..7e15a79aa9 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/FileSearchTopComponent.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/FileSearchTopComponent.java @@ -338,4 +338,4 @@ public final class FileSearchTopComponent extends TopComponent implements DataEx public TopComponent getTopComponent() { return this; } -} +} \ No newline at end of file diff --git a/MenuActions/src/org/sleuthkit/autopsy/menuactions/SearchResultMenu.java b/MenuActions/src/org/sleuthkit/autopsy/menuactions/SearchResultMenu.java index 60eafc3b58..8b3b434b04 100644 --- a/MenuActions/src/org/sleuthkit/autopsy/menuactions/SearchResultMenu.java +++ b/MenuActions/src/org/sleuthkit/autopsy/menuactions/SearchResultMenu.java @@ -30,7 +30,7 @@ import org.sleuthkit.autopsy.directorytree.DirectoryTreeTopComponent; import org.sleuthkit.autopsy.filesearch.FileSearchTopComponent; /** - * Menu item lists DataResult tabs.w + * Menu item lists DataResult tabs. */ public class SearchResultMenu extends JMenuItem implements DynamicMenuContent {