1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.opencastproject.composer.api;
24
25 import org.opencastproject.util.EqualsUtil;
26
27 import org.apache.commons.lang3.StringUtils;
28
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Map.Entry;
34
35 import javax.xml.bind.annotation.XmlAccessType;
36 import javax.xml.bind.annotation.XmlAccessorType;
37 import javax.xml.bind.annotation.XmlAttribute;
38 import javax.xml.bind.annotation.XmlElement;
39 import javax.xml.bind.annotation.XmlElementWrapper;
40 import javax.xml.bind.annotation.XmlID;
41 import javax.xml.bind.annotation.XmlRootElement;
42 import javax.xml.bind.annotation.XmlTransient;
43 import javax.xml.bind.annotation.XmlType;
44 import javax.xml.bind.annotation.XmlValue;
45
46
47
48
49 @XmlAccessorType(XmlAccessType.FIELD)
50 @XmlType(name = "profile", namespace = "http://composer.opencastproject.org")
51 @XmlRootElement(name = "profile", namespace = "http://composer.opencastproject.org")
52 public class EncodingProfileImpl implements EncodingProfile {
53
54
55 @XmlAttribute(name = "id")
56 @XmlID
57 protected String identifier = null;
58
59
60 @XmlElement(name = "name")
61 protected String name = null;
62
63 @XmlTransient
64 protected Object source;
65
66
67 @XmlElement(name = "outputmediatype")
68 protected MediaType outputType = null;
69
70
71
72
73
74
75
76 @XmlElement(name = "mimetype")
77 protected String mimeType = null;
78
79
80 @XmlElement(name = "inputmediatype")
81 protected MediaType applicableType = null;
82
83
84 @XmlElement(name = "extension")
85 @XmlElementWrapper(name = "extensions")
86 protected List<Extension> extensions = new ArrayList<Extension>();
87
88 @XmlElementWrapper(name = "suffixes")
89 protected HashMap<String,String> suffixes = new HashMap<String, String>();
90
91 @XmlElement(name = "jobLoad")
92 protected Float jobLoad = 1.5f;
93
94
95
96
97
98
99
100
101
102 public EncodingProfileImpl(String identifier, String name, Object source) {
103 this.identifier = identifier;
104 this.name = name;
105 this.source = source;
106 }
107
108
109 public EncodingProfileImpl() {
110 }
111
112
113
114
115
116
117 @Override
118 public String getIdentifier() {
119 return identifier;
120 }
121
122
123
124
125
126
127
128 public void setIdentifier(String id) {
129 identifier = id;
130 }
131
132
133
134
135
136
137 @Override
138 public String getName() {
139 return name;
140 }
141
142
143
144
145
146
147
148 public void setName(String name) {
149 this.name = name;
150 }
151
152
153
154
155
156
157 @Override
158 public Object getSource() {
159 return source;
160 }
161
162
163
164
165
166
167 @Override
168 public MediaType getOutputType() {
169 return outputType;
170 }
171
172
173
174
175
176
177
178 public void setOutputType(MediaType type) {
179 this.outputType = type;
180 }
181
182
183
184
185
186
187 @Override
188 public String getSuffix() {
189 if (suffixes.keySet().size() == 0) return null;
190 if (suffixes.containsKey("default")) {
191 return suffixes.get("default");
192 } else {
193 return suffixes.get(suffixes.values().toArray()[0]);
194 }
195 }
196
197
198
199
200
201
202
203 public void setSuffix(String suffix) {
204 setSuffix("default", suffix);
205 }
206
207
208
209
210
211
212
213 public void setSuffix(String tag ,String suffix) {
214 this.suffixes.put(tag, suffix);
215 }
216
217
218
219
220 @Override
221 public String getMimeType() {
222 return mimeType;
223 }
224
225
226
227
228
229
230 @Override
231 public void setMimeType(String mimeType) {
232 this.mimeType = mimeType;
233 }
234
235
236
237
238
239
240 @Override
241 public MediaType getApplicableMediaType() {
242 return applicableType;
243 }
244
245
246
247
248
249
250
251 public void setApplicableType(MediaType applicableType) {
252 this.applicableType = applicableType;
253 }
254
255
256
257
258
259
260 @Override
261 public boolean isApplicableTo(MediaType type) {
262 if (type == null)
263 throw new IllegalArgumentException("Type must not be null");
264 return type.equals(applicableType);
265 }
266
267
268
269
270
271
272 @Override
273 public String getExtension(String key) {
274 return getExtensions().get(key);
275 }
276
277
278
279
280
281
282
283
284
285 public void addExtension(String key, String value) {
286 if (StringUtils.isBlank(key))
287 throw new IllegalArgumentException("Argument 'key' must not be null");
288 if (value == null)
289 throw new IllegalArgumentException("Argument 'value' must not be null");
290 removeExtension(key);
291 extensions.add(new Extension(key, value));
292 }
293
294
295
296
297
298
299 @Override
300 public Map<String, String> getExtensions() {
301 Map<String, String> map = new HashMap<String, String>();
302 for (Extension extension : extensions) {
303 map.put(extension.getKey(), extension.getValue());
304 }
305 return map;
306 }
307
308
309
310
311
312
313
314 public void setExtensions(Map<String, String> extension) {
315 extensions.clear();
316 for (Entry<String, String> entry : extension.entrySet()) {
317 extensions.add(new Extension(entry));
318 }
319 }
320
321
322
323
324
325
326
327
328
329 public String removeExtension(String key) {
330 int index = -1;
331 for (int i = 0; i < extensions.size(); i++) {
332 if (extensions.get(i).getKey().equals(key)) {
333 index = i;
334 break;
335 }
336 }
337 if (index == -1)
338 return null;
339 return extensions.remove(index).getValue();
340 }
341
342
343
344
345
346
347 @Override
348 public boolean hasExtensions() {
349 return extensions != null && extensions.size() > 0;
350 }
351
352
353
354
355
356
357 @Override
358 public float getJobLoad() {
359 return jobLoad;
360 }
361
362
363
364
365
366
367 public void setJobLoad(Float jobLoad) {
368 this.jobLoad = jobLoad;
369 }
370
371
372
373
374
375
376 @Override
377 public int hashCode() {
378 return identifier.hashCode();
379 }
380
381
382
383
384
385
386 @Override
387 public boolean equals(Object obj) {
388 if (obj instanceof EncodingProfile) {
389 EncodingProfile mf = (EncodingProfile) obj;
390 return identifier.equals(mf.getIdentifier());
391 }
392 return false;
393 }
394
395
396
397
398
399
400 @Override
401 public String toString() {
402 return identifier;
403 }
404
405 @Override
406 public String getSuffix(String tag) {
407 if (suffixes.containsKey(tag)) return suffixes.get(tag);
408 else return null;
409 }
410
411 @Override
412 public List<String> getTags() {
413 return new ArrayList<String>(suffixes.keySet());
414 }
415
416
417
418
419 @XmlAccessorType(XmlAccessType.FIELD)
420 @XmlType(name = "extension", namespace = "http://composer.opencastproject.org")
421 public static class Extension {
422
423
424 @XmlAttribute
425 private String key;
426
427
428 @XmlValue
429 private String value;
430
431
432
433
434 public Extension() {
435 }
436
437
438
439
440
441
442
443
444
445 public Extension(String key, String value) {
446 this.key = key;
447 this.value = value;
448 }
449
450
451
452
453
454
455
456 public Extension(Map.Entry<String, String> e) {
457 key = e.getKey();
458 value = e.getValue();
459 }
460
461
462
463
464 public String getKey() {
465 return key;
466 }
467
468
469
470
471 public String getValue() {
472 return value;
473 }
474
475 @Override
476 public boolean equals(Object obj) {
477 if (obj instanceof Extension) {
478 Extension ext = (Extension) obj;
479 return key.equals(ext.getKey()) && value.equals(ext.getValue());
480 }
481 return false;
482 }
483
484 @Override
485 public int hashCode() {
486 return EqualsUtil.hash(key, value);
487 }
488 }
489
490 }