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) {
190 return null;
191 }
192 if (suffixes.containsKey("default")) {
193 return suffixes.get("default");
194 } else {
195 return suffixes.get(suffixes.values().toArray()[0]);
196 }
197 }
198
199
200
201
202
203
204
205 public void setSuffix(String suffix) {
206 setSuffix("default", suffix);
207 }
208
209
210
211
212
213
214
215 public void setSuffix(String tag ,String suffix) {
216 this.suffixes.put(tag, suffix);
217 }
218
219
220
221
222 @Override
223 public String getMimeType() {
224 return mimeType;
225 }
226
227
228
229
230
231
232 @Override
233 public void setMimeType(String mimeType) {
234 this.mimeType = mimeType;
235 }
236
237
238
239
240
241
242 @Override
243 public MediaType getApplicableMediaType() {
244 return applicableType;
245 }
246
247
248
249
250
251
252
253 public void setApplicableType(MediaType applicableType) {
254 this.applicableType = applicableType;
255 }
256
257
258
259
260
261
262
263 @Override
264 public boolean isApplicableTo(MediaType type) {
265 if (type == null) {
266 throw new IllegalArgumentException("Type must not be null");
267 }
268 return type.equals(applicableType);
269 }
270
271
272
273
274
275
276 @Override
277 public String getExtension(String key) {
278 return getExtensions().get(key);
279 }
280
281
282
283
284
285
286
287
288
289 public void addExtension(String key, String value) {
290 if (StringUtils.isBlank(key)) {
291 throw new IllegalArgumentException("Argument 'key' must not be null");
292 }
293 if (value == null) {
294 throw new IllegalArgumentException("Argument 'value' must not be null");
295 }
296 removeExtension(key);
297 extensions.add(new Extension(key, value));
298 }
299
300
301
302
303
304
305 @Override
306 public Map<String, String> getExtensions() {
307 Map<String, String> map = new HashMap<String, String>();
308 for (Extension extension : extensions) {
309 map.put(extension.getKey(), extension.getValue());
310 }
311 return map;
312 }
313
314
315
316
317
318
319
320 public void setExtensions(Map<String, String> extension) {
321 extensions.clear();
322 for (Entry<String, String> entry : extension.entrySet()) {
323 extensions.add(new Extension(entry));
324 }
325 }
326
327
328
329
330
331
332
333
334
335 public String removeExtension(String key) {
336 int index = -1;
337 for (int i = 0; i < extensions.size(); i++) {
338 if (extensions.get(i).getKey().equals(key)) {
339 index = i;
340 break;
341 }
342 }
343 if (index == -1) {
344 return null;
345 }
346 return extensions.remove(index).getValue();
347 }
348
349
350
351
352
353
354 @Override
355 public boolean hasExtensions() {
356 return extensions != null && extensions.size() > 0;
357 }
358
359
360
361
362
363
364 @Override
365 public float getJobLoad() {
366 return jobLoad;
367 }
368
369
370
371
372
373
374 public void setJobLoad(Float jobLoad) {
375 this.jobLoad = jobLoad;
376 }
377
378
379
380
381
382
383 @Override
384 public int hashCode() {
385 return identifier.hashCode();
386 }
387
388
389
390
391
392
393 @Override
394 public boolean equals(Object obj) {
395 if (obj instanceof EncodingProfile) {
396 EncodingProfile mf = (EncodingProfile) obj;
397 return identifier.equals(mf.getIdentifier());
398 }
399 return false;
400 }
401
402
403
404
405
406
407 @Override
408 public String toString() {
409 return identifier;
410 }
411
412 @Override
413 public String getSuffix(String tag) {
414 if (suffixes.containsKey(tag)) {
415 return suffixes.get(tag);
416 } else {
417 return null;
418 }
419 }
420
421 @Override
422 public List<String> getTags() {
423 return new ArrayList<String>(suffixes.keySet());
424 }
425
426
427
428
429 @XmlAccessorType(XmlAccessType.FIELD)
430 @XmlType(name = "extension", namespace = "http://composer.opencastproject.org")
431 public static class Extension {
432
433
434 @XmlAttribute
435 private String key;
436
437
438 @XmlValue
439 private String value;
440
441
442
443
444 public Extension() {
445 }
446
447
448
449
450
451
452
453
454
455 public Extension(String key, String value) {
456 this.key = key;
457 this.value = value;
458 }
459
460
461
462
463
464
465
466 public Extension(Map.Entry<String, String> e) {
467 key = e.getKey();
468 value = e.getValue();
469 }
470
471
472
473
474 public String getKey() {
475 return key;
476 }
477
478
479
480
481 public String getValue() {
482 return value;
483 }
484
485 @Override
486 public boolean equals(Object obj) {
487 if (obj instanceof Extension) {
488 Extension ext = (Extension) obj;
489 return key.equals(ext.getKey()) && value.equals(ext.getValue());
490 }
491 return false;
492 }
493
494 @Override
495 public int hashCode() {
496 return EqualsUtil.hash(key, value);
497 }
498 }
499
500 }