]> git.basschouten.com Git - openhab-addons.git/blob
8c7de1346840a16e61f1506b9736a4b4158385b3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.xmltv.internal.jaxb;
14
15 import java.time.Instant;
16 import java.time.ZonedDateTime;
17 import java.time.format.DateTimeFormatter;
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import javax.xml.bind.annotation.XmlAccessType;
22 import javax.xml.bind.annotation.XmlAccessorType;
23 import javax.xml.bind.annotation.XmlAttribute;
24 import javax.xml.bind.annotation.XmlElement;
25 import javax.xml.bind.annotation.XmlType;
26 import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
27 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
28
29 import org.eclipse.jdt.annotation.NonNullByDefault;
30
31 /**
32  * Java class for a programme XML element
33  *
34  * @author GaĆ«l L'hopital - Initial contribution
35  */
36 @XmlAccessorType(XmlAccessType.FIELD)
37 @XmlType
38 @NonNullByDefault
39 public class Programme {
40     private static final DateTimeFormatter XMLTV_DATE_FORMAT = DateTimeFormatter.ofPattern("yyyyMMddHHmmss Z");
41
42     @XmlElement(name = "title", required = true)
43     protected List<WithLangType> titles = new ArrayList<>();
44
45     @XmlElement(name = "category")
46     protected List<WithLangType> categories = new ArrayList<>();
47
48     @XmlElement(name = "icon")
49     protected List<Icon> icons = new ArrayList<>();
50
51     @XmlAttribute(required = true)
52     private String start = "";
53
54     @XmlAttribute
55     private String stop = "";
56
57     @XmlAttribute(required = true)
58     @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
59     protected String channel = "";
60
61     public List<WithLangType> getTitles() {
62         return titles;
63     }
64
65     public List<WithLangType> getCategories() {
66         return categories;
67     }
68
69     public Instant getProgrammeStart() {
70         long epoch = iso860DateToEpoch(start);
71         return Instant.ofEpochMilli(epoch);
72     }
73
74     public Instant getProgrammeStop() {
75         long epoch = iso860DateToEpoch(stop);
76         return Instant.ofEpochMilli(epoch);
77     }
78
79     private long iso860DateToEpoch(String date) {
80         return ZonedDateTime.parse(date, XMLTV_DATE_FORMAT).toInstant().toEpochMilli();
81     }
82
83     public List<Icon> getIcons() {
84         return icons;
85     }
86
87     public String getChannel() {
88         return channel;
89     }
90 }