src/solaris/classes/sun/print/IPPPrintService.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2007, 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 import java.io.InputStreamReader;
  58 import java.nio.charset.Charset;
  59 
  60 import java.util.Iterator;
  61 import java.util.HashSet;
  62 
  63 
  64 public class IPPPrintService implements PrintService, SunPrinterJobService {
  65 
  66     public static final boolean debugPrint;
  67     private static final String debugPrefix = "IPPPrintService>> ";
  68     protected static void debug_println(String str) {
  69         if (debugPrint) {
  70             System.out.println(str);
  71         }
  72     }
  73 
  74     private static final String FORCE_PIPE_PROP = "sun.print.ippdebug";
  75 
  76     static {
  77         String debugStr =
  78                 (String)java.security.AccessController.doPrivileged(
  79                   new sun.security.action.GetPropertyAction(FORCE_PIPE_PROP));
  80 
  81         debugPrint = "true".equalsIgnoreCase(debugStr);
  82     }
  83 
  84     private String printer;
  85     private URI    myURI;
  86     private URL    myURL;
  87     transient private ServiceNotifier notifier = null;
  88 
  89     private static int MAXCOPIES = 1000;
  90     private static short MAX_ATTRIBUTE_LENGTH = 255;
  91 
  92     private CUPSPrinter cps;
  93     private HttpURLConnection urlConnection = null;
  94     private DocFlavor[] supportedDocFlavors;
  95     private Class[] supportedCats;
  96     private MediaTray[] mediaTrays;
  97     private MediaSizeName[] mediaSizeNames;
  98     private CustomMediaSizeName[] customMediaSizeNames;


 407                 // right now we always get it from PPD.
 408                 // maybe use "&& (usePPD)" later?
 409                 // Another reason why we use PPD is because
 410                 // IPP currently does not support it but PPD does.
 411 
 412                 try {
 413                     cps = new CUPSPrinter(printer);
 414                     mediaSizeNames = cps.getMediaSizeNames();
 415                     mediaTrays = cps.getMediaTrays();
 416                     customMediaSizeNames = cps.getCustomMediaSizeNames();
 417                     urlConnection.disconnect();
 418                     init = true;
 419                     return;
 420                 } catch (Exception e) {
 421                     IPPPrintService.debug_println(debugPrefix+
 422                                        "initAttributes, error creating CUPSPrinter e="+e);
 423                 }
 424             }
 425 
 426             // use IPP to get all media,
 427             Media[] allMedia = (Media[])getSupportedMedia();
 428             ArrayList sizeList = new ArrayList();
 429             ArrayList trayList = new ArrayList();
 430             for (int i=0; i<allMedia.length; i++) {
 431                 if (allMedia[i] instanceof MediaSizeName) {
 432                     sizeList.add(allMedia[i]);
 433                 } else if (allMedia[i] instanceof MediaTray) {
 434                     trayList.add(allMedia[i]);
 435                 }
 436             }
 437 
 438             if (sizeList != null) {
 439                 mediaSizeNames = new MediaSizeName[sizeList.size()];
 440                 mediaSizeNames = (MediaSizeName[])sizeList.toArray(
 441                                                        mediaSizeNames);
 442             }
 443             if (trayList != null) {
 444                 mediaTrays = new MediaTray[trayList.size()];
 445                 mediaTrays = (MediaTray[])trayList.toArray(
 446                                                            mediaTrays);
 447             }


 917         }
 918         if (supportedDocFlavors != null) {
 919             for (int f=0; f<supportedDocFlavors.length; f++) {
 920                 if (flavor.equals(supportedDocFlavors[f])) {
 921                     return true;
 922                 }
 923             }
 924         }
 925         return false;
 926     }
 927 
 928 
 929     /**
 930      * Finds matching CustomMediaSizeName of given media.
 931      */
 932     public CustomMediaSizeName findCustomMedia(MediaSizeName media) {
 933         if (customMediaSizeNames == null) {
 934             return null;
 935         }
 936         for (int i=0; i< customMediaSizeNames.length; i++) {
 937             CustomMediaSizeName custom =
 938                 (CustomMediaSizeName)customMediaSizeNames[i];
 939             MediaSizeName msn = custom.getStandardMedia();
 940             if (media.equals(msn)) {
 941                 return customMediaSizeNames[i];
 942             }
 943         }
 944         return null;
 945     }
 946 
 947 
 948     /**
 949      * Returns the matching standard Media using string comparison of names.
 950      */
 951     private Media getIPPMedia(String mediaName) {
 952         CustomMediaSizeName sampleSize = new CustomMediaSizeName("sample", "",
 953                                                                  0, 0);
 954         Media[] sizes = sampleSize.getSuperEnumTable();
 955         for (int i=0; i<sizes.length; i++) {
 956             if (mediaName.equals(""+sizes[i])) {
 957                 return sizes[i];
 958             }


   1 /*
   2  * Copyright (c) 2003, 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 import java.io.InputStreamReader;
  58 import java.nio.charset.Charset;
  59 
  60 import java.util.Iterator;
  61 import java.util.HashSet;
  62 
  63 
  64 public class IPPPrintService implements PrintService, SunPrinterJobService {
  65 
  66     public static final boolean debugPrint;
  67     private static final String debugPrefix = "IPPPrintService>> ";
  68     protected static void debug_println(String str) {
  69         if (debugPrint) {
  70             System.out.println(str);
  71         }
  72     }
  73 
  74     private static final String FORCE_PIPE_PROP = "sun.print.ippdebug";
  75 
  76     static {
  77         String debugStr = java.security.AccessController.doPrivileged(

  78                   new sun.security.action.GetPropertyAction(FORCE_PIPE_PROP));
  79 
  80         debugPrint = "true".equalsIgnoreCase(debugStr);
  81     }
  82 
  83     private String printer;
  84     private URI    myURI;
  85     private URL    myURL;
  86     transient private ServiceNotifier notifier = null;
  87 
  88     private static int MAXCOPIES = 1000;
  89     private static short MAX_ATTRIBUTE_LENGTH = 255;
  90 
  91     private CUPSPrinter cps;
  92     private HttpURLConnection urlConnection = null;
  93     private DocFlavor[] supportedDocFlavors;
  94     private Class[] supportedCats;
  95     private MediaTray[] mediaTrays;
  96     private MediaSizeName[] mediaSizeNames;
  97     private CustomMediaSizeName[] customMediaSizeNames;


 406                 // right now we always get it from PPD.
 407                 // maybe use "&& (usePPD)" later?
 408                 // Another reason why we use PPD is because
 409                 // IPP currently does not support it but PPD does.
 410 
 411                 try {
 412                     cps = new CUPSPrinter(printer);
 413                     mediaSizeNames = cps.getMediaSizeNames();
 414                     mediaTrays = cps.getMediaTrays();
 415                     customMediaSizeNames = cps.getCustomMediaSizeNames();
 416                     urlConnection.disconnect();
 417                     init = true;
 418                     return;
 419                 } catch (Exception e) {
 420                     IPPPrintService.debug_println(debugPrefix+
 421                                        "initAttributes, error creating CUPSPrinter e="+e);
 422                 }
 423             }
 424 
 425             // use IPP to get all media,
 426             Media[] allMedia = getSupportedMedia();
 427             ArrayList sizeList = new ArrayList();
 428             ArrayList trayList = new ArrayList();
 429             for (int i=0; i<allMedia.length; i++) {
 430                 if (allMedia[i] instanceof MediaSizeName) {
 431                     sizeList.add(allMedia[i]);
 432                 } else if (allMedia[i] instanceof MediaTray) {
 433                     trayList.add(allMedia[i]);
 434                 }
 435             }
 436 
 437             if (sizeList != null) {
 438                 mediaSizeNames = new MediaSizeName[sizeList.size()];
 439                 mediaSizeNames = (MediaSizeName[])sizeList.toArray(
 440                                                        mediaSizeNames);
 441             }
 442             if (trayList != null) {
 443                 mediaTrays = new MediaTray[trayList.size()];
 444                 mediaTrays = (MediaTray[])trayList.toArray(
 445                                                            mediaTrays);
 446             }


 916         }
 917         if (supportedDocFlavors != null) {
 918             for (int f=0; f<supportedDocFlavors.length; f++) {
 919                 if (flavor.equals(supportedDocFlavors[f])) {
 920                     return true;
 921                 }
 922             }
 923         }
 924         return false;
 925     }
 926 
 927 
 928     /**
 929      * Finds matching CustomMediaSizeName of given media.
 930      */
 931     public CustomMediaSizeName findCustomMedia(MediaSizeName media) {
 932         if (customMediaSizeNames == null) {
 933             return null;
 934         }
 935         for (int i=0; i< customMediaSizeNames.length; i++) {
 936             CustomMediaSizeName custom = customMediaSizeNames[i];

 937             MediaSizeName msn = custom.getStandardMedia();
 938             if (media.equals(msn)) {
 939                 return customMediaSizeNames[i];
 940             }
 941         }
 942         return null;
 943     }
 944 
 945 
 946     /**
 947      * Returns the matching standard Media using string comparison of names.
 948      */
 949     private Media getIPPMedia(String mediaName) {
 950         CustomMediaSizeName sampleSize = new CustomMediaSizeName("sample", "",
 951                                                                  0, 0);
 952         Media[] sizes = sampleSize.getSuperEnumTable();
 953         for (int i=0; i<sizes.length; i++) {
 954             if (mediaName.equals(""+sizes[i])) {
 955                 return sizes[i];
 956             }