]> git.basschouten.com Git - openhab-addons.git/blob
220ef515364651a0784327efb34d6998e03037a3
[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 feature) {
43                 NodeList resourceType = feature.getElementsByTagName("dd:ResourceType");
44
45                 if (resourceType.getLength() > 0) {
46                     switch (resourceType.item(0).getTextContent()) {
47                         case "ledm:hpLedmProductStatusDyn":
48                             localProductStatus = true;
49                             break;
50
51                         case "ledm:hpLedmProductUsageDyn":
52                             localProductUsage = true;
53                             break;
54
55                         case "eSCL:eSclManifest":
56                             localScannerStatus = true;
57                             break;
58                     }
59                 }
60             }
61         }
62
63         productStatus = localProductStatus;
64         productUsage = localProductUsage;
65         scannerStatus = localScannerStatus;
66     }
67
68     public boolean getProductStatusSupported() {
69         return productStatus;
70     }
71
72     public boolean getProductUsageSupported() {
73         return productUsage;
74     }
75
76     public boolean getScannerStatusSupported() {
77         return scannerStatus;
78     }
79 }