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 java.util.EnumSet;
18 import java.util.Locale;
19
20
21
22
23 public class DLNAFlagsAttribute extends DLNAAttribute<EnumSet<DLNAFlags>> {
24
25 public DLNAFlagsAttribute() {
26 setValue(EnumSet.noneOf(DLNAFlags.class));
27 }
28
29 public DLNAFlagsAttribute(DLNAFlags... flags) {
30 if (flags != null && flags.length > 0) {
31 DLNAFlags first = flags[0];
32 if (flags.length > 1) {
33 System.arraycopy(flags, 1, flags, 0, flags.length - 1);
34 setValue(EnumSet.of(first, flags));
35 } else {
36 setValue(EnumSet.of(first));
37 }
38 }
39 }
40
41 public void setString(String s, String cf) throws InvalidDLNAProtocolAttributeException {
42 EnumSet<DLNAFlags> value = EnumSet.noneOf(DLNAFlags.class);
43 try {
44 int parseInt = Integer.parseInt(s.substring(0, s.length() - 24), 16);
45 for (DLNAFlags op : DLNAFlags.values()) {
46 int code = op.getCode() & parseInt;
47 if (op.getCode() == code) {
48 value.add(op);
49 }
50 }
51 } catch (Exception e) {
52 }
53
54 if (value.isEmpty())
55 throw new InvalidDLNAProtocolAttributeException("Can't parse DLNA flags integer from: " + s);
56
57 setValue(value);
58 }
59
60 public String getString() {
61 int code = 0;
62 for (DLNAFlags op : getValue()) {
63 code |= op.getCode();
64 }
65 return String.format(Locale.ROOT, "%08x%024x", code, 0);
66 }
67 }