src/share/classes/java/awt/print/PrinterJob.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, 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


  57      * associated with the default printer.
  58      * If no printers are available on the system, a PrinterJob will still
  59      * be returned from this method, but <code>getPrintService()</code>
  60      * will return <code>null</code>, and calling
  61      * {@link #print() print} with this <code>PrinterJob</code> might
  62      * generate an exception.  Applications that need to determine if
  63      * there are suitable printers before creating a <code>PrinterJob</code>
  64      * should ensure that the array returned from
  65      * {@link #lookupPrintServices() lookupPrintServices} is not empty.
  66      * @return a new <code>PrinterJob</code>.
  67      *
  68      * @throws  SecurityException if a security manager exists and its
  69      *          {@link java.lang.SecurityManager#checkPrintJobAccess}
  70      *          method disallows this thread from creating a print job request
  71      */
  72     public static PrinterJob getPrinterJob() {
  73         SecurityManager security = System.getSecurityManager();
  74         if (security != null) {
  75             security.checkPrintJobAccess();
  76         }
  77         return (PrinterJob) java.security.AccessController.doPrivileged(
  78             new java.security.PrivilegedAction() {
  79             public Object run() {
  80                 String nm = System.getProperty("java.awt.printerjob", null);
  81                 try {
  82                     return (PrinterJob)Class.forName(nm).newInstance();
  83                 } catch (ClassNotFoundException e) {
  84                     throw new AWTError("PrinterJob not found: " + nm);
  85                 } catch (InstantiationException e) {
  86                  throw new AWTError("Could not instantiate PrinterJob: " + nm);
  87                 } catch (IllegalAccessException e) {
  88                     throw new AWTError("Could not access PrinterJob: " + nm);
  89                 }
  90             }
  91         });
  92     }
  93 
  94     /**
  95      * A convenience method which looks up 2D print services.
  96      * Services returned from this method may be installed on
  97      * <code>PrinterJob</code>s which support print services.
  98      * Calling this method is equivalent to calling
  99      * {@link javax.print.PrintServiceLookup#lookupPrintServices(


   1 /*
   2  * Copyright (c) 1997, 2014, 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


  57      * associated with the default printer.
  58      * If no printers are available on the system, a PrinterJob will still
  59      * be returned from this method, but <code>getPrintService()</code>
  60      * will return <code>null</code>, and calling
  61      * {@link #print() print} with this <code>PrinterJob</code> might
  62      * generate an exception.  Applications that need to determine if
  63      * there are suitable printers before creating a <code>PrinterJob</code>
  64      * should ensure that the array returned from
  65      * {@link #lookupPrintServices() lookupPrintServices} is not empty.
  66      * @return a new <code>PrinterJob</code>.
  67      *
  68      * @throws  SecurityException if a security manager exists and its
  69      *          {@link java.lang.SecurityManager#checkPrintJobAccess}
  70      *          method disallows this thread from creating a print job request
  71      */
  72     public static PrinterJob getPrinterJob() {
  73         SecurityManager security = System.getSecurityManager();
  74         if (security != null) {
  75             security.checkPrintJobAccess();
  76         }
  77         return java.security.AccessController.doPrivileged(
  78             new java.security.PrivilegedAction<PrinterJob>() {
  79             public PrinterJob run() {
  80                 String nm = System.getProperty("java.awt.printerjob", null);
  81                 try {
  82                     return (PrinterJob)Class.forName(nm).newInstance();
  83                 } catch (ClassNotFoundException e) {
  84                     throw new AWTError("PrinterJob not found: " + nm);
  85                 } catch (InstantiationException e) {
  86                  throw new AWTError("Could not instantiate PrinterJob: " + nm);
  87                 } catch (IllegalAccessException e) {
  88                     throw new AWTError("Could not access PrinterJob: " + nm);
  89                 }
  90             }
  91         });
  92     }
  93 
  94     /**
  95      * A convenience method which looks up 2D print services.
  96      * Services returned from this method may be installed on
  97      * <code>PrinterJob</code>s which support print services.
  98      * Calling this method is equivalent to calling
  99      * {@link javax.print.PrintServiceLookup#lookupPrintServices(