Class MediaQueryTools


  • @Immutable
    public final class MediaQueryTools
    extends Object
    A small utility class to wrap an existing CascadingStyleSheet within a specific media, if possible. CascadingStyleSheet can only be wrapped, if they don't contain a media rule themselves.
    Author:
    Philip Helger
    • Method Detail

      • parseToMediaQuery

        @Nullable
        public static com.helger.commons.collection.impl.ICommonsList<CSSMediaQuery> parseToMediaQuery​(@Nullable
                                                                                                       String sMediaQuery,
                                                                                                       @Nonnull
                                                                                                       ECSSVersion eVersion)
        Utility method to convert a media query string to a structured list of CSSMediaQuery objects.
        Parameters:
        sMediaQuery - The media query string to parse. May be null.
        eVersion - The CSS version to use. May not be null.
        Returns:
        null if the passed media query is null or empty or not parsable.
      • canWrapInMediaQuery

        public static boolean canWrapInMediaQuery​(@Nullable
                                                  CascadingStyleSheet aCSS,
                                                  boolean bAllowNestedMediaQueries)
        Check if the passed CSS can be wrapped in an external media rule.
        Parameters:
        aCSS - The CSS to be checked for wrapping. May be null.
        bAllowNestedMediaQueries - if true nested media queries are allowed, false if they are prohibited.
        Returns:
        true if the CSS can be wrapped, false if it can't be wrapped.
      • getWrappedInMediaQuery

        @Nullable
        public static CascadingStyleSheet getWrappedInMediaQuery​(@Nonnull
                                                                 CascadingStyleSheet aCSS,
                                                                 @Nonnull
                                                                 CSSMediaQuery aMediaQuery,
                                                                 boolean bAllowNestedMediaQueries)
        Get the CSS wrapped in the specified media query. Note: all existing rule objects are reused, so modifying them also modifies the original CSS!
        Parameters:
        aCSS - The CSS to be wrapped. May not be null.
        aMediaQuery - The media query to use.
        bAllowNestedMediaQueries - if true nested media queries are allowed, false if they are prohibited.
        Returns:
        null if out CSS cannot be wrapped, the newly created CascadingStyleSheet object otherwise.
      • getWrappedInMediaQuery

        @Nullable
        public static CascadingStyleSheet getWrappedInMediaQuery​(@Nonnull
                                                                 CascadingStyleSheet aCSS,
                                                                 @Nonnull @Nonempty
                                                                 Iterable<? extends CSSMediaQuery> aMediaQueries,
                                                                 boolean bAllowNestedMediaQueries)
        Get the CSS wrapped in the specified media query. Note: all existing rule objects are reused, so modifying them also modifies the original CSS!
        Parameters:
        aCSS - The CSS to be wrapped. May not be null.
        aMediaQueries - The media queries to use. May neither be null nor empty nor may it contain null elements.
        bAllowNestedMediaQueries - if true nested media queries are allowed, false if they are prohibited.
        Returns:
        null if out CSS cannot be wrapped, the newly created CascadingStyleSheet object otherwise.