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.internal.*; 018 019 020/** 021 * Represents a parsed <l>Accept-Charset</l> HTTP request header. 022 * 023 * <p> 024 * Character sets that are acceptable. 025 * 026 * <h5 class='figure'>Example</h5> 027 * <p class='bcode'> 028 * Accept-Charset: utf-8 029 * </p> 030 * 031 * <h5 class='topic'>RFC2616 Specification</h5> 032 * 033 * The Accept-Charset request-header field can be used to indicate what character sets are acceptable for the response. 034 * 035 * <p> 036 * This field allows clients capable of understanding more comprehensive or special- purpose character sets to signal 037 * that capability to a server which is capable of representing documents in those character sets. 038 * <p class='bcode'> 039 * Accept-Charset = "Accept-Charset" ":" 040 * 1#( ( charset | "*" )[ ";" "q" "=" qvalue ] ) 041 * </p> 042 * 043 * <p> 044 * Character set values are described in section 3.4. Each charset MAY be given an associated quality value which 045 * represents the user's preference for that charset. 046 * The default value is q=1. 047 * An example is... 048 * <p class='bcode'> 049 * Accept-Charset: iso-8859-5, unicode-1-1;q=0.8 050 * </p> 051 * 052 * <p> 053 * The special value "*", if present in the Accept-Charset field, matches every character set (including ISO-8859-1) 054 * which is not mentioned elsewhere in the Accept-Charset field. 055 * 056 * <p> 057 * If no "*" is present in an Accept-Charset field, then all character sets not explicitly mentioned get a quality 058 * value of 0, except for ISO-8859-1, which gets a quality value of 1 if not explicitly mentioned. 059 * 060 * <p> 061 * If no Accept-Charset header is present, the default is that any character set is acceptable. 062 * 063 * <p> 064 * If an Accept-Charset header is present, and if the server cannot send a response which is acceptable according to 065 * the Accept-Charset header, then the server SHOULD send an error response with the 406 (not acceptable) status code, 066 * though the sending of an unacceptable response is also allowed. 067 * 068 * <h5 class='section'>See Also:</h5> 069 * <ul class='doctree'> 070 * <li class='extlink'><a class='doclink' href='https://www.w3.org/Protocols/rfc2616/rfc2616.html'>Hypertext Transfer Protocol -- HTTP/1.1</a> 071 * </ul> 072 */ 073public final class AcceptCharset extends HeaderRangeArray { 074 075 private static final Cache<String,AcceptCharset> cache = new Cache<>(NOCACHE, CACHE_MAX_SIZE); 076 077 /** 078 * Returns a parsed <code>Accept-Charset</code> header. 079 * 080 * @param value The <code>Accept-Charset</code> header string. 081 * @return The parsed <code>Accept-Charset</code> header, or <jk>null</jk> if the string was null. 082 */ 083 public static AcceptCharset forString(String value) { 084 if (value == null) 085 return null; 086 AcceptCharset a = cache.get(value); 087 if (a == null) 088 a = cache.put(value, new AcceptCharset(value)); 089 return a; 090 } 091 092 private AcceptCharset(String value) { 093 super(value); 094 } 095}