Package com.helger.css.reader
Class CSSReaderDeclarationList
- java.lang.Object
-
- com.helger.css.reader.CSSReaderDeclarationList
-
@Immutable public final class CSSReaderDeclarationList extends Object
This is the central user class for reading and parsing partial CSS from different sources. This class reads CSS style declarations as used in HTML<style>
attributes only.- Author:
- Philip Helger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ICSSInterpretErrorHandler
getDefaultInterpretErrorHandler()
static ICSSParseErrorHandler
getDefaultParseErrorHandler()
static ICSSParseExceptionCallback
getDefaultParseExceptionHandler()
static boolean
isValidCSS(com.helger.commons.io.resource.IReadableResource aRes, Charset aCharset, ECSSVersion eVersion)
Check if the passed CSS resource can be parsed without errorstatic boolean
isValidCSS(File aFile, Charset aCharset, ECSSVersion eVersion)
Check if the passed CSS file can be parsed without errorstatic boolean
isValidCSS(InputStream aIS, Charset aCharset, 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 CSSDeclarationList
readFromFile(File aFile, Charset aCharset, ECSSVersion eVersion)
static CSSDeclarationList
readFromFile(File aFile, Charset aCharset, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler)
static CSSDeclarationList
readFromFile(File aFile, Charset aCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler)
static CSSDeclarationList
readFromFile(File aFile, Charset aCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler)
static CSSDeclarationList
readFromFile(File aFile, Charset aCharset, CSSReaderSettings aSettings)
Read the CSS from the passed File.static CSSDeclarationList
readFromReader(Reader aReader, ECSSVersion eVersion)
Read the CSS from the passedReader
.static CSSDeclarationList
readFromReader(Reader aReader, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedReader
.static CSSDeclarationList
readFromReader(Reader aReader, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passedReader
.static CSSDeclarationList
readFromReader(Reader aReader, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedReader
.static CSSDeclarationList
readFromReader(Reader aReader, CSSReaderSettings aSettings)
Read the CSS from the passedReader
.static CSSDeclarationList
readFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aCharset, ECSSVersion eVersion)
Read the CSS from the passedIHasInputStream
.static CSSDeclarationList
readFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aCharset, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedIHasInputStream
.static CSSDeclarationList
readFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passedIHasInputStream
.static CSSDeclarationList
readFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedIHasInputStream
.static CSSDeclarationList
readFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aCharset, CSSReaderSettings aSettings)
Read the CSS from the passedIHasInputStream
.static CSSDeclarationList
readFromStream(InputStream aIS, Charset aCharset, ECSSVersion eVersion)
Read the CSS from the passedInputStream
.static CSSDeclarationList
readFromStream(InputStream aIS, Charset aCharset, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedInputStream
.static CSSDeclarationList
readFromStream(InputStream aIS, Charset aCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passedInputStream
.static CSSDeclarationList
readFromStream(InputStream aIS, Charset aCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedInputStream
.static CSSDeclarationList
readFromStream(InputStream aIS, Charset aCharset, CSSReaderSettings aSettings)
Read the CSS from the passedInputStream
.static CSSDeclarationList
readFromString(String sCSS, ECSSVersion eVersion)
Read the CSS from the passed String.static CSSDeclarationList
readFromString(String sCSS, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed String.static CSSDeclarationList
readFromString(String sCSS, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passed String.static CSSDeclarationList
readFromString(String sCSS, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed String.static CSSDeclarationList
readFromString(String sCSS, CSSReaderSettings aSettings)
Read the CSS from the passed String.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 ofThrowingCSSParseErrorHandler
. - Since:
- 3.7.4
-
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.- Since:
- 3.7.4
-
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 aCharset, @Nonnull ECSSVersion eVersion)
Check if the passed CSS file can be parsed without error- Parameters:
aFile
- The file to be parsed. May not benull
.aCharset
- The charset to be used for reading the CSS file. 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 aCharset, @Nonnull ECSSVersion eVersion)
Check if the passed CSS resource can be parsed without error- Parameters:
aRes
- The resource to be parsed. May not benull
.aCharset
- The charset to be used for reading the CSS file. 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 aCharset, @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
.aCharset
- The charset to be used. 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, 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 CSSDeclarationList readFromString(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion)
Read the CSS from the passed String.- 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.
-
readFromString
@Nullable public static CSSDeclarationList readFromString(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passed String.- 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.
-
readFromString
@Nullable public static CSSDeclarationList readFromString(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed String.- 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.
-
readFromString
@Nullable public static CSSDeclarationList readFromString(@Nonnull String sCSS, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passed String.- 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.
-
readFromString
@Nullable public static CSSDeclarationList readFromString(@Nonnull String sCSS, @Nonnull CSSReaderSettings aSettings)
Read the CSS from the passed String.- 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:
- 6.4.3
-
readFromFile
@Nullable public static CSSDeclarationList readFromFile(@Nonnull File aFile, @Nonnull Charset aCharset, @Nonnull ECSSVersion eVersion)
-
readFromFile
@Nullable public static CSSDeclarationList readFromFile(@Nonnull File aFile, @Nonnull Charset aCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler)
-
readFromFile
@Nullable public static CSSDeclarationList readFromFile(@Nonnull File aFile, @Nonnull Charset aCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
-
readFromFile
@Nullable public static CSSDeclarationList readFromFile(@Nonnull File aFile, @Nonnull Charset aCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
-
readFromFile
@Nullable public static CSSDeclarationList readFromFile(@Nonnull File aFile, @Nonnull Charset aCharset, @Nonnull CSSReaderSettings aSettings)
Read the CSS from the passed File.- Parameters:
aFile
- The file containing the CSS to be parsed. May not benull
.aCharset
- The charset to be used. 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:
- 6.4.3
-
readFromStream
@Nullable public static CSSDeclarationList readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull Charset aCharset, @Nonnull ECSSVersion eVersion)
Read the CSS from the passedIHasInputStream
.- Parameters:
aISP
- The input stream provider to use. May not benull
.aCharset
- The charset to be used. 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 CSSDeclarationList readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull Charset aCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passedIHasInputStream
.- Parameters:
aISP
- The input stream provider to use. May not benull
.aCharset
- The charset to be used. 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.
-
readFromStream
@Nullable public static CSSDeclarationList readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull Charset aCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedIHasInputStream
.- Parameters:
aISP
- The input stream provider to use. May not benull
.aCharset
- The charset to be used. 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 CSSDeclarationList readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull Charset aCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedIHasInputStream
.- Parameters:
aISP
- The input stream provider to use. May not benull
.aCharset
- The charset to be used. 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 CSSDeclarationList readFromStream(@Nonnull com.helger.commons.io.IHasInputStream aISP, @Nonnull Charset aCharset, @Nonnull CSSReaderSettings aSettings)
Read the CSS from the passedIHasInputStream
.- Parameters:
aISP
- The input stream provider to use. May not benull
.aCharset
- The charset to be used. 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:
- 6.4.3
-
readFromStream
@Nullable public static CSSDeclarationList readFromStream(@Nonnull @WillClose InputStream aIS, @Nonnull Charset aCharset, @Nonnull ECSSVersion eVersion)
Read the CSS from the passedInputStream
.- Parameters:
aIS
- The input stream to use. Will be closed automatically after reading - independent of success or error. May not benull
.aCharset
- The charset to be used. May not benull
.eVersion
- The CSS version to use. May not benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.- Since:
- 3.7.4
-
readFromStream
@Nullable public static CSSDeclarationList readFromStream(@Nonnull @WillClose InputStream aIS, @Nonnull Charset aCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passedInputStream
.- Parameters:
aIS
- The input stream to use. Will be closed automatically after reading - independent of success or error. May not benull
.aCharset
- The charset to be used. 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.4
-
readFromStream
@Nullable public static CSSDeclarationList readFromStream(@Nonnull @WillClose InputStream aIS, @Nonnull Charset aCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedInputStream
.- Parameters:
aIS
- The input stream to use. Will be closed automatically after reading - independent of success or error. May not benull
.aCharset
- The charset to be used. 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.4
-
readFromStream
@Nullable public static CSSDeclarationList readFromStream(@Nonnull @WillClose InputStream aIS, @Nonnull Charset aCharset, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedInputStream
.- Parameters:
aIS
- The input stream to use. Will be closed automatically after reading - independent of success or error. May not benull
.aCharset
- The charset to be used. 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.4
-
readFromStream
@Nullable public static CSSDeclarationList readFromStream(@Nonnull @WillClose InputStream aIS, @Nonnull Charset aCharset, @Nonnull CSSReaderSettings aSettings)
Read the CSS from the passedInputStream
.- Parameters:
aIS
- The input stream to use. Will be closed automatically after reading - independent of success or error. May not benull
.aCharset
- The charset to be used. 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:
- 6.4.3
-
readFromReader
@Nullable public static CSSDeclarationList readFromReader(@Nonnull @WillClose Reader aReader, @Nonnull ECSSVersion eVersion)
Read the CSS from the passedReader
.- Parameters:
aReader
- The reader to use. Will be closed automatically after reading - independent of success or error. May not benull
.eVersion
- The CSS version to use. May not benull
.- Returns:
null
if reading failed, the CSS declarations otherwise.
-
readFromReader
@Nullable public static CSSDeclarationList readFromReader(@Nonnull @WillClose Reader aReader, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler)
Read the CSS from the passedReader
.- Parameters:
aReader
- The reader to use. Will be closed automatically after reading - independent of success or error. 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.
-
readFromReader
@Nullable public static CSSDeclarationList readFromReader(@Nonnull @WillClose Reader aReader, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedReader
.- Parameters:
aReader
- The reader to use. Will be closed automatically after reading - independent of success or error. 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.
-
readFromReader
@Nullable public static CSSDeclarationList readFromReader(@Nonnull @WillClose Reader aReader, @Nonnull ECSSVersion eVersion, @Nullable ICSSParseErrorHandler aCustomErrorHandler, @Nullable ICSSParseExceptionCallback aCustomExceptionHandler)
Read the CSS from the passedReader
.- Parameters:
aReader
- The reader to use. Will be closed automatically after reading - independent of success or error. 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.
-
readFromReader
@Nullable public static CSSDeclarationList readFromReader(@Nonnull @WillClose Reader aReader, @Nonnull CSSReaderSettings aSettings)
Read the CSS from the passedReader
.- Parameters:
aReader
- The reader to use. Will be closed automatically after reading - independent of success or error. 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
-
-