net.sf.uadetector.ReadableUserAgent Java Examples

The following examples show how to use net.sf.uadetector.ReadableUserAgent. 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: UserAgentExtractor.java    From attic-apex-malhar with 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 File: UserAgentExtractor.java    From attic-apex-malhar with 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 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 #4
Source File: DeviceEnrichmentUtil.java    From realtime-analytics with GNU General Public License v2.0 5 votes vote down vote up
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 File: UserAgentParserAndCache.java    From divolte-collector with 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 File: DslRecordMapping.java    From divolte-collector with 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 File: DslRecordMapping.java    From divolte-collector with 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 File: DslRecordMapping.java    From divolte-collector with 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));
}