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 // http://www.faqs.org/rfcs/rfc2183.html
21
22 /**
23 * @version $Rev: 54266 $ $Date: 2004-10-10 14:02:50 -0700 (Sun, 10 Oct 2004) $
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 ParameterList list = null;
36 int semicolon;
37 if (disposition != null && (semicolon = disposition.indexOf(";")) != -1) {
38 list = new ParameterList(disposition.substring(semicolon + 1));
39 disposition = disposition.substring(0, semicolon);
40 }
41 setDisposition(disposition);
42 setParameterList(list);
43 }
44
45 public ContentDisposition(String disposition, ParameterList list) {
46 setDisposition(disposition);
47 setParameterList(list);
48 }
49
50 public String getDisposition() {
51 return _disposition;
52 }
53
54 public String getParameter(String name) {
55 if (_list == null) {
56 return null;
57 } else {
58 return _list.get(name);
59 }
60 }
61
62 public ParameterList getParameterList() {
63 return _list;
64 }
65
66 public void setDisposition(String string) {
67 _disposition = string;
68 }
69
70 public void setParameter(String name, String value) {
71 _list = new ParameterList();
72 _list.set(name, value);
73 }
74
75 public void setParameterList(ParameterList list) {
76 if (list == null) {
77 _list = new ParameterList();
78 } else {
79 _list = list;
80 }
81 }
82
83 public String toString() {
84 if (_disposition == null && _list.size() == 0) {
85 return null;
86 }
87 return (_disposition == null ? "" : _disposition)
88 + (_list.size() == 0 ? "" : _list.toString());
89 }
90 }