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>Content-Disposition</l> HTTP request header.
027 *
028 * <p>
029 * In a regular HTTP response, the Content-Disposition response header is a header indicating if the content is expected
030 * to be displayed inline in the browser, that is, as a Web page or as part of a Web page, or as an attachment, that is
031 * downloaded and saved locally.
032 *
033 * <h5 class='figure'>Example</h5>
034 * <p class='bcode'>
035 *    Content-Disposition: form-data; name="fieldName"; filename="filename.jpg"
036 * </p>
037 *
038 * <h5 class='topic'>RFC2616 Specification</h5>
039 *
040 * The Expect request-header field is used to indicate that particular server behaviors are required by the client.
041 * <p class='bcode'>
042 * content-disposition = "Content-Disposition" ":"
043 *    disposition-type *( ";" disposition-parm )
044 *    disposition-type = "attachment" | disp-extension-token
045 *    disposition-parm = filename-parm | disp-extension-parm
046 *    filename-parm = "filename" "=" quoted-string
047 * disp-extension-token = token
048 *    disp-extension-parm = token "=" ( token | quoted-string )
049 * </p>
050 *
051 * <h5 class='section'>See Also:</h5><ul>
052 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a>
053 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
054 * </ul>
055 *
056 * @serial exclude
057 */
058@Header("Content-Disposition")
059public class ContentDisposition extends BasicStringRangesHeader {
060   private static final long serialVersionUID = 1L;
061   private static final String NAME = "Content-Disposition";
062
063   private static final Cache<String,ContentDisposition> CACHE = Cache.of(String.class, ContentDisposition.class).build();
064
065   /**
066    * Static creator.
067    *
068    * @param value
069    *    The header value.
070    *    <br>Must be parsable by {@link StringRanges#of(String)}.
071    *    <br>Can be <jk>null</jk>.
072    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
073    */
074   public static ContentDisposition of(String value) {
075      return value == null ? null : CACHE.get(value, () -> new ContentDisposition(value));
076   }
077
078   /**
079    * Static creator.
080    *
081    * @param value
082    *    The header value.
083    *    <br>Can be <jk>null</jk>.
084    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
085    */
086   public static ContentDisposition of(StringRanges value) {
087      return value == null ? null : new ContentDisposition(value);
088   }
089
090   /**
091    * Static creator with delayed value.
092    *
093    * <p>
094    * Header value is re-evaluated on each call to {@link #getValue()}.
095    *
096    * @param value
097    *    The supplier of the header value.
098    *    <br>Can be <jk>null</jk>.
099    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
100    */
101   public static ContentDisposition of(Supplier<StringRanges> value) {
102      return value == null ? null : new ContentDisposition(value);
103   }
104
105   /**
106    * Constructor.
107    *
108    * @param value
109    *    The header value.
110    *    <br>Must be parsable by {@link StringRanges#of(String)}.
111    *    <br>Can be <jk>null</jk>.
112    */
113   public ContentDisposition(String value) {
114      super(NAME, value);
115   }
116
117   /**
118    * Constructor.
119    *
120    * @param value
121    *    The header value.
122    *    <br>Can be <jk>null</jk>.
123    */
124   public ContentDisposition(StringRanges value) {
125      super(NAME, value);
126   }
127
128   /**
129    * Constructor with delayed value.
130    *
131    * <p>
132    * Header value is re-evaluated on each call to {@link #getValue()}.
133    *
134    * @param value
135    *    The supplier of the header value.
136    *    <br>Can be <jk>null</jk>.
137    */
138   public ContentDisposition(Supplier<StringRanges> value) {
139      super(NAME, value);
140   }
141}