java.lang.Object
org.htmlunit.csp.Directive
- Direct Known Subclasses:
HostSourceDirective,PluginTypesDirective,ReportUriDirective,RequireTrustedTypesForDirective,SandboxDirective,TrustedTypesDirective
Base class for all CSP directive representations.
A Directive holds the list of raw string values that were parsed for a
single directive in a Content Security Policy. Subclasses interpret those
values into structured data (source expressions, sandbox keywords, etc.).
- Author:
- Salvation Team
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA callback interface for receiving errors and warnings encountered while parsing a single directive's values. -
Field Summary
FieldsModifier and TypeFieldDescriptionPredicate that tests whether a string is a valid directive name (ALPHA / DIGIT / "-"). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAppends a value to this directive's value list.static booleanTests if a string contains any non-directive characters.Returns an unmodifiable view of this directive's raw string values.protected voidremoveValueIgnoreCase(String value) Removes all occurrences of a value from this directive (case-insensitive comparison).
-
Field Details
-
IS_DIRECTIVE_NAME
Predicate that tests whether a string is a valid directive name (ALPHA / DIGIT / "-").
-
-
Constructor Details
-
Directive
Constructs a directive with the given list of values.Each value is validated through
addValue(String)during construction.- Parameters:
values- the raw string values for this directive- Throws:
IllegalArgumentException- if any value is empty, non-ASCII, or contains whitespace / comma / semicolon
-
-
Method Details
-
containsNonDirectiveCharacter
Tests if a string contains any non-directive characters. Non-directive characters are: ASCII whitespace (tab, newline, form feed, carriage return, space), comma, or semicolon.- Parameters:
input- the string to test (can be null)- Returns:
- true if the string contains any non-directive characters, false otherwise
-
addValue
Appends a value to this directive's value list.The value must be a non-empty ASCII string that does not contain whitespace, commas, or semicolons.
- Parameters:
value- the value to add- Throws:
IllegalArgumentException- if the value is empty, non-ASCII, or contains whitespace / comma / semicolon
-
getValues
Returns an unmodifiable view of this directive's raw string values.- Returns:
- the list of values for this directive
-
removeValueIgnoreCase
Removes all occurrences of a value from this directive (case-insensitive comparison).- Parameters:
value- the value to remove (compared case-insensitively)
-