Autopsy  3.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 
20 package org.sleuthkit.autopsy.contentviewers;
21 
22 import java.awt.Component;
23 import org.openide.nodes.Node;
24 import org.openide.util.NbBundle;
25 import org.openide.util.lookup.ServiceProvider;
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);
85  ActionListener actList = new ActionListener(){
86  @Override
87  public void actionPerformed(ActionEvent e){
88  JMenuItem jmi = (JMenuItem) e.getSource();
89  if(jmi.equals(copyMenuItem))
90  outputViewPane.copy();
91  else if(jmi.equals(selectAllMenuItem))
92  outputViewPane.selectAll();
93  }
94  };
95  copyMenuItem.addActionListener(actList);
96  selectAllMenuItem.addActionListener(actList);
97  */
98 
100  }
101 
102  private void setText(String str) {
103  jTextPane1.setText("<html><body>" + str + "</body></html>"); //NON-NLS
104  }
105 
106  private void startTable(StringBuilder sb) {
107  sb.append("<table>"); //NON-NLS
108  }
109 
110  private void endTable(StringBuilder sb) {
111  sb.append("</table>"); //NON-NLS
112  }
113 
114  private void addRow(StringBuilder sb, String key, String value) {
115  sb.append("<tr><td>"); //NON-NLS
116  sb.append(key);
117  sb.append("</td><td>"); //NON-NLS
118  sb.append(value);
119  sb.append("</td></tr>"); //NON-NLS
120  }
121 
122  @Override
123  public void setNode(Node node) {
124  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
125  if (file == null) {
126  setText(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.nonFilePassedIn"));
127  return;
128  }
129 
130  StringBuilder sb = new StringBuilder();
131  startTable(sb);
132 
133  try {
134  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), file.getUniquePath());
135  } catch (TskCoreException ex) {
136  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), file.getParentPath() + "/" + file.getName());
137  }
138 
139  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.type"), file.getType().getName());
140  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.size"), new Long(file.getSize()).toString() );
141  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.fileNameAlloc"), file.getDirFlagAsString());
142  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.metadataAlloc"), file.getMetaFlagsAsString());
143  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.modified"), ContentUtils.getStringTime(file.getMtime(), file));
144  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.accessed"), ContentUtils.getStringTime(file.getAtime(), file));
145  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.created"), ContentUtils.getStringTime(file.getCrtime(), file));
146  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.changed"), ContentUtils.getStringTime(file.getCtime(), file));
147 
148  String md5 = file.getMd5Hash();
149  if (md5 == null) {
150  md5 = NbBundle.getMessage(this.getClass(), "Metadata.tableRowContent.md5notCalc");
151  }
152  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.md5"), md5);
153  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.hashLookupResults"), file.getKnown().toString());
154 
155  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.internalid"), new Long(file.getId()).toString());
156  if (file.getType().compareTo(TSK_DB_FILES_TYPE_ENUM.LOCAL) == 0) {
157  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.localPath"), file.getLocalAbsPath());
158  }
159 
160  endTable(sb);
161 
162  /* If we have a file system file, grab the more detailed metadata text too */
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  if (file == null) {
213  return false;
214  }
215  return true;
216  }
217 
218  @Override
219  public int isPreferred(Node node) {
220  return 1;
221  }
222 }
static String getStringTime(long epochSeconds, TimeZone tzone)
void addRow(StringBuilder sb, String key, String value)
Definition: Metadata.java:114
synchronized List< String > getMetaDataText()
TskData.TSK_DB_FILES_TYPE_ENUM getType()
static void configureTextPaneAsHtml(JTextPane pane)
Definition: Utilities.java:31

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