1 package com
.easysw
.cups
;
4 * @version 1.2 26-FEB-2006
5 * @author Easy Software Products
7 * Internet Printing Protocol definitions for the Common UNIX Printing
10 * Copyright 1997-2006 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 USA
24 * Voice: (301) 373-9600
25 * EMail: cups-info@cups.org
26 * WWW: http://www.cups.org/
30 * An <code>Cups</code> object is used for connecting to servers,
31 * reading and writing data, and performing common CUPS operations.
45 static final int REQ_STATE_CREATE_HTTP
= 0;
46 static final int REQ_STATE_WRITE_HTTP_HEADER
= 1;
47 static final int REQ_STATE_WRITE_IPP_HEADER
= 2;
48 static final int REQ_STATE_WRITE_IPP_ATTRS
= 3;
49 static final int REQ_STATE_FINISH_IPP_ATTRS
= 4;
50 static final int REQ_STATE_READ_RESPONSE
= 5;
51 static final int REQ_STATE_DONE
= 6;
52 static final String
[] req_state_names
=
63 static final int FILEREQ_STATE_CREATE_HTTP
= 0;
64 static final int FILEREQ_STATE_WRITE_HTTP_HEADER
= 1;
65 static final int FILEREQ_STATE_WRITE_IPP_HEADER
= 2;
66 static final int FILEREQ_STATE_WRITE_IPP_ATTRS
= 3;
67 static final int FILEREQ_STATE_FINISH_IPP_ATTRS
= 4;
68 static final int FILEREQ_STATE_WRITE_FILE_DATA
= 5;
69 static final int FILEREQ_STATE_READ_RESPONSE
= 6;
70 static final int FILEREQ_STATE_DONE
= 7;
71 static final String
[] filereq_state_names
=
83 IPP ipp
; // IPP Request
84 IPPHttp http
; // Connection to server
87 String protocol
; // Protocol name
88 String address
; // address/name of server
90 String path
; // Path ....
91 String dest
; // Name of destination printer
92 String instance
; // Instance of printer
95 // encrypt, user, and passwd are not fully implemented!
97 boolean encrypt
; // Open encrypted connection.
98 String user
; // User to login as.
99 String passwd
; // Password if needed.
101 String site
; // URL of site.
103 int last_error
; // Last error #
104 String error_text
; // Text for error
115 address
= "localhost";
118 site
= "http://localhost:631/";
127 * Constructor using a <code>URL</code>.
129 * @param <code>p_url</code> A <code>URL</code> object.
131 public Cups( URL p_url
)
136 protocol
= p_url
.getProtocol() + "://";
137 address
= p_url
.getHost();
138 port
= p_url
.getPort();
139 path
= p_url
.getPath();
141 site
= protocol
+ address
;
143 site
= site
+ ":" + port
;
145 if (path
.length() > 0)
157 * Set the value of the <code>protocol</code> member. Valid values
160 * @param <code>p_protocol</code> String with protocol.
162 public void setProtocol( String p_protocol
)
164 protocol
= p_protocol
;
165 site
= protocol
+ "://" + address
+ ":" + port
+ path
;
169 * Set the value of the <code>server</code> member. This is an
170 * IP address or a hostname.
172 * @param <code>p_server</code> IP address or hostname.
174 public void setServer( String p_server
)
177 site
= protocol
+ "://" + address
+ ":" + port
+ path
;
182 * Set the value of the <code>port</code> member.
184 * @param <code>p_port</code> Port number.
186 public void setPort( int p_port
)
189 site
= protocol
+ "://" + address
+ ":" + port
+ path
;
194 * Set the value of the <code>user</code> member.
196 * @param <code>p_user</code> User name.
198 public void setUser( String p_user
)
205 * Set the value of the <code>passwd</code> member.
207 * @param <code>p_passwd</code> Password.
209 public void setPasswd( String p_passwd
)
216 * Set the value of the <code>dest</code> member.
218 * @param <code>p_dest</code> Destination.
220 public void setDest( String p_dest
)
227 * Set the value of the <code>instance</code> member.
229 * @param <code>p_instance</code> Instance.
231 public void setInstance( String p_instance
)
233 instance
= p_instance
;
238 * Set the value of the <code>encrypt</code> member.
240 * @param <code>p_enrypt</code> Yes or no.
242 public void setEncrypt( boolean p_encrypt
)
249 * Get the value of the <code>encrypt</code> member.
251 * @return <code>boolean</code> Encryption on or off.
253 public boolean getEncrypt()
260 * Set the value of the <code>path</code> member. This is the
261 * path that will be used in the POST method.
263 * @param <code>p_path</code> Path on server.
265 public void setPath( String p_path
)
268 site
= protocol
+ "://" + address
+ ":" + port
+ path
;
273 public boolean doRequest(String from
) throws IOException
275 // System.out.println("doRequest From: " + from );
282 * Do a CUPS request to the server.
284 * @param <code>p_dest</code> Destination name.
285 * @return <code>boolean</code> True on success, false otherwise
286 * @throw <code>IOException</code>
288 public boolean doRequest() throws IOException
291 int state
= REQ_STATE_CREATE_HTTP
;
299 case REQ_STATE_CREATE_HTTP
:
300 String url_str
= site
+ dest
;
304 if (user
.length() > 0 && passwd
.length() > 0)
305 http
= new IPPHttp(url_str
, "", user
, passwd
);
307 http
= new IPPHttp(url_str
);
310 catch (IOException e
)
318 case REQ_STATE_WRITE_HTTP_HEADER
:
320 // Send the HTTP header.
322 switch( http
.writeHeader( http
.path
, ipp
.sizeInBytes() ))
324 case IPPHttp
.HTTP_FORBIDDEN
:
325 case IPPHttp
.HTTP_NOT_FOUND
:
326 case IPPHttp
.HTTP_BAD_REQUEST
:
327 case IPPHttp
.HTTP_METHOD_NOT_ALLOWED
:
328 case IPPHttp
.HTTP_PAYMENT_REQUIRED
:
329 case IPPHttp
.HTTP_UPGRADE_REQUIRED
:
330 case IPPHttp
.HTTP_ERROR
:
331 case IPPHttp
.HTTP_UNAUTHORIZED
:
335 if (!http
.reConnect())
337 System
.out
.println("Could not reConnect(0)!");
353 case REQ_STATE_WRITE_IPP_HEADER
:
355 // Send the request header.
357 byte[] header
= new byte[8];
360 header
[2] = (byte)((ipp
.request
.operation_id
& 0xff00) >> 8);
361 header
[3] = (byte)(ipp
.request
.operation_id
& 0xff);
362 header
[4] = (byte)((ipp
.request
.request_id
& 0xff000000) >> 24);
363 header
[5] = (byte)((ipp
.request
.request_id
& 0xff0000) >> 16);
364 header
[6] = (byte)((ipp
.request
.request_id
& 0xff00) >> 8);
365 header
[7] = (byte)(ipp
.request
.request_id
& 0xff);
366 http
.write( header
);
367 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
372 if (http
.reConnect())
373 state
= REQ_STATE_WRITE_HTTP_HEADER
;
376 System
.out
.println("Could not reConnect(1)\n");
389 case REQ_STATE_WRITE_IPP_ATTRS
:
391 // Send the attributes list.
396 boolean auth_error
= false;
397 for (int i
=0; i
< ipp
.attrs
.size() && !auth_error
; i
++)
399 attr
= (IPPAttribute
)ipp
.attrs
.get(i
);
400 sz
= attr
.sizeInBytes(last_group
);
401 bytes
= attr
.getBytes(sz
,last_group
);
402 last_group
= attr
.group_tag
;
406 // Check for server response between each attribute.
408 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
413 if (!http
.reConnect())
415 System
.out
.println("Could not reConnect(2)");
418 state
= REQ_STATE_WRITE_HTTP_HEADER
;
434 case REQ_STATE_FINISH_IPP_ATTRS
:
436 // Send the end of attributes tag.
438 byte[] footer
= new byte[1];
439 footer
[0] = (byte)IPPDefs
.TAG_END
;
440 http
.write( footer
);
443 // Keep checking .....
445 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
450 if (!http
.reConnect())
452 System
.out
.println("Could not reConnect(3)");
455 state
= REQ_STATE_WRITE_HTTP_HEADER
;
467 case REQ_STATE_READ_RESPONSE
:
469 // Now read back response
472 read_length
= http
.read_header();
473 switch( http
.status
)
475 case IPPHttp
.HTTP_OK
:
478 case IPPHttp
.HTTP_UNAUTHORIZED
:
480 state
= REQ_STATE_WRITE_HTTP_HEADER
;
488 if (!http
.reConnect())
490 System
.out
.println("Could not reConnect(4)");
493 state
= REQ_STATE_WRITE_HTTP_HEADER
;
497 System
.out
.println("Too many errors: " + errors
);
503 if ((read_length
> 0) && (state
== REQ_STATE_READ_RESPONSE
))
505 http
.read_buffer
= http
.read(read_length
);
506 ipp
= http
.processResponse();
521 } // End of doRequest
526 * Send a FILE to the CUPS server.
528 * @param <code>file</code> File to send.
529 * @return <code>boolean</code> True on success, false otherwise
530 * @throw <code>IOException</code>
532 public boolean doRequest(File file
) throws IOException
535 int state
= FILEREQ_STATE_CREATE_HTTP
;
537 FileInputStream fis
= null;
544 case FILEREQ_STATE_CREATE_HTTP
:
545 String url_str
= site
+ dest
;
548 if (user
.length() > 0 && passwd
.length() > 0)
549 http
= new IPPHttp(url_str
, "", user
, passwd
);
551 http
= new IPPHttp(url_str
);
554 catch (IOException e
)
562 case FILEREQ_STATE_WRITE_HTTP_HEADER
:
570 // Open an input stream to the file.
574 fis
= new FileInputStream(file
);
576 catch (IOException e
)
579 error_text
= "Error opening file input stream.";
584 // Send the HTTP header.
586 int ippSz
= ipp
.sizeInBytes() + (int)file
.length();
587 switch( http
.writeHeader( http
.path
, ippSz
))
589 case IPPHttp
.HTTP_FORBIDDEN
:
590 case IPPHttp
.HTTP_NOT_FOUND
:
591 case IPPHttp
.HTTP_BAD_REQUEST
:
592 case IPPHttp
.HTTP_METHOD_NOT_ALLOWED
:
593 case IPPHttp
.HTTP_PAYMENT_REQUIRED
:
594 case IPPHttp
.HTTP_UPGRADE_REQUIRED
:
595 case IPPHttp
.HTTP_ERROR
:
596 case IPPHttp
.HTTP_UNAUTHORIZED
:
612 case FILEREQ_STATE_WRITE_IPP_HEADER
:
614 // Send the request header.
616 byte[] header
= new byte[8];
619 header
[2] = (byte)((ipp
.request
.operation_id
& 0xff00) >> 8);
620 header
[3] = (byte)(ipp
.request
.operation_id
& 0xff);
621 header
[4] = (byte)((ipp
.request
.request_id
& 0xff000000) >> 24);
622 header
[5] = (byte)((ipp
.request
.request_id
& 0xff0000) >> 16);
623 header
[6] = (byte)((ipp
.request
.request_id
& 0xff00) >> 8);
624 header
[7] = (byte)(ipp
.request
.request_id
& 0xff);
625 http
.write( header
);
626 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
632 state
= FILEREQ_STATE_WRITE_HTTP_HEADER
;
641 case FILEREQ_STATE_WRITE_IPP_ATTRS
:
643 // Send the attributes list.
648 boolean auth_error
= false;
649 for (int i
=0; i
< ipp
.attrs
.size() && !auth_error
; i
++)
651 attr
= (IPPAttribute
)ipp
.attrs
.get(i
);
652 sz
= attr
.sizeInBytes(last_group
);
653 bytes
= attr
.getBytes(sz
,last_group
);
654 last_group
= attr
.group_tag
;
658 // Check for server response between each attribute.
660 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
666 state
= FILEREQ_STATE_WRITE_HTTP_HEADER
;
680 case FILEREQ_STATE_FINISH_IPP_ATTRS
:
682 // Send the end of attributes tag.
684 byte[] footer
= new byte[1];
685 footer
[0] = (byte)IPPDefs
.TAG_END
;
686 http
.write( footer
);
689 // Keep checking .....
691 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
697 state
= FILEREQ_STATE_WRITE_HTTP_HEADER
;
707 case FILEREQ_STATE_WRITE_FILE_DATA
:
709 // Send the file data - this could be improved on ALOT.
712 byte[] b
= new byte[1024];
713 while ((state
== FILEREQ_STATE_WRITE_FILE_DATA
) &&
714 ((count
= fis
.read(b
)) != -1))
717 // Keep checking .....
719 if (http
.checkForResponse() >= IPPHttp
.HTTP_BAD_REQUEST
)
725 state
= FILEREQ_STATE_WRITE_HTTP_HEADER
;
735 http
.write( b
, count
);
740 if (state
== FILEREQ_STATE_WRITE_FILE_DATA
)
750 case FILEREQ_STATE_READ_RESPONSE
:
752 // Now read back response
755 read_length
= http
.read_header();
756 switch( http
.status
)
758 case IPPHttp
.HTTP_OK
:
761 case IPPHttp
.HTTP_UNAUTHORIZED
:
763 state
= FILEREQ_STATE_WRITE_HTTP_HEADER
;
772 state
= FILEREQ_STATE_WRITE_HTTP_HEADER
;
781 if ((read_length
> 0) && (state
== FILEREQ_STATE_READ_RESPONSE
))
783 http
.read_buffer
= http
.read(read_length
);
784 ipp
= http
.processResponse();
789 case FILEREQ_STATE_DONE
:
799 } // End of doRequest(file)
808 * Get a list of jobs.
810 * @param <code>showMyJobs</code> Show only jobs for user.
811 * @param <code>showCompleted</code> Show completed OR active jobs.
813 * @return <code>CupsJob[]</code> Array of job objects, or null.
814 * @throw <code>IOException</code>
816 public CupsJob
[] cupsGetJobs( boolean showMyJobs
, boolean showCompleted
)
822 String req_attrs
[] = /* Requested attributes */
830 "time-at-processing",
834 "job-originating-user-name"
839 ipp
.request
= new IPPRequest( 1, (short)IPPDefs
.GET_JOBS
);
841 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
842 "attributes-charset" );
843 a
.addString( "", "iso-8859-1" );
847 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
848 "attributes-natural-language" );
849 a
.addString( "", "en" );
854 // Add the printer uri
856 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_URI
,
860 a
.addString( "", site
);
862 a
.addString( "", "ipp://localhost/jobs" ); // Default ...
868 // Add the requesting user name
869 // **FIX** This should be fixed to use the user member.
871 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_NAME
,
872 "requesting-user-name" );
873 a
.addString( "", "root" );
877 // Show only my jobs?
881 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_BOOLEAN
,
883 a
.addBoolean( true );
888 // Show completed jobs?
892 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_KEYWORD
,
894 a
.addString( "", "completed" );
899 // Get ALL attributes - to get only listed ones,
900 // uncomment this and fill in req_attrs.
902 // a = new IPPAttribute( IPPDefs.TAG_OPERATION, IPPDefs.TAG_KEYWORD,
903 // "requested-attributes" );
904 // a.addStrings( "", req_attrs );
905 // ipp.addAttribute(a);
908 // Do the request and process the response.
910 if (doRequest("cupsGetJobs"))
915 // First we have to figure out how many jobs there are
916 // so we can create the array.
920 // Skip past leading attributes
924 while ((i
< ipp
.attrs
.size()) && (group_tag
!= IPPDefs
.TAG_JOB
))
926 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
927 group_tag
= a
.group_tag
;
928 if (group_tag
!= IPPDefs
.TAG_JOB
)
933 group_tag
= IPPDefs
.TAG_JOB
;
934 while ((i
< ipp
.attrs
.size()) && (group_tag
== IPPDefs
.TAG_JOB
))
936 a
= (IPPAttribute
)ipp
.attrs
.get(i
++);
937 if ((a
!= null) && (a
.name
.compareTo("job-id") == 0))
947 // Now create the array of the proper size.
950 CupsJob
[] jobs
= new CupsJob
[num_jobs
];
951 for (n
=0; n
< num_jobs
; n
++)
953 jobs
[n
] = new CupsJob();
960 // Skip past leading attributes
964 while ((i
< ipp
.attrs
.size()) && (group_tag
!= IPPDefs
.TAG_JOB
))
966 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
967 group_tag
= a
.group_tag
;
968 if (group_tag
!= IPPDefs
.TAG_JOB
)
973 // Now we actually fill the array with the job data.
976 for (;i
< ipp
.attrs
.size(); i
++)
978 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
980 if (a
.group_tag
== IPPDefs
.TAG_ZERO
)
989 jobs
[n
].updateAttribute( a
);
991 catch (ArrayIndexOutOfBoundsException e
)
1001 } // End of cupsGetJobs
1006 * Get a list of printers.
1008 * @return <code>String[]</code> Array of printers, or null.
1009 * @throw <code>IOException</code>
1011 public String
[] cupsGetPrinters()
1020 // Fill in the required attributes
1022 ipp
.request
= new IPPRequest( 1, (short)IPPDefs
.CUPS_GET_PRINTERS
);
1024 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
1025 "attributes-charset" );
1026 a
.addString( "", "iso-8859-1" );
1027 ipp
.addAttribute(a
);
1030 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
1031 "attributes-natural-language" );
1032 a
.addString( "", "en" );
1033 ipp
.addAttribute(a
);
1036 if (doRequest("cupsGetPrinters"))
1038 int num_printers
= 0;
1039 for (int i
=0; i
< ipp
.attrs
.size(); i
++)
1041 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
1042 if ((a
.name
.compareTo("printer-name") == 0) &&
1043 (a
.value_tag
== IPPDefs
.TAG_NAME
))
1048 if (num_printers
< 1)
1051 String
[] printers
= new String
[num_printers
];
1054 for (int i
=0; i
< ipp
.attrs
.size(); i
++)
1056 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
1057 if (a
.group_tag
< 2)
1060 if ((a
.name
.compareTo("printer-name") == 0) &&
1061 (a
.value_tag
== IPPDefs
.TAG_NAME
))
1063 val
= (IPPValue
)a
.values
.get(0);
1066 printers
[n
] = val
.text
;
1073 } // if doRequest ...
1077 } // End of cupsGetPrinters
1083 * Get default destination.
1085 * @return <code>String</code> Name of default printer, or null.
1086 * @throw <code>IOException</code>
1088 public String
cupsGetDefault()
1097 // Fill in the required attributes
1099 ipp
.request
= new IPPRequest( 1, (short)IPPDefs
.CUPS_GET_DEFAULT
);
1101 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
1102 "attributes-charset" );
1103 a
.addString( "", "iso-8859-1" );
1104 ipp
.addAttribute(a
);
1107 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
1108 "attributes-natural-language" );
1109 a
.addString( "", "en" );
1110 ipp
.addAttribute(a
);
1113 if (doRequest("cupsGetDefault"))
1115 if ((ipp
== null) || (ipp
.attrs
== null))
1118 int num_printers
= 0;
1119 for (int i
=0; i
< ipp
.attrs
.size(); i
++)
1121 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
1122 if ((a
.name
.compareTo("printer-name") == 0) &&
1123 (a
.value_tag
== IPPDefs
.TAG_NAME
))
1125 IPPValue val
= (IPPValue
)a
.values
.get(0);
1132 } // if doRequest ...
1136 } // End of cupsGetDefault
1144 * Get printer attributes
1146 * @param <code>printer_name</code> Name of printer to get info for.
1147 * @return <code>List</code> List of attributes.
1148 * @throw <code>IOException</code>
1150 * @see <code>CupsPrinter</code>
1152 public List
cupsGetPrinterAttributes( String printer_name
)
1161 // Fill in the required attributes
1163 ipp
.request
= new IPPRequest( 1, (short)IPPDefs
.GET_PRINTER_ATTRIBUTES
);
1165 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
1166 "attributes-charset" );
1167 a
.addString( "", "iso-8859-1" );
1168 ipp
.addAttribute(a
);
1171 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
1172 "attributes-natural-language" );
1173 a
.addString( "", "en" );
1174 ipp
.addAttribute(a
);
1176 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_URI
,
1178 String p_uri
= "ipp://" + address
+ ":" +
1179 port
+ "/printers/" + printer_name
;
1180 a
.addString( "", p_uri
);
1181 ipp
.addAttribute(a
);
1183 if (doRequest("cupsGetPrinterAttributes"))
1190 } // End of cupsGetPrinterAttributes
1198 * @param <code>p_filename</code> Path of file to print.
1199 * @param <code>p_attrs[]</code> Array of print job attributes.
1201 * @return <code>CupsJob</code> Object with job info.
1203 * @throw <code>IOException</code>
1205 * @see <code>CupsJob</code>
1207 public CupsJob
cupsPrintFile( String p_filename
,
1208 IPPAttribute p_attrs
[] )
1217 file
= new File(p_filename
);
1221 error_text
= "File does not exist.";
1225 if (!file
.canRead())
1228 error_text
= "File cannot be read.";
1235 // Fill in the required attributes
1237 ipp
.request
= new IPPRequest( 1, (short)IPPDefs
.PRINT_JOB
);
1239 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
1240 "attributes-charset" );
1241 a
.addString( "", "iso-8859-1" );
1242 ipp
.addAttribute(a
);
1245 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
1246 "attributes-natural-language" );
1247 a
.addString( "", "en" );
1248 ipp
.addAttribute(a
);
1251 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_URI
,
1253 a
.addString( "", site
+ dest
);
1254 ipp
.addAttribute(a
);
1257 // **FIX** Fix this later.
1259 a = new IPPAttribute( IPPDefs.TAG_OPERATION, IPPDefs.TAG_NAME,
1260 "requesting-user-name" );
1261 // a.addString( "", p_username );
1262 a.addString( "", "root");
1263 ipp.addAttribute(a);
1267 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_NAME
,
1269 a
.addString( "", file
.getName() );
1270 ipp
.addAttribute(a
);
1272 if (p_attrs
!= null)
1274 for (int i
=0; i
< p_attrs
.length
; i
++)
1277 ipp
.addAttribute(a
);
1281 if (doRequest(file
))
1283 job
= new CupsJob();
1284 for (int i
=0; i
< ipp
.attrs
.size(); i
++)
1286 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
1287 job
.updateAttribute(a
);
1291 } // if doRequest ...
1295 } // End of cupsPrintFile
1302 * Cancel a job - send a job cancel request to the server.
1304 * @param <code>printer_name</code> Destination.
1305 * @param <code>p_job_id</code> ID of job.
1306 * @param <code>p_user_name</code> Requesting user name.
1308 * @throw <code>IOException</code>
1310 public int cupsCancelJob( String printer_name
,
1312 String p_user_name
)
1321 // Fill in the required attributes
1323 ipp
.request
= new IPPRequest( 1, (short)IPPDefs
.CANCEL_JOB
);
1325 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
1326 "attributes-charset" );
1327 a
.addString( "", "iso-8859-1" );
1328 ipp
.addAttribute(a
);
1331 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
1332 "attributes-natural-language" );
1333 a
.addString( "", "en" );
1334 ipp
.addAttribute(a
);
1337 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_URI
,
1339 a
.addString( "", site
+ dest
);
1340 ipp
.addAttribute(a
);
1343 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_INTEGER
,
1345 a
.addInteger( p_job_id
);
1346 ipp
.addAttribute(a
);
1349 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_NAME
,
1350 "requesting-user-name" );
1351 a
.addString( "", p_user_name
);
1352 ipp
.addAttribute(a
);
1354 if (doRequest("cupsCancelJob"))
1356 for (int i
=0; i
< ipp
.attrs
.size(); i
++)
1358 a
= (IPPAttribute
)ipp
.attrs
.get(i
);
1363 } // if doRequest ...
1367 } // End of cupsCancelJob
1372 public List
cupsGetPrinterStatus(String printer_name
)
1381 // Fill in the required attributes
1383 ipp
.request
= new IPPRequest(1,(short)IPPDefs
.GET_PRINTER_ATTRIBUTES
);
1385 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_CHARSET
,
1386 "attributes-charset" );
1387 a
.addString( "", "iso-8859-1" );
1388 ipp
.addAttribute(a
);
1391 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_LANGUAGE
,
1392 "attributes-natural-language" );
1393 a
.addString( "", "en" );
1394 ipp
.addAttribute(a
);
1396 a
= new IPPAttribute( IPPDefs
.TAG_OPERATION
, IPPDefs
.TAG_URI
,
1398 p_uri
= "ipp://" + address
+ ":" +
1399 port
+ "/printers/" + printer_name
;
1400 a
.addString( "", p_uri
);
1401 ipp
.addAttribute(a
);
1403 if (doRequest("cupsGetPrinterStatus"))
1414 } // End of Cups class