Package com.helger.css.writer
Class CSSWriter
- java.lang.Object
-
- com.helger.css.writer.CSSWriter
-
@NotThreadSafe public class CSSWriter extends Object
Convert CSS domain objects back to a text representation.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_OPTIMIZED_OUTPUTBy default optimized output is disabled
-
Constructor Summary
Constructors Constructor Description CSSWriter()Constructor for creating non-optimized output.CSSWriter(ECSSVersion eVersion)Constructor for creating non-optimized output.CSSWriter(ECSSVersion eVersion, boolean bOptimizedOutput)Constructor.CSSWriter(CSSWriterSettings aSettings)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetContentCharset()StringgetCSSAsString(CascadingStyleSheet aCSS)Create the CSS without a specific charset.StringgetCSSAsString(ICSSWriteable aCSS)Get the string representation of the passed CSS object.StringgetFooterText()StringgetHeaderText()CSSWriterSettingsgetSettings()booleanisWriteFooterText()Check if the footer text should be emitted.booleanisWriteHeaderText()Check if the header text should be emitted.CSSWritersetContentCharset(String sContentCharset)Define the content charset to be used.CSSWritersetFooterText(String sFooterText)Set a custom footer text that should be emitted.CSSWritersetHeaderText(String sHeaderText)Set a custom header text that should be emitted.CSSWritersetWriteFooterText(boolean bWriteFooterText)Determine whether the file footer should be written or not.CSSWritersetWriteHeaderText(boolean bWriteHeaderText)Determine whether the file header should be written or not.voidwriteCSS(CascadingStyleSheet aCSS, Writer aWriter)Write the CSS content to the passed writer.voidwriteCSS(ICSSWriteable aCSS, Writer aWriter)Write the CSS content to the passed writer.
-
-
-
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 benull.
-
CSSWriter
public CSSWriter(@Nonnull ECSSVersion eVersion, boolean bOptimizedOutput)
Constructor.- Parameters:
eVersion- The CSS version to emit the code for. May not benull.bOptimizedOutput- Iftruethe 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 benull.
-
-
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:
trueif the header text should be emitted,falseif 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- Iftruethe header text will be written, iffalsethe 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 ifisWriteHeaderText()returnstrue.- Parameters:
sHeaderText- The header text to be emitted. May benull.- 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:
trueif the footer text should be emitted,falseif 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- Iftruethe footer text will be written, iffalsethe 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 ifisWriteFooterText()returnstrue.- Parameters:
sFooterText- The footer text to be emitted. May benull.- 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 notnulland not empty, the@charsetelement 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 benullto 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.
-
writeCSS
public void writeCSS(@Nonnull CascadingStyleSheet aCSS, @Nonnull @WillClose Writer aWriter) throws IOException
Write the CSS content to the passed writer. No specific charset is used.- Parameters:
aCSS- The CSS to write. May not benull.aWriter- The write to write the text to. May not benull. Is automatically closed after the writing!- Throws:
IOException- In case writing fails.IllegalStateException- In case some elements cannot be written in the version supplied in the constructor.- See Also:
getCSSAsString(CascadingStyleSheet)
-
getCSSAsString
@Nonnull public String getCSSAsString(@Nonnull CascadingStyleSheet aCSS)
Create the CSS without a specific charset.- Parameters:
aCSS- The CSS object to be converted to text. May not benull.- Returns:
- The text representation of the CSS.
- See Also:
writeCSS(CascadingStyleSheet, Writer)
-
writeCSS
public void writeCSS(@Nonnull ICSSWriteable aCSS, @Nonnull @WillClose Writer aWriter) throws IOException
Write the CSS content to the passed writer. No specific charset is used.- Parameters:
aCSS- The CSS to write. May not benull.aWriter- The write to write the text to. May not benull. Is automatically closed after the writing!- Throws:
IOException- In case writing fails.IllegalStateException- In case some elements cannot be written in the version supplied in the constructor.- See Also:
getCSSAsString(ICSSWriteable)
-
getCSSAsString
@Nonnull public String getCSSAsString(@Nonnull ICSSWriteable aCSS)
Get the string representation of the passed CSS object. It can be any object that implementsICSSWriteable.- Parameters:
aCSS- The CSS object to be converted to text. May not benull.- Returns:
- The text representation of the CSS.
- See Also:
writeCSS(ICSSWriteable, Writer)
-
-