Skip to content

Package: ContentDisposition

ContentDisposition

nameinstructionbranchcomplexitylinemethod
ContentDisposition()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
ContentDisposition(String)
M: 52 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
ContentDisposition(String, ParameterList)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getDisposition()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getParameter(String)
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getParameterList()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setDisposition(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setParameter(String, String)
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setParameterList(ParameterList)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
toString()
M: 30 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package jakarta.mail.internet;
18:
19: /**
20: * This class represents a MIME ContentDisposition value. It provides
21: * methods to parse a ContentDisposition string into individual components
22: * and to generate a MIME style ContentDisposition string.
23: *
24: * @author John Mani
25: */
26:
27: public class ContentDisposition {
28:
29: private static final boolean contentDispositionStrict =
30: MimeUtility.getBooleanSystemProperty("mail.mime.contentdisposition.strict", true);
31:
32: private String disposition; // disposition
33: private ParameterList list; // parameter list
34:
35: /**
36: * No-arg Constructor.
37: */
38: public ContentDisposition() {
39: }
40:
41: /**
42: * Constructor.
43: *
44: * @param disposition disposition
45: * @param list ParameterList
46: * @since JavaMail 1.2
47: */
48: public ContentDisposition(String disposition, ParameterList list) {
49: this.disposition = disposition;
50: this.list = list;
51: }
52:
53: /**
54: * Constructor that takes a ContentDisposition string. The String
55: * is parsed into its constituents: dispostion and parameters.
56: * A ParseException is thrown if the parse fails.
57: *
58: * @param s the ContentDisposition string.
59: * @throws ParseException if the parse fails.
60: * @since JavaMail 1.2
61: */
62: public ContentDisposition(String s) throws ParseException {
63: HeaderTokenizer h = new HeaderTokenizer(s, HeaderTokenizer.MIME);
64: HeaderTokenizer.Token tk;
65:
66: // First "disposition" ..
67: tk = h.next();
68:• if (tk.getType() != HeaderTokenizer.Token.ATOM) {
69:• if (contentDispositionStrict) {
70: throw new ParseException("Expected disposition, got " +
71: tk.getValue());
72: }
73: } else {
74: disposition = tk.getValue();
75: }
76:
77: // Then parameters ..
78: String rem = h.getRemainder();
79:• if (rem != null) {
80: try {
81: list = new ParameterList(rem);
82: } catch (ParseException px) {
83:• if (contentDispositionStrict) {
84: throw px;
85: }
86: }
87: }
88: }
89:
90: /**
91: * Return the disposition value.
92: *
93: * @return the disposition
94: * @since JavaMail 1.2
95: */
96: public String getDisposition() {
97: return disposition;
98: }
99:
100: /**
101: * Return the specified parameter value. Returns <code>null</code>
102: * if this parameter is absent.
103: *
104: * @param name the parameter name
105: * @return parameter value
106: * @since JavaMail 1.2
107: */
108: public String getParameter(String name) {
109:• if (list == null)
110: return null;
111:
112: return list.get(name);
113: }
114:
115: /**
116: * Return a ParameterList object that holds all the available
117: * parameters. Returns null if no parameters are available.
118: *
119: * @return ParameterList
120: * @since JavaMail 1.2
121: */
122: public ParameterList getParameterList() {
123: return list;
124: }
125:
126: /**
127: * Set the disposition. Replaces the existing disposition.
128: *
129: * @param disposition the disposition
130: * @since JavaMail 1.2
131: */
132: public void setDisposition(String disposition) {
133: this.disposition = disposition;
134: }
135:
136: /**
137: * Set the specified parameter. If this parameter already exists,
138: * it is replaced by this new value.
139: *
140: * @param name parameter name
141: * @param value parameter value
142: * @since JavaMail 1.2
143: */
144: public void setParameter(String name, String value) {
145:• if (list == null)
146: list = new ParameterList();
147:
148: list.set(name, value);
149: }
150:
151: /**
152: * Set a new ParameterList.
153: *
154: * @param list ParameterList
155: * @since JavaMail 1.2
156: */
157: public void setParameterList(ParameterList list) {
158: this.list = list;
159: }
160:
161: /**
162: * Retrieve a RFC2045 style string representation of
163: * this ContentDisposition. Returns an empty string if
164: * the conversion failed.
165: *
166: * @return RFC2045 style string
167: * @since JavaMail 1.2
168: */
169: @Override
170: public String toString() {
171:• if (disposition == null)
172: return "";
173:
174:• if (list == null)
175: return disposition;
176:
177: StringBuilder sb = new StringBuilder(disposition);
178:
179: // append the parameter list
180: // use the length of the string buffer + the length of
181: // the header name formatted as follows "Content-Disposition: "
182: sb.append(list.toString(sb.length() + 21));
183: return sb.toString();
184: }
185: }