1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.types;
17
18 import org.fourthline.cling.model.Constants;
19
20 import java.util.logging.Logger;
21 import java.util.regex.Pattern;
22 import java.util.regex.Matcher;
23
24
25
26
27
28
29
30
31
32 public class UDAServiceId extends ServiceId {
33
34 private static Logger log = Logger.getLogger(UDAServiceId.class.getName());
35
36 public static final String DEFAULT_NAMESPACE = "upnp-org";
37 public static final String BROKEN_DEFAULT_NAMESPACE = "schemas-upnp-org";
38
39 public static final Pattern PATTERN =
40 Pattern.compile("urn:" + DEFAULT_NAMESPACE + ":serviceId:(" + Constants.REGEX_ID+ ")");
41
42
43 public static final Pattern BROKEN_PATTERN =
44 Pattern.compile("urn:" + BROKEN_DEFAULT_NAMESPACE + ":service:(" + Constants.REGEX_ID+ ")");
45
46 public UDAServiceId(String id) {
47 super(DEFAULT_NAMESPACE, id);
48 }
49
50 public static UDAServiceId valueOf(String s) throws InvalidValueException {
51 Matcher matcher = UDAServiceId.PATTERN.matcher(s);
52 if (matcher.matches() && matcher.groupCount() >= 1) {
53 return new UDAServiceId(matcher.group(1));
54 }
55
56 matcher = UDAServiceId.BROKEN_PATTERN.matcher(s);
57 if (matcher.matches() && matcher.groupCount() >= 1) {
58 return new UDAServiceId(matcher.group(1));
59 }
60
61
62 matcher = Pattern.compile("urn:upnp-orgerviceId:urnchemas-upnp-orgervice:(" + Constants.REGEX_ID + ")").matcher(s);
63 if (matcher.matches()) {
64 log.warning("UPnP specification violation, recovering from Eyecon garbage: " + s);
65 return new UDAServiceId(matcher.group(1));
66 }
67
68
69 if("ContentDirectory".equals(s) ||
70 "ConnectionManager".equals(s) ||
71 "RenderingControl".equals(s) ||
72 "AVTransport".equals(s)) {
73 log.warning("UPnP specification violation, fixing broken Service ID: " + s);
74 return new UDAServiceId(s);
75 }
76
77 throw new InvalidValueException("Can't parse UDA service ID string (upnp-org/id): " + s);
78 }
79
80 }