1 package com
.easysw
.cups
;
4 * @version 1.2 26-FEB-2006
7 * Internet Printing Protocol definitions for the Common UNIX Printing
10 * Copyright 2007 by Apple Inc.
11 * Copyright 1997-2006 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 * An <code>Cups</code> object is used for connecting to servers,
22 * reading and writing data, and performing common CUPS operations.
36 static final int REQ_STATE_CREATE_HTTP
= 0;
37 static final int REQ_STATE_WRITE_HTTP_HEADER
= 1;
38 static final int REQ_STATE_WRITE_IPP_HEADER
= 2;
39 static final int REQ_STATE_WRITE_IPP_ATTRS
= 3;
40 static final int REQ_STATE_FINISH_IPP_ATTRS
= 4;
41 static final int REQ_STATE_READ_RESPONSE
= 5;
42 static final int REQ_STATE_DONE
= 6;
43 static final String
[] req_state_names
=
54 static final int FILEREQ_STATE_CREATE_HTTP
= 0;
55 static final int FILEREQ_STATE_WRITE_HTTP_HEADER
= 1;
56 static final int FILEREQ_STATE_WRITE_IPP_HEADER
= 2;
57 static final int FILEREQ_STATE_WRITE_IPP_ATTRS
= 3;
58 static final int FILEREQ_STATE_FINISH_IPP_ATTRS
= 4;
59 static final int FILEREQ_STATE_WRITE_FILE_DATA
= 5;
60 static final int FILEREQ_STATE_READ_RESPONSE
= 6;
61 static final int FILEREQ_STATE_DONE
= 7;
62 static final String
[] filereq_state_names
=
74 IPP ipp
; // IPP Request
75 IPPHttp http
; // Connection to server
78 String protocol
; // Protocol name
79 String address
; // address/name of server
81 String path
; // Path ....
82 String dest
; // Name of destination printer
83 String instance
; // Instance of printer
86 // encrypt, user, and passwd are not fully implemented!
88 boolean encrypt
; // Open encrypted connection.
89 String user
; // User to login as.
90 String passwd
; // Password if needed.
92 String site
; // URL of site.
94 int last_error
; // Last error #
95 String error_text
; // Text for error
106 address
= "localhost";
109 site
= "http://localhost:631/";
118 * Constructor using a <code>URL</code>.
120 * @param <code>p_url</code> A <code>URL</code> object.
122 public Cups( URL p_url
)
127 protocol
= p_url
.getProtocol() + "://";
128 address
= p_url
.getHost();
129 port
= p_url
.getPort();
130 path
= p_url
.getPath();
132 site
= protocol
+ address
;
134 site
= site
+ ":" + port
;
136 if (path
.length() > 0)
148 * Set the value of the <code>protocol</code> member. Valid values
151 * @param <code>p_protocol</code> String with protocol.
153 public void setProtocol( String p_protocol
)
155 protocol
= p_protocol
;
156 site
= protocol
+ "://" + address
+ ":" + port
+ path
;
160 * Set the value of the <code>server</code> member. This is an
161 * IP address or a hostname.
163 * @param <code>p_server</code> IP address or hostname.
165 public void setServer( String p_server
)
168 site
= protocol
+ "://" + address
+ ":" + port
+ path
;
173 * Set the value of the <code>port</code> member.
175 * @param <code>p_port</code> Port number.
177 public void setPort( int p_port
)
180 site
= protocol
+ "://" + address
+ ":" + port
+ path
;
185 * Set the value of the <code>user</code> member.
187 * @param <code>p_user</code> User name.
189 public void setUser( String p_user
)
196 * Set the value of the <code>passwd</code> member.
198 * @param <code>p_passwd</code> Password.
200 public void setPasswd( String p_passwd
)
207 * Set the value of the <code>dest</code> member.
209 * @param <code>p_dest</code> Destination.
211 public void setDest( String p_dest
)
218 * Set the value of the <code>instance</code> member.
220 * @param <code>p_instance</code> Instance.
222 public void setInstance( String p_instance
)
224 instance
= p_instance
;
229 * Set the value of the <code>encrypt</code> member.
231 * @param <code>p_enrypt</code> Yes or no.
233 public void setEncrypt( boolean p_encrypt
)
240 * Get the value of the <code>encrypt</code> member.
242 * @return <code>boolean</code> Encryption on or off.
244 public boolean getEncrypt()
251 * Set the value of the <code>path</code> member. This is the
252 * path that will be used in the POST method.
254 * @param <code>p_path</code> Path on server.
256 public void setPath( String p_path
)
259 site
= protocol
+ "://" + address
+ ":" + port
+ path
;
264 public boolean doRequest(String from
) throws IOException
266 // System.out.println("doRequest From: " + from );
273 * Do a CUPS request to the server.
275 * @param <code>p_dest</code> Destination name.
276 * @return <code>boolean</code> True on success, false otherwise
277 * @throw <code>IOException</code>
279 public boolean doRequest() throws IOException
282 int state
= REQ_STATE_CREATE_HTTP
;
290 case REQ_STATE_CREATE_HTTP
:
291 String url_str
= site
+ dest
;
295 if (user
.length() > 0 && passwd
.length() > 0)
296 http
= new IPPHttp(url_str
, "", user
, passwd
);
298 http
= new IPPHttp(url_str
);
301 catch (IOException e
)
309 case REQ_STATE_WRITE_HTTP_HEADER
:
311 // Send the HTTP header.
313 switch( http
.writeHeader( http
.path
, ipp
.sizeInBytes() ))
315 case IPPHttp
.HTTP_FORBIDDEN
:
316 case IPPHttp
.HTTP_NOT_FOUND
:
317 case IPPHttp
.HTTP_BAD_REQUEST
:
318 case IPPHttp
.HTTP_METHOD_NOT_ALLOWED
:
319 case IPPHttp
.HTTP_PAYMENT_REQUIRED
:
320 case IPPHttp
.HTTP_UPGRADE_REQUIRED
:
321 case IPPHttp
.HTTP_ERROR
:
322 case IPPHttp
.HTTP_UNAUTHORIZED
:
326 if (!http
.reConnect())
328 System
.out
.println("Could not reConnect(0)!");
344 case REQ_STATE_WRITE_IPP_HEADER
:
346 // Send the request header.
348 byte[] header
= new byte[8];
351 header
[2] = (byte)((ipp
.request
.operation_id
& 0xff00) >> 8);
352 header
[3] = (byte)(ipp
.request
.operation_id
& 0xff);
353 header
[4] = (byte)((ipp
.request
.request_id
& 0xff000000) >> 24);
354 header
[5] = (byte)((ipp
.request
.request_id
& 0xff0000) >> 16);
355 header
[6] = (byte)((ipp
.request
.request_id
& 0xff00) >> 8);
356 header
[7] = (byte)(ipp
.request
.request_id
& 0xff);
357 http
.write( header
);
358 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
363 if (http
.reConnect())
364 state
= REQ_STATE_WRITE_HTTP_HEADER
;
367 System
.out
.println("Could not reConnect(1)\n");
380 case REQ_STATE_WRITE_IPP_ATTRS
:
382 // Send the attributes list.
387 boolean auth_error
= false;
388 for (int i
=0; i
< ipp
.attrs
.size() && !auth_error
; i
++)
390 attr
= (IPPAttribute
)ipp
.attrs
.get(i
);
391 sz
= attr
.sizeInBytes(last_group
);
392 bytes
= attr
.getBytes(sz
,last_group
);
393 last_group
= attr
.group_tag
;
397 // Check for server response between each attribute.
399 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
404 if (!http
.reConnect())
406 System
.out
.println("Could not reConnect(2)");
409 state
= REQ_STATE_WRITE_HTTP_HEADER
;
425 case REQ_STATE_FINISH_IPP_ATTRS
:
427 // Send the end of attributes tag.
429 byte[] footer
= new byte[1];
430 footer
[0] = (byte)IPPDefs
.TAG_END
;
431 http
.write( footer
);
434 // Keep checking .....
436 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
441 if (!http
.reConnect())
443 System
.out
.println("Could not reConnect(3)");
446 state
= REQ_STATE_WRITE_HTTP_HEADER
;
458 case REQ_STATE_READ_RESPONSE
:
460 // Now read back response
463 read_length
= http
.read_header();
464 switch( http
.status
)
466 case IPPHttp
.HTTP_OK
:
469 case IPPHttp
.HTTP_UNAUTHORIZED
:
471 state
= REQ_STATE_WRITE_HTTP_HEADER
;
479 if (!http
.reConnect())
481 System
.out
.println("Could not reConnect(4)");
484 state
= REQ_STATE_WRITE_HTTP_HEADER
;
488 System
.out
.println("Too many errors: " + errors
);
494 if ((read_length
> 0) && (state
== REQ_STATE_READ_RESPONSE
))
496 http
.read_buffer
= http
.read(read_length
);
497 ipp
= http
.processResponse();
512 } // End of doRequest
517 * Send a FILE to the CUPS server.
519 * @param <code>file</code> File to send.
520 * @return <code>boolean</code> True on success, false otherwise
521 * @throw <code>IOException</code>
523 public boolean doRequest(File file
) throws IOException
526 int state
= FILEREQ_STATE_CREATE_HTTP
;
528 FileInputStream fis
= null;
535 case FILEREQ_STATE_CREATE_HTTP
:
536 String url_str
= site
+ dest
;
539 if (user
.length() > 0 && passwd
.length() > 0)
540 http
= new IPPHttp(url_str
, "", user
, passwd
);
542 http
= new IPPHttp(url_str
);
545 catch (IOException e
)
553 case FILEREQ_STATE_WRITE_HTTP_HEADER
:
561 // Open an input stream to the file.
565 fis
= new FileInputStream(file
);
567 catch (IOException e
)
570 error_text
= "Error opening file input stream.";
575 // Send the HTTP header.
577 int ippSz
= ipp
.sizeInBytes() + (int)file
.length();
578 switch( http
.writeHeader( http
.path
, ippSz
))
580 case IPPHttp
.HTTP_FORBIDDEN
:
581 case IPPHttp
.HTTP_NOT_FOUND
:
582 case IPPHttp
.HTTP_BAD_REQUEST
:
583 case IPPHttp
.HTTP_METHOD_NOT_ALLOWED
:
584 case IPPHttp
.HTTP_PAYMENT_REQUIRED
:
585 case IPPHttp
.HTTP_UPGRADE_REQUIRED
:
586 case IPPHttp
.HTTP_ERROR
:
587 case IPPHttp
.HTTP_UNAUTHORIZED
:
603 case FILEREQ_STATE_WRITE_IPP_HEADER
:
605 // Send the request header.
607 byte[] header
= new byte[8];
610 header
[2] = (byte)((ipp
.request
.operation_id
& 0xff00) >> 8);
611 header
[3] = (byte)(ipp
.request
.operation_id
& 0xff);
612 header
[4] = (byte)((ipp
.request
.request_id
& 0xff000000) >> 24);
613 header
[5] = (byte)((ipp
.request
.request_id
& 0xff0000) >> 16);
614 header
[6] = (byte)((ipp
.request
.request_id
& 0xff00) >> 8);
615 header
[7] = (byte)(ipp
.request
.request_id
& 0xff);
616 http
.write( header
);
617 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
623 state
= FILEREQ_STATE_WRITE_HTTP_HEADER
;
632 case FILEREQ_STATE_WRITE_IPP_ATTRS
:
634 // Send the attributes list.
639 boolean auth_error
= false;
640 for (int i
=0; i
< ipp
.attrs
.size() && !auth_error
; i
++)
642 attr
= (IPPAttribute
)ipp
.attrs
.get(i
);
643 sz
= attr
.sizeInBytes(last_group
);
644 bytes
= attr
.getBytes(sz
,last_group
);
645 last_group
= attr
.group_tag
;
649 // Check for server response between each attribute.
651 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
657 state
= FILEREQ_STATE_WRITE_HTTP_HEADER
;
671 case FILEREQ_STATE_FINISH_IPP_ATTRS
:
673 // Send the end of attributes tag.
675 byte[] footer
= new byte[1];
676 footer
[0] = (byte)IPPDefs
.TAG_END
;
677 http
.write( footer
);
680 // Keep checking .....
682 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
688 state
= FILEREQ_STATE_WRITE_HTTP_HEADER
;
698 case FILEREQ_STATE_WRITE_FILE_DATA
:
700 // Send the file data - this could be improved on ALOT.
703 byte[] b
= new byte[1024];
704 while ((state
== FILEREQ_STATE_WRITE_FILE_DATA
) &&
705 ((count
= fis
.read(b
)) != -1))
708 // Keep checking .....
710 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
716 state
= FILEREQ_STATE_WRITE_HTTP_HEADER
;
726 http
.write( b
, count
);
731 if (state
== FILEREQ_STATE_WRITE_FILE_DATA
)
741 case FILEREQ_STATE_READ_RESPONSE
:
743 // Now read back response
746 read_length
= http
.read_header();
747 switch( http
.status
)
749 case IPPHttp
.HTTP_OK
:
752 case IPPHttp
.HTTP_UNAUTHORIZED
:
754 state
= FILEREQ_STATE_WRITE_HTTP_HEADER
;
763 state
= FILEREQ_STATE_WRITE_HTTP_HEADER
;
772 if ((read_length
> 0) && (state
== FILEREQ_STATE_READ_RESPONSE
))
774 http
.read_buffer
= http
.read(read_length
);
775 ipp
= http
.processResponse();
780 case FILEREQ_STATE_DONE
:
790 } // End of doRequest(file)
799 * Get a list of jobs.
801 * @param <code>showMyJobs</code> Show only jobs for user.
802 * @param <code>showCompleted</code> Show completed OR active jobs.
804 * @return <code>CupsJob[]</code> Array of job objects, or null.
805 * @throw <code>IOException</code>
807 public CupsJob
[] cupsGetJobs( boolean showMyJobs
, boolean showCompleted
)
813 String req_attrs
[] = /* Requested attributes */
821 "time-at-processing",
825 "job-originating-user-name"
830 ipp
.request
= new IPPRequest( 1, (short)IPPDefs
.GET_JOBS
);
832 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
833 "attributes-charset" );
834 a
.addString( "", "iso-8859-1" );
838 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
839 "attributes-natural-language" );
840 a
.addString( "", "en" );
845 // Add the printer uri
847 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_URI
,
851 a
.addString( "", site
);
853 a
.addString( "", "ipp://localhost/jobs" ); // Default ...
859 // Add the requesting user name
860 // **FIX** This should be fixed to use the user member.
862 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_NAME
,
863 "requesting-user-name" );
864 a
.addString( "", "root" );
868 // Show only my jobs?
872 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_BOOLEAN
,
874 a
.addBoolean( true );
879 // Show completed jobs?
883 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_KEYWORD
,
885 a
.addString( "", "completed" );
890 // Get ALL attributes - to get only listed ones,
891 // uncomment this and fill in req_attrs.
893 // a = new IPPAttribute( IPPDefs.TAG_OPERATION, IPPDefs.TAG_KEYWORD,
894 // "requested-attributes" );
895 // a.addStrings( "", req_attrs );
896 // ipp.addAttribute(a);
899 // Do the request and process the response.
901 if (doRequest("cupsGetJobs"))
906 // First we have to figure out how many jobs there are
907 // so we can create the array.
911 // Skip past leading attributes
915 while ((i
< ipp
.attrs
.size()) && (group_tag
!= IPPDefs
.TAG_JOB
))
917 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
918 group_tag
= a
.group_tag
;
919 if (group_tag
!= IPPDefs
.TAG_JOB
)
924 group_tag
= IPPDefs
.TAG_JOB
;
925 while ((i
< ipp
.attrs
.size()) && (group_tag
== IPPDefs
.TAG_JOB
))
927 a
= (IPPAttribute
)ipp
.attrs
.get(i
++);
928 if ((a
!= null) && (a
.name
.compareTo("job-id") == 0))
938 // Now create the array of the proper size.
941 CupsJob
[] jobs
= new CupsJob
[num_jobs
];
942 for (n
=0; n
< num_jobs
; n
++)
944 jobs
[n
] = new CupsJob();
951 // Skip past leading attributes
955 while ((i
< ipp
.attrs
.size()) && (group_tag
!= IPPDefs
.TAG_JOB
))
957 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
958 group_tag
= a
.group_tag
;
959 if (group_tag
!= IPPDefs
.TAG_JOB
)
964 // Now we actually fill the array with the job data.
967 for (;i
< ipp
.attrs
.size(); i
++)
969 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
971 if (a
.group_tag
== IPPDefs
.TAG_ZERO
)
980 jobs
[n
].updateAttribute( a
);
982 catch (ArrayIndexOutOfBoundsException e
)
992 } // End of cupsGetJobs
997 * Get a list of printers.
999 * @return <code>String[]</code> Array of printers, or null.
1000 * @throw <code>IOException</code>
1002 public String
[] cupsGetPrinters()
1011 // Fill in the required attributes
1013 ipp
.request
= new IPPRequest( 1, (short)IPPDefs
.CUPS_GET_PRINTERS
);
1015 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
1016 "attributes-charset" );
1017 a
.addString( "", "iso-8859-1" );
1018 ipp
.addAttribute(a
);
1021 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
1022 "attributes-natural-language" );
1023 a
.addString( "", "en" );
1024 ipp
.addAttribute(a
);
1027 if (doRequest("cupsGetPrinters"))
1029 int num_printers
= 0;
1030 for (int i
=0; i
< ipp
.attrs
.size(); i
++)
1032 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
1033 if ((a
.name
.compareTo("printer-name") == 0) &&
1034 (a
.value_tag
== IPPDefs
.TAG_NAME
))
1039 if (num_printers
< 1)
1042 String
[] printers
= new String
[num_printers
];
1045 for (int i
=0; i
< ipp
.attrs
.size(); i
++)
1047 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
1048 if (a
.group_tag
< 2)
1051 if ((a
.name
.compareTo("printer-name") == 0) &&
1052 (a
.value_tag
== IPPDefs
.TAG_NAME
))
1054 val
= (IPPValue
)a
.values
.get(0);
1057 printers
[n
] = val
.text
;
1064 } // if doRequest ...
1068 } // End of cupsGetPrinters
1074 * Get default destination.
1076 * @return <code>String</code> Name of default printer, or null.
1077 * @throw <code>IOException</code>
1079 public String
cupsGetDefault()
1088 // Fill in the required attributes
1090 ipp
.request
= new IPPRequest( 1, (short)IPPDefs
.CUPS_GET_DEFAULT
);
1092 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
1093 "attributes-charset" );
1094 a
.addString( "", "iso-8859-1" );
1095 ipp
.addAttribute(a
);
1098 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
1099 "attributes-natural-language" );
1100 a
.addString( "", "en" );
1101 ipp
.addAttribute(a
);
1104 if (doRequest("cupsGetDefault"))
1106 if ((ipp
== null) || (ipp
.attrs
== null))
1109 int num_printers
= 0;
1110 for (int i
=0; i
< ipp
.attrs
.size(); i
++)
1112 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
1113 if ((a
.name
.compareTo("printer-name") == 0) &&
1114 (a
.value_tag
== IPPDefs
.TAG_NAME
))
1116 IPPValue val
= (IPPValue
)a
.values
.get(0);
1123 } // if doRequest ...
1127 } // End of cupsGetDefault
1135 * Get printer attributes
1137 * @param <code>printer_name</code> Name of printer to get info for.
1138 * @return <code>List</code> List of attributes.
1139 * @throw <code>IOException</code>
1141 * @see <code>CupsPrinter</code>
1143 public List
cupsGetPrinterAttributes( String printer_name
)
1152 // Fill in the required attributes
1154 ipp
.request
= new IPPRequest( 1, (short)IPPDefs
.GET_PRINTER_ATTRIBUTES
);
1156 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
1157 "attributes-charset" );
1158 a
.addString( "", "iso-8859-1" );
1159 ipp
.addAttribute(a
);
1162 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
1163 "attributes-natural-language" );
1164 a
.addString( "", "en" );
1165 ipp
.addAttribute(a
);
1167 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_URI
,
1169 String p_uri
= "ipp://" + address
+ ":" +
1170 port
+ "/printers/" + printer_name
;
1171 a
.addString( "", p_uri
);
1172 ipp
.addAttribute(a
);
1174 if (doRequest("cupsGetPrinterAttributes"))
1181 } // End of cupsGetPrinterAttributes
1189 * @param <code>p_filename</code> Path of file to print.
1190 * @param <code>p_attrs[]</code> Array of print job attributes.
1192 * @return <code>CupsJob</code> Object with job info.
1194 * @throw <code>IOException</code>
1196 * @see <code>CupsJob</code>
1198 public CupsJob
cupsPrintFile( String p_filename
,
1199 IPPAttribute p_attrs
[] )
1208 file
= new File(p_filename
);
1212 error_text
= "File does not exist.";
1216 if (!file
.canRead())
1219 error_text
= "File cannot be read.";
1226 // Fill in the required attributes
1228 ipp
.request
= new IPPRequest( 1, (short)IPPDefs
.PRINT_JOB
);
1230 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
1231 "attributes-charset" );
1232 a
.addString( "", "iso-8859-1" );
1233 ipp
.addAttribute(a
);
1236 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
1237 "attributes-natural-language" );
1238 a
.addString( "", "en" );
1239 ipp
.addAttribute(a
);
1242 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_URI
,
1244 a
.addString( "", site
+ dest
);
1245 ipp
.addAttribute(a
);
1248 // **FIX** Fix this later.
1250 a = new IPPAttribute( IPPDefs.TAG_OPERATION, IPPDefs.TAG_NAME,
1251 "requesting-user-name" );
1252 // a.addString( "", p_username );
1253 a.addString( "", "root");
1254 ipp.addAttribute(a);
1258 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_NAME
,
1260 a
.addString( "", file
.getName() );
1261 ipp
.addAttribute(a
);
1263 if (p_attrs
!= null)
1265 for (int i
=0; i
< p_attrs
.length
; i
++)
1268 ipp
.addAttribute(a
);
1272 if (doRequest(file
))
1274 job
= new CupsJob();
1275 for (int i
=0; i
< ipp
.attrs
.size(); i
++)
1277 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
1278 job
.updateAttribute(a
);
1282 } // if doRequest ...
1286 } // End of cupsPrintFile
1293 * Cancel a job - send a job cancel request to the server.
1295 * @param <code>printer_name</code> Destination.
1296 * @param <code>p_job_id</code> ID of job.
1297 * @param <code>p_user_name</code> Requesting user name.
1299 * @throw <code>IOException</code>
1301 public int cupsCancelJob( String printer_name
,
1303 String p_user_name
)
1312 // Fill in the required attributes
1314 ipp
.request
= new IPPRequest( 1, (short)IPPDefs
.CANCEL_JOB
);
1316 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
1317 "attributes-charset" );
1318 a
.addString( "", "iso-8859-1" );
1319 ipp
.addAttribute(a
);
1322 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
1323 "attributes-natural-language" );
1324 a
.addString( "", "en" );
1325 ipp
.addAttribute(a
);
1328 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_URI
,
1330 a
.addString( "", site
+ dest
);
1331 ipp
.addAttribute(a
);
1334 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_INTEGER
,
1336 a
.addInteger( p_job_id
);
1337 ipp
.addAttribute(a
);
1340 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_NAME
,
1341 "requesting-user-name" );
1342 a
.addString( "", p_user_name
);
1343 ipp
.addAttribute(a
);
1345 if (doRequest("cupsCancelJob"))
1347 for (int i
=0; i
< ipp
.attrs
.size(); i
++)
1349 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
1354 } // if doRequest ...
1358 } // End of cupsCancelJob
1363 public List
cupsGetPrinterStatus(String printer_name
)
1372 // Fill in the required attributes
1374 ipp
.request
= new IPPRequest(1,(short)IPPDefs
.GET_PRINTER_ATTRIBUTES
);
1376 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
1377 "attributes-charset" );
1378 a
.addString( "", "iso-8859-1" );
1379 ipp
.addAttribute(a
);
1382 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
1383 "attributes-natural-language" );
1384 a
.addString( "", "en" );
1385 ipp
.addAttribute(a
);
1387 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_URI
,
1389 p_uri
= "ipp://" + address
+ ":" +
1390 port
+ "/printers/" + printer_name
;
1391 a
.addString( "", p_uri
);
1392 ipp
.addAttribute(a
);
1394 if (doRequest("cupsGetPrinterStatus"))
1405 } // End of Cups class