Package eu.bitwalker.useragentutils

Examples of eu.bitwalker.useragentutils.UserAgent


    // skip if excluded
    if (excludedUserAgents.contains(userAgentString)) {
      return false;
    }

    UserAgent userAgent = parseUserAgent(userAgentString);
    if (userAgent != null) {
      switch (userAgent.getBrowser().getBrowserType()) {
        case WEB_BROWSER:
        case MOBILE_BROWSER:
        case TEXT_BROWSER:
          return true;
      }
View Full Code Here


  private UserAgent parseUserAgent(final String headerValue) {
    if (headerValue == null) {
      return null;
    }

    UserAgent userAgent = cache.getIfPresent(headerValue);
    if (userAgent == null) {
      userAgent = UserAgent.parseUserAgentString(headerValue);
      cache.put(headerValue, userAgent);
    }
    return userAgent;
View Full Code Here

  /**
   * Test method for {@link eu.bitwalker.useragentutils.UserAgent#parseUserAgentString(java.lang.String)}.
   */
  @Test
  public void testParseUserAgentString() {
    UserAgent userAgent = UserAgent.parseUserAgentString("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
    assertEquals(OperatingSystem.WINDOWS_XP, userAgent.getOperatingSystem());
    assertEquals(Browser.IE6, userAgent.getBrowser());
  }
View Full Code Here

   * Test method for {@link eu.bitwalker.useragentutils.UserAgent#parseUserAgentString(java.lang.String)}
   * that checks for proper handling of a <code>null</code> userAgentString.
   */
  @Test
  public void testParseUserAgentStringNull() {
    UserAgent userAgent = UserAgent.parseUserAgentString(null);
    assertEquals(OperatingSystem.UNKNOWN, userAgent.getOperatingSystem());
    assertEquals(Browser.UNKNOWN, userAgent.getBrowser());
    assertNull(userAgent.getBrowserVersion());
  }
View Full Code Here

  /**
   * Test method for {@link eu.bitwalker.useragentutils.UserAgent#toString()}.
   */
  @Test
  public void testToString() {
    UserAgent userAgent = UserAgent.parseUserAgentString("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
    assertEquals(OperatingSystem.WINDOWS_XP.toString() + "-" + Browser.IE6.toString(), userAgent.toString());
  }
View Full Code Here

  /**
   * Test method for {@link eu.bitwalker.useragentutils.UserAgent#valueOf(int)}.
   */
  @Test
  public void testValueOf() {
    UserAgent userAgent = UserAgent.parseUserAgentString("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
    UserAgent retrievedUserAgent = UserAgent.valueOf(userAgent.getId());
    assertEquals(userAgent, retrievedUserAgent);
  }
View Full Code Here

  /**
   * Test method for {@link eu.bitwalker.useragentutils.UserAgent#valueOf(String)}.
   */
  @Test
  public void testValueOf2() {
    UserAgent userAgent = UserAgent.parseUserAgentString("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
    UserAgent retrievedUserAgent = UserAgent.valueOf(userAgent.toString());
    assertEquals(userAgent, retrievedUserAgent);
  }
View Full Code Here

  @Override
  public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
      ModelAndView modelAndView) throws Exception {
    if(modelAndView!=null) {
      String viewName = modelAndView.getViewName();
      UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
      if(viewName.startsWith("modules/") && DeviceType.MOBILE.equals(userAgent.getOperatingSystem().getDeviceType())){
        modelAndView.setViewName(viewName.replaceFirst("modules", "mobile"));
      }
    }
  }
View Full Code Here

TOP

Related Classes of eu.bitwalker.useragentutils.UserAgent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.