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 Details

    • 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 of ThrowingCSSParseErrorHandler.
      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 be null 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 of LoggingCSSParseExceptionCallback.
      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 be null.
      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 be null.
      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 be null.
      aCharset - The charset to be used for reading the CSS file. May not be null.
      eVersion - The CSS version to be used for scanning. May not be null.
      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 be null.
      aCharset - The charset to be used for reading the CSS file. May not be null.
      eVersion - The CSS version to be used for scanning. May not be null.
      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 calling readFromStream(IHasInputStream,Charset, ECSSVersion) and checking for a non-null result.
      Parameters:
      aIS - The input stream to use. Is automatically closed. May not be null.
      aCharset - The charset to be used. May not be null.
      eVersion - The CSS version to use. May not be null.
      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 calling readFromString(String, ECSSVersion) and checking for a non-null result.
      Parameters:
      sCSS - The CSS string to scan. May not be null.
      eVersion - The CSS version to use. May not be null.
      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 calling readFromStream(IHasInputStream, Charset, ECSSVersion) and checking for a non-null result.
      Parameters:
      aReader - The reader to use. May not be null.
      eVersion - The CSS version to use. May not be null.
      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 be null.
      eVersion - The CSS version to use. May not be null.
      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 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.
      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 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.
      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 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.
      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 be null.
      aSettings - The settings to be used for reading the CSS. May not be null.
      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 be null.
      aCharset - The charset to be used. May not be null.
      aSettings - The settings to be used for reading the CSS. May not be null.
      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 passed IHasInputStream.
      Parameters:
      aISP - The input stream provider to use. May not be null.
      aCharset - The charset to be used. May not be null.
      eVersion - The CSS version to use. May not be null.
      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 passed IHasInputStream.
      Parameters:
      aISP - The input stream provider to use. May not be null.
      aCharset - The charset to be used. 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.
      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 passed IHasInputStream.
      Parameters:
      aISP - The input stream provider to use. May not be null.
      aCharset - The charset to be used. 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.
      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 passed IHasInputStream.
      Parameters:
      aISP - The input stream provider to use. May not be null.
      aCharset - The charset to be used. 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.
      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 passed IHasInputStream.
      Parameters:
      aISP - The input stream provider to use. May not be null.
      aCharset - The charset to be used. May not be null.
      aSettings - The settings to be used for reading the CSS. May not be null.
      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 passed InputStream.
      Parameters:
      aIS - The input stream to use. Will be closed automatically after reading - independent of success or error. May not be null.
      aCharset - The charset to be used. May not be null.
      eVersion - The CSS version to use. May not be null.
      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 passed InputStream.
      Parameters:
      aIS - The input stream to use. Will be closed automatically after reading - independent of success or error. May not be null.
      aCharset - The charset to be used. 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.
      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 passed InputStream.
      Parameters:
      aIS - The input stream to use. Will be closed automatically after reading - independent of success or error. May not be null.
      aCharset - The charset to be used. 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.
      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 passed InputStream.
      Parameters:
      aIS - The input stream to use. Will be closed automatically after reading - independent of success or error. May not be null.
      aCharset - The charset to be used. 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.
      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 passed InputStream.
      Parameters:
      aIS - The input stream to use. Will be closed automatically after reading - independent of success or error. May not be null.
      aCharset - The charset to be used. May not be null.
      aSettings - The settings to be used for reading the CSS. May not be null.
      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 passed Reader.
      Parameters:
      aReader - The reader to use. Will be closed automatically after reading - independent of success or error. May not be null.
      eVersion - The CSS version to use. May not be null.
      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 passed Reader.
      Parameters:
      aReader - The reader to use. Will be closed automatically after reading - independent of success or error. 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.
      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 passed Reader.
      Parameters:
      aReader - The reader to use. Will be closed automatically after reading - independent of success or error. 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.
      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 passed Reader.
      Parameters:
      aReader - The reader to use. Will be closed automatically after reading - independent of success or error. 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.
      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 passed Reader.
      Parameters:
      aReader - The reader to use. Will be closed automatically after reading - independent of success or error. May not be null.
      aSettings - The settings to be used for reading the CSS. May not be null.
      Returns:
      null if reading failed, the CSS declarations otherwise.
      Since:
      3.8.2