提交 2b93640a 编写于 作者: J jgodinez

8022241: [macosx] [PIT] lookupPrintServices() returns one too long array

Reviewed-by: prr, jchen
上级 7cceecb4
...@@ -245,7 +245,7 @@ public class UnixPrintServiceLookup extends PrintServiceLookup ...@@ -245,7 +245,7 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
continue; continue;
} }
if ((defaultPrintService != null) if ((defaultPrintService != null)
&& printers[p].equals(defaultPrintService.getName())) { && printers[p].equals(getPrinterDestName(defaultPrintService))) {
printerList.add(defaultPrintService); printerList.add(defaultPrintService);
defaultIndex = printerList.size() - 1; defaultIndex = printerList.size() - 1;
} else { } else {
...@@ -270,11 +270,12 @@ public class UnixPrintServiceLookup extends PrintServiceLookup ...@@ -270,11 +270,12 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
} else { } else {
int j; int j;
for (j=0; j<printServices.length; j++) { for (j=0; j<printServices.length; j++) {
if ((printServices[j] != null) && if (printServices[j] != null) {
(printers[p].equals(printServices[j].getName()))) { if (printers[p].equals(getPrinterDestName(printServices[j]))) {
printerList.add(printServices[j]); printerList.add(printServices[j]);
printServices[j] = null; printServices[j] = null;
break; break;
}
} }
} }
...@@ -360,6 +361,17 @@ public class UnixPrintServiceLookup extends PrintServiceLookup ...@@ -360,6 +361,17 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
return true; 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 /* On a network with many (hundreds) of network printers, it
* can save several seconds if you know all you want is a particular * can save several seconds if you know all you want is a particular
* printer, to ask for that printer rather than retrieving all printers. * printer, to ask for that printer rather than retrieving all printers.
...@@ -369,10 +381,12 @@ public class UnixPrintServiceLookup extends PrintServiceLookup ...@@ -369,10 +381,12 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
if (name == null || name.equals("") || !checkPrinterName(name)) { if (name == null || name.equals("") || !checkPrinterName(name)) {
return null; return null;
} }
/* check is all printers are already available */ /* check if all printers are already available */
if (printServices != null) { if (printServices != null) {
for (PrintService printService : printServices) { for (PrintService printService : printServices) {
if (printService.getName().equals(name)) { PrinterName printerName =
(PrinterName)printService.getAttribute(PrinterName.class);
if (printerName.getValue().equals(name)) {
return printService; return printService;
} }
} }
...@@ -567,7 +581,7 @@ public class UnixPrintServiceLookup extends PrintServiceLookup ...@@ -567,7 +581,7 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
defaultPrintService = null; defaultPrintService = null;
if (printServices != null) { if (printServices != null) {
for (int j=0; j<printServices.length; j++) { for (int j=0; j<printServices.length; j++) {
if (defaultPrinter.equals(printServices[j].getName())) { if (defaultPrinter.equals(getPrinterDestName(printServices[j]))) {
defaultPrintService = printServices[j]; defaultPrintService = printServices[j];
break; break;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册