Class Directive

java.lang.Object
org.htmlunit.csp.Directive
Direct Known Subclasses:
HostSourceDirective, PluginTypesDirective, ReportUriDirective, RequireTrustedTypesForDirective, SandboxDirective, TrustedTypesDirective

public class Directive extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static interface 
    A callback interface for receiving errors and warnings encountered while parsing a single directive's values.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Predicate<String>
    Predicate that tests whether a string is a valid directive name (ALPHA / DIGIT / "-").
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructs a directive with the given list of values.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Appends a value to this directive's value list.
    static boolean
    Tests if a string contains any non-directive characters.
    Returns an unmodifiable view of this directive's raw string values.
    protected void
    Removes all occurrences of a value from this directive (case-insensitive comparison).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • IS_DIRECTIVE_NAME

      public static final Predicate<String> IS_DIRECTIVE_NAME
      Predicate that tests whether a string is a valid directive name (ALPHA / DIGIT / "-").
  • Constructor Details

    • Directive

      protected Directive(List<String> values)
      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

      public static boolean containsNonDirectiveCharacter(String input)
      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

      protected void addValue(String value)
      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

      public List<String> getValues()
      Returns an unmodifiable view of this directive's raw string values.
      Returns:
      the list of values for this directive
    • removeValueIgnoreCase

      protected void removeValueIgnoreCase(String value)
      Removes all occurrences of a value from this directive (case-insensitive comparison).
      Parameters:
      value - the value to remove (compared case-insensitively)