jdk/src/java.desktop/unix/classes/sun/print/CUPSPrinter.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 25774 jdk/src/solaris/classes/sun/print/CUPSPrinter.java@21b78da4b2df
child 27082 7ab1aa5e8713
child 27269 1ef2879dc7ad
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21224
diff changeset
     2
 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1737
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1737
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1737
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1737
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1737
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.print;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.HttpURLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.print.IPPPrintService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.print.CustomMediaSizeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.print.CustomMediaTray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.print.attribute.standard.Media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.print.attribute.standard.MediaSizeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.print.attribute.standard.MediaSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.print.attribute.standard.MediaTray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.print.attribute.standard.MediaPrintableArea;
25774
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
    42
import javax.print.attribute.standard.PrinterResolution;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.print.attribute.Size2DSyntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.print.attribute.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.print.attribute.EnumSyntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.print.attribute.standard.PrinterName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class CUPSPrinter  {
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 715
diff changeset
    50
    private static final String debugPrefix = "CUPSPrinter>> ";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final double PRINTER_DPI = 72.0;
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 715
diff changeset
    52
    private boolean initialized;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static native String getCupsServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static native int getCupsPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static native boolean canConnect(String server, int port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static native boolean initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // These functions need to be synchronized as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // CUPS does not support multi-threading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static synchronized native String[] getMedia(String printer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static synchronized native float[] getPageSizes(String printer);
25774
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
    61
    private static synchronized native void
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
    62
        getResolutions(String printer, ArrayList<Integer> resolutionList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    //public static boolean useIPPMedia = false; will be used later
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private MediaPrintableArea[] cupsMediaPrintables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private MediaSizeName[] cupsMediaSNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private CustomMediaSizeName[] cupsCustomMediaSNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private MediaTray[] cupsMediaTrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public  int nPageSizes = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public  int nTrays = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private  String[] media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private  float[] pageSizes;
25774
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
    74
    int[]   resolutionsArray;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private String printer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static boolean libFound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static String cupsServer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static int cupsPort = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        // load awt library to access native code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        java.security.AccessController.doPrivileged(
12559
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 5506
diff changeset
    84
            new java.security.PrivilegedAction<Void>() {
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 5506
diff changeset
    85
                public Void run() {
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 5506
diff changeset
    86
                    System.loadLibrary("awt");
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 5506
diff changeset
    87
                    return null;
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 5506
diff changeset
    88
                }
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 5506
diff changeset
    89
            });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        libFound = initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (libFound) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
           cupsServer = getCupsServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
           cupsPort = getCupsPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    CUPSPrinter (String printerName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (printerName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new IllegalArgumentException("null printer name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        printer = printerName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        cupsMediaSNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        cupsMediaPrintables = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        cupsMediaTrays = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        initialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (!libFound) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            throw new RuntimeException("cups lib not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            // get page + tray names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            media =  getMedia(printer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            if (media == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                // either PPD file is not found or printer is unknown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                throw new RuntimeException("error getting PPD");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            // get sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            pageSizes = getPageSizes(printer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            if (pageSizes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                nPageSizes = pageSizes.length/6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                nTrays = media.length/2-nPageSizes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                assert (nTrays >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
25774
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   126
            ArrayList<Integer> resolutionList = new ArrayList<>();
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   127
            getResolutions(printer, resolutionList);
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   128
            resolutionsArray = new int[resolutionList.size()];
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   129
            for (int i=0; i < resolutionList.size(); i++) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   130
                resolutionsArray[i] = resolutionList.get(i);
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   131
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Returns array of MediaSizeNames derived from PPD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public MediaSizeName[] getMediaSizeNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        initMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return cupsMediaSNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Returns array of Custom MediaSizeNames derived from PPD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public CustomMediaSizeName[] getCustomMediaSizeNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        initMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return cupsCustomMediaSNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
25555
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
   153
    public int getDefaultMediaIndex() {
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
   154
        return ((pageSizes.length >1) ? (int)(pageSizes[pageSizes.length -1]) : 0);
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
   155
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Returns array of MediaPrintableArea derived from PPD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public MediaPrintableArea[] getMediaPrintableArea() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        initMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return cupsMediaPrintables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Returns array of MediaTrays derived from PPD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public MediaTray[] getMediaTrays() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        initMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return cupsMediaTrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
25774
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   173
    /**
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   174
     * return the raw packed array of supported printer resolutions.
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   175
     */
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   176
    int[] getRawResolutions() {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   177
        return resolutionsArray;
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   178
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Initialize media by translating PPD info to PrintService attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 715
diff changeset
   183
    private synchronized void initMedia() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (pageSizes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        cupsMediaPrintables = new MediaPrintableArea[nPageSizes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        cupsMediaSNames = new MediaSizeName[nPageSizes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        cupsCustomMediaSNames = new CustomMediaSizeName[nPageSizes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        CustomMediaSizeName msn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        MediaPrintableArea mpa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        float length, width, x, y, w, h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        // initialize names and printables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        for (int i=0; i<nPageSizes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            // media width and length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            width = (float)(pageSizes[i*6]/PRINTER_DPI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            length = (float)(pageSizes[i*6+1]/PRINTER_DPI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            // media printable area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            x = (float)(pageSizes[i*6+2]/PRINTER_DPI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            h = (float)(pageSizes[i*6+3]/PRINTER_DPI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            w = (float)(pageSizes[i*6+4]/PRINTER_DPI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            y = (float)(pageSizes[i*6+5]/PRINTER_DPI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            msn = new CustomMediaSizeName(media[i*2], media[i*2+1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                                          width, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            // add to list of standard MediaSizeNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            if ((cupsMediaSNames[i] = msn.getStandardMedia()) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                // add custom if no matching standard media
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                cupsMediaSNames[i] = msn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                // add this new custom msn to MediaSize array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                if ((width > 0.0) && (length > 0.0)) {
25555
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
   223
                    try {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    new MediaSize(width, length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                                  Size2DSyntax.INCH, msn);
25555
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
   226
                    } catch (IllegalArgumentException e) {
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
   227
                        /* PDF printer in Linux for Ledger paper causes
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
   228
                        "IllegalArgumentException: X dimension > Y dimension".
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
   229
                        We rotate based on IPP spec. */
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
   230
                        new MediaSize(length, width, Size2DSyntax.INCH, msn);
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
   231
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            // add to list of custom MediaSizeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            // for internal use of IPPPrintService
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            cupsCustomMediaSNames[i] = msn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            mpa = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                mpa = new MediaPrintableArea(x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                             MediaPrintableArea.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                if (width > 0 && length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    mpa = new MediaPrintableArea(0, 0, width, length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                             MediaPrintableArea.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            cupsMediaPrintables[i] = mpa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        // initialize trays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        cupsMediaTrays = new MediaTray[nTrays];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        MediaTray mt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        for (int i=0; i<nTrays; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            mt = new CustomMediaTray(media[(nPageSizes+i)*2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                     media[(nPageSizes+i)*2+1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            cupsMediaTrays[i] = mt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Get CUPS default printer using IPP.
21224
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   266
     * Returns 2 values - index 0 is printer name, index 1 is the uri.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
21224
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   268
    static String[] getDefaultPrinter() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            URL url = new URL("http", getServer(), getPort(), "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            final HttpURLConnection urlConnection =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                IPPPrintService.getIPPConnection(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            if (urlConnection != null) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   275
                OutputStream os = java.security.AccessController.
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   276
                    doPrivileged(new java.security.PrivilegedAction<OutputStream>() {
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   277
                        public OutputStream run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                return urlConnection.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                            } catch (Exception e) {
23287
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents: 22584
diff changeset
   281
                               IPPPrintService.debug_println(debugPrefix+e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                if (os == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                AttributeClass attCl[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    AttributeClass.ATTRIBUTES_CHARSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    new AttributeClass("requested-attributes",
21224
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   295
                                       AttributeClass.TAG_URI,
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   296
                                       "printer-uri")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                if (IPPPrintService.writeIPPRequest(os,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                        IPPPrintService.OP_CUPS_GET_DEFAULT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                        attCl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   303
                    HashMap<String, AttributeClass> defaultMap = null;
21224
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   304
                    String[] printerInfo = new String[2];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    InputStream is = urlConnection.getInputStream();
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   306
                    HashMap<String, AttributeClass>[] responseMap = IPPPrintService.readIPPResponse(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                         is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    is.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
12997
7ad469d89bed 7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents: 12559
diff changeset
   310
                    if (responseMap != null && responseMap.length > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                        defaultMap = responseMap[0];
23287
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents: 22584
diff changeset
   312
                    } else {
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents: 22584
diff changeset
   313
                       IPPPrintService.debug_println(debugPrefix+
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents: 22584
diff changeset
   314
                           " empty response map for GET_DEFAULT.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    if (defaultMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                        os.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                        urlConnection.disconnect();
12997
7ad469d89bed 7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents: 12559
diff changeset
   320
7ad469d89bed 7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents: 12559
diff changeset
   321
                        /* CUPS on OS X, as initially configured, considers the
7ad469d89bed 7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents: 12559
diff changeset
   322
                         * default printer to be the last one used that's
7ad469d89bed 7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents: 12559
diff changeset
   323
                         * presently available. So if no default was
7ad469d89bed 7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents: 12559
diff changeset
   324
                         * reported, exec lpstat -d which has all the Apple
7ad469d89bed 7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents: 12559
diff changeset
   325
                         * special behaviour for this built in.
7ad469d89bed 7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents: 12559
diff changeset
   326
                         */
7ad469d89bed 7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents: 12559
diff changeset
   327
                         if (UnixPrintServiceLookup.isMac()) {
21224
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   328
                             printerInfo[0] = UnixPrintServiceLookup.
12997
7ad469d89bed 7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents: 12559
diff changeset
   329
                                                   getDefaultPrinterNameSysV();
21224
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   330
                             printerInfo[1] = null;
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21224
diff changeset
   331
                             return printerInfo.clone();
12997
7ad469d89bed 7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents: 12559
diff changeset
   332
                         } else {
7ad469d89bed 7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents: 12559
diff changeset
   333
                             return null;
7ad469d89bed 7124536: [macosx] PrintServiceLookup.lookupDefaultPrintService() return null
prr
parents: 12559
diff changeset
   334
                         }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
21224
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   337
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   338
                    AttributeClass attribClass = defaultMap.get("printer-name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    if (attribClass != null) {
21224
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   341
                        printerInfo[0] = attribClass.getStringValue();
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   342
                        attribClass = defaultMap.get("printer-uri-supported");
23287
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents: 22584
diff changeset
   343
                        IPPPrintService.debug_println(debugPrefix+
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents: 22584
diff changeset
   344
                          "printer-uri-supported="+attribClass);
21224
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   345
                        if (attribClass != null) {
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   346
                            printerInfo[1] = attribClass.getStringValue();
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   347
                        } else {
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   348
                            printerInfo[1] = null;
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   349
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                        os.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                        urlConnection.disconnect();
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21224
diff changeset
   352
                        return printerInfo.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                os.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                urlConnection.disconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Get list of all CUPS printers using IPP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
21224
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 14342
diff changeset
   367
    static String[] getAllPrinters() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            URL url = new URL("http", getServer(), getPort(), "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            final HttpURLConnection urlConnection =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                IPPPrintService.getIPPConnection(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if (urlConnection != null) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   375
                OutputStream os = java.security.AccessController.
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   376
                    doPrivileged(new java.security.PrivilegedAction<OutputStream>() {
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   377
                        public OutputStream run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                                return urlConnection.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                if (os == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                AttributeClass attCl[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    AttributeClass.ATTRIBUTES_CHARSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    new AttributeClass("requested-attributes",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                                       AttributeClass.TAG_KEYWORD,
542
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 2
diff changeset
   395
                                       "printer-uri-supported")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                if (IPPPrintService.writeIPPRequest(os,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                IPPPrintService.OP_CUPS_GET_PRINTERS, attCl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    InputStream is = urlConnection.getInputStream();
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   402
                    HashMap<String, AttributeClass>[] responseMap =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                        IPPPrintService.readIPPResponse(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    is.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    os.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                    urlConnection.disconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    if (responseMap == null || responseMap.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   413
                    ArrayList<String> printerNames = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    for (int i=0; i< responseMap.length; i++) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   415
                        AttributeClass attribClass =
542
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 2
diff changeset
   416
                            responseMap[i].get("printer-uri-supported");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                        if (attribClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                            String nameStr = attribClass.getStringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                            printerNames.add(nameStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                    }
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23287
diff changeset
   423
                    return printerNames.toArray(new String[] {});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    os.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    urlConnection.disconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * Returns CUPS server name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public static String getServer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        return cupsServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * Returns CUPS port number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    public static int getPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return cupsPort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * Detects if CUPS is running.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    public static boolean isCupsRunning() {
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 715
diff changeset
   454
        IPPPrintService.debug_println(debugPrefix+"libFound "+libFound);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        if (libFound) {
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 715
diff changeset
   456
            IPPPrintService.debug_println(debugPrefix+"CUPS server "+getServer()+
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                                          " port "+getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            return canConnect(getServer(), getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
}