19 package org.sleuthkit.autopsy.contentviewers;
21 import java.awt.Component;
22 import java.awt.Cursor;
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.logging.Level;
26 import org.openide.util.NbBundle;
27 import org.openide.windows.WindowManager;
35 @SuppressWarnings(
"PMD.SingularField")
36 final class HtmlViewer extends javax.swing.JPanel implements FileTypeViewer {
38 private static final long serialVersionUID = 1L;
39 private static final Logger logger = Logger.getLogger(HtmlViewer.class.getName());
40 private static final String[] SUPPORTED_MIMETYPES =
new String[]{
42 "application/xhtml+xml"
62 "HtmlViewer_file_error=This file is missing or unreadable.",})
63 private String getHtmlText(AbstractFile abstractFile) {
65 int fileSize = (int) abstractFile.getSize();
66 byte[] buffer =
new byte[fileSize];
67 abstractFile.read(buffer, 0, fileSize);
68 return new String(buffer);
69 }
catch (TskCoreException ex) {
70 logger.log(Level.SEVERE, String.format(
"Unable to read from file '%s' (id=%d).",
71 abstractFile.getName(), abstractFile.getId()), ex);
72 return String.format(
"<p>%s</p>", Bundle.HtmlViewer_file_error());
81 @SuppressWarnings(
"unchecked")
83 private
void initComponents() {
85 setLayout(
new java.awt.BorderLayout());
92 public List<String> getSupportedMIMETypes() {
93 return Arrays.asList(SUPPORTED_MIMETYPES);
97 public void setFile(AbstractFile file) {
98 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
99 htmlPanel.setHtmlText(getHtmlText(file));
100 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
104 public Component getComponent() {
109 public void resetComponent() {
114 public boolean isSupported(AbstractFile file) {