001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.http; 014 015import static org.apache.juneau.http.Constants.*; 016 017import org.apache.juneau.http.annotation.*; 018import org.apache.juneau.internal.*; 019 020 021/** 022 * Represents a parsed <l>Accept-Charset</l> HTTP request header. 023 * 024 * <p> 025 * Character sets that are acceptable. 026 * 027 * <h5 class='figure'>Example</h5> 028 * <p class='bcode w800'> 029 * Accept-Charset: utf-8 030 * </p> 031 * 032 * <h5 class='topic'>RFC2616 Specification</h5> 033 * 034 * The Accept-Charset request-header field can be used to indicate what character sets are acceptable for the response. 035 * 036 * <p> 037 * This field allows clients capable of understanding more comprehensive or special- purpose character sets to signal 038 * that capability to a server which is capable of representing documents in those character sets. 039 * <p class='bcode w800'> 040 * Accept-Charset = "Accept-Charset" ":" 041 * 1#( ( charset | "*" )[ ";" "q" "=" qvalue ] ) 042 * </p> 043 * 044 * <p> 045 * Character set values are described in section 3.4. Each charset MAY be given an associated quality value which 046 * represents the user's preference for that charset. 047 * The default value is q=1. 048 * An example is... 049 * <p class='bcode w800'> 050 * Accept-Charset: iso-8859-5, unicode-1-1;q=0.8 051 * </p> 052 * 053 * <p> 054 * The special value "*", if present in the Accept-Charset field, matches every character set (including ISO-8859-1) 055 * which is not mentioned elsewhere in the Accept-Charset field. 056 * 057 * <p> 058 * If no "*" is present in an Accept-Charset field, then all character sets not explicitly mentioned get a quality 059 * value of 0, except for ISO-8859-1, which gets a quality value of 1 if not explicitly mentioned. 060 * 061 * <p> 062 * If no Accept-Charset header is present, the default is that any character set is acceptable. 063 * 064 * <p> 065 * If an Accept-Charset header is present, and if the server cannot send a response which is acceptable according to 066 * the Accept-Charset header, then the server SHOULD send an error response with the 406 (not acceptable) status code, 067 * though the sending of an unacceptable response is also allowed. 068 * 069 * <ul class='seealso'> 070 * <li class='extlink'>{@doc RFC2616} 071 * </ul> 072 */ 073@Header("Accept-Charset") 074public final class AcceptCharset extends HeaderRangeArray { 075 076 private static final Cache<String,AcceptCharset> cache = new Cache<>(NOCACHE, CACHE_MAX_SIZE); 077 078 /** 079 * Returns a parsed <c>Accept-Charset</c> header. 080 * 081 * @param value The <c>Accept-Charset</c> header string. 082 * @return The parsed <c>Accept-Charset</c> header, or <jk>null</jk> if the string was null. 083 */ 084 public static AcceptCharset forString(String value) { 085 if (value == null) 086 return null; 087 AcceptCharset a = cache.get(value); 088 if (a == null) 089 a = cache.put(value, new AcceptCharset(value)); 090 return a; 091 } 092 093 private AcceptCharset(String value) { 094 super(value); 095 } 096}