org.opencms.i18n
Class CmsAcceptLanguageHeaderParser

java.lang.Object
  extended by org.opencms.i18n.CmsAcceptLanguageHeaderParser
All Implemented Interfaces:
java.util.Iterator

public class CmsAcceptLanguageHeaderParser
extends java.lang.Object
implements java.util.Iterator

Parses the HTTP Accept-Language header as per section 14.4 of RFC 2068 (HTTP 1.1 header field definitions) and creates a sorted list of Locales from it.

Since:
6.0.0
Version:
$Revision: 1.22 $
Author:
Daniel Rall, Alexander Kandzior

Nested Class Summary
protected static class CmsAcceptLanguageHeaderParser.AcceptLanguage
          Struct representing an element of the HTTP Accept-Language header.
 
Field Summary
static java.lang.String ACCEPT_LANGUAGE
          A constant for the HTTP Accept-Language header.
protected static java.lang.Float DEFAULT_QUALITY
          The default m_quality value for an AcceptLanguage object.
 
Constructor Summary
CmsAcceptLanguageHeaderParser(javax.servlet.http.HttpServletRequest req, java.util.Locale defaultLocale)
          Parses the Accept-Language header from the provided request.
CmsAcceptLanguageHeaderParser(java.lang.String header, java.util.Locale defaultLocale)
          Parses the Accept-Language header.
 
Method Summary
static java.lang.String createLanguageHeader()
          Creates a value string for the HTTP Accept-Language header based on the default localed.
 java.util.List getAcceptedLocales()
          Returns the sorted list of accepted Locales.
 boolean hasNext()
           
 java.lang.Object next()
          Creates a Locale from the next element of the Accept-Language header.
 void remove()
          Not implemented.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACCEPT_LANGUAGE

public static final java.lang.String ACCEPT_LANGUAGE
A constant for the HTTP Accept-Language header.

See Also:
Constant Field Values

DEFAULT_QUALITY

protected static final java.lang.Float DEFAULT_QUALITY
The default m_quality value for an AcceptLanguage object.

Constructor Detail

CmsAcceptLanguageHeaderParser

public CmsAcceptLanguageHeaderParser(javax.servlet.http.HttpServletRequest req,
                                     java.util.Locale defaultLocale)
Parses the Accept-Language header from the provided request.

Parameters:
req - the request to parse
defaultLocale - the default locale to use

CmsAcceptLanguageHeaderParser

public CmsAcceptLanguageHeaderParser(java.lang.String header,
                                     java.util.Locale defaultLocale)
Parses the Accept-Language header.

Parameters:
header - the Accept-Language header (i.e. en, es;q=0.8, zh-TW;q=0.1)
defaultLocale - the default locale to use
Method Detail

createLanguageHeader

public static java.lang.String createLanguageHeader()
Creates a value string for the HTTP Accept-Language header based on the default localed.

Returns:
value string for the HTTP Accept-Language

getAcceptedLocales

public java.util.List getAcceptedLocales()
Returns the sorted list of accepted Locales.

Returns:
the sorted list of accepted Locales

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator
Returns:
Whether there are more locales.

next

public java.lang.Object next()
Creates a Locale from the next element of the Accept-Language header.

Specified by:
next in interface java.util.Iterator
Returns:
The next highest-rated Locale.

remove

public final void remove()
                  throws CmsIllegalArgumentException
Not implemented.

Specified by:
remove in interface java.util.Iterator
Throws:
CmsIllegalArgumentException - always to signal that remove is not implemented (interface contract defines UnsupportedOperationException)