< prev index next >

src/java.desktop/unix/classes/sun/print/UnixPrintJob.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


 377              if (nUp != null) {
 378                  mOptions += " number-up="+nUp.getValue();
 379              }
 380 
 381              if (orient != OrientationRequested.PORTRAIT &&
 382                  (flavor != null) &&
 383                  !flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE)) {
 384                  mOptions += " orientation-requested="+orient.getValue();
 385              }
 386 
 387              if (sides != null) {
 388                  mOptions += " sides="+sides;
 389              }
 390 
 391         }
 392 
 393         IPPPrintService.debug_println(debugPrefix+"mOptions "+mOptions);
 394         String repClassName = flavor.getRepresentationClassName();
 395         String val = flavor.getParameter("charset");
 396         String encoding = "us-ascii";
 397         if (val != null && !val.equals("")) {
 398             encoding = val;
 399         }
 400 
 401         if (flavor.equals(DocFlavor.INPUT_STREAM.GIF) ||
 402             flavor.equals(DocFlavor.INPUT_STREAM.JPEG) ||
 403             flavor.equals(DocFlavor.INPUT_STREAM.PNG) ||
 404             flavor.equals(DocFlavor.BYTE_ARRAY.GIF) ||
 405             flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) ||
 406             flavor.equals(DocFlavor.BYTE_ARRAY.PNG)) {
 407             try {
 408                 instream = doc.getStreamForBytes();
 409                 if (instream == null) {
 410                     notifyEvent(PrintJobEvent.JOB_FAILED);
 411                     throw new PrintException("No stream for data");
 412                 }
 413                 if (!(service instanceof IPPPrintService &&
 414                     ((IPPPrintService)service).isIPPSupportedImages(
 415                                                 flavor.getMimeType()))) {
 416                     printableJob(new ImagePrinter(instream));
 417                     if (service instanceof IPPPrintService) {


 716         DocAttributeSet docSet = doc.getAttributes();
 717         if (docSet != null) {
 718             attrs = docSet.toArray();
 719             for (int i=0; i<attrs.length; i++) {
 720                 if (attrs[i] instanceof PrintRequestAttribute) {
 721                     reqAttrSet.add(attrs[i]);
 722                 }
 723                 if (attrs[i] instanceof PrintJobAttribute) {
 724                     jobAttrSet.add(attrs[i]);
 725                 }
 726             }
 727         }
 728 
 729         /* add the user name to the job */
 730         String userName = "";
 731         try {
 732           userName = System.getProperty("user.name");
 733         } catch (SecurityException se) {
 734         }
 735 
 736         if (userName == null || userName.equals("")) {
 737             RequestingUserName ruName =
 738                 (RequestingUserName)reqSet.get(RequestingUserName.class);
 739             if (ruName != null) {
 740                 jobAttrSet.add(
 741                     new JobOriginatingUserName(ruName.getValue(),
 742                                                ruName.getLocale()));
 743             } else {
 744                 jobAttrSet.add(new JobOriginatingUserName("", null));
 745             }
 746         } else {
 747             jobAttrSet.add(new JobOriginatingUserName(userName, null));
 748         }
 749 
 750         /* if no job name supplied use doc name (if supplied), if none and
 751          * its a URL use that, else finally anything .. */
 752         if (jobAttrSet.get(JobName.class) == null) {
 753             JobName jobName;
 754             if (docSet != null && docSet.get(DocumentName.class) != null) {
 755                 DocumentName docName =
 756                     (DocumentName)docSet.get(DocumentName.class);


 848             } else if (category == Sides.class) {
 849                 sides = (Sides)attr;
 850             }
 851         }
 852     }
 853 
 854     private String[] printExecCmd(String printer, String options,
 855                                  boolean noJobSheet,
 856                                  String jobTitle, int copies, String spoolFile) {
 857         int PRINTER = 0x1;
 858         int OPTIONS = 0x2;
 859         int JOBTITLE  = 0x4;
 860         int COPIES  = 0x8;
 861         int NOSHEET  = 0x10;
 862         int pFlags = 0;
 863         String[] execCmd;
 864         int ncomps = 2; // minimum number of print args
 865         int n = 0;
 866 
 867         // conveniently "lp" is the default destination for both lp and lpr.
 868         if (printer != null && !printer.equals("") && !printer.equals("lp")) {
 869             pFlags |= PRINTER;
 870             ncomps+=1;
 871         }
 872         if (options != null && !options.equals("")) {
 873             pFlags |= OPTIONS;
 874             ncomps+=1;
 875         }
 876         if (jobTitle != null && !jobTitle.equals("")) {
 877             pFlags |= JOBTITLE;
 878             ncomps+=1;
 879         }
 880         if (copies > 1) {
 881             pFlags |= COPIES;
 882             ncomps+=1;
 883         }
 884         if (noJobSheet) {
 885             pFlags |= NOSHEET;
 886             ncomps+=1;
 887         } else if (getPrintService().
 888                         isAttributeCategorySupported(JobSheets.class)) {
 889             ncomps+=1;
 890         }
 891         if (PrintServiceLookupProvider.osname.equals("SunOS")) {
 892             ncomps+=1; // lp uses 1 more arg than lpr (make a copy)
 893             execCmd = new String[ncomps];
 894             execCmd[n++] = "/usr/bin/lp";
 895             execCmd[n++] = "-c";           // make a copy of the spool file
 896             if ((pFlags & PRINTER) != 0) {


   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


 377              if (nUp != null) {
 378                  mOptions += " number-up="+nUp.getValue();
 379              }
 380 
 381              if (orient != OrientationRequested.PORTRAIT &&
 382                  (flavor != null) &&
 383                  !flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE)) {
 384                  mOptions += " orientation-requested="+orient.getValue();
 385              }
 386 
 387              if (sides != null) {
 388                  mOptions += " sides="+sides;
 389              }
 390 
 391         }
 392 
 393         IPPPrintService.debug_println(debugPrefix+"mOptions "+mOptions);
 394         String repClassName = flavor.getRepresentationClassName();
 395         String val = flavor.getParameter("charset");
 396         String encoding = "us-ascii";
 397         if (val != null && !val.isEmpty()) {
 398             encoding = val;
 399         }
 400 
 401         if (flavor.equals(DocFlavor.INPUT_STREAM.GIF) ||
 402             flavor.equals(DocFlavor.INPUT_STREAM.JPEG) ||
 403             flavor.equals(DocFlavor.INPUT_STREAM.PNG) ||
 404             flavor.equals(DocFlavor.BYTE_ARRAY.GIF) ||
 405             flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) ||
 406             flavor.equals(DocFlavor.BYTE_ARRAY.PNG)) {
 407             try {
 408                 instream = doc.getStreamForBytes();
 409                 if (instream == null) {
 410                     notifyEvent(PrintJobEvent.JOB_FAILED);
 411                     throw new PrintException("No stream for data");
 412                 }
 413                 if (!(service instanceof IPPPrintService &&
 414                     ((IPPPrintService)service).isIPPSupportedImages(
 415                                                 flavor.getMimeType()))) {
 416                     printableJob(new ImagePrinter(instream));
 417                     if (service instanceof IPPPrintService) {


 716         DocAttributeSet docSet = doc.getAttributes();
 717         if (docSet != null) {
 718             attrs = docSet.toArray();
 719             for (int i=0; i<attrs.length; i++) {
 720                 if (attrs[i] instanceof PrintRequestAttribute) {
 721                     reqAttrSet.add(attrs[i]);
 722                 }
 723                 if (attrs[i] instanceof PrintJobAttribute) {
 724                     jobAttrSet.add(attrs[i]);
 725                 }
 726             }
 727         }
 728 
 729         /* add the user name to the job */
 730         String userName = "";
 731         try {
 732           userName = System.getProperty("user.name");
 733         } catch (SecurityException se) {
 734         }
 735 
 736         if (userName == null || userName.isEmpty()) {
 737             RequestingUserName ruName =
 738                 (RequestingUserName)reqSet.get(RequestingUserName.class);
 739             if (ruName != null) {
 740                 jobAttrSet.add(
 741                     new JobOriginatingUserName(ruName.getValue(),
 742                                                ruName.getLocale()));
 743             } else {
 744                 jobAttrSet.add(new JobOriginatingUserName("", null));
 745             }
 746         } else {
 747             jobAttrSet.add(new JobOriginatingUserName(userName, null));
 748         }
 749 
 750         /* if no job name supplied use doc name (if supplied), if none and
 751          * its a URL use that, else finally anything .. */
 752         if (jobAttrSet.get(JobName.class) == null) {
 753             JobName jobName;
 754             if (docSet != null && docSet.get(DocumentName.class) != null) {
 755                 DocumentName docName =
 756                     (DocumentName)docSet.get(DocumentName.class);


 848             } else if (category == Sides.class) {
 849                 sides = (Sides)attr;
 850             }
 851         }
 852     }
 853 
 854     private String[] printExecCmd(String printer, String options,
 855                                  boolean noJobSheet,
 856                                  String jobTitle, int copies, String spoolFile) {
 857         int PRINTER = 0x1;
 858         int OPTIONS = 0x2;
 859         int JOBTITLE  = 0x4;
 860         int COPIES  = 0x8;
 861         int NOSHEET  = 0x10;
 862         int pFlags = 0;
 863         String[] execCmd;
 864         int ncomps = 2; // minimum number of print args
 865         int n = 0;
 866 
 867         // conveniently "lp" is the default destination for both lp and lpr.
 868         if (printer != null && !printer.isEmpty() && !printer.equals("lp")) {
 869             pFlags |= PRINTER;
 870             ncomps+=1;
 871         }
 872         if (options != null && !options.isEmpty()) {
 873             pFlags |= OPTIONS;
 874             ncomps+=1;
 875         }
 876         if (jobTitle != null && !jobTitle.isEmpty()) {
 877             pFlags |= JOBTITLE;
 878             ncomps+=1;
 879         }
 880         if (copies > 1) {
 881             pFlags |= COPIES;
 882             ncomps+=1;
 883         }
 884         if (noJobSheet) {
 885             pFlags |= NOSHEET;
 886             ncomps+=1;
 887         } else if (getPrintService().
 888                         isAttributeCategorySupported(JobSheets.class)) {
 889             ncomps+=1;
 890         }
 891         if (PrintServiceLookupProvider.osname.equals("SunOS")) {
 892             ncomps+=1; // lp uses 1 more arg than lpr (make a copy)
 893             execCmd = new String[ncomps];
 894             execCmd[n++] = "/usr/bin/lp";
 895             execCmd[n++] = "-c";           // make a copy of the spool file
 896             if ((pFlags & PRINTER) != 0) {


< prev index next >