net.sf.uadetector.UserAgentStringParser Java Examples

The following examples show how to use net.sf.uadetector.UserAgentStringParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Browser.java    From frameworkium-core with Apache License 2.0 5 votes vote down vote up
/**
 * Create browser object.
 */
public Browser() {

    Optional<String> userAgent = UITestLifecycle.get().getUserAgent();
    if (userAgent.isPresent() && !userAgent.get().isEmpty()) {
        UserAgentStringParser uaParser = UADetectorServiceFactory.getResourceModuleParser();
        ReadableUserAgent agent = uaParser.parse(userAgent.get());

        this.name = agent.getName();
        this.version = agent.getVersionNumber().toVersionString();
        this.device = agent.getDeviceCategory().getName();
        this.platform = agent.getOperatingSystem().getName();
        this.platformVersion = agent.getOperatingSystem().getVersionNumber().toVersionString();

    } else {
        // Fall-back to the Property class
        if (BROWSER.isSpecified()) {
            this.name = BROWSER.getValue().toLowerCase();
        } else {
            this.name = DriverSetup.DEFAULT_BROWSER.toString();
        }
        if (BROWSER_VERSION.isSpecified()) {
            this.version = BROWSER_VERSION.getValue();
        }
        if (DEVICE.isSpecified()) {
            this.device = DEVICE.getValue();
        }
        if (PLATFORM.isSpecified()) {
            this.platform = PLATFORM.getValue();
        }
        if (PLATFORM_VERSION.isSpecified()) {
            this.platformVersion = PLATFORM_VERSION.getValue();
        }
    }
}
 
Example #2
Source File: UserAgentParserAndCache.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
private static UserAgentStringParser parserBasedOnTypeConfig(UserAgentParserConfiguration.ParserType type) {
    switch (type) {
    case CACHING_AND_UPDATING:
        logger.info("Using caching and updating user agent parser.");
        return UADetectorServiceFactory.getCachingAndUpdatingParser();
    case ONLINE_UPDATING:
        logger.info("Using online updating user agent parser.");
        return UADetectorServiceFactory.getOnlineUpdatingParser();
    case NON_UPDATING:
        logger.info("Using non-updating (resource module based) user agent parser.");
        return UADetectorServiceFactory.getResourceModuleParser();
    default:
        throw new IllegalArgumentException("Invalid user agent parser type. Valid values are: caching_and_updating, online_updating, non_updating.");
    }
}
 
Example #3
Source File: UserAgentParserAndCache.java    From divolte-collector with Apache License 2.0 4 votes vote down vote up
public UserAgentParserAndCache(final ValidatedConfiguration vc) {
    final UserAgentStringParser parser = parserBasedOnTypeConfig(vc.configuration().global.mapper.userAgentParser.type);
    this.cache = sizeBoundCacheFromLoadingFunction(parser::parse, vc.configuration().global.mapper.userAgentParser.cacheSize);
    logger.info("User agent parser data version: {}", parser.getDataVersion());
}