2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.hpprinter.internal.api;
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;
22 * The {@link HPStatus} is responsible for handling reading of status data.
24 * @author Stewart Cossey - Initial contribution
27 public class HPStatus {
28 public static final String ENDPOINT = "/DevMgmt/ProductStatusDyn.xml";
30 private final String printerStatus;
31 private final boolean trayEmptyOrOpen;
33 public HPStatus(Document document) {
34 NodeList nodes = document.getDocumentElement().getElementsByTagName("psdyn:Status");
36 String localPrinterStatus = "Unknown";
37 boolean localTrayEmptyOrOpen = false;
38 for (int i = 0; i < nodes.getLength(); i++) {
39 Element element = (Element) nodes.item(i);
40 String statusCategory = element.getElementsByTagName("pscat:StatusCategory").item(0).getTextContent();
41 if (!"genuineHP".equals(statusCategory) && !"trayEmpty".equals(statusCategory)) {
42 localPrinterStatus = statusCategory;
44 if ("trayEmpty".equals(statusCategory)) {
45 localTrayEmptyOrOpen = true;
48 trayEmptyOrOpen = localTrayEmptyOrOpen;
49 printerStatus = localPrinterStatus;
52 public boolean getTrayEmptyOrOpen() {
53 return trayEmptyOrOpen;
56 public @Nullable String getPrinterStatus() {