解析引擎类型

@param userAgentString User-Agent字符串
@return 引擎类型
325667
private static Engine parseEngine(String userAgentString) {
		for (Engine engine : Engine.engines) {
			if (engine.isMatch(userAgentString)) {
				return engine;
			}
		}
		return Engine.Unknown;
	}
708540
private static URI buildDefaultURI(final String userId) {
        // Construct the default URI for the user ID that is not a URI.
        String userAgentBaseUri = System.getProperty(USER_AGENT_BASE_URI_PROPERTY);
        if (isNullOrEmpty(userAgentBaseUri)) {
            // use the default local user agent base uri
            userAgentBaseUri = DEFAULT_USER_AGENT_BASE_URI;
        }

        final String userAgentUri = userAgentBaseUri + userId;

        LOGGER.trace("Default URI is created for user {}: {}", userId, userAgentUri);
        return URI.create(userAgentUri);
    }
126510
def _extract_info_from_useragent(user_agent):
    """"""
    parsed_string = user_agent_parser.Parse(user_agent)
    return {
        'os': parsed_string.get('os', {}).get('family'),
        'browser': parsed_string.get('user_agent', {}).get('family'),
        'browser_version': parsed_string.get('user_agent', {}).get('major'),
        'device': parsed_string.get('device', {}).get('family'),
    }
206358
public static List<String> getCallbackUserRoles(UserGroupCallback userGroupCallback, String userId) {
		List<String> roles = userGroupCallback != null ? userGroupCallback.getGroupsForUser(userId) : new ArrayList<>();
		if (roles == null || roles.isEmpty()) {
			roles = new ArrayList<>();
			roles.add("");
		}

		return roles;
	}
347346
public synchronized UserAgent getUserAgent() {
    if (this.userAgent == null) {
      if (isService) {
        this.userAgent =
            new UserAgent(
                this.serviceName,
                this.projectId,
                this.sslEnabled,
                this.nfvoIp,
                this.nfvoPort,
                this.version,
                this.serviceKey);
      } else {
        this.userAgent =
            new UserAgent(
                this.username,
                this.password,
                this.projectId,
                this.sslEnabled,
                this.nfvoIp,
                this.nfvoPort,
                this.version);
      }
    }
    return this.userAgent;
  }
984269
public function cleanUserAgentString($userAgentString)
  {
    // clean up the string
    $userAgentString = trim(strtolower($userAgentString));

    // replace browser names with their aliases
    $userAgentString = strtr($userAgentString, $this->getKnownBrowserAliases());

    // replace operating system names with their aliases
    $userAgentString = strtr($userAgentString, $this->getKnownOperatingSystemAliases());

    // replace engine names with their aliases
    $userAgentString = strtr($userAgentString, $this->getKnownEngineAliases());

    return $userAgentString;
  }
606428
public function getMostSpecific(array $userAgents)
    {
        $array = [];
        foreach ($userAgents as $string) {
            // Strip non-US-ASCII characters
            $array[$string] = strtolower($this->strip($string));
        }
        foreach (array_map('strtolower', $this->getUserAgents()) as $generated) {
            if (($result = array_search($generated, $array)) !== false) {
                // Match found
                return $result;
            }
        }
        return false;
    }
844770
protected function doParse($userAgentString)
  {
    $userAgent = array(
      'string'            => $this->cleanUserAgentString($userAgentString),
      'browser_name'      => null,
      'browser_version'   => null,
      'operating_system'  => null,
      'engine'            => null
    );

    if(empty($userAgent['string']))
    {
      return $userAgent;
    }

    // build regex that matches phrases for known browsers
    // (e.g. "Firefox/2.0" or "MSIE 6.0" (This only matches the major and minor
    // version numbers.  E.g. "2.0.0.6" is parsed as simply "2.0"
    $pattern = '#('.join('|', $this->getKnownBrowsers()).')[/ ]+([0-9]+(?:\.[0-9]+)?)#';

    // Find all phrases (or return empty array if none found)
    if (preg_match_all($pattern, $userAgent['string'], $matches))
    {
      // Since some UAs have more than one phrase (e.g Firefox has a Gecko phrase,
      // Opera 7,8 have a MSIE phrase), use the last one found (the right-most one
      // in the UA).  That's usually the most correct.
      $i = count($matches[1])-1;

      if (isset($matches[1][$i]))
      {
        $userAgent['browser_name'] = $matches[1][$i];
      }
      if (isset($matches[2][$i]))
      {
        $userAgent['browser_version'] = $matches[2][$i];
      }
    }

    // Find operating system
    $pattern = '#'.join('|', $this->getKnownOperatingSystems()).'#';
    
    if (preg_match($pattern, $userAgent['string'], $match))
    {
      if (isset($match[0]))
      {
        $userAgent['operating_system'] = $match[0];
      }
    }

    // Find engine
    $pattern = '#'.join('|', $this->getKnownEngines()).'#';
    
    if (preg_match($pattern, $userAgent['string'], $match))
    {
      if (isset($match[0]))
      {
        $userAgent['engine'] = $match[0];
      }
    }

    return $userAgent;
  }
497937
function formatUserAgent(userAgent) {
	var formattedUserAgent = userAgent.toLowerCase();

	// Strip the version number from robot/1.0 user agents
	var idx = formattedUserAgent.indexOf('/');
	if (idx > -1) {
		formattedUserAgent = formattedUserAgent.substr(0, idx);
	}

	return formattedUserAgent.trim();
}
1086573
public static function getWindowsPhoneModel($userAgent)
    {
        // Normalize spaces in UA before capturing parts
        $userAgent = preg_replace('|;(?! )|', '; ', $userAgent);
        // This regex is relatively fast because there is not much backtracking, and almost all UAs will match
        if (preg_match('|IEMobile/\d+\.\d+;(?: ARM;)?(?: Touch;)? ?([^;\)]+(; ?[^;\)]+)?)|', $userAgent, $matches)
            || preg_match('|Android [\d\.]+?; ([^;\)]+(; ?[^;\)]+)?).+?Edge/\d|', $userAgent, $matches)
        ) {
            $model = $matches[1];
            // Some UAs contain '_blocked' and that string causes matching errors:
            //   Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.5; Trident/3.1; IEMobile/7.0; LG_blocked; LG-E900)
            //   Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG_blocked_blocked_blocked_blocked; SGH-i937)
            //   Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG_blocked_blocked; SGH-i917)
            //   Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG_blocked_blocked; SGH-i937)
            //   Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG_blocked; OMNIA7)
            //   Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG_blocked; SGH-i917)
            $model = str_replace('_blocked', '', $model);

            // Nokia Windows Phone 7.5/8 'RM-' devices make matching particularly difficult:
            //   Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; RM-821_eu_euro1)
            //   Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; RM-821_eu_euro2_248)
            //   Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; RM-824_nam_att_100)
            //   Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; RM-821_eu_euro1_276)
            //   Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; RM-821_eu_euro1_292)
            //   Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; RM-821_eu_euro2_224)
            //   Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; RM-821_eu_euro2_248)
            //   Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; RM-821_eu_sweden_235)
            $model = preg_replace('/(NOKIA; RM-.+?)_.*/', '$1', $model, 1);

            //Doing the same normalization as above for Microsoft branded devices (RIP Nokia!)
            $model = preg_replace('/(Microsoft; RM-.+?)_.*/', '$1', $model, 1);

            return $model;
        }

        return null;
    }
974495
public ActionString getUserDataString(String value) {
        if (value == null) {
            return null;
        }
        ActionString output = null;
        if (mapAllMethods != null) {
            // handle all methods case.
            output = getUserDataStringFromAllMap(mapAllMethods, value);
        } else {
            output = getUserDataStringFromMethodsMap(value);
        }
        if (tc.isDebugEnabled())
            Tr.debug(tc, "getUserDataString output: " + output);
        return output;
    }
254421
function (cb) {
        if (AmazonMws.USER_AGENT_SERIALIZED) {
            return cb(AmazonMws.USER_AGENT_SERIALIZED);
        }
        this.getClientUserAgentSeeded(AmazonMws.USER_AGENT, function (cua) {
            AmazonMws.USER_AGENT_SERIALIZED = cua;
            cb(AmazonMws.USER_AGENT_SERIALIZED);
        });
    }
1106807
public AgentProperties findParametersForAzure( Logger logger ) {
		logger.info( "User data are being retrieved for Microsoft Azure..." );

		String userData = "";
		try {
			// Get the user data from /var/lib/waagent/ovf-env.xml and decode it
			String userDataEncoded = getValueOfTagInXMLFile( "/var/lib/waagent/ovf-env.xml", "CustomData" );
			userData = new String( Base64.decodeBase64( userDataEncoded.getBytes( StandardCharsets.UTF_8 )), "UTF-8" );

		} catch( IOException | ParserConfigurationException | SAXException e ) {
			logger.severe( "The agent properties could not be read. " + e.getMessage());
			Utils.logException( logger, e );
		}

		// Get the public IP Address from /var/lib/waagent/SharedConfig.xml
		AgentProperties result = null;
		String publicIPAddress;
		try {
			result = AgentProperties.readIaasProperties( userData, logger );
			publicIPAddress = getSpecificAttributeOfTagInXMLFile( "/var/lib/waagent/SharedConfig.xml", "Endpoint", "loadBalancedPublicAddress" );
			result.setIpAddress( publicIPAddress );

		} catch( ParserConfigurationException | SAXException e ) {
			logger.severe( "The agent could not retrieve a public IP address. " + e.getMessage());
			Utils.logException( logger, e );

		} catch( IOException e ) {
			logger.severe( "The agent could not retrieve its configuration. " + e.getMessage());
			Utils.logException( logger, e );
		}

		return result;
	}
1291786
function(userAgent){
		var ua = parser.setUA(userAgent).getResult();
		//console.log(ua);
		var approval = true;
		_.each(ExcludeDevices, function(a) {
			//if(typeof(a.device) != 'undefined') console.log(ua.device.type + " ?? " + a.device.type);
			if(typeof(a.browser) != 'undefined' && ua.browser.name == a.browser.name && ua.browser.major < a.browser.major) {
				// The user's browser is too old.
				console.log(ua.browser.name + " v." + ua.browser.major + " is too old major version");
				approval = false;
			} else if(typeof(a.device) != 'undefined' && ua.device.type == a.device.type) {
				// The user's devices is not allowed
				console.log(ua.device.type + " is not allowed");
				approval = false;
			} else {
				//return true;
			}
		});
		return approval;
	}
22141
@Nonnull
  private static UserAgentElementList _decryptUserAgent (@Nonnull final String sUserAgent)
  {
    final UserAgentElementList ret = new UserAgentElementList ();
    final StringScanner aSS = new StringScanner (sUserAgent.trim ());
    while (true)
    {
      aSS.skipWhitespaces ();
      final int nIndex = aSS.findFirstIndex ('/', ' ', '[', '(');
      if (nIndex == -1)
        break;

      switch (aSS.getCharAtIndex (nIndex))
      {
        case '/':
        {
          // e.g. "a/b"
          final String sKey = aSS.getUntilIndex (nIndex);
          final String sValue = aSS.skip (1).getUntilWhiteSpace ();
          final String sFullValue = sKey + "/" + sValue;
          // Special handling of URLs :)
          if (URLProtocolRegistry.getInstance ().hasKnownProtocol (sFullValue))
            ret.add (sFullValue);
          else
            ret.add (Pair.create (sKey, sValue));
          break;
        }
        case ' ':
        {
          // e.g. "Opera 6.03"
          // e.g. "HTC_P3700 Opera/9.50 (Windows NT 5.1; U; de)"
          final String sText = aSS.getUntilIndex (nIndex).trim ();
          final Matcher aMatcher = RegExHelper.getMatcher ("([^\\s]+)\\s+([0-9]+\\.[0-9]+)", sText);
          if (aMatcher.matches ())
            ret.add (Pair.create (aMatcher.group (1), aMatcher.group (2)));
          else
            ret.add (sText);
          break;
        }
        case '[':
        {
          // e.g. "[en]"
          aSS.setIndex (nIndex).skip (1); // skip incl. "["
          ret.add (aSS.getUntil (']'));
          aSS.skip (1);
          break;
        }
        case '(':
        {
          // e.g. "(compatible; MSIE 5.0; Windows 2000)"
          aSS.setIndex (nIndex).skip (1); // skip incl. "("
          final String sParams = aSS.getUntilBalanced (1, '(', ')');

          // convert to ";" separated list
          final ICommonsList <String> aParams = StringHelper.getExploded (';', sParams);
          ret.add (aParams.getAllMapped (String::trim));
          break;
        }
        default:
          throw new IllegalStateException ("Invalid character: " + aSS.getCharAtIndex (nIndex));
      }
    }

    // add all remaining parts as is
    final String sRest = aSS.getRest ().trim ();
    if (sRest.length () > 0)
      ret.add (sRest);
    return ret;
  }
1144940
protected function parseUserAgent($userAgentString)
    {
        $parser = new WhichBrowser\Parser($userAgentString);

        if (!$parser->isDetected()) {
            return;
        }

        if ($parser->isType('mobile')) {
            $this->setType('mobile');
        } elseif ($parser->isType('tablet')) {
            $this->setType('tablet');
        } elseif ($parser->isType('desktop')) {
            $this->setType('pc');
        } else {
            $this->setType('other');
        }

        if ($parser->isOs('Android')) {
            $this->setOperatingSystem('android');
        } elseif ($parser->isOs('iOS')) {
            $this->setOperatingSystem('ios');
        } elseif ($parser->isOs('Windows')) {
            $this->setOperatingSystem('windows');
        } elseif ($parser->isOs('Windows Phone')) {
            $this->setOperatingSystem('windows-mobile');
        } else {
            $this->setOperatingSystem('other');
        }
    }
686745
public void setUserAgent(String userAgent) {
        this.userAgent = userAgent.toLowerCase();

        // Re-order the set
        Set<UserAgentDirectives> replace = new TreeSet<UserAgentDirectives>(
            new UserAgentDirectives.UserAgentComparator(this.userAgent));
        replace.addAll(rules);
        rules = replace;
    }