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;
44 private static final String
EMPTY_HTML =
"<html><head></head><body></body></html>";
63 void showMessage(String message) {
65 textPanel.setText(
"<html><head></head><body>"
66 + MessageFormat.format(
"<p class=\"{0}\">{1}</p>",
84 void displayResults(NodeResults nodeResults) {
85 Document document = Jsoup.parse(EMPTY_HTML);
86 Element body = document.getElementsByTag(
"body").first();
88 Optional<Element> panelHeader =
appendPanelHeader(body, nodeResults.getItemName(), nodeResults.getAggregateScore());
91 List<ResultDisplayAttributes> displayAttributes = nodeResults.getAnalysisResults();
92 for (
int idx = 0; idx < displayAttributes.size(); idx++) {
93 AnalysisResultsViewModel.ResultDisplayAttributes resultAttrs = displayAttributes.get(idx);
94 Element sectionDiv =
appendResult(body, idx, resultAttrs);
95 if (idx > 0 || panelHeader.isPresent()) {
96 sectionDiv.attr(
"class", ContentViewerHtmlStyles.getSpacedSectionClassName());
101 ContentViewerHtmlStyles.setStyles(
textPanel);
105 Optional<AnalysisResult> selectedResult = nodeResults.getSelectedResult();
106 if (selectedResult.isPresent()) {
125 "AnalysisResultsContentPanel_aggregateScore_displayKey=Aggregate Score",
126 "AnalysisResultsContentPanel_content_displayKey=Item"
128 private Optional<Element>
appendPanelHeader(Element parent, Optional<String> itemName, Optional<Score> score) {
130 if (!itemName.isPresent() || !score.isPresent()) {
131 return Optional.empty();
134 Element container = parent.appendElement(
"div");
137 container.appendElement(
"p")
139 .text(MessageFormat.format(
"{0}: {1}",
140 Bundle.AnalysisResultsContentPanel_content_displayKey(),
144 container.appendElement(
"p")
146 .text(MessageFormat.format(
"{0}: {1}",
147 Bundle.AnalysisResultsContentPanel_aggregateScore_displayKey(),
148 score.get().getSignificance().getDisplayName()));
150 return Optional.ofNullable(container);
160 private String
getAnchor(AnalysisResult analysisResult) {
161 return RESULT_ANCHOR_PREFIX + analysisResult.getId();
173 @NbBundle.Messages({
"# {0} - analysisResultsNumber",
174 "AnalysisResultsContentPanel_result_headerKey=Analysis Result {0}"
179 Bundle.AnalysisResultsContentPanel_result_headerKey(index + 1),
180 Optional.ofNullable(
getAnchor(attrs.getAnalysisResult())));
183 Element table = sectionDiv.appendElement(
"table")
184 .attr(
"valign",
"top")
185 .attr(
"align",
"left");
189 Element tableBody = table.appendElement(
"tbody");
192 for (Pair<String, String> keyVal : attrs.getAttributesToDisplay()) {
193 Element row = tableBody.appendElement(
"tr");
194 String keyString = keyVal.getKey() == null ?
"" : keyVal.getKey() +
":";
195 Element keyTd = row.appendElement(
"td")
198 keyTd.appendElement(
"span")
202 String valueString = keyVal.getValue() == null ?
"" : keyVal.getValue();
203 row.appendElement(
"td")
220 private Element
appendSection(Element parent, String headerText, Optional<String> anchorId) {
221 Element sectionDiv = parent.appendElement(
"div");
224 Element anchorEl = null;
225 if (anchorId.isPresent()) {
226 anchorEl = sectionDiv.appendElement(
"a");
227 anchorEl.attr(
"name", anchorId.get());
228 anchorEl.attr(
"style",
"padding: 0px; margin: 0px; display: inline-block;");
232 Element header = null;
233 header = (anchorEl == null)
234 ? sectionDiv.appendElement(
"h1")
235 : anchorEl.appendElement(
"h1");
237 header.text(headerText);
239 header.attr(
"style",
"display: inline-block");
250 @SuppressWarnings(
"unchecked")
254 javax.swing.JScrollPane scrollPane =
new javax.swing.JScrollPane();
257 setPreferredSize(
new java.awt.Dimension(100, 58));
261 textPanel.setPreferredSize(
new java.awt.Dimension(600, 52));
264 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
265 this.setLayout(layout);
266 layout.setHorizontalGroup(
267 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
268 .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 907, Short.MAX_VALUE)
270 layout.setVerticalGroup(
271 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
272 .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< String > itemName, 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