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.classic.header;
018
019import java.util.function.*;
020
021import org.apache.juneau.http.*;
022
023/**
024 * Represents a parsed <l>Content-Language</l> HTTP response header.
025 *
026 * <p>
027 * The natural language or languages of the intended audience for the enclosed content.
028 *
029 * <h5 class='figure'>Example</h5>
030 * <p class='bcode'>
031 *    Content-Language: da
032 * </p>
033 *
034 * <h5 class='topic'>RFC2616 Specification</h5>
035 *
036 * The Content-Language entity-header field describes the natural language(s) of the intended audience for the
037 * enclosed entity.
038 * Note that this might not be equivalent to all the languages used within the entity-body.
039 * <p class='bcode'>
040 *    Content-Language  = "Content-Language" ":" 1#language-tag
041 * </p>
042 *
043 * <p>
044 * Language tags are defined in section 3.10.
045 * The primary purpose of Content-Language is to allow a user to identify and differentiate entities according to the
046 * user's own preferred language.
047 * Thus, if the body content is intended only for a Danish-literate audience, the appropriate field is...
048 * <p class='bcode'>
049 *    Content-Language: da
050 * </p>
051 *
052 * <p>
053 * If no Content-Language is specified, the default is that the content is intended for all language audiences.
054 * This might mean that the sender does not consider it to be specific to any natural language, or that the sender
055 * does not know for which language it is intended.
056 *
057 * <p>
058 * Multiple languages MAY be listed for content that is intended for multiple audiences.
059 * For example, a rendition of the "Treaty of Waitangi," presented simultaneously in the original Maori and English
060 * versions, would call for...
061 * <p class='bcode'>
062 *    Content-Language: mi, en
063 * </p>
064 *
065 * <p>
066 * However, just because multiple languages are present within an entity does not mean that it is intended for
067 * multiple linguistic audiences.
068 * An example would be a beginner's language primer, such as "A First Lesson in Latin," which is clearly intended to
069 * be used by an English-literate audience.
070 * In this case, the Content-Language would properly only include "en".
071 *
072 * <p>
073 * Content-Language MAY be applied to any media type -- it is not limited to textual documents.
074 *
075 * <h5 class='section'>See Also:</h5><ul>
076 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommon">juneau-rest-common</a>
077 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
078 * </ul>
079 *
080 * @serial exclude
081 */
082@Header("Content-Language")
083@SuppressWarnings({
084   "java:S9149" // Public Juneau DSL factory; hiding parent of()/create() is intentional.
085})
086public class ContentLanguage extends BasicCsvHeader {
087   private static final long serialVersionUID = 1L;
088   private static final String NAME = "Content-Language";
089
090   /**
091    * Static creator.
092    *
093    * @param value
094    *    The header value.
095    *    <br>Can be <jk>null</jk>.
096    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
097    */
098   public static ContentLanguage of(String value) {
099      return value == null ? null : new ContentLanguage(value);
100   }
101
102   /**
103    * Static creator.
104    *
105    * @param value
106    *    The header value.
107    *    <br>Can be <jk>null</jk>.
108    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
109    */
110   public static ContentLanguage of(String...value) {
111      return value == null ? null : new ContentLanguage(value);
112   }
113
114   /**
115    * Static creator for two CSV tokens.
116    *
117    * <p>
118    * This distinct fixed-arity overload ensures two literal {@link String} arguments resolve to this class's own
119    * factory (returning a {@link ContentLanguage}) rather than the inherited fixed-arity
120    * {@link BasicCsvHeader#of(String,String)}, which Java overload resolution would otherwise prefer.
121    *
122    * @param value1 The first CSV token.
123    * @param value2 The second CSV token.
124    * @return A new header bean.
125    */
126   public static ContentLanguage of(String value1, String value2) {
127      return new ContentLanguage(value1, value2);
128   }
129
130   /**
131    * Static creator with delayed value.
132    *
133    * <p>
134    * Header value is re-evaluated on each call to {@link #getValue()}.
135    *
136    * @param value
137    *    The supplier of the header value.
138    *    <br>Can be <jk>null</jk>.
139    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
140    */
141   public static ContentLanguage of(Supplier<String[]> value) {
142      return value == null ? null : new ContentLanguage(value);
143   }
144
145   /**
146    * Constructor.
147    *
148    * @param value
149    *    The header value.
150    *    <br>Can be <jk>null</jk> to create a header with no value.
151    */
152   public ContentLanguage(String value) {
153      super(NAME, value);
154   }
155
156   /**
157    * Constructor.
158    *
159    * @param value
160    *    The header value.
161    *    <br>Can be <jk>null</jk> or empty to create a header with no value.
162    */
163   public ContentLanguage(String...value) {
164      super(NAME, value);
165   }
166
167   /**
168    * Constructor with delayed value.
169    *
170    * <p>
171    * Header value is re-evaluated on each call to {@link #getValue()}.
172    *
173    * @param value
174    *    The supplier of the header value.
175    *    <br>Can be <jk>null</jk> to create a header with no value.
176    */
177   public ContentLanguage(Supplier<String[]> value) {
178      super(NAME, value);
179   }
180}