jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
changeset 19357 7780d9ec205c
parent 18752 2a4f599c6bff
child 21278 ef8a3a2a72f2
child 21224 58a31574ac84
equal deleted inserted replaced
19356:6f8b216b81bd 19357:7780d9ec205c
   243         for (int p=0; p<printers.length; p++) {
   243         for (int p=0; p<printers.length; p++) {
   244             if (printers[p] == null) {
   244             if (printers[p] == null) {
   245                 continue;
   245                 continue;
   246             }
   246             }
   247             if ((defaultPrintService != null)
   247             if ((defaultPrintService != null)
   248                 && printers[p].equals(defaultPrintService.getName())) {
   248                 && printers[p].equals(getPrinterDestName(defaultPrintService))) {
   249                 printerList.add(defaultPrintService);
   249                 printerList.add(defaultPrintService);
   250                 defaultIndex = printerList.size() - 1;
   250                 defaultIndex = printerList.size() - 1;
   251             } else {
   251             } else {
   252                 if (printServices == null) {
   252                 if (printServices == null) {
   253                     IPPPrintService.debug_println(debugPrefix+
   253                     IPPPrintService.debug_println(debugPrefix+
   268                         printerList.add(new UnixPrintService(printers[p]));
   268                         printerList.add(new UnixPrintService(printers[p]));
   269                     }
   269                     }
   270                 } else {
   270                 } else {
   271                     int j;
   271                     int j;
   272                     for (j=0; j<printServices.length; j++) {
   272                     for (j=0; j<printServices.length; j++) {
   273                         if ((printServices[j] != null) &&
   273                         if (printServices[j] != null) {
   274                             (printers[p].equals(printServices[j].getName()))) {
   274                             if (printers[p].equals(getPrinterDestName(printServices[j]))) {
   275                             printerList.add(printServices[j]);
   275                                 printerList.add(printServices[j]);
   276                             printServices[j] = null;
   276                                 printServices[j] = null;
   277                             break;
   277                                 break;
       
   278                             }
   278                         }
   279                         }
   279                     }
   280                     }
   280 
   281 
   281                     if (j == printServices.length) {      // not found?
   282                     if (j == printServices.length) {      // not found?
   282                         if (CUPSPrinter.isCupsRunning()) {
   283                         if (CUPSPrinter.isCupsRunning()) {
   358           }
   359           }
   359         }
   360         }
   360         return true;
   361         return true;
   361       }
   362       }
   362 
   363 
       
   364     /*
       
   365      * Gets the printer name compatible with the list of printers returned by
       
   366      * the system when we query default or all the available printers.
       
   367      */
       
   368     private String getPrinterDestName(PrintService ps) {
       
   369         if (isMac()) {
       
   370             return ((IPPPrintService)ps).getDest();
       
   371         }
       
   372         return ps.getName();
       
   373     }
       
   374 
   363     /* On a network with many (hundreds) of network printers, it
   375     /* On a network with many (hundreds) of network printers, it
   364      * can save several seconds if you know all you want is a particular
   376      * can save several seconds if you know all you want is a particular
   365      * printer, to ask for that printer rather than retrieving all printers.
   377      * printer, to ask for that printer rather than retrieving all printers.
   366      */
   378      */
   367     private PrintService getServiceByName(PrinterName nameAttr) {
   379     private PrintService getServiceByName(PrinterName nameAttr) {
   368         String name = nameAttr.getValue();
   380         String name = nameAttr.getValue();
   369         if (name == null || name.equals("") || !checkPrinterName(name)) {
   381         if (name == null || name.equals("") || !checkPrinterName(name)) {
   370             return null;
   382             return null;
   371         }
   383         }
   372         /* check is all printers are already available */
   384         /* check if all printers are already available */
   373         if (printServices != null) {
   385         if (printServices != null) {
   374             for (PrintService printService : printServices) {
   386             for (PrintService printService : printServices) {
   375                 if (printService.getName().equals(name)) {
   387                 PrinterName printerName =
       
   388                     (PrinterName)printService.getAttribute(PrinterName.class);
       
   389                 if (printerName.getValue().equals(name)) {
   376                     return printService;
   390                     return printService;
   377                 }
   391                 }
   378             }
   392             }
   379         }
   393         }
   380         /* take CUPS into account first */
   394         /* take CUPS into account first */
   565             return null;
   579             return null;
   566         }
   580         }
   567         defaultPrintService = null;
   581         defaultPrintService = null;
   568         if (printServices != null) {
   582         if (printServices != null) {
   569             for (int j=0; j<printServices.length; j++) {
   583             for (int j=0; j<printServices.length; j++) {
   570                 if (defaultPrinter.equals(printServices[j].getName())) {
   584                 if (defaultPrinter.equals(getPrinterDestName(printServices[j]))) {
   571                     defaultPrintService = printServices[j];
   585                     defaultPrintService = printServices[j];
   572                     break;
   586                     break;
   573                 }
   587                 }
   574             }
   588             }
   575         }
   589         }