1 package com
.easysw
.cups
;
4 * @version 1.00 06-NOV-2002
5 * @author Easy Software Products
7 * Internet Printing Protocol definitions for the Common UNIX Printing
10 * Copyright 1997-2002 by Easy Software Products.
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
19 * Attn: CUPS Licensing Information
20 * Easy Software Products
21 * 44141 Airport View Drive, Suite 204
22 * Hollywood, Maryland 20636-3111 USA
24 * Voice: (301) 373-9603
25 * EMail: cups-info@cups.org
26 * WWW: http://www.cups.org
30 * A <code>CupsPrinter</code> holds printer attribute / status information,
31 * and has methods to process CUPS server responses.
42 public class CupsPrinter
46 // Printer attributes / status members.
50 String printer_location
;
52 String printer_more_info
;
54 String
[] printer_uri_supported
; // Strings
55 String
[] uri_authentication_supported
; // Strings
56 String
[] uri_security_supported
; // Strings
58 String attributes_charset
;
59 String attributes_natural_language
;
62 String printer_state_text
;
63 String printer_state_reasons
;
65 boolean printer_is_accepting_jobs
;
68 long printer_current_time
;
72 String
[] pdl_override_supported
;
73 String
[] ipp_versions_supported
;
75 int[] operations_supported
; // Integers
77 boolean multiple_document_jobs_supported
;
78 int multiple_operation_time_out
;
79 int[] multiple_document_handling_supported
; // Integers
81 String charset_configured
;
82 String natural_language_configured
;
83 String generated_natural_language_supported
;
84 String
[] charset_supported
; // Strings
86 String document_format_default
;
87 String
[] document_format_supported
; // Strings
89 String
[] compression_supported
; // Strings
91 int job_priority_default
;
92 int job_priority_supported
;
95 int lower_copies_supported
;
96 int upper_copies_supported
;
98 boolean page_ranges_supported
;
100 int number_up_default
;
101 int[] number_up_supported
; // integers
104 int orientation_requested_default
;
105 int[] orientation_requested_supported
; // Integers
107 int job_quota_period
;
111 String job_sheets_default
; // Should this be a list too?
112 String
[] job_sheets_supported
; // Strings
116 boolean color_supported
;
117 int pages_per_minute
;
119 String printer_make_and_model
;
121 String media_default
;
122 String
[] media_supported
; // Strings
124 int finishings_default
;
125 int[] finishings_supported
; // Integers
132 * Constructor. Does not get status or attributes.
134 * @param <code>c</code> Cups object.
136 * @see <code>Cups</code>
138 public CupsPrinter(Cups c
)
144 * Constructor with name. Get status and attributes.
146 * @param <code>c</code> Cups object.
147 * @param <code>name</code> Name of printer.
149 * @see <code>Cups</code>
151 public CupsPrinter(Cups c
, String name
)
165 * Initialize the members with mostly sane values.
168 public void setDefaults()
171 printer_location
= "";
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";
180 printer_state_text
= "";
181 printer_state_reasons
= "";
182 printer_is_accepting_jobs
= false;
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;
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;
212 job_sheets_default
= "none,none";
213 job_sheets_supported
= null;
215 color_supported
= false;
216 pages_per_minute
= 0;
217 printer_make_and_model
= "";
219 media_supported
= null;
220 finishings_default
= 0;
221 finishings_supported
= null;
227 * Get the printer's status.
229 * @param <code>c</code> Cups object.
231 * @return <code>Boolean</code> True on success.
233 * @see <code>Cups</code>
235 public boolean getStatus(Cups c
)
243 attrs
= c
.cupsGetPrinterStatus(printer_name
);
244 for (int i
=0; i
< attrs
.size(); i
++)
246 a
= (IPPAttribute
)attrs
.get(i
);
251 catch (IOException e
)
260 * Get the printer's attributes.
262 * @param <code>c</code> Cups object.
264 * @return <code>Boolean</code> True on success.
266 * @see <code>Cups</code>
268 public boolean getAttributes(Cups c
)
276 attrs
= c
.cupsGetPrinterAttributes(printer_name
);
277 for (int i
=0; i
< attrs
.size(); i
++)
279 a
= (IPPAttribute
)attrs
.get(i
);
284 catch (IOException e
)
294 * Process an attribute from the cups.doRequest() method and move
295 * the values into local members.
297 * @param <code>a</code> IPPAttribute.
299 * @see <code>IPPAttributes</code>
300 * @see <code>IPPValues</code>
302 public void updateAttribute( IPPAttribute a
)
309 if (a
.name
.compareTo("printer-name") == 0)
311 v
= (IPPValue
)a
.values
.get(0);
312 printer_name
= v
.text
;
314 else if (a
.name
.compareTo("printer-location") == 0)
316 v
= (IPPValue
)a
.values
.get(0);
317 printer_location
= v
.text
;
319 else if (a
.name
.compareTo("printer-info") == 0)
321 v
= (IPPValue
)a
.values
.get(0);
322 printer_info
= v
.text
;
324 else if (a
.name
.compareTo("printer-more-info") == 0)
326 v
= (IPPValue
)a
.values
.get(0);
327 printer_more_info
= v
.text
;
329 else if (a
.name
.compareTo("printer-uri-supported") == 0)
331 printer_uri_supported
= new String
[a
.values
.size()];
332 for (i
=0; i
< a
.values
.size(); i
++)
334 v
= (IPPValue
)a
.values
.get(i
);
335 printer_uri_supported
[i
] = v
.text
;
338 else if (a
.name
.compareTo("uri-authentication-supported") == 0)
340 uri_authentication_supported
= new String
[a
.values
.size()];
341 for (i
=0; i
< a
.values
.size(); i
++)
343 v
= (IPPValue
)a
.values
.get(i
);
344 uri_authentication_supported
[i
] = v
.text
;
347 else if (a
.name
.compareTo("uri-security-supported") == 0)
349 uri_security_supported
= new String
[a
.values
.size()];
350 for (i
=0; i
< a
.values
.size(); i
++)
352 v
= (IPPValue
)a
.values
.get(i
);
353 uri_security_supported
[i
] = v
.text
;
356 else if (a
.name
.compareTo("attributes-charset") == 0)
358 v
= (IPPValue
)a
.values
.get(0);
359 attributes_charset
= v
.text
;
361 else if (a
.name
.compareTo("attributes-natural-language") == 0)
363 v
= (IPPValue
)a
.values
.get(0);
364 attributes_natural_language
= v
.text
;
366 else if (a
.name
.compareTo("printer-state") == 0)
368 v
= (IPPValue
)a
.values
.get(0);
369 printer_state
= v
.integer_value
;
370 switch( printer_state
)
372 case 3: printer_state_text
= "idle";
374 case 4: printer_state_text
= "processing";
376 case 5: printer_state_text
= "stopped";
380 else if (a
.name
.compareTo("printer-state-reasons") == 0)
382 v
= (IPPValue
)a
.values
.get(0);
383 printer_state_reasons
= v
.text
;
385 else if (a
.name
.compareTo("printer-is-accepting-jobs") == 0)
387 v
= (IPPValue
)a
.values
.get(0);
388 printer_is_accepting_jobs
= v
.boolean_value
;
390 else if (a
.name
.compareTo("printer-up-time") == 0)
392 v
= (IPPValue
)a
.values
.get(0);
393 printer_up_time
= v
.integer_value
;
395 else if (a
.name
.compareTo("printer-current-time") == 0)
397 v
= (IPPValue
)a
.values
.get(0);
398 printer_current_time
= v
.unix_time
; // *** FIX ***
400 else if (a
.name
.compareTo("queue-job-count") == 0)
402 v
= (IPPValue
)a
.values
.get(0);
403 queued_job_count
= v
.integer_value
;
405 else if (a
.name
.compareTo("pdl-override-supported") == 0)
407 pdl_override_supported
= new String
[a
.values
.size()];
408 for (i
=0; i
< a
.values
.size(); i
++)
410 v
= (IPPValue
)a
.values
.get(i
);
411 pdl_override_supported
[i
] = v
.text
;
414 else if (a
.name
.compareTo("ipp-versions-supported") == 0)
416 ipp_versions_supported
= new String
[a
.values
.size()];
417 for (i
=0; i
< a
.values
.size(); i
++)
419 v
= (IPPValue
)a
.values
.get(i
);
420 ipp_versions_supported
[i
] = v
.text
;
423 else if (a
.name
.compareTo("operations-supported") == 0)
425 operations_supported
= new int[a
.values
.size()];
426 for (i
=0; i
< a
.values
.size(); i
++)
428 v
= (IPPValue
)a
.values
.get(i
);
429 operations_supported
[i
] = v
.integer_value
;
432 else if (a
.name
.compareTo("multiple-document-jobs-supported") == 0)
434 v
= (IPPValue
)a
.values
.get(0);
435 multiple_document_jobs_supported
= v
.boolean_value
;
437 else if (a
.name
.compareTo("multiple-operation-time-out") == 0)
439 v
= (IPPValue
)a
.values
.get(0);
440 multiple_operation_time_out
= v
.integer_value
;
442 else if (a
.name
.compareTo("multiple-document-handling-supported") == 0)
444 multiple_document_handling_supported
= new int[a
.values
.size()];
445 for (i
=0; i
< a
.values
.size(); i
++)
447 v
= (IPPValue
)a
.values
.get(i
);
448 multiple_document_handling_supported
[i
] = v
.integer_value
;
451 else if (a
.name
.compareTo("charset-configured") == 0)
453 v
= (IPPValue
)a
.values
.get(0);
454 charset_configured
= v
.text
;
456 else if (a
.name
.compareTo("natural-language-configured") == 0)
458 v
= (IPPValue
)a
.values
.get(0);
459 natural_language_configured
= v
.text
;
461 else if (a
.name
.compareTo("generated-natural-language-supported") == 0)
463 // *** Should this be a list too?
464 v
= (IPPValue
)a
.values
.get(0);
465 generated_natural_language_supported
= v
.text
;
467 else if (a
.name
.compareTo("charset-supported") == 0)
469 charset_supported
= new String
[a
.values
.size()];
470 for (i
=0; i
< a
.values
.size(); i
++)
472 v
= (IPPValue
)a
.values
.get(i
);
473 charset_supported
[i
] = v
.text
;
476 else if (a
.name
.compareTo("document-format-default") == 0)
478 v
= (IPPValue
)a
.values
.get(0);
479 document_format_default
= v
.text
;
481 else if (a
.name
.compareTo("document-format-supported") == 0)
483 document_format_supported
= new String
[a
.values
.size()];
484 for (i
=0; i
< a
.values
.size(); i
++)
486 v
= (IPPValue
)a
.values
.get(i
);
487 document_format_supported
[i
] = v
.text
;
490 else if (a
.name
.compareTo("compression-supported") == 0)
492 compression_supported
= new String
[a
.values
.size()];
493 for (i
=0; i
< a
.values
.size(); i
++)
495 v
= (IPPValue
)a
.values
.get(i
);
496 compression_supported
[i
] = v
.text
;
499 else if (a
.name
.compareTo("job-priority-default") == 0)
501 v
= (IPPValue
)a
.values
.get(0);
502 job_priority_default
= v
.integer_value
;
504 else if (a
.name
.compareTo("job-priority-supported") == 0)
506 // *** Should be a list? ***
507 v
= (IPPValue
)a
.values
.get(0);
508 job_priority_supported
= v
.integer_value
;
510 else if (a
.name
.compareTo("copies-default") == 0)
512 v
= (IPPValue
)a
.values
.get(0);
513 copies_default
= v
.integer_value
;
515 else if (a
.name
.compareTo("copies-supported") == 0)
517 v
= (IPPValue
)a
.values
.get(0);
518 lower_copies_supported
= v
.lower
;
519 upper_copies_supported
= v
.upper
;
521 else if (a
.name
.compareTo("page-ranges-supported") == 0)
523 v
= (IPPValue
)a
.values
.get(0);
524 page_ranges_supported
= v
.boolean_value
;
526 else if (a
.name
.compareTo("number-up-default") == 0)
528 v
= (IPPValue
)a
.values
.get(0);
529 number_up_default
= v
.integer_value
;
531 else if (a
.name
.compareTo("number-up-supported") == 0)
533 number_up_supported
= new int[a
.values
.size()];
534 for (i
=0; i
< a
.values
.size(); i
++)
536 v
= (IPPValue
)a
.values
.get(i
);
537 number_up_supported
[i
] = v
.integer_value
;
540 else if (a
.name
.compareTo("orientation-requested-default") == 0)
542 v
= (IPPValue
)a
.values
.get(0);
543 orientation_requested_default
= v
.integer_value
;
545 else if (a
.name
.compareTo("orientation-requested-supported") == 0)
547 orientation_requested_supported
= new int[a
.values
.size()];
548 for (i
=0; i
< a
.values
.size(); i
++)
550 v
= (IPPValue
)a
.values
.get(i
);
551 orientation_requested_supported
[i
] = v
.integer_value
;
554 else if (a
.name
.compareTo("job-quota-period") == 0)
556 v
= (IPPValue
)a
.values
.get(0);
557 job_quota_period
= v
.integer_value
;
559 else if (a
.name
.compareTo("job-k-limit") == 0)
561 v
= (IPPValue
)a
.values
.get(0);
562 job_k_limit
= v
.integer_value
;
564 else if (a
.name
.compareTo("job-page-limit") == 0)
566 v
= (IPPValue
)a
.values
.get(0);
567 job_page_limit
= v
.integer_value
;
569 else if (a
.name
.compareTo("job-sheets-default") == 0)
571 v
= (IPPValue
)a
.values
.get(0);
572 job_sheets_default
= v
.text
;
574 else if (a
.name
.compareTo("job-sheets-supported") == 0)
576 job_sheets_supported
= new String
[a
.values
.size()];
577 for (i
=0; i
< a
.values
.size(); i
++)
579 v
= (IPPValue
)a
.values
.get(i
);
580 job_sheets_supported
[i
] = v
.text
;
583 else if (a
.name
.compareTo("device-uri") == 0)
585 v
= (IPPValue
)a
.values
.get(0);
588 else if (a
.name
.compareTo("color-supported") == 0)
590 v
= (IPPValue
)a
.values
.get(0);
591 color_supported
= v
.boolean_value
;
593 else if (a
.name
.compareTo("pages-per-minute") == 0)
595 v
= (IPPValue
)a
.values
.get(0);
596 pages_per_minute
= v
.integer_value
;
598 else if (a
.name
.compareTo("printer-make-and-model") == 0)
600 v
= (IPPValue
)a
.values
.get(0);
601 printer_make_and_model
= v
.text
;
603 else if (a
.name
.compareTo("media-default") == 0)
605 v
= (IPPValue
)a
.values
.get(0);
606 media_default
= v
.text
;
608 else if (a
.name
.compareTo("media-supported") == 0)
610 media_supported
= new String
[a
.values
.size()];
611 for (i
=0; i
< a
.values
.size(); i
++)
613 v
= (IPPValue
)a
.values
.get(i
);
614 media_supported
[i
] = v
.text
;
617 else if (a
.name
.compareTo("finishings-default") == 0)
619 v
= (IPPValue
)a
.values
.get(0);
620 finishings_default
= v
.integer_value
;
622 else if (a
.name
.compareTo("finishings-supported") == 0)
624 finishings_supported
= new int[a
.values
.size()];
625 for (i
=0; i
< a
.values
.size(); i
++)
627 v
= (IPPValue
)a
.values
.get(i
);
628 finishings_supported
[i
] = v
.integer_value
;
631 else if (a
.name
.compareTo("printer-type") == 0)
633 v
= (IPPValue
)a
.values
.get(0);
634 printer_type
= v
.integer_value
;
637 } // End of updateAttribute()
641 * Get the printer name.
643 * @return <code>String</code> Printer Name.
645 public String
getPrinterName()
647 return(printer_name
);
651 * Get the printer state text.
653 * @return <code>String</code> State text.
655 public String
getStateText()
657 return(printer_state_text
);
661 * Get the printer state reasons.
663 * @return <code>String</code> State reason.
665 public String
getStateReasons()
667 return(printer_state_reasons
);
671 * Get the printer location.
673 * @return <code>String</code> State location.
675 public String
getLocation()
677 return(printer_location
);
681 * Get the printer make and model.
683 * @return <code>String</code> Make and model.
685 public String
getMakeAndModel()
687 return(printer_make_and_model
);
693 * Get the default job sheets.
695 * @return <code>String</code> Default job sheets.
697 public String
getJobSheetsDefault()
699 return(job_sheets_default
);
703 * Get the printer job sheets supported.
705 * @return <code>String[]</code> Array of supported job sheets.
707 public String
[] getJobSheetsSupported()
709 return(job_sheets_supported
);
714 * Get the default orientation.
716 * @return <code>int</code> Default page orientation.
718 public int getOrientationDefault()
720 return(orientation_requested_default
);
724 * Get the printer orientation supported.
726 * @return <code>int[]</code> Array of supported orientations.
728 public int[] getOrientationSupported()
730 return(orientation_requested_supported
);
735 * Get the printer lower copies supported.
737 * @return <code>int</code> Lower of the range.
739 public int getLowerCopiesSupported()
741 return(lower_copies_supported
);
746 * Get the printer upper copies supported.
748 * @return <code>int</code> Upper of the range.
750 public int getUpperCopiesSupported()
752 return(upper_copies_supported
);
757 * Get the printer number of copies default.
759 * @return <code>int</code> Default number of copies.
761 public int getCopiesDefault()
763 return(copies_default
);
768 * Get whether the printer supports page ranges.
770 * @return <code>boolean</code> True or false.
772 public boolean getPageRangesSupported()
774 return(page_ranges_supported
);
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
);
791 if (printer_uri_supported
!= null)
793 System
.out
.println("Printer URI's Supported: ");
794 for (i
=0; i
< printer_uri_supported
.length
; i
++)
796 System
.out
.println(" " + printer_uri_supported
[i
] );
800 if (uri_authentication_supported
!= null)
802 System
.out
.println("URI Authentication Supported: ");
803 for (i
=0; i
< uri_authentication_supported
.length
; i
++)
805 System
.out
.println(" " + uri_authentication_supported
[i
] );
809 if (uri_security_supported
!= null)
811 System
.out
.println("URI Security Supported: ");
812 for (i
=0; i
< uri_security_supported
.length
; i
++)
814 System
.out
.println(" " + uri_security_supported
[i
] );
818 System
.out
.println("Attributes Charset: " + attributes_charset
);
819 System
.out
.println("Attributes Natural Language: " + attributes_natural_language
);
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
);
825 if (printer_is_accepting_jobs
)
826 System
.out
.println("Accepting Jobs: Yes");
828 System
.out
.println("Accepting Jobs: No");
835 } // End of CupsPrinter class