Class DeviceMatch

java.lang.Object
com.iizix.selector.DeviceMatch

public class DeviceMatch extends Object
Matches devices for Selectors.
Author:
Christopher Mindus
  • Field Details

    • DEV_CLASS

      public static final String DEV_CLASS
      The client environment key of the device class the client reported: "phone", "tablet" or "desktop" (iz/client.js classifyDevice); absent for a client from before v5.
      See Also:
    • DEV_OS

      public static final String DEV_OS
      The client environment key of the operating system the client reported: "iOS", "Android", "Windows", "macOS", "Linux", "ChromeOS" or "Unknown".
      See Also:
    • CLASS_PHONE

      public static final String CLASS_PHONE
      The device class of a phone.
      See Also:
    • CLASS_TABLET

      public static final String CLASS_TABLET
      The device class of a tablet.
      See Also:
    • CLASS_DESKTOP

      public static final String CLASS_DESKTOP
      The device class of a desktop or a notebook.
      See Also:
  • Constructor Details

    • DeviceMatch

      public DeviceMatch()
  • Method Details

    • getDeviceValue

      public static String getDeviceValue(EnvProps env, String key)
      Gets a value the client reported in its client environment, such as DEV_CLASS.
      Parameters:
      env - The client environment.
      key - The key.
      Returns:
      The value, or null when the client did not report it.
    • match

      public static boolean match(EnvProps envProps, String match)
      Matches a device.

      A retired or unknown match string answers false and is logged as a warning once per JVM, not at every evaluation: a selector naming one is evaluated at every panel choice.

      Parameters:
      envProps - The Client environment properties.
      match - The match string.
      Returns:
      true for match, false otherwise.
    • getDescription

      public static String getDescription(String match)
      Gets the device description for a string. This method is typically used in the Designer.
      Parameters:
      match - The match string.
      Returns:
      The description of the device matching, null for none.
    • exists

      public static boolean exists(String match)
      Checks if the match string exists.
      Parameters:
      match - The match string.
      Returns:
      true if it exists, false otherwise.
    • isRetired

      public static boolean isRetired(String match)
      Checks if the match string was retired in v5. A retired string does not exist (exists(String) is false), matches nothing and verifies as a warning, not as an error, so that a selector file naming it still loads.
      Parameters:
      match - The match string.
      Returns:
      true if it was retired, false otherwise.
    • getRetiredText

      public static String getRetiredText(String match)
      Gets what to use instead of a retired match string.
      Parameters:
      match - The match string.
      Returns:
      The replacement text, starting in lower case, or null if the string is not retired.
    • getRetiredMessage

      public static String getRetiredMessage(String match)
      Gets the message for a retired match string, as the verification and the Designer show it.
      Parameters:
      match - The match string.
      Returns:
      The message, or null if the string is not retired.
    • getRetiredMap

      public static Map<String,String> getRetiredMap()
      Gets the map of the retired match strings.
      Returns:
      A new mutable map with the retired match strings as keys and what to use instead as values.
    • getFamily

      public static String getFamily(String match)
      Gets the family of a match string, as the Designer groups them.
      Parameters:
      match - The match string.
      Returns:
      The family title, or null if the string has no known prefix.
    • getMap

      public static Map<String,String> getMap()
      Gets the map of devices that can match with this class. Retired match strings are not in it.
      Returns:
      A new mutable map with the string match as keys and descriptions as values.
    • getUserAgent

      public static String getUserAgent(EnvProps env) throws Exception
      Gets client "User Agent" string.
      Parameters:
      env - The environment for a client.
      Returns:
      The user agent string.
      Throws:
      Exception - An exception due to failure in performing the test, with a message why it failed.
    • getParsedUserAgent

      public static ua_parser.Client getParsedUserAgent(EnvProps env) throws Exception
      Gets the parsed user agent instance.
      Parameters:
      env - The environment for a client.
      Returns:
      The parsed user agent for the client, a cached value (i.e. parsed once only).
      Throws:
      Exception - An exception due to failure in performing the test, with a message why it failed.
    • getDeviceDetectionFromUserAgent

      public static io.github.mngsk.devicedetector.Detection getDeviceDetectionFromUserAgent(EnvProps env) throws Exception
      Gets the cached device detection instance based on the parsed user agent.
      Parameters:
      env - The environment for a client.
      Returns:
      The cached device detection instance based on the parsed user agent (i.e. parsed once only).
      Throws:
      Exception - An exception due to failure in performing the test, with a message why it failed.
    • getDeviceDetectionOperatingSystemFromUserAgent

      public static String getDeviceDetectionOperatingSystemFromUserAgent(EnvProps env) throws Exception
      Gets the Operating System from the cached device detection instance based on the parsed user agent.
      Parameters:
      env - The environment for a client.
      Returns:
      The OS.
      Throws:
      Exception - An exception due to failure in performing the test, with a message why it failed.
    • isiOS

      public static boolean isiOS(EnvProps env) throws Exception
      Check for iOS device (iPhone or iPad).
      Parameters:
      env - Environment properties
      Returns:
      true if the environment properties indicate a iOS device
      Throws:
      Exception - An exception due to failure in performing the test, with a message why it failed.
    • isAndroid

      public static boolean isAndroid(EnvProps env) throws Exception
      Check for Android device (phone or tablet).
      Parameters:
      env - Environment properties.
      Returns:
      true if the environment properties indicate a Android device.
      Throws:
      Exception - An exception due to failure in performing the test, with a message why it failed.
    • isWinPhone

      public static boolean isWinPhone(EnvProps env) throws Exception
      Check for Windows Phone.
      Parameters:
      env - Environment properties.
      Returns:
      true if the environment properties indicate a Windows Phone.
      Throws:
      Exception - An exception due to failure in performing the test, with a message why it failed.
    • isMac

      public static boolean isMac(EnvProps env) throws Exception
      Check for Mac OS device.
      Parameters:
      env - Environment properties.
      Returns:
      true if the environment properties indicate a Mac device.
      Throws:
      Exception - An exception due to failure in performing the test, with a message why it failed.
    • isDesktop

      @Deprecated public static boolean isDesktop(EnvProps env) throws Exception
      Deprecated.
      Use the method {@link #getDeviceDetectionFromUserAgent(EnvProps)}.isDesktop() instead.
      Check for desktop device.

      This method returns the value from {@link #getDeviceDetectionFromUserAgent(EnvProps)}.isDesktop().

      Parameters:
      env - Environment properties
      Returns:
      true if the environment properties indicate a desktop device
      Throws:
      Exception - An exception due to failure in performing the test, with a message why it failed.
    • getSelectorMatch

      public static String getSelectorMatch(String userAgent)
      Generate output for a User Agent with every possible selector match. OS and device information is also appended. New lines separate entries.
      Parameters:
      userAgent - The user agent string.
      Returns:
      The formatted string.