1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
281 is.close();
282
283 if (responseMap != null && responseMap.length > 0) {
284 defaultMap = responseMap[0];
285 }
286
287 if (defaultMap == null) {
288 os.close();
289 urlConnection.disconnect();
290
291 /* CUPS on OS X, as initially configured, considers the
292 * default printer to be the last one used that's
293 * presently available. So if no default was
294 * reported, exec lpstat -d which has all the Apple
295 * special behaviour for this built in.
296 */
297 if (UnixPrintServiceLookup.isMac()) {
298 printerInfo[0] = UnixPrintServiceLookup.
299 getDefaultPrinterNameSysV();
300 printerInfo[1] = null;
301 return (String[])printerInfo.clone();
302 } else {
303 return null;
304 }
305 }
306
307
308 AttributeClass attribClass = (AttributeClass)
309 defaultMap.get("printer-name");
310
311 if (attribClass != null) {
312 printerInfo[0] = attribClass.getStringValue();
313 attribClass = (AttributeClass)defaultMap.get("device-uri");
314 if (attribClass != null) {
315 printerInfo[1] = attribClass.getStringValue();
316 } else {
317 printerInfo[1] = null;
318 }
319 os.close();
320 urlConnection.disconnect();
321 return (String [])printerInfo.clone();
322 }
323 }
324 os.close();
325 urlConnection.disconnect();
326 }
327 } catch (Exception e) {
328 }
329 return null;
330 }
331
332
333 /**
334 * Get list of all CUPS printers using IPP.
335 */
336 static String[] getAllPrinters() {
337 try {
338 URL url = new URL("http", getServer(), getPort(), "");
339
340 final HttpURLConnection urlConnection =
341 IPPPrintService.getIPPConnection(url);
|
1 /*
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
281 is.close();
282
283 if (responseMap != null && responseMap.length > 0) {
284 defaultMap = responseMap[0];
285 }
286
287 if (defaultMap == null) {
288 os.close();
289 urlConnection.disconnect();
290
291 /* CUPS on OS X, as initially configured, considers the
292 * default printer to be the last one used that's
293 * presently available. So if no default was
294 * reported, exec lpstat -d which has all the Apple
295 * special behaviour for this built in.
296 */
297 if (UnixPrintServiceLookup.isMac()) {
298 printerInfo[0] = UnixPrintServiceLookup.
299 getDefaultPrinterNameSysV();
300 printerInfo[1] = null;
301 return printerInfo.clone();
302 } else {
303 return null;
304 }
305 }
306
307
308 AttributeClass attribClass = (AttributeClass)
309 defaultMap.get("printer-name");
310
311 if (attribClass != null) {
312 printerInfo[0] = attribClass.getStringValue();
313 attribClass = (AttributeClass)defaultMap.get("device-uri");
314 if (attribClass != null) {
315 printerInfo[1] = attribClass.getStringValue();
316 } else {
317 printerInfo[1] = null;
318 }
319 os.close();
320 urlConnection.disconnect();
321 return printerInfo.clone();
322 }
323 }
324 os.close();
325 urlConnection.disconnect();
326 }
327 } catch (Exception e) {
328 }
329 return null;
330 }
331
332
333 /**
334 * Get list of all CUPS printers using IPP.
335 */
336 static String[] getAllPrinters() {
337 try {
338 URL url = new URL("http", getServer(), getPort(), "");
339
340 final HttpURLConnection urlConnection =
341 IPPPrintService.getIPPConnection(url);
|