Java Code Examples for net.sf.uadetector.ReadableUserAgent

The following examples show how to use net.sf.uadetector.ReadableUserAgent. These examples are extracted from open source projects. 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 Project: attic-apex-malhar   Source File: UserAgentExtractor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ReadableUserAgent parse(final String userAgentString)
{
  ReadableUserAgent result = cache.getIfPresent(userAgentString);
  if (result == null) {
    result = parser.parse(userAgentString);
    cache.put(userAgentString, result);
  }
  return result;
}
 
Example 2
Source Project: attic-apex-malhar   Source File: UserAgentExtractor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> extractInformation(Object value)
{
  Map<String, Object> m = new HashMap<String, Object>();
  ReadableUserAgent agent = parser.parse(value.toString());
  m.put("browser", agent.getName());
  m.put("os", agent.getOperatingSystem().getName());
  return m;
}
 
Example 3
Source Project: frameworkium-core   Source File: Browser.java    License: 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 4
private DeviceInfo _getDeviceInfo(String userAgent) {
	DeviceInfo deviceInfo = new DeviceInfo();
    if (userAgent == null) {
        return deviceInfo;
    }

    ReadableUserAgent agent = parser.parse(userAgent);

    String deviceCategory = agent.getDeviceCategory().getName();

    OperatingSystem operatingSystem = agent.getOperatingSystem();
    String osFamily = operatingSystem.getFamilyName();
    String osVersion = operatingSystem.getVersionNumber().toVersionString();


    String userAgentName =  agent.getName();
    String userAgentType = agent.getTypeName();
    String userAgentFamily = agent.getFamily().getName();
    String userAgentVersion = agent.getVersionNumber().toVersionString();

    deviceInfo.setDeviceCategory(deviceCategory);
    deviceInfo.setOsFamily(osFamily);
    deviceInfo.setOsVersion(osVersion);
    deviceInfo.setUserAgent(userAgentName);
    deviceInfo.setUserAgentType(userAgentType);
    deviceInfo.setUserAgentFamily(userAgentFamily);
    deviceInfo.setUserAgentVersion(userAgentVersion);

    return deviceInfo;
}
 
Example 5
Source Project: divolte-collector   Source File: UserAgentParserAndCache.java    License: Apache License 2.0 5 votes vote down vote up
public Optional<ReadableUserAgent> tryParse(final String userAgentString) {
    try {
        return Optional.of(cache.get(userAgentString));
    } catch (final ExecutionException e) {
        logger.debug("Failed to parse user agent string for: " + userAgentString);
        return Optional.empty();
    }
}
 
Example 6
Source Project: divolte-collector   Source File: DslRecordMapping.java    License: Apache License 2.0 4 votes vote down vote up
UserAgentValueProducer(final ValueProducer<String> source, final UserAgentParserAndCache parser) {
    super("userAgent()",
          ReadableUserAgent.class,
          (e, c) -> source.produce(e, c).flatMap(parser::tryParse),
          true);
}
 
Example 7
Source Project: divolte-collector   Source File: DslRecordMapping.java    License: Apache License 2.0 4 votes vote down vote up
public ValueProducer<String> name() {
    return new PrimitiveValueProducer<>(identifier + ".name()",
                                        String.class,
                                        (e,c) -> produce(e, c).map(ReadableUserAgent::getName));
}
 
Example 8
Source Project: divolte-collector   Source File: DslRecordMapping.java    License: Apache License 2.0 4 votes vote down vote up
public ValueProducer<String> vendor() {
    return new PrimitiveValueProducer<>(identifier + ".vendor()",
                                        String.class,
                                        (e,c) -> produce(e, c).map(ReadableUserAgent::getProducer));
}