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;
 
 31 import org.
sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
 
 32 
 38 @ServiceProvider(service = DataContentViewer.class, position = 6)
 40 
 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  setPreferredSize(new java.awt.Dimension(100, 52));
 63 
 64  jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
 65  jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
 66  jScrollPane2.setPreferredSize(new java.awt.Dimension(610, 52));
 67 
 68  jTextPane1.setEditable(false);
 69  jTextPane1.setPreferredSize(new java.awt.Dimension(600, 52));
 70  jScrollPane2.setViewportView(jTextPane1);
 71 
 72  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
 73  this.setLayout(layout);
 74  layout.setHorizontalGroup(
 75  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 76  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 77  );
 78  layout.setVerticalGroup(
 79  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 80  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 81  );
 82  }// </editor-fold>//GEN-END:initComponents
 83  // Variables declaration - do not modify//GEN-BEGIN:variables
 87  // End of variables declaration//GEN-END:variables
 88 
 90  /*
 91  * jTextPane1.setComponentPopupMenu(rightClickMenu); ActionListener
 92  * actList = new ActionListener(){ @Override public void
 93  * actionPerformed(ActionEvent e){ JMenuItem jmi = (JMenuItem)
 94  * e.getSource(); if(jmi.equals(copyMenuItem)) outputViewPane.copy();
 95  * else if(jmi.equals(selectAllMenuItem)) outputViewPane.selectAll(); }
 96  * }; copyMenuItem.addActionListener(actList);
 97  * selectAllMenuItem.addActionListener(actList);
 98  */
 99 
 101  }
 102 
 104  jTextPane1.setText("<html><body>" + str + "</body></html>"); //NON-NLS
 105  }
 106 
 108  sb.append("<table>"); //NON-NLS
 109  }
 110 
 112  sb.append("</table>"); //NON-NLS
 113  }
 114 
 115   private void addRow(StringBuilder sb, String key, String value) {
 
 116  sb.append("<tr><td>"); //NON-NLS
 117  sb.append(key);
 118  sb.append("</td><td>"); //NON-NLS
 119  sb.append(value);
 120  sb.append("</td></tr>"); //NON-NLS
 121  }
 122 
 123  @Messages({
 124  "Metadata.tableRowTitle.mimeType=MIME Type",
 125  "Metadata.nodeText.truncated=(results truncated)"})
 126  @Override
 128  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
 129  if (file == null) {
 130  setText(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.nonFilePassedIn"));
 131  return;
 132  }
 133 
 134  StringBuilder sb = new StringBuilder();
 135  startTable(sb);
 136 
 137  try {
 138  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), file.getUniquePath());
 139  } catch (TskCoreException ex) {
 140  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), file.getParentPath() + "/" + file.getName());
 141  }
 142 
 143  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.type"), file.getType().getName());
 144  addRow(sb, Bundle.Metadata_tableRowTitle_mimeType(), file.getMIMEType());
 145  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.size"), Long.toString(file.getSize()));
 146  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.fileNameAlloc"), file.getDirFlagAsString());
 147  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.metadataAlloc"), file.getMetaFlagsAsString());
 148  addRow(sb, NbBundle.getMessage(
this.getClass(), 
"Metadata.tableRowTitle.modified"), 
ContentUtils.
getStringTime(file.getMtime(), file));
 
 149  addRow(sb, NbBundle.getMessage(
this.getClass(), 
"Metadata.tableRowTitle.accessed"), 
ContentUtils.
getStringTime(file.getAtime(), file));
 
 150  addRow(sb, NbBundle.getMessage(
this.getClass(), 
"Metadata.tableRowTitle.created"), 
ContentUtils.
getStringTime(file.getCrtime(), file));
 
 151  addRow(sb, NbBundle.getMessage(
this.getClass(), 
"Metadata.tableRowTitle.changed"), 
ContentUtils.
getStringTime(file.getCtime(), file));
 
 152  
 153 
 154  String md5 = file.getMd5Hash();
 155  if (md5 == null) {
 156  md5 = NbBundle.getMessage(this.getClass(), "Metadata.tableRowContent.md5notCalc");
 157  }
 158  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.md5"), md5);
 159  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.hashLookupResults"), file.getKnown().toString());
 160 
 161  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.internalid"), Long.toString(file.getId()));
 162  if (file.getType().compareTo(TSK_DB_FILES_TYPE_ENUM.LOCAL) == 0) {
 163  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.localPath"), file.getLocalAbsPath());
 164  }
 165 
 166  endTable(sb);
 167 
 168  /*
 169  * If we have a file system file, grab the more detailed metadata text
 170  * too
 171  */
 172  try {
 173  if (file instanceof FsContent) {
 174  FsContent fsFile = (FsContent) file;
 175 
 176  sb.append("<hr /><pre>\n"); //NON-NLS
 177  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.text"));
 178  sb.append(" <br /><br />"); // NON-NLS
 179  for (String str : fsFile.getMetaDataText()) {
 180  sb.append(str).append("<br />"); //NON-NLS
 181  
 182  /* 
 183  * Very long results can cause the UI to hang before displaying,
 184  * so truncate the results if necessary.
 185  */
 186  if(sb.length() > 50000){
 187  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.truncated"));
 188  break;
 189  }
 190  }
 191  sb.append("</pre>\n"); //NON-NLS
 192  }
 193  } catch (TskCoreException ex) {
 194  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.exceptionNotice.text")).append(ex.getLocalizedMessage());
 195  }
 196 
 197  setText(sb.toString());
 198  jTextPane1.setCaretPosition(0);
 199  this.setCursor(null);
 200  }
 201 
 202  @Override
 204  return NbBundle.getMessage(this.getClass(), "Metadata.title");
 205  }
 206 
 207  @Override
 209  return NbBundle.getMessage(this.getClass(), "Metadata.toolTip");
 210  }
 211 
 212  @Override
 215  }
 216 
 217  @Override
 219  return this;
 220  }
 221 
 222  @Override
 224  setText("");
 225  return;
 226  }
 227 
 228  @Override
 230  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
 231  return file != null;
 232  }
 233 
 234  @Override
 236  return 1;
 237  }
 238 }
void endTable(StringBuilder sb)
static String getStringTime(long epochSeconds, TimeZone tzone)
void addRow(StringBuilder sb, String key, String value)
javax.swing.JTextPane jTextPane1
javax.swing.JPopupMenu jPopupMenu1
void customizeComponents()
static void configureTextPaneAsHtml(JTextPane pane)
boolean isSupported(Node node)
DataContentViewer createInstance()
int isPreferred(Node node)
javax.swing.JScrollPane jScrollPane2
void startTable(StringBuilder sb)