Class DeviceMatcher


  • public class DeviceMatcher
    extends java.lang.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 Summary

      Constructors 
      ConstructorDescription
      DeviceMatcher()
      Constructs the device matcher.
    • Constructor Detail

      • DeviceMatcher

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

      • getInstance

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

        public void loadFile​(java.net.URL url)
                      throws java.io.IOException,
                             org.xml.sax.SAXException
        Opens the XML file and loads topics from it. Previously loaded topics are kept.
        Parameters:
        url - The file to load.
        Throws:
        org.xml.sax.SAXException - For parser errors.
        java.io.IOException - For I/O exception or if XML file is in wrong format.
      • hasTopic

        public boolean hasTopic​(java.lang.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​(java.lang.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.