提交 e906c83a 编写于 作者: P prr

7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null

Reviewed-by: bae, igor
上级 191ed6b0
......@@ -278,14 +278,26 @@ public class CUPSPrinter {
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)
......
......@@ -114,6 +114,10 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
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 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
}
}
} else {
if (isSysV()) {
if (isMac() || isSysV()) {
printers = getAllPrinterNamesSysV();
} else { //BSD
printers = getAllPrinterNamesBSD();
......@@ -361,7 +365,7 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
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 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
if (CUPSPrinter.isCupsRunning()) {
defaultPrinter = CUPSPrinter.getDefaultPrinter();
} else {
if (isSysV()) {
if (isMac() || isSysV()) {
defaultPrinter = getDefaultPrinterNameSysV();
} else {
defaultPrinter = getDefaultPrinterNameBSD();
......@@ -644,7 +648,7 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
return names;
}
private String getDefaultPrinterNameSysV() {
static String getDefaultPrinterNameSysV() {
String defaultPrinter = "lp";
String command = "/usr/bin/lpstat -d";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册