changeset 7833:0c950b2be7ab

8022241: [macosx] [PIT] lookupPrintServices() returns one too long array Reviewed-by: prr, jchen
author jgodinez
date Mon, 19 Aug 2013 11:21:19 -0700
parents dadd43e02a79
children 64be71ae6185 12ac08d79c9b
files src/solaris/classes/sun/print/UnixPrintServiceLookup.java
diffstat 1 files changed, 23 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/classes/sun/print/UnixPrintServiceLookup.java	Mon Aug 19 03:58:47 2013 -0700
+++ b/src/solaris/classes/sun/print/UnixPrintServiceLookup.java	Mon Aug 19 11:21:19 2013 -0700
@@ -245,7 +245,7 @@
                 continue;
             }
             if ((defaultPrintService != null)
-                && printers[p].equals(defaultPrintService.getName())) {
+                && printers[p].equals(getPrinterDestName(defaultPrintService))) {
                 printerList.add(defaultPrintService);
                 defaultIndex = printerList.size() - 1;
             } else {
@@ -270,11 +270,12 @@
                 } else {
                     int j;
                     for (j=0; j<printServices.length; j++) {
-                        if ((printServices[j] != null) &&
-                            (printers[p].equals(printServices[j].getName()))) {
-                            printerList.add(printServices[j]);
-                            printServices[j] = null;
-                            break;
+                        if (printServices[j] != null) {
+                            if (printers[p].equals(getPrinterDestName(printServices[j]))) {
+                                printerList.add(printServices[j]);
+                                printServices[j] = null;
+                                break;
+                            }
                         }
                     }
 
@@ -360,6 +361,17 @@
         return true;
       }
 
+    /*
+     * Gets the printer name compatible with the list of printers returned by
+     * the system when we query default or all the available printers.
+     */
+    private String getPrinterDestName(PrintService ps) {
+        if (isMac()) {
+            return ((IPPPrintService)ps).getDest();
+        }
+        return ps.getName();
+    }
+
     /* On a network with many (hundreds) of network printers, it
      * can save several seconds if you know all you want is a particular
      * printer, to ask for that printer rather than retrieving all printers.
@@ -369,10 +381,12 @@
         if (name == null || name.equals("") || !checkPrinterName(name)) {
             return null;
         }
-        /* check is all printers are already available */
+        /* check if all printers are already available */
         if (printServices != null) {
             for (PrintService printService : printServices) {
-                if (printService.getName().equals(name)) {
+                PrinterName printerName =
+                    (PrinterName)printService.getAttribute(PrinterName.class);
+                if (printerName.getValue().equals(name)) {
                     return printService;
                 }
             }
@@ -567,7 +581,7 @@
         defaultPrintService = null;
         if (printServices != null) {
             for (int j=0; j<printServices.length; j++) {
-                if (defaultPrinter.equals(printServices[j].getName())) {
+                if (defaultPrinter.equals(getPrinterDestName(printServices[j]))) {
                     defaultPrintService = printServices[j];
                     break;
                 }