springmvc-uadetector

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

License

License

GroupId

GroupId

com.github.mjeanroy
ArtifactId

ArtifactId

springmvc-uadetector
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

springmvc-uadetector
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project URL

Project URL

https://github.com/mjeanroy/springmvc-uadetector
Source Code Management

Source Code Management

https://github.com/mjeanroy/springmvc-uadetector

Download springmvc-uadetector

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mjeanroy/springmvc-uadetector/ -->
<dependency>
    <groupId>com.github.mjeanroy</groupId>
    <artifactId>springmvc-uadetector</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mjeanroy/springmvc-uadetector/
implementation 'com.github.mjeanroy:springmvc-uadetector:0.1.1'
// https://jarcasting.com/artifacts/com.github.mjeanroy/springmvc-uadetector/
implementation ("com.github.mjeanroy:springmvc-uadetector:0.1.1")
'com.github.mjeanroy:springmvc-uadetector:jar:0.1.1'
<dependency org="com.github.mjeanroy" name="springmvc-uadetector" rev="0.1.1">
  <artifact name="springmvc-uadetector" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mjeanroy', module='springmvc-uadetector', version='0.1.1')
)
libraryDependencies += "com.github.mjeanroy" % "springmvc-uadetector" % "0.1.1"
[com.github.mjeanroy/springmvc-uadetector "0.1.1"]

Dependencies

compile (4)

Group / Artifact Type Version
net.sf.uadetector : uadetector-resources jar 2014.08
org.springframework : spring-webmvc jar 4.1.0.RELEASE
com.google.guava : guava Optional jar 17.0
net.sf.ehcache : ehcache Optional jar 2.8.4

provided (1)

Group / Artifact Type Version
javax.servlet : javax.servlet-api jar 3.1.0

test (4)

Group / Artifact Type Version
junit : junit jar 4.11
org.mockito : mockito-all jar 1.9.5
org.assertj : assertj-core jar 1.6.1
org.apache.commons : commons-lang3 jar 3.3.2

Project Modules

There are no modules declared in this project.

SpringMVC-UADetectors


Simple library that can be used to wrap awesome uadetector library into your springmvc project.

Java Configuration

Just add EnableUADetector to be able to inject ReadableUserAgent arguments to your controller methods. This annotation can be configured with following parameters:

Parameter Values Description
cache NONE Do not use any cache.
DEFAULT Use simple cache provided by springmvc-uadetector (use a concurrent hashmap internally).
GUAVA Use guava cache (guava must be on classpath).
AUTO Use guava cache if guava is available or switch to simple cache implementation. This is the default.
autowire true Allow ReadableUserAgent and Browser arguments to be autowired.
false Disable autowiring of ReadableUserAgent and Browser arguments. This is the default.

Additions

In addition to ReadableUserAgent object, springmvc-uadetector allow you to use a Browser object that contains shortcuts on top of ReadableUserAgent to easily check well known browsers and specific Internet Explorer versions.

Here is a sample:

Browser browser = new Browser(readableUserAgent);

browser.isIE();
browser.isFirefox();
browser.isOpera();
browser.isSafari();
browser.isGoogleChrome();
browser.isChromium();

browser.isIE6();
browser.isIE7();
// And more...

Sample

Here is a standard spring configuration:

package com.myApp;

import org.springframework.web.servlet.config.annotation.EnableWebMvc
import com.github.mjeanroy.springmvc.uadetector.configuration.EnableUADetector;
import com.github.mjeanroy.springmvc.uadetector.configuration.UACacheProvider;

@EnableWebMvc
@EnableUADetector(autowire = true, cache = UACacheProvider.AUTO)
public class MyAppConfiguration() {
}

Here is a spring mvc controller using arguments resolvers:

package com.myApp;

import net.sf.uadetector.ReadableUserAgent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMethod;

@RestController
public class FirstController {

    /**
     * Return browser family.
     * See how an instance of ReadableUserAgent can be used as
     * a method parameter.
     *
     * @param userAgent Current user agent.
     * @return Browser Family.
     */
    @RequestMapping(value = "/ua/name", method = RequestMethod.GET)
    public String index(ReadableUserAgent userAgent) {
        return userAgent.getFamily().toString();
    }
}

Here is a spring mvc controller using autowiring:

package com.myApp;

import net.sf.uadetector.ReadableUserAgent;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMethod;

@RestController
public class SecondController {

    @Autowire
    private ReadableUserAgent userAgent;

    /**
     * Return browser family.
     * See how an instance of ReadableUserAgent is automatically
     * autowired.
     *
     * @return Browser Family.
     */
    @RequestMapping(value = "/ua/name", method = RequestMethod.GET)
    public String index() {
        return userAgent.getFamily().toString();
    }
}

Versions

Version
0.1.1
0.1.0