Package com.helger.css.writer
Class CSSWriter
java.lang.Object
com.helger.css.writer.CSSWriter
Convert CSS domain objects back to a text representation.
- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanBy default optimized output is disabled -
Constructor Summary
ConstructorsConstructorDescriptionConstructor 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
Modifier and TypeMethodDescriptionCreate the CSS without a specific charset.getCSSAsString(ICSSWriteable aCSS) Get the string representation of the passed CSS object.booleanCheck if the footer text should be emitted.booleanCheck if the header text should be emitted.setContentCharset(String sContentCharset) Define the content charset to be used.setFooterText(String sFooterText) Set a custom footer text that should be emitted.setHeaderText(String sHeaderText) Set a custom header text that should be emitted.setWriteFooterText(boolean bWriteFooterText) Determine whether the file footer should be written or not.setWriteHeaderText(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 Details
-
DEFAULT_OPTIMIZED_OUTPUT
public static final boolean DEFAULT_OPTIMIZED_OUTPUTBy default optimized output is disabled- See Also:
-
-
Constructor Details
-
CSSWriter
public CSSWriter()Constructor for creating non-optimized output. -
CSSWriter
Constructor for creating non-optimized output.- Parameters:
eVersion- The CSS version to emit the code for. May not benull.
-
CSSWriter
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
Constructor- Parameters:
aSettings- The settings to be used. May not benull.
-
-
Method Details
-
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
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
- Returns:
- The currently defined header text. May be
null.
-
setHeaderText
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
-
getContentCharset
- Returns:
- The current defined content charset for the CSS. By default it is
null.
-
setContentCharset
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
- 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
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
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
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:
-