changeset 12997:7ad469d89bed

7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null Reviewed-by: bae, igor
author prr
date Tue, 19 Jun 2012 09:07:31 -0700
parents 5ce6db38ea84
children 5db2c4bdf3f2 9a70fa2cc59c
files jdk/src/solaris/classes/sun/print/CUPSPrinter.java jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
diffstat 2 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/solaris/classes/sun/print/CUPSPrinter.java	Sun Jun 17 22:07:44 2012 -0700
+++ b/jdk/src/solaris/classes/sun/print/CUPSPrinter.java	Tue Jun 19 09:07:31 2012 -0700
@@ -278,14 +278,26 @@
                                          is);
                     is.close();
 
-                    if (responseMap.length > 0) {
+                    if (responseMap != null && responseMap.length > 0) {
                         defaultMap = responseMap[0];
                     }
 
                     if (defaultMap == null) {
                         os.close();
                         urlConnection.disconnect();
-                        return null;
+
+                        /* CUPS on OS X, as initially configured, considers the
+                         * default printer to be the last one used that's
+                         * presently available. So if no default was
+                         * reported, exec lpstat -d which has all the Apple
+                         * special behaviour for this built in.
+                         */
+                         if (UnixPrintServiceLookup.isMac()) {
+                             return UnixPrintServiceLookup.
+                                                   getDefaultPrinterNameSysV();
+                         } else {
+                             return null;
+                         }
                     }
 
                     AttributeClass attribClass = (AttributeClass)
--- a/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java	Sun Jun 17 22:07:44 2012 -0700
+++ b/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java	Tue Jun 19 09:07:31 2012 -0700
@@ -114,6 +114,10 @@
             new sun.security.action.GetPropertyAction("os.name"));
     }
 
+    static boolean isMac() {
+        return osname.startsWith("Mac");
+    }
+
     static boolean isSysV() {
         return osname.equals("SunOS");
     }
@@ -212,7 +216,7 @@
                 }
             }
         } else {
-            if (isSysV()) {
+            if (isMac() || isSysV()) {
                 printers = getAllPrinterNamesSysV();
             } else { //BSD
                 printers = getAllPrinterNamesBSD();
@@ -361,7 +365,7 @@
         if (name == null || name.equals("") || !checkPrinterName(name)) {
             return null;
         }
-        if (isSysV()) {
+        if (isMac() || isSysV()) {
             printer = getNamedPrinterNameSysV(name);
         } else {
             printer = getNamedPrinterNameBSD(name);
@@ -523,7 +527,7 @@
         if (CUPSPrinter.isCupsRunning()) {
             defaultPrinter = CUPSPrinter.getDefaultPrinter();
         } else {
-            if (isSysV()) {
+            if (isMac() || isSysV()) {
                 defaultPrinter = getDefaultPrinterNameSysV();
             } else {
                 defaultPrinter = getDefaultPrinterNameBSD();
@@ -644,7 +648,7 @@
         return names;
     }
 
-    private String getDefaultPrinterNameSysV() {
+    static String getDefaultPrinterNameSysV() {
         String defaultPrinter = "lp";
         String command = "/usr/bin/lpstat -d";