Autopsy  4.1
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.NbBundle.Messages;
25 import org.openide.util.lookup.ServiceProvider;
28 import org.sleuthkit.datamodel.AbstractFile;
29 import org.sleuthkit.datamodel.FsContent;
30 import org.sleuthkit.datamodel.TskCoreException;
31 import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
32 
38 @ServiceProvider(service = DataContentViewer.class, position = 3)
39 public class Metadata extends javax.swing.JPanel implements DataContentViewer {
40 
44  public Metadata() {
45  initComponents();
46  customizeComponents();
47  }
48 
54  @SuppressWarnings("unchecked")
55  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
56  private void initComponents() {
57 
58  jPopupMenu1 = new javax.swing.JPopupMenu();
59  jScrollPane2 = new javax.swing.JScrollPane();
60  jTextPane1 = new javax.swing.JTextPane();
61 
62  jTextPane1.setEditable(false);
63  jScrollPane2.setViewportView(jTextPane1);
64 
65  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
66  this.setLayout(layout);
67  layout.setHorizontalGroup(
68  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
69  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
70  );
71  layout.setVerticalGroup(
72  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
73  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
74  );
75  }// </editor-fold>//GEN-END:initComponents
76  // Variables declaration - do not modify//GEN-BEGIN:variables
77  private javax.swing.JPopupMenu jPopupMenu1;
78  private javax.swing.JScrollPane jScrollPane2;
79  private javax.swing.JTextPane jTextPane1;
80  // End of variables declaration//GEN-END:variables
81 
82  private void customizeComponents() {
83  /*
84  * jTextPane1.setComponentPopupMenu(rightClickMenu); ActionListener
85  * actList = new ActionListener(){ @Override public void
86  * actionPerformed(ActionEvent e){ JMenuItem jmi = (JMenuItem)
87  * e.getSource(); if(jmi.equals(copyMenuItem)) outputViewPane.copy();
88  * else if(jmi.equals(selectAllMenuItem)) outputViewPane.selectAll(); }
89  * }; copyMenuItem.addActionListener(actList);
90  * selectAllMenuItem.addActionListener(actList);
91  */
92 
94  }
95 
96  private void setText(String str) {
97  jTextPane1.setText("<html><body>" + str + "</body></html>"); //NON-NLS
98  }
99 
100  private void startTable(StringBuilder sb) {
101  sb.append("<table>"); //NON-NLS
102  }
103 
104  private void endTable(StringBuilder sb) {
105  sb.append("</table>"); //NON-NLS
106  }
107 
108  private void addRow(StringBuilder sb, String key, String value) {
109  sb.append("<tr><td>"); //NON-NLS
110  sb.append(key);
111  sb.append("</td><td>"); //NON-NLS
112  sb.append(value);
113  sb.append("</td></tr>"); //NON-NLS
114  }
115 
116  @Messages({"Metadata.tableRowTitle.mimeType=MIME Type"})
117  @Override
118  public void setNode(Node node) {
119  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
120  if (file == null) {
121  setText(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.nonFilePassedIn"));
122  return;
123  }
124 
125  StringBuilder sb = new StringBuilder();
126  startTable(sb);
127 
128  try {
129  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), file.getUniquePath());
130  } catch (TskCoreException ex) {
131  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), file.getParentPath() + "/" + file.getName());
132  }
133 
134  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.type"), file.getType().getName());
135  addRow(sb, Bundle.Metadata_tableRowTitle_mimeType(), file.getMIMEType());
136  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.size"), Long.toString(file.getSize()));
137  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.fileNameAlloc"), file.getDirFlagAsString());
138  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.metadataAlloc"), file.getMetaFlagsAsString());
139  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.modified"), ContentUtils.getStringTime(file.getMtime(), file));
140  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.accessed"), ContentUtils.getStringTime(file.getAtime(), file));
141  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.created"), ContentUtils.getStringTime(file.getCrtime(), file));
142  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.changed"), ContentUtils.getStringTime(file.getCtime(), file));
143 
144 
145  String md5 = file.getMd5Hash();
146  if (md5 == null) {
147  md5 = NbBundle.getMessage(this.getClass(), "Metadata.tableRowContent.md5notCalc");
148  }
149  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.md5"), md5);
150  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.hashLookupResults"), file.getKnown().toString());
151 
152  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.internalid"), Long.toString(file.getId()));
153  if (file.getType().compareTo(TSK_DB_FILES_TYPE_ENUM.LOCAL) == 0) {
154  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.localPath"), file.getLocalAbsPath());
155  }
156 
157  endTable(sb);
158 
159  /*
160  * If we have a file system file, grab the more detailed metadata text
161  * too
162  */
163  try {
164  if (file instanceof FsContent) {
165  FsContent fsFile = (FsContent) file;
166 
167  sb.append("<hr /><pre>\n"); //NON-NLS
168  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.text"));
169  sb.append(" <br /><br />"); // NON-NLS
170  for (String str : fsFile.getMetaDataText()) {
171  sb.append(str).append("<br />"); //NON-NLS
172  }
173  sb.append("</pre>\n"); //NON-NLS
174  }
175  } catch (TskCoreException ex) {
176  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.exceptionNotice.text")).append(ex.getLocalizedMessage());
177  }
178 
179  setText(sb.toString());
180  jTextPane1.setCaretPosition(0);
181  this.setCursor(null);
182  }
183 
184  @Override
185  public String getTitle() {
186  return NbBundle.getMessage(this.getClass(), "Metadata.title");
187  }
188 
189  @Override
190  public String getToolTip() {
191  return NbBundle.getMessage(this.getClass(), "Metadata.toolTip");
192  }
193 
194  @Override
195  public DataContentViewer createInstance() {
196  return new Metadata();
197  }
198 
199  @Override
200  public Component getComponent() {
201  return this;
202  }
203 
204  @Override
205  public void resetComponent() {
206  return;
207  }
208 
209  @Override
210  public boolean isSupported(Node node) {
211  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
212  return file != null;
213  }
214 
215  @Override
216  public int isPreferred(Node node) {
217  return 1;
218  }
219 }
static String getStringTime(long epochSeconds, TimeZone tzone)
void addRow(StringBuilder sb, String key, String value)
Definition: Metadata.java:108
static void configureTextPaneAsHtml(JTextPane pane)
Definition: Utilities.java:31

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.