Skip to content
Snippets Groups Projects
Unverified Commit c95b8e99 authored by Richard Cordovano's avatar Richard Cordovano Committed by GitHub
Browse files

Merge pull request #4604 from raman-bt/4786-malformed-html

4786: Handle incorrectly written HTML files.
parents 7cedf222 dd621c54
Branches
Tags
No related merge requests found
...@@ -32,8 +32,10 @@ GstVideoPanel.progress.buffering=Buffering... ...@@ -32,8 +32,10 @@ GstVideoPanel.progress.buffering=Buffering...
GstVideoPanel.progressLabel.bufferingErr=Error buffering file GstVideoPanel.progressLabel.bufferingErr=Error buffering file
GstVideoPanel.progress.infoLabel.updateErr=Error updating video progress: {0} GstVideoPanel.progress.infoLabel.updateErr=Error updating video progress: {0}
GstVideoPanel.ExtractMedia.progress.buffering=Buffering {0} GstVideoPanel.ExtractMedia.progress.buffering=Buffering {0}
Html_text_display_error=The HTML text cannot be displayed, it may not be correctly formed HTML.
HtmlPanel_showImagesToggleButton_hide=Hide Images HtmlPanel_showImagesToggleButton_hide=Hide Images
HtmlPanel_showImagesToggleButton_show=Show Images HtmlPanel_showImagesToggleButton_show=Show Images
HtmlViewer_file_error=This file is missing or unreadable.
MediaFileViewer.AccessibleContext.accessibleDescription= MediaFileViewer.AccessibleContext.accessibleDescription=
MediaFileViewer.title=Media MediaFileViewer.title=Media
MediaFileViewer.toolTip=Displays supported multimedia files (images, videos, audio) MediaFileViewer.toolTip=Displays supported multimedia files (images, videos, audio)
......
...@@ -92,20 +92,24 @@ private String cleanseHTML(String htmlInString) { ...@@ -92,20 +92,24 @@ private String cleanseHTML(String htmlInString) {
*/ */
@Messages({ @Messages({
"HtmlPanel_showImagesToggleButton_show=Show Images", "HtmlPanel_showImagesToggleButton_show=Show Images",
"HtmlPanel_showImagesToggleButton_hide=Hide Images" "HtmlPanel_showImagesToggleButton_hide=Hide Images",
"Html_text_display_error=The HTML text cannot be displayed, it may not be correctly formed HTML.",
}) })
private void refresh() { private void refresh() {
if (false == htmlText.isEmpty()) { if (false == htmlText.isEmpty()) {
if (showImagesToggleButton.isSelected()) { try {
showImagesToggleButton.setText(Bundle.HtmlPanel_showImagesToggleButton_hide()); if (showImagesToggleButton.isSelected()) {
this.htmlbodyTextPane.setText(wrapInHtmlBody(htmlText)); showImagesToggleButton.setText(Bundle.HtmlPanel_showImagesToggleButton_hide());
} else { this.htmlbodyTextPane.setText(wrapInHtmlBody(htmlText));
showImagesToggleButton.setText(Bundle.HtmlPanel_showImagesToggleButton_show()); } else {
this.htmlbodyTextPane.setText(wrapInHtmlBody(cleanseHTML(htmlText))); showImagesToggleButton.setText(Bundle.HtmlPanel_showImagesToggleButton_show());
this.htmlbodyTextPane.setText(wrapInHtmlBody(cleanseHTML(htmlText)));
}
showImagesToggleButton.setEnabled(true);
htmlbodyTextPane.setCaretPosition(0);
} catch(Exception ex) {
this.htmlbodyTextPane.setText(wrapInHtmlBody(Bundle.Html_text_display_error()));
} }
htmlbodyTextPane.setCaretPosition(0);
showImagesToggleButton.setEnabled(true);
} }
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import org.openide.util.NbBundle;
import org.openide.windows.WindowManager; import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.AbstractFile;
...@@ -56,6 +57,9 @@ final class HtmlViewer extends javax.swing.JPanel implements FileTypeViewer { ...@@ -56,6 +57,9 @@ final class HtmlViewer extends javax.swing.JPanel implements FileTypeViewer {
* *
* @return The text content of the file. * @return The text content of the file.
*/ */
@NbBundle.Messages({
"HtmlViewer_file_error=This file is missing or unreadable.",
})
private String getHtmlText(AbstractFile abstractFile) { private String getHtmlText(AbstractFile abstractFile) {
try { try {
int fileSize = (int) abstractFile.getSize(); int fileSize = (int) abstractFile.getSize();
...@@ -65,9 +69,8 @@ private String getHtmlText(AbstractFile abstractFile) { ...@@ -65,9 +69,8 @@ private String getHtmlText(AbstractFile abstractFile) {
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
logger.log(Level.SEVERE, String.format("Unable to read from file '%s' (id=%d).", logger.log(Level.SEVERE, String.format("Unable to read from file '%s' (id=%d).",
abstractFile.getName(), abstractFile.getId()), ex); abstractFile.getName(), abstractFile.getId()), ex);
return String.format("<p>%s</p>", Bundle.HtmlViewer_file_error());
} }
return null;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment