Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
Metadata.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.contentviewers;
20 
21 import java.awt.Component;
22 import org.openide.nodes.Node;
23 import org.openide.util.NbBundle;
24 import org.openide.util.lookup.ServiceProvider;
27 import org.sleuthkit.datamodel.AbstractFile;
28 import org.sleuthkit.datamodel.FsContent;
29 import org.sleuthkit.datamodel.TskCoreException;
30 import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
31 
37 @ServiceProvider(service = DataContentViewer.class, position = 3)
38 public class Metadata extends javax.swing.JPanel implements DataContentViewer {
39 
43  public Metadata() {
44  initComponents();
45  customizeComponents();
46  }
47 
53  @SuppressWarnings("unchecked")
54  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
55  private void initComponents() {
56 
57  jPopupMenu1 = new javax.swing.JPopupMenu();
58  jScrollPane2 = new javax.swing.JScrollPane();
59  jTextPane1 = new javax.swing.JTextPane();
60 
61  jTextPane1.setEditable(false);
62  jScrollPane2.setViewportView(jTextPane1);
63 
64  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
65  this.setLayout(layout);
66  layout.setHorizontalGroup(
67  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
68  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
69  );
70  layout.setVerticalGroup(
71  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
72  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
73  );
74  }// </editor-fold>//GEN-END:initComponents
75  // Variables declaration - do not modify//GEN-BEGIN:variables
76  private javax.swing.JPopupMenu jPopupMenu1;
77  private javax.swing.JScrollPane jScrollPane2;
78  private javax.swing.JTextPane jTextPane1;
79  // End of variables declaration//GEN-END:variables
80 
81  private void customizeComponents() {
82  /*
83  * jTextPane1.setComponentPopupMenu(rightClickMenu); ActionListener
84  * actList = new ActionListener(){ @Override public void
85  * actionPerformed(ActionEvent e){ JMenuItem jmi = (JMenuItem)
86  * e.getSource(); if(jmi.equals(copyMenuItem)) outputViewPane.copy();
87  * else if(jmi.equals(selectAllMenuItem)) outputViewPane.selectAll(); }
88  * }; copyMenuItem.addActionListener(actList);
89  * selectAllMenuItem.addActionListener(actList);
90  */
91 
93  }
94 
95  private void setText(String str) {
96  jTextPane1.setText("<html><body>" + str + "</body></html>"); //NON-NLS
97  }
98 
99  private void startTable(StringBuilder sb) {
100  sb.append("<table>"); //NON-NLS
101  }
102 
103  private void endTable(StringBuilder sb) {
104  sb.append("</table>"); //NON-NLS
105  }
106 
107  private void addRow(StringBuilder sb, String key, String value) {
108  sb.append("<tr><td>"); //NON-NLS
109  sb.append(key);
110  sb.append("</td><td>"); //NON-NLS
111  sb.append(value);
112  sb.append("</td></tr>"); //NON-NLS
113  }
114 
115  @Override
116  public void setNode(Node node) {
117  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
118  if (file == null) {
119  setText(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.nonFilePassedIn"));
120  return;
121  }
122 
123  StringBuilder sb = new StringBuilder();
124  startTable(sb);
125 
126  try {
127  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), file.getUniquePath());
128  } catch (TskCoreException ex) {
129  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), file.getParentPath() + "/" + file.getName());
130  }
131 
132  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.type"), file.getType().getName());
133  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.size"), new Long(file.getSize()).toString());
134  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.fileNameAlloc"), file.getDirFlagAsString());
135  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.metadataAlloc"), file.getMetaFlagsAsString());
136  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.modified"), ContentUtils.getStringTime(file.getMtime(), file));
137  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.accessed"), ContentUtils.getStringTime(file.getAtime(), file));
138  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.created"), ContentUtils.getStringTime(file.getCrtime(), file));
139  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.changed"), ContentUtils.getStringTime(file.getCtime(), file));
140 
141  String md5 = file.getMd5Hash();
142  if (md5 == null) {
143  md5 = NbBundle.getMessage(this.getClass(), "Metadata.tableRowContent.md5notCalc");
144  }
145  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.md5"), md5);
146  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.hashLookupResults"), file.getKnown().toString());
147 
148  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.internalid"), new Long(file.getId()).toString());
149  if (file.getType().compareTo(TSK_DB_FILES_TYPE_ENUM.LOCAL) == 0) {
150  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.localPath"), file.getLocalAbsPath());
151  }
152 
153  endTable(sb);
154 
155  /*
156  * If we have a file system file, grab the more detailed metadata text
157  * too
158  */
159  try {
160  if (file instanceof FsContent) {
161  FsContent fsFile = (FsContent) file;
162 
163  sb.append("<hr /><pre>\n"); //NON-NLS
164  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.text"));
165  sb.append(" <br /><br />"); // NON-NLS
166  for (String str : fsFile.getMetaDataText()) {
167  sb.append(str).append("<br />"); //NON-NLS
168  }
169  sb.append("</pre>\n"); //NON-NLS
170  }
171  } catch (TskCoreException ex) {
172  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.exceptionNotice.text")).append(ex.getLocalizedMessage());
173  }
174 
175  setText(sb.toString());
176  jTextPane1.setCaretPosition(0);
177  this.setCursor(null);
178  }
179 
180  @Override
181  public String getTitle() {
182  return NbBundle.getMessage(this.getClass(), "Metadata.title");
183  }
184 
185  @Override
186  public String getToolTip() {
187  return NbBundle.getMessage(this.getClass(), "Metadata.toolTip");
188  }
189 
190  @Override
191  public DataContentViewer createInstance() {
192  return new Metadata();
193  }
194 
195  @Override
196  public Component getComponent() {
197  return this;
198  }
199 
200  @Override
201  public void resetComponent() {
202  return;
203  }
204 
205  @Override
206  public boolean isSupported(Node node) {
207  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
208  if (file == null) {
209  return false;
210  }
211  return true;
212  }
213 
214  @Override
215  public int isPreferred(Node node) {
216  return 1;
217  }
218 }
static String getStringTime(long epochSeconds, TimeZone tzone)
void addRow(StringBuilder sb, String key, String value)
Definition: Metadata.java:107
static void configureTextPaneAsHtml(JTextPane pane)
Definition: Utilities.java:31

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.