src/solaris/classes/sun/print/UnixPrintServiceLookup.java
Print this page
rev 8972 : 8031134: PPC64: implement printing on AIX
*** 76,85 ****
--- 76,98 ----
private static int minRefreshTime = DEFAULT_MINREFRESH;
static String osname;
+ // List of commands used to deal with the printer queues on AIX
+ String[] lpNameComAix = {
+ "/usr/bin/lsallq",
+ "/usr/bin/lpstat -W -p|/usr/bin/expand|/usr/bin/cut -f1 -d' '",
+ "/usr/bin/lpstat -W -d|/usr/bin/expand|/usr/bin/cut -f1 -d' '",
+ "/usr/bin/lpstat -W -v"
+ };
+ private static final int aix_lsallq = 0;
+ private static final int aix_lpstat_p = 1;
+ private static final int aix_lpstat_d = 2;
+ private static final int aix_lpstat_v = 3;
+ private static int aix_defaultPrinterEnumeration = aix_lsallq;
+
static {
/* The system property "sun.java2d.print.polling"
* can be used to force the printing code to poll or not poll
* for PrintServices.
*/
*** 112,121 ****
--- 125,152 ----
}
}
osname = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("os.name"));
+
+ /* The system property "sun.java2d.print.aix.lpstat"
+ * can be used to force the usage of 'lpstat -p' to enumerate all
+ * printer queues. By default we use 'lsallq', because 'lpstat -p' can
+ * take lots of time if thousands of printers are attached to a server.
+ */
+ if (osname.equals("AIX")) {
+ String aixPrinterEnumerator = java.security.AccessController.doPrivileged(
+ new sun.security.action.GetPropertyAction("sun.java2d.print.aix.lpstat"));
+
+ if (aixPrinterEnumerator != null) {
+ if (aixPrinterEnumerator.equalsIgnoreCase("lpstat")) {
+ aix_defaultPrinterEnumeration = aix_lpstat_p;
+ } else if (aixPrinterEnumerator.equalsIgnoreCase("lsallq")) {
+ aix_defaultPrinterEnumeration = aix_lsallq;
+ }
+ }
+ }
}
static boolean isMac() {
return osname.startsWith("Mac");
}
*** 131,140 ****
--- 162,175 ----
static boolean isBSD() {
return (osname.equals("Linux") ||
osname.contains("OS X"));
}
+ static boolean isAIX( ) {
+ return osname.equals("AIX");
+ }
+
static final int UNINITIALIZED = -1;
static final int BSD_LPD = 0;
static final int BSD_LPD_NG = 1;
static int cmdIndex = UNINITIALIZED;
*** 249,258 ****
--- 284,295 ----
}
}
} else {
if (isMac() || isSysV()) {
printers = getAllPrinterNamesSysV();
+ } else if (isAIX()) {
+ printers = getAllPrinterNamesAIX();
} else { //BSD
printers = getAllPrinterNamesBSD();
}
}
*** 433,442 ****
--- 470,481 ----
}
/* fallback if nothing not having a printer at this point */
PrintService printer = null;
if (isMac() || isSysV()) {
printer = getNamedPrinterNameSysV(name);
+ } else if (isAIX()) {
+ printer = getNamedPrinterNameAIX(name);
} else {
printer = getNamedPrinterNameBSD(name);
}
return printer;
}
*** 598,607 ****
--- 637,648 ----
defaultPrinter = printerInfo[0];
psuri = printerInfo[1];
} else {
if (isMac() || isSysV()) {
defaultPrinter = getDefaultPrinterNameSysV();
+ } else if (isAIX()) {
+ defaultPrinter = getDefaultPrinterNameAIX();
} else {
defaultPrinter = getDefaultPrinterNameBSD();
}
}
if (defaultPrinter == null) {
*** 772,786 ****
}
}
return (String[])printerNames.toArray(new String[printerNames.size()]);
}
static String[] execCmd(final String command) {
ArrayList results = null;
try {
final String[] cmd = new String[3];
! if (isSysV()) {
cmd[0] = "/usr/bin/sh";
cmd[1] = "-c";
cmd[2] = "env LC_ALL=C " + command;
} else {
cmd[0] = "/bin/sh";
--- 813,868 ----
}
}
return (String[])printerNames.toArray(new String[printerNames.size()]);
}
+ private String getDefaultPrinterNameAIX() {
+ String defaultPrinter = "lp";
+ String[] names = execCmd(lpNameComAix[aix_lpstat_d]);
+ // Remove headers and bogus entries added by remote printers.
+ names = UnixPrintService.filterPrinterNamesAIX(names);
+ if (names == null || names.length == 0) {
+ return defaultPrinter;
+ } else if (names.length != 1) {
+ // No default printer found
+ return null;
+ } else {
+ return names[0];
+ }
+ }
+
+ private PrintService getNamedPrinterNameAIX(String name) {
+ // On AIX there should be no blank after '-v'.
+ String[] result = execCmd(lpNameComAix[aix_lpstat_v] + name);
+ // Remove headers and bogus entries added by remote printers.
+ result = UnixPrintService.filterPrinterNamesAIX(result);
+ if (result == null || result.length == 0 || result.length != 1) {
+ return null;
+ } else {
+ return new UnixPrintService(name);
+ }
+ }
+
+ private String[] getAllPrinterNamesAIX() {
+ // Determine all printers of the system.
+ String [] names = execCmd(lpNameComAix[aix_defaultPrinterEnumeration]);
+
+ // Remove headers and bogus entries added by remote printers.
+ names = UnixPrintService.filterPrinterNamesAIX(names);
+
+ ArrayList<String> printerNames = new ArrayList<String>();
+ for ( int i=0; i < names.length; i++) {
+ printerNames.add(names[i]);
+ }
+ return (String[])printerNames.toArray(new String[printerNames.size()]);
+ }
+
static String[] execCmd(final String command) {
ArrayList results = null;
try {
final String[] cmd = new String[3];
! if (isSysV() || isAIX()) {
cmd[0] = "/usr/bin/sh";
cmd[1] = "-c";
cmd[2] = "env LC_ALL=C " + command;
} else {
cmd[0] = "/bin/sh";