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