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