Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
HtmlViewer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019 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 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;
29 import org.sleuthkit.datamodel.AbstractFile;
30 import org.sleuthkit.datamodel.TskCoreException;
31 
35 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
36 final class HtmlViewer extends javax.swing.JPanel implements FileTypeViewer {
37 
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[]{
41  "text/html",
42  "application/xhtml+xml"
43  };
45 
49  HtmlViewer() {
50  initComponents();
51  this.add(htmlPanel);
52  }
53 
61  @NbBundle.Messages({
62  "HtmlViewer_file_error=This file is missing or unreadable.",})
63  private String getHtmlText(AbstractFile abstractFile) {
64  try {
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());
73  }
74  }
75 
81  @SuppressWarnings("unchecked")
82  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
83  private void initComponents() {
84 
85  setLayout(new java.awt.BorderLayout());
86  }// </editor-fold>//GEN-END:initComponents
87 
88 
89  // Variables declaration - do not modify//GEN-BEGIN:variables
90  // End of variables declaration//GEN-END:variables
91  @Override
92  public List<String> getSupportedMIMETypes() {
93  return Arrays.asList(SUPPORTED_MIMETYPES);
94  }
95 
96  @Override
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));
101  }
102 
103  @Override
104  public Component getComponent() {
105  return this;
106  }
107 
108  @Override
109  public void resetComponent() {
110  htmlPanel.reset();
111  }
112 
113  @Override
114  public boolean isSupported(AbstractFile file) {
115  return true;
116  }
117 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.