]> git.basschouten.com Git - openhab-addons.git/blob
d725a7fc0e979992f4649d81fb4fc906c860c624
[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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.w3c.dom.Document;
17 import org.w3c.dom.Element;
18 import org.w3c.dom.Node;
19 import org.w3c.dom.NodeList;
20
21 /**
22  * The {@link HPScannerStatus} is responsible for handling reading of scanner status data.
23  *
24  * @author Stewart Cossey - Initial contribution
25  */
26 @NonNullByDefault
27 public class HPFeatures {
28     public static final String ENDPOINT = "/DevMgmt/DiscoveryTree.xml";
29
30     private final boolean productStatus;
31     private final boolean productUsage;
32     private final boolean scannerStatus;
33
34     public HPFeatures(Document document) {
35         Element root = (Element) document.getDocumentElement();
36
37         boolean localProductStatus = false;
38         boolean localProductUsage = false;
39         boolean localScannerStatus = false;
40
41         for (Node n = root.getFirstChild(); n != null; n = n.getNextSibling()) {
42             if (n instanceof Element) {
43                 Element feature = (Element) n;
44
45                 NodeList resourceType = feature.getElementsByTagName("dd:ResourceType");
46
47                 if (resourceType.getLength() > 0) {
48                     switch (resourceType.item(0).getTextContent()) {
49                         case "ledm:hpLedmProductStatusDyn":
50                             localProductStatus = true;
51                             break;
52
53                         case "ledm:hpLedmProductUsageDyn":
54                             localProductUsage = true;
55                             break;
56
57                         case "eSCL:eSclManifest":
58                             localScannerStatus = true;
59                             break;
60                     }
61                 }
62             }
63         }
64
65         productStatus = localProductStatus;
66         productUsage = localProductUsage;
67         scannerStatus = localScannerStatus;
68     }
69
70     public boolean getProductStatusSupported() {
71         return productStatus;
72     }
73
74     public boolean getProductUsageSupported() {
75         return productUsage;
76     }
77
78     public boolean getScannerStatusSupported() {
79         return scannerStatus;
80     }
81 }