author | jgodinez |
Tue, 19 Aug 2008 16:04:06 -0700 | |
changeset 1722 | b676952a5943 |
parent 1721 | 7a86d7e13fdf |
child 1727 | 5e5e0235b14f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1722
b676952a5943
6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
1721
diff
changeset
|
2 |
* Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.print; |
|
27 |
||
28 |
import javax.print.attribute.*; |
|
29 |
import javax.print.attribute.standard.*; |
|
30 |
import javax.print.DocFlavor; |
|
31 |
import javax.print.DocPrintJob; |
|
32 |
import javax.print.PrintService; |
|
33 |
import javax.print.ServiceUIFactory; |
|
34 |
import java.util.ArrayList; |
|
35 |
import java.util.HashMap; |
|
36 |
import java.util.Locale; |
|
37 |
import java.util.Date; |
|
38 |
import java.util.Arrays; |
|
39 |
import java.security.AccessController; |
|
40 |
import java.security.PrivilegedActionException; |
|
41 |
import java.security.PrivilegedExceptionAction; |
|
42 |
import javax.print.event.PrintServiceAttributeListener; |
|
43 |
||
44 |
import java.net.URI; |
|
45 |
import java.net.URISyntaxException; |
|
46 |
import java.net.URL; |
|
47 |
import java.net.HttpURLConnection; |
|
48 |
import java.io.File; |
|
49 |
import java.io.InputStream; |
|
50 |
import java.io.OutputStream; |
|
51 |
import java.io.OutputStreamWriter; |
|
52 |
import java.io.DataInputStream; |
|
53 |
import java.io.ByteArrayOutputStream; |
|
54 |
import java.io.ByteArrayInputStream; |
|
55 |
import java.io.BufferedReader; |
|
56 |
import java.io.InputStreamReader; |
|
57 |
import java.nio.charset.Charset; |
|
58 |
||
59 |
import java.util.Iterator; |
|
1720 | 60 |
import java.util.HashSet; |
2 | 61 |
|
62 |
||
63 |
public class IPPPrintService implements PrintService, SunPrinterJobService { |
|
64 |
||
65 |
public static boolean debugPrint = false; |
|
66 |
private static String debugPrefix = "IPPPrintService>> "; |
|
67 |
protected static void debug_println(String str) { |
|
68 |
if (debugPrint) { |
|
69 |
System.out.println(str); |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
||
74 |
private String printer; |
|
75 |
private URI myURI; |
|
76 |
private URL myURL; |
|
77 |
transient private ServiceNotifier notifier = null; |
|
78 |
||
79 |
private static int MAXCOPIES = 1000; |
|
80 |
private static short MAX_ATTRIBUTE_LENGTH = 255; |
|
81 |
||
82 |
private CUPSPrinter cps; |
|
83 |
private HttpURLConnection urlConnection = null; |
|
84 |
private DocFlavor[] supportedDocFlavors; |
|
85 |
private Class[] supportedCats; |
|
86 |
private MediaTray[] mediaTrays; |
|
87 |
private MediaSizeName[] mediaSizeNames; |
|
88 |
private CustomMediaSizeName[] customMediaSizeNames; |
|
89 |
private int defaultMediaIndex; |
|
90 |
private boolean isCupsPrinter; |
|
91 |
private boolean init; |
|
92 |
private Boolean isPS; |
|
93 |
private HashMap getAttMap; |
|
94 |
private boolean pngImagesAdded = false; |
|
95 |
private boolean gifImagesAdded = false; |
|
96 |
private boolean jpgImagesAdded = false; |
|
97 |
||
98 |
||
99 |
/** |
|
100 |
* IPP Status Codes |
|
101 |
*/ |
|
102 |
private static final byte STATUSCODE_SUCCESS = 0x00; |
|
103 |
||
104 |
/** |
|
105 |
* IPP Group Tags. Each tag is used once before the first attribute |
|
106 |
* of that group. |
|
107 |
*/ |
|
108 |
// operation attributes group |
|
109 |
private static final byte GRPTAG_OP_ATTRIBUTES = 0x01; |
|
110 |
// job attributes group |
|
111 |
private static final byte GRPTAG_JOB_ATTRIBUTES = 0x02; |
|
112 |
// printer attributes group |
|
113 |
private static final byte GRPTAG_PRINTER_ATTRIBUTES = 0x04; |
|
114 |
// used as the last tag in an IPP message. |
|
115 |
private static final byte GRPTAG_END_ATTRIBUTES = 0x03; |
|
116 |
||
117 |
/** |
|
118 |
* IPP Operation codes |
|
119 |
*/ |
|
120 |
// gets the attributes for a printer |
|
121 |
public static final String OP_GET_ATTRIBUTES = "000B"; |
|
122 |
// gets the default printer |
|
123 |
public static final String OP_CUPS_GET_DEFAULT = "4001"; |
|
124 |
// gets the list of printers |
|
125 |
public static final String OP_CUPS_GET_PRINTERS = "4002"; |
|
126 |
||
127 |
||
128 |
/** |
|
129 |
* List of all PrintRequestAttributes. This is used |
|
130 |
* for looping through all the IPP attribute name. |
|
131 |
*/ |
|
132 |
private static Object[] printReqAttribDefault = { |
|
133 |
Chromaticity.COLOR, |
|
134 |
new Copies(1), |
|
135 |
Fidelity.FIDELITY_FALSE, |
|
136 |
Finishings.NONE, |
|
137 |
//new JobHoldUntil(new Date()), |
|
138 |
//new JobImpressions(0), |
|
139 |
//JobImpressions, |
|
140 |
//JobKOctets, |
|
141 |
//JobMediaSheets, |
|
142 |
new JobName("", Locale.getDefault()), |
|
143 |
//JobPriority, |
|
144 |
JobSheets.NONE, |
|
145 |
(Media)MediaSizeName.NA_LETTER, |
|
146 |
//MediaPrintableArea.class, // not an IPP attribute |
|
147 |
//MultipleDocumentHandling.SINGLE_DOCUMENT, |
|
148 |
new NumberUp(1), |
|
149 |
OrientationRequested.PORTRAIT, |
|
150 |
new PageRanges(1), |
|
151 |
//PresentationDirection, |
|
152 |
// CUPS does not supply printer-resolution attribute |
|
153 |
//new PrinterResolution(300, 300, PrinterResolution.DPI), |
|
154 |
//PrintQuality.NORMAL, |
|
155 |
new RequestingUserName("", Locale.getDefault()), |
|
156 |
//SheetCollate.UNCOLLATED, //CUPS has no sheet collate? |
|
157 |
Sides.ONE_SIDED, |
|
158 |
}; |
|
159 |
||
160 |
||
161 |
/** |
|
162 |
* List of all PrintServiceAttributes. This is used |
|
163 |
* for looping through all the IPP attribute name. |
|
164 |
*/ |
|
165 |
private static Object[][] serviceAttributes = { |
|
166 |
{ColorSupported.class, "color-supported"}, |
|
167 |
{PagesPerMinute.class, "pages-per-minute"}, |
|
168 |
{PagesPerMinuteColor.class, "pages-per-minute-color"}, |
|
169 |
{PDLOverrideSupported.class, "pdl-override-supported"}, |
|
170 |
{PrinterInfo.class, "printer-info"}, |
|
171 |
{PrinterIsAcceptingJobs.class, "printer-is-accepting-jobs"}, |
|
172 |
{PrinterLocation.class, "printer-location"}, |
|
173 |
{PrinterMakeAndModel.class, "printer-make-and-model"}, |
|
174 |
{PrinterMessageFromOperator.class, "printer-message-from-operator"}, |
|
175 |
{PrinterMoreInfo.class, "printer-more-info"}, |
|
176 |
{PrinterMoreInfoManufacturer.class, "printer-more-info-manufacturer"}, |
|
177 |
{PrinterName.class, "printer-name"}, |
|
178 |
{PrinterState.class, "printer-state"}, |
|
179 |
{PrinterStateReasons.class, "printer-state-reasons"}, |
|
180 |
{PrinterURI.class, "printer-uri"}, |
|
181 |
{QueuedJobCount.class, "queued-job-count"} |
|
182 |
}; |
|
183 |
||
184 |
||
185 |
/** |
|
186 |
* List of DocFlavors, grouped based on matching mime-type. |
|
187 |
* NOTE: For any change in the predefined DocFlavors, it must be reflected |
|
188 |
* here also. |
|
189 |
*/ |
|
190 |
// PDF DocFlavors |
|
191 |
private static DocFlavor[] appPDF = { |
|
192 |
DocFlavor.BYTE_ARRAY.PDF, |
|
193 |
DocFlavor.INPUT_STREAM.PDF, |
|
194 |
DocFlavor.URL.PDF |
|
195 |
}; |
|
196 |
||
197 |
// Postscript DocFlavors |
|
198 |
private static DocFlavor[] appPostScript = { |
|
199 |
DocFlavor.BYTE_ARRAY.POSTSCRIPT, |
|
200 |
DocFlavor.INPUT_STREAM.POSTSCRIPT, |
|
201 |
DocFlavor.URL.POSTSCRIPT |
|
202 |
}; |
|
203 |
||
204 |
// Autosense DocFlavors |
|
205 |
private static DocFlavor[] appOctetStream = { |
|
206 |
DocFlavor.BYTE_ARRAY.AUTOSENSE, |
|
207 |
DocFlavor.INPUT_STREAM.AUTOSENSE, |
|
208 |
DocFlavor.URL.AUTOSENSE |
|
209 |
}; |
|
210 |
||
211 |
// Text DocFlavors |
|
212 |
private static DocFlavor[] textPlain = { |
|
213 |
DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_8, |
|
214 |
DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_16, |
|
215 |
DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_16BE, |
|
216 |
DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_16LE, |
|
217 |
DocFlavor.BYTE_ARRAY.TEXT_PLAIN_US_ASCII, |
|
218 |
DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8, |
|
219 |
DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_16, |
|
220 |
DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_16BE, |
|
221 |
DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_16LE, |
|
222 |
DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII, |
|
223 |
DocFlavor.URL.TEXT_PLAIN_UTF_8, |
|
224 |
DocFlavor.URL.TEXT_PLAIN_UTF_16, |
|
225 |
DocFlavor.URL.TEXT_PLAIN_UTF_16BE, |
|
226 |
DocFlavor.URL.TEXT_PLAIN_UTF_16LE, |
|
227 |
DocFlavor.URL.TEXT_PLAIN_US_ASCII, |
|
228 |
DocFlavor.CHAR_ARRAY.TEXT_PLAIN, |
|
229 |
DocFlavor.STRING.TEXT_PLAIN, |
|
230 |
DocFlavor.READER.TEXT_PLAIN |
|
231 |
}; |
|
232 |
||
233 |
private static DocFlavor[] textPlainHost = { |
|
234 |
DocFlavor.BYTE_ARRAY.TEXT_PLAIN_HOST, |
|
235 |
DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST, |
|
236 |
DocFlavor.URL.TEXT_PLAIN_HOST |
|
237 |
}; |
|
238 |
||
239 |
// JPG DocFlavors |
|
240 |
private static DocFlavor[] imageJPG = { |
|
241 |
DocFlavor.BYTE_ARRAY.JPEG, |
|
242 |
DocFlavor.INPUT_STREAM.JPEG, |
|
243 |
DocFlavor.URL.JPEG |
|
244 |
}; |
|
245 |
||
246 |
// GIF DocFlavors |
|
247 |
private static DocFlavor[] imageGIF = { |
|
248 |
DocFlavor.BYTE_ARRAY.GIF, |
|
249 |
DocFlavor.INPUT_STREAM.GIF, |
|
250 |
DocFlavor.URL.GIF |
|
251 |
}; |
|
252 |
||
253 |
// PNG DocFlavors |
|
254 |
private static DocFlavor[] imagePNG = { |
|
255 |
DocFlavor.BYTE_ARRAY.PNG, |
|
256 |
DocFlavor.INPUT_STREAM.PNG, |
|
257 |
DocFlavor.URL.PNG |
|
258 |
}; |
|
259 |
||
260 |
// HTML DocFlavors |
|
261 |
private static DocFlavor[] textHtml = { |
|
262 |
DocFlavor.BYTE_ARRAY.TEXT_HTML_UTF_8, |
|
263 |
DocFlavor.BYTE_ARRAY.TEXT_HTML_UTF_16, |
|
264 |
DocFlavor.BYTE_ARRAY.TEXT_HTML_UTF_16BE, |
|
265 |
DocFlavor.BYTE_ARRAY.TEXT_HTML_UTF_16LE, |
|
266 |
DocFlavor.BYTE_ARRAY.TEXT_HTML_US_ASCII, |
|
267 |
DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_8, |
|
268 |
DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_16, |
|
269 |
DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_16BE, |
|
270 |
DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_16LE, |
|
271 |
DocFlavor.INPUT_STREAM.TEXT_HTML_US_ASCII, |
|
272 |
DocFlavor.URL.TEXT_HTML_UTF_8, |
|
273 |
DocFlavor.URL.TEXT_HTML_UTF_16, |
|
274 |
DocFlavor.URL.TEXT_HTML_UTF_16BE, |
|
275 |
DocFlavor.URL.TEXT_HTML_UTF_16LE, |
|
276 |
DocFlavor.URL.TEXT_HTML_US_ASCII, |
|
277 |
// These are not handled in UnixPrintJob so commenting these |
|
278 |
// for now. |
|
279 |
/* |
|
280 |
DocFlavor.CHAR_ARRAY.TEXT_HTML, |
|
281 |
DocFlavor.STRING.TEXT_HTML, |
|
282 |
DocFlavor.READER.TEXT_HTML, |
|
283 |
*/ |
|
284 |
}; |
|
285 |
||
286 |
private static DocFlavor[] textHtmlHost = { |
|
287 |
DocFlavor.BYTE_ARRAY.TEXT_HTML_HOST, |
|
288 |
DocFlavor.INPUT_STREAM.TEXT_HTML_HOST, |
|
289 |
DocFlavor.URL.TEXT_HTML_HOST, |
|
290 |
}; |
|
291 |
||
292 |
||
293 |
// PCL DocFlavors |
|
294 |
private static DocFlavor[] appPCL = { |
|
295 |
DocFlavor.BYTE_ARRAY.PCL, |
|
296 |
DocFlavor.INPUT_STREAM.PCL, |
|
297 |
DocFlavor.URL.PCL |
|
298 |
}; |
|
299 |
||
300 |
// List of all DocFlavors, used in looping |
|
301 |
// through all supported mime-types |
|
302 |
private static Object[] allDocFlavors = { |
|
303 |
appPDF, appPostScript, appOctetStream, |
|
304 |
textPlain, imageJPG, imageGIF, imagePNG, |
|
305 |
textHtml, appPCL, |
|
306 |
}; |
|
307 |
||
308 |
||
309 |
IPPPrintService(String name, URL url) { |
|
310 |
if ((name == null) || (url == null)){ |
|
311 |
throw new IllegalArgumentException("null uri or printer name"); |
|
312 |
} |
|
313 |
printer = name; |
|
314 |
supportedDocFlavors = null; |
|
315 |
supportedCats = null; |
|
316 |
mediaSizeNames = null; |
|
317 |
customMediaSizeNames = null; |
|
318 |
mediaTrays = null; |
|
319 |
myURL = url; |
|
320 |
cps = null; |
|
321 |
isCupsPrinter = false; |
|
322 |
init = false; |
|
323 |
defaultMediaIndex = -1; |
|
324 |
||
325 |
String host = myURL.getHost(); |
|
326 |
if (host!=null && host.equals(CUPSPrinter.getServer())) { |
|
327 |
isCupsPrinter = true; |
|
328 |
try { |
|
329 |
myURI = new URI("ipp://"+host+ |
|
330 |
"/printers/"+printer); |
|
331 |
debug_println(debugPrefix+"IPPPrintService myURI : "+myURI); |
|
332 |
} catch (java.net.URISyntaxException e) { |
|
333 |
throw new IllegalArgumentException("invalid url"); |
|
334 |
} |
|
335 |
} |
|
336 |
} |
|
337 |
||
338 |
||
542
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
339 |
IPPPrintService(String name, String uriStr, boolean isCups) { |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
340 |
if ((name == null) || (uriStr == null)){ |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
341 |
throw new IllegalArgumentException("null uri or printer name"); |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
342 |
} |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
343 |
printer = name; |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
344 |
supportedDocFlavors = null; |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
345 |
supportedCats = null; |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
346 |
mediaSizeNames = null; |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
347 |
customMediaSizeNames = null; |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
348 |
mediaTrays = null; |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
349 |
cps = null; |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
350 |
init = false; |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
351 |
defaultMediaIndex = -1; |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
352 |
try { |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
353 |
myURL = |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
354 |
new URL(uriStr.replaceFirst("ipp", "http")); |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
355 |
} catch (Exception e) { |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
356 |
IPPPrintService.debug_println(debugPrefix+ |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
357 |
" IPPPrintService, myURL="+ |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
358 |
myURL+" Exception= "+ |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
359 |
e); |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
360 |
} |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
361 |
|
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
362 |
isCupsPrinter = isCups; |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
363 |
try { |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
364 |
myURI = new URI(uriStr); |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
365 |
debug_println(debugPrefix+"IPPPrintService myURI : "+myURI); |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
366 |
} catch (java.net.URISyntaxException e) { |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
367 |
throw new IllegalArgumentException("invalid uri"); |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
368 |
} |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
369 |
} |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
370 |
|
2 | 371 |
|
372 |
/* |
|
373 |
* Initialize mediaSizeNames, mediaTrays and other attributes. |
|
374 |
* Media size/trays are initialized to non-null values, may be 0-length |
|
375 |
* array. |
|
376 |
* NOTE: Must be called from a synchronized block only. |
|
377 |
*/ |
|
378 |
private void initAttributes() { |
|
379 |
if (!init) { |
|
380 |
// init customMediaSizeNames |
|
381 |
customMediaSizeNames = new CustomMediaSizeName[0]; |
|
382 |
||
383 |
if ((urlConnection = getIPPConnection(myURL)) == null) { |
|
384 |
mediaSizeNames = new MediaSizeName[0]; |
|
385 |
mediaTrays = new MediaTray[0]; |
|
386 |
debug_println("NULL urlConnection "); |
|
387 |
init = true; |
|
388 |
return; |
|
389 |
} |
|
390 |
||
391 |
// get all supported attributes through IPP |
|
392 |
opGetAttributes(); |
|
393 |
||
394 |
if (isCupsPrinter) { |
|
395 |
// note, it is possible to query media in CUPS using IPP |
|
396 |
// right now we always get it from PPD. |
|
397 |
// maybe use "&& (usePPD)" later? |
|
398 |
// Another reason why we use PPD is because |
|
399 |
// IPP currently does not support it but PPD does. |
|
400 |
||
401 |
try { |
|
402 |
cps = new CUPSPrinter(printer); |
|
403 |
mediaSizeNames = cps.getMediaSizeNames(); |
|
404 |
mediaTrays = cps.getMediaTrays(); |
|
405 |
customMediaSizeNames = cps.getCustomMediaSizeNames(); |
|
406 |
urlConnection.disconnect(); |
|
407 |
init = true; |
|
408 |
return; |
|
409 |
} catch (Exception e) { |
|
410 |
IPPPrintService.debug_println(debugPrefix+ |
|
542
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
411 |
" error creating CUPSPrinter e="+e); |
2 | 412 |
} |
413 |
} |
|
414 |
||
415 |
// use IPP to get all media, |
|
416 |
Media[] allMedia = (Media[])getSupportedMedia(); |
|
417 |
ArrayList sizeList = new ArrayList(); |
|
418 |
ArrayList trayList = new ArrayList(); |
|
419 |
for (int i=0; i<allMedia.length; i++) { |
|
420 |
if (allMedia[i] instanceof MediaSizeName) { |
|
421 |
sizeList.add(allMedia[i]); |
|
422 |
} else if (allMedia[i] instanceof MediaTray) { |
|
423 |
trayList.add(allMedia[i]); |
|
424 |
} |
|
425 |
} |
|
426 |
||
427 |
if (sizeList != null) { |
|
428 |
mediaSizeNames = new MediaSizeName[sizeList.size()]; |
|
429 |
mediaSizeNames = (MediaSizeName[])sizeList.toArray( |
|
430 |
mediaSizeNames); |
|
431 |
} |
|
432 |
if (trayList != null) { |
|
433 |
mediaTrays = new MediaTray[trayList.size()]; |
|
434 |
mediaTrays = (MediaTray[])trayList.toArray( |
|
435 |
mediaTrays); |
|
436 |
} |
|
437 |
urlConnection.disconnect(); |
|
438 |
||
439 |
init = true; |
|
440 |
} |
|
441 |
} |
|
442 |
||
443 |
||
444 |
public DocPrintJob createPrintJob() { |
|
445 |
SecurityManager security = System.getSecurityManager(); |
|
446 |
if (security != null) { |
|
447 |
security.checkPrintJobAccess(); |
|
448 |
} |
|
449 |
// REMIND: create IPPPrintJob |
|
450 |
return new UnixPrintJob(this); |
|
451 |
} |
|
452 |
||
453 |
||
454 |
public synchronized Object |
|
455 |
getSupportedAttributeValues(Class<? extends Attribute> category, |
|
456 |
DocFlavor flavor, |
|
457 |
AttributeSet attributes) |
|
458 |
{ |
|
459 |
if (category == null) { |
|
460 |
throw new NullPointerException("null category"); |
|
461 |
} |
|
462 |
if (!Attribute.class.isAssignableFrom(category)) { |
|
463 |
throw new IllegalArgumentException(category + |
|
464 |
" does not implement Attribute"); |
|
465 |
} |
|
466 |
if (flavor != null) { |
|
467 |
if (!isDocFlavorSupported(flavor)) { |
|
468 |
throw new IllegalArgumentException(flavor + |
|
469 |
" is an unsupported flavor"); |
|
470 |
} else if (isAutoSense(flavor)) { |
|
471 |
return null; |
|
472 |
} |
|
473 |
||
474 |
} |
|
475 |
||
476 |
if (!isAttributeCategorySupported(category)) { |
|
477 |
return null; |
|
478 |
} |
|
479 |
||
480 |
/* Test if the flavor is compatible with the attributes */ |
|
481 |
if (!isDestinationSupported(flavor, attributes)) { |
|
482 |
return null; |
|
483 |
} |
|
484 |
||
485 |
initAttributes(); |
|
486 |
||
487 |
/* Test if the flavor is compatible with the category */ |
|
488 |
if ((category == Copies.class) || |
|
489 |
(category == CopiesSupported.class)) { |
|
490 |
CopiesSupported cs = new CopiesSupported(1, MAXCOPIES); |
|
491 |
AttributeClass attribClass = (getAttMap != null) ? |
|
492 |
(AttributeClass)getAttMap.get(cs.getName()) : null; |
|
493 |
if (attribClass != null) { |
|
494 |
int[] range = attribClass.getIntRangeValue(); |
|
495 |
cs = new CopiesSupported(range[0], range[1]); |
|
496 |
} |
|
497 |
return cs; |
|
498 |
} else if (category == Chromaticity.class) { |
|
499 |
if (flavor == null || |
|
500 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || |
|
501 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) || |
|
502 |
flavor.equals(DocFlavor.BYTE_ARRAY.GIF) || |
|
503 |
flavor.equals(DocFlavor.INPUT_STREAM.GIF) || |
|
504 |
flavor.equals(DocFlavor.URL.GIF) || |
|
505 |
flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) || |
|
506 |
flavor.equals(DocFlavor.INPUT_STREAM.JPEG) || |
|
507 |
flavor.equals(DocFlavor.URL.JPEG) || |
|
508 |
flavor.equals(DocFlavor.BYTE_ARRAY.PNG) || |
|
509 |
flavor.equals(DocFlavor.INPUT_STREAM.PNG) || |
|
510 |
flavor.equals(DocFlavor.URL.PNG)) { |
|
511 |
||
512 |
Chromaticity[]arr = new Chromaticity[1]; |
|
513 |
arr[0] = Chromaticity.COLOR; |
|
514 |
return (arr); |
|
515 |
} else { |
|
516 |
return null; |
|
517 |
} |
|
518 |
} else if (category == Destination.class) { |
|
519 |
if (flavor == null || |
|
520 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || |
|
521 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) { |
|
522 |
try { |
|
523 |
return new Destination((new File("out.ps")).toURI()); |
|
524 |
} catch (SecurityException se) { |
|
525 |
try { |
|
526 |
return new Destination(new URI("file:out.ps")); |
|
527 |
} catch (URISyntaxException e) { |
|
528 |
return null; |
|
529 |
} |
|
530 |
} |
|
531 |
} |
|
532 |
return null; |
|
533 |
} else if (category == Fidelity.class) { |
|
534 |
Fidelity []arr = new Fidelity[2]; |
|
535 |
arr[0] = Fidelity.FIDELITY_FALSE; |
|
536 |
arr[1] = Fidelity.FIDELITY_TRUE; |
|
537 |
return arr; |
|
538 |
} else if (category == Finishings.class) { |
|
539 |
AttributeClass attribClass = (getAttMap != null) ? |
|
540 |
(AttributeClass)getAttMap.get("finishings-supported") |
|
541 |
: null; |
|
542 |
if (attribClass != null) { |
|
543 |
int[] finArray = attribClass.getArrayOfIntValues(); |
|
544 |
if ((finArray != null) && (finArray.length > 0)) { |
|
545 |
Finishings[] finSup = new Finishings[finArray.length]; |
|
546 |
for (int i=0; i<finArray.length; i++) { |
|
547 |
finSup[i] = Finishings.NONE; |
|
548 |
Finishings[] fAll = (Finishings[]) |
|
549 |
(new ExtFinishing(100)).getAll(); |
|
550 |
for (int j=0; j<fAll.length; j++) { |
|
551 |
if (finArray[i] == fAll[j].getValue()) { |
|
552 |
finSup[i] = fAll[j]; |
|
553 |
break; |
|
554 |
} |
|
555 |
} |
|
556 |
} |
|
557 |
return finSup; |
|
558 |
} |
|
559 |
} |
|
560 |
} else if (category == JobName.class) { |
|
561 |
return new JobName("Java Printing", null); |
|
562 |
} else if (category == JobSheets.class) { |
|
563 |
JobSheets arr[] = new JobSheets[2]; |
|
564 |
arr[0] = JobSheets.NONE; |
|
565 |
arr[1] = JobSheets.STANDARD; |
|
566 |
return arr; |
|
567 |
||
568 |
} else if (category == Media.class) { |
|
569 |
Media[] allMedia = new Media[mediaSizeNames.length+ |
|
570 |
mediaTrays.length]; |
|
571 |
||
572 |
for (int i=0; i<mediaSizeNames.length; i++) { |
|
573 |
allMedia[i] = mediaSizeNames[i]; |
|
574 |
} |
|
575 |
||
576 |
for (int i=0; i<mediaTrays.length; i++) { |
|
577 |
allMedia[i+mediaSizeNames.length] = mediaTrays[i]; |
|
578 |
} |
|
579 |
||
580 |
if (allMedia.length == 0) { |
|
581 |
allMedia = new Media[1]; |
|
582 |
allMedia[0] = (Media)getDefaultAttributeValue(Media.class); |
|
583 |
} |
|
584 |
||
585 |
return allMedia; |
|
586 |
} else if (category == MediaPrintableArea.class) { |
|
587 |
MediaPrintableArea[] mpas = null; |
|
588 |
if (cps != null) { |
|
589 |
mpas = cps.getMediaPrintableArea(); |
|
590 |
} |
|
591 |
||
592 |
if (mpas == null) { |
|
593 |
mpas = new MediaPrintableArea[1]; |
|
594 |
mpas[0] = (MediaPrintableArea) |
|
595 |
getDefaultAttributeValue(MediaPrintableArea.class); |
|
596 |
} |
|
597 |
||
598 |
if ((attributes == null) || (attributes.size() == 0)) { |
|
599 |
ArrayList<MediaPrintableArea> printableList = |
|
600 |
new ArrayList<MediaPrintableArea>(); |
|
601 |
||
602 |
for (int i=0; i<mpas.length; i++) { |
|
603 |
if (mpas[i] != null) { |
|
604 |
printableList.add(mpas[i]); |
|
605 |
} |
|
606 |
} |
|
607 |
if (printableList.size() > 0) { |
|
608 |
mpas = new MediaPrintableArea[printableList.size()]; |
|
609 |
printableList.toArray(mpas); |
|
610 |
} |
|
611 |
return mpas; |
|
612 |
} |
|
613 |
||
614 |
int match = -1; |
|
615 |
Media media = (Media)attributes.get(Media.class); |
|
616 |
if (media != null && media instanceof MediaSizeName) { |
|
617 |
MediaSizeName msn = (MediaSizeName)media; |
|
618 |
||
619 |
// case when no supported mediasizenames are reported |
|
620 |
// check given media against the default |
|
621 |
if (mediaSizeNames.length == 0 && |
|
622 |
msn.equals(getDefaultAttributeValue(Media.class))) { |
|
623 |
//default printable area is that of default mediasize |
|
624 |
return mpas; |
|
625 |
} |
|
626 |
||
627 |
for (int i=0; i<mediaSizeNames.length; i++) { |
|
628 |
if (msn.equals(mediaSizeNames[i])) { |
|
629 |
match = i; |
|
630 |
} |
|
631 |
} |
|
632 |
} |
|
633 |
||
634 |
if (match == -1) { |
|
635 |
return null; |
|
636 |
} else { |
|
637 |
MediaPrintableArea []arr = new MediaPrintableArea[1]; |
|
638 |
arr[0] = mpas[match]; |
|
639 |
return arr; |
|
640 |
} |
|
641 |
} else if (category == NumberUp.class) { |
|
642 |
AttributeClass attribClass = (getAttMap != null) ? |
|
643 |
(AttributeClass)getAttMap.get("number-up-supported") : null; |
|
644 |
if (attribClass != null) { |
|
645 |
int[] values = attribClass.getArrayOfIntValues(); |
|
646 |
if (values != null) { |
|
647 |
NumberUp[] nUp = new NumberUp[values.length]; |
|
648 |
for (int i=0; i<values.length; i++) { |
|
649 |
nUp[i] = new NumberUp(values[i]); |
|
650 |
} |
|
651 |
return nUp; |
|
652 |
} else { |
|
653 |
return null; |
|
654 |
} |
|
655 |
} |
|
656 |
} else if (category == OrientationRequested.class) { |
|
535
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
657 |
boolean revPort = false; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
658 |
OrientationRequested[] orientSup = null; |
2 | 659 |
|
660 |
AttributeClass attribClass = (getAttMap != null) ? |
|
661 |
(AttributeClass)getAttMap.get("orientation-requested-supported") |
|
662 |
: null; |
|
663 |
if (attribClass != null) { |
|
664 |
int[] orientArray = attribClass.getArrayOfIntValues(); |
|
665 |
if ((orientArray != null) && (orientArray.length > 0)) { |
|
535
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
666 |
orientSup = |
2 | 667 |
new OrientationRequested[orientArray.length]; |
668 |
for (int i=0; i<orientArray.length; i++) { |
|
669 |
switch (orientArray[i]) { |
|
670 |
default: |
|
671 |
case 3 : |
|
672 |
orientSup[i] = OrientationRequested.PORTRAIT; |
|
673 |
break; |
|
674 |
case 4: |
|
675 |
orientSup[i] = OrientationRequested.LANDSCAPE; |
|
676 |
break; |
|
677 |
case 5: |
|
678 |
orientSup[i] = |
|
679 |
OrientationRequested.REVERSE_LANDSCAPE; |
|
680 |
break; |
|
681 |
case 6: |
|
682 |
orientSup[i] = |
|
683 |
OrientationRequested.REVERSE_PORTRAIT; |
|
535
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
684 |
revPort = true; |
2 | 685 |
break; |
686 |
} |
|
687 |
} |
|
688 |
} |
|
689 |
} |
|
535
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
690 |
if (flavor == null || |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
691 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
692 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) { |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
693 |
|
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
694 |
if (revPort && flavor == null) { |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
695 |
OrientationRequested []orSup = new OrientationRequested[4]; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
696 |
orSup[0] = OrientationRequested.PORTRAIT; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
697 |
orSup[1] = OrientationRequested.LANDSCAPE; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
698 |
orSup[2] = OrientationRequested.REVERSE_LANDSCAPE; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
699 |
orSup[3] = OrientationRequested.REVERSE_PORTRAIT; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
700 |
return orSup; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
701 |
} else { |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
702 |
OrientationRequested []orSup = new OrientationRequested[3]; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
703 |
orSup[0] = OrientationRequested.PORTRAIT; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
704 |
orSup[1] = OrientationRequested.LANDSCAPE; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
705 |
orSup[2] = OrientationRequested.REVERSE_LANDSCAPE; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
706 |
return orSup; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
707 |
} |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
708 |
} else { |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
709 |
return orientSup; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
710 |
} |
2 | 711 |
} else if (category == PageRanges.class) { |
712 |
if (flavor == null || |
|
713 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || |
|
714 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) { |
|
715 |
PageRanges []arr = new PageRanges[1]; |
|
716 |
arr[0] = new PageRanges(1, Integer.MAX_VALUE); |
|
717 |
return arr; |
|
718 |
} else { |
|
719 |
// Returning null as this is not yet supported in UnixPrintJob. |
|
720 |
return null; |
|
721 |
} |
|
722 |
} else if (category == RequestingUserName.class) { |
|
723 |
String userName = ""; |
|
724 |
try { |
|
725 |
userName = System.getProperty("user.name", ""); |
|
726 |
} catch (SecurityException se) { |
|
727 |
} |
|
728 |
return new RequestingUserName(userName, null); |
|
729 |
} else if (category == Sides.class) { |
|
730 |
// The printer takes care of Sides so if short-edge |
|
731 |
// is chosen in a job, the rotation is done by the printer. |
|
732 |
// Orientation is rotated by emulation if pageable |
|
733 |
// or printable so if the document is in Landscape, this may |
|
734 |
// result in double rotation. |
|
735 |
AttributeClass attribClass = (getAttMap != null) ? |
|
736 |
(AttributeClass)getAttMap.get("sides-supported") |
|
737 |
: null; |
|
738 |
if (attribClass != null) { |
|
739 |
String[] sidesArray = attribClass.getArrayOfStringValues(); |
|
740 |
if ((sidesArray != null) && (sidesArray.length > 0)) { |
|
741 |
Sides[] sidesSup = new Sides[sidesArray.length]; |
|
742 |
for (int i=0; i<sidesArray.length; i++) { |
|
743 |
if (sidesArray[i].endsWith("long-edge")) { |
|
744 |
sidesSup[i] = Sides.TWO_SIDED_LONG_EDGE; |
|
745 |
} else if (sidesArray[i].endsWith("short-edge")) { |
|
746 |
sidesSup[i] = Sides.TWO_SIDED_SHORT_EDGE; |
|
747 |
} else { |
|
748 |
sidesSup[i] = Sides.ONE_SIDED; |
|
749 |
} |
|
750 |
} |
|
751 |
return sidesSup; |
|
752 |
} |
|
753 |
} |
|
754 |
} |
|
755 |
||
756 |
return null; |
|
757 |
} |
|
758 |
||
759 |
//This class is for getting all pre-defined Finishings |
|
760 |
private class ExtFinishing extends Finishings { |
|
761 |
ExtFinishing(int value) { |
|
762 |
super(100); // 100 to avoid any conflicts with predefined values. |
|
763 |
} |
|
764 |
||
765 |
EnumSyntax[] getAll() { |
|
766 |
EnumSyntax[] es = super.getEnumValueTable(); |
|
767 |
return es; |
|
768 |
} |
|
769 |
} |
|
770 |
||
771 |
||
772 |
public AttributeSet getUnsupportedAttributes(DocFlavor flavor, |
|
773 |
AttributeSet attributes) { |
|
774 |
if (flavor != null && !isDocFlavorSupported(flavor)) { |
|
775 |
throw new IllegalArgumentException("flavor " + flavor + |
|
776 |
"is not supported"); |
|
777 |
} |
|
778 |
||
779 |
if (attributes == null) { |
|
780 |
return null; |
|
781 |
} |
|
782 |
||
783 |
Attribute attr; |
|
784 |
AttributeSet unsupp = new HashAttributeSet(); |
|
785 |
Attribute []attrs = attributes.toArray(); |
|
786 |
for (int i=0; i<attrs.length; i++) { |
|
787 |
try { |
|
788 |
attr = attrs[i]; |
|
789 |
if (!isAttributeCategorySupported(attr.getCategory())) { |
|
790 |
unsupp.add(attr); |
|
791 |
} else if (!isAttributeValueSupported(attr, flavor, |
|
792 |
attributes)) { |
|
793 |
unsupp.add(attr); |
|
794 |
} |
|
795 |
} catch (ClassCastException e) { |
|
796 |
} |
|
797 |
} |
|
798 |
if (unsupp.isEmpty()) { |
|
799 |
return null; |
|
800 |
} else { |
|
801 |
return unsupp; |
|
802 |
} |
|
803 |
} |
|
804 |
||
805 |
||
806 |
public synchronized DocFlavor[] getSupportedDocFlavors() { |
|
807 |
||
808 |
if (supportedDocFlavors != null) { |
|
809 |
int len = supportedDocFlavors.length; |
|
810 |
DocFlavor[] copyflavors = new DocFlavor[len]; |
|
811 |
System.arraycopy(supportedDocFlavors, 0, copyflavors, 0, len); |
|
812 |
return copyflavors; |
|
813 |
} |
|
814 |
initAttributes(); |
|
815 |
||
816 |
if ((getAttMap != null) && |
|
817 |
getAttMap.containsKey("document-format-supported")) { |
|
818 |
||
819 |
AttributeClass attribClass = |
|
820 |
(AttributeClass)getAttMap.get("document-format-supported"); |
|
821 |
if (attribClass != null) { |
|
822 |
String mimeType; |
|
823 |
boolean psSupported = false; |
|
824 |
String[] docFlavors = attribClass.getArrayOfStringValues(); |
|
825 |
DocFlavor[] flavors; |
|
1720 | 826 |
HashSet docList = new HashSet(); |
2 | 827 |
int j; |
828 |
String hostEnc = DocFlavor.hostEncoding. |
|
829 |
toLowerCase(Locale.ENGLISH); |
|
830 |
boolean addHostEncoding = !hostEnc.equals("utf-8") && |
|
831 |
!hostEnc.equals("utf-16") && !hostEnc.equals("utf-16be") && |
|
832 |
!hostEnc.equals("utf-16le") && !hostEnc.equals("us-ascii"); |
|
833 |
||
834 |
for (int i = 0; i < docFlavors.length; i++) { |
|
835 |
for (j=0; j<allDocFlavors.length; j++) { |
|
836 |
flavors = (DocFlavor[])allDocFlavors[j]; |
|
837 |
||
838 |
mimeType = flavors[0].getMimeType(); |
|
839 |
if (mimeType.startsWith(docFlavors[i])) { |
|
840 |
||
841 |
docList.addAll(Arrays.asList(flavors)); |
|
842 |
||
843 |
if (mimeType.equals("text/plain") && |
|
844 |
addHostEncoding) { |
|
845 |
docList.add(Arrays.asList(textPlainHost)); |
|
846 |
} else if (mimeType.equals("text/html") && |
|
847 |
addHostEncoding) { |
|
848 |
docList.add(Arrays.asList(textHtmlHost)); |
|
849 |
} else if (mimeType.equals("image/png")) { |
|
850 |
pngImagesAdded = true; |
|
851 |
} else if (mimeType.equals("image/gif")) { |
|
852 |
gifImagesAdded = true; |
|
853 |
} else if (mimeType.equals("image/jpeg")) { |
|
854 |
jpgImagesAdded = true; |
|
855 |
} else if (mimeType.indexOf("postscript") != -1) { |
|
856 |
psSupported = true; |
|
857 |
} |
|
858 |
break; |
|
859 |
} |
|
860 |
} |
|
861 |
||
862 |
// Not added? Create new DocFlavors |
|
863 |
if (j == allDocFlavors.length) { |
|
864 |
// make new DocFlavors |
|
865 |
docList.add(new DocFlavor.BYTE_ARRAY(docFlavors[i])); |
|
866 |
docList.add(new DocFlavor.INPUT_STREAM(docFlavors[i])); |
|
867 |
docList.add(new DocFlavor.URL(docFlavors[i])); |
|
868 |
} |
|
869 |
} |
|
870 |
||
871 |
// check if we need to add image DocFlavors |
|
1720 | 872 |
// and Pageable/Printable flavors |
542
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
873 |
if (psSupported || isCupsPrinter) { |
1720 | 874 |
/* |
875 |
Always add Pageable and Printable for CUPS |
|
876 |
since it uses Filters to convert from Postscript |
|
877 |
to device printer language. |
|
878 |
*/ |
|
879 |
docList.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE); |
|
880 |
docList.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE); |
|
881 |
||
882 |
docList.addAll(Arrays.asList(imageJPG)); |
|
883 |
docList.addAll(Arrays.asList(imagePNG)); |
|
884 |
docList.addAll(Arrays.asList(imageGIF)); |
|
2 | 885 |
} |
886 |
supportedDocFlavors = new DocFlavor[docList.size()]; |
|
887 |
docList.toArray(supportedDocFlavors); |
|
888 |
int len = supportedDocFlavors.length; |
|
889 |
DocFlavor[] copyflavors = new DocFlavor[len]; |
|
890 |
System.arraycopy(supportedDocFlavors, 0, copyflavors, 0, len); |
|
891 |
return copyflavors; |
|
892 |
} |
|
893 |
} |
|
894 |
return null; |
|
895 |
} |
|
896 |
||
897 |
||
898 |
public boolean isDocFlavorSupported(DocFlavor flavor) { |
|
899 |
if (supportedDocFlavors == null) { |
|
900 |
getSupportedDocFlavors(); |
|
901 |
} |
|
902 |
if (supportedDocFlavors != null) { |
|
903 |
for (int f=0; f<supportedDocFlavors.length; f++) { |
|
904 |
if (flavor.equals(supportedDocFlavors[f])) { |
|
905 |
return true; |
|
906 |
} |
|
907 |
} |
|
908 |
} |
|
909 |
return false; |
|
910 |
} |
|
911 |
||
912 |
||
913 |
/** |
|
914 |
* Finds matching CustomMediaSizeName of given media. |
|
915 |
*/ |
|
916 |
public CustomMediaSizeName findCustomMedia(MediaSizeName media) { |
|
917 |
for (int i=0; i< customMediaSizeNames.length; i++) { |
|
918 |
CustomMediaSizeName custom = |
|
919 |
(CustomMediaSizeName)customMediaSizeNames[i]; |
|
920 |
MediaSizeName msn = custom.getStandardMedia(); |
|
921 |
if (media.equals(msn)) { |
|
922 |
return customMediaSizeNames[i]; |
|
923 |
} |
|
924 |
} |
|
925 |
return null; |
|
926 |
} |
|
927 |
||
928 |
||
929 |
/** |
|
930 |
* Returns the matching standard Media using string comparison of names. |
|
931 |
*/ |
|
932 |
private Media getIPPMedia(String mediaName) { |
|
933 |
CustomMediaSizeName sampleSize = new CustomMediaSizeName("sample", "", |
|
934 |
0, 0); |
|
935 |
Media[] sizes = sampleSize.getSuperEnumTable(); |
|
936 |
for (int i=0; i<sizes.length; i++) { |
|
937 |
if (mediaName.equals(""+sizes[i])) { |
|
938 |
return sizes[i]; |
|
939 |
} |
|
940 |
} |
|
941 |
CustomMediaTray sampleTray = new CustomMediaTray("sample", ""); |
|
942 |
Media[] trays = sampleTray.getSuperEnumTable(); |
|
943 |
for (int i=0; i<trays.length; i++) { |
|
944 |
if (mediaName.equals(""+trays[i])) { |
|
945 |
return trays[i]; |
|
946 |
} |
|
947 |
} |
|
948 |
return null; |
|
949 |
} |
|
950 |
||
951 |
private Media[] getSupportedMedia() { |
|
952 |
if ((getAttMap != null) && |
|
953 |
getAttMap.containsKey("media-supported")) { |
|
954 |
||
955 |
AttributeClass attribClass = |
|
956 |
(AttributeClass)getAttMap.get("media-supported"); |
|
957 |
||
958 |
if (attribClass != null) { |
|
959 |
String[] mediaVals = attribClass.getArrayOfStringValues(); |
|
960 |
Media msn; |
|
961 |
Media[] mediaNames = |
|
962 |
new Media[mediaVals.length]; |
|
963 |
for (int i=0; i<mediaVals.length; i++) { |
|
964 |
msn = getIPPMedia(mediaVals[i]); |
|
965 |
//REMIND: if null, create custom? |
|
966 |
mediaNames[i] = msn; |
|
967 |
} |
|
968 |
return mediaNames; |
|
969 |
} |
|
970 |
} |
|
971 |
return new Media[0]; |
|
972 |
} |
|
973 |
||
974 |
||
975 |
public synchronized Class[] getSupportedAttributeCategories() { |
|
976 |
if (supportedCats != null) { |
|
977 |
return supportedCats; |
|
978 |
} |
|
979 |
||
980 |
initAttributes(); |
|
981 |
||
982 |
ArrayList catList = new ArrayList(); |
|
983 |
Class cl; |
|
984 |
||
985 |
for (int i=0; i < printReqAttribDefault.length; i++) { |
|
986 |
PrintRequestAttribute pra = |
|
987 |
(PrintRequestAttribute)printReqAttribDefault[i]; |
|
988 |
if (getAttMap != null && |
|
989 |
getAttMap.containsKey(pra.getName()+"-supported")) { |
|
990 |
cl = pra.getCategory(); |
|
991 |
catList.add(cl); |
|
992 |
} |
|
993 |
} |
|
994 |
||
995 |
// Some IPP printers like lexc710 do not have list of supported media |
|
996 |
// but CUPS can get the media from PPD, so we still report as |
|
997 |
// supported category. |
|
998 |
if (isCupsPrinter) { |
|
999 |
if (!catList.contains(Media.class)) { |
|
1000 |
catList.add(Media.class); |
|
1001 |
} |
|
1002 |
||
1003 |
// Always add MediaPrintable for cups, |
|
1004 |
// because we can get it from PPD. |
|
1005 |
catList.add(MediaPrintableArea.class); |
|
1006 |
||
1007 |
// this is already supported in UnixPrintJob |
|
1008 |
catList.add(Destination.class); |
|
1009 |
} |
|
1010 |
||
1011 |
// With the assumption that Chromaticity is equivalent to |
|
1012 |
// ColorSupported. |
|
1013 |
if (getAttMap != null && getAttMap.containsKey("color-supported")) { |
|
1014 |
catList.add(Chromaticity.class); |
|
1015 |
} |
|
1016 |
supportedCats = new Class[catList.size()]; |
|
1017 |
catList.toArray(supportedCats); |
|
1018 |
return supportedCats; |
|
1019 |
} |
|
1020 |
||
1021 |
||
1022 |
public boolean |
|
1023 |
isAttributeCategorySupported(Class<? extends Attribute> category) |
|
1024 |
{ |
|
1025 |
if (category == null) { |
|
1026 |
throw new NullPointerException("null category"); |
|
1027 |
} |
|
1028 |
if (!(Attribute.class.isAssignableFrom(category))) { |
|
1029 |
throw new IllegalArgumentException(category + |
|
1030 |
" is not an Attribute"); |
|
1031 |
} |
|
1032 |
||
1033 |
if (supportedCats == null) { |
|
1034 |
getSupportedAttributeCategories(); |
|
1035 |
} |
|
1036 |
||
535
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1037 |
// It is safe to assume that Orientation is always supported |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1038 |
// and even if CUPS or an IPP device reports it as not, |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1039 |
// our renderer can do portrait, landscape and |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1040 |
// reverse landscape. |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1041 |
if (category == OrientationRequested.class) { |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1042 |
return true; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1043 |
} |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1044 |
|
2 | 1045 |
for (int i=0;i<supportedCats.length;i++) { |
1046 |
if (category == supportedCats[i]) { |
|
1047 |
return true; |
|
1048 |
} |
|
1049 |
} |
|
1050 |
||
1051 |
return false; |
|
1052 |
} |
|
1053 |
||
1054 |
||
1055 |
public synchronized <T extends PrintServiceAttribute> |
|
1056 |
T getAttribute(Class<T> category) |
|
1057 |
{ |
|
1058 |
if (category == null) { |
|
1059 |
throw new NullPointerException("category"); |
|
1060 |
} |
|
1061 |
if (!(PrintServiceAttribute.class.isAssignableFrom(category))) { |
|
1062 |
throw new IllegalArgumentException("Not a PrintServiceAttribute"); |
|
1063 |
} |
|
1064 |
||
1065 |
initAttributes(); |
|
1066 |
||
1067 |
if (category == PrinterName.class) { |
|
1068 |
return (T)(new PrinterName(printer, null)); |
|
1069 |
} else if (category == QueuedJobCount.class) { |
|
1070 |
QueuedJobCount qjc = new QueuedJobCount(0); |
|
1071 |
AttributeClass ac = (getAttMap != null) ? |
|
1072 |
(AttributeClass)getAttMap.get(qjc.getName()) |
|
1073 |
: null; |
|
1074 |
if (ac != null) { |
|
1075 |
qjc = new QueuedJobCount(ac.getIntValue()); |
|
1076 |
} |
|
1077 |
return (T)qjc; |
|
1078 |
} else if (category == PrinterIsAcceptingJobs.class) { |
|
1079 |
PrinterIsAcceptingJobs accJob = |
|
1080 |
PrinterIsAcceptingJobs.ACCEPTING_JOBS; |
|
1081 |
AttributeClass ac = (getAttMap != null) ? |
|
1082 |
(AttributeClass)getAttMap.get(accJob.getName()) |
|
1083 |
: null; |
|
1084 |
if ((ac != null) && (ac.getByteValue() == 0)) { |
|
1085 |
accJob = PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS; |
|
1086 |
} |
|
1087 |
return (T)accJob; |
|
1088 |
} else if (category == ColorSupported.class) { |
|
1089 |
ColorSupported cs = ColorSupported.SUPPORTED; |
|
1090 |
AttributeClass ac = (getAttMap != null) ? |
|
1091 |
(AttributeClass)getAttMap.get(cs.getName()) |
|
1092 |
: null; |
|
1093 |
if ((ac != null) && (ac.getByteValue() == 0)) { |
|
1094 |
cs = ColorSupported.NOT_SUPPORTED; |
|
1095 |
} |
|
1096 |
return (T)cs; |
|
1097 |
} else if (category == PDLOverrideSupported.class) { |
|
1098 |
||
1099 |
if (isCupsPrinter) { |
|
1100 |
// Documented: For CUPS this will always be false |
|
1101 |
return (T)PDLOverrideSupported.NOT_ATTEMPTED; |
|
1102 |
} else { |
|
1103 |
// REMIND: check attribute values |
|
1104 |
return (T)PDLOverrideSupported.NOT_ATTEMPTED; |
|
1105 |
} |
|
1106 |
} else { |
|
1107 |
return null; |
|
1108 |
} |
|
1109 |
} |
|
1110 |
||
1111 |
||
1112 |
public synchronized PrintServiceAttributeSet getAttributes() { |
|
1113 |
// update getAttMap by sending again get-attributes IPP request |
|
1114 |
init = false; |
|
1115 |
initAttributes(); |
|
1116 |
||
1117 |
HashPrintServiceAttributeSet attrs = |
|
1118 |
new HashPrintServiceAttributeSet(); |
|
1119 |
||
1120 |
for (int i=0; i < serviceAttributes.length; i++) { |
|
1121 |
String name = (String)serviceAttributes[i][1]; |
|
1122 |
if (getAttMap != null && getAttMap.containsKey(name)) { |
|
1123 |
Class c = (Class)serviceAttributes[i][0]; |
|
1124 |
PrintServiceAttribute psa = getAttribute(c); |
|
1125 |
if (psa != null) { |
|
1126 |
attrs.add(psa); |
|
1127 |
} |
|
1128 |
} |
|
1129 |
} |
|
1130 |
return AttributeSetUtilities.unmodifiableView(attrs); |
|
1131 |
} |
|
1132 |
||
1133 |
public boolean isIPPSupportedImages(String mimeType) { |
|
1134 |
if (supportedDocFlavors == null) { |
|
1135 |
getSupportedDocFlavors(); |
|
1136 |
} |
|
1137 |
||
1138 |
if (mimeType.equals("image/png") && pngImagesAdded) { |
|
1139 |
return true; |
|
1140 |
} else if (mimeType.equals("image/gif") && gifImagesAdded) { |
|
1141 |
return true; |
|
1142 |
} else if (mimeType.equals("image/jpeg") && jpgImagesAdded) { |
|
1143 |
return true; |
|
1144 |
} |
|
1145 |
||
1146 |
return false; |
|
1147 |
} |
|
1148 |
||
1149 |
||
1150 |
private boolean isSupportedCopies(Copies copies) { |
|
1151 |
CopiesSupported cs = (CopiesSupported) |
|
1152 |
getSupportedAttributeValues(Copies.class, null, null); |
|
1153 |
int[][] members = cs.getMembers(); |
|
1154 |
int min, max; |
|
1155 |
if ((members.length > 0) && (members[0].length > 0)) { |
|
1156 |
min = members[0][0]; |
|
1157 |
max = members[0][1]; |
|
1158 |
} else { |
|
1159 |
min = 1; |
|
1160 |
max = MAXCOPIES; |
|
1161 |
} |
|
1162 |
||
1163 |
int value = copies.getValue(); |
|
1164 |
return (value >= min && value <= max); |
|
1165 |
} |
|
1166 |
||
1167 |
private boolean isAutoSense(DocFlavor flavor) { |
|
1168 |
if (flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) || |
|
1169 |
flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) || |
|
1170 |
flavor.equals(DocFlavor.URL.AUTOSENSE)) { |
|
1171 |
return true; |
|
1172 |
} |
|
1173 |
else { |
|
1174 |
return false; |
|
1175 |
} |
|
1176 |
} |
|
1177 |
||
1178 |
private synchronized boolean isSupportedMediaTray(MediaTray msn) { |
|
1179 |
initAttributes(); |
|
1180 |
||
1181 |
if (mediaTrays != null) { |
|
1182 |
for (int i=0; i<mediaTrays.length; i++) { |
|
1183 |
if (msn.equals(mediaTrays[i])) { |
|
1184 |
return true; |
|
1185 |
} |
|
1186 |
} |
|
1187 |
} |
|
1188 |
return false; |
|
1189 |
} |
|
1190 |
||
1191 |
private synchronized boolean isSupportedMedia(MediaSizeName msn) { |
|
1192 |
initAttributes(); |
|
1193 |
||
1194 |
if (msn.equals((Media)getDefaultAttributeValue(Media.class))) { |
|
1195 |
return true; |
|
1196 |
} |
|
1197 |
for (int i=0; i<mediaSizeNames.length; i++) { |
|
1198 |
debug_println("mediaSizeNames[i] "+mediaSizeNames[i]); |
|
1199 |
if (msn.equals(mediaSizeNames[i])) { |
|
1200 |
return true; |
|
1201 |
} |
|
1202 |
} |
|
1203 |
return false; |
|
1204 |
} |
|
1205 |
||
1206 |
/* Return false if flavor is not null, pageable, nor printable and |
|
1207 |
* Destination is part of attributes. |
|
1208 |
*/ |
|
1209 |
private boolean |
|
1210 |
isDestinationSupported(DocFlavor flavor, AttributeSet attributes) { |
|
1211 |
||
1212 |
if ((attributes != null) && |
|
1213 |
(attributes.get(Destination.class) != null) && |
|
1214 |
!(flavor == null || |
|
1215 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || |
|
1216 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) { |
|
1217 |
return false; |
|
1218 |
} |
|
1219 |
return true; |
|
1220 |
} |
|
1221 |
||
1222 |
||
1223 |
public boolean isAttributeValueSupported(Attribute attr, |
|
1224 |
DocFlavor flavor, |
|
1225 |
AttributeSet attributes) { |
|
1226 |
if (attr == null) { |
|
1227 |
throw new NullPointerException("null attribute"); |
|
1228 |
} |
|
1229 |
if (flavor != null) { |
|
1230 |
if (!isDocFlavorSupported(flavor)) { |
|
1231 |
throw new IllegalArgumentException(flavor + |
|
1232 |
" is an unsupported flavor"); |
|
1233 |
} else if (isAutoSense(flavor)) { |
|
1234 |
return false; |
|
1235 |
} |
|
1236 |
} |
|
1237 |
Class category = attr.getCategory(); |
|
1238 |
if (!isAttributeCategorySupported(category)) { |
|
1239 |
return false; |
|
1240 |
} |
|
1241 |
||
1242 |
/* Test if the flavor is compatible with the attributes */ |
|
1243 |
if (!isDestinationSupported(flavor, attributes)) { |
|
1244 |
return false; |
|
1245 |
} |
|
1246 |
||
1247 |
/* Test if the flavor is compatible with the category */ |
|
1248 |
if (attr.getCategory() == Chromaticity.class) { |
|
1249 |
if ((flavor == null) || |
|
1250 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || |
|
1251 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) || |
|
1252 |
flavor.equals(DocFlavor.BYTE_ARRAY.GIF) || |
|
1253 |
flavor.equals(DocFlavor.INPUT_STREAM.GIF) || |
|
1254 |
flavor.equals(DocFlavor.URL.GIF) || |
|
1255 |
flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) || |
|
1256 |
flavor.equals(DocFlavor.INPUT_STREAM.JPEG) || |
|
1257 |
flavor.equals(DocFlavor.URL.JPEG) || |
|
1258 |
flavor.equals(DocFlavor.BYTE_ARRAY.PNG) || |
|
1259 |
flavor.equals(DocFlavor.INPUT_STREAM.PNG) || |
|
1260 |
flavor.equals(DocFlavor.URL.PNG)) { |
|
1261 |
return attr == Chromaticity.COLOR; |
|
1262 |
} else { |
|
1263 |
return false; |
|
1264 |
} |
|
1265 |
} else if (attr.getCategory() == Copies.class) { |
|
1266 |
return isSupportedCopies((Copies)attr); |
|
1267 |
} else if (attr.getCategory() == Destination.class) { |
|
1268 |
if (flavor == null || |
|
1269 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || |
|
1270 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) { |
|
1271 |
URI uri = ((Destination)attr).getURI(); |
|
1272 |
if ("file".equals(uri.getScheme()) && |
|
1273 |
!(uri.getSchemeSpecificPart().equals(""))) { |
|
1274 |
return true; |
|
1275 |
} |
|
1276 |
} |
|
1277 |
return false; |
|
1278 |
} else if (attr.getCategory() == Media.class) { |
|
1279 |
if (attr instanceof MediaSizeName) { |
|
1280 |
return isSupportedMedia((MediaSizeName)attr); |
|
1281 |
} |
|
1282 |
if (attr instanceof MediaTray) { |
|
1283 |
return isSupportedMediaTray((MediaTray)attr); |
|
1284 |
} |
|
1285 |
} else if (attr.getCategory() == PageRanges.class) { |
|
1286 |
if (flavor != null && |
|
1287 |
!(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || |
|
1288 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) { |
|
1289 |
return false; |
|
1290 |
} |
|
1291 |
} else if (attr.getCategory() == SheetCollate.class) { |
|
1292 |
if (flavor != null && |
|
1293 |
!(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || |
|
1294 |
flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) { |
|
1295 |
return false; |
|
1296 |
} |
|
1297 |
} else if (attr.getCategory() == Sides.class) { |
|
1298 |
Sides[] sidesArray = (Sides[])getSupportedAttributeValues( |
|
1299 |
Sides.class, |
|
1300 |
flavor, |
|
1301 |
attributes); |
|
1302 |
||
1303 |
if (sidesArray != null) { |
|
1304 |
for (int i=0; i<sidesArray.length; i++) { |
|
1305 |
if (sidesArray[i] == (Sides)attr) { |
|
1306 |
return true; |
|
1307 |
} |
|
1308 |
} |
|
1309 |
} |
|
1310 |
return false; |
|
1311 |
} else if (attr.getCategory() == OrientationRequested.class) { |
|
1312 |
OrientationRequested[] orientArray = |
|
1313 |
(OrientationRequested[])getSupportedAttributeValues( |
|
1314 |
OrientationRequested.class, |
|
1315 |
flavor, |
|
1316 |
attributes); |
|
1317 |
||
1318 |
if (orientArray != null) { |
|
1319 |
for (int i=0; i<orientArray.length; i++) { |
|
1320 |
if (orientArray[i] == (OrientationRequested)attr) { |
|
1321 |
return true; |
|
1322 |
} |
|
1323 |
} |
|
1324 |
} |
|
1325 |
return false; |
|
1326 |
} |
|
1327 |
return true; |
|
1328 |
} |
|
1329 |
||
1330 |
||
1331 |
public synchronized Object |
|
1332 |
getDefaultAttributeValue(Class<? extends Attribute> category) |
|
1333 |
{ |
|
1334 |
if (category == null) { |
|
1335 |
throw new NullPointerException("null category"); |
|
1336 |
} |
|
1337 |
if (!Attribute.class.isAssignableFrom(category)) { |
|
1338 |
throw new IllegalArgumentException(category + |
|
1339 |
" is not an Attribute"); |
|
1340 |
} |
|
1341 |
if (!isAttributeCategorySupported(category)) { |
|
1342 |
return null; |
|
1343 |
} |
|
1344 |
||
1345 |
initAttributes(); |
|
1346 |
||
1347 |
String catName = null; |
|
1348 |
for (int i=0; i < printReqAttribDefault.length; i++) { |
|
1349 |
PrintRequestAttribute pra = |
|
1350 |
(PrintRequestAttribute)printReqAttribDefault[i]; |
|
1351 |
if (pra.getCategory() == category) { |
|
1352 |
catName = pra.getName(); |
|
1353 |
break; |
|
1354 |
} |
|
1355 |
} |
|
1356 |
String attribName = catName+"-default"; |
|
1357 |
AttributeClass attribClass = (getAttMap != null) ? |
|
1358 |
(AttributeClass)getAttMap.get(attribName) : null; |
|
1359 |
||
1360 |
if (category == Copies.class) { |
|
1361 |
if (attribClass != null) { |
|
1362 |
return new Copies(attribClass.getIntValue()); |
|
1363 |
} else { |
|
1364 |
return new Copies(1); |
|
1365 |
} |
|
1366 |
} else if (category == Chromaticity.class) { |
|
1367 |
return Chromaticity.COLOR; |
|
1368 |
} else if (category == Destination.class) { |
|
1369 |
try { |
|
1370 |
return new Destination((new File("out.ps")).toURI()); |
|
1371 |
} catch (SecurityException se) { |
|
1372 |
try { |
|
1373 |
return new Destination(new URI("file:out.ps")); |
|
1374 |
} catch (URISyntaxException e) { |
|
1375 |
return null; |
|
1376 |
} |
|
1377 |
} |
|
1378 |
} else if (category == Fidelity.class) { |
|
1379 |
return Fidelity.FIDELITY_FALSE; |
|
1380 |
} else if (category == Finishings.class) { |
|
1381 |
return Finishings.NONE; |
|
1382 |
} else if (category == JobName.class) { |
|
1383 |
return new JobName("Java Printing", null); |
|
1384 |
} else if (category == JobSheets.class) { |
|
1385 |
if (attribClass != null && |
|
1386 |
attribClass.getStringValue().equals("none")) { |
|
1387 |
return JobSheets.NONE; |
|
1388 |
} else { |
|
1389 |
return JobSheets.STANDARD; |
|
1390 |
} |
|
1391 |
} else if (category == Media.class) { |
|
1392 |
defaultMediaIndex = 0; |
|
1393 |
if (mediaSizeNames.length == 0) { |
|
1394 |
String defaultCountry = Locale.getDefault().getCountry(); |
|
1395 |
if (defaultCountry != null && |
|
1396 |
(defaultCountry.equals("") || |
|
1397 |
defaultCountry.equals(Locale.US.getCountry()) || |
|
1398 |
defaultCountry.equals(Locale.CANADA.getCountry()))) { |
|
1399 |
return MediaSizeName.NA_LETTER; |
|
1400 |
} else { |
|
1401 |
return MediaSizeName.ISO_A4; |
|
1402 |
} |
|
1403 |
} |
|
1404 |
||
1405 |
if (attribClass != null) { |
|
1406 |
String name = attribClass.getStringValue(); |
|
1407 |
if (isCupsPrinter) { |
|
1408 |
for (int i=0; i< customMediaSizeNames.length; i++) { |
|
1409 |
//REMIND: get default from PPD. In native _getMedia, |
|
1410 |
// move default (ppd_option_t->defchoice) to index 0. |
|
1411 |
// In the meantime, use indexOf because PPD name |
|
1412 |
// may be different from the IPP attribute name. |
|
1413 |
if (customMediaSizeNames[i].toString().indexOf(name) |
|
1414 |
!= -1) { |
|
1415 |
defaultMediaIndex = i; |
|
1416 |
return mediaSizeNames[defaultMediaIndex]; |
|
1417 |
} |
|
1418 |
} |
|
1419 |
} else { |
|
1420 |
for (int i=0; i< mediaSizeNames.length; i++) { |
|
1421 |
if (mediaSizeNames[i].toString().indexOf(name) != -1) { |
|
1422 |
defaultMediaIndex = i; |
|
1423 |
return mediaSizeNames[defaultMediaIndex]; |
|
1424 |
} |
|
1425 |
} |
|
1426 |
} |
|
1427 |
} |
|
1428 |
return mediaSizeNames[defaultMediaIndex]; |
|
1429 |
||
1430 |
} else if (category == MediaPrintableArea.class) { |
|
1431 |
MediaPrintableArea[] mpas; |
|
1432 |
if ((cps != null) && |
|
1433 |
((mpas = cps.getMediaPrintableArea()) != null)) { |
|
1434 |
if (defaultMediaIndex == -1) { |
|
1435 |
// initializes value of defaultMediaIndex |
|
1436 |
getDefaultAttributeValue(Media.class); |
|
1437 |
} |
|
1438 |
return mpas[defaultMediaIndex]; |
|
1439 |
} else { |
|
1440 |
String defaultCountry = Locale.getDefault().getCountry(); |
|
1441 |
float iw, ih; |
|
1442 |
if (defaultCountry != null && |
|
1443 |
(defaultCountry.equals("") || |
|
1444 |
defaultCountry.equals(Locale.US.getCountry()) || |
|
1445 |
defaultCountry.equals(Locale.CANADA.getCountry()))) { |
|
1446 |
iw = MediaSize.NA.LETTER.getX(Size2DSyntax.INCH) - 0.5f; |
|
1447 |
ih = MediaSize.NA.LETTER.getY(Size2DSyntax.INCH) - 0.5f; |
|
1448 |
} else { |
|
1449 |
iw = MediaSize.ISO.A4.getX(Size2DSyntax.INCH) - 0.5f; |
|
1450 |
ih = MediaSize.ISO.A4.getY(Size2DSyntax.INCH) - 0.5f; |
|
1451 |
} |
|
1452 |
return new MediaPrintableArea(0.25f, 0.25f, iw, ih, |
|
1453 |
MediaPrintableArea.INCH); |
|
1454 |
} |
|
1455 |
} else if (category == NumberUp.class) { |
|
1456 |
return new NumberUp(1); // for CUPS this is always 1 |
|
1457 |
} else if (category == OrientationRequested.class) { |
|
1458 |
if (attribClass != null) { |
|
1459 |
switch (attribClass.getIntValue()) { |
|
1460 |
default: |
|
1461 |
case 3: return OrientationRequested.PORTRAIT; |
|
1462 |
case 4: return OrientationRequested.LANDSCAPE; |
|
1463 |
case 5: return OrientationRequested.REVERSE_LANDSCAPE; |
|
1464 |
case 6: return OrientationRequested.REVERSE_PORTRAIT; |
|
1465 |
} |
|
1466 |
} else { |
|
1467 |
return OrientationRequested.PORTRAIT; |
|
1468 |
} |
|
1469 |
} else if (category == PageRanges.class) { |
|
1470 |
if (attribClass != null) { |
|
1471 |
int[] range = attribClass.getIntRangeValue(); |
|
1472 |
return new PageRanges(range[0], range[1]); |
|
1473 |
} else { |
|
1474 |
return new PageRanges(1, Integer.MAX_VALUE); |
|
1475 |
} |
|
1476 |
} else if (category == RequestingUserName.class) { |
|
1477 |
String userName = ""; |
|
1478 |
try { |
|
1479 |
userName = System.getProperty("user.name", ""); |
|
1480 |
} catch (SecurityException se) { |
|
1481 |
} |
|
1482 |
return new RequestingUserName(userName, null); |
|
1483 |
} else if (category == SheetCollate.class) { |
|
1484 |
return SheetCollate.UNCOLLATED; |
|
1485 |
} else if (category == Sides.class) { |
|
1486 |
if (attribClass != null) { |
|
1487 |
if (attribClass.getStringValue().endsWith("long-edge")) { |
|
1488 |
return Sides.TWO_SIDED_LONG_EDGE; |
|
1489 |
} else if (attribClass.getStringValue().endsWith( |
|
1490 |
"short-edge")) { |
|
1491 |
return Sides.TWO_SIDED_SHORT_EDGE; |
|
1492 |
} |
|
1493 |
} |
|
1494 |
return Sides.ONE_SIDED; |
|
1495 |
} |
|
1496 |
||
1497 |
return null; |
|
1498 |
} |
|
1499 |
||
1500 |
public ServiceUIFactory getServiceUIFactory() { |
|
1501 |
return null; |
|
1502 |
} |
|
1503 |
||
1504 |
public void wakeNotifier() { |
|
1505 |
synchronized (this) { |
|
1506 |
if (notifier != null) { |
|
1507 |
notifier.wake(); |
|
1508 |
} |
|
1509 |
} |
|
1510 |
} |
|
1511 |
||
1512 |
public void addPrintServiceAttributeListener( |
|
1513 |
PrintServiceAttributeListener listener) { |
|
1514 |
synchronized (this) { |
|
1515 |
if (listener == null) { |
|
1516 |
return; |
|
1517 |
} |
|
1518 |
if (notifier == null) { |
|
1519 |
notifier = new ServiceNotifier(this); |
|
1520 |
} |
|
1521 |
notifier.addListener(listener); |
|
1522 |
} |
|
1523 |
} |
|
1524 |
||
1525 |
public void removePrintServiceAttributeListener( |
|
1526 |
PrintServiceAttributeListener listener) { |
|
1527 |
synchronized (this) { |
|
1528 |
if (listener == null || notifier == null ) { |
|
1529 |
return; |
|
1530 |
} |
|
1531 |
notifier.removeListener(listener); |
|
1532 |
if (notifier.isEmpty()) { |
|
1533 |
notifier.stopNotifier(); |
|
1534 |
notifier = null; |
|
1535 |
} |
|
1536 |
} |
|
1537 |
} |
|
1538 |
||
1539 |
public String getName() { |
|
1540 |
return printer; |
|
1541 |
} |
|
1542 |
||
1543 |
||
1544 |
public boolean usesClass(Class c) { |
|
1545 |
return (c == sun.print.PSPrinterJob.class); |
|
1546 |
} |
|
1547 |
||
1548 |
||
1549 |
public static HttpURLConnection getIPPConnection(URL url) { |
|
1550 |
HttpURLConnection connection; |
|
1551 |
try { |
|
1552 |
connection = (HttpURLConnection)url.openConnection(); |
|
1553 |
} catch (java.io.IOException ioe) { |
|
1554 |
return null; |
|
1555 |
} |
|
1556 |
if (!(connection instanceof HttpURLConnection)) { |
|
1557 |
return null; |
|
1558 |
} |
|
1559 |
connection.setUseCaches(false); |
|
1560 |
connection.setDefaultUseCaches(false); |
|
1561 |
connection.setDoInput(true); |
|
1562 |
connection.setDoOutput(true); |
|
1563 |
connection.setRequestProperty("Content-type", "application/ipp"); |
|
1564 |
return connection; |
|
1565 |
} |
|
1566 |
||
1567 |
||
1568 |
public synchronized boolean isPostscript() { |
|
1569 |
if (isPS == null) { |
|
1570 |
isPS = Boolean.TRUE; |
|
1571 |
if (isCupsPrinter) { |
|
1572 |
try { |
|
1573 |
urlConnection = getIPPConnection( |
|
542
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
1574 |
new URL(myURL+".ppd")); |
2 | 1575 |
|
1576 |
InputStream is = urlConnection.getInputStream(); |
|
1577 |
if (is != null) { |
|
1578 |
BufferedReader d = |
|
1579 |
new BufferedReader(new InputStreamReader(is, |
|
1580 |
Charset.forName("ISO-8859-1"))); |
|
1581 |
String lineStr; |
|
1582 |
while ((lineStr = d.readLine()) != null) { |
|
1583 |
if (lineStr.startsWith("*cupsFilter:")) { |
|
1584 |
isPS = Boolean.FALSE; |
|
1585 |
break; |
|
1586 |
} |
|
1587 |
} |
|
1588 |
} |
|
1589 |
} catch (java.io.IOException e) { |
|
542
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
1590 |
debug_println(" isPostscript, e= "+e); |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
1591 |
/* if PPD is not found, this may be a raw printer |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
1592 |
and in this case it is assumed that it is a |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
1593 |
Postscript printer */ |
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
535
diff
changeset
|
1594 |
// do nothing |
2 | 1595 |
} |
1596 |
} |
|
1597 |
} |
|
1598 |
return isPS.booleanValue(); |
|
1599 |
} |
|
1600 |
||
1601 |
||
1602 |
private void opGetAttributes() { |
|
1603 |
try { |
|
1604 |
debug_println(debugPrefix+"opGetAttributes myURI "+myURI+" myURL "+myURL); |
|
1605 |
||
1606 |
AttributeClass attClNoUri[] = { |
|
1607 |
AttributeClass.ATTRIBUTES_CHARSET, |
|
1608 |
AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE}; |
|
1609 |
||
1610 |
AttributeClass attCl[] = { |
|
1611 |
AttributeClass.ATTRIBUTES_CHARSET, |
|
1612 |
AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE, |
|
1613 |
new AttributeClass("printer-uri", |
|
1614 |
AttributeClass.TAG_URI, |
|
1615 |
""+myURI)}; |
|
1616 |
||
1617 |
OutputStream os = (OutputStream)java.security.AccessController. |
|
1618 |
doPrivileged(new java.security.PrivilegedAction() { |
|
1619 |
public Object run() { |
|
1620 |
try { |
|
1621 |
return urlConnection.getOutputStream(); |
|
1622 |
} catch (Exception e) { |
|
1623 |
} |
|
1624 |
return null; |
|
1625 |
} |
|
1626 |
}); |
|
1627 |
||
1628 |
if (os == null) { |
|
1629 |
return; |
|
1630 |
} |
|
1631 |
||
1632 |
boolean success = (myURI == null) ? |
|
1633 |
writeIPPRequest(os, OP_GET_ATTRIBUTES, attClNoUri) : |
|
1634 |
writeIPPRequest(os, OP_GET_ATTRIBUTES, attCl); |
|
1635 |
if (success) { |
|
1636 |
InputStream is = null; |
|
1637 |
if ((is = urlConnection.getInputStream())!=null) { |
|
1638 |
HashMap[] responseMap = readIPPResponse(is); |
|
1639 |
||
1640 |
if (responseMap != null && responseMap.length > 0) { |
|
1641 |
getAttMap = responseMap[0]; |
|
1642 |
} |
|
1643 |
} else { |
|
1644 |
debug_println(debugPrefix+"opGetAttributes - null input stream"); |
|
1645 |
} |
|
1646 |
is.close(); |
|
1647 |
} |
|
1648 |
os.close(); |
|
1649 |
} catch (java.io.IOException e) { |
|
1650 |
debug_println(debugPrefix+"opGetAttributes - input/output stream: "+e); |
|
1651 |
} |
|
1652 |
} |
|
1653 |
||
1654 |
||
1655 |
public static boolean writeIPPRequest(OutputStream os, |
|
1656 |
String operCode, |
|
1657 |
AttributeClass[] attCl) { |
|
535
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1658 |
OutputStreamWriter osw; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1659 |
try { |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1660 |
osw = new OutputStreamWriter(os, "UTF-8"); |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1661 |
} catch (java.io.UnsupportedEncodingException exc) { |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1662 |
debug_println("UTF-8 not supported? Exception: "+exc); |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1663 |
return false; |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1664 |
} |
2 | 1665 |
char[] opCode = new char[2]; |
1666 |
opCode[0] = (char)Byte.parseByte(operCode.substring(0,2), 16); |
|
1667 |
opCode[1] = (char)Byte.parseByte(operCode.substring(2,4), 16); |
|
1668 |
char[] bytes = {0x01, 0x01, 0x00, 0x01}; |
|
1669 |
try { |
|
1670 |
osw.write(bytes, 0, 2); // version number |
|
1671 |
osw.write(opCode, 0, 2); // operation code |
|
1672 |
bytes[0] = 0x00; bytes[1] = 0x00; |
|
1673 |
osw.write(bytes, 0, 4); // request ID #1 |
|
1674 |
||
1675 |
bytes[0] = 0x01; // operation-group-tag |
|
1676 |
osw.write(bytes[0]); |
|
1677 |
||
1678 |
String valStr; |
|
1679 |
char[] lenStr; |
|
1680 |
||
1681 |
AttributeClass ac; |
|
1682 |
for (int i=0; i < attCl.length; i++) { |
|
1683 |
ac = attCl[i]; |
|
1684 |
osw.write(ac.getType()); // value tag |
|
1685 |
||
1686 |
lenStr = ac.getLenChars(); |
|
1687 |
osw.write(lenStr, 0, 2); // length |
|
1688 |
osw.write(""+ac, 0, ac.getName().length()); |
|
1689 |
||
1690 |
// check if string range (0x35 -> 0x49) |
|
1691 |
if (ac.getType() >= AttributeClass.TAG_TEXT_LANGUAGE && |
|
1692 |
ac.getType() <= AttributeClass.TAG_MIME_MEDIATYPE){ |
|
1693 |
valStr = (String)ac.getObjectValue(); |
|
1694 |
bytes[0] = 0; bytes[1] = (char)valStr.length(); |
|
1695 |
osw.write(bytes, 0, 2); |
|
1696 |
osw.write(valStr, 0, valStr.length()); |
|
1697 |
} // REMIND: need to support other value tags but for CUPS |
|
1698 |
// string is all we need. |
|
1699 |
} |
|
1700 |
||
1701 |
osw.write(GRPTAG_END_ATTRIBUTES); |
|
1702 |
osw.flush(); |
|
1703 |
osw.close(); |
|
1704 |
} catch (java.io.IOException ioe) { |
|
1705 |
debug_println(debugPrefix+"IPPPrintService Exception in writeIPPRequest: "+ioe); |
|
1706 |
return false; |
|
1707 |
} |
|
1708 |
return true; |
|
1709 |
} |
|
1710 |
||
1711 |
||
1712 |
public static HashMap[] readIPPResponse(InputStream inputStream) { |
|
1713 |
||
1714 |
if (inputStream == null) { |
|
1715 |
return null; |
|
1716 |
} |
|
1717 |
||
1718 |
byte response[] = new byte[MAX_ATTRIBUTE_LENGTH]; |
|
1719 |
try { |
|
1720 |
||
1721 |
DataInputStream ois = new DataInputStream(inputStream); |
|
1722 |
||
1723 |
// read status and ID |
|
1724 |
if ((ois.read(response, 0, 8) > -1) && |
|
1725 |
(response[2] == STATUSCODE_SUCCESS)) { |
|
1726 |
||
1727 |
ByteArrayOutputStream outObj; |
|
1728 |
int counter=0; |
|
1729 |
short len = 0; |
|
1730 |
String attribStr = null; |
|
1731 |
// assign default value |
|
1732 |
byte valTagByte = AttributeClass.TAG_KEYWORD; |
|
1733 |
ArrayList respList = new ArrayList(); |
|
1734 |
HashMap responseMap = new HashMap(); |
|
1735 |
||
1736 |
response[0] = ois.readByte(); |
|
1737 |
||
1738 |
// check for group tags |
|
1739 |
while ((response[0] >= GRPTAG_OP_ATTRIBUTES) && |
|
1740 |
(response[0] <= GRPTAG_PRINTER_ATTRIBUTES) |
|
1741 |
&& (response[0] != GRPTAG_END_ATTRIBUTES)) { |
|
1742 |
debug_println(debugPrefix+"checking group tag, response[0]= "+ |
|
1743 |
response[0]); |
|
1744 |
||
1745 |
outObj = new ByteArrayOutputStream(); |
|
1746 |
//make sure counter and attribStr are re-initialized |
|
1747 |
counter = 0; |
|
1748 |
attribStr = null; |
|
1749 |
||
1750 |
// read value tag |
|
1751 |
response[0] = ois.readByte(); |
|
535
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1752 |
while (response[0] >= AttributeClass.TAG_UNSUPPORTED_VALUE && |
2 | 1753 |
response[0] <= AttributeClass.TAG_MEMBER_ATTRNAME) { |
1754 |
// read name length |
|
1755 |
len = ois.readShort(); |
|
1756 |
||
1757 |
// If current value is not part of previous attribute |
|
1758 |
// then close stream and add it to HashMap. |
|
1759 |
// It is part of previous attribute if name length=0. |
|
1760 |
if ((len != 0) && (attribStr != null)) { |
|
1761 |
//last byte is the total # of values |
|
1762 |
outObj.write(counter); |
|
1763 |
outObj.flush(); |
|
1764 |
outObj.close(); |
|
1765 |
byte outArray[] = outObj.toByteArray(); |
|
1766 |
||
1767 |
// if key exists, new HashMap |
|
1768 |
if (responseMap.containsKey(attribStr)) { |
|
1769 |
respList.add(responseMap); |
|
1770 |
responseMap = new HashMap(); |
|
1771 |
} |
|
1772 |
||
535
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1773 |
// exclude those that are unknown |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1774 |
if (valTagByte >= AttributeClass.TAG_INT) { |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1775 |
AttributeClass ac = |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1776 |
new AttributeClass(attribStr, |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1777 |
valTagByte, |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1778 |
outArray); |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1779 |
|
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1780 |
responseMap.put(ac.getName(), ac); |
e6b909c9e627
6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents:
2
diff
changeset
|
1781 |
} |
2 | 1782 |
|
1783 |
outObj = new ByteArrayOutputStream(); |
|
1784 |
counter = 0; //reset counter |
|
1785 |
} |
|
1786 |
//check if this is new value tag |
|
1787 |
if (counter == 0) { |
|
1788 |
valTagByte = response[0]; |
|
1789 |
} |
|
1790 |
// read attribute name |
|
1791 |
if (len != 0) { |
|
1792 |
// read "len" characters |
|
1793 |
// make sure it doesn't exceed the maximum |
|
1794 |
if (len > MAX_ATTRIBUTE_LENGTH) { |
|
1795 |
response = new byte[len]; // expand as needed |
|
1796 |
} |
|
1797 |
ois.read(response, 0, len); |
|
1798 |
attribStr = new String(response, 0, len); |
|
1799 |
} |
|
1800 |
// read value length |
|
1801 |
len = ois.readShort(); |
|
1802 |
// write name length |
|
1803 |
outObj.write(len); |
|
1804 |
// read value, make sure it doesn't exceed the maximum |
|
1805 |
if (len > MAX_ATTRIBUTE_LENGTH) { |
|
1806 |
response = new byte[len]; // expand as needed |
|
1807 |
} |
|
1808 |
ois.read(response, 0, len); |
|
1809 |
// write value of "len" length |
|
1810 |
outObj.write(response, 0, len); |
|
1811 |
counter++; |
|
1812 |
// read next byte |
|
1813 |
response[0] = ois.readByte(); |
|
1814 |
} |
|
1815 |
||
1816 |
if (attribStr != null) { |
|
1817 |
outObj.write(counter); |
|
1818 |
outObj.flush(); |
|
1819 |
outObj.close(); |
|
1820 |
||
1821 |
// if key exists in old HashMap, new HashMap |
|
1822 |
if ((counter != 0) && |
|
1823 |
responseMap.containsKey(attribStr)) { |
|
1824 |
respList.add(responseMap); |
|
1825 |
responseMap = new HashMap(); |
|
1826 |
} |
|
1827 |
||
1828 |
byte outArray[] = outObj.toByteArray(); |
|
1829 |
||
1830 |
AttributeClass ac = |
|
1831 |
new AttributeClass(attribStr, |
|
1832 |
valTagByte, |
|
1833 |
outArray); |
|
1834 |
responseMap.put(ac.getName(), ac); |
|
1835 |
} |
|
1836 |
} |
|
1837 |
ois.close(); |
|
1838 |
if ((responseMap != null) && (responseMap.size() > 0)) { |
|
1839 |
respList.add(responseMap); |
|
1840 |
} |
|
1841 |
return (HashMap[])respList.toArray( |
|
1842 |
new HashMap[respList.size()]); |
|
1843 |
} else { |
|
1844 |
debug_println(debugPrefix+ |
|
1845 |
"readIPPResponse client error, IPP status code-" |
|
1846 |
+Integer.toHexString(response[2])+" & " |
|
1847 |
+Integer.toHexString(response[3])); |
|
1848 |
return null; |
|
1849 |
} |
|
1850 |
||
1851 |
} catch (java.io.IOException e) { |
|
1852 |
debug_println(debugPrefix+"readIPPResponse: "+e); |
|
1853 |
return null; |
|
1854 |
} |
|
1855 |
} |
|
1856 |
||
1857 |
||
1858 |
public String toString() { |
|
1859 |
return "IPP Printer : " + getName(); |
|
1860 |
} |
|
1861 |
||
1862 |
public boolean equals(Object obj) { |
|
1863 |
return (obj == this || |
|
1864 |
(obj instanceof IPPPrintService && |
|
1865 |
((IPPPrintService)obj).getName().equals(getName()))); |
|
1866 |
} |
|
1722
b676952a5943
6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
1721
diff
changeset
|
1867 |
|
b676952a5943
6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
1721
diff
changeset
|
1868 |
public int hashCode() { |
b676952a5943
6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
1721
diff
changeset
|
1869 |
return this.getClass().hashCode()+getName().hashCode(); |
b676952a5943
6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
1721
diff
changeset
|
1870 |
} |
2 | 1871 |
} |