This commit is contained in:
Sebastian Sdorra
2015-02-10 21:05:38 +01:00
parent e5184ac6a0
commit 919f5843d4
3 changed files with 56 additions and 65 deletions

View File

@@ -45,6 +45,8 @@ import static com.google.common.base.Preconditions.*;
import java.nio.charset.Charset; import java.nio.charset.Charset;
/** /**
* The software agent that is acting on behalf of a user. The user agent
* represents a browser or one of the repository client (svn, git or hg).
* *
* @author Sebastian Sdorra <s.sdorra@gmail.com> * @author Sebastian Sdorra <s.sdorra@gmail.com>
* @since 1.45 * @since 1.45
@@ -53,7 +55,7 @@ public final class UserAgent
{ {
/** /**
* Constructs ... * Constructs a new user agent
* *
* *
* @param name * @param name
@@ -71,12 +73,12 @@ public final class UserAgent
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
* Method description * Returns the {@link Builder} for the UserAgent.
* *
* *
* @param name * @param name name of the UserAgent
* *
* @return * @return builder for UserAgent
*/ */
public static Builder builder(String name) public static Builder builder(String name)
{ {
@@ -84,12 +86,7 @@ public final class UserAgent
} }
/** /**
* Method description * {@inheritDoc}
*
*
* @param obj
*
* @return
*/ */
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj)
@@ -112,10 +109,7 @@ public final class UserAgent
} }
/** /**
* Method description * {@inheritDoc}
*
*
* @return
*/ */
@Override @Override
public int hashCode() public int hashCode()
@@ -124,10 +118,7 @@ public final class UserAgent
} }
/** /**
* Method description * {@inheritDoc}
*
*
* @return
*/ */
@Override @Override
public String toString() public String toString()
@@ -144,10 +135,10 @@ public final class UserAgent
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/** /**
* Method description * Returns the {@link Charset}, which is used to decode the basic
* authentication header.
* *
* * @return {@link Charset} for basic authentication
* @return
*/ */
public Charset getBasicAuthenticationCharset() public Charset getBasicAuthenticationCharset()
{ {
@@ -155,10 +146,10 @@ public final class UserAgent
} }
/** /**
* Method description * Returns the name of UserAgent.
* *
* *
* @return * @return name of UserAgent
*/ */
public String getName() public String getName()
{ {
@@ -166,10 +157,10 @@ public final class UserAgent
} }
/** /**
* Method description * Returns {@code true} if UserAgent is a browser.
* *
* *
* @return * @return {@code true} if UserAgent is a browser
*/ */
public boolean isBrowser() public boolean isBrowser()
{ {
@@ -179,20 +170,16 @@ public final class UserAgent
//~--- inner classes -------------------------------------------------------- //~--- inner classes --------------------------------------------------------
/** /**
* Class description * Builder class for {@link UserAgent}.
*
*
* @version Enter version here..., 14/10/15
* @author Enter your name here...
*/ */
public static class Builder public static class Builder
{ {
/** /**
* Constructs ... * Constructs a new UserAgent builder.
* *
* *
* @param name * @param name name of the UserAgent
*/ */
public Builder(String name) public Builder(String name)
{ {
@@ -202,12 +189,12 @@ public final class UserAgent
//~--- methods ------------------------------------------------------------ //~--- methods ------------------------------------------------------------
/** /**
* Method description * Sets {@link Charset} which is used to decode the basic authentication.
* *
* *
* @param basicAuthenticationCharset * @param basicAuthenticationCharset charset for basic authentication
* *
* @return * @return {@code this}
*/ */
public Builder basicAuthenticationCharset( public Builder basicAuthenticationCharset(
Charset basicAuthenticationCharset) Charset basicAuthenticationCharset)
@@ -219,12 +206,12 @@ public final class UserAgent
} }
/** /**
* Method description * Set to {@code true} if the {@link UserAgent} is a browser.
* *
* *
* @param browser * @param browser {@code true} for a browser
* *
* @return * @return {@code this}
*/ */
public Builder browser(boolean browser) public Builder browser(boolean browser)
{ {
@@ -234,10 +221,10 @@ public final class UserAgent
} }
/** /**
* Method description * Builds the {@link UserAgent}.
* *
* *
* @return * @return new {@link UserAgent}
*/ */
public UserAgent build() public UserAgent build()
{ {
@@ -246,25 +233,25 @@ public final class UserAgent
//~--- fields ------------------------------------------------------------- //~--- fields -------------------------------------------------------------
/** Field description */ /** name of UserAgent */
private final String name; private final String name;
/** Field description */ /** indicator for browsers */
private boolean browser = true; private boolean browser = true;
/** Field description */ /** basic authentication charset */
private Charset basicAuthenticationCharset = Charsets.ISO_8859_1; private Charset basicAuthenticationCharset = Charsets.ISO_8859_1;
} }
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */ /** basic authentication charset */
private final Charset basicAuthenticationCharset; private final Charset basicAuthenticationCharset;
/** Field description */ /** indicator for browsers */
private final boolean browser; private final boolean browser;
/** Field description */ /** name of UserAgent */
private final String name; private final String name;
} }

View File

@@ -55,6 +55,8 @@ import java.util.Set;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
/** /**
* Parser for User-Agent header. The UserAgentParser parses the User-Agent
* header and returns a {@link UserAgent} object.
* *
* @author Sebastian Sdorra <s.sdorra@gmail.com> * @author Sebastian Sdorra <s.sdorra@gmail.com>
* @since 1.45 * @since 1.45
@@ -63,26 +65,26 @@ import javax.servlet.http.HttpServletRequest;
public final class UserAgentParser public final class UserAgentParser
{ {
/** Field description */ /** name of the cache */
@VisibleForTesting @VisibleForTesting
static final String CACHE_NAME = "sonia.scm.user-agent"; static final String CACHE_NAME = "sonia.scm.user-agent";
/** Field description */ /** unknown UserAgent */
@VisibleForTesting @VisibleForTesting
static final UserAgent UNKNOWN = UserAgent.builder("UNKNOWN").build(); static final UserAgent UNKNOWN = UserAgent.builder("UNKNOWN").build();
/** Field description */ /** logger */
private static final Logger logger = private static final Logger logger =
LoggerFactory.getLogger(UserAgentParser.class); LoggerFactory.getLogger(UserAgentParser.class);
//~--- constructors --------------------------------------------------------- //~--- constructors ---------------------------------------------------------
/** /**
* Constructs ... * Constructs a new UserAgentParser.
* *
* *
* @param providers * @param providers set of providers
* @param cacheManager * @param cacheManager cache manager
*/ */
@Inject @Inject
public UserAgentParser(Set<UserAgentProvider> providers, public UserAgentParser(Set<UserAgentProvider> providers,
@@ -96,12 +98,12 @@ public final class UserAgentParser
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
* Method description * Extracts the User-Agent header and returns an {@link UserAgent} object.
* *
* *
* @param request * @param request http request
* *
* @return * @return {@link UserAgent} object
*/ */
public UserAgent parse(HttpServletRequest request) public UserAgent parse(HttpServletRequest request)
{ {
@@ -109,12 +111,12 @@ public final class UserAgentParser
} }
/** /**
* Method description * Parses the User-Agent header and returns a {@link UserAgent} object.
* *
* *
* @param userAgent * @param userAgent User-Agent header
* *
* @return * @return {@link UserAgent} object
*/ */
public UserAgent parse(String userAgent) public UserAgent parse(String userAgent)
{ {
@@ -138,7 +140,7 @@ public final class UserAgentParser
ua = UNKNOWN; ua = UNKNOWN;
} }
// cache.put(uas, ua); cache.put(uas, ua);
} }
logger.trace("return user-agent {} for {}", ua, userAgent); logger.trace("return user-agent {} for {}", ua, userAgent);
@@ -148,9 +150,9 @@ public final class UserAgentParser
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */ /** cache for parsed UserAgents */
private final Cache<String, UserAgent> cache; private final Cache<String, UserAgent> cache;
/** Field description */ /** set of providers */
private final Set<UserAgentProvider> providers; private final Set<UserAgentProvider> providers;
} }

View File

@@ -36,8 +36,10 @@ package sonia.scm.web;
import sonia.scm.plugin.ExtensionPoint; import sonia.scm.plugin.ExtensionPoint;
/** /**
* Provider to parse User-Agent header and returns an {@link UserAgent} object.
* The {@link UserAgentProvider} is used by the {@link UserAgentParser}.
* *
* @author Sebastian Sdorra <sebastian.sdorra@gmail.com> * @author Sebastian Sdorra <s.sdorra@gmail.com>
* @since 1.45 * @since 1.45
*/ */
@ExtensionPoint(multi = true) @ExtensionPoint(multi = true)
@@ -45,12 +47,12 @@ public interface UserAgentProvider
{ {
/** /**
* Method description * Parses the User-Agent header and returns a {@link UserAgent} object.
* *
* *
* @param userAgentString * @param userAgentString User-Agent header
* *
* @return * @return {@link UserAgent} object
*/ */
public UserAgent parseUserAgent(String userAgentString); public UserAgent parseUserAgent(String userAgentString);
} }