19 package org.sleuthkit.autopsy.contentviewers.analysisresults;
21 import java.text.MessageFormat;
22 import java.util.List;
23 import java.util.Optional;
24 import org.apache.commons.lang3.tuple.Pair;
25 import org.jsoup.Jsoup;
26 import org.jsoup.nodes.Document;
27 import org.jsoup.nodes.Element;
28 import org.openide.util.NbBundle;
29 import org.openide.util.NbBundle.Messages;
45 private static final String
EMPTY_HTML =
"<html><head></head><body></body></html>";
64 void showMessage(String message) {
66 textPanel.setText(
"<html><head></head><body>"
67 + MessageFormat.format(
"<p class=\"{0}\">{1}</p>",
85 void displayResults(NodeResults nodeResults) {
86 Document document = Jsoup.parse(EMPTY_HTML);
87 Element body = document.getElementsByTag(
"body").first();
89 Optional<Element> panelHeader =
appendPanelHeader(body, nodeResults.getContent(), nodeResults.getAggregateScore());
92 List<ResultDisplayAttributes> displayAttributes = nodeResults.getAnalysisResults();
93 for (
int idx = 0; idx < displayAttributes.size(); idx++) {
94 AnalysisResultsViewModel.ResultDisplayAttributes resultAttrs = displayAttributes.get(idx);
95 Element sectionDiv =
appendResult(body, idx, resultAttrs);
96 if (idx > 0 || panelHeader.isPresent()) {
97 sectionDiv.attr(
"class", ContentViewerHtmlStyles.getSpacedSectionClassName());
102 ContentViewerHtmlStyles.setStyles(
textPanel);
106 Optional<AnalysisResult> selectedResult = nodeResults.getSelectedResult();
107 if (selectedResult.isPresent()) {
126 "AnalysisResultsContentPanel_aggregateScore_displayKey=Aggregate Score",
127 "AnalysisResultsContentPanel_content_displayKey=Item"
129 private Optional<Element>
appendPanelHeader(Element parent, Optional<Content> content, Optional<Score> score) {
130 if (!content.isPresent() || !score.isPresent()) {
131 return Optional.empty();
134 Element container = parent.appendElement(
"div");
137 content.ifPresent((c) -> {
138 container.appendElement(
"p")
140 .text(MessageFormat.format(
"{0}: {1}",
141 Bundle.AnalysisResultsContentPanel_content_displayKey(),
146 score.ifPresent((s) -> {
147 container.appendElement(
"p")
149 .text(MessageFormat.format(
"{0}: {1}",
150 Bundle.AnalysisResultsContentPanel_aggregateScore_displayKey(),
151 s.getSignificance().getDisplayName()));
154 return Optional.ofNullable(container);
164 private String
getAnchor(AnalysisResult analysisResult) {
165 return RESULT_ANCHOR_PREFIX + analysisResult.getId();
177 @NbBundle.Messages({
"# {0} - analysisResultsNumber",
178 "AnalysisResultsContentPanel_result_headerKey=Analysis Result {0}"
183 Bundle.AnalysisResultsContentPanel_result_headerKey(index + 1),
184 Optional.ofNullable(
getAnchor(attrs.getAnalysisResult())));
187 Element table = sectionDiv.appendElement(
"table")
188 .attr(
"valign",
"top")
189 .attr(
"align",
"left");
193 Element tableBody = table.appendElement(
"tbody");
196 for (Pair<String, String> keyVal : attrs.getAttributesToDisplay()) {
197 Element row = tableBody.appendElement(
"tr");
198 String keyString = keyVal.getKey() == null ?
"" : keyVal.getKey() +
":";
199 Element keyTd = row.appendElement(
"td")
202 keyTd.appendElement(
"span")
206 String valueString = keyVal.getValue() == null ?
"" : keyVal.getValue();
207 row.appendElement(
"td")
224 private Element
appendSection(Element parent, String headerText, Optional<String> anchorId) {
225 Element sectionDiv = parent.appendElement(
"div");
228 Element anchorEl = null;
229 if (anchorId.isPresent()) {
230 anchorEl = sectionDiv.appendElement(
"a");
231 anchorEl.attr(
"name", anchorId.get());
232 anchorEl.attr(
"style",
"padding: 0px; margin: 0px; display: inline-block;");
236 Element header = null;
237 header = (anchorEl == null)
238 ? sectionDiv.appendElement(
"h1")
239 : anchorEl.appendElement(
"h1");
241 header.text(headerText);
243 header.attr(
"style",
"display: inline-block");
254 @SuppressWarnings(
"unchecked")
258 javax.swing.JScrollPane scrollPane =
new javax.swing.JScrollPane();
261 setPreferredSize(
new java.awt.Dimension(100, 58));
265 textPanel.setPreferredSize(
new java.awt.Dimension(600, 52));
268 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
269 this.setLayout(layout);
270 layout.setHorizontalGroup(
271 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
272 .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 907, Short.MAX_VALUE)
274 layout.setVerticalGroup(
275 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
276 .addComponent(scrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE)
static final String EMPTY_HTML
static String escapeHtml(String toEscape)
String getAnchor(AnalysisResult analysisResult)
Optional< Element > appendPanelHeader(Element parent, Optional< Content > content, Optional< Score > score)
static String getTextClassName()
Element appendSection(Element parent, String headerText, Optional< String > anchorId)
static void setStyles(JTextPane textPane)
static String getKeyColumnClassName()
static String getIndentedClassName()
static final String RESULT_ANCHOR_PREFIX
Element appendResult(Element parent, int index, AnalysisResultsViewModel.ResultDisplayAttributes attrs)
javax.swing.JTextPane textPanel
AnalysisResultsContentPanel()
static void setupHtmlJTextPane(JTextPane textPane)
static String getHeaderClassName()
static String getMessageClassName()
static final long serialVersionUID