]> git.basschouten.com Git - openhab-addons.git/blob
35b9325df173fdf7b5fef8ecfe46940ba0f07541
[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.NodeList;
19
20 /**
21  * The {@link HPProductUsageFeatures} is responsible for determining what type of printer usage
22  * data the Web Interface supports including any features.
23  *
24  * @author Stewart Cossey - Initial contribution
25  */
26 @NonNullByDefault
27 public class HPProductUsageFeatures {
28     public static final String ENDPOINT = "/DevMgmt/ProductUsageDyn.xml";
29
30     private PrinterType printerType = PrinterType.UNKNOWN;
31     private boolean jamEvents;
32     private boolean mispickEvents;
33     private boolean subscriptionImpressions;
34     private boolean frontPanelCancel;
35     private boolean cumuMarking;
36     private boolean pagesRemaining;
37
38     private boolean scanAdf;
39     private boolean scanFlatbed;
40     private boolean scanToHost;
41     private boolean scanToEmail;
42     private boolean scanToFolder;
43
44     private boolean printApplication;
45     private boolean printApplicationChrome;
46
47     private boolean scannerEngine;
48     private boolean copyApplication;
49
50     private boolean cloudPrint;
51
52     public enum PrinterType {
53         UNKNOWN,
54         MONOCHROME,
55         SINGLECOLOR,
56         MULTICOLOR
57     }
58
59     public HPProductUsageFeatures(final Document document) {
60         // Check what Ink/Toner colours are present
61         final NodeList consumableInk = document.getDocumentElement().getElementsByTagName("pudyn:Consumable");
62
63         for (int i = 0; i < consumableInk.getLength(); i++) {
64             final Element currInk = (Element) consumableInk.item(i);
65             final String inkName = currInk.getElementsByTagName("dd:MarkerColor").item(0).getTextContent();
66             final String consumeType = currInk.getElementsByTagName("dd:ConsumableTypeEnum").item(0).getTextContent();
67
68             if ("printhead".equalsIgnoreCase(consumeType)) {
69                 continue;
70             }
71
72             cumuMarking = (currInk.getElementsByTagName("dd2:CumulativeMarkingAgentUsed").getLength() > 0);
73
74             switch (inkName.toLowerCase()) {
75                 case "cyan":
76                 case "magenta":
77                 case "yellow":
78                     printerType = PrinterType.MULTICOLOR; // Is multicolor if it has this ink
79                     break;
80
81                 case "cyanmagentayellow":
82                     printerType = PrinterType.SINGLECOLOR; // Is singlecolor if it has this ink
83                     break;
84
85                 case "black":
86                     if (printerType == PrinterType.UNKNOWN) {
87                         printerType = PrinterType.MONOCHROME; // Is Monochrome
88                     }
89                     break;
90             }
91         }
92
93         pagesRemaining = (((Element) consumableInk.item(0)).getElementsByTagName("dd:EstimatedPagesRemaining")
94                 .getLength() > 0);
95
96         final NodeList printerSubUnit = document.getDocumentElement().getElementsByTagName("pudyn:PrinterSubunit");
97         if (printerSubUnit.getLength() > 0) {
98             final Element currPrinterSubUnit = (Element) printerSubUnit.item(0);
99
100             jamEvents = (currPrinterSubUnit.getElementsByTagName("dd:JamEvents").getLength() > 0);
101             mispickEvents = (currPrinterSubUnit.getElementsByTagName("dd:MispickEvents").getLength() > 0);
102             subscriptionImpressions = (currPrinterSubUnit.getElementsByTagName("pudyn:SubscriptionImpressions")
103                     .getLength() > 0);
104             frontPanelCancel = (currPrinterSubUnit.getElementsByTagName("dd:TotalFrontPanelCancelPresses")
105                     .getLength() > 0);
106         }
107
108         final NodeList scannerSubUnit = document.getDocumentElement()
109                 .getElementsByTagName("pudyn:ScanApplicationSubunit");
110         if (scannerSubUnit.getLength() > 0) {
111             final Element currScannerSubUnit = (Element) scannerSubUnit.item(0);
112
113             scanAdf = (currScannerSubUnit.getElementsByTagName("dd:AdfImages").getLength() > 0);
114             scanFlatbed = (currScannerSubUnit.getElementsByTagName("dd:FlatbedImages").getLength() > 0);
115             scanToEmail = (currScannerSubUnit.getElementsByTagName("dd:ImagesSentToEmail").getLength() > 0);
116             scanToFolder = (currScannerSubUnit.getElementsByTagName("dd:ImagesSentToFolder").getLength() > 0);
117             scanToHost = (currScannerSubUnit.getElementsByTagName("dd:ScanToHostImages").getLength() > 0);
118         }
119
120         final NodeList scanAppSubUnit = document.getDocumentElement()
121                 .getElementsByTagName("pudyn:ScanApplicationSubunit");
122         if (scanAppSubUnit.getLength() > 0) {
123             printApplication = true;
124
125             final Element currAppSubUnit = (Element) scanAppSubUnit.item(0);
126
127             printApplicationChrome = (currAppSubUnit.getElementsByTagName("pudyn:RemoteDeviceType").getLength() > 0);
128         }
129
130         final NodeList printAppSubUnit = document.getDocumentElement()
131                 .getElementsByTagName("pudyn:PrintApplicationSubunit");
132         if (printAppSubUnit.getLength() > 0) {
133             final Element currPrintAppSubUnit = (Element) printAppSubUnit.item(0);
134
135             cloudPrint = (currPrintAppSubUnit.getElementsByTagName("dd:CloudPrintImpressions").getLength() > 0);
136         }
137
138         final NodeList scannerEngineSubUnit = document.getDocumentElement()
139                 .getElementsByTagName("pudyn:ScannerEngineSubunit");
140         scannerEngine = (scannerEngineSubUnit.getLength() > 0);
141
142         final NodeList copyAppSubUnit = document.getDocumentElement()
143                 .getElementsByTagName("pudyn:CopyApplicationSubunit");
144         copyApplication = (copyAppSubUnit.getLength() > 0);
145     }
146
147     public PrinterType getType() {
148         return printerType;
149     }
150
151     /**
152      * Printer data contains Scanner Engine.
153      * 
154      * pudyn:ProductUsageDyn -> pudyn:ScannerEngineSubunit
155      * 
156      * return {boolean} True is supported.
157      */
158     public boolean hasScannerEngine() {
159         return scannerEngine;
160     }
161
162     /**
163      * Printer data contains Copy Application.
164      * 
165      * pudyn:ProductUsageDyn -> pudyn:ScannerEngineSubunit
166      * 
167      * return {boolean} True is supported.
168      */
169     public boolean hasCopyApplication() {
170         return copyApplication;
171     }
172
173     /**
174      * Printer data contains Estimated Pages Remaining.
175      * 
176      * pudyn:ProductUsageDyn -> pudyn:ConsumableSubunit -> pudyn:Consumable -> dd:EstimatedPagesRemaining
177      * 
178      * return {boolean} True is supported.
179      */
180     public boolean hasPagesRemaining() {
181         return pagesRemaining;
182     }
183
184     /**
185      * Printer data contains Scan to Email.
186      *
187      * pudyn:ProductUsageDyn -> pudyn:ScanApplicationSubunit -> dd:ImagesSentToEmail
188      *
189      * @return {boolean} True if supported.
190      */
191     public boolean hasScanToEmail() {
192         return scanToEmail;
193     }
194
195     /**
196      * Printer data contains Scan to Folder.
197      *
198      * pudyn:ProductUsageDyn -> pudyn:ScanApplicationSubunit -> dd:ImagesSentToFolder
199      *
200      * @return {boolean} True if supported.
201      */
202     public boolean hasScanToFolder() {
203         return scanToFolder;
204     }
205
206     /**
207      * Printer data contains Scan to Host.
208      *
209      * pudyn:ProductUsageDyn -> pudyn:ScanApplicationSubunit -> dd:ScanToHostImages
210      *
211      * @return {boolean} True if supported.
212      */
213     public boolean hasScanToHost() {
214         return scanToHost;
215     }
216
217     /**
218      * Printer data contains Scanner Automatic Document Feeder.
219      *
220      * pudyn:ProductUsageDyn -> pudyn:ScanApplicationSubunit -> dd:AdfImages
221      *
222      * @return {boolean} True if supported.
223      */
224     public boolean hasScanADF() {
225         return scanAdf;
226     }
227
228     /**
229      * Printer data contains Scanner Flatbed.
230      *
231      * pudyn:ProductUsageDyn -> pudyn:ScanApplicationSubunit -> dd:FlatbedImages
232      *
233      * @return {boolean} True if supported.
234      */
235     public boolean hasScanFlatbed() {
236         return scanFlatbed;
237     }
238
239     /**
240      * Printer data has Google Cloud Print impressions.
241      * 
242      * pudyn:ProductUsageDyn -> pudyn:PrintApplicationSubunit -> dd:CloudPrintImpressions
243      * 
244      * @return {boolean} True if supported.
245      */
246     public boolean hasCloudPrint() {
247         return cloudPrint;
248     }
249
250     /**
251      * Printer data contains Print Application Usage Information.
252      *
253      * pudyn:ProductUsageDyn -> pudyn:MobileApplicationSubunit
254      *
255      * @return {boolean} True if supported.
256      */
257     public boolean hasPrintApplication() {
258         return printApplication;
259     }
260
261     /**
262      * Printer data contains Chrome Print Application Usage Information.
263      *
264      * pudyn:ProductUsageDyn -> pudyn:MobileApplicationSubunit
265      *
266      * @return {boolean} True if supported.
267      */
268     public boolean hasPrintApplicationChrome() {
269         return printApplicationChrome;
270     }
271
272     /**
273      * Printer data contains Cumulative Marking Agent Used.
274      *
275      * pudyn:ProductUsageDyn -> pudyn:ConsumableSubunit -> pudyn:Consumable -> dd2:CumulativeMarkingAgentUsed
276      *
277      * @return {boolean} True if supported.
278      */
279     public boolean hasCumulativeMarking() {
280         return cumuMarking;
281     }
282
283     /**
284      * Printer data contains Jam Events.
285      *
286      * pudyn:ProductUsageDyn -> pudyn:PrinterSubunit -> dd:JamEvents
287      *
288      * @return {boolean} True if supported.
289      */
290     public boolean hasJamEvents() {
291         return jamEvents;
292     }
293
294     /**
295      * Printer data contains Mispick Events.
296      *
297      * pudyn:ProductUsageDyn -> pudyn:PrinterSubunit -> dd:MispickEvents
298      *
299      * @return {boolean} True if supported.
300      */
301     public boolean hasMispickEvents() {
302         return mispickEvents;
303     }
304
305     /**
306      * Printer data contains Subscription Impressions count.
307      *
308      * pudyn:ProductUsageDyn -> pudyn:PrinterSubunit ->
309      * pudyn:SubscriptionImpressions
310      *
311      * @return {boolean} True if supported.
312      */
313     public boolean hasSubscriptionCount() {
314         return subscriptionImpressions;
315     }
316
317     /**
318      * Printer data contains Front panel cancel presses count.
319      *
320      * pudyn:ProductUsageDyn -> pudyn:PrinterSubunit ->
321      * dd:TotalFrontPanelCancelPresses
322      *
323      * @return {boolean} True if supported.
324      */
325     public boolean hasTotalFrontPanelCancelPresses() {
326         return frontPanelCancel;
327     }
328 }