Package eu.maveniverse.domtrip
Enum QuoteStyle
- java.lang.Object
-
- java.lang.Enum<QuoteStyle>
-
- eu.maveniverse.domtrip.QuoteStyle
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<QuoteStyle>
public enum QuoteStyle extends java.lang.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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description charcharacter()Gets the quote character for this style.static QuoteStylefromChar(char c)Returns the QuoteStyle corresponding to the given character.chargetCharacter()Deprecated.Usecharacter()instead.java.lang.StringtoString()Returns the quote character as a string.static QuoteStylevalueOf(java.lang.String name)Returns the enum constant of this type with the specified name.static QuoteStyle[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
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 Detail
-
values
public static QuoteStyle[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (QuoteStyle c : QuoteStyle.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static QuoteStyle valueOf(java.lang.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:
java.lang.IllegalArgumentException- if this enum type has no constant with the specified namejava.lang.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.Usecharacter()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 java.lang.String toString()
Returns the quote character as a string.- Overrides:
toStringin classjava.lang.Enum<QuoteStyle>- Returns:
- the quote character as a single-character string
-
-