1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package javax.mail.internet;
21
22
23
24
25
26
27 public class ContentDisposition {
28 private String _disposition;
29 private ParameterList _list;
30
31 public ContentDisposition() {
32 setDisposition(null);
33 setParameterList(null);
34 }
35
36 public ContentDisposition(String disposition) throws ParseException {
37
38 HeaderTokenizer tokenizer = new HeaderTokenizer(disposition, HeaderTokenizer.MIME);
39
40
41 HeaderTokenizer.Token token = tokenizer.next();
42 if (token.getType() != HeaderTokenizer.Token.ATOM) {
43 throw new ParseException("Invalid content disposition");
44 }
45
46 _disposition = token.getValue();
47
48
49 String remainder = tokenizer.getRemainder();
50 if (remainder != null) {
51 _list = new ParameterList(remainder);
52 }
53 }
54
55 public ContentDisposition(String disposition, ParameterList list) {
56 setDisposition(disposition);
57 setParameterList(list);
58 }
59
60 public String getDisposition() {
61 return _disposition;
62 }
63
64 public String getParameter(String name) {
65 if (_list == null) {
66 return null;
67 } else {
68 return _list.get(name);
69 }
70 }
71
72 public ParameterList getParameterList() {
73 return _list;
74 }
75
76 public void setDisposition(String string) {
77 _disposition = string;
78 }
79
80 public void setParameter(String name, String value) {
81 if (_list == null) {
82 _list = new ParameterList();
83 }
84 _list.set(name, value);
85 }
86
87 public void setParameterList(ParameterList list) {
88 if (list == null) {
89 _list = new ParameterList();
90 } else {
91 _list = list;
92 }
93 }
94
95 public String toString() {
96
97
98 if (_disposition == null) {
99 return null;
100 }
101
102
103
104 if (_list == null) {
105 return _disposition;
106 }
107
108
109
110 return _disposition + _list.toString("Content-Disposition".length() + _disposition.length());
111 }
112 }