]> git.ipfire.org Git - thirdparty/cups.git/blame - scripting/java/src/com/easysw/cups/CupsPrinter.java
Load cups into easysw/current.
[thirdparty/cups.git] / scripting / java / src / com / easysw / cups / CupsPrinter.java
CommitLineData
ef416fc2 1package com.easysw.cups;
2
3/**
4 * @version 1.00 06-NOV-2002
5 * @author Easy Software Products
6 *
7 * Internet Printing Protocol definitions for the Common UNIX Printing
8 * System (CUPS).
9 *
10 * Copyright 1997-2002 by Easy Software Products.
11 *
12 * These coded instructions, statements, and computer programs are the
13 * property of Easy Software Products and are protected by Federal
14 * copyright law. Distribution and use rights are outlined in the file
15 * "LICENSE.txt" which should have been included with this file. If this
16 * file is missing or damaged please contact Easy Software Products
17 * at:
18 *
19 * Attn: CUPS Licensing Information
20 * Easy Software Products
21 * 44141 Airport View Drive, Suite 204
22 * Hollywood, Maryland 20636-3111 USA
23 *
24 * Voice: (301) 373-9603
25 * EMail: cups-info@cups.org
26 * WWW: http://www.cups.org
27 */
28
29/**
30 * A <code>CupsPrinter</code> holds printer attribute / status information,
31 * and has methods to process CUPS server responses.
32 *
33 * @author TDB
34 * @version 1.0
35 * @since JDK1.3
36 */
37
38import java.io.*;
39import java.net.*;
40import java.util.*;
41
42public class CupsPrinter
43{
44
45 //
46 // Printer attributes / status members.
47 //
48 String printer_name;
49
50 String printer_location;
51 String printer_info;
52 String printer_more_info;
53
54 String[] printer_uri_supported; // Strings
55 String[] uri_authentication_supported; // Strings
56 String[] uri_security_supported; // Strings
57
58 String attributes_charset;
59 String attributes_natural_language;
60
61 int printer_state;
62 String printer_state_text;
63 String printer_state_reasons;
64
65 boolean printer_is_accepting_jobs;
66
67 long printer_up_time;
68 long printer_current_time;
69
70 int queued_job_count;
71
72 String[] pdl_override_supported;
73 String[] ipp_versions_supported;
74
75 int[] operations_supported; // Integers
76
77 boolean multiple_document_jobs_supported;
78 int multiple_operation_time_out;
79 int[] multiple_document_handling_supported; // Integers
80
81 String charset_configured;
82 String natural_language_configured;
83 String generated_natural_language_supported;
84 String[] charset_supported; // Strings
85
86 String document_format_default;
87 String[] document_format_supported; // Strings
88
89 String[] compression_supported; // Strings
90
91 int job_priority_default;
92 int job_priority_supported;
93
94 int copies_default;
95 int lower_copies_supported;
96 int upper_copies_supported;
97
98 boolean page_ranges_supported;
99
100 int number_up_default;
101 int[] number_up_supported; // integers
102
103
104 int orientation_requested_default;
105 int[] orientation_requested_supported; // Integers
106
107 int job_quota_period;
108 int job_k_limit;
109 int job_page_limit;
110
111 String job_sheets_default; // Should this be a list too?
112 String[] job_sheets_supported; // Strings
113
114 String device_uri;
115
116 boolean color_supported;
117 int pages_per_minute;
118
119 String printer_make_and_model;
120
121 String media_default;
122 String[] media_supported; // Strings
123
124 int finishings_default;
125 int[] finishings_supported; // Integers
126
127 int printer_type;
128
129
130
131 /**
132 * Constructor. Does not get status or attributes.
133 *
134 * @param <code>c</code> Cups object.
135 *
136 * @see <code>Cups</code>
137 */
138 public CupsPrinter(Cups c)
139 {
140 setDefaults();
141 }
142
143 /**
144 * Constructor with name. Get status and attributes.
145 *
146 * @param <code>c</code> Cups object.
147 * @param <code>name</code> Name of printer.
148 *
149 * @see <code>Cups</code>
150 */
151 public CupsPrinter(Cups c, String name)
152 {
153 setDefaults();
154 printer_name = name;
155
156 //
157 //
158 getStatus(c);
159 getAttributes(c);
160 }
161
162
163
164 /**
165 * Initialize the members with mostly sane values.
166 *
167 */
168 public void setDefaults()
169 {
170 printer_name = "";
171 printer_location = "";
172 printer_info = "";
173 printer_more_info = "";
174 printer_uri_supported = null;
175 uri_authentication_supported = null;
176 uri_security_supported = null;
177 attributes_charset = "us-ascii";
178 attributes_natural_language = "en";
179 printer_state = -1;
180 printer_state_text = "";
181 printer_state_reasons = "";
182 printer_is_accepting_jobs = false;
183 printer_up_time = 0;
184 printer_current_time = 0;
185 queued_job_count = 0;
186 pdl_override_supported = null;
187 ipp_versions_supported = null;
188 operations_supported = null;
189 multiple_document_jobs_supported = false;
190 multiple_operation_time_out = 0;
191 multiple_document_handling_supported = null;
192 charset_configured = "";
193 natural_language_configured = "";
194 generated_natural_language_supported = "";
195 charset_supported = null;
196 document_format_default = "";
197 document_format_supported = null;
198 compression_supported = null;
199 job_priority_default = -1;
200 job_priority_supported = -1;
201 copies_default = 1;
202 lower_copies_supported = 1;
203 upper_copies_supported = 1;
204 page_ranges_supported = false;
205 number_up_default = 0;
206 number_up_supported = null;
207 orientation_requested_default = 0;
208 orientation_requested_supported = null;
209 job_quota_period = 0;
210 job_k_limit = 0;
211 job_page_limit = 0;
212 job_sheets_default = "none,none";
213 job_sheets_supported = null;
214 device_uri = "";
215 color_supported = false;
216 pages_per_minute = 0;
217 printer_make_and_model = "";
218 media_default = "";
219 media_supported = null;
220 finishings_default = 0;
221 finishings_supported = null;
222 printer_type = 0;
223 }
224
225
226 /**
227 * Get the printer's status.
228 *
229 * @param <code>c</code> Cups object.
230 *
231 * @return <code>Boolean</code> True on success.
232 *
233 * @see <code>Cups</code>
234 */
235 public boolean getStatus(Cups c)
236 {
237 List attrs;
238 IPPAttribute a;
239 String p_uri;
240
241 try
242 {
243 attrs = c.cupsGetPrinterStatus(printer_name);
244 for (int i=0; i < attrs.size(); i++)
245 {
246 a = (IPPAttribute)attrs.get(i);
247 updateAttribute(a);
248 }
249 return(true);
250 }
251 catch (IOException e)
252 {
253 return(false);
254 }
255 }
256
257
258
259 /**
260 * Get the printer's attributes.
261 *
262 * @param <code>c</code> Cups object.
263 *
264 * @return <code>Boolean</code> True on success.
265 *
266 * @see <code>Cups</code>
267 */
268 public boolean getAttributes(Cups c)
269 {
270 List attrs;
271 IPPAttribute a;
272 String p_uri;
273
274 try
275 {
276 attrs = c.cupsGetPrinterAttributes(printer_name);
277 for (int i=0; i < attrs.size(); i++)
278 {
279 a = (IPPAttribute)attrs.get(i);
280 updateAttribute(a);
281 }
282 return(true);
283 }
284 catch (IOException e)
285 {
286 return(false);
287 }
288 }
289
290
291
292
293 /**
294 * Process an attribute from the cups.doRequest() method and move
295 * the values into local members.
296 *
297 * @param <code>a</code> IPPAttribute.
298 *
299 * @see <code>IPPAttributes</code>
300 * @see <code>IPPValues</code>
301 */
302 public void updateAttribute( IPPAttribute a )
303 {
304 IPPValue v;
305 int i;
306
307 // a.dump_values();
308
309 if (a.name.compareTo("printer-name") == 0)
310 {
311 v = (IPPValue)a.values.get(0);
312 printer_name = v.text;
313 }
314 else if (a.name.compareTo("printer-location") == 0)
315 {
316 v = (IPPValue)a.values.get(0);
317 printer_location = v.text;
318 }
319 else if (a.name.compareTo("printer-info") == 0)
320 {
321 v = (IPPValue)a.values.get(0);
322 printer_info = v.text;
323 }
324 else if (a.name.compareTo("printer-more-info") == 0)
325 {
326 v = (IPPValue)a.values.get(0);
327 printer_more_info = v.text;
328 }
329 else if (a.name.compareTo("printer-uri-supported") == 0)
330 {
331 printer_uri_supported = new String[a.values.size()];
332 for (i=0; i < a.values.size(); i++)
333 {
334 v = (IPPValue)a.values.get(i);
335 printer_uri_supported[i] = v.text;
336 }
337 }
338 else if (a.name.compareTo("uri-authentication-supported") == 0)
339 {
340 uri_authentication_supported = new String[a.values.size()];
341 for (i=0; i < a.values.size(); i++)
342 {
343 v = (IPPValue)a.values.get(i);
344 uri_authentication_supported[i] = v.text;
345 }
346 }
347 else if (a.name.compareTo("uri-security-supported") == 0)
348 {
349 uri_security_supported = new String[a.values.size()];
350 for (i=0; i < a.values.size(); i++)
351 {
352 v = (IPPValue)a.values.get(i);
353 uri_security_supported[i] = v.text;
354 }
355 }
356 else if (a.name.compareTo("attributes-charset") == 0)
357 {
358 v = (IPPValue)a.values.get(0);
359 attributes_charset = v.text;
360 }
361 else if (a.name.compareTo("attributes-natural-language") == 0)
362 {
363 v = (IPPValue)a.values.get(0);
364 attributes_natural_language = v.text;
365 }
366 else if (a.name.compareTo("printer-state") == 0)
367 {
368 v = (IPPValue)a.values.get(0);
369 printer_state = v.integer_value;
370 switch( printer_state )
371 {
372 case 3: printer_state_text = "idle";
373 break;
374 case 4: printer_state_text = "processing";
375 break;
376 case 5: printer_state_text = "stopped";
377 break;
378 }
379 }
380 else if (a.name.compareTo("printer-state-reasons") == 0)
381 {
382 v = (IPPValue)a.values.get(0);
383 printer_state_reasons = v.text;
384 }
385 else if (a.name.compareTo("printer-is-accepting-jobs") == 0)
386 {
387 v = (IPPValue)a.values.get(0);
388 printer_is_accepting_jobs = v.boolean_value;
389 }
390 else if (a.name.compareTo("printer-up-time") == 0)
391 {
392 v = (IPPValue)a.values.get(0);
393 printer_up_time = v.integer_value;
394 }
395 else if (a.name.compareTo("printer-current-time") == 0)
396 {
397 v = (IPPValue)a.values.get(0);
398 printer_current_time = v.unix_time; // *** FIX ***
399 }
400 else if (a.name.compareTo("queue-job-count") == 0)
401 {
402 v = (IPPValue)a.values.get(0);
403 queued_job_count = v.integer_value;
404 }
405 else if (a.name.compareTo("pdl-override-supported") == 0)
406 {
407 pdl_override_supported = new String[a.values.size()];
408 for (i=0; i < a.values.size(); i++)
409 {
410 v = (IPPValue)a.values.get(i);
411 pdl_override_supported[i] = v.text;
412 }
413 }
414 else if (a.name.compareTo("ipp-versions-supported") == 0)
415 {
416 ipp_versions_supported = new String[a.values.size()];
417 for (i=0; i < a.values.size(); i++)
418 {
419 v = (IPPValue)a.values.get(i);
420 ipp_versions_supported[i] = v.text;
421 }
422 }
423 else if (a.name.compareTo("operations-supported") == 0)
424 {
425 operations_supported = new int[a.values.size()];
426 for (i=0; i < a.values.size(); i++)
427 {
428 v = (IPPValue)a.values.get(i);
429 operations_supported[i] = v.integer_value;
430 }
431 }
432 else if (a.name.compareTo("multiple-document-jobs-supported") == 0)
433 {
434 v = (IPPValue)a.values.get(0);
435 multiple_document_jobs_supported = v.boolean_value;
436 }
437 else if (a.name.compareTo("multiple-operation-time-out") == 0)
438 {
439 v = (IPPValue)a.values.get(0);
440 multiple_operation_time_out = v.integer_value;
441 }
442 else if (a.name.compareTo("multiple-document-handling-supported") == 0)
443 {
444 multiple_document_handling_supported = new int[a.values.size()];
445 for (i=0; i < a.values.size(); i++)
446 {
447 v = (IPPValue)a.values.get(i);
448 multiple_document_handling_supported[i] = v.integer_value;
449 }
450 }
451 else if (a.name.compareTo("charset-configured") == 0)
452 {
453 v = (IPPValue)a.values.get(0);
454 charset_configured = v.text;
455 }
456 else if (a.name.compareTo("natural-language-configured") == 0)
457 {
458 v = (IPPValue)a.values.get(0);
459 natural_language_configured = v.text;
460 }
461 else if (a.name.compareTo("generated-natural-language-supported") == 0)
462 {
463 // *** Should this be a list too?
464 v = (IPPValue)a.values.get(0);
465 generated_natural_language_supported = v.text;
466 }
467 else if (a.name.compareTo("charset-supported") == 0)
468 {
469 charset_supported = new String[a.values.size()];
470 for (i=0; i < a.values.size(); i++)
471 {
472 v = (IPPValue)a.values.get(i);
473 charset_supported[i] = v.text;
474 }
475 }
476 else if (a.name.compareTo("document-format-default") == 0)
477 {
478 v = (IPPValue)a.values.get(0);
479 document_format_default = v.text;
480 }
481 else if (a.name.compareTo("document-format-supported") == 0)
482 {
483 document_format_supported = new String[a.values.size()];
484 for (i=0; i < a.values.size(); i++)
485 {
486 v = (IPPValue)a.values.get(i);
487 document_format_supported[i] = v.text;
488 }
489 }
490 else if (a.name.compareTo("compression-supported") == 0)
491 {
492 compression_supported = new String[a.values.size()];
493 for (i=0; i < a.values.size(); i++)
494 {
495 v = (IPPValue)a.values.get(i);
496 compression_supported[i] = v.text;
497 }
498 }
499 else if (a.name.compareTo("job-priority-default") == 0)
500 {
501 v = (IPPValue)a.values.get(0);
502 job_priority_default = v.integer_value;
503 }
504 else if (a.name.compareTo("job-priority-supported") == 0)
505 {
506 // *** Should be a list? ***
507 v = (IPPValue)a.values.get(0);
508 job_priority_supported = v.integer_value;
509 }
510 else if (a.name.compareTo("copies-default") == 0)
511 {
512 v = (IPPValue)a.values.get(0);
513 copies_default = v.integer_value;
514 }
515 else if (a.name.compareTo("copies-supported") == 0)
516 {
517 v = (IPPValue)a.values.get(0);
518 lower_copies_supported = v.lower;
519 upper_copies_supported = v.upper;
520 }
521 else if (a.name.compareTo("page-ranges-supported") == 0)
522 {
523 v = (IPPValue)a.values.get(0);
524 page_ranges_supported = v.boolean_value;
525 }
526 else if (a.name.compareTo("number-up-default") == 0)
527 {
528 v = (IPPValue)a.values.get(0);
529 number_up_default = v.integer_value;
530 }
531 else if (a.name.compareTo("number-up-supported") == 0)
532 {
533 number_up_supported = new int[a.values.size()];
534 for (i=0; i < a.values.size(); i++)
535 {
536 v = (IPPValue)a.values.get(i);
537 number_up_supported[i] = v.integer_value;
538 }
539 }
540 else if (a.name.compareTo("orientation-requested-default") == 0)
541 {
542 v = (IPPValue)a.values.get(0);
543 orientation_requested_default = v.integer_value;
544 }
545 else if (a.name.compareTo("orientation-requested-supported") == 0)
546 {
547 orientation_requested_supported = new int[a.values.size()];
548 for (i=0; i < a.values.size(); i++)
549 {
550 v = (IPPValue)a.values.get(i);
551 orientation_requested_supported[i] = v.integer_value;
552 }
553 }
554 else if (a.name.compareTo("job-quota-period") == 0)
555 {
556 v = (IPPValue)a.values.get(0);
557 job_quota_period = v.integer_value;
558 }
559 else if (a.name.compareTo("job-k-limit") == 0)
560 {
561 v = (IPPValue)a.values.get(0);
562 job_k_limit = v.integer_value;
563 }
564 else if (a.name.compareTo("job-page-limit") == 0)
565 {
566 v = (IPPValue)a.values.get(0);
567 job_page_limit = v.integer_value;
568 }
569 else if (a.name.compareTo("job-sheets-default") == 0)
570 {
571 v = (IPPValue)a.values.get(0);
572 job_sheets_default = v.text;
573 }
574 else if (a.name.compareTo("job-sheets-supported") == 0)
575 {
576 job_sheets_supported = new String[a.values.size()];
577 for (i=0; i < a.values.size(); i++)
578 {
579 v = (IPPValue)a.values.get(i);
580 job_sheets_supported[i] = v.text;
581 }
582 }
583 else if (a.name.compareTo("device-uri") == 0)
584 {
585 v = (IPPValue)a.values.get(0);
586 device_uri = v.text;
587 }
588 else if (a.name.compareTo("color-supported") == 0)
589 {
590 v = (IPPValue)a.values.get(0);
591 color_supported = v.boolean_value;
592 }
593 else if (a.name.compareTo("pages-per-minute") == 0)
594 {
595 v = (IPPValue)a.values.get(0);
596 pages_per_minute = v.integer_value;
597 }
598 else if (a.name.compareTo("printer-make-and-model") == 0)
599 {
600 v = (IPPValue)a.values.get(0);
601 printer_make_and_model = v.text;
602 }
603 else if (a.name.compareTo("media-default") == 0)
604 {
605 v = (IPPValue)a.values.get(0);
606 media_default = v.text;
607 }
608 else if (a.name.compareTo("media-supported") == 0)
609 {
610 media_supported = new String[a.values.size()];
611 for (i=0; i < a.values.size(); i++)
612 {
613 v = (IPPValue)a.values.get(i);
614 media_supported[i] = v.text;
615 }
616 }
617 else if (a.name.compareTo("finishings-default") == 0)
618 {
619 v = (IPPValue)a.values.get(0);
620 finishings_default = v.integer_value;
621 }
622 else if (a.name.compareTo("finishings-supported") == 0)
623 {
624 finishings_supported = new int[a.values.size()];
625 for (i=0; i < a.values.size(); i++)
626 {
627 v = (IPPValue)a.values.get(i);
628 finishings_supported[i] = v.integer_value;
629 }
630 }
631 else if (a.name.compareTo("printer-type") == 0)
632 {
633 v = (IPPValue)a.values.get(0);
634 printer_type = v.integer_value;
635 }
636
637 } // End of updateAttribute()
638
639
640 /**
641 * Get the printer name.
642 *
643 * @return <code>String</code> Printer Name.
644 */
645 public String getPrinterName()
646 {
647 return(printer_name);
648 }
649
650 /**
651 * Get the printer state text.
652 *
653 * @return <code>String</code> State text.
654 */
655 public String getStateText()
656 {
657 return(printer_state_text);
658 }
659
660 /**
661 * Get the printer state reasons.
662 *
663 * @return <code>String</code> State reason.
664 */
665 public String getStateReasons()
666 {
667 return(printer_state_reasons);
668 }
669
670 /**
671 * Get the printer location.
672 *
673 * @return <code>String</code> State location.
674 */
675 public String getLocation()
676 {
677 return(printer_location);
678 }
679
680 /**
681 * Get the printer make and model.
682 *
683 * @return <code>String</code> Make and model.
684 */
685 public String getMakeAndModel()
686 {
687 return(printer_make_and_model);
688 }
689
690
691
692 /**
693 * Get the default job sheets.
694 *
695 * @return <code>String</code> Default job sheets.
696 */
697 public String getJobSheetsDefault()
698 {
699 return(job_sheets_default);
700 }
701
702 /**
703 * Get the printer job sheets supported.
704 *
705 * @return <code>String[]</code> Array of supported job sheets.
706 */
707 public String[] getJobSheetsSupported()
708 {
709 return(job_sheets_supported);
710 }
711
712
713 /**
714 * Get the default orientation.
715 *
716 * @return <code>int</code> Default page orientation.
717 */
718 public int getOrientationDefault()
719 {
720 return(orientation_requested_default);
721 }
722
723 /**
724 * Get the printer orientation supported.
725 *
726 * @return <code>int[]</code> Array of supported orientations.
727 */
728 public int[] getOrientationSupported()
729 {
730 return(orientation_requested_supported);
731 }
732
733
734 /**
735 * Get the printer lower copies supported.
736 *
737 * @return <code>int</code> Lower of the range.
738 */
739 public int getLowerCopiesSupported()
740 {
741 return(lower_copies_supported);
742 }
743
744
745 /**
746 * Get the printer upper copies supported.
747 *
748 * @return <code>int</code> Upper of the range.
749 */
750 public int getUpperCopiesSupported()
751 {
752 return(upper_copies_supported);
753 }
754
755
756 /**
757 * Get the printer number of copies default.
758 *
759 * @return <code>int</code> Default number of copies.
760 */
761 public int getCopiesDefault()
762 {
763 return(copies_default);
764 }
765
766
767 /**
768 * Get whether the printer supports page ranges.
769 *
770 * @return <code>boolean</code> True or false.
771 */
772 public boolean getPageRangesSupported()
773 {
774 return(page_ranges_supported);
775 }
776
777
778
779 /**
780 * Debug method.
781 */
782 void dump()
783 {
784 int i;
785
786 System.out.println("Printer Name: " + printer_name );
787 System.out.println("Location: " + printer_location );
788 System.out.println("Printer Info: " + printer_info );
789 System.out.println("More Info: " + printer_more_info );
790
791 if (printer_uri_supported != null)
792 {
793 System.out.println("Printer URI's Supported: ");
794 for (i=0; i < printer_uri_supported.length; i++)
795 {
796 System.out.println(" " + printer_uri_supported[i] );
797 }
798 }
799
800 if (uri_authentication_supported != null)
801 {
802 System.out.println("URI Authentication Supported: ");
803 for (i=0; i < uri_authentication_supported.length; i++)
804 {
805 System.out.println(" " + uri_authentication_supported[i] );
806 }
807 }
808
809 if (uri_security_supported != null)
810 {
811 System.out.println("URI Security Supported: ");
812 for (i=0; i < uri_security_supported.length; i++)
813 {
814 System.out.println(" " + uri_security_supported[i] );
815 }
816 }
817
818 System.out.println("Attributes Charset: " + attributes_charset );
819 System.out.println("Attributes Natural Language: " + attributes_natural_language );
820
821 System.out.println("Printer State: " + printer_state );
822 System.out.println("Printer State Text: " + printer_state_text );
823 System.out.println("Printer State Reasons: " + printer_state_reasons );
824
825 if (printer_is_accepting_jobs)
826 System.out.println("Accepting Jobs: Yes");
827 else
828 System.out.println("Accepting Jobs: No");
829
830
831}
832
833
834
835} // End of CupsPrinter class
836
837