Autopsy  4.10.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 
41  private static final String[] SUPPORTED_MIMETYPES = new String[]{
42  "text/html",
43  "application/xhtml+xml"
44  };
45 
49  HtmlViewer() {
50  initComponents();
51  }
52 
60  @NbBundle.Messages({
61  "HtmlViewer_file_error=This file is missing or unreadable.",
62  })
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  htmlPanel = new org.sleuthkit.autopsy.contentviewers.HtmlPanel();
86 
87  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
88  this.setLayout(layout);
89  layout.setHorizontalGroup(
90  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
91  .addGroup(layout.createSequentialGroup()
92  .addContainerGap()
93  .addComponent(htmlPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
94  .addContainerGap())
95  );
96  layout.setVerticalGroup(
97  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
98  .addGroup(layout.createSequentialGroup()
99  .addContainerGap()
100  .addComponent(htmlPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
101  .addContainerGap())
102  );
103  }// </editor-fold>//GEN-END:initComponents
104 
105 
106  // Variables declaration - do not modify//GEN-BEGIN:variables
107  private org.sleuthkit.autopsy.contentviewers.HtmlPanel htmlPanel;
108  // End of variables declaration//GEN-END:variables
109 
110  @Override
111  public List<String> getSupportedMIMETypes() {
112  return Arrays.asList(SUPPORTED_MIMETYPES);
113  }
114 
115  @Override
116  public void setFile(AbstractFile file) {
117  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
118  htmlPanel.setHtmlText(getHtmlText(file));
119  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
120  }
121 
122  @Override
123  public Component getComponent() {
124  return this;
125  }
126 
127  @Override
128  public void resetComponent() {
129  htmlPanel.reset();
130  }
131 }

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