1
2
3
4
5 package net.sourceforge.jsdp;
6
7 import java.util.regex.Pattern;
8
9
10
11
12
13
14
15
16
17
18
19
20
21 public class Information implements Field {
22
23
24 private static final long serialVersionUID = 7479814033467823932L;
25
26
27 private static final Pattern valuePattern = Pattern.compile("[^\\r\\n\0]+");
28
29
30 private String value;
31
32
33
34
35 protected Information() {
36
37 super();
38 }
39
40
41
42
43
44
45
46
47 public Information(final String value) throws SDPException {
48
49 super();
50 setValue(value);
51 }
52
53
54
55
56
57
58
59
60
61
62 public static Information parse(final String field) throws SDPParseException {
63
64 if (!field.startsWith("i=")) {
65 throw new SDPParseException("The string \"" + field + "\" isn't an information field");
66 }
67
68 Information i = null;
69
70 try {
71 i = new Information(field.substring(2));
72 }
73 catch (SDPException parseException) {
74 throw new SDPParseException("The string \"" + field + "\" isn't a valid information field", parseException);
75 }
76
77 return i;
78 }
79
80
81
82
83
84
85 public Object clone() {
86
87 Information info = new Information();
88 info.value = new String(this.value);
89
90 return info;
91 }
92
93
94
95
96
97
98 public char getType() {
99
100 return Field.INFORMATION_FIELD;
101 }
102
103
104
105
106
107
108 public String getValue() {
109
110 return value;
111 }
112
113
114
115
116
117
118
119
120 public void setValue(final String value) throws SDPException {
121
122 if (!valuePattern.matcher(value).matches()) {
123 throw new SDPException("Invalid session information");
124 }
125
126 this.value = value;
127 }
128
129
130
131
132
133
134
135 public String toString() {
136
137 return getType() + "=" + getValue();
138 }
139 }