org.melati.util
Class AcceptCharset

Package class diagram package AcceptCharset
java.lang.Object
  extended by org.melati.util.HttpHeader
      extended by org.melati.util.AcceptCharset

public class AcceptCharset
extends HttpHeader

Representation of the Accept-Charset header fields.

Provides features for choosing a charset according to client or server preferences.

Author:
jimw At paneris.org

Nested Class Summary
static class AcceptCharset.CharsetAndQValue
          A charset and associated qvalue.
 class AcceptCharset.CharsetAndQValueIterator
          Enumeration of AcceptCharset.CharsetAndQValue.
protected static class AcceptCharset.Comparator<T>
          Comparator for comparing AcceptCharset.CharsetAndQValue objects.
 
Nested classes/interfaces inherited from class org.melati.util.HttpHeader
HttpHeader.FieldIterator, HttpHeader.HttpHeaderException, HttpHeader.TokenAndQValue, HttpHeader.TokenAndQValueIterator, HttpHeader.Tokenizer, HttpHeader.WordIterator
 
Field Summary
protected  HashMap<String,AcceptCharset.CharsetAndQValue> supportedAcceptedOrPreferred
          Charsets supported by the jvm and accepted by the client or preferred by the server.
 
Fields inherited from class org.melati.util.HttpHeader
tokenizer
 
Constructor Summary
AcceptCharset(String values, List<String> serverPreference)
          Create an instance from the Accept-Charset header field values and a set of server preferred charset names.
 
Method Summary
 AcceptCharset.CharsetAndQValueIterator charsetAndQValueIterator()
          Factory method to create and return the next HttpHeader.TokenAndQValue.
 String choice(AcceptCharset.Comparator<AcceptCharset.CharsetAndQValue> comparator)
          If there is none, return null, and the caller can either use an unacceptable character set or generate a 406 error.
 String clientChoice()
           
 HttpHeader.TokenAndQValue nextTokenAndQValue()
          Factory method to create and return the next HttpHeader.TokenAndQValue.
 String serverChoice()
           
 
Methods inherited from class org.melati.util.HttpHeader
tokenAndQValueIterator, wordIterator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

supportedAcceptedOrPreferred

protected HashMap<String,AcceptCharset.CharsetAndQValue> supportedAcceptedOrPreferred
Charsets supported by the jvm and accepted by the client or preferred by the server.

Constructor Detail

AcceptCharset

public AcceptCharset(String values,
                     List<String> serverPreference)
Create an instance from the Accept-Charset header field values and a set of server preferred charset names.

The field values might have appeared in a single Accept-Charset header or in several that were concatenated with comma separator in order. This concatenation is often done for the caller, by a servlet container or something, but it must be done.

null is taken to mean there were no Accept-Charset header fields.

If a client supported charset is unsupported by the JVM it is ignored. If the caller wants to ensure that there are none then it must check for itself.

If the same charset is specified more than once (perhaps under different names or aliases) then the first occurrence is significant.

The server preferences provides a list of charsets used if there is a wildcard specification. This class does not currently try other available charsets so to avoid 406 errors to reasonable clients, enough reasonable charsets must be listed in serverPreferences.

Method Detail

nextTokenAndQValue

public HttpHeader.TokenAndQValue nextTokenAndQValue()
Factory method to create and return the next HttpHeader.TokenAndQValue.

Overrides:
nextTokenAndQValue in class HttpHeader
Returns:
a new TokenAndQValue
See Also:
HttpHeader.nextTokenAndQValue()

charsetAndQValueIterator

public AcceptCharset.CharsetAndQValueIterator charsetAndQValueIterator()
Factory method to create and return the next HttpHeader.TokenAndQValue.

Returns:
a new Iterator

clientChoice

public String clientChoice()
Returns:
the first supported charset that is also acceptable to the client in order of client preference.

serverChoice

public String serverChoice()
Returns:
the first supported charset also acceptable to the client in order of server preference.

choice

public String choice(AcceptCharset.Comparator<AcceptCharset.CharsetAndQValue> comparator)
If there is none, return null, and the caller can either use an unacceptable character set or generate a 406 error. see #firstOther

Returns:
the first supported charset also acceptable to the client in order defined by the given AcceptCharset.Comparator


Copyright © 2000-2010 PanEris. All Rights Reserved.