< prev index next >

src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java

Print this page
rev 59106 : imported patch client


 134          * take lots of time if thousands of printers are attached to a server.
 135          */
 136         if (isAIX()) {
 137             String aixPrinterEnumerator = java.security.AccessController.doPrivileged(
 138                 new sun.security.action.GetPropertyAction("sun.java2d.print.aix.lpstat"));
 139 
 140             if (aixPrinterEnumerator != null) {
 141                 if (aixPrinterEnumerator.equalsIgnoreCase("lpstat")) {
 142                     aix_defaultPrinterEnumeration = aix_lpstat_p;
 143                 } else if (aixPrinterEnumerator.equalsIgnoreCase("lsallq")) {
 144                     aix_defaultPrinterEnumeration = aix_lsallq;
 145                 }
 146             }
 147         }
 148     }
 149 
 150     static boolean isMac() {
 151         return osname.startsWith("Mac");
 152     }
 153 
 154     static boolean isSysV() {
 155         return osname.equals("SunOS");
 156     }
 157 
 158     static boolean isLinux() {
 159         return (osname.equals("Linux"));
 160     }
 161 
 162     static boolean isBSD() {
 163         return (osname.equals("Linux") ||
 164                 osname.contains("OS X"));
 165     }
 166 
 167     static boolean isAIX() {
 168         return osname.equals("AIX");
 169     }
 170 
 171     static final int UNINITIALIZED = -1;
 172     static final int BSD_LPD = 0;
 173     static final int BSD_LPD_NG = 1;
 174 
 175     static int cmdIndex = UNINITIALIZED;
 176 
 177     String[] lpcFirstCom = {


 284             try {
 285                 printerURIs = CUPSPrinter.getAllPrinters();
 286                 IPPPrintService.debug_println("CUPS URIs = " + printerURIs);
 287                 if (printerURIs != null) {
 288                     for (int p = 0; p < printerURIs.length; p++) {
 289                        IPPPrintService.debug_println("URI="+printerURIs[p]);
 290                     }
 291                 }
 292             } catch (Throwable t) {
 293             IPPPrintService.debug_println(debugPrefix+
 294               "Exception getting all CUPS printers : " + t);
 295             }
 296             if ((printerURIs != null) && (printerURIs.length > 0)) {
 297                 printers = new String[printerURIs.length];
 298                 for (int i=0; i<printerURIs.length; i++) {
 299                     int lastIndex = printerURIs[i].lastIndexOf("/");
 300                     printers[i] = printerURIs[i].substring(lastIndex+1);
 301                 }
 302             }
 303         } else {
 304             if (isMac() || isSysV()) {
 305                 printers = getAllPrinterNamesSysV();
 306             } else if (isAIX()) {
 307                 printers = getAllPrinterNamesAIX();
 308             } else { //BSD
 309                 printers = getAllPrinterNamesBSD();
 310             }
 311         }
 312 
 313         if (printers == null) {
 314             if (defaultPrintService != null) {
 315                 printServices = new PrintService[1];
 316                 printServices[0] = defaultPrintService;
 317             } else {
 318                 printServices = null;
 319             }
 320             return;
 321         }
 322 
 323         ArrayList<PrintService> printerList = new ArrayList<>();
 324         int defaultIndex = -1;


 468                     return printService;
 469                 }
 470             }
 471         }
 472         /* take CUPS into account first */
 473         if (CUPSPrinter.isCupsRunning()) {
 474             try {
 475                 return new IPPPrintService(name,
 476                                            new URL("http://"+
 477                                                    CUPSPrinter.getServer()+":"+
 478                                                    CUPSPrinter.getPort()+"/"+
 479                                                    name));
 480             } catch (Exception e) {
 481                 IPPPrintService.debug_println(debugPrefix+
 482                                               " getServiceByName Exception "+
 483                                               e);
 484             }
 485         }
 486         /* fallback if nothing not having a printer at this point */
 487         PrintService printer = null;
 488         if (isMac() || isSysV()) {
 489             printer = getNamedPrinterNameSysV(name);
 490         } else if (isAIX()) {
 491             printer = getNamedPrinterNameAIX(name);
 492         } else {
 493             printer = getNamedPrinterNameBSD(name);
 494         }
 495         return printer;
 496     }
 497 
 498     private PrintService[]
 499         getPrintServices(PrintServiceAttributeSet serviceSet) {
 500 
 501         if (serviceSet == null || serviceSet.isEmpty()) {
 502             return getPrintServices();
 503         }
 504 
 505         /* Typically expect that if a service attribute is specified that
 506          * its a printer name and there ought to be only one match.
 507          * Directly retrieve that service and confirm
 508          * that it meets the other requirements.


 636 
 637     public synchronized PrintService getDefaultPrintService() {
 638         SecurityManager security = System.getSecurityManager();
 639         if (security != null) {
 640           security.checkPrintJobAccess();
 641         }
 642 
 643         // clear defaultPrintService
 644         defaultPrintService = null;
 645         String psuri = null;
 646 
 647         IPPPrintService.debug_println("isRunning ? "+
 648                                       (CUPSPrinter.isCupsRunning()));
 649         if (CUPSPrinter.isCupsRunning()) {
 650             String[] printerInfo = CUPSPrinter.getDefaultPrinter();
 651             if (printerInfo != null && printerInfo.length >= 2) {
 652                 defaultPrinter = printerInfo[0];
 653                 psuri = printerInfo[1];
 654             }
 655         } else {
 656             if (isMac() || isSysV()) {
 657                 defaultPrinter = getDefaultPrinterNameSysV();
 658             } else if (isAIX()) {
 659                 defaultPrinter = getDefaultPrinterNameAIX();
 660             } else {
 661                 defaultPrinter = getDefaultPrinterNameBSD();
 662             }
 663         }
 664         if (defaultPrinter == null) {
 665             return null;
 666         }
 667         defaultPrintService = null;
 668         if (printServices != null) {
 669             for (int j=0; j<printServices.length; j++) {
 670                 if (defaultPrinter.equals(getPrinterDestName(printServices[j]))) {
 671                     defaultPrintService = printServices[j];
 672                     break;
 673                 }
 674             }
 675         }
 676         if (defaultPrintService == null) {


 855     }
 856 
 857     private String[] getAllPrinterNamesAIX() {
 858         // Determine all printers of the system.
 859         String [] names = execCmd(lpNameComAix[aix_defaultPrinterEnumeration]);
 860 
 861         // Remove headers and bogus entries added by remote printers.
 862         names = UnixPrintService.filterPrinterNamesAIX(names);
 863 
 864         ArrayList<String> printerNames = new ArrayList<String>();
 865         for ( int i=0; i < names.length; i++) {
 866             printerNames.add(names[i]);
 867         }
 868         return printerNames.toArray(new String[printerNames.size()]);
 869     }
 870 
 871     static String[] execCmd(final String command) {
 872         ArrayList<String> results = null;
 873         try {
 874             final String[] cmd = new String[3];
 875             if (isSysV() || isAIX()) {
 876                 cmd[0] = "/usr/bin/sh";
 877                 cmd[1] = "-c";
 878                 cmd[2] = "env LC_ALL=C " + command;
 879             } else {
 880                 cmd[0] = "/bin/sh";
 881                 cmd[1] = "-c";
 882                 cmd[2] = "LC_ALL=C " + command;
 883             }
 884 
 885             results = AccessController.doPrivileged(
 886                 new PrivilegedExceptionAction<ArrayList<String>>() {
 887                     public ArrayList<String> run() throws IOException {
 888 
 889                         Process proc;
 890                         BufferedReader bufferedReader = null;
 891                         File f = Files.createTempFile("prn","xc").toFile();
 892                         cmd[2] = cmd[2]+">"+f.getAbsolutePath();
 893 
 894                         proc = Runtime.getRuntime().exec(cmd);
 895                         try {




 134          * take lots of time if thousands of printers are attached to a server.
 135          */
 136         if (isAIX()) {
 137             String aixPrinterEnumerator = java.security.AccessController.doPrivileged(
 138                 new sun.security.action.GetPropertyAction("sun.java2d.print.aix.lpstat"));
 139 
 140             if (aixPrinterEnumerator != null) {
 141                 if (aixPrinterEnumerator.equalsIgnoreCase("lpstat")) {
 142                     aix_defaultPrinterEnumeration = aix_lpstat_p;
 143                 } else if (aixPrinterEnumerator.equalsIgnoreCase("lsallq")) {
 144                     aix_defaultPrinterEnumeration = aix_lsallq;
 145                 }
 146             }
 147         }
 148     }
 149 
 150     static boolean isMac() {
 151         return osname.startsWith("Mac");
 152     }
 153 




 154     static boolean isLinux() {
 155         return (osname.equals("Linux"));
 156     }
 157 
 158     static boolean isBSD() {
 159         return (osname.equals("Linux") ||
 160                 osname.contains("OS X"));
 161     }
 162 
 163     static boolean isAIX() {
 164         return osname.equals("AIX");
 165     }
 166 
 167     static final int UNINITIALIZED = -1;
 168     static final int BSD_LPD = 0;
 169     static final int BSD_LPD_NG = 1;
 170 
 171     static int cmdIndex = UNINITIALIZED;
 172 
 173     String[] lpcFirstCom = {


 280             try {
 281                 printerURIs = CUPSPrinter.getAllPrinters();
 282                 IPPPrintService.debug_println("CUPS URIs = " + printerURIs);
 283                 if (printerURIs != null) {
 284                     for (int p = 0; p < printerURIs.length; p++) {
 285                        IPPPrintService.debug_println("URI="+printerURIs[p]);
 286                     }
 287                 }
 288             } catch (Throwable t) {
 289             IPPPrintService.debug_println(debugPrefix+
 290               "Exception getting all CUPS printers : " + t);
 291             }
 292             if ((printerURIs != null) && (printerURIs.length > 0)) {
 293                 printers = new String[printerURIs.length];
 294                 for (int i=0; i<printerURIs.length; i++) {
 295                     int lastIndex = printerURIs[i].lastIndexOf("/");
 296                     printers[i] = printerURIs[i].substring(lastIndex+1);
 297                 }
 298             }
 299         } else {
 300             if (isMac()) {
 301                 printers = getAllPrinterNamesSysV();
 302             } else if (isAIX()) {
 303                 printers = getAllPrinterNamesAIX();
 304             } else { //BSD
 305                 printers = getAllPrinterNamesBSD();
 306             }
 307         }
 308 
 309         if (printers == null) {
 310             if (defaultPrintService != null) {
 311                 printServices = new PrintService[1];
 312                 printServices[0] = defaultPrintService;
 313             } else {
 314                 printServices = null;
 315             }
 316             return;
 317         }
 318 
 319         ArrayList<PrintService> printerList = new ArrayList<>();
 320         int defaultIndex = -1;


 464                     return printService;
 465                 }
 466             }
 467         }
 468         /* take CUPS into account first */
 469         if (CUPSPrinter.isCupsRunning()) {
 470             try {
 471                 return new IPPPrintService(name,
 472                                            new URL("http://"+
 473                                                    CUPSPrinter.getServer()+":"+
 474                                                    CUPSPrinter.getPort()+"/"+
 475                                                    name));
 476             } catch (Exception e) {
 477                 IPPPrintService.debug_println(debugPrefix+
 478                                               " getServiceByName Exception "+
 479                                               e);
 480             }
 481         }
 482         /* fallback if nothing not having a printer at this point */
 483         PrintService printer = null;
 484         if (isMac()) {
 485             printer = getNamedPrinterNameSysV(name);
 486         } else if (isAIX()) {
 487             printer = getNamedPrinterNameAIX(name);
 488         } else {
 489             printer = getNamedPrinterNameBSD(name);
 490         }
 491         return printer;
 492     }
 493 
 494     private PrintService[]
 495         getPrintServices(PrintServiceAttributeSet serviceSet) {
 496 
 497         if (serviceSet == null || serviceSet.isEmpty()) {
 498             return getPrintServices();
 499         }
 500 
 501         /* Typically expect that if a service attribute is specified that
 502          * its a printer name and there ought to be only one match.
 503          * Directly retrieve that service and confirm
 504          * that it meets the other requirements.


 632 
 633     public synchronized PrintService getDefaultPrintService() {
 634         SecurityManager security = System.getSecurityManager();
 635         if (security != null) {
 636           security.checkPrintJobAccess();
 637         }
 638 
 639         // clear defaultPrintService
 640         defaultPrintService = null;
 641         String psuri = null;
 642 
 643         IPPPrintService.debug_println("isRunning ? "+
 644                                       (CUPSPrinter.isCupsRunning()));
 645         if (CUPSPrinter.isCupsRunning()) {
 646             String[] printerInfo = CUPSPrinter.getDefaultPrinter();
 647             if (printerInfo != null && printerInfo.length >= 2) {
 648                 defaultPrinter = printerInfo[0];
 649                 psuri = printerInfo[1];
 650             }
 651         } else {
 652             if (isMac()) {
 653                 defaultPrinter = getDefaultPrinterNameSysV();
 654             } else if (isAIX()) {
 655                 defaultPrinter = getDefaultPrinterNameAIX();
 656             } else {
 657                 defaultPrinter = getDefaultPrinterNameBSD();
 658             }
 659         }
 660         if (defaultPrinter == null) {
 661             return null;
 662         }
 663         defaultPrintService = null;
 664         if (printServices != null) {
 665             for (int j=0; j<printServices.length; j++) {
 666                 if (defaultPrinter.equals(getPrinterDestName(printServices[j]))) {
 667                     defaultPrintService = printServices[j];
 668                     break;
 669                 }
 670             }
 671         }
 672         if (defaultPrintService == null) {


 851     }
 852 
 853     private String[] getAllPrinterNamesAIX() {
 854         // Determine all printers of the system.
 855         String [] names = execCmd(lpNameComAix[aix_defaultPrinterEnumeration]);
 856 
 857         // Remove headers and bogus entries added by remote printers.
 858         names = UnixPrintService.filterPrinterNamesAIX(names);
 859 
 860         ArrayList<String> printerNames = new ArrayList<String>();
 861         for ( int i=0; i < names.length; i++) {
 862             printerNames.add(names[i]);
 863         }
 864         return printerNames.toArray(new String[printerNames.size()]);
 865     }
 866 
 867     static String[] execCmd(final String command) {
 868         ArrayList<String> results = null;
 869         try {
 870             final String[] cmd = new String[3];
 871             if (isAIX()) {
 872                 cmd[0] = "/usr/bin/sh";
 873                 cmd[1] = "-c";
 874                 cmd[2] = "env LC_ALL=C " + command;
 875             } else {
 876                 cmd[0] = "/bin/sh";
 877                 cmd[1] = "-c";
 878                 cmd[2] = "LC_ALL=C " + command;
 879             }
 880 
 881             results = AccessController.doPrivileged(
 882                 new PrivilegedExceptionAction<ArrayList<String>>() {
 883                     public ArrayList<String> run() throws IOException {
 884 
 885                         Process proc;
 886                         BufferedReader bufferedReader = null;
 887                         File f = Files.createTempFile("prn","xc").toFile();
 888                         cmd[2] = cmd[2]+">"+f.getAbsolutePath();
 889 
 890                         proc = Runtime.getRuntime().exec(cmd);
 891                         try {


< prev index next >