1 /**
2 *
3 * Copyright 2003-2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package javax.mail.internet;
19
20
21
22 /**
23 * @version $Rev: 381393 $ $Date: 2006-02-27 09:38:03 -0800 (Mon, 27 Feb 2006) $
24 */
25 public class ContentDisposition {
26 private String _disposition;
27 private ParameterList _list;
28
29 public ContentDisposition() {
30 setDisposition(null);
31 setParameterList(null);
32 }
33
34 public ContentDisposition(String disposition) throws ParseException {
35
36 HeaderTokenizer tokenizer = new HeaderTokenizer(disposition, HeaderTokenizer.MIME);
37
38
39 HeaderTokenizer.Token token = tokenizer.next();
40 if (token.getType() != HeaderTokenizer.Token.ATOM) {
41 throw new ParseException("Invalid content disposition");
42 }
43
44 _disposition = token.getValue();
45
46
47 String remainder = tokenizer.getRemainder();
48 if (remainder != null) {
49 _list = new ParameterList(remainder);
50 }
51 }
52
53 public ContentDisposition(String disposition, ParameterList list) {
54 setDisposition(disposition);
55 setParameterList(list);
56 }
57
58 public String getDisposition() {
59 return _disposition;
60 }
61
62 public String getParameter(String name) {
63 if (_list == null) {
64 return null;
65 } else {
66 return _list.get(name);
67 }
68 }
69
70 public ParameterList getParameterList() {
71 return _list;
72 }
73
74 public void setDisposition(String string) {
75 _disposition = string;
76 }
77
78 public void setParameter(String name, String value) {
79 if (_list == null) {
80 _list = new ParameterList();
81 }
82 _list.set(name, value);
83 }
84
85 public void setParameterList(ParameterList list) {
86 if (list == null) {
87 _list = new ParameterList();
88 } else {
89 _list = list;
90 }
91 }
92
93 public String toString() {
94
95
96 if (_disposition == null) {
97 return null;
98 }
99
100
101
102 if (_list == null) {
103 return _disposition;
104 }
105
106
107
108 return _disposition + _list.toString(21 + _disposition.length());
109 }
110 }