]> git.basschouten.com Git - openhab-addons.git/blob
afc34df18bcd07b41545234e7ab5dc02294f5dd0
[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.ihc.internal.ws.datatypes;
14
15 import java.io.IOException;
16
17 import javax.xml.xpath.XPathExpressionException;
18
19 import org.openhab.binding.ihc.internal.ws.exeptions.IhcExecption;
20
21 /**
22  * Class for WSFile complex type.
23  *
24  * @author Pauli Anttila - Initial contribution
25  */
26 public class WSFile {
27     private byte[] data;
28     private String filename;
29
30     public WSFile() {
31     }
32
33     public WSFile(byte[] data, String filename) {
34         this.data = data;
35         this.filename = filename;
36     }
37
38     /**
39      * Gets the data value for this WSFile.
40      *
41      * @return data
42      */
43     public byte[] getData() {
44         return data;
45     }
46
47     /**
48      * Sets the data value for this WSFile.
49      *
50      * @param data
51      */
52     public void setData(byte[] data) {
53         this.data = data;
54     }
55
56     /**
57      * Gets the filename value for this WSFile.
58      *
59      * @return filename
60      */
61     public String getFilename() {
62         return filename;
63     }
64
65     /**
66      * Sets the filename value for this WSFile.
67      *
68      * @param filename
69      */
70     public void setFilename(String filename) {
71         this.filename = filename;
72     }
73
74     public WSFile parseXMLData(String data) throws IhcExecption {
75         try {
76             filename = XPathUtils.parseXMLValue(data,
77                     "/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:getIHCProjectSegment4/ns1:filename");
78             this.data = XPathUtils
79                     .parseXMLValue(data, "/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:getIHCProjectSegment4/ns1:data")
80                     .getBytes();
81             return this;
82         } catch (IOException | XPathExpressionException e) {
83             throw new IhcExecption("Error occured during XML data parsing", e);
84         }
85     }
86 }