8016343: [macosx] Print job goes to default printer regardless of chosen printer
authorjgodinez
Fri, 26 Jul 2013 15:25:12 -0700
changeset 19013 7854d8c8ec5a
parent 19012 c8e01130fe04
child 19015 499b6055bfe6
8016343: [macosx] Print job goes to default printer regardless of chosen printer Reviewed-by: jchen, prr
jdk/src/share/classes/sun/print/PSPrinterJob.java
jdk/src/solaris/classes/sun/print/IPPPrintService.java
jdk/src/solaris/classes/sun/print/UnixPrintJob.java
jdk/test/javax/print/DialogMargins.java
--- a/jdk/src/share/classes/sun/print/PSPrinterJob.java	Fri Jul 26 15:08:49 2013 -0700
+++ b/jdk/src/share/classes/sun/print/PSPrinterJob.java	Fri Jul 26 15:25:12 2013 -0700
@@ -59,6 +59,8 @@
 import javax.print.StreamPrintService;
 import javax.print.attribute.HashPrintRequestAttributeSet;
 import javax.print.attribute.PrintRequestAttributeSet;
+import javax.print.attribute.PrintServiceAttributeSet;
+import javax.print.attribute.standard.PrinterName;
 import javax.print.attribute.standard.Chromaticity;
 import javax.print.attribute.standard.Copies;
 import javax.print.attribute.standard.Destination;
@@ -471,6 +473,9 @@
                 PrintService pServ = getPrintService();
                 if (pServ != null) {
                     mDestination = pServ.getName();
+                    if (UnixPrintServiceLookup.isMac()) {
+                        mDestination = ((IPPPrintService)pServ).getDest();
+                    }
                 }
             }
         }
@@ -766,8 +771,12 @@
             }
         }
         if (mDestType == RasterPrinterJob.PRINTER) {
-            if (getPrintService() != null) {
-                mDestination = getPrintService().getName();
+            PrintService pServ = getPrintService();
+            if (pServ != null) {
+                mDestination = pServ.getName();
+                if (UnixPrintServiceLookup.isMac()) {
+                    mDestination = ((IPPPrintService)pServ).getDest();
+                }
             }
             PrinterSpooler spooler = new PrinterSpooler();
             java.security.AccessController.doPrivileged(spooler);
--- a/jdk/src/solaris/classes/sun/print/IPPPrintService.java	Fri Jul 26 15:08:49 2013 -0700
+++ b/jdk/src/solaris/classes/sun/print/IPPPrintService.java	Fri Jul 26 15:25:12 2013 -0700
@@ -1099,6 +1099,15 @@
 
         if (category == PrinterName.class) {
             return (T)(new PrinterName(printer, null));
+        } else if (category == PrinterInfo.class) {
+            PrinterInfo pInfo = new PrinterInfo(printer, null);
+            AttributeClass ac = (getAttMap != null) ?
+                (AttributeClass)getAttMap.get(pInfo.getName())
+                : null;
+            if (ac != null) {
+                return (T)(new PrinterInfo(ac.getStringValue(), null));
+            }
+            return (T)pInfo;
         } else if (category == QueuedJobCount.class) {
             QueuedJobCount qjc = new QueuedJobCount(0);
             AttributeClass ac = (getAttMap != null) ?
@@ -1566,7 +1575,24 @@
         }
     }
 
+    String getDest() {
+        return printer;
+    }
+
     public String getName() {
+        /*
+         * Mac is using printer-info IPP attribute for its human-readable printer
+         * name and is also the identifier used in NSPrintInfo:setPrinter.
+         */
+        if (UnixPrintServiceLookup.isMac()) {
+            PrintServiceAttributeSet psaSet = this.getAttributes();
+            if (psaSet != null) {
+                PrinterInfo pName = (PrinterInfo)psaSet.get(PrinterInfo.class);
+                if (pName != null) {
+                    return pName.toString();
+                }
+            }
+        }
         return printer;
     }
 
--- a/jdk/src/solaris/classes/sun/print/UnixPrintJob.java	Fri Jul 26 15:08:49 2013 -0700
+++ b/jdk/src/solaris/classes/sun/print/UnixPrintJob.java	Fri Jul 26 15:25:12 2013 -0700
@@ -65,6 +65,7 @@
 import javax.print.attribute.PrintJobAttributeSet;
 import javax.print.attribute.PrintRequestAttribute;
 import javax.print.attribute.PrintRequestAttributeSet;
+import javax.print.attribute.PrintServiceAttributeSet;
 import javax.print.attribute.standard.Copies;
 import javax.print.attribute.standard.Destination;
 import javax.print.attribute.standard.DocumentName;
@@ -76,6 +77,7 @@
 import javax.print.attribute.standard.MediaSize;
 import javax.print.attribute.standard.MediaSizeName;
 import javax.print.attribute.standard.OrientationRequested;
+import javax.print.attribute.standard.PrinterName;
 import javax.print.attribute.standard.RequestingUserName;
 import javax.print.attribute.standard.NumberUp;
 import javax.print.attribute.standard.Sides;
@@ -120,6 +122,9 @@
     UnixPrintJob(PrintService service) {
         this.service = service;
         mDestination = service.getName();
+        if (UnixPrintServiceLookup.isMac()) {
+            mDestination = ((IPPPrintService)service).getDest();
+        }
         mDestType = UnixPrintJob.DESTPRINTER;
     }
 
--- a/jdk/test/javax/print/DialogMargins.java	Fri Jul 26 15:08:49 2013 -0700
+++ b/jdk/test/javax/print/DialogMargins.java	Fri Jul 26 15:25:12 2013 -0700
@@ -25,11 +25,12 @@
 
 /**
  * @test
- * @bug 4485755 6361370 6448717 5080051 6939417
+ * @bug 4485755 6361370 6448717 5080051 6939417 8016343
  * @summary dialog doesn't have way to specify margins
  *          for 6361370, verify exception for offline printer in Windows
  *          for 6448717, faster display of print dialog
  *          for 6500903, verify status of printer if accepting jobs or not
+ *          for 8016343, verify printing to non-default printer
  * @author prr
  * @run main/manual DialogMargins
  */