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.http.annotation.*;
023import org.apache.juneau.internal.*;
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
061   //-----------------------------------------------------------------------------------------------------------------
062   // Static
063   //-----------------------------------------------------------------------------------------------------------------
064
065   private static final long serialVersionUID = 1L;
066   private static final String NAME = "Content-Disposition";
067
068   private static final Cache<String,ContentDisposition> CACHE = Cache.of(String.class, ContentDisposition.class).build();
069
070   /**
071    * Static creator.
072    *
073    * @param value
074    *    The header value.
075    *    <br>Must be parsable by {@link StringRanges#of(String)}.
076    *    <br>Can be <jk>null</jk>.
077    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
078    */
079   public static ContentDisposition of(String value) {
080      return value == null ? null : CACHE.get(value, ()->new ContentDisposition(value));
081   }
082
083   /**
084    * Static creator.
085    *
086    * @param value
087    *    The header value.
088    *    <br>Can be <jk>null</jk>.
089    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
090    */
091   public static ContentDisposition of(StringRanges value) {
092      return value == null ? null : new ContentDisposition(value);
093   }
094
095   /**
096    * Static creator with delayed value.
097    *
098    * <p>
099    * Header value is re-evaluated on each call to {@link #getValue()}.
100    *
101    * @param value
102    *    The supplier of the header value.
103    *    <br>Can be <jk>null</jk>.
104    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
105    */
106   public static ContentDisposition of(Supplier<StringRanges> value) {
107      return value == null ? null : new ContentDisposition(value);
108   }
109
110   //-----------------------------------------------------------------------------------------------------------------
111   // Instance
112   //-----------------------------------------------------------------------------------------------------------------
113
114   /**
115    * Constructor.
116    *
117    * @param value
118    *    The header value.
119    *    <br>Must be parsable by {@link StringRanges#of(String)}.
120    *    <br>Can be <jk>null</jk>.
121    */
122   public ContentDisposition(String value) {
123      super(NAME, value);
124   }
125
126   /**
127    * Constructor.
128    *
129    * @param value
130    *    The header value.
131    *    <br>Can be <jk>null</jk>.
132    */
133   public ContentDisposition(StringRanges value) {
134      super(NAME, value);
135   }
136
137   /**
138    * Constructor with delayed value.
139    *
140    * <p>
141    * Header value is re-evaluated on each call to {@link #getValue()}.
142    *
143    * @param value
144    *    The supplier of the header value.
145    *    <br>Can be <jk>null</jk>.
146    */
147   public ContentDisposition(Supplier<StringRanges> value) {
148      super(NAME, value);
149   }
150}