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