Class ThreatCSVWriter
java.lang.Object
java.io.Writer
be.kuleuven.cs.distrinet.sparta.io.ThreatWriter
be.kuleuven.cs.distrinet.sparta.io.ThreatCSVWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
A
ThreatWriter to export one or more threats to a csv file. This
writer does not automatically write a CSV header. If this is needed it can be
manually written out using Writer.write(String) or
writeHeader().-
Field Summary
Fields inherited from class be.kuleuven.cs.distrinet.sparta.io.ThreatWriter
writer -
Constructor Summary
ConstructorsConstructorDescriptionThreatCSVWriter(Writer writer) Create a newThreatCSVWriterto provided support for writing out a default set of threat properties to text-based files.Create a newThreatCSVWriterto provided support for writing out a specified set of threat properties to text-based files. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringescapeField(String arg) Escape a single CSV field: wrap it in double quotes and double any embedded double quote, per RFC 4180, so that values containing a quote or the;delimiter do not break the CSV structure.static StringescapeFieldValue(String arg) Escape a single CSV data field: applies the RFC 4180 quoting ofescapeField(String)plus the OWASP CSV-injection mitigation - a value starting with=,+,-,@, tab or carriage return is prefixed with a single quote'so a spreadsheet application treats it as text instead of executing it as a formula.voidWrite-out a threatvoidWrite a csv header based on the provided set of property names inThreatCSVWriter(Writer, Map)Methods inherited from class be.kuleuven.cs.distrinet.sparta.io.ThreatWriter
close, flush, getProperties, newLine, write, write
-
Constructor Details
-
ThreatCSVWriter
Create a newThreatCSVWriterto provided support for writing out a default set of threat properties to text-based files.- Parameters:
writer- a writer
-
ThreatCSVWriter
Create a newThreatCSVWriterto provided support for writing out a specified set of threat properties to text-based files. If any of the provided functions return aModelElement, theThreatWriterwill attempt to retrieve the name of the element when writing it to the output writer.- Parameters:
writer- a writerproperties- a set of functions, which applied to a threat provide the property to write out
-
-
Method Details
-
write
Write-out a threat- Specified by:
writein classThreatWriter- Parameters:
threat- theThreatto write out- Throws:
IOException- If an I/O error occurs.
-
escapeField
Escape a single CSV field: wrap it in double quotes and double any embedded double quote, per RFC 4180, so that values containing a quote or the;delimiter do not break the CSV structure.- Parameters:
arg- the raw field value (may benull, treated as empty).- Returns:
- the quoted and escaped field.
-
escapeFieldValue
Escape a single CSV data field: applies the RFC 4180 quoting ofescapeField(String)plus the OWASP CSV-injection mitigation - a value starting with=,+,-,@, tab or carriage return is prefixed with a single quote'so a spreadsheet application treats it as text instead of executing it as a formula.The guard is deliberately applied uniformly: a negative-looking value such as
-5also becomes'-5, because-is a formula trigger (-5+cmd|...attacks) and safety takes precedence. This does not affect the default numeric columns in practice: risks and vulnerabilities are non-negative, pre-formatted strings. Headers, whose names the exporter controls, are escaped withescapeField(String)only.- Parameters:
arg- the raw field value (may benull, treated as empty).- Returns:
- the quoted, escaped and formula-guarded field.
-
writeHeader
Write a csv header based on the provided set of property names inThreatCSVWriter(Writer, Map)- Throws:
IOException- If an I/O error occurs
-