Class DeviceMatcher

java.lang.Object
com.iizix.selector.DeviceMatcher

public class DeviceMatcher extends Object
Class that loads an external XML file for device matching.

The matching is done on one or more of:

  id             origin                      description
  --------       -------------------------   -----------------------------
  ua             env: navigator.userAgent    User agent
  pua/os.family  env: navigator.userAgent    User agent (os.family: parsed with ua-parser)
  pua/os.major   env: navigator.userAgent    User agent (os.major:  parsed with ua-parser)
  ptf:           env: navigator.platform     Platform
  dd:            env: device.diagonal        Device size
  sw:            env: screen.width           Screen width
  sh:            env: screen.height          Screen height
  saw:           env: screen.availableWidth  Screen available width
  sah:           env: screen.availableHeight Screen available height           
  cap:           capability: name            Capability name    
  

  • Matching topic is defined as:
          {topic name="nnn"}
            ...devices...
          {/topic}
        
  • Device tag as:
          {device name="nnn"}
            ...match...
          {/device}
        
  • Verification can be combined with "or" or "and":
          {or [negate="true"]}
            {and [negate="true"]}
              {string id="nnn" match="iPad" type="equals"/}
              {value id="mmm" min="100" max="200"/}
            {/and}
            {value id="abc" min="10" max="20"/}
          {/or}
        
  • String matching:
    {string id="nnn" match="string" type="type" [case="false"] [negate="true"]/}
    where type is "equals", "in" (like indexOf or contains), "wild" or "regexp".
    case="false" means case insensitive match.
  • Value matching
    {value id="nnn" [min="value"] [max="value"] [negate="true"]/}.
  • Negation of match
    [negate="true"] on any tag means that the match is negated (boolean NOT).
Author:
Christopher Mindus
  • Constructor Details

    • DeviceMatcher

      public DeviceMatcher()
      Constructs the device matcher.
  • Method Details

    • getInstance

      public static DeviceMatcher getInstance()
      Gets the singleton.
    • hasTopic

      public boolean hasTopic(String topic)
      Verifies that a topic is present.
      Parameters:
      topic - The topic name.
      Returns:
      true if topic is present in the DeviceMatcher.xml file.
    • isMatching

      public boolean isMatching(String topic, IInfoProvider info)
      Matches a topic. A severe error is logged if the topic is not found.
      Parameters:
      topic - The topic name.
      info - The information provider.
      Returns:
      The match flag.