Enum QuoteStyle

java.lang.Object
java.lang.Enum<QuoteStyle>
eu.maveniverse.domtrip.QuoteStyle
All Implemented Interfaces:
Serializable, Comparable<QuoteStyle>, java.lang.constant.Constable

public enum QuoteStyle extends Enum<QuoteStyle>
Enumeration for XML attribute quote styles, supporting both single and double quotes.

XML attributes can be quoted with either single quotes (') or double quotes ("). DomTrip preserves the original quote style during round-trip processing and allows explicit control over quote style when creating new attributes.

Quote Style Preservation:

When parsing XML, DomTrip automatically detects and preserves the original quote style for each attribute. This ensures that the serialized XML maintains the exact same formatting as the input.

Usage Examples:

// Set attribute with specific quote style
element.attribute("class", "important", QuoteStyle.SINGLE);
// Results in: class='important'

element.attribute("id", "main", QuoteStyle.DOUBLE);
// Results in: id="main"

// Get quote style from character
QuoteStyle style = QuoteStyle.fromChar('"');  // DOUBLE
QuoteStyle style2 = QuoteStyle.fromChar('\''); // SINGLE

// Use in configuration
DomTripConfig config = DomTripConfig.defaults()
    .withQuoteStyle(QuoteStyle.SINGLE);

XML Specification Compliance:

Both quote styles are valid according to the XML specification. The choice between them is often a matter of style preference or necessity when the attribute value contains one type of quote character.

See Also:
  • Enum Constant Details

    • DOUBLE

      public static final QuoteStyle DOUBLE
      Double quote character (") for attribute values
    • SINGLE

      public static final QuoteStyle SINGLE
      Single quote character (') for attribute values
  • Method Details

    • values

      public static QuoteStyle[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static QuoteStyle valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • character

      public char character()
      Gets the quote character for this style.
      Returns:
      the quote character (either '"' or '\'')
    • getCharacter

      @Deprecated public char getCharacter()
      Deprecated.
      Use character() instead.
      Gets the quote character for this style.
      Returns:
      the quote character
    • fromChar

      public static QuoteStyle fromChar(char c) throws DomTripException
      Returns the QuoteStyle corresponding to the given character.

      This method is useful when parsing XML attributes to determine the original quote style used.

      Parameters:
      c - the quote character to convert
      Returns:
      the corresponding QuoteStyle
      Throws:
      DomTripException - if the character is not a valid quote character
    • toString

      public String toString()
      Returns the quote character as a string.
      Overrides:
      toString in class Enum<QuoteStyle>
      Returns:
      the quote character as a single-character string