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