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