]> git.basschouten.com Git - openhab-addons.git/blob
b3ebb62d71cc43a3e0ea8e2013366e63b6a8d71d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.hpprinter.internal.api;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.core.thing.Thing;
20 import org.w3c.dom.Document;
21 import org.w3c.dom.Element;
22 import org.w3c.dom.Node;
23 import org.w3c.dom.NodeList;
24
25 /**
26  * The {@link HPProperties} is responsible for returning the
27  * reading of data from the HP Embedded Web Server.
28  *
29  * @author Martin van Wingerden - Initial contribution
30  */
31 @NonNullByDefault
32 public class HPProperties {
33     public static final String ENDPOINT = "/DevMgmt/ProductConfigDyn.xml";
34     private final Map<String, String> properties = new HashMap<>();
35
36     public HPProperties(Document document) {
37         NodeList nodes = document.getDocumentElement().getElementsByTagName("prdcfgdyn:ProductInformation");
38
39         for (int i = 0; i < nodes.getLength(); i++) {
40             Element element = (Element) nodes.item(i);
41             properties.put(Thing.PROPERTY_SERIAL_NUMBER,
42                     element.getElementsByTagName("dd:SerialNumber").item(0).getTextContent());
43             properties.put(Thing.PROPERTY_MODEL_ID,
44                     element.getElementsByTagName("dd:ProductNumber").item(0).getTextContent());
45             Node firmwareDate = element.getElementsByTagName("dd:Version").item(0);
46             properties.put(Thing.PROPERTY_FIRMWARE_VERSION, firmwareDate.getChildNodes().item(0).getTextContent());
47         }
48     }
49
50     public Map<String, String> getProperties() {
51         return properties;
52     }
53 }