Enum LineSeparator

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<LineSeparator>

    public enum LineSeparator
    extends java.lang.Enum<LineSeparator>
    An enumeration of common separators that are used for JDOM output.

    These enumerated values can be used as input to the Format.setLineSeparator(LineSeparator) method. Additionally, the names of these constants can be also be used in the System Property JDOMConstants.JDOM2_PROPERTY_LINE_SEPARATOR which is used to define the default Line Separator sequence for JDOM output. See DEFAULT Javadoc.

    JDOM has historically used the CR/NL sequence '\r\n' as a line-terminator. This sequence has the advantage that the output is easily opened in the 'Notepad' editor on Windows. Other editors on other platforms are typically smart enough to automatically adjust to whatever termination sequence is used in the document. The XML specification requires that the CR/NL sequence should be 'normalized' to a single newline '\n' when the document is parsed (XML 1.1 End-Of-Line Handling). As a result there is no XML issue with the JDOM default CR/NL end-of-line sequence.

    It should be noted that because JDOM internally stores just a '\n' as a line separator that any other output separator requires additional processing to output. There is a distinct performance benefit for using the UNIX, or NL LineSeparator for output.

    JDOM has always allowed the line-terminating sequence to be customised (or even disabled) for each XMLOutputter operation by using this Format class.

    JDOM2 introduces two new features in relation to the end-of-line sequence. Firstly, it introduces this new LineSeparator enumeration which formalises the common line separators that can be used. In addition to the simple String-based Format.setLineSeparator(String) method you can now also call Format.setLineSeparator(LineSeparator) with one of the common enumerations.

    The second new JDOM2 feature is the ability to set a global default end-of-line sequence. JDOM 1.x forced the default sequence to be the CRLF sequence, but JDOM2 allows you to set the system property JDOMConstants.JDOM2_PROPERTY_LINE_SEPARATOR which will be used as the default sequence for Format. You can set the property to be the name of one of these LineSeparator enumerations too. For example, the following will cause all default Format instances to use the System-dependent end-of-line sequence instead of always CRLF:

     java -Dorg.jdom2.output.LineSeparator=SYSTEM ...
     
    Since:
    JDOM2
    Author:
    Rolf Lear
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      CR
      The Separator sequence CR which is '\r'.
      CRNL
      The Separator sequence CRNL which is '\r\n'.
      DEFAULT
      Use the sequence '\r\n' unless the System property JDOMConstants.JDOM2_PROPERTY_LINE_SEPARATOR is defined, in which case use the value specified in that property.
      DOS
      The 'DOS' Separator sequence CRLF (CRNL) which is '\r\n'.
      NL
      The Separator sequence NL which is '\n'.
      NONE
      Perform no end-of-line processing.
      SYSTEM
      The system-dependent Separator sequence NL which is obtained from System.getProperty("line.separator").
      UNIX
      The 'UNIX' Separator sequence NL which is '\n'.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String value()
      The String sequence used for this Separator
      static LineSeparator valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static LineSeparator[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • CRNL

        public static final LineSeparator CRNL
        The Separator sequence CRNL which is '\r\n'. This is the default sequence.
      • NL

        public static final LineSeparator NL
        The Separator sequence NL which is '\n'.
      • CR

        public static final LineSeparator CR
        The Separator sequence CR which is '\r'.
      • DOS

        public static final LineSeparator DOS
        The 'DOS' Separator sequence CRLF (CRNL) which is '\r\n'.
      • UNIX

        public static final LineSeparator UNIX
        The 'UNIX' Separator sequence NL which is '\n'.
      • SYSTEM

        public static final LineSeparator SYSTEM
        The system-dependent Separator sequence NL which is obtained from System.getProperty("line.separator"). This should be the equivalent of DOS on windows platforms, and of UNIX on UNIX and Apple systems (after Mac OSX).
      • NONE

        public static final LineSeparator NONE
        Perform no end-of-line processing.
      • DEFAULT

        public static final LineSeparator DEFAULT
        Use the sequence '\r\n' unless the System property JDOMConstants.JDOM2_PROPERTY_LINE_SEPARATOR is defined, in which case use the value specified in that property. If the value in that property matches one of the Enumeration names (e.g. SYSTEM) then use the sequence specified in that enumeration.
    • Method Detail

      • values

        public static LineSeparator[] 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 (LineSeparator c : LineSeparator.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static LineSeparator 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 name
        java.lang.NullPointerException - if the argument is null
      • value

        public java.lang.String value()
        The String sequence used for this Separator
        Returns:
        an End-Of-Line String