Added basic metadata content viewer and made HTML stye sheets common

This commit is contained in:
Brian Carrier 2013-09-09 17:00:16 -04:00
parent e49294f6f6
commit f436e0bfd4
4 changed files with 293 additions and 19 deletions

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
<Container class="javax.swing.JPopupMenu" name="jPopupMenu1">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/>
</Layout>
</Container>
</NonVisualComponents>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane2" alignment="0" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane2" alignment="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane2">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTextPane" name="jTextPane1">
<Properties>
<Property name="editable" type="boolean" value="false"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View File

@ -0,0 +1,189 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2013 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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)
);
}// </editor-fold>//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("<html><body>" + str + "</body></html>");
}
private void startTable(StringBuilder sb) {
sb.append("<table>");
}
private void endTable(StringBuilder sb) {
sb.append("</table>");
}
private void addRow(StringBuilder sb, String key, String value) {
sb.append("<tr><td>");
sb.append(key);
sb.append("</td><td>");
sb.append(value);
sb.append("</td></tr>");
}
@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;
}
}

View File

@ -0,0 +1,49 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2013 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 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;}");
}
}

View File

@ -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