1 package com
.easysw
.cups
;
4 * @version 1.00 06-NOV-2002
7 * Internet Printing Protocol definitions for the Common UNIX Printing
10 * Copyright 2007 by Apple Inc.
11 * Copyright 1997-2002 by Easy Software Products.
13 * These coded instructions, statements, and computer programs are the
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/".
21 * A <code>CupsPrinter</code> holds printer attribute / status information,
22 * and has methods to process CUPS server responses.
33 public class CupsPrinter
37 // Printer attributes / status members.
41 String printer_location
;
43 String printer_more_info
;
45 String
[] printer_uri_supported
; // Strings
46 String
[] uri_authentication_supported
; // Strings
47 String
[] uri_security_supported
; // Strings
49 String attributes_charset
;
50 String attributes_natural_language
;
53 String printer_state_text
;
54 String printer_state_reasons
;
56 boolean printer_is_accepting_jobs
;
59 long printer_current_time
;
63 String
[] pdl_override_supported
;
64 String
[] ipp_versions_supported
;
66 int[] operations_supported
; // Integers
68 boolean multiple_document_jobs_supported
;
69 int multiple_operation_time_out
;
70 int[] multiple_document_handling_supported
; // Integers
72 String charset_configured
;
73 String natural_language_configured
;
74 String generated_natural_language_supported
;
75 String
[] charset_supported
; // Strings
77 String document_format_default
;
78 String
[] document_format_supported
; // Strings
80 String
[] compression_supported
; // Strings
82 int job_priority_default
;
83 int job_priority_supported
;
86 int lower_copies_supported
;
87 int upper_copies_supported
;
89 boolean page_ranges_supported
;
91 int number_up_default
;
92 int[] number_up_supported
; // integers
95 int orientation_requested_default
;
96 int[] orientation_requested_supported
; // Integers
102 String job_sheets_default
; // Should this be a list too?
103 String
[] job_sheets_supported
; // Strings
107 boolean color_supported
;
108 int pages_per_minute
;
110 String printer_make_and_model
;
112 String media_default
;
113 String
[] media_supported
; // Strings
115 int finishings_default
;
116 int[] finishings_supported
; // Integers
123 * Constructor. Does not get status or attributes.
125 * @param <code>c</code> Cups object.
127 * @see <code>Cups</code>
129 public CupsPrinter(Cups c
)
135 * Constructor with name. Get status and attributes.
137 * @param <code>c</code> Cups object.
138 * @param <code>name</code> Name of printer.
140 * @see <code>Cups</code>
142 public CupsPrinter(Cups c
, String name
)
156 * Initialize the members with mostly sane values.
159 public void setDefaults()
162 printer_location
= "";
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";
171 printer_state_text
= "";
172 printer_state_reasons
= "";
173 printer_is_accepting_jobs
= false;
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;
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;
203 job_sheets_default
= "none,none";
204 job_sheets_supported
= null;
206 color_supported
= false;
207 pages_per_minute
= 0;
208 printer_make_and_model
= "";
210 media_supported
= null;
211 finishings_default
= 0;
212 finishings_supported
= null;
218 * Get the printer's status.
220 * @param <code>c</code> Cups object.
222 * @return <code>Boolean</code> True on success.
224 * @see <code>Cups</code>
226 public boolean getStatus(Cups c
)
234 attrs
= c
.cupsGetPrinterStatus(printer_name
);
235 for (int i
=0; i
< attrs
.size(); i
++)
237 a
= (IPPAttribute
)attrs
.get(i
);
242 catch (IOException e
)
251 * Get the printer's attributes.
253 * @param <code>c</code> Cups object.
255 * @return <code>Boolean</code> True on success.
257 * @see <code>Cups</code>
259 public boolean getAttributes(Cups c
)
267 attrs
= c
.cupsGetPrinterAttributes(printer_name
);
268 for (int i
=0; i
< attrs
.size(); i
++)
270 a
= (IPPAttribute
)attrs
.get(i
);
275 catch (IOException e
)
285 * Process an attribute from the cups.doRequest() method and move
286 * the values into local members.
288 * @param <code>a</code> IPPAttribute.
290 * @see <code>IPPAttributes</code>
291 * @see <code>IPPValues</code>
293 public void updateAttribute( IPPAttribute a
)
300 if (a
.name
.compareTo("printer-name") == 0)
302 v
= (IPPValue
)a
.values
.get(0);
303 printer_name
= v
.text
;
305 else if (a
.name
.compareTo("printer-location") == 0)
307 v
= (IPPValue
)a
.values
.get(0);
308 printer_location
= v
.text
;
310 else if (a
.name
.compareTo("printer-info") == 0)
312 v
= (IPPValue
)a
.values
.get(0);
313 printer_info
= v
.text
;
315 else if (a
.name
.compareTo("printer-more-info") == 0)
317 v
= (IPPValue
)a
.values
.get(0);
318 printer_more_info
= v
.text
;
320 else if (a
.name
.compareTo("printer-uri-supported") == 0)
322 printer_uri_supported
= new String
[a
.values
.size()];
323 for (i
=0; i
< a
.values
.size(); i
++)
325 v
= (IPPValue
)a
.values
.get(i
);
326 printer_uri_supported
[i
] = v
.text
;
329 else if (a
.name
.compareTo("uri-authentication-supported") == 0)
331 uri_authentication_supported
= new String
[a
.values
.size()];
332 for (i
=0; i
< a
.values
.size(); i
++)
334 v
= (IPPValue
)a
.values
.get(i
);
335 uri_authentication_supported
[i
] = v
.text
;
338 else if (a
.name
.compareTo("uri-security-supported") == 0)
340 uri_security_supported
= new String
[a
.values
.size()];
341 for (i
=0; i
< a
.values
.size(); i
++)
343 v
= (IPPValue
)a
.values
.get(i
);
344 uri_security_supported
[i
] = v
.text
;
347 else if (a
.name
.compareTo("attributes-charset") == 0)
349 v
= (IPPValue
)a
.values
.get(0);
350 attributes_charset
= v
.text
;
352 else if (a
.name
.compareTo("attributes-natural-language") == 0)
354 v
= (IPPValue
)a
.values
.get(0);
355 attributes_natural_language
= v
.text
;
357 else if (a
.name
.compareTo("printer-state") == 0)
359 v
= (IPPValue
)a
.values
.get(0);
360 printer_state
= v
.integer_value
;
361 switch( printer_state
)
363 case 3: printer_state_text
= "idle";
365 case 4: printer_state_text
= "processing";
367 case 5: printer_state_text
= "stopped";
371 else if (a
.name
.compareTo("printer-state-reasons") == 0)
373 v
= (IPPValue
)a
.values
.get(0);
374 printer_state_reasons
= v
.text
;
376 else if (a
.name
.compareTo("printer-is-accepting-jobs") == 0)
378 v
= (IPPValue
)a
.values
.get(0);
379 printer_is_accepting_jobs
= v
.boolean_value
;
381 else if (a
.name
.compareTo("printer-up-time") == 0)
383 v
= (IPPValue
)a
.values
.get(0);
384 printer_up_time
= v
.integer_value
;
386 else if (a
.name
.compareTo("printer-current-time") == 0)
388 v
= (IPPValue
)a
.values
.get(0);
389 printer_current_time
= v
.unix_time
; // *** FIX ***
391 else if (a
.name
.compareTo("queue-job-count") == 0)
393 v
= (IPPValue
)a
.values
.get(0);
394 queued_job_count
= v
.integer_value
;
396 else if (a
.name
.compareTo("pdl-override-supported") == 0)
398 pdl_override_supported
= new String
[a
.values
.size()];
399 for (i
=0; i
< a
.values
.size(); i
++)
401 v
= (IPPValue
)a
.values
.get(i
);
402 pdl_override_supported
[i
] = v
.text
;
405 else if (a
.name
.compareTo("ipp-versions-supported") == 0)
407 ipp_versions_supported
= new String
[a
.values
.size()];
408 for (i
=0; i
< a
.values
.size(); i
++)
410 v
= (IPPValue
)a
.values
.get(i
);
411 ipp_versions_supported
[i
] = v
.text
;
414 else if (a
.name
.compareTo("operations-supported") == 0)
416 operations_supported
= new int[a
.values
.size()];
417 for (i
=0; i
< a
.values
.size(); i
++)
419 v
= (IPPValue
)a
.values
.get(i
);
420 operations_supported
[i
] = v
.integer_value
;
423 else if (a
.name
.compareTo("multiple-document-jobs-supported") == 0)
425 v
= (IPPValue
)a
.values
.get(0);
426 multiple_document_jobs_supported
= v
.boolean_value
;
428 else if (a
.name
.compareTo("multiple-operation-time-out") == 0)
430 v
= (IPPValue
)a
.values
.get(0);
431 multiple_operation_time_out
= v
.integer_value
;
433 else if (a
.name
.compareTo("multiple-document-handling-supported") == 0)
435 multiple_document_handling_supported
= new int[a
.values
.size()];
436 for (i
=0; i
< a
.values
.size(); i
++)
438 v
= (IPPValue
)a
.values
.get(i
);
439 multiple_document_handling_supported
[i
] = v
.integer_value
;
442 else if (a
.name
.compareTo("charset-configured") == 0)
444 v
= (IPPValue
)a
.values
.get(0);
445 charset_configured
= v
.text
;
447 else if (a
.name
.compareTo("natural-language-configured") == 0)
449 v
= (IPPValue
)a
.values
.get(0);
450 natural_language_configured
= v
.text
;
452 else if (a
.name
.compareTo("generated-natural-language-supported") == 0)
454 // *** Should this be a list too?
455 v
= (IPPValue
)a
.values
.get(0);
456 generated_natural_language_supported
= v
.text
;
458 else if (a
.name
.compareTo("charset-supported") == 0)
460 charset_supported
= new String
[a
.values
.size()];
461 for (i
=0; i
< a
.values
.size(); i
++)
463 v
= (IPPValue
)a
.values
.get(i
);
464 charset_supported
[i
] = v
.text
;
467 else if (a
.name
.compareTo("document-format-default") == 0)
469 v
= (IPPValue
)a
.values
.get(0);
470 document_format_default
= v
.text
;
472 else if (a
.name
.compareTo("document-format-supported") == 0)
474 document_format_supported
= new String
[a
.values
.size()];
475 for (i
=0; i
< a
.values
.size(); i
++)
477 v
= (IPPValue
)a
.values
.get(i
);
478 document_format_supported
[i
] = v
.text
;
481 else if (a
.name
.compareTo("compression-supported") == 0)
483 compression_supported
= new String
[a
.values
.size()];
484 for (i
=0; i
< a
.values
.size(); i
++)
486 v
= (IPPValue
)a
.values
.get(i
);
487 compression_supported
[i
] = v
.text
;
490 else if (a
.name
.compareTo("job-priority-default") == 0)
492 v
= (IPPValue
)a
.values
.get(0);
493 job_priority_default
= v
.integer_value
;
495 else if (a
.name
.compareTo("job-priority-supported") == 0)
497 // *** Should be a list? ***
498 v
= (IPPValue
)a
.values
.get(0);
499 job_priority_supported
= v
.integer_value
;
501 else if (a
.name
.compareTo("copies-default") == 0)
503 v
= (IPPValue
)a
.values
.get(0);
504 copies_default
= v
.integer_value
;
506 else if (a
.name
.compareTo("copies-supported") == 0)
508 v
= (IPPValue
)a
.values
.get(0);
509 lower_copies_supported
= v
.lower
;
510 upper_copies_supported
= v
.upper
;
512 else if (a
.name
.compareTo("page-ranges-supported") == 0)
514 v
= (IPPValue
)a
.values
.get(0);
515 page_ranges_supported
= v
.boolean_value
;
517 else if (a
.name
.compareTo("number-up-default") == 0)
519 v
= (IPPValue
)a
.values
.get(0);
520 number_up_default
= v
.integer_value
;
522 else if (a
.name
.compareTo("number-up-supported") == 0)
524 number_up_supported
= new int[a
.values
.size()];
525 for (i
=0; i
< a
.values
.size(); i
++)
527 v
= (IPPValue
)a
.values
.get(i
);
528 number_up_supported
[i
] = v
.integer_value
;
531 else if (a
.name
.compareTo("orientation-requested-default") == 0)
533 v
= (IPPValue
)a
.values
.get(0);
534 orientation_requested_default
= v
.integer_value
;
536 else if (a
.name
.compareTo("orientation-requested-supported") == 0)
538 orientation_requested_supported
= new int[a
.values
.size()];
539 for (i
=0; i
< a
.values
.size(); i
++)
541 v
= (IPPValue
)a
.values
.get(i
);
542 orientation_requested_supported
[i
] = v
.integer_value
;
545 else if (a
.name
.compareTo("job-quota-period") == 0)
547 v
= (IPPValue
)a
.values
.get(0);
548 job_quota_period
= v
.integer_value
;
550 else if (a
.name
.compareTo("job-k-limit") == 0)
552 v
= (IPPValue
)a
.values
.get(0);
553 job_k_limit
= v
.integer_value
;
555 else if (a
.name
.compareTo("job-page-limit") == 0)
557 v
= (IPPValue
)a
.values
.get(0);
558 job_page_limit
= v
.integer_value
;
560 else if (a
.name
.compareTo("job-sheets-default") == 0)
562 v
= (IPPValue
)a
.values
.get(0);
563 job_sheets_default
= v
.text
;
565 else if (a
.name
.compareTo("job-sheets-supported") == 0)
567 job_sheets_supported
= new String
[a
.values
.size()];
568 for (i
=0; i
< a
.values
.size(); i
++)
570 v
= (IPPValue
)a
.values
.get(i
);
571 job_sheets_supported
[i
] = v
.text
;
574 else if (a
.name
.compareTo("device-uri") == 0)
576 v
= (IPPValue
)a
.values
.get(0);
579 else if (a
.name
.compareTo("color-supported") == 0)
581 v
= (IPPValue
)a
.values
.get(0);
582 color_supported
= v
.boolean_value
;
584 else if (a
.name
.compareTo("pages-per-minute") == 0)
586 v
= (IPPValue
)a
.values
.get(0);
587 pages_per_minute
= v
.integer_value
;
589 else if (a
.name
.compareTo("printer-make-and-model") == 0)
591 v
= (IPPValue
)a
.values
.get(0);
592 printer_make_and_model
= v
.text
;
594 else if (a
.name
.compareTo("media-default") == 0)
596 v
= (IPPValue
)a
.values
.get(0);
597 media_default
= v
.text
;
599 else if (a
.name
.compareTo("media-supported") == 0)
601 media_supported
= new String
[a
.values
.size()];
602 for (i
=0; i
< a
.values
.size(); i
++)
604 v
= (IPPValue
)a
.values
.get(i
);
605 media_supported
[i
] = v
.text
;
608 else if (a
.name
.compareTo("finishings-default") == 0)
610 v
= (IPPValue
)a
.values
.get(0);
611 finishings_default
= v
.integer_value
;
613 else if (a
.name
.compareTo("finishings-supported") == 0)
615 finishings_supported
= new int[a
.values
.size()];
616 for (i
=0; i
< a
.values
.size(); i
++)
618 v
= (IPPValue
)a
.values
.get(i
);
619 finishings_supported
[i
] = v
.integer_value
;
622 else if (a
.name
.compareTo("printer-type") == 0)
624 v
= (IPPValue
)a
.values
.get(0);
625 printer_type
= v
.integer_value
;
628 } // End of updateAttribute()
632 * Get the printer name.
634 * @return <code>String</code> Printer Name.
636 public String
getPrinterName()
638 return(printer_name
);
642 * Get the printer state text.
644 * @return <code>String</code> State text.
646 public String
getStateText()
648 return(printer_state_text
);
652 * Get the printer state reasons.
654 * @return <code>String</code> State reason.
656 public String
getStateReasons()
658 return(printer_state_reasons
);
662 * Get the printer location.
664 * @return <code>String</code> State location.
666 public String
getLocation()
668 return(printer_location
);
672 * Get the printer make and model.
674 * @return <code>String</code> Make and model.
676 public String
getMakeAndModel()
678 return(printer_make_and_model
);
684 * Get the default job sheets.
686 * @return <code>String</code> Default job sheets.
688 public String
getJobSheetsDefault()
690 return(job_sheets_default
);
694 * Get the printer job sheets supported.
696 * @return <code>String[]</code> Array of supported job sheets.
698 public String
[] getJobSheetsSupported()
700 return(job_sheets_supported
);
705 * Get the default orientation.
707 * @return <code>int</code> Default page orientation.
709 public int getOrientationDefault()
711 return(orientation_requested_default
);
715 * Get the printer orientation supported.
717 * @return <code>int[]</code> Array of supported orientations.
719 public int[] getOrientationSupported()
721 return(orientation_requested_supported
);
726 * Get the printer lower copies supported.
728 * @return <code>int</code> Lower of the range.
730 public int getLowerCopiesSupported()
732 return(lower_copies_supported
);
737 * Get the printer upper copies supported.
739 * @return <code>int</code> Upper of the range.
741 public int getUpperCopiesSupported()
743 return(upper_copies_supported
);
748 * Get the printer number of copies default.
750 * @return <code>int</code> Default number of copies.
752 public int getCopiesDefault()
754 return(copies_default
);
759 * Get whether the printer supports page ranges.
761 * @return <code>boolean</code> True or false.
763 public boolean getPageRangesSupported()
765 return(page_ranges_supported
);
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
);
782 if (printer_uri_supported
!= null)
784 System
.out
.println("Printer URI's Supported: ");
785 for (i
=0; i
< printer_uri_supported
.length
; i
++)
787 System
.out
.println(" " + printer_uri_supported
[i
] );
791 if (uri_authentication_supported
!= null)
793 System
.out
.println("URI Authentication Supported: ");
794 for (i
=0; i
< uri_authentication_supported
.length
; i
++)
796 System
.out
.println(" " + uri_authentication_supported
[i
] );
800 if (uri_security_supported
!= null)
802 System
.out
.println("URI Security Supported: ");
803 for (i
=0; i
< uri_security_supported
.length
; i
++)
805 System
.out
.println(" " + uri_security_supported
[i
] );
809 System
.out
.println("Attributes Charset: " + attributes_charset
);
810 System
.out
.println("Attributes Natural Language: " + attributes_natural_language
);
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
);
816 if (printer_is_accepting_jobs
)
817 System
.out
.println("Accepting Jobs: Yes");
819 System
.out
.println("Accepting Jobs: No");
826 } // End of CupsPrinter class