1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.fourthline.cling.support.model.dlna;
16
17 import org.fourthline.cling.model.types.InvalidValueException;
18 import org.fourthline.cling.support.avtransport.lastchange.AVTransportVariable.TransportPlaySpeed;
19
20
21
22
23 public class DLNAPlaySpeedAttribute extends DLNAAttribute<TransportPlaySpeed[]> {
24
25 public DLNAPlaySpeedAttribute() {
26 setValue(new TransportPlaySpeed[] {});
27 }
28
29 public DLNAPlaySpeedAttribute(TransportPlaySpeed[] speeds) {
30 setValue(speeds);
31 }
32
33 public DLNAPlaySpeedAttribute(String[] speeds) {
34 TransportPlaySpeed[] sp = new TransportPlaySpeed[speeds.length];
35 try {
36 for (int i = 0; i < speeds.length; i++) {
37 sp[i] = new TransportPlaySpeed(speeds[i]);
38 }
39 } catch (InvalidValueException invalidValueException) {
40 throw new InvalidDLNAProtocolAttributeException("Can't parse DLNA play speeds.");
41 }
42 setValue(sp);
43 }
44
45 public void setString(String s, String cf) throws InvalidDLNAProtocolAttributeException {
46 TransportPlaySpeed[] value = null;
47 if (s != null && s.length() != 0) {
48 String[] speeds = s.split(",");
49 try {
50 value = new TransportPlaySpeed[speeds.length];
51 for (int i = 0; i < speeds.length; i++) {
52 value[i] = new TransportPlaySpeed(speeds[i]);
53 }
54 } catch (InvalidValueException invalidValueException) {
55 value = null;
56 }
57 }
58 if (value == null) {
59 throw new InvalidDLNAProtocolAttributeException("Can't parse DLNA play speeds from: " + s);
60 }
61 setValue(value);
62 }
63
64 public String getString() {
65 String s = "";
66 for (TransportPlaySpeed speed : getValue()) {
67 if (speed.getValue().equals("1"))
68 continue;
69 s += (s.length() == 0 ? "" : ",") + speed;
70 }
71 return s;
72 }
73
74 }