本文整理了Java中eu.bitwalker.useragentutils.Browser
类的一些代码示例,展示了Browser
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Browser
类的具体详情如下:
包路径:eu.bitwalker.useragentutils.Browser
类名称:Browser
[英]Enum constants for most common browsers, including e-mail clients and bots.
[中]大多数常见浏览器(包括电子邮件客户端和bot)的枚举常量。
代码示例来源:origin: sanluan/PublicCMS
@Override
public void execute(RenderHandler handler) throws IOException, Exception {
HttpServletRequest request = handler.getRequest();
if (null != request) {
String userAgent = RequestUtils.getUserAgent(request);
UserAgent ua = UserAgent.parseUserAgentString(userAgent);
Map<String, Object> map = new HashMap<>();
map.put("id", ua.getId());
map.put("browser", ua.getBrowser());
map.put("browserGroup", ua.getBrowser().getGroup());
map.put("browserType", ua.getBrowser().getBrowserType());
map.put("browserVersion", ua.getBrowserVersion());
map.put("operatingSystem", ua.getOperatingSystem());
map.put("operatingSystemGroup", ua.getOperatingSystem().getGroup());
map.put("deviceType", ua.getOperatingSystem().getDeviceType());
map.put("userAgent", userAgent);
handler.put("object", map).render();
}
}
代码示例来源:origin: HaraldWalker/user-agent-utils
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final UserAgent other = (UserAgent) obj;
if (browser == null) {
if (other.browser != null)
return false;
} else if (!browser.equals(other.browser))
return false;
if (id != other.id)
return false;
if (operatingSystem == null) {
if (other.operatingSystem != null)
return false;
} else if (!operatingSystem.equals(other.operatingSystem))
return false;
return true;
}
代码示例来源:origin: HaraldWalker/user-agent-utils
/**
* Combined string representation of both enums
*/
public String toString() {
return this.operatingSystem.toString() + "-" + this.browser.toString();
}
代码示例来源:origin: HaraldWalker/user-agent-utils
/**
* Returns the enum constant of this type with the specified id.
* Throws IllegalArgumentException if the value does not exist.
* @param id Id of the browser
* @return Browser enum
*/
public static Browser valueOf(short id)
{
for (Browser browser : Browser.values())
{
if (browser.getId() == id)
return browser;
}
// same behavior as standard valueOf(string) method
throw new IllegalArgumentException(
"No enum const for id " + id);
}
代码示例来源:origin: HaraldWalker/user-agent-utils
/**
* Detects the detailed version information of the browser. Depends on the userAgent to be available.
* Returns null if it can not detect the version information.
* @param userAgentString User-agent string as provided in the request.
* @return Version
*/
public Version getVersion(String userAgentString) {
if (userAgentString == null) {
return null;
}
if (versionFetcher == null) {
return getGroup() != this ? getGroup().getVersion(userAgentString) : null;
}
return versionFetcher.version(userAgentString);
}
代码示例来源:origin: HaraldWalker/user-agent-utils
public UserAgent(String userAgentString)
{
String userAgentLowercaseString = userAgentString == null ? null : userAgentString.toLowerCase();
Browser browser = Browser.parseUserAgentLowercaseString(userAgentLowercaseString);
OperatingSystem operatingSystem = OperatingSystem.UNKNOWN;
// BOTs don't have an interesting OS for us
if (browser != Browser.BOT)
operatingSystem = OperatingSystem.parseUserAgentLowercaseString(userAgentLowercaseString);
this.operatingSystem = operatingSystem;
this.browser = browser;
this.id = ((operatingSystem.getId() << 16) + browser.getId());
this.userAgentString = userAgentString;
}
代码示例来源:origin: com.gitee.morilys.jsmile/jsmile-kit
/**
* 获取用户浏览器
*
* @param request
* @return
*/
public static String getUserBrowser(HttpServletRequest request) {
UserAgent userAgent = getUserAgent(request);
String browser = "";
if (userAgent != null) {
try {
browser = userAgent.getBrowser().getName();
} catch (Exception e) {
logger.error("获取用户浏览器版本号失败!");
}
}
return browser;
}
代码示例来源:origin: brant-hwang/spring-logback-slack-notification-example
public static BrowserType getBrowserType(HttpServletRequest request) {
Browser browser = getBrowser(request);
return browser == null ? BrowserType.UNKNOWN : browser.getBrowserType();
}
代码示例来源:origin: stackoverflow.com
public class BrowserTest{
@Test
public void testNoArgsConstructor(){
Browser testedBrowser = new Browser();
assertNull(testedBrowser.getWineCase());
assertNull(testedBrowser.getWebsite());
assertEquals(00065, testedBrowser.getId());
assertEquals(1992, testedBrowser.getYearOfBirth());
assertTrue(testedBrowser.getMemberId());
assertFalse(testedBrowser.isDiscount());
}
//more tests
}
代码示例来源:origin: net.shibboleth.idp/idp-authn-api
/**
* Determines whether this user agent is an instance of the given browser.
*
* @param browser browser to check.
*
* @return True if this user agent is an instance of the given browser, false otherwise.
*/
public boolean isInstance(@Nonnull final Browser browser) {
Constraint.isNotNull(browser, "Browser cannot be null");
if (userAgent == null) {
return false;
}
return userAgent.getBrowser().getGroup().equals(browser) || userAgent.getBrowser().equals(browser);
}
代码示例来源:origin: HaraldWalker/user-agent-utils
/**
* @return top level browser family
*/
public Browser getGroup() {
if (this.parent != null) {
return parent.getGroup();
}
return this;
}
代码示例来源:origin: HaraldWalker/user-agent-utils
/**
* Iterates over all Browsers to compare the browser signature with
* the user agent string. If no match can be found Browser.UNKNOWN will
* be returned.
* Starts with the top level browsers and only if one of those matches
* checks children browsers.
* Steps out of loop as soon as there is a match.
* @param agentString User-agent sting as provided in the request.
* @return Browser enum
*/
public static Browser parseUserAgentString(String agentString)
{
return parseUserAgentString(agentString, topLevelBrowsers);
}
代码示例来源:origin: HaraldWalker/user-agent-utils
public UserAgent(OperatingSystem operatingSystem, Browser browser)
{
this.operatingSystem = operatingSystem;
this.browser = browser;
this.id = (( operatingSystem.getId() << 16) + browser.getId());
}
代码示例来源:origin: ralscha/spring4ws-demos
? ua.getBrowser().getName()
: "";
代码示例来源:origin: mcekovic/tennis-crystal-ball
private static BrowserType getAgentType(HttpServletRequest httpRequest) {
return UserAgent.parseUserAgentString(httpRequest.getHeader("User-Agent")).getBrowser().getBrowserType();
}
}
代码示例来源:origin: eu.bitwalker/UserAgentUtils
/**
* @return top level browser family
*/
public Browser getGroup() {
if (this.parent != null) {
return parent.getGroup();
}
return this;
}
代码示例来源:origin: eu.bitwalker/UserAgentUtils
/**
* Detects the detailed version information of the browser. Depends on the userAgent to be available.
* Returns null if it can not detect the version information.
* @param userAgentString User-agent string as provided in the request.
* @return Version
*/
public Version getVersion(String userAgentString) {
if (versionFetcher == null) {
return getGroup() != this ? getGroup().getVersion(userAgentString) : null;
}
return versionFetcher.version(userAgentString);
}
代码示例来源:origin: eu.bitwalker/UserAgentUtils
public UserAgent(String userAgentString)
{
String userAgentLowercaseString = userAgentString == null ? null : userAgentString.toLowerCase();
Browser browser = Browser.parseUserAgentLowercaseString(userAgentLowercaseString);
OperatingSystem operatingSystem = OperatingSystem.UNKNOWN;
// BOTs don't have an interesting OS for us
if (browser != Browser.BOT)
operatingSystem = OperatingSystem.parseUserAgentLowercaseString(userAgentLowercaseString);
this.operatingSystem = operatingSystem;
this.browser = browser;
this.id = ((operatingSystem.getId() << 16) + browser.getId());
this.userAgentString = userAgentString;
}
代码示例来源:origin: eu.bitwalker/UserAgentUtils
/**
* Returns the enum constant of this type with the specified id.
* Throws IllegalArgumentException if the value does not exist.
* @param id Id of the browser
* @return Browser enum
*/
public static Browser valueOf(short id)
{
for (Browser browser : Browser.values())
{
if (browser.getId() == id)
return browser;
}
// same behavior as standard valueOf(string) method
throw new IllegalArgumentException(
"No enum const for id " + id);
}
代码示例来源:origin: eu.bitwalker/UserAgentUtils
/**
* Iterates over all Browsers to compare the browser signature with
* the user agent string. If no match can be found Browser.UNKNOWN will
* be returned.
* Starts with the top level browsers and only if one of those matches
* checks children browsers.
* Steps out of loop as soon as there is a match.
* @param agentString User-agent sting as provided in the request.
* @return Browser enum
*/
public static Browser parseUserAgentString(String agentString)
{
return parseUserAgentString(agentString, topLevelBrowsers);
}
内容来源于网络,如有侵权,请联系作者删除!