Package com.helger.css.reader
Class CSSReader
- java.lang.Object
-
- com.helger.css.reader.CSSReader
-
@ThreadSafe public final class CSSReader extends Object
This is the central user class for reading and parsing CSS from different sources. This class reads full CSS declarations only. To read only a declaration list (like from an HTML<style>
attribute) theCSSReaderDeclarationList
is available.- Author:
- Philip Helger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Charset
getCharsetDeclaredInCSS(com.helger.commons.io.IHasInputStream aISP)
Determine the charset to read the CSS file.static ICSSInterpretErrorHandler
getDefaultInterpretErrorHandler()
static ICSSParseErrorHandler
getDefaultParseErrorHandler()
static ICSSParseExceptionCallback
getDefaultParseExceptionHandler()
static boolean
isValidCSS(com.helger.commons.io.resource.IReadableResource aRes, Charset aFallbackCharset, ECSSVersion eVersion)
Check if the passed CSS resource can be parsed without errorstatic boolean
isValidCSS(File aFile, Charset aFallbackCharset, ECSSVersion eVersion)
Check if the passed CSS file can be parsed without errorstatic boolean
isValidCSS(InputStream aIS, Charset aFallbackCharset, ECSSVersion eVersion)
Check if the passed input stream can be resembled to valid CSS content.static boolean
isValidCSS(Reader aReader, ECSSVersion eVersion)
Check if the passed reader can be resembled to valid CSS content.static boolean
isValidCSS(String sCSS, ECSSVersion eVersion)
Check if the passed String can be resembled to valid CSS content.static CascadingStyleSheet
readFromFile(File aFile, CSSReaderSettings aSettings)
Read the CSS from the passed File.static CascadingStyleSheet
readFromFile(File aFile, Charset aFallbackCharset, ECSSVersion eVersion)
Read the CSS from the passed File.static CascadingStyleSheet
readFromFile(File aFile, Charset aFallbackCharset, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed File.static CascadingStyleSheet
readFromFile(File aFile, Charset aFallbackCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passed File.static CascadingStyleSheet
readFromFile(File aFile, Charset aFallbackCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed File.static CascadingStyleSheet
readFromReader(com.helger.commons.io.IHasReader aRP, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedIHasReader
.static CascadingStyleSheet
readFromReader(com.helger.commons.io.IHasReader aRP, CSSReaderSettings aSettings)
Read the CSS from the passedIHasReader
.static CascadingStyleSheet
readFromStream(com.helger.commons.io.IHasInputStream aISP, CSSReaderSettings aSettings)
Read the CSS from the passedIHasInputStream
.static CascadingStyleSheet
readFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aFallbackCharset, ECSSVersion eVersion)
Read the CSS from the passedIHasInputStream
.static CascadingStyleSheet
readFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aFallbackCharset, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedIHasInputStream
.static CascadingStyleSheet
readFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aFallbackCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passedIHasInputStream
.static CascadingStyleSheet
readFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aFallbackCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedIHasInputStream
.static CascadingStyleSheet
readFromString(String sCSS, ECSSVersion eVersion)
Read the CSS from the passed String using a character stream.static CascadingStyleSheet
readFromString(String sCSS, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed String using a character stream.static CascadingStyleSheet
readFromString(String sCSS, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passed String using a character stream.static CascadingStyleSheet
readFromString(String sCSS, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed String using a character stream.static CascadingStyleSheet
readFromString(String sCSS, Charset aFallbackCharset, ECSSVersion eVersion)
Read the CSS from the passed String using a byte stream.static CascadingStyleSheet
readFromString(String sCSS, Charset aFallbackCharset, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed String using a byte stream.static CascadingStyleSheet
readFromString(String sCSS, Charset aFallbackCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passed String using a byte stream.static CascadingStyleSheet
readFromString(String sCSS, Charset aFallbackCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed String using a byte stream.static CascadingStyleSheet
readFromStringReader(String sCSS, CSSReaderSettings aSettings)
Read the CSS from the passed String using a character stream.static CascadingStyleSheet
readFromStringStream(String sCSS, CSSReaderSettings aSettings)
Read the CSS from the passed String using a byte stream.static void
setDefaultInterpretErrorHandler(ICSSInterpretErrorHandler aDefaultErrorHandler)
Set the default interpret error handler to handle interpretation errors in successfully parsed CSS.static void
setDefaultParseErrorHandler(ICSSParseErrorHandler aDefaultParseErrorHandler)
Set the default CSS parse error handler (for recoverable errors).static void
setDefaultParseExceptionHandler(ICSSParseExceptionCallback aDefaultParseExceptionHandler)
Set the default CSS parse exception handler (for unrecoverable errors).
-
-
-
Method Detail
-
getDefaultParseErrorHandler
@Nullable public static ICSSParseErrorHandler getDefaultParseErrorHandler()
- Returns:
- The default CSS parse error handler. May be
null
. For backwards compatibility reasons this is be default an instance ofLoggingCSSParseErrorHandler
.
-
setDefaultParseErrorHandler
public static void setDefaultParseErrorHandler(@Nullable ICSSParseErrorHandler aDefaultParseErrorHandler)
Set the default CSS parse error handler (for recoverable errors).- Parameters:
aDefaultParseErrorHandler
- The new default error handler to be used. May benull
to indicate that no special error handler should be used.
-
getDefaultParseExceptionHandler
@Nonnull public static ICSSParseExceptionCallback getDefaultParseExceptionHandler()
- Returns:
- The default CSS parse exception handler. May not be
null
. For backwards compatibility reasons this is be default an instance ofLoggingCSSParseExceptionCallback
. - Since:
- 3.7.4
-
setDefaultParseExceptionHandler
public static void setDefaultParseExceptionHandler(@Nonnull ICSSParseExceptionCallback aDefaultParseExceptionHandler)
Set the default CSS parse exception handler (for unrecoverable errors).- Parameters:
aDefaultParseExceptionHandler
- The new default exception handler to be used. May not benull
.- Since:
- 3.7.4
-
getDefaultInterpretErrorHandler
@Nonnull public static ICSSInterpretErrorHandler getDefaultInterpretErrorHandler()
- Returns:
- The default interpret error handler to handle interpretation errors
in successfully parsed CSS. Never
null
. - Since:
- 5.0.2
-
setDefaultInterpretErrorHandler
public static void setDefaultInterpretErrorHandler(@Nonnull ICSSInterpretErrorHandler aDefaultErrorHandler)
Set the default interpret error handler to handle interpretation errors in successfully parsed CSS.- Parameters:
aDefaultErrorHandler
- The default error handler to be used. May not benull
.- Since:
- 5.0.2
-
isValidCSS
public static boolean isValidCSS(@Nonnull File aFile, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion)
Check if the passed CSS file can be parsed without error- Parameters:
aFile
- The file to be parsed. May not benull
.aFallbackCharset
- The charset to be used for reading the CSS file in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to be used for scanning. May not benull
.- Returns:
true
if the file can be parsed without error,false
if not
-
isValidCSS
public static boolean isValidCSS(@Nonnull com.helger.commons.io.resource.IReadableResource aRes, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion)
Check if the passed CSS resource can be parsed without error- Parameters:
aRes
- The resource to be parsed. May not benull
.aFallbackCharset
- The charset to be used for reading the CSS file in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to be used for scanning. May not benull
.- Returns:
true
if the file can be parsed without error,false
if not
-
isValidCSS
public static boolean isValidCSS(@Nonnull @WillClose InputStream aIS, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion)
Check if the passed input stream can be resembled to valid CSS content. This is accomplished by fully parsing the CSS file each time the method is called. This is similar to callingreadFromStream(IHasInputStream,Charset, ECSSVersion)
and checking for a non-null
result.- Parameters:
aIS
- The input stream to use. Is automatically closed. May not benull
.aFallbackCharset
- The charset to be used in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to use. May not benull
.- Returns:
true
if the CSS is valid according to the version,false
if not
-
isValidCSS
public static boolean isValidCSS(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion)
Check if the passed String can be resembled to valid CSS content. This is accomplished by fully parsing the CSS file each time the method is called. This is similar to callingreadFromString(String, Charset, ECSSVersion)
and checking for a non-null
result.- Parameters:
sCSS
- The CSS string to scan. May not benull
.eVersion
- The CSS version to use. May not benull
.- Returns:
true
if the CSS is valid according to the version,false
if not
-
isValidCSS
public static boolean isValidCSS(@Nonnull @WillClose Reader aReader, @Nonnull ECSSVersion eVersion)
Check if the passed reader can be resembled to valid CSS content. This is accomplished by fully parsing the CSS each time the method is called. This is similar to callingreadFromStream(IHasInputStream, Charset, ECSSVersion)
and checking for a non-null
result.- Parameters:
aReader
- The reader to use. May not benull
.eVersion
- The CSS version to use. May not benull
.- Returns:
true
if the CSS is valid according to the version,false
if not
-
readFromString
@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion)
Read the CSS from the passed String using a byte stream.- Parameters:
sCSS
- The source string containing the CSS to be parsed. May not benull
.aFallbackCharset
- The charset to be used in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to use. May not benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.
-
readFromString
@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passed String using a byte stream.- Parameters:
sCSS
- The source string containing the CSS to be parsed. May not benull
.aFallbackCharset
- The charset to be used in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to use. May not benull
.aCustomErrorHandler
- An optional custom error handler that can be used to collect the recoverable parsing errors. May benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.
-
readFromString
@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed String using a byte stream.- Parameters:
sCSS
- The source string containing the CSS to be parsed. May not benull
.aFallbackCharset
- The charset to be used in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to use. May not benull
.aCustomExceptionHandler
- An optional custom exception handler that can be used to collect the unrecoverable parsing errors. May benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.
-
readFromString
@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed String using a byte stream.- Parameters:
sCSS
- The source string containing the CSS to be parsed. May not benull
.aFallbackCharset
- The charset to be used in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to use. May not benull
.aCustomErrorHandler
- An optional custom error handler that can be used to collect the recoverable parsing errors. May benull
.aCustomExceptionHandler
- An optional custom exception handler that can be used to collect the unrecoverable parsing errors. May benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.- Since:
- 3.7.3
-
readFromStringStream
@Nullable public static CascadingStyleSheet readFromStringStream(@Nonnull String sCSS, @Nonnull CSSReaderSettings aSettings)
Read the CSS from the passed String using a byte stream.- Parameters:
sCSS
- The source string containing the CSS to be parsed. May not benull
.aSettings
- The settings to be used for reading the CSS. May not benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.- Since:
- 3.8.2
-
readFromString
@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion)
Read the CSS from the passed String using a character stream. An eventually contained@charset
rule is ignored.- Parameters:
sCSS
- The source string containing the CSS to be parsed. May not benull
.eVersion
- The CSS version to use. May not benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.- Since:
- 3.7.3
-
readFromString
@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passed String using a character stream. An eventually contained@charset
rule is ignored.- Parameters:
sCSS
- The source string containing the CSS to be parsed. May not benull
.eVersion
- The CSS version to use. May not benull
.aCustomErrorHandler
- An optional custom error handler that can be used to collect the recoverable parsing errors. May benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.- Since:
- 3.7.3
-
readFromString
@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed String using a character stream. An eventually contained@charset
rule is ignored.- Parameters:
sCSS
- The source string containing the CSS to be parsed. May not benull
.eVersion
- The CSS version to use. May not benull
.aCustomExceptionHandler
- An optional custom exception handler that can be used to collect the unrecoverable parsing errors. May benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.- Since:
- 3.7.3
-
readFromString
@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed String using a character stream. An eventually contained@charset
rule is ignored.- Parameters:
sCSS
- The source string containing the CSS to be parsed. May not benull
.eVersion
- The CSS version to use. May not benull
.aCustomErrorHandler
- An optional custom error handler that can be used to collect the recoverable parsing errors. May benull
.aCustomExceptionHandler
- An optional custom exception handler that can be used to collect the unrecoverable parsing errors. May benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.- Since:
- 3.7.3
-
readFromStringReader
@Nullable public static CascadingStyleSheet readFromStringReader(@Nonnull String sCSS, @Nonnull CSSReaderSettings aSettings)
Read the CSS from the passed String using a character stream. An eventually contained@charset
rule is ignored.- Parameters:
sCSS
- The source string containing the CSS to be parsed. May not benull
.aSettings
- The settings to be used for reading the CSS. May not benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.- Since:
- 3.8.2
-
readFromFile
@Nullable public static CascadingStyleSheet readFromFile(@Nonnull File aFile, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion)
Read the CSS from the passed File.- Parameters:
aFile
- The file containing the CSS to be parsed. May not benull
.aFallbackCharset
- The charset to be used in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to use. May not benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.
-
readFromFile
@Nullable public static CascadingStyleSheet readFromFile(@Nonnull File aFile, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passed File.- Parameters:
aFile
- The file containing the CSS to be parsed. May not benull
.aFallbackCharset
- The charset to be used in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to use. May not benull
.aCustomErrorHandler
- An optional custom error handler that can be used to collect the recoverable parsing errors. May benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.
-
readFromFile
@Nullable public static CascadingStyleSheet readFromFile(@Nonnull File aFile, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed File.- Parameters:
aFile
- The file containing the CSS to be parsed. May not benull
.aFallbackCharset
- The charset to be used in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to use. May not benull
.aCustomExceptionHandler
- An optional custom exception handler that can be used to collect the unrecoverable parsing errors. May benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.
-
readFromFile
@Nullable public static CascadingStyleSheet readFromFile(@Nonnull File aFile, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed File.- Parameters:
aFile
- The file containing the CSS to be parsed. May not benull
.aFallbackCharset
- The charset to be used in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to use. May not benull
.aCustomErrorHandler
- An optional custom error handler that can be used to collect the recoverable parsing errors. May benull
.aCustomExceptionHandler
- An optional custom exception handler that can be used to collect the unrecoverable parsing errors. May benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.
-
readFromFile
@Nullable public static CascadingStyleSheet readFromFile(@Nonnull File aFile, @Nonnull CSSReaderSettings aSettings)
Read the CSS from the passed File.- Parameters:
aFile
- The file containing the CSS to be parsed. May not benull
.aSettings
- The settings to be used for reading the CSS. May not benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.- Since:
- 3.8.2
-
readFromStream
@Nullable public static CascadingStyleSheet readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion)
Read the CSS from the passedIHasInputStream
. If the CSS contains an explicit charset, the whole CSS is parsed again, with the charset found inside the file, so the passedIHasInputStream
must be able to create a new input stream on second invocation!- Parameters:
aISP
- The input stream provider to use. Must be able to create new input streams on every invocation, in case an explicit charset node was found. May not benull
.aFallbackCharset
- The charset to be used in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to use. May not benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.
-
readFromStream
@Nullable public static CascadingStyleSheet readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passedIHasInputStream
. If the CSS contains an explicit charset, the whole CSS is parsed again, with the charset found inside the file, so the passedIHasInputStream
must be able to create a new input stream on second invocation!- Parameters:
aISP
- The input stream provider to use. Must be able to create new input streams on every invocation, in case an explicit charset node was found. May not benull
.aFallbackCharset
- The charset to be used in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to use. May not benull
.aCustomErrorHandler
- An optional custom error handler that can be used to collect the recoverable parsing errors. May benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.
-
getCharsetDeclaredInCSS
@Nullable public static Charset getCharsetDeclaredInCSS(@Nonnull com.helger.commons.io.IHasInputStream aISP)
Determine the charset to read the CSS file. The logic is as follows:- Determine the charset used to read the @charset from the stream. If a BOM is present and a matching Charset is present, this charset is used. As a fallback the CSS file is initially read with ISO-8859-1.
- If the CSS content contains a valid @charset rule, the defined charset is returned even if a different BOM is present.
- If the CSS content does not contain a valid @charset rule than the charset of the BOM is returned (if any).
- Otherwise
null
is returned.
- Parameters:
aISP
- The input stream provider to read from. May not benull
.- Returns:
null
if the input stream could not be opened or if neither a BOM nor a charset is specified. Otherwise a non-null
Charset is returned.- Throws:
IllegalStateException
- if an invalid charset is supplied
-
readFromStream
@Nullable public static CascadingStyleSheet readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedIHasInputStream
. If the CSS contains an explicit charset, the whole CSS is parsed again, with the charset found inside the file, so the passedIHasInputStream
must be able to create a new input stream on second invocation!- Parameters:
aISP
- The input stream provider to use. Must be able to create new input streams on every invocation, in case an explicit charset node was found. May not benull
.aFallbackCharset
- The charset to be used in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to use. May not benull
.aCustomExceptionHandler
- An optional custom exception handler that can be used to collect the unrecoverable parsing errors. May benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.
-
readFromStream
@Nullable public static CascadingStyleSheet readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedIHasInputStream
. If the CSS contains an explicit charset, the whole CSS is parsed again, with the charset found inside the file, so the passedIHasInputStream
must be able to create a new input stream on second invocation!- Parameters:
aISP
- The input stream provider to use. Must be able to create new input streams on every invocation, in case an explicit charset node was found. May not benull
.aFallbackCharset
- The charset to be used in case neither a@charset
rule nor a BOM is present. May not benull
.eVersion
- The CSS version to use. May not benull
.aCustomErrorHandler
- An optional custom error handler that can be used to collect the recoverable parsing errors. May benull
.aCustomExceptionHandler
- An optional custom exception handler that can be used to collect the unrecoverable parsing errors. May benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.
-
readFromStream
@Nullable public static CascadingStyleSheet readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull CSSReaderSettings aSettings)
Read the CSS from the passedIHasInputStream
. If the CSS contains an explicit charset, the whole CSS is parsed again, with the charset found inside the file, so the passedIHasInputStream
must be able to create a new input stream on second invocation!- Parameters:
aISP
- The input stream provider to use. Must be able to create new input streams on every invocation, in case an explicit charset node was found. May not benull
.aSettings
- The settings to be used for reading the CSS. May not benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.- Since:
- 3.8.2
-
readFromReader
@Nullable public static CascadingStyleSheet readFromReader(@Nonnull com.helger.commons.io.IHasReader aRP, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedIHasReader
. If the CSS contains an explicit@charset
rule, it is ignored and the charset used to create the reader is used instead!- Parameters:
aRP
- The reader provider to use. The reader is retrieved exactly once and closed anyway. May not benull
.eVersion
- The CSS version to use. May not benull
.aCustomErrorHandler
- An optional custom error handler that can be used to collect the recoverable parsing errors. May benull
.aCustomExceptionHandler
- An optional custom exception handler that can be used to collect the unrecoverable parsing errors. May benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.- Since:
- 3.7.3
-
readFromReader
@Nullable public static CascadingStyleSheet readFromReader(@Nonnull com.helger.commons.io.IHasReader aRP, @Nonnull CSSReaderSettings aSettings)
Read the CSS from the passedIHasReader
. If the CSS contains an explicit@charset
rule, it is ignored and the charset used to create the reader is used instead! Also the fallback charset from theCSSReaderSettings
is ignored.- Parameters:
aRP
- The reader provider to use. The reader is retrieved exactly once and closed anyway. May not benull
.aSettings
- The settings to be used for reading the CSS. May not benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.- Since:
- 3.8.2
-
-