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 static org.apache.juneau.http.Constants.*; 016 017import java.util.function.*; 018 019import org.apache.juneau.http.annotation.*; 020import org.apache.juneau.internal.*; 021 022/** 023 * Represents a parsed <l>Content-Disposition</l> HTTP request header. 024 * 025 * <p> 026 * In a regular HTTP response, the Content-Disposition response header is a header indicating if the content is expected 027 * 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 028 * downloaded and saved locally. 029 * 030 * <h5 class='figure'>Example</h5> 031 * <p class='bcode w800'> 032 * Content-Disposition: form-data; name="fieldName"; filename="filename.jpg" 033 * </p> 034 * 035 * <h5 class='topic'>RFC2616 Specification</h5> 036 * 037 * The Expect request-header field is used to indicate that particular server behaviors are required by the client. 038 * <p class='bcode w800'> 039 * content-disposition = "Content-Disposition" ":" 040 * disposition-type *( ";" disposition-parm ) 041 * disposition-type = "attachment" | disp-extension-token 042 * disposition-parm = filename-parm | disp-extension-parm 043 * filename-parm = "filename" "=" quoted-string 044 * disp-extension-token = token 045 * disp-extension-parm = token "=" ( token | quoted-string ) 046 * </p> 047 * 048 * <ul class='seealso'> 049 * <li class='extlink'>{@doc ExtRFC2616} 050 * </ul> 051 */ 052@Header("Content-Disposition") 053public class ContentDisposition extends BasicStringRangeArrayHeader { 054 055 private static final long serialVersionUID = 1L; 056 057 private static final Cache<String,ContentDisposition> CACHE = new Cache<>(NOCACHE, CACHE_MAX_SIZE); 058 059 /** 060 * Returns a parsed and cached header. 061 * 062 * @param value 063 * The header value. 064 * @return A cached {@link ContentDisposition} object. 065 */ 066 public static ContentDisposition of(String value) { 067 if (value == null) 068 return null; 069 ContentDisposition x = CACHE.get(value); 070 if (x == null) 071 x = CACHE.put(value, new ContentDisposition(value)); 072 return x; 073 } 074 075 /** 076 * Convenience creator. 077 * 078 * @param value 079 * The header value. 080 * <br>Can be any of the following: 081 * <ul> 082 * <li>{@link String} 083 * <li>Anything else - Converted to <c>String</c> then parsed. 084 * </ul> 085 * @return A new {@link ContentDisposition} object. 086 */ 087 public static ContentDisposition of(Object value) { 088 if (value == null) 089 return null; 090 return new ContentDisposition(value); 091 } 092 093 /** 094 * Convenience creator using supplier. 095 * 096 * <p> 097 * Header value is re-evaluated on each call to {@link #getValue()}. 098 * 099 * @param value 100 * The header value supplier. 101 * <br>Can be any of the following: 102 * <ul> 103 * <li>{@link String} 104 * <li>Anything else - Converted to <c>String</c> then parsed. 105 * </ul> 106 * @return A new {@link ContentDisposition} object. 107 */ 108 public static ContentDisposition of(Supplier<?> value) { 109 if (value == null) 110 return null; 111 return new ContentDisposition(value); 112 } 113 114 /** 115 * Constructor. 116 * 117 * @param value 118 * The header value. 119 * <br>Can be any of the following: 120 * <ul> 121 * <li>{@link String} 122 * <li>Anything else - Converted to <c>String</c> then parsed. 123 * <li>A {@link Supplier} of anything on this list. 124 * </ul> 125 */ 126 public ContentDisposition(Object value) { 127 super("Content-Disposition", value); 128 } 129 130 /** 131 * Constructor 132 * 133 * @param value 134 * The header value. 135 */ 136 public ContentDisposition(String value) { 137 this((Object)value); 138 } 139}