Class CSSWriter


  • @NotThreadSafe
    public class CSSWriter
    extends Object
    Convert CSS domain objects back to a text representation.
    Author:
    Philip Helger
    • Field Detail

      • DEFAULT_OPTIMIZED_OUTPUT

        public static final boolean DEFAULT_OPTIMIZED_OUTPUT
        By default optimized output is disabled
        See Also:
        Constant Field Values
    • Constructor Detail

      • CSSWriter

        public CSSWriter()
        Constructor for creating non-optimized output.
      • CSSWriter

        public CSSWriter​(@Nonnull
                         ECSSVersion eVersion)
        Constructor for creating non-optimized output.
        Parameters:
        eVersion - The CSS version to emit the code for. May not be null .
      • CSSWriter

        public CSSWriter​(@Nonnull
                         ECSSVersion eVersion,
                         boolean bOptimizedOutput)
        Constructor.
        Parameters:
        eVersion - The CSS version to emit the code for. May not be null .
        bOptimizedOutput - If true the number of bytes emitted by this writer is minimized. Also style rules having no declarations are omitted.
      • CSSWriter

        public CSSWriter​(@Nonnull
                         CSSWriterSettings aSettings)
        Constructor
        Parameters:
        aSettings - The settings to be used. May not be null.
    • Method Detail

      • isWriteHeaderText

        public boolean isWriteHeaderText()
        Check if the header text should be emitted. By default it is enabled, if non-optimized output is desired.
        Returns:
        true if the header text should be emitted, false if not.
      • setWriteHeaderText

        @Nonnull
        public CSSWriter setWriteHeaderText​(boolean bWriteHeaderText)
        Determine whether the file header should be written or not. By default it is enabled, if non-optimized output is desired.
        Parameters:
        bWriteHeaderText - If true the header text will be written, if false the text will not be written.
        Returns:
        this
      • getHeaderText

        @Nullable
        public String getHeaderText()
        Returns:
        The currently defined header text. May be null.
      • setHeaderText

        @Nonnull
        public CSSWriter setHeaderText​(@Nullable
                                       String sHeaderText)
        Set a custom header text that should be emitted. This text may be multi line separated by the '\n' character. It will emitted if isWriteHeaderText() returns true.
        Parameters:
        sHeaderText - The header text to be emitted. May be null.
        Returns:
        this
      • isWriteFooterText

        public boolean isWriteFooterText()
        Check if the footer text should be emitted. By default it is enabled, if non-optimized output is desired.
        Returns:
        true if the footer text should be emitted, false if not.
      • setWriteFooterText

        @Nonnull
        public CSSWriter setWriteFooterText​(boolean bWriteFooterText)
        Determine whether the file footer should be written or not. By default it is enabled, if non-optimized output is desired.
        Parameters:
        bWriteFooterText - If true the footer text will be written, if false the text will not be written.
        Returns:
        this
      • getFooterText

        @Nullable
        public String getFooterText()
        Returns:
        The currently defined footer text. May be null.
      • setFooterText

        @Nonnull
        public CSSWriter setFooterText​(@Nullable
                                       String sFooterText)
        Set a custom footer text that should be emitted. This text may be multi line separated by the '\n' character. It will emitted if isWriteFooterText() returns true.
        Parameters:
        sFooterText - The footer text to be emitted. May be null.
        Returns:
        this
      • getContentCharset

        @Nullable
        public String getContentCharset()
        Returns:
        The current defined content charset for the CSS. By default it is null.
      • setContentCharset

        @Nonnull
        public CSSWriter setContentCharset​(@Nullable
                                           String sContentCharset)
        Define the content charset to be used. If not null and not empty, the @charset element is emitted into the CSS. By default no charset is defined.
        Important: this does not define the encoding of the output - it is just a declarative marker inside the code. Best practice is to use the same encoding for the CSS and the respective writer!
        Parameters:
        sContentCharset - The content charset to be used. May be null to indicate that no special charset name should be emitted into the CSS.
        Returns:
        this
      • getSettings

        @Nonnull
        @ReturnsMutableObject("Design")
        public CSSWriterSettings getSettings()
        Returns:
        The CSS writer settings that are used to generate the different element code. This is the same object as passed into/created by the constructor. Never null.