From f436e0bfd443b2f0abc35e827c995e907db671d3 Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Mon, 9 Sep 2013 17:00:16 -0400 Subject: [PATCH] Added basic metadata content viewer and made HTML stye sheets common --- .../autopsy/contentviewers/Metadata.form | 52 +++++ .../autopsy/contentviewers/Metadata.java | 189 ++++++++++++++++++ .../autopsy/contentviewers/Utilities.java | 49 +++++ .../DataContentViewerArtifact.java | 22 +- 4 files changed, 293 insertions(+), 19 deletions(-) create mode 100755 Core/src/org/sleuthkit/autopsy/contentviewers/Metadata.form create mode 100755 Core/src/org/sleuthkit/autopsy/contentviewers/Metadata.java create mode 100755 Core/src/org/sleuthkit/autopsy/contentviewers/Utilities.java diff --git a/Core/src/org/sleuthkit/autopsy/contentviewers/Metadata.form b/Core/src/org/sleuthkit/autopsy/contentviewers/Metadata.form new file mode 100755 index 0000000000..f5255ac1af --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/contentviewers/Metadata.form @@ -0,0 +1,52 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/Core/src/org/sleuthkit/autopsy/contentviewers/Metadata.java b/Core/src/org/sleuthkit/autopsy/contentviewers/Metadata.java new file mode 100755 index 0000000000..cae2561fc8 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/contentviewers/Metadata.java @@ -0,0 +1,189 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2013 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.contentviewers; + +import java.awt.Component; +import javax.swing.JTextPane; +import org.openide.nodes.Node; +import org.openide.util.lookup.ServiceProvider; +import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; +import org.sleuthkit.datamodel.AbstractFile; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * Shows file metadata as a list to make it easy to copy and paste. + * Typically shows the same data that can also be found in the ResultViewer table, + * just a different order and allows the full path to be visible in the bottom area. + */ +@ServiceProvider(service = DataContentViewer.class, position = 3) +public class Metadata extends javax.swing.JPanel implements DataContentViewer +{ + /** + * Creates new form Metadata + */ + public Metadata() { + initComponents(); + customizeComponents(); + } + + /** + * 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() { + + jPopupMenu1 = new javax.swing.JPopupMenu(); + jScrollPane2 = new javax.swing.JScrollPane(); + jTextPane1 = new javax.swing.JTextPane(); + + jTextPane1.setEditable(false); + jScrollPane2.setViewportView(jTextPane1); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPopupMenu jPopupMenu1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JTextPane jTextPane1; + // End of variables declaration//GEN-END:variables + + private void customizeComponents(){ + /* + jTextPane1.setComponentPopupMenu(rightClickMenu); + ActionListener actList = new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e){ + JMenuItem jmi = (JMenuItem) e.getSource(); + if(jmi.equals(copyMenuItem)) + outputViewPane.copy(); + else if(jmi.equals(selectAllMenuItem)) + outputViewPane.selectAll(); + } + }; + copyMenuItem.addActionListener(actList); + selectAllMenuItem.addActionListener(actList); + */ + + Utilities.configureTextPaneAsHtml(jTextPane1); + } + + private void setText(String str) { + jTextPane1.setText("" + str + ""); + } + + private void startTable(StringBuilder sb) { + sb.append(""); + } + + private void endTable(StringBuilder sb) { + sb.append("
"); + } + + private void addRow(StringBuilder sb, String key, String value) { + sb.append(""); + sb.append(key); + sb.append(""); + sb.append(value); + sb.append(""); + } + + @Override + public void setNode(Node node) { + AbstractFile file = node.getLookup().lookup(AbstractFile.class); + if (file == null) { + setText("Non-file passed in"); + return; + } + + StringBuilder sb = new StringBuilder(); + startTable(sb); + + try { + addRow(sb, "Name", file.getUniquePath()); + } catch (TskCoreException ex) { + addRow(sb, "Name", file.getParentPath() + "/" + file.getName()); + } + + addRow(sb, "Modified", file.getMtimeAsDate()); + addRow(sb, "Accessed", file.getAtimeAsDate()); + addRow(sb, "Created", file.getCrtimeAsDate()); + addRow(sb, "Changed", file.getCtimeAsDate()); + + String md5 = file.getMd5Hash(); + if (md5 == null) { + md5 = "Not calculated"; + } + addRow(sb, "MD5", md5); + + endTable(sb); + setText(sb.toString()); + } + + @Override + public String getTitle() { + return "Metadata"; + } + + @Override + public String getToolTip() { + return ""; + } + + @Override + public DataContentViewer createInstance() { + return new Metadata(); + } + + @Override + public Component getComponent() { + return this; + } + + @Override + public void resetComponent() { + return; + } + + @Override + public boolean isSupported(Node node) { + AbstractFile file = node.getLookup().lookup(AbstractFile.class); + if (file == null) { + return false; + } + return true; + } + + @Override + public int isPreferred(Node node, boolean isSupported) { + return 1; + } +} diff --git a/Core/src/org/sleuthkit/autopsy/contentviewers/Utilities.java b/Core/src/org/sleuthkit/autopsy/contentviewers/Utilities.java new file mode 100755 index 0000000000..08203ff782 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/contentviewers/Utilities.java @@ -0,0 +1,49 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2013 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.contentviewers; + +import javax.swing.JTextPane; +import javax.swing.text.html.HTMLEditorKit; +import javax.swing.text.html.StyleSheet; + +/** + * + * Methods common to ContentViewers. + */ +public class Utilities { + + public static void configureTextPaneAsHtml(JTextPane pane) { + pane.setContentType("text/html;charset=UTF-8"); + HTMLEditorKit kit = new HTMLEditorKit(); + pane.setEditorKit(kit); + StyleSheet styleSheet = kit.getStyleSheet(); + /* I tried to play around with inheritence on font-size and it didn't + * always work. Defined all of the basics just in case. + * @@@ IngestInboxViewer also defines styles similar to this. Consider + * a method that sets consistent styles for all viewers and takes font + * size as an argument. + */ + styleSheet.addRule("body {font-family:Arial;font-size:14pt;}"); + styleSheet.addRule("p {font-family:Arial;font-size:14pt;}"); + styleSheet.addRule("li {font-family:Arial;font-size:14pt;}"); + styleSheet.addRule("td {font-family:Arial;font-size:14pt;overflow:hidden;padding-right:5px;padding-left:5px;}"); + styleSheet.addRule("th {font-family:Arial;font-size:14pt;overflow:hidden;padding-right:5px;padding-left:5px;font-weight:bold;}"); + styleSheet.addRule("p {font-family:Arial;font-size:14pt;}"); + } +} diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerArtifact.java b/Core/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerArtifact.java index b56614bbc4..978c8dc079 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerArtifact.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerArtifact.java @@ -31,11 +31,10 @@ import org.sleuthkit.autopsy.coreutils.Logger; import javax.swing.JMenuItem; import javax.swing.JTextPane; import javax.swing.SwingWorker; -import javax.swing.text.html.HTMLEditorKit; -import javax.swing.text.html.StyleSheet; import org.openide.nodes.Node; import org.openide.util.Lookup; import org.openide.util.lookup.ServiceProvider; +import org.sleuthkit.autopsy.contentviewers.Utilities; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; import org.sleuthkit.autopsy.datamodel.ArtifactStringContent; import org.sleuthkit.datamodel.BlackboardArtifact; @@ -245,22 +244,7 @@ public class DataContentViewerArtifact extends javax.swing.JPanel implements Dat copyMenuItem.addActionListener(actList); selectAllMenuItem.addActionListener(actList); - outputViewPane.setContentType("text/html;charset=UTF-8"); - HTMLEditorKit kit = new HTMLEditorKit(); - outputViewPane.setEditorKit(kit); - StyleSheet styleSheet = kit.getStyleSheet(); - /* I tried to play around with inheritence on font-size and it didn't - * always work. Defined all of the basics just in case. - * @@@ IngestInboxViewer also defines styles similar to this. Consider - * a method that sets consistent styles for all viewers and takes font - * size as an argument. - */ - styleSheet.addRule("body {font-family:Arial;font-size:14pt;}"); - styleSheet.addRule("p {font-family:Arial;font-size:14pt;}"); - styleSheet.addRule("li {font-family:Arial;font-size:14pt;}"); - styleSheet.addRule("td {font-family:Arial;font-size:14pt;overflow:hidden;padding-right:5px;padding-left:5px;}"); - styleSheet.addRule("th {font-family:Arial;font-size:14pt;overflow:hidden;padding-right:5px;padding-left:5px;font-weight:bold;}"); - styleSheet.addRule("p {font-family:Arial;font-size:14pt;}"); + Utilities.configureTextPaneAsHtml(outputViewPane); } /** @@ -304,7 +288,7 @@ public class DataContentViewerArtifact extends javax.swing.JPanel implements Dat @Override public String getTitle() { - return "Result View"; + return "Results"; } @Override