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 public class SessionName implements Field {
21
22
23 private static final long serialVersionUID = 6770714073389574787L;
24
25
26 private static final Pattern namePattern = Pattern.compile("[^\\r\\n\0]+");
27
28
29 private String value;
30
31
32
33
34
35 public SessionName() {
36
37 super();
38 this.value = "-";
39 }
40
41
42
43
44
45
46
47
48
49 public SessionName(final String value) throws SDPException {
50
51 super();
52 setValue(value);
53 }
54
55
56
57
58
59
60
61
62
63
64 public static SessionName parse(final String field) throws SDPParseException {
65
66 if (!field.startsWith("s=")) {
67 throw new SDPParseException("The string \"" + field + "\" isn't a session name field");
68 }
69
70 SessionName s = null;
71
72 try {
73
74 s = new SessionName(field.substring(2));
75 }
76 catch (SDPException parseException) {
77 throw new SDPParseException("The string \"" + field + "\" isn't a valid session name field", parseException);
78 }
79
80 return s;
81 }
82
83
84
85
86
87
88 public Object clone() {
89
90 SessionName session = new SessionName();
91 session.value = new String(this.value);
92
93 return session;
94 }
95
96
97
98
99
100
101 public char getType() {
102
103 return Field.SESSION_NAME_FIELD;
104 }
105
106
107
108
109
110
111 public String getValue() {
112
113 return value;
114 }
115
116
117
118
119
120
121
122
123
124 public void setValue(final String value) throws SDPException {
125
126 if (!namePattern.matcher(value).matches()) {
127 throw new SDPException("Invalid session name");
128 }
129
130 this.value = value;
131 }
132
133
134
135
136
137
138
139 public String toString() {
140
141 return getType() + "=" + value;
142 }
143 }