]> git.basschouten.com Git - openhab-addons.git/blob
f54f5f3ba14a45643a611b30631e020d9dab8b5b
[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.eclipse.jdt.annotation.Nullable;
17 import org.w3c.dom.Document;
18 import org.w3c.dom.Element;
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 HPScannerStatus {
28     public static final String ENDPOINT = "/eSCL/ScannerStatus";
29
30     private final String status;
31     private final Boolean adfLoaded;
32
33     public HPScannerStatus(Document document) {
34         String localScannerStatus = "Unknown";
35         Boolean localAdfLoaded = false;
36
37         Element nodes = (Element) document.getDocumentElement();
38
39         NodeList state = nodes.getElementsByTagName("pwg:State");
40         if (state.getLength() > 0) {
41             localScannerStatus = state.item(0).getTextContent();
42         }
43
44         NodeList adfState = nodes.getElementsByTagName("scan:AdfState");
45         if (adfState.getLength() > 0) {
46             String adfStatus = adfState.item(0).getTextContent();
47             localAdfLoaded = convertAdfStatus(adfStatus);
48         }
49
50         adfLoaded = localAdfLoaded;
51         status = localScannerStatus;
52     }
53
54     private static Boolean convertAdfStatus(String status) {
55         return "ScannerAdfLoaded".equals(status);
56     }
57
58     public Boolean getAdfLoaded() {
59         return adfLoaded;
60     }
61
62     public @Nullable String getScannerStatus() {
63         return status;
64     }
65 }