本文整理汇总了Java中net.sf.uadetector.UserAgentStringParser类的典型用法代码示例。如果您正苦于以下问题:Java UserAgentStringParser类的具体用法?Java UserAgentStringParser怎么用?Java UserAgentStringParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserAgentStringParser类属于net.sf.uadetector包,在下文中一共展示了UserAgentStringParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Browser
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
/**
* Create browser object.
*/
public Browser() {
Optional<String> userAgent = BaseUITest.getUserAgent();
if (userAgent.isPresent() && !userAgent.get().isEmpty()) {
// Try to parse the UA
UserAgentStringParser uaParser = UADetectorServiceFactory.getResourceModuleParser();
ReadableUserAgent agent = uaParser.parse(userAgent.get());
// Set the params based on this agent
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();
}
}
}
示例2: cache
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
protected UADetectorCache cache(UserAgentStringParser parser) {
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder()
.maximumSize(getMaximumSize())
.expireAfterWrite(getTimeToLiveInSeconds(), TimeUnit.SECONDS);
return new GuavaCache(builder, parser);
}
示例3: cache
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
protected UADetectorCache cache(UserAgentStringParser parser) {
CacheManager cacheManager = CacheManager.getInstance();
Cache ehCache = cacheManager.getCache("uadetector");
CacheConfiguration configuration = ehCache.getCacheConfiguration();
configuration.setMemoryStoreEvictionPolicy("LRU");
configuration.setMaxEntriesLocalHeap(getMaximumSize());
configuration.setTimeToLiveSeconds(getTimeToLiveInSeconds());
return new EhCacheCache(ehCache, parser);
}
示例4: it_should_build_cached_parser_with_custom_parser
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
@Test
public void it_should_build_cached_parser_with_custom_parser() throws Exception {
CachedUserAgentStringParser cachedParser = new CachedUserAgentStringParser(parser);
UserAgentStringParser internalParser = (UserAgentStringParser) readField(cachedParser, "parser", true);
UADetectorCache internalCache = (UADetectorCache) readField(cachedParser, "cache", true);
assertThat(internalParser).isNotNull().isSameAs(parser);
assertThat(internalCache).isNotNull().isExactlyInstanceOf(SimpleCache.class);
}
示例5: it_should_build_simple_cache_with_parser
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
@Test
public void it_should_build_simple_cache_with_parser() throws Exception {
GuavaCache cache = new GuavaCache(builder, parser);
UserAgentStringParser internalParser = (UserAgentStringParser) readField(cache, "parser", true);
LoadingCache<String, ReadableUserAgent> internalCache = (LoadingCache<String, ReadableUserAgent>) readField(cache, "cache", true);
assertThat(internalParser).isNotNull().isSameAs(parser);
assertThat(internalCache).isNotNull();
assertThat(internalCache.size()).isZero();
}
示例6: it_should_build_simple_cache_with_parser
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
@Test
public void it_should_build_simple_cache_with_parser() throws Exception {
EhCacheCache cache = new EhCacheCache(ehCache, parser);
UserAgentStringParser internalParser = (UserAgentStringParser) readField(cache, "parser", true);
Ehcache internalCache = (Ehcache) readField(cache, "cache", true);
assertThat(internalParser).isNotNull().isSameAs(parser);
assertThat(internalCache).isNotNull();
assertThat(internalCache.getSize()).isZero();
}
示例7: it_should_create_entry_factory
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
@Test
public void it_should_create_entry_factory() throws Exception {
EhCacheEntryFactory factory = new EhCacheEntryFactory(parser);
UserAgentStringParser internalParser = (UserAgentStringParser) readField(factory, "parser", true);
assertThat(internalParser).isNotNull().isSameAs(parser);
}
示例8: it_should_build_simple_cache_with_parser
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
@Test
public void it_should_build_simple_cache_with_parser() throws Exception {
SimpleCache cache = new SimpleCache(parser);
UserAgentStringParser internalParser = (UserAgentStringParser) readField(cache, "parser", true);
ConcurrentMap<String, ReadableUserAgent> internalCache = (ConcurrentMap<String, ReadableUserAgent>) readField(cache, "cache", true);
assertThat(internalParser).isNotNull().isSameAs(parser);
assertThat(internalCache).isNotNull().isEmpty();
}
示例9: addContents
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
@Override
public void addContents(@NonNull Container result) {
final StaplerRequest currentRequest = Stapler.getCurrentRequest();
if (currentRequest != null) {
result.add(new PrintedContent("browser.md") {
@Override
protected void printTo(PrintWriter out) throws IOException {
out.println("Browser");
out.println("=======");
out.println();
Area screenResolution = Functions.getScreenResolution();
if (screenResolution != null) {
out.println(" * Screen size: " + screenResolution.toString());
}
UserAgentStringParser parser = UADetectorServiceFactory.getResourceModuleParser();
String userAgent = currentRequest.getHeader("User-Agent");
ReadableUserAgent agent = parser.parse(userAgent);
OperatingSystem operatingSystem = agent.getOperatingSystem();
out.println(" * User Agent");
out.println(" - Type: " + agent.getType().getName());
out.println(" - Name: " + agent.getName());
out.println(" - Family: " + agent.getFamily());
out.println(" - Producer: " + agent.getProducer());
out.println(" - Version: " + agent.getVersionNumber().toVersionString());
out.println(" - Raw: `" + userAgent.replaceAll("`", "`") + '`');
out.println(" * Operating System");
out.println(" - Name: " + operatingSystem.getName());
out.println(" - Family: " + operatingSystem.getFamily());
out.println(" - Producer: " + operatingSystem.getProducer());
out.println(" - Version: " + operatingSystem.getVersionNumber().toVersionString());
out.println();
}
});
}
}
示例10: getUADetectorExample
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
private static ReadableUserAgent getUADetectorExample(String userAgentString) {
UserAgentStringParser userAgentStringParser = UADetectorServiceFactory.getCachingAndUpdatingParser();
return userAgentStringParser.parse(userAgentString);
}
示例11: init
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
/**
* create the executor
*/
public void init() throws ServletException {
this.ipdb = RuntimeContext.injector().getInstance(IPLocationDB.class);
this.uagentParser = RuntimeContext.injector().getInstance(UserAgentStringParser.class);
}
示例12: initUserAgentParser
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
@Provides
@Singleton
private UserAgentStringParser initUserAgentParser () {
return new CachedUserAgentStringParser();
}
示例13: userAgentStringParser
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
@Bean(destroyMethod = "shutdown")
public UserAgentStringParser userAgentStringParser() {
return UADetectorServiceFactory.getResourceModuleParser();
}
示例14: userAgentStringParser
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
@Bean(destroyMethod = "shutdown")
public UserAgentStringParser userAgentStringParser() {
UserAgentStringParser parser = UADetectorServiceFactory.getResourceModuleParser();
UADetectorCache cache = cache(parser);
return new CachedUserAgentStringParser(parser, cache);
}
示例15: cache
import net.sf.uadetector.UserAgentStringParser; //导入依赖的package包/类
protected UADetectorCache cache(UserAgentStringParser parser) {
return new SimpleCache(parser);
}