@ThreadSafe public final class CSSReader extends Object
<style> attribute) the
CSSReaderDeclarationList is available.| Modifier and Type | Method and 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(File aFile,
Charset aFallbackCharset,
ECSSVersion eVersion)
Check if the passed CSS file can be parsed without error
|
static boolean |
isValidCSS(InputStream aIS,
Charset aFallbackCharset,
ECSSVersion eVersion)
Check if the passed input stream can be resembled to valid CSS content.
|
static boolean |
isValidCSS(com.helger.commons.io.resource.IReadableResource aRes,
Charset aFallbackCharset,
ECSSVersion eVersion)
Check if the passed CSS resource can be parsed without error
|
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,
Charset aFallbackCharset,
ECSSVersion eVersion)
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 |
readFromFile(File aFile,
Charset aFallbackCharset,
ECSSVersion eVersion,
ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed File.
|
static CascadingStyleSheet |
readFromFile(File aFile,
CSSReaderSettings aSettings)
Read the CSS from the passed File.
|
static CascadingStyleSheet |
readFromReader(com.helger.commons.io.IHasReader aRP,
CSSReaderSettings aSettings)
Read the CSS from the passed
IReaderProvider. |
static CascadingStyleSheet |
readFromReader(com.helger.commons.io.IHasReader aRP,
ECSSVersion eVersion,
ICSSParseErrorHandler aCustomErrorHandler,
ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed
IReaderProvider. |
static CascadingStyleSheet |
readFromStream(com.helger.commons.io.IHasInputStream aISP,
Charset aFallbackCharset,
ECSSVersion eVersion)
Read the CSS from the passed
IHasInputStream. |
static CascadingStyleSheet |
readFromStream(com.helger.commons.io.IHasInputStream aISP,
Charset aFallbackCharset,
ECSSVersion eVersion,
ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passed
IHasInputStream. |
static CascadingStyleSheet |
readFromStream(com.helger.commons.io.IHasInputStream aISP,
Charset aFallbackCharset,
ECSSVersion eVersion,
ICSSParseErrorHandler aCustomErrorHandler,
ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed
IHasInputStream. |
static CascadingStyleSheet |
readFromStream(com.helger.commons.io.IHasInputStream aISP,
Charset aFallbackCharset,
ECSSVersion eVersion,
ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed
IHasInputStream. |
static CascadingStyleSheet |
readFromStream(com.helger.commons.io.IHasInputStream aISP,
CSSReaderSettings aSettings)
Read the CSS from the passed
IHasInputStream. |
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,
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 |
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,
ECSSVersion eVersion)
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,
ECSSVersion eVersion,
ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed String using a character 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).
|
@Nullable public static ICSSParseErrorHandler getDefaultParseErrorHandler()
null. For
backwards compatibility reasons this is be default an instance of
ThrowingCSSParseErrorHandler.public static void setDefaultParseErrorHandler(@Nullable ICSSParseErrorHandler aDefaultParseErrorHandler)
aDefaultParseErrorHandler - The new default error handler to be used. May be null
to indicate that no special error handler should be used.@Nonnull public static ICSSParseExceptionCallback getDefaultParseExceptionHandler()
null. For backwards compatibility reasons this is be
default an instance of LoggingCSSParseExceptionCallback.public static void setDefaultParseExceptionHandler(@Nonnull ICSSParseExceptionCallback aDefaultParseExceptionHandler)
aDefaultParseExceptionHandler - The new default exception handler to be used. May not be
null.@Nonnull public static ICSSInterpretErrorHandler getDefaultInterpretErrorHandler()
null.public static void setDefaultInterpretErrorHandler(@Nonnull ICSSInterpretErrorHandler aDefaultErrorHandler)
aDefaultErrorHandler - The default error handler to be used. May not be null.public static boolean isValidCSS(@Nonnull File aFile, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion)
aFile - The file to be parsed. May not be null.aFallbackCharset - The charset to be used for reading the CSS file in case neither a
@charset rule nor a BOM is present. May not be
null.eVersion - The CSS version to be used for scanning. May not be
null.true if the file can be parsed without error,
false if notpublic static boolean isValidCSS(@Nonnull com.helger.commons.io.resource.IReadableResource aRes, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion)
aRes - The resource to be parsed. May not be null.aFallbackCharset - The charset to be used for reading the CSS file in case neither a
@charset rule nor a BOM is present. May not be
null.eVersion - The CSS version to be used for scanning. May not be
null.true if the file can be parsed without error,
false if notpublic static boolean isValidCSS(@Nonnull @WillClose InputStream aIS, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion)
readFromStream(IHasInputStream,Charset, ECSSVersion) and checking
for a non-null result.aIS - The input stream to use. Is automatically closed. May not be
null.aFallbackCharset - The charset to be used in case neither a @charset rule
nor a BOM is present. May not be null.eVersion - The CSS version to use. May not be null.true if the CSS is valid according to the version,
false if notpublic static boolean isValidCSS(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion)
readFromString(String, Charset, ECSSVersion) and checking for a
non-null result.sCSS - The CSS string to scan. May not be null.eVersion - The CSS version to use. May not be null.true if the CSS is valid according to the version,
false if notpublic static boolean isValidCSS(@Nonnull @WillClose Reader aReader, @Nonnull ECSSVersion eVersion)
readFromStream(IHasInputStream, Charset, ECSSVersion) and checking
for a non-null result.aReader - The reader to use. May not be null.eVersion - The CSS version to use. May not be null.true if the CSS is valid according to the version,
false if not@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion)
sCSS - The source string containing the CSS to be parsed. May not be
null.aFallbackCharset - The charset to be used in case neither a @charset rule
nor a BOM is present. May not be null.eVersion - The CSS version to use. May not be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler)
sCSS - The source string containing the CSS to be parsed. May not be
null.aFallbackCharset - The charset to be used in case neither a @charset rule
nor a BOM is present. May not be null.eVersion - The CSS version to use. May not be null.aCustomErrorHandler - An optional custom error handler that can be used to collect the
recoverable parsing errors. May be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
sCSS - The source string containing the CSS to be parsed. May not be
null.aFallbackCharset - The charset to be used in case neither a @charset rule
nor a BOM is present. May not be null.eVersion - The CSS version to use. May not be null.aCustomExceptionHandler - An optional custom exception handler that can be used to collect the
unrecoverable parsing errors. May be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
sCSS - The source string containing the CSS to be parsed. May not be
null.aFallbackCharset - The charset to be used in case neither a @charset rule
nor a BOM is present. May not be null.eVersion - The CSS version to use. May not be null.aCustomErrorHandler - An optional custom error handler that can be used to collect the
recoverable parsing errors. May be null.aCustomExceptionHandler - An optional custom exception handler that can be used to collect the
unrecoverable parsing errors. May be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromStringStream(@Nonnull String sCSS, @Nonnull CSSReaderSettings aSettings)
sCSS - The source string containing the CSS to be parsed. May not be
null.aSettings - The settings to be used for reading the CSS. May not be
null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion)
@charset rule is ignored.sCSS - The source string containing the CSS to be parsed. May not be
null.eVersion - The CSS version to use. May not be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler)
@charset rule is ignored.sCSS - The source string containing the CSS to be parsed. May not be
null.eVersion - The CSS version to use. May not be null.aCustomErrorHandler - An optional custom error handler that can be used to collect the
recoverable parsing errors. May be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
@charset rule is ignored.sCSS - The source string containing the CSS to be parsed. May not be
null.eVersion - The CSS version to use. May not be null.aCustomExceptionHandler - An optional custom exception handler that can be used to collect the
unrecoverable parsing errors. May be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromString(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
@charset rule is ignored.sCSS - The source string containing the CSS to be parsed. May not be
null.eVersion - The CSS version to use. May not be null.aCustomErrorHandler - An optional custom error handler that can be used to collect the
recoverable parsing errors. May be null.aCustomExceptionHandler - An optional custom exception handler that can be used to collect the
unrecoverable parsing errors. May be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromStringReader(@Nonnull String sCSS, @Nonnull CSSReaderSettings aSettings)
@charset rule is ignored.sCSS - The source string containing the CSS to be parsed. May not be
null.aSettings - The settings to be used for reading the CSS. May not be
null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromFile(@Nonnull File aFile, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion)
aFile - The file containing the CSS to be parsed. May not be
null.aFallbackCharset - The charset to be used in case neither a @charset rule
nor a BOM is present. May not be null.eVersion - The CSS version to use. May not be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromFile(@Nonnull File aFile, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler)
aFile - The file containing the CSS to be parsed. May not be
null.aFallbackCharset - The charset to be used in case neither a @charset rule
nor a BOM is present. May not be null.eVersion - The CSS version to use. May not be null.aCustomErrorHandler - An optional custom error handler that can be used to collect the
recoverable parsing errors. May be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromFile(@Nonnull File aFile, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
aFile - The file containing the CSS to be parsed. May not be
null.aFallbackCharset - The charset to be used in case neither a @charset rule
nor a BOM is present. May not be null.eVersion - The CSS version to use. May not be null.aCustomExceptionHandler - An optional custom exception handler that can be used to collect the
unrecoverable parsing errors. May be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromFile(@Nonnull File aFile, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
aFile - The file containing the CSS to be parsed. May not be
null.aFallbackCharset - The charset to be used in case neither a @charset rule
nor a BOM is present. May not be null.eVersion - The CSS version to use. May not be null.aCustomErrorHandler - An optional custom error handler that can be used to collect the
recoverable parsing errors. May be null.aCustomExceptionHandler - An optional custom exception handler that can be used to collect the
unrecoverable parsing errors. May be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromFile(@Nonnull File aFile, @Nonnull CSSReaderSettings aSettings)
aFile - The file containing the CSS to be parsed. May not be
null.aSettings - The settings to be used for reading the CSS. May not be
null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion)
IHasInputStream. If the CSS contains
an explicit charset, the whole CSS is parsed again, with the charset found
inside the file, so the passed IHasInputStream must be able to
create a new input stream on second invocation!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 be null.aFallbackCharset - The charset to be used in case neither a @charset rule
nor a BOM is present. May not be null.eVersion - The CSS version to use. May not be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler)
IHasInputStream. If the CSS contains
an explicit charset, the whole CSS is parsed again, with the charset found
inside the file, so the passed IHasInputStream must be able to
create a new input stream on second invocation!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 be null.aFallbackCharset - The charset to be used in case neither a @charset rule
nor a BOM is present. May not be null.eVersion - The CSS version to use. May not be null.aCustomErrorHandler - An optional custom error handler that can be used to collect the
recoverable parsing errors. May be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static Charset getCharsetDeclaredInCSS(@Nonnull com.helger.commons.io.IHasInputStream aISP)
null is returned.aISP - The input stream provider to read from. May not be null
.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.IllegalStateException - if an invalid charset is supplied@Nullable public static CascadingStyleSheet readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
IHasInputStream. If the CSS contains
an explicit charset, the whole CSS is parsed again, with the charset found
inside the file, so the passed IHasInputStream must be able to
create a new input stream on second invocation!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 be null.aFallbackCharset - The charset to be used in case neither a @charset rule
nor a BOM is present. May not be null.eVersion - The CSS version to use. May not be null.aCustomExceptionHandler - An optional custom exception handler that can be used to collect the
unrecoverable parsing errors. May be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull Charset aFallbackCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
IHasInputStream. If the CSS contains
an explicit charset, the whole CSS is parsed again, with the charset found
inside the file, so the passed IHasInputStream must be able to
create a new input stream on second invocation!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 be null.aFallbackCharset - The charset to be used in case neither a @charset rule
nor a BOM is present. May not be null.eVersion - The CSS version to use. May not be null.aCustomErrorHandler - An optional custom error handler that can be used to collect the
recoverable parsing errors. May be null.aCustomExceptionHandler - An optional custom exception handler that can be used to collect the
unrecoverable parsing errors. May be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull CSSReaderSettings aSettings)
IHasInputStream. If the CSS contains
an explicit charset, the whole CSS is parsed again, with the charset found
inside the file, so the passed IHasInputStream must be able to
create a new input stream on second invocation!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 be null.aSettings - The settings to be used for reading the CSS. May not be
null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromReader(@Nonnull com.helger.commons.io.IHasReader aRP, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
IReaderProvider. If the CSS contains
an explicit @charset rule, it is ignored and the charset used
to create the reader is used instead!aRP - The reader provider to use. The reader is retrieved exactly once and
closed anyway. May not be null.eVersion - The CSS version to use. May not be null.aCustomErrorHandler - An optional custom error handler that can be used to collect the
recoverable parsing errors. May be null.aCustomExceptionHandler - An optional custom exception handler that can be used to collect the
unrecoverable parsing errors. May be null.null if reading failed, the CSS declarations
otherwise.@Nullable public static CascadingStyleSheet readFromReader(@Nonnull com.helger.commons.io.IHasReader aRP, @Nonnull CSSReaderSettings aSettings)
IReaderProvider. 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 the
CSSReaderSettings is ignored.aRP - The reader provider to use. The reader is retrieved exactly once and
closed anyway. May not be null.aSettings - The settings to be used for reading the CSS. May not be
null.null if reading failed, the CSS declarations
otherwise.Copyright © 2014–2018 Philip Helger. All rights reserved.