]> git.basschouten.com Git - openhab-addons.git/blob
23b4393b97871da448e853ade25e33ba514f9b19
[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.kodi.internal.model;
14
15 import java.util.regex.Matcher;
16 import java.util.regex.Pattern;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * Class representing a Kodi favorite.
23  *
24  * @author Christoph Weitkamp - Initial contribution
25  */
26 @NonNullByDefault
27 public class KodiFavorite {
28     // handle titles which are wrapped e.g. [COLOR FFE95E01]Title[/COLOR]
29     private static final Pattern TITLE_PATTERN = Pattern.compile("(\\[COLOR\\s\\w{8}\\])|(\\[/COLOR\\])");
30
31     /**
32      * The title of the favorite
33      */
34     private String title;
35
36     /**
37      * The type of the favorite
38      */
39     private String favoriteType = "unknown";
40
41     /**
42      * The path of the favorite
43      */
44     @Nullable
45     private String path;
46
47     /**
48      * The window of the favorite
49      */
50     @Nullable
51     private String window;
52
53     /**
54      * The parameters of the favorites window
55      */
56     @Nullable
57     private String windowParameter;
58
59     /**
60      * Constructs a favorite with the given title.
61      *
62      * @param title title of the favorite
63      */
64     public KodiFavorite(final String title) {
65         this.title = title;
66     }
67
68     /**
69      * Returns the title of the favorite.
70      *
71      * @return the title of the favorite
72      */
73     public String getTitle() {
74         return title;
75     }
76
77     /**
78      * Sets the title of the favorite.
79      *
80      * @param title title of the favorite
81      */
82     public void setTitle(final String title) {
83         Matcher m = TITLE_PATTERN.matcher(title);
84         this.title = m.replaceAll("");
85     }
86
87     /**
88      * Returns the type of the favorite.
89      *
90      * @return the type of the favorite
91      */
92     public String getFavoriteType() {
93         return favoriteType;
94     }
95
96     /**
97      * Sets the type of the favorite.
98      *
99      * @param favoriteType type of the favorite. Valid values are: "media", "window", "script" or "unknown"
100      */
101     public void setFavoriteType(final String favoriteType) {
102         this.favoriteType = favoriteType;
103     }
104
105     /**
106      * Returns the path of the favorite.
107      *
108      * @return the path of the favorite
109      */
110     @Nullable
111     public String getPath() {
112         return path;
113     }
114
115     /**
116      * Sets the path of the favorite.
117      *
118      * @param path path of the favorite
119      */
120     public void setPath(final String path) {
121         this.path = path;
122     }
123
124     /**
125      * Returns the window of the favorite.
126      *
127      * @return the window of the favorite
128      */
129     @Nullable
130     public String getWindow() {
131         return window;
132     }
133
134     /**
135      * Sets the window of the favorite.
136      *
137      * @param window the window of the favorite
138      */
139     public void setWindow(final String window) {
140         this.window = window;
141     }
142
143     /**
144      * Returns the parameters of the favorites window.
145      *
146      * @return the parameters of the favorites window
147      */
148     @Nullable
149     public String getWindowParameter() {
150         return windowParameter;
151     }
152
153     /**
154      * Sets the parameters of the favorites window.
155      *
156      * @param windowParameter the parameters of the favorites window
157      */
158     public void setWindowParameter(final String windowParameter) {
159         this.windowParameter = windowParameter;
160     }
161 }