1 /***
2 * Java DAB EPG API - Serialize/Deserialize To/From POJOs to XML/Binary as per
3 * ETSI specifications TS 102 818 (XML Specification for DAB EPG) and TS 102
4 * 371 (Transportation and Binary Encoding Specification for EPG).
5 *
6 * Copyright (C) 2007 GCap Media PLC
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 package com.gcapmedia.dab.epg;
23
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26
27 /***
28 * <p>A unique identifier for a programme, programme event or programme
29 * group in the format in the format of a Content Reference ID as
30 * defined in the TV-Anytime specification.</p>
31 *
32 * <p>This CRID (Content Reference
33 * ID) should be in the form of: <pre>crid://<authority>/<data></pre>
34 *
35 * Where
36 * <code><authority></code> is a registered Internet domain name that the
37 * CRID author has permission to use. The <code><authority></code> string is
38 * case insensitive. <code><data></code> is a free format string (URI
39 * compliant and case insensitive) that is meaningful to the given authority and
40 * should uniquely identify the content within that authority.
41 *
42 */
43 public class Crid {
44
45 /***
46 * CRID authority
47 */
48 private String authority;
49
50 /***
51 * CRID data
52 */
53 private String data;
54
55 /***
56 * CRID pattern
57 */
58 private final static Pattern cridPattern = Pattern.compile("crid://[^///]+///[^///]+");
59
60 /***
61 * Create a new CRID
62 * @param authority CRID authority
63 * @param data CRID data
64 */
65 public Crid(String authority, String data) {
66 this.authority = authority;
67 this.data = data;
68 }
69
70 /***
71 * Create a new CRID from its string representation
72 * @param crid CRID string
73 */
74 public Crid(String crid) {
75
76
77 if(!cridPattern.matcher(crid).matches()) {
78 throw new IllegalArgumentException("CRID does not match the pattern: " + cridPattern.pattern());
79 }
80
81
82 Matcher matcher = Pattern.compile("(?<=crid://)[^///]+(?=///[^///]+)").matcher(crid);
83 matcher.find();
84 this.authority = matcher.group();
85
86
87 matcher = Pattern.compile("[^///]+$").matcher(crid);
88 matcher.find();
89 this.data = matcher.group();
90 }
91
92 /***
93 * @return Returns the CRID authority
94 */
95 public String getAuthority() {
96 return authority;
97 }
98
99 /***
100 * @return Returns the CRID data
101 */
102 public String getData() {
103 return data;
104 }
105
106 /***
107 * @return Returns the formatted CRID
108 */
109 public String getCrid() {
110 return "crid://" + authority + "/" + data;
111 }
112
113 /***
114 * @see java.lang.Object#equals(java.lang.Object)
115 */
116 @Override
117 public boolean equals(Object obj) {
118 if(!(obj instanceof Crid)) {
119 return false;
120 }
121 Crid that = (Crid)obj;
122 return this.authority.equals(that.authority) && this.data.equals(that.data);
123 }
124
125 /***
126 * @see java.lang.Object#toString()
127 */
128 public String toString() {
129 return getCrid();
130 }
131
132 }