< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 272                      results[2].trim().startsWith("queuing is enabled") &&
 273                      results[3].trim().startsWith("printing is enabled"))) {
 274                     return PrinterIsAcceptingJobs.ACCEPTING_JOBS ;
 275                 }
 276             }
 277         }
 278         return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS ;
 279     }
 280 
 281     // Filter the list of possible AIX Printers and remove header lines
 282     // and extra lines which have been added for remote printers.
 283     // 'protected' because this method is also used from PrintServiceLookupProvider.
 284     protected static String[] filterPrinterNamesAIX(String[] posPrinters) {
 285         ArrayList<String> printers = new ArrayList<>();
 286         String [] splitPart;
 287 
 288         for(int i = 0; i < posPrinters.length; i++) {
 289             // Remove the header lines
 290             if (posPrinters[i].startsWith("---") ||
 291                 posPrinters[i].startsWith("Queue") ||
 292                 posPrinters[i].equals("")) continue;
 293 
 294             // Check if there is a ":" in the end of the first colomn.
 295             // This means that it is not a valid printer definition.
 296             splitPart = posPrinters[i].split(" ");
 297             if(splitPart.length >= 1 && !splitPart[0].trim().endsWith(":")) {
 298                 printers.add(posPrinters[i]);
 299             }
 300         }
 301 
 302         return printers.toArray(new String[printers.size()]);
 303     }
 304 
 305     private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsAIX() {
 306         // On AIX there should not be a blank after '-a'.
 307         String command = "/usr/bin/lpstat -a" + printer;
 308         String[] results= PrintServiceLookupProvider.execCmd(command);
 309 
 310         // Remove headers and bogus entries added by remote printers.
 311         results = filterPrinterNamesAIX(results);
 312 


 677             return Chromaticity.COLOR;
 678         } else if (category == Destination.class) {
 679             try {
 680                 return new Destination((new File("out.ps")).toURI());
 681             } catch (SecurityException se) {
 682                 try {
 683                     return new Destination(new URI("file:out.ps"));
 684                 } catch (URISyntaxException e) {
 685                     return null;
 686                 }
 687             }
 688         } else if (category == Fidelity.class) {
 689             return Fidelity.FIDELITY_FALSE;
 690         } else if (category == JobName.class) {
 691             return new JobName("Java Printing", null);
 692         } else if (category == JobSheets.class) {
 693             return JobSheets.STANDARD;
 694         } else if (category == Media.class) {
 695             String defaultCountry = Locale.getDefault().getCountry();
 696             if (defaultCountry != null &&
 697                 (defaultCountry.equals("") ||
 698                  defaultCountry.equals(Locale.US.getCountry()) ||
 699                  defaultCountry.equals(Locale.CANADA.getCountry()))) {
 700                 return MediaSizeName.NA_LETTER;
 701             } else {
 702                  return MediaSizeName.ISO_A4;
 703             }
 704         } else if (category == MediaPrintableArea.class) {
 705             String defaultCountry = Locale.getDefault().getCountry();
 706             float iw, ih;
 707             if (defaultCountry != null &&
 708                 (defaultCountry.equals("") ||
 709                  defaultCountry.equals(Locale.US.getCountry()) ||
 710                  defaultCountry.equals(Locale.CANADA.getCountry()))) {
 711                 iw = MediaSize.NA.LETTER.getX(Size2DSyntax.INCH) - 0.5f;
 712                 ih = MediaSize.NA.LETTER.getY(Size2DSyntax.INCH) - 0.5f;
 713             } else {
 714                 iw = MediaSize.ISO.A4.getX(Size2DSyntax.INCH) - 0.5f;
 715                 ih = MediaSize.ISO.A4.getY(Size2DSyntax.INCH) - 0.5f;
 716             }
 717             return new MediaPrintableArea(0.25f, 0.25f, iw, ih,
 718                                           MediaPrintableArea.INCH);
 719         } else if (category == OrientationRequested.class) {
 720             return OrientationRequested.PORTRAIT;
 721         } else if (category == PageRanges.class) {
 722             return new PageRanges(1, Integer.MAX_VALUE);
 723         } else if (category == RequestingUserName.class) {
 724             String userName = "";
 725             try {
 726               userName = System.getProperty("user.name", "");
 727             } catch (SecurityException se) {
 728             }


 980         Class<? extends Attribute> category = attr.getCategory();
 981         if (!isAttributeCategorySupported(category)) {
 982             return false;
 983         }
 984         else if (attr.getCategory() == Chromaticity.class) {
 985             if (flavor == null || isServiceFormattedFlavor(flavor)) {
 986                 return attr == Chromaticity.COLOR;
 987             } else {
 988                 return false;
 989             }
 990         }
 991         else if (attr.getCategory() == Copies.class) {
 992             return (flavor == null ||
 993                    !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
 994                      flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
 995                      flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) &&
 996                 isSupportedCopies((Copies)attr);
 997         } else if (attr.getCategory() == Destination.class) {
 998             URI uri = ((Destination)attr).getURI();
 999                 if ("file".equals(uri.getScheme()) &&
1000                     !(uri.getSchemeSpecificPart().equals(""))) {
1001                 return true;
1002             } else {
1003             return false;
1004             }
1005         } else if (attr.getCategory() == Media.class) {
1006             if (attr instanceof MediaSizeName) {
1007                 return isSupportedMedia((MediaSizeName)attr);
1008             } else {
1009                 return false;
1010             }
1011         } else if (attr.getCategory() == OrientationRequested.class) {
1012             if (attr == OrientationRequested.REVERSE_PORTRAIT ||
1013                 (flavor != null) &&
1014                 !isServiceFormattedFlavor(flavor)) {
1015                 return false;
1016             }
1017         } else if (attr.getCategory() == PageRanges.class) {
1018             if (flavor != null &&
1019                 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1020                 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {


   1 /*
   2  * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 272                      results[2].trim().startsWith("queuing is enabled") &&
 273                      results[3].trim().startsWith("printing is enabled"))) {
 274                     return PrinterIsAcceptingJobs.ACCEPTING_JOBS ;
 275                 }
 276             }
 277         }
 278         return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS ;
 279     }
 280 
 281     // Filter the list of possible AIX Printers and remove header lines
 282     // and extra lines which have been added for remote printers.
 283     // 'protected' because this method is also used from PrintServiceLookupProvider.
 284     protected static String[] filterPrinterNamesAIX(String[] posPrinters) {
 285         ArrayList<String> printers = new ArrayList<>();
 286         String [] splitPart;
 287 
 288         for(int i = 0; i < posPrinters.length; i++) {
 289             // Remove the header lines
 290             if (posPrinters[i].startsWith("---") ||
 291                 posPrinters[i].startsWith("Queue") ||
 292                 posPrinters[i].isEmpty()) continue;
 293 
 294             // Check if there is a ":" in the end of the first colomn.
 295             // This means that it is not a valid printer definition.
 296             splitPart = posPrinters[i].split(" ");
 297             if(splitPart.length >= 1 && !splitPart[0].trim().endsWith(":")) {
 298                 printers.add(posPrinters[i]);
 299             }
 300         }
 301 
 302         return printers.toArray(new String[printers.size()]);
 303     }
 304 
 305     private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsAIX() {
 306         // On AIX there should not be a blank after '-a'.
 307         String command = "/usr/bin/lpstat -a" + printer;
 308         String[] results= PrintServiceLookupProvider.execCmd(command);
 309 
 310         // Remove headers and bogus entries added by remote printers.
 311         results = filterPrinterNamesAIX(results);
 312 


 677             return Chromaticity.COLOR;
 678         } else if (category == Destination.class) {
 679             try {
 680                 return new Destination((new File("out.ps")).toURI());
 681             } catch (SecurityException se) {
 682                 try {
 683                     return new Destination(new URI("file:out.ps"));
 684                 } catch (URISyntaxException e) {
 685                     return null;
 686                 }
 687             }
 688         } else if (category == Fidelity.class) {
 689             return Fidelity.FIDELITY_FALSE;
 690         } else if (category == JobName.class) {
 691             return new JobName("Java Printing", null);
 692         } else if (category == JobSheets.class) {
 693             return JobSheets.STANDARD;
 694         } else if (category == Media.class) {
 695             String defaultCountry = Locale.getDefault().getCountry();
 696             if (defaultCountry != null &&
 697                 (defaultCountry.isEmpty() ||
 698                  defaultCountry.equals(Locale.US.getCountry()) ||
 699                  defaultCountry.equals(Locale.CANADA.getCountry()))) {
 700                 return MediaSizeName.NA_LETTER;
 701             } else {
 702                  return MediaSizeName.ISO_A4;
 703             }
 704         } else if (category == MediaPrintableArea.class) {
 705             String defaultCountry = Locale.getDefault().getCountry();
 706             float iw, ih;
 707             if (defaultCountry != null &&
 708                 (defaultCountry.isEmpty() ||
 709                  defaultCountry.equals(Locale.US.getCountry()) ||
 710                  defaultCountry.equals(Locale.CANADA.getCountry()))) {
 711                 iw = MediaSize.NA.LETTER.getX(Size2DSyntax.INCH) - 0.5f;
 712                 ih = MediaSize.NA.LETTER.getY(Size2DSyntax.INCH) - 0.5f;
 713             } else {
 714                 iw = MediaSize.ISO.A4.getX(Size2DSyntax.INCH) - 0.5f;
 715                 ih = MediaSize.ISO.A4.getY(Size2DSyntax.INCH) - 0.5f;
 716             }
 717             return new MediaPrintableArea(0.25f, 0.25f, iw, ih,
 718                                           MediaPrintableArea.INCH);
 719         } else if (category == OrientationRequested.class) {
 720             return OrientationRequested.PORTRAIT;
 721         } else if (category == PageRanges.class) {
 722             return new PageRanges(1, Integer.MAX_VALUE);
 723         } else if (category == RequestingUserName.class) {
 724             String userName = "";
 725             try {
 726               userName = System.getProperty("user.name", "");
 727             } catch (SecurityException se) {
 728             }


 980         Class<? extends Attribute> category = attr.getCategory();
 981         if (!isAttributeCategorySupported(category)) {
 982             return false;
 983         }
 984         else if (attr.getCategory() == Chromaticity.class) {
 985             if (flavor == null || isServiceFormattedFlavor(flavor)) {
 986                 return attr == Chromaticity.COLOR;
 987             } else {
 988                 return false;
 989             }
 990         }
 991         else if (attr.getCategory() == Copies.class) {
 992             return (flavor == null ||
 993                    !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
 994                      flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
 995                      flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) &&
 996                 isSupportedCopies((Copies)attr);
 997         } else if (attr.getCategory() == Destination.class) {
 998             URI uri = ((Destination)attr).getURI();
 999                 if ("file".equals(uri.getScheme()) &&
1000                     !uri.getSchemeSpecificPart().isEmpty()) {
1001                 return true;
1002             } else {
1003             return false;
1004             }
1005         } else if (attr.getCategory() == Media.class) {
1006             if (attr instanceof MediaSizeName) {
1007                 return isSupportedMedia((MediaSizeName)attr);
1008             } else {
1009                 return false;
1010             }
1011         } else if (attr.getCategory() == OrientationRequested.class) {
1012             if (attr == OrientationRequested.REVERSE_PORTRAIT ||
1013                 (flavor != null) &&
1014                 !isServiceFormattedFlavor(flavor)) {
1015                 return false;
1016             }
1017         } else if (attr.getCategory() == PageRanges.class) {
1018             if (flavor != null &&
1019                 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1020                 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {


< prev index next >