]> git.basschouten.com Git - openhab-addons.git/blob
9ad00f00106f4a7615c7a270296b1f06c739ae4b
[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.vdr.internal.svdrp;
14
15 import java.util.NoSuchElementException;
16 import java.util.StringTokenizer;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19
20 /**
21  * The {@link SVDRPWelcome} contains SVDRP Response Data that is sent after Connection has been established
22  *
23  * @author Matthias Klocke - Initial contribution
24  */
25 @NonNullByDefault
26 public class SVDRPWelcome {
27
28     private String version = "";
29     private String charset = "";
30     private String dateAndTime = "";
31
32     private SVDRPWelcome() {
33     }
34
35     /**
36      * Parse SVDRPResponse into SVDRPWelcome Object
37      *
38      * @param message SVDRP Client Response
39      *            Example: VDRHOST SVDRP VideoDiskRecorder 2.4.5; Sat Jan 9 22:28:11 2021; UTF-8
40      * @return Welcome Object
41      * @throws SVDRPParseResponseException thrown if response data is not parseable
42      */
43     public static SVDRPWelcome parse(String message) throws SVDRPParseResponseException {
44         SVDRPWelcome welcome = new SVDRPWelcome();
45         StringTokenizer st = new StringTokenizer(message, ";");
46         try {
47             String hostAndVersion = st.nextToken();
48             String dateAndTime = st.nextToken();
49             String charset = st.nextToken();
50             welcome.setCharset(charset.trim());
51             welcome.setVersion(hostAndVersion.substring(hostAndVersion.lastIndexOf(" ")).trim());
52             welcome.setDateAndTime(dateAndTime.trim());
53         } catch (NoSuchElementException nex) {
54             throw new SVDRPParseResponseException(nex.getMessage(), nex);
55         }
56         return welcome;
57     }
58
59     /**
60      * Get VDR version
61      *
62      * @return VDR version String
63      */
64     public String getVersion() {
65         return version;
66     }
67
68     /**
69      * Set VDR version
70      *
71      * @param version VDR version String
72      */
73     public void setVersion(String version) {
74         this.version = version;
75     }
76
77     /**
78      * Get VDR Charset
79      *
80      * @return VDR charset
81      */
82     public String getCharset() {
83         return charset;
84     }
85
86     /**
87      * Set VDR Charset
88      *
89      * @param charset VDR charset
90      */
91     public void setCharset(String charset) {
92         this.charset = charset;
93     }
94
95     /**
96      * Get VDR Date and Time String
97      *
98      * @return VDR Date and Time String
99      */
100     public String getDateAndTime() {
101         return dateAndTime;
102     }
103
104     /**
105      * Set VDR Date and Time String
106      *
107      * @param dateAndTime VDR Date and Time String
108      */
109     public void setDateAndTime(String dateAndTime) {
110         this.dateAndTime = dateAndTime;
111     }
112 }