001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.http.header; 018 019import java.util.function.*; 020 021import org.apache.juneau.*; 022import org.apache.juneau.commons.collections.*; 023import org.apache.juneau.http.annotation.*; 024 025/** 026 * Represents a parsed <l>Accept-Charset</l> HTTP request header. 027 * 028 * <p> 029 * Character sets that are acceptable. 030 * 031 * <h5 class='figure'>Example</h5> 032 * <p class='bcode'> 033 * Accept-Charset: utf-8 034 * </p> 035 * 036 * <h5 class='topic'>RFC2616 Specification</h5> 037 * 038 * The Accept-Charset request-header field can be used to indicate what character sets are acceptable for the response. 039 * 040 * <p> 041 * This field allows clients capable of understanding more comprehensive or special- purpose character sets to signal 042 * that capability to a server which is capable of representing documents in those character sets. 043 * <p class='bcode'> 044 * Accept-Charset = "Accept-Charset" ":" 045 * 1#( ( charset | "*" )[ ";" "q" "=" qvalue ] ) 046 * </p> 047 * 048 * <p> 049 * Character set values are described in section 3.4. Each charset MAY be given an associated quality value which 050 * represents the user's preference for that charset. 051 * The default value is q=1. 052 * An example is... 053 * <p class='bcode'> 054 * Accept-Charset: iso-8859-5, unicode-1-1;q=0.8 055 * </p> 056 * 057 * <p> 058 * The special value "*", if present in the Accept-Charset field, matches every character set (including ISO-8859-1) 059 * which is not mentioned elsewhere in the Accept-Charset field. 060 * 061 * <p> 062 * If no "*" is present in an Accept-Charset field, then all character sets not explicitly mentioned get a quality 063 * value of 0, except for ISO-8859-1, which gets a quality value of 1 if not explicitly mentioned. 064 * 065 * <p> 066 * If no Accept-Charset header is present, the default is that any character set is acceptable. 067 * 068 * <p> 069 * If an Accept-Charset header is present, and if the server cannot send a response which is acceptable according to 070 * the Accept-Charset header, then the server SHOULD send an error response with the 406 (not acceptable) status code, 071 * though the sending of an unacceptable response is also allowed. 072 * 073 * <h5 class='section'>See Also:</h5><ul> 074 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a> 075 * <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a> 076 * </ul> 077 * 078 * @serial exclude 079 */ 080@Header("Accept-Charset") 081public class AcceptCharset extends BasicStringRangesHeader { 082 private static final long serialVersionUID = 1L; 083 private static final String NAME = "Accept-Charset"; 084 085 private static final Cache<String,AcceptCharset> CACHE = Cache.of(String.class, AcceptCharset.class).build(); 086 087 /** 088 * Static creator. 089 * 090 * @param value 091 * The header value. 092 * <br>Must be parsable by {@link StringRanges#of(String)}. 093 * <br>Can be <jk>null</jk>. 094 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 095 */ 096 public static AcceptCharset of(String value) { 097 return value == null ? null : CACHE.get(value, () -> new AcceptCharset(value)); 098 } 099 100 /** 101 * Static creator. 102 * 103 * @param value 104 * The header value. 105 * <br>Can be <jk>null</jk>. 106 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 107 */ 108 public static AcceptCharset of(StringRanges value) { 109 return value == null ? null : new AcceptCharset(value); 110 } 111 112 /** 113 * Static creator with delayed value. 114 * 115 * <p> 116 * Header value is re-evaluated on each call to {@link #getValue()}. 117 * 118 * @param value 119 * The supplier of the header value. 120 * <br>Can be <jk>null</jk>. 121 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 122 */ 123 public static AcceptCharset of(Supplier<StringRanges> value) { 124 return value == null ? null : new AcceptCharset(value); 125 } 126 127 /** 128 * Constructor. 129 * 130 * @param value 131 * The header value. 132 * <br>Must be parsable by {@link StringRanges#of(String)}. 133 * <br>Can be <jk>null</jk>. 134 */ 135 public AcceptCharset(String value) { 136 super(NAME, value); 137 } 138 139 /** 140 * Constructor. 141 * 142 * @param value 143 * The header value. 144 * <br>Can be <jk>null</jk>. 145 */ 146 public AcceptCharset(StringRanges value) { 147 super(NAME, value); 148 } 149 150 /** 151 * Constructor with delayed value. 152 * 153 * <p> 154 * Header value is re-evaluated on each call to {@link #getValue()}. 155 * 156 * @param value 157 * The supplier of the header value. 158 * <br>Can be <jk>null</jk>. 159 */ 160 public AcceptCharset(Supplier<StringRanges> value) { 161 super(NAME, value); 162 } 163}