Skip to content

Add Javadoc to de.rub.nds.scanner.core.report package #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
de53990
Add Javadoc to AnalyzedPropertyTextEncoder
ic0ns Jun 18, 2025
a31578b
Add Javadoc to AnsiColor
ic0ns Jun 18, 2025
b0c2d24
Add Javadoc to AnsiEscapeSequence
ic0ns Jun 18, 2025
884b778
Add Javadoc to ColorEncoding
ic0ns Jun 18, 2025
d3441a9
Add Javadoc to Encoder
ic0ns Jun 18, 2025
5b7701c
Add Javadoc to PerformanceData
ic0ns Jun 18, 2025
ba54582
Add Javadoc to PrintingScheme
ic0ns Jun 18, 2025
8ba7629
Add Javadoc to ReportCreator
ic0ns Jun 18, 2025
fab3d5a
Add Javadoc to ReportPrinter
ic0ns Jun 18, 2025
86e74df
Add Javadoc to ScanReport
ic0ns Jun 18, 2025
343274e
Add Javadoc to TestResultTextEncoder
ic0ns Jun 18, 2025
2526091
Add Javadoc to HeadlineContainer
ic0ns Jun 18, 2025
8679d0b
Add Javadoc to KeyValueContainer
ic0ns Jun 18, 2025
38c1db6
Add Javadoc to ListContainer
ic0ns Jun 18, 2025
91d4014
Add Javadoc to ReportContainer
ic0ns Jun 18, 2025
9137cb0
Add Javadoc to TableContainer
ic0ns Jun 18, 2025
2e14abf
Add Javadoc to TextContainer
ic0ns Jun 18, 2025
660de1f
Add Javadoc to PropertyResultRatingInfluencer
ic0ns Jun 18, 2025
c975088
Add Javadoc to PropertyResultRecommendation
ic0ns Jun 18, 2025
f90fd19
Add Javadoc to RatingInfluencer
ic0ns Jun 18, 2025
828d576
Add Javadoc to RatingInfluencers
ic0ns Jun 18, 2025
9fc0bce
Add Javadoc to RatingInfluencersIO
ic0ns Jun 18, 2025
a6d526e
Add Javadoc to Recommendation
ic0ns Jun 18, 2025
95d5494
Add Javadoc to Recommendations
ic0ns Jun 18, 2025
9fabbfe
Add Javadoc to RecommendationsIO
ic0ns Jun 18, 2025
1aba575
Add Javadoc to ScoreReport
ic0ns Jun 18, 2025
3d93931
Add Javadoc to SiteReportRater
ic0ns Jun 18, 2025
187e643
formatted
ic0ns Jun 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,30 @@
import de.rub.nds.scanner.core.probe.AnalyzedProperty;
import java.util.HashMap;

/**
* An encoder that converts AnalyzedProperty instances to their text representation. Uses a provided
* mapping to translate properties to custom strings.
*/
public class AnalyzedPropertyTextEncoder extends Encoder<AnalyzedProperty> {

private final HashMap<AnalyzedProperty, String> map;

/**
* Creates a new AnalyzedPropertyTextEncoder with the specified property-to-text mapping.
*
* @param map a HashMap mapping AnalyzedProperty instances to their string representations
*/
public AnalyzedPropertyTextEncoder(HashMap<AnalyzedProperty, String> map) {
this.map = map;
}

/**
* Encodes an AnalyzedProperty to its string representation. If a mapping exists, returns the
* mapped value; otherwise returns the property's name.
*
* @param analyzedProperty the property to encode
* @return the string representation of the property
*/
@Override
public String encode(AnalyzedProperty analyzedProperty) {
if (map == null) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/de/rub/nds/scanner/core/report/AnsiColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import java.util.HashMap;
import java.util.Map;

/**
* Enum representing ANSI color codes for terminal output. Provides foreground colors, background
* colors, and text formatting options.
*/
public enum AnsiColor {
RESET("\u001B[0m"),
BLACK("\u001B[30m"),
Expand Down Expand Up @@ -48,10 +52,21 @@ public enum AnsiColor {
}
}

/**
* Returns the AnsiColor corresponding to the given ANSI code string.
*
* @param code the ANSI code string
* @return the corresponding AnsiColor, or null if no match is found
*/
public static AnsiColor getAnsiColor(String code) {
return MAP.get(code);
}

/**
* Returns the ANSI code string for this color.
*
* @return the ANSI code string
*/
public String getCode() {
return code;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
*/
package de.rub.nds.scanner.core.report;

/**
* Utility class containing ANSI escape sequences for terminal manipulation. Provides constants for
* cursor movement and line manipulation.
*/
public class AnsiEscapeSequence {

/** ANSI escape sequence to move cursor up one line */
public static final String ANSI_ONE_LINE_UP = "\033[1A";

/** ANSI escape sequence to erase the current line */
public static final String ANSI_ERASE_LINE = "\033[2K";
}
23 changes: 23 additions & 0 deletions src/main/java/de/rub/nds/scanner/core/report/ColorEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,41 @@
import de.rub.nds.scanner.core.probe.result.TestResult;
import java.util.HashMap;

/**
* Handles color encoding for test results in terminal output. Maps test results to ANSI colors for
* visual differentiation.
*/
public class ColorEncoding {

private final HashMap<TestResult, AnsiColor> colorMap;

/**
* Creates a new ColorEncoding with the specified result-to-color mapping.
*
* @param colorMap a HashMap mapping TestResult instances to AnsiColor codes
*/
public ColorEncoding(HashMap<TestResult, AnsiColor> colorMap) {
this.colorMap = colorMap;
}

/**
* Returns the AnsiColor associated with a given test result.
*
* @param result the test result
* @return the associated AnsiColor, or null if no mapping exists
*/
public AnsiColor getColor(TestResult result) {
return colorMap.get(result);
}

/**
* Encodes the given text with the color associated with the test result. If a color mapping
* exists and is not DEFAULT_COLOR, wraps the text with appropriate ANSI codes.
*
* @param result the test result determining the color
* @param encodedText the text to be colored
* @return the color-encoded text string
*/
public String encode(TestResult result, String encodedText) {
AnsiColor color = this.getColor(result);
if (color != null && color != AnsiColor.DEFAULT_COLOR) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/de/rub/nds/scanner/core/report/Encoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@
*/
package de.rub.nds.scanner.core.report;

/**
* Abstract base class for encoding objects to their string representation.
*
* @param <T> the type of objects this encoder can encode
*/
public abstract class Encoder<T> {

/**
* Encodes the given object to its string representation.
*
* @param t the object to encode
* @return the string representation of the object
*/
public abstract String encode(T t);
}
41 changes: 41 additions & 0 deletions src/main/java/de/rub/nds/scanner/core/report/PerformanceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

import de.rub.nds.scanner.core.probe.ProbeType;

/**
* Container for performance data of a single probe execution. Tracks timing information for
* performance analysis.
*/
public class PerformanceData {

private ProbeType type;
Expand All @@ -24,32 +28,69 @@ private PerformanceData() {
this.stopTime = 0;
}

/**
* Creates a new PerformanceData instance with the specified parameters.
*
* @param type the type of probe
* @param startTime the start time in milliseconds
* @param stopTime the stop time in milliseconds
*/
public PerformanceData(ProbeType type, long startTime, long stopTime) {
this.type = type;
this.startTime = startTime;
this.stopTime = stopTime;
}

/**
* Returns the probe type.
*
* @return the probe type
*/
public ProbeType getType() {
return type;
}

/**
* Sets the probe type.
*
* @param type the probe type to set
*/
public void setType(ProbeType type) {
this.type = type;
}

/**
* Returns the start time in milliseconds.
*
* @return the start time
*/
public long getStartTime() {
return startTime;
}

/**
* Sets the start time in milliseconds.
*
* @param startTime the start time to set
*/
public void setStartTime(long startTime) {
this.startTime = startTime;
}

/**
* Returns the stop time in milliseconds.
*
* @return the stop time
*/
public long getStopTime() {
return stopTime;
}

/**
* Sets the stop time in milliseconds.
*
* @param stopTime the stop time to set
*/
public void setStopTime(long stopTime) {
this.stopTime = stopTime;
}
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/de/rub/nds/scanner/core/report/PrintingScheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
import de.rub.nds.scanner.core.probe.result.TestResult;
import java.util.HashMap;

/**
* Defines the visual presentation scheme for scan report results, including text encoding and color
* encoding configurations for different property types and categories.
*/
public class PrintingScheme {

private HashMap<AnalyzedProperty, ColorEncoding> valueColorEncodings;
Expand All @@ -27,8 +31,19 @@ public class PrintingScheme {

private ColorEncoding defaultColorEncoding;

/** Constructs a new PrintingScheme with default settings. */
public PrintingScheme() {}

/**
* Constructs a new PrintingScheme with specified encoding configurations.
*
* @param colorEncodings property-specific color encodings
* @param textEncodings category-specific text encodings
* @param defaultTextEncoding default text encoder for values without specific encodings
* @param defaultColorEncoding default color encoder for values without specific encodings
* @param specialTextEncoding property-specific text encodings that override category encodings
* @param keyTextEncoding encoders for property keys/names
*/
public PrintingScheme(
HashMap<AnalyzedProperty, ColorEncoding> colorEncodings,
HashMap<AnalyzedPropertyCategory, TestResultTextEncoder> textEncodings,
Expand All @@ -44,14 +59,32 @@ public PrintingScheme(
this.keyTextEncoding = keyTextEncoding;
}

/**
* Returns the map of property-specific color encodings.
*
* @return map of color encodings for specific properties
*/
public HashMap<AnalyzedProperty, ColorEncoding> getValueColorEncodings() {
return valueColorEncodings;
}

/**
* Returns the map of category-specific text encodings.
*
* @return map of text encodings for property categories
*/
public HashMap<AnalyzedPropertyCategory, TestResultTextEncoder> getValueTextEncodings() {
return valueTextEncodings;
}

/**
* Encodes the result value for a property as a string with optional color formatting.
*
* @param report the scan report containing the result
* @param property the property whose result should be encoded
* @param useColors whether to apply color encoding to the result
* @return the encoded string representation of the result
*/
public String getEncodedString(
ScanReport report, AnalyzedProperty property, boolean useColors) {
TestResult result = report.getResult(property);
Expand All @@ -70,6 +103,13 @@ public String getEncodedString(
}
}

/**
* Encodes the result value for a property as plain text without color formatting.
*
* @param report the scan report containing the result
* @param property the property whose result should be encoded
* @return the plain text representation of the result
*/
public String getEncodedValueText(ScanReport report, AnalyzedProperty property) {
TestResult result = report.getResult(property);
TestResultTextEncoder textEncoding = specialValueTextEncoding.get(property);
Expand All @@ -80,20 +120,42 @@ public String getEncodedValueText(ScanReport report, AnalyzedProperty property)
return textEncoding.encode(result);
}

/**
* Encodes the property key/name as text.
*
* @param report the scan report (currently unused but kept for API consistency)
* @param property the property whose key should be encoded
* @return the encoded text representation of the property key
*/
public String getEncodedKeyText(ScanReport report, AnalyzedProperty property) {
Encoder<AnalyzedProperty> textEncoding =
keyTextEncoding.getOrDefault(property, new AnalyzedPropertyTextEncoder(null));

return textEncoding.encode(property);
}

/**
* Determines the appropriate color for displaying a property's result value.
*
* @param report the scan report containing the result
* @param property the property whose result color should be determined
* @return the ANSI color to use for the result value
*/
public AnsiColor getValueColor(ScanReport report, AnalyzedProperty property) {
TestResult result = report.getResult(property);
ColorEncoding colorEncoding =
valueColorEncodings.getOrDefault(property, defaultColorEncoding);
return colorEncoding.getColor(result);
}

/**
* Determines the color for displaying a property key. Currently always returns the default
* color.
*
* @param report the scan report (currently unused)
* @param property the property (currently unused)
* @return the default ANSI color
*/
public AnsiColor getKeyColor(ScanReport report, AnalyzedProperty property) {
return AnsiColor.DEFAULT_COLOR;
}
Expand Down
Loading