Package com.helger.css.reader
Class CSSReaderDeclarationList
java.lang.Object
com.helger.css.reader.CSSReaderDeclarationList
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
Modifier and TypeMethodDescriptionstatic ICSSInterpretErrorHandlerstatic ICSSParseErrorHandlerstatic ICSSParseExceptionCallbackstatic booleanisValidCSS(com.helger.commons.io.resource.IReadableResource aRes, Charset aCharset, ECSSVersion eVersion) Check if the passed CSS resource can be parsed without errorstatic booleanisValidCSS(File aFile, Charset aCharset, ECSSVersion eVersion) Check if the passed CSS file can be parsed without errorstatic booleanisValidCSS(InputStream aIS, Charset aCharset, ECSSVersion eVersion) Check if the passed input stream can be resembled to valid CSS content.static booleanisValidCSS(Reader aReader, ECSSVersion eVersion) Check if the passed reader can be resembled to valid CSS content.static booleanisValidCSS(String sCSS, ECSSVersion eVersion) Check if the passed String can be resembled to valid CSS content.static CSSDeclarationListreadFromFile(File aFile, Charset aCharset, ECSSVersion eVersion) static CSSDeclarationListreadFromFile(File aFile, Charset aCharset, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler) static CSSDeclarationListreadFromFile(File aFile, Charset aCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler) static CSSDeclarationListreadFromFile(File aFile, Charset aCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler) static CSSDeclarationListreadFromFile(File aFile, Charset aCharset, CSSReaderSettings aSettings) Read the CSS from the passed File.static CSSDeclarationListreadFromReader(Reader aReader, ECSSVersion eVersion) Read the CSS from the passedReader.static CSSDeclarationListreadFromReader(Reader aReader, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler) Read the CSS from the passedReader.static CSSDeclarationListreadFromReader(Reader aReader, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler) Read the CSS from the passedReader.static CSSDeclarationListreadFromReader(Reader aReader, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler) Read the CSS from the passedReader.static CSSDeclarationListreadFromReader(Reader aReader, CSSReaderSettings aSettings) Read the CSS from the passedReader.static CSSDeclarationListreadFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aCharset, ECSSVersion eVersion) Read the CSS from the passedIHasInputStream.static CSSDeclarationListreadFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aCharset, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler) Read the CSS from the passedIHasInputStream.static CSSDeclarationListreadFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler) Read the CSS from the passedIHasInputStream.static CSSDeclarationListreadFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler) Read the CSS from the passedIHasInputStream.static CSSDeclarationListreadFromStream(com.helger.commons.io.IHasInputStream aISP, Charset aCharset, CSSReaderSettings aSettings) Read the CSS from the passedIHasInputStream.static CSSDeclarationListreadFromStream(InputStream aIS, Charset aCharset, ECSSVersion eVersion) Read the CSS from the passedInputStream.static CSSDeclarationListreadFromStream(InputStream aIS, Charset aCharset, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler) Read the CSS from the passedInputStream.static CSSDeclarationListreadFromStream(InputStream aIS, Charset aCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler) Read the CSS from the passedInputStream.static CSSDeclarationListreadFromStream(InputStream aIS, Charset aCharset, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler) Read the CSS from the passedInputStream.static CSSDeclarationListreadFromStream(InputStream aIS, Charset aCharset, CSSReaderSettings aSettings) Read the CSS from the passedInputStream.static CSSDeclarationListreadFromString(String sCSS, ECSSVersion eVersion) Read the CSS from the passed String.static CSSDeclarationListreadFromString(String sCSS, ECSSVersion eVersion, ICSSParseExceptionCallback aCustomExceptionHandler) Read the CSS from the passed String.static CSSDeclarationListreadFromString(String sCSS, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler) Read the CSS from the passed String.static CSSDeclarationListreadFromString(String sCSS, ECSSVersion eVersion, ICSSParseErrorHandler aCustomErrorHandler, ICSSParseExceptionCallback aCustomExceptionHandler) Read the CSS from the passed String.static CSSDeclarationListreadFromString(String sCSS, CSSReaderSettings aSettings) Read the CSS from the passed String.static voidsetDefaultInterpretErrorHandler(ICSSInterpretErrorHandler aDefaultErrorHandler) Set the default interpret error handler to handle interpretation errors in successfully parsed CSS.static voidsetDefaultParseErrorHandler(ICSSParseErrorHandler aDefaultParseErrorHandler) Set the default CSS parse error handler (for recoverable errors).static voidsetDefaultParseExceptionHandler(ICSSParseExceptionCallback aDefaultParseExceptionHandler) Set the default CSS parse exception handler (for unrecoverable errors).
-
Method Details
-
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 benullto indicate that no special error handler should be used.- Since:
- 3.7.4
-
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
- 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:
trueif the file can be parsed without error,falseif 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:
trueif the file can be parsed without error,falseif 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-nullresult.- 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:
trueif the CSS is valid according to the version,falseif not
-
isValidCSS
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-nullresult.- Parameters:
sCSS- The CSS string to scan. May not benull.eVersion- The CSS version to use. May not benull.- Returns:
trueif the CSS is valid according to the version,falseif not
-
isValidCSS
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-nullresult.- Parameters:
aReader- The reader to use. May not benull.eVersion- The CSS version to use. May not benull.- Returns:
trueif the CSS is valid according to the version,falseif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif 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:
nullif reading failed, the CSS declarations otherwise.- Since:
- 3.8.2
-