author | mdoerr |
Tue, 13 Feb 2018 17:38:03 +0100 | |
changeset 48965 | be873d8c0114 |
parent 47216 | 71c04702a3d5 |
child 52248 | 2e330da7cbf4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21224
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.print; |
|
27 |
||
28 |
import java.net.URL; |
|
29 |
import java.net.HttpURLConnection; |
|
30 |
import java.io.OutputStream; |
|
31 |
import java.io.InputStream; |
|
32 |
import java.util.ArrayList; |
|
33 |
import java.util.HashMap; |
|
34 |
import sun.print.IPPPrintService; |
|
35 |
import sun.print.CustomMediaSizeName; |
|
36 |
import sun.print.CustomMediaTray; |
|
37 |
import javax.print.attribute.standard.Media; |
|
38 |
import javax.print.attribute.standard.MediaSizeName; |
|
39 |
import javax.print.attribute.standard.MediaSize; |
|
40 |
import javax.print.attribute.standard.MediaTray; |
|
41 |
import javax.print.attribute.standard.MediaPrintableArea; |
|
25774
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
42 |
import javax.print.attribute.standard.PrinterResolution; |
2 | 43 |
import javax.print.attribute.Size2DSyntax; |
44 |
import javax.print.attribute.Attribute; |
|
45 |
import javax.print.attribute.EnumSyntax; |
|
46 |
import javax.print.attribute.standard.PrinterName; |
|
47 |
||
48 |
||
49 |
public class CUPSPrinter { |
|
1737
90d4fe987b09
6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents:
715
diff
changeset
|
50 |
private static final String debugPrefix = "CUPSPrinter>> "; |
2 | 51 |
private static final double PRINTER_DPI = 72.0; |
1737
90d4fe987b09
6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents:
715
diff
changeset
|
52 |
private boolean initialized; |
2 | 53 |
private static native String getCupsServer(); |
54 |
private static native int getCupsPort(); |
|
36470
d5a6c81c5254
8058316: lookupDefaultPrintService returns null on Solaris 11
psadhukhan
parents:
27282
diff
changeset
|
55 |
private static native String getCupsDefaultPrinter(); |
2 | 56 |
private static native boolean canConnect(String server, int port); |
57 |
private static native boolean initIDs(); |
|
58 |
// These functions need to be synchronized as |
|
59 |
// CUPS does not support multi-threading. |
|
60 |
private static synchronized native String[] getMedia(String printer); |
|
61 |
private static synchronized native float[] getPageSizes(String printer); |
|
25774
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
62 |
private static synchronized native void |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
63 |
getResolutions(String printer, ArrayList<Integer> resolutionList); |
2 | 64 |
//public static boolean useIPPMedia = false; will be used later |
65 |
||
66 |
private MediaPrintableArea[] cupsMediaPrintables; |
|
67 |
private MediaSizeName[] cupsMediaSNames; |
|
68 |
private CustomMediaSizeName[] cupsCustomMediaSNames; |
|
69 |
private MediaTray[] cupsMediaTrays; |
|
70 |
||
71 |
public int nPageSizes = 0; |
|
72 |
public int nTrays = 0; |
|
73 |
private String[] media; |
|
74 |
private float[] pageSizes; |
|
25774
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
75 |
int[] resolutionsArray; |
2 | 76 |
private String printer; |
77 |
||
78 |
private static boolean libFound; |
|
79 |
private static String cupsServer = null; |
|
80 |
private static int cupsPort = 0; |
|
81 |
||
82 |
static { |
|
83 |
// load awt library to access native code |
|
84 |
java.security.AccessController.doPrivileged( |
|
12559
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
5506
diff
changeset
|
85 |
new java.security.PrivilegedAction<Void>() { |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
5506
diff
changeset
|
86 |
public Void run() { |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
5506
diff
changeset
|
87 |
System.loadLibrary("awt"); |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
5506
diff
changeset
|
88 |
return null; |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
5506
diff
changeset
|
89 |
} |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
5506
diff
changeset
|
90 |
}); |
2 | 91 |
libFound = initIDs(); |
92 |
if (libFound) { |
|
93 |
cupsServer = getCupsServer(); |
|
94 |
cupsPort = getCupsPort(); |
|
95 |
} |
|
96 |
} |
|
97 |
||
98 |
||
99 |
CUPSPrinter (String printerName) { |
|
100 |
if (printerName == null) { |
|
101 |
throw new IllegalArgumentException("null printer name"); |
|
102 |
} |
|
103 |
printer = printerName; |
|
104 |
cupsMediaSNames = null; |
|
105 |
cupsMediaPrintables = null; |
|
106 |
cupsMediaTrays = null; |
|
107 |
initialized = false; |
|
108 |
||
109 |
if (!libFound) { |
|
110 |
throw new RuntimeException("cups lib not found"); |
|
111 |
} else { |
|
112 |
// get page + tray names |
|
113 |
media = getMedia(printer); |
|
114 |
if (media == null) { |
|
115 |
// either PPD file is not found or printer is unknown |
|
116 |
throw new RuntimeException("error getting PPD"); |
|
117 |
} |
|
118 |
||
119 |
// get sizes |
|
120 |
pageSizes = getPageSizes(printer); |
|
121 |
if (pageSizes != null) { |
|
122 |
nPageSizes = pageSizes.length/6; |
|
123 |
||
124 |
nTrays = media.length/2-nPageSizes; |
|
125 |
assert (nTrays >= 0); |
|
126 |
} |
|
25774
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
127 |
ArrayList<Integer> resolutionList = new ArrayList<>(); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
128 |
getResolutions(printer, resolutionList); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
129 |
resolutionsArray = new int[resolutionList.size()]; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
130 |
for (int i=0; i < resolutionList.size(); i++) { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
131 |
resolutionsArray[i] = resolutionList.get(i); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
132 |
} |
2 | 133 |
} |
134 |
} |
|
135 |
||
136 |
||
137 |
/** |
|
138 |
* Returns array of MediaSizeNames derived from PPD. |
|
139 |
*/ |
|
27082 | 140 |
MediaSizeName[] getMediaSizeNames() { |
2 | 141 |
initMedia(); |
142 |
return cupsMediaSNames; |
|
143 |
} |
|
144 |
||
145 |
||
146 |
/** |
|
147 |
* Returns array of Custom MediaSizeNames derived from PPD. |
|
148 |
*/ |
|
27082 | 149 |
CustomMediaSizeName[] getCustomMediaSizeNames() { |
2 | 150 |
initMedia(); |
151 |
return cupsCustomMediaSNames; |
|
152 |
} |
|
153 |
||
25555 | 154 |
public int getDefaultMediaIndex() { |
155 |
return ((pageSizes.length >1) ? (int)(pageSizes[pageSizes.length -1]) : 0); |
|
156 |
} |
|
2 | 157 |
|
158 |
/** |
|
159 |
* Returns array of MediaPrintableArea derived from PPD. |
|
160 |
*/ |
|
27082 | 161 |
MediaPrintableArea[] getMediaPrintableArea() { |
2 | 162 |
initMedia(); |
163 |
return cupsMediaPrintables; |
|
164 |
} |
|
165 |
||
166 |
/** |
|
167 |
* Returns array of MediaTrays derived from PPD. |
|
168 |
*/ |
|
27082 | 169 |
MediaTray[] getMediaTrays() { |
2 | 170 |
initMedia(); |
171 |
return cupsMediaTrays; |
|
172 |
} |
|
173 |
||
25774
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
174 |
/** |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
175 |
* return the raw packed array of supported printer resolutions. |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
176 |
*/ |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
177 |
int[] getRawResolutions() { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
178 |
return resolutionsArray; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
179 |
} |
2 | 180 |
|
181 |
/** |
|
182 |
* Initialize media by translating PPD info to PrintService attributes. |
|
183 |
*/ |
|
1737
90d4fe987b09
6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents:
715
diff
changeset
|
184 |
private synchronized void initMedia() { |
2 | 185 |
if (initialized) { |
186 |
return; |
|
187 |
} else { |
|
188 |
initialized = true; |
|
189 |
} |
|
190 |
||
191 |
if (pageSizes == null) { |
|
192 |
return; |
|
193 |
} |
|
194 |
||
195 |
cupsMediaPrintables = new MediaPrintableArea[nPageSizes]; |
|
196 |
cupsMediaSNames = new MediaSizeName[nPageSizes]; |
|
197 |
cupsCustomMediaSNames = new CustomMediaSizeName[nPageSizes]; |
|
198 |
||
199 |
CustomMediaSizeName msn; |
|
200 |
MediaPrintableArea mpa; |
|
201 |
float length, width, x, y, w, h; |
|
202 |
||
203 |
// initialize names and printables |
|
204 |
for (int i=0; i<nPageSizes; i++) { |
|
205 |
// media width and length |
|
206 |
width = (float)(pageSizes[i*6]/PRINTER_DPI); |
|
207 |
length = (float)(pageSizes[i*6+1]/PRINTER_DPI); |
|
208 |
// media printable area |
|
209 |
x = (float)(pageSizes[i*6+2]/PRINTER_DPI); |
|
210 |
h = (float)(pageSizes[i*6+3]/PRINTER_DPI); |
|
211 |
w = (float)(pageSizes[i*6+4]/PRINTER_DPI); |
|
212 |
y = (float)(pageSizes[i*6+5]/PRINTER_DPI); |
|
213 |
||
214 |
msn = new CustomMediaSizeName(media[i*2], media[i*2+1], |
|
215 |
width, length); |
|
216 |
||
217 |
// add to list of standard MediaSizeNames |
|
218 |
if ((cupsMediaSNames[i] = msn.getStandardMedia()) == null) { |
|
219 |
// add custom if no matching standard media |
|
220 |
cupsMediaSNames[i] = msn; |
|
221 |
||
222 |
// add this new custom msn to MediaSize array |
|
223 |
if ((width > 0.0) && (length > 0.0)) { |
|
25555 | 224 |
try { |
2 | 225 |
new MediaSize(width, length, |
226 |
Size2DSyntax.INCH, msn); |
|
25555 | 227 |
} catch (IllegalArgumentException e) { |
228 |
/* PDF printer in Linux for Ledger paper causes |
|
229 |
"IllegalArgumentException: X dimension > Y dimension". |
|
230 |
We rotate based on IPP spec. */ |
|
231 |
new MediaSize(length, width, Size2DSyntax.INCH, msn); |
|
232 |
} |
|
2 | 233 |
} |
234 |
} |
|
235 |
||
236 |
// add to list of custom MediaSizeName |
|
237 |
// for internal use of IPPPrintService |
|
238 |
cupsCustomMediaSNames[i] = msn; |
|
239 |
||
240 |
mpa = null; |
|
241 |
try { |
|
242 |
mpa = new MediaPrintableArea(x, y, w, h, |
|
243 |
MediaPrintableArea.INCH); |
|
244 |
} catch (IllegalArgumentException e) { |
|
245 |
if (width > 0 && length > 0) { |
|
246 |
mpa = new MediaPrintableArea(0, 0, width, length, |
|
247 |
MediaPrintableArea.INCH); |
|
248 |
} |
|
249 |
} |
|
250 |
cupsMediaPrintables[i] = mpa; |
|
251 |
} |
|
252 |
||
253 |
// initialize trays |
|
254 |
cupsMediaTrays = new MediaTray[nTrays]; |
|
255 |
||
256 |
MediaTray mt; |
|
257 |
for (int i=0; i<nTrays; i++) { |
|
258 |
mt = new CustomMediaTray(media[(nPageSizes+i)*2], |
|
259 |
media[(nPageSizes+i)*2+1]); |
|
260 |
cupsMediaTrays[i] = mt; |
|
261 |
} |
|
262 |
||
263 |
} |
|
264 |
||
265 |
/** |
|
266 |
* Get CUPS default printer using IPP. |
|
21224
58a31574ac84
8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents:
14342
diff
changeset
|
267 |
* Returns 2 values - index 0 is printer name, index 1 is the uri. |
2 | 268 |
*/ |
21224
58a31574ac84
8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents:
14342
diff
changeset
|
269 |
static String[] getDefaultPrinter() { |
36470
d5a6c81c5254
8058316: lookupDefaultPrintService returns null on Solaris 11
psadhukhan
parents:
27282
diff
changeset
|
270 |
// Try to get user/lpoptions-defined printer name from CUPS |
d5a6c81c5254
8058316: lookupDefaultPrintService returns null on Solaris 11
psadhukhan
parents:
27282
diff
changeset
|
271 |
// if not user-set, then go for server default destination |
d5a6c81c5254
8058316: lookupDefaultPrintService returns null on Solaris 11
psadhukhan
parents:
27282
diff
changeset
|
272 |
String printerInfo[] = new String[2]; |
d5a6c81c5254
8058316: lookupDefaultPrintService returns null on Solaris 11
psadhukhan
parents:
27282
diff
changeset
|
273 |
printerInfo[0] = getCupsDefaultPrinter(); |
d5a6c81c5254
8058316: lookupDefaultPrintService returns null on Solaris 11
psadhukhan
parents:
27282
diff
changeset
|
274 |
|
d5a6c81c5254
8058316: lookupDefaultPrintService returns null on Solaris 11
psadhukhan
parents:
27282
diff
changeset
|
275 |
if (printerInfo[0] != null) { |
d5a6c81c5254
8058316: lookupDefaultPrintService returns null on Solaris 11
psadhukhan
parents:
27282
diff
changeset
|
276 |
printerInfo[1] = null; |
d5a6c81c5254
8058316: lookupDefaultPrintService returns null on Solaris 11
psadhukhan
parents:
27282
diff
changeset
|
277 |
return printerInfo.clone(); |
d5a6c81c5254
8058316: lookupDefaultPrintService returns null on Solaris 11
psadhukhan
parents:
27282
diff
changeset
|
278 |
} |
2 | 279 |
try { |
280 |
URL url = new URL("http", getServer(), getPort(), ""); |
|
281 |
final HttpURLConnection urlConnection = |
|
282 |
IPPPrintService.getIPPConnection(url); |
|
283 |
||
284 |
if (urlConnection != null) { |
|
25140
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
285 |
OutputStream os = java.security.AccessController. |
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
286 |
doPrivileged(new java.security.PrivilegedAction<OutputStream>() { |
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
287 |
public OutputStream run() { |
2 | 288 |
try { |
289 |
return urlConnection.getOutputStream(); |
|
290 |
} catch (Exception e) { |
|
23287
c0f8cdafef56
8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
22584
diff
changeset
|
291 |
IPPPrintService.debug_println(debugPrefix+e); |
2 | 292 |
} |
293 |
return null; |
|
294 |
} |
|
295 |
}); |
|
296 |
||
297 |
if (os == null) { |
|
298 |
return null; |
|
299 |
} |
|
300 |
||
301 |
AttributeClass attCl[] = { |
|
302 |
AttributeClass.ATTRIBUTES_CHARSET, |
|
303 |
AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE, |
|
304 |
new AttributeClass("requested-attributes", |
|
21224
58a31574ac84
8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents:
14342
diff
changeset
|
305 |
AttributeClass.TAG_URI, |
58a31574ac84
8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents:
14342
diff
changeset
|
306 |
"printer-uri") |
2 | 307 |
}; |
308 |
||
309 |
if (IPPPrintService.writeIPPRequest(os, |
|
310 |
IPPPrintService.OP_CUPS_GET_DEFAULT, |
|
311 |
attCl)) { |
|
312 |
||
25140
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
313 |
HashMap<String, AttributeClass> defaultMap = null; |
36470
d5a6c81c5254
8058316: lookupDefaultPrintService returns null on Solaris 11
psadhukhan
parents:
27282
diff
changeset
|
314 |
|
2 | 315 |
InputStream is = urlConnection.getInputStream(); |
25140
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
316 |
HashMap<String, AttributeClass>[] responseMap = IPPPrintService.readIPPResponse( |
2 | 317 |
is); |
318 |
is.close(); |
|
319 |
||
12997
7ad469d89bed
7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents:
12559
diff
changeset
|
320 |
if (responseMap != null && responseMap.length > 0) { |
2 | 321 |
defaultMap = responseMap[0]; |
23287
c0f8cdafef56
8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
22584
diff
changeset
|
322 |
} else { |
c0f8cdafef56
8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
22584
diff
changeset
|
323 |
IPPPrintService.debug_println(debugPrefix+ |
c0f8cdafef56
8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
22584
diff
changeset
|
324 |
" empty response map for GET_DEFAULT."); |
2 | 325 |
} |
326 |
||
327 |
if (defaultMap == null) { |
|
328 |
os.close(); |
|
329 |
urlConnection.disconnect(); |
|
12997
7ad469d89bed
7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents:
12559
diff
changeset
|
330 |
|
7ad469d89bed
7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents:
12559
diff
changeset
|
331 |
/* CUPS on OS X, as initially configured, considers the |
7ad469d89bed
7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents:
12559
diff
changeset
|
332 |
* default printer to be the last one used that's |
7ad469d89bed
7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents:
12559
diff
changeset
|
333 |
* presently available. So if no default was |
7ad469d89bed
7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents:
12559
diff
changeset
|
334 |
* reported, exec lpstat -d which has all the Apple |
7ad469d89bed
7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents:
12559
diff
changeset
|
335 |
* special behaviour for this built in. |
7ad469d89bed
7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents:
12559
diff
changeset
|
336 |
*/ |
27269
1ef2879dc7ad
8055705: Rename UnixPrintServiceLookup and Win32PrintServiceLookup as a platform neutral class name
prr
parents:
25859
diff
changeset
|
337 |
if (PrintServiceLookupProvider.isMac()) { |
1ef2879dc7ad
8055705: Rename UnixPrintServiceLookup and Win32PrintServiceLookup as a platform neutral class name
prr
parents:
25859
diff
changeset
|
338 |
printerInfo[0] = PrintServiceLookupProvider. |
12997
7ad469d89bed
7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents:
12559
diff
changeset
|
339 |
getDefaultPrinterNameSysV(); |
21224
58a31574ac84
8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents:
14342
diff
changeset
|
340 |
printerInfo[1] = null; |
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21224
diff
changeset
|
341 |
return printerInfo.clone(); |
12997
7ad469d89bed
7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents:
12559
diff
changeset
|
342 |
} else { |
7ad469d89bed
7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents:
12559
diff
changeset
|
343 |
return null; |
7ad469d89bed
7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents:
12559
diff
changeset
|
344 |
} |
2 | 345 |
} |
346 |
||
21224
58a31574ac84
8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents:
14342
diff
changeset
|
347 |
|
25140
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
348 |
AttributeClass attribClass = defaultMap.get("printer-name"); |
2 | 349 |
|
350 |
if (attribClass != null) { |
|
21224
58a31574ac84
8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents:
14342
diff
changeset
|
351 |
printerInfo[0] = attribClass.getStringValue(); |
25140
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
352 |
attribClass = defaultMap.get("printer-uri-supported"); |
23287
c0f8cdafef56
8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
22584
diff
changeset
|
353 |
IPPPrintService.debug_println(debugPrefix+ |
c0f8cdafef56
8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents:
22584
diff
changeset
|
354 |
"printer-uri-supported="+attribClass); |
21224
58a31574ac84
8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents:
14342
diff
changeset
|
355 |
if (attribClass != null) { |
58a31574ac84
8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents:
14342
diff
changeset
|
356 |
printerInfo[1] = attribClass.getStringValue(); |
58a31574ac84
8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents:
14342
diff
changeset
|
357 |
} else { |
58a31574ac84
8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents:
14342
diff
changeset
|
358 |
printerInfo[1] = null; |
58a31574ac84
8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents:
14342
diff
changeset
|
359 |
} |
2 | 360 |
os.close(); |
361 |
urlConnection.disconnect(); |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21224
diff
changeset
|
362 |
return printerInfo.clone(); |
2 | 363 |
} |
364 |
} |
|
365 |
os.close(); |
|
366 |
urlConnection.disconnect(); |
|
367 |
} |
|
368 |
} catch (Exception e) { |
|
369 |
} |
|
370 |
return null; |
|
371 |
} |
|
372 |
||
373 |
||
374 |
/** |
|
375 |
* Get list of all CUPS printers using IPP. |
|
376 |
*/ |
|
21224
58a31574ac84
8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents:
14342
diff
changeset
|
377 |
static String[] getAllPrinters() { |
2 | 378 |
try { |
379 |
URL url = new URL("http", getServer(), getPort(), ""); |
|
380 |
||
381 |
final HttpURLConnection urlConnection = |
|
382 |
IPPPrintService.getIPPConnection(url); |
|
383 |
||
384 |
if (urlConnection != null) { |
|
25140
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
385 |
OutputStream os = java.security.AccessController. |
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
386 |
doPrivileged(new java.security.PrivilegedAction<OutputStream>() { |
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
387 |
public OutputStream run() { |
2 | 388 |
try { |
389 |
return urlConnection.getOutputStream(); |
|
390 |
} catch (Exception e) { |
|
391 |
} |
|
392 |
return null; |
|
393 |
} |
|
394 |
}); |
|
395 |
||
396 |
if (os == null) { |
|
397 |
return null; |
|
398 |
} |
|
399 |
||
400 |
AttributeClass attCl[] = { |
|
401 |
AttributeClass.ATTRIBUTES_CHARSET, |
|
402 |
AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE, |
|
403 |
new AttributeClass("requested-attributes", |
|
404 |
AttributeClass.TAG_KEYWORD, |
|
542
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
2
diff
changeset
|
405 |
"printer-uri-supported") |
2 | 406 |
}; |
407 |
||
408 |
if (IPPPrintService.writeIPPRequest(os, |
|
409 |
IPPPrintService.OP_CUPS_GET_PRINTERS, attCl)) { |
|
410 |
||
411 |
InputStream is = urlConnection.getInputStream(); |
|
25140
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
412 |
HashMap<String, AttributeClass>[] responseMap = |
2 | 413 |
IPPPrintService.readIPPResponse(is); |
414 |
||
415 |
is.close(); |
|
416 |
os.close(); |
|
417 |
urlConnection.disconnect(); |
|
418 |
||
419 |
if (responseMap == null || responseMap.length == 0) { |
|
420 |
return null; |
|
421 |
} |
|
422 |
||
25140
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
423 |
ArrayList<String> printerNames = new ArrayList<>(); |
2 | 424 |
for (int i=0; i< responseMap.length; i++) { |
25140
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
425 |
AttributeClass attribClass = |
542
eb75700cdf75
6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents:
2
diff
changeset
|
426 |
responseMap[i].get("printer-uri-supported"); |
2 | 427 |
|
428 |
if (attribClass != null) { |
|
429 |
String nameStr = attribClass.getStringValue(); |
|
430 |
printerNames.add(nameStr); |
|
431 |
} |
|
432 |
} |
|
25140
80e863984492
8042870: Fix raw and unchecked warnings in sun.print
darcy
parents:
23287
diff
changeset
|
433 |
return printerNames.toArray(new String[] {}); |
2 | 434 |
} else { |
435 |
os.close(); |
|
436 |
urlConnection.disconnect(); |
|
437 |
} |
|
438 |
} |
|
439 |
||
440 |
} catch (Exception e) { |
|
441 |
} |
|
442 |
return null; |
|
443 |
||
444 |
} |
|
445 |
||
446 |
/** |
|
447 |
* Returns CUPS server name. |
|
448 |
*/ |
|
449 |
public static String getServer() { |
|
450 |
return cupsServer; |
|
451 |
} |
|
452 |
||
453 |
/** |
|
454 |
* Returns CUPS port number. |
|
455 |
*/ |
|
456 |
public static int getPort() { |
|
457 |
return cupsPort; |
|
458 |
} |
|
459 |
||
460 |
/** |
|
461 |
* Detects if CUPS is running. |
|
462 |
*/ |
|
463 |
public static boolean isCupsRunning() { |
|
1737
90d4fe987b09
6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents:
715
diff
changeset
|
464 |
IPPPrintService.debug_println(debugPrefix+"libFound "+libFound); |
2 | 465 |
if (libFound) { |
1737
90d4fe987b09
6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents:
715
diff
changeset
|
466 |
IPPPrintService.debug_println(debugPrefix+"CUPS server "+getServer()+ |
2 | 467 |
" port "+getPort()); |
468 |
return canConnect(getServer(), getPort()); |
|
469 |
} else { |
|
470 |
return false; |
|
471 |
} |
|
472 |
} |
|
473 |
||
474 |
||
475 |
} |