src/java.desktop/unix/classes/sun/print/IPPPrintService.java
author mdoerr
Tue, 13 Feb 2018 17:38:03 +0100
changeset 48965 be873d8c0114
parent 47216 71c04702a3d5
child 50486 143c539c00dc
permissions -rw-r--r--
8196786: [PPC64+s390] ConstantDynamic support Reviewed-by: psandoz, dsamersoff
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: 21780
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: 3923
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: 3923
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: 3923
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3923
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3923
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 javax.print.attribute.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.print.attribute.standard.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.print.DocFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.print.DocPrintJob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.print.PrintService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.print.ServiceUIFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.PrivilegedActionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.security.PrivilegedExceptionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.print.event.PrintServiceAttributeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.net.URISyntaxException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.net.URL;
21780
aa006e1a6eb9 8028584: sun.net.www.protocol.file.FileURLConnection cannot be cast to java.net.HttpURLConnection
jgodinez
parents: 21224
diff changeset
    47
import java.net.URLConnection;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.net.HttpURLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.io.OutputStreamWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.io.DataInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.io.ByteArrayOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.io.ByteArrayInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.io.InputStreamReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import java.util.Iterator;
1720
539a197aefbd 6731937: javax/print/CheckDupFlavor.java fails
jgodinez
parents: 542
diff changeset
    61
import java.util.HashSet;
43723
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
    62
import java.util.Map;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
public class IPPPrintService implements PrintService, SunPrinterJobService {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
    67
    public static final boolean debugPrint;
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
    68
    private static final String debugPrefix = "IPPPrintService>> ";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected static void debug_println(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (debugPrint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            System.out.println(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
    75
    private static final String FORCE_PIPE_PROP = "sun.print.ippdebug";
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
    76
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
    77
    static {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21780
diff changeset
    78
        String debugStr = java.security.AccessController.doPrivileged(
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
    79
                  new sun.security.action.GetPropertyAction(FORCE_PIPE_PROP));
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
    80
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
    81
        debugPrint = "true".equalsIgnoreCase(debugStr);
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
    82
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private String printer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private URI    myURI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private URL    myURL;
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27282
diff changeset
    87
    private transient ServiceNotifier notifier = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static int MAXCOPIES = 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static short MAX_ATTRIBUTE_LENGTH = 255;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private CUPSPrinter cps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private HttpURLConnection urlConnection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private DocFlavor[] supportedDocFlavors;
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
    95
    private Class<?>[] supportedCats;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private MediaTray[] mediaTrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private MediaSizeName[] mediaSizeNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private CustomMediaSizeName[] customMediaSizeNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private int defaultMediaIndex;
25774
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   100
    private int[] rawResolutions = null;
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   101
    private PrinterResolution[] printerResolutions = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private boolean isCupsPrinter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private boolean init;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private Boolean isPS;
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   105
    private HashMap<String, AttributeClass> getAttMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private boolean pngImagesAdded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private boolean gifImagesAdded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private boolean jpgImagesAdded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * IPP Status Codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private static final byte STATUSCODE_SUCCESS = 0x00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * IPP Group Tags.  Each tag is used once before the first attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * of that group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    // operation attributes group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private static final byte GRPTAG_OP_ATTRIBUTES = 0x01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    // job attributes group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private static final byte GRPTAG_JOB_ATTRIBUTES = 0x02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    // printer attributes group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private static final byte GRPTAG_PRINTER_ATTRIBUTES = 0x04;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    // used as the last tag in an IPP message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private static final byte GRPTAG_END_ATTRIBUTES = 0x03;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * IPP Operation codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    // gets the attributes for a printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public static final String OP_GET_ATTRIBUTES = "000B";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    // gets the default printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static final String OP_CUPS_GET_DEFAULT = "4001";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    // gets the list of printers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public static final String OP_CUPS_GET_PRINTERS = "4002";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * List of all PrintRequestAttributes.  This is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * for looping through all the IPP attribute name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private static Object[] printReqAttribDefault = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        Chromaticity.COLOR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        new Copies(1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        Fidelity.FIDELITY_FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        Finishings.NONE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        //new JobHoldUntil(new Date()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        //new JobImpressions(0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        //JobImpressions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        //JobKOctets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        //JobMediaSheets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        new JobName("", Locale.getDefault()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        //JobPriority,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        JobSheets.NONE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        (Media)MediaSizeName.NA_LETTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        //MediaPrintableArea.class, // not an IPP attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        //MultipleDocumentHandling.SINGLE_DOCUMENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        new NumberUp(1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        OrientationRequested.PORTRAIT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        new PageRanges(1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        //PresentationDirection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                 // CUPS does not supply printer-resolution attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        //new PrinterResolution(300, 300, PrinterResolution.DPI),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        //PrintQuality.NORMAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        new RequestingUserName("", Locale.getDefault()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        //SheetCollate.UNCOLLATED, //CUPS has no sheet collate?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        Sides.ONE_SIDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * List of all PrintServiceAttributes.  This is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * for looping through all the IPP attribute name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    private static Object[][] serviceAttributes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        {ColorSupported.class, "color-supported"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        {PagesPerMinute.class,  "pages-per-minute"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        {PagesPerMinuteColor.class, "pages-per-minute-color"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        {PDLOverrideSupported.class, "pdl-override-supported"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        {PrinterInfo.class, "printer-info"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        {PrinterIsAcceptingJobs.class, "printer-is-accepting-jobs"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        {PrinterLocation.class, "printer-location"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        {PrinterMakeAndModel.class, "printer-make-and-model"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        {PrinterMessageFromOperator.class, "printer-message-from-operator"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        {PrinterMoreInfo.class, "printer-more-info"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        {PrinterMoreInfoManufacturer.class, "printer-more-info-manufacturer"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        {PrinterName.class, "printer-name"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        {PrinterState.class, "printer-state"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        {PrinterStateReasons.class, "printer-state-reasons"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        {PrinterURI.class, "printer-uri"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        {QueuedJobCount.class, "queued-job-count"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * List of DocFlavors, grouped based on matching mime-type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * NOTE: For any change in the predefined DocFlavors, it must be reflected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * here also.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    // PDF DocFlavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private static DocFlavor[] appPDF = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        DocFlavor.BYTE_ARRAY.PDF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        DocFlavor.INPUT_STREAM.PDF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        DocFlavor.URL.PDF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    // Postscript DocFlavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    private static DocFlavor[] appPostScript = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        DocFlavor.BYTE_ARRAY.POSTSCRIPT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        DocFlavor.INPUT_STREAM.POSTSCRIPT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        DocFlavor.URL.POSTSCRIPT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    // Autosense DocFlavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    private static DocFlavor[] appOctetStream = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        DocFlavor.BYTE_ARRAY.AUTOSENSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        DocFlavor.INPUT_STREAM.AUTOSENSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        DocFlavor.URL.AUTOSENSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    // Text DocFlavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    private static DocFlavor[] textPlain = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_16BE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_16LE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        DocFlavor.BYTE_ARRAY.TEXT_PLAIN_US_ASCII,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_16BE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_16LE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        DocFlavor.URL.TEXT_PLAIN_UTF_8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        DocFlavor.URL.TEXT_PLAIN_UTF_16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        DocFlavor.URL.TEXT_PLAIN_UTF_16BE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        DocFlavor.URL.TEXT_PLAIN_UTF_16LE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        DocFlavor.URL.TEXT_PLAIN_US_ASCII,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        DocFlavor.CHAR_ARRAY.TEXT_PLAIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        DocFlavor.STRING.TEXT_PLAIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        DocFlavor.READER.TEXT_PLAIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    private static DocFlavor[] textPlainHost = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        DocFlavor.BYTE_ARRAY.TEXT_PLAIN_HOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        DocFlavor.URL.TEXT_PLAIN_HOST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    // JPG DocFlavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    private static DocFlavor[] imageJPG = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        DocFlavor.BYTE_ARRAY.JPEG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        DocFlavor.INPUT_STREAM.JPEG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        DocFlavor.URL.JPEG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    // GIF DocFlavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    private static DocFlavor[] imageGIF = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        DocFlavor.BYTE_ARRAY.GIF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        DocFlavor.INPUT_STREAM.GIF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        DocFlavor.URL.GIF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    // PNG DocFlavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    private static DocFlavor[] imagePNG = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        DocFlavor.BYTE_ARRAY.PNG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        DocFlavor.INPUT_STREAM.PNG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        DocFlavor.URL.PNG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    // HTML DocFlavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    private  static DocFlavor[] textHtml = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        DocFlavor.BYTE_ARRAY.TEXT_HTML_UTF_8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        DocFlavor.BYTE_ARRAY.TEXT_HTML_UTF_16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        DocFlavor.BYTE_ARRAY.TEXT_HTML_UTF_16BE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        DocFlavor.BYTE_ARRAY.TEXT_HTML_UTF_16LE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        DocFlavor.BYTE_ARRAY.TEXT_HTML_US_ASCII,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_16BE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_16LE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        DocFlavor.INPUT_STREAM.TEXT_HTML_US_ASCII,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        DocFlavor.URL.TEXT_HTML_UTF_8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        DocFlavor.URL.TEXT_HTML_UTF_16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        DocFlavor.URL.TEXT_HTML_UTF_16BE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        DocFlavor.URL.TEXT_HTML_UTF_16LE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        DocFlavor.URL.TEXT_HTML_US_ASCII,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // These are not handled in UnixPrintJob so commenting these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        // for now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        DocFlavor.CHAR_ARRAY.TEXT_HTML,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        DocFlavor.STRING.TEXT_HTML,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        DocFlavor.READER.TEXT_HTML,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    private  static DocFlavor[] textHtmlHost = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        DocFlavor.BYTE_ARRAY.TEXT_HTML_HOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        DocFlavor.INPUT_STREAM.TEXT_HTML_HOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        DocFlavor.URL.TEXT_HTML_HOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    // PCL DocFlavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    private static DocFlavor[] appPCL = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        DocFlavor.BYTE_ARRAY.PCL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        DocFlavor.INPUT_STREAM.PCL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        DocFlavor.URL.PCL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    // List of all DocFlavors, used in looping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    // through all supported mime-types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    private static Object[] allDocFlavors = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        appPDF, appPostScript, appOctetStream,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        textPlain, imageJPG, imageGIF, imagePNG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        textHtml, appPCL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    IPPPrintService(String name, URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if ((name == null) || (url == null)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            throw new IllegalArgumentException("null uri or printer name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
33860
f75ee0470f4b 8139216: Non-ASCII characters in CUPS printer names are not properly displayed
psadhukhan
parents: 32865
diff changeset
   325
        try {
f75ee0470f4b 8139216: Non-ASCII characters in CUPS printer names are not properly displayed
psadhukhan
parents: 32865
diff changeset
   326
            printer = java.net.URLDecoder.decode(name, "UTF-8");
f75ee0470f4b 8139216: Non-ASCII characters in CUPS printer names are not properly displayed
psadhukhan
parents: 32865
diff changeset
   327
        } catch (java.io.UnsupportedEncodingException e) {
f75ee0470f4b 8139216: Non-ASCII characters in CUPS printer names are not properly displayed
psadhukhan
parents: 32865
diff changeset
   328
            printer = name;
f75ee0470f4b 8139216: Non-ASCII characters in CUPS printer names are not properly displayed
psadhukhan
parents: 32865
diff changeset
   329
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        supportedDocFlavors = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        supportedCats = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        mediaSizeNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        customMediaSizeNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        mediaTrays = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        myURL = url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        cps = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        isCupsPrinter = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        init = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        defaultMediaIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        String host = myURL.getHost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if (host!=null && host.equals(CUPSPrinter.getServer())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            isCupsPrinter = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                myURI =  new URI("ipp://"+host+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                                 "/printers/"+printer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                debug_println(debugPrefix+"IPPPrintService myURI : "+myURI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            } catch (java.net.URISyntaxException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                throw new IllegalArgumentException("invalid url");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
542
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   355
    IPPPrintService(String name, String uriStr, boolean isCups) {
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   356
        if ((name == null) || (uriStr == null)){
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   357
            throw new IllegalArgumentException("null uri or printer name");
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   358
        }
33860
f75ee0470f4b 8139216: Non-ASCII characters in CUPS printer names are not properly displayed
psadhukhan
parents: 32865
diff changeset
   359
        try {
f75ee0470f4b 8139216: Non-ASCII characters in CUPS printer names are not properly displayed
psadhukhan
parents: 32865
diff changeset
   360
            printer = java.net.URLDecoder.decode(name, "UTF-8");
f75ee0470f4b 8139216: Non-ASCII characters in CUPS printer names are not properly displayed
psadhukhan
parents: 32865
diff changeset
   361
        } catch (java.io.UnsupportedEncodingException e) {
f75ee0470f4b 8139216: Non-ASCII characters in CUPS printer names are not properly displayed
psadhukhan
parents: 32865
diff changeset
   362
            printer = name;
f75ee0470f4b 8139216: Non-ASCII characters in CUPS printer names are not properly displayed
psadhukhan
parents: 32865
diff changeset
   363
        }
542
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   364
        supportedDocFlavors = null;
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   365
        supportedCats = null;
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   366
        mediaSizeNames = null;
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   367
        customMediaSizeNames = null;
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   368
        mediaTrays = null;
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   369
        cps = null;
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   370
        init = false;
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   371
        defaultMediaIndex = -1;
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   372
        try {
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   373
            myURL =
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   374
                new URL(uriStr.replaceFirst("ipp", "http"));
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   375
        } catch (Exception e) {
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   376
            IPPPrintService.debug_println(debugPrefix+
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   377
                                          " IPPPrintService, myURL="+
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   378
                                          myURL+" Exception= "+
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   379
                                          e);
21224
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 19013
diff changeset
   380
            throw new IllegalArgumentException("invalid url");
542
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   381
        }
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   382
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   383
        isCupsPrinter = isCups;
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   384
        try {
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   385
            myURI =  new URI(uriStr);
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   386
            debug_println(debugPrefix+"IPPPrintService myURI : "+myURI);
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   387
        } catch (java.net.URISyntaxException e) {
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   388
            throw new IllegalArgumentException("invalid uri");
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   389
        }
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   390
    }
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   391
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * Initialize mediaSizeNames, mediaTrays and other attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * Media size/trays are initialized to non-null values, may be 0-length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * NOTE: Must be called from a synchronized block only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    private void initAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (!init) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            // init customMediaSizeNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            customMediaSizeNames = new CustomMediaSizeName[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            if ((urlConnection = getIPPConnection(myURL)) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                mediaSizeNames = new MediaSizeName[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                mediaTrays = new MediaTray[0];
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
   407
                debug_println(debugPrefix+"initAttributes, NULL urlConnection ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                init = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            // get all supported attributes through IPP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            opGetAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            if (isCupsPrinter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                // note, it is possible to query media in CUPS using IPP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                // right now we always get it from PPD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                // maybe use "&& (usePPD)" later?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                // Another reason why we use PPD is because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                // IPP currently does not support it but PPD does.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    cps = new CUPSPrinter(printer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    mediaSizeNames = cps.getMediaSizeNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    mediaTrays = cps.getMediaTrays();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    customMediaSizeNames = cps.getCustomMediaSizeNames();
25555
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
   427
                    defaultMediaIndex = cps.getDefaultMediaIndex();
25774
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   428
                    rawResolutions = cps.getRawResolutions();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                    urlConnection.disconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    init = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    IPPPrintService.debug_println(debugPrefix+
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
   434
                                       "initAttributes, error creating CUPSPrinter e="+e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            // use IPP to get all media,
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21780
diff changeset
   439
            Media[] allMedia = getSupportedMedia();
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   440
            ArrayList<Media> sizeList = new ArrayList<>();
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   441
            ArrayList<Media> trayList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            for (int i=0; i<allMedia.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                if (allMedia[i] instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    sizeList.add(allMedia[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                } else if (allMedia[i] instanceof MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    trayList.add(allMedia[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            if (sizeList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                mediaSizeNames = new MediaSizeName[sizeList.size()];
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   452
                mediaSizeNames = sizeList.toArray(mediaSizeNames);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            if (trayList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                mediaTrays = new MediaTray[trayList.size()];
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   456
                mediaTrays = trayList.toArray(mediaTrays);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            urlConnection.disconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            init = true;
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
    public DocPrintJob createPrintJob() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            security.checkPrintJobAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // REMIND: create IPPPrintJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        return new UnixPrintJob(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    public synchronized Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        getSupportedAttributeValues(Class<? extends Attribute> category,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                    DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                                    AttributeSet attributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            throw new NullPointerException("null category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (!Attribute.class.isAssignableFrom(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            throw new IllegalArgumentException(category +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                                 " does not implement Attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        if (flavor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            if (!isDocFlavorSupported(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                throw new IllegalArgumentException(flavor +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                               " is an unsupported flavor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            } else if (isAutoSense(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if (!isAttributeCategorySupported(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        /* Test if the flavor is compatible with the attributes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        if (!isDestinationSupported(flavor, attributes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        initAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        /* Test if the flavor is compatible with the category */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        if ((category == Copies.class) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            (category == CopiesSupported.class)) {
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   511
            if (flavor == null ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   512
                !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   513
                  flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   514
                  flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) {
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   515
                CopiesSupported cs = new CopiesSupported(1, MAXCOPIES);
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   516
                AttributeClass attribClass = (getAttMap != null) ?
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   517
                    getAttMap.get(cs.getName()) : null;
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   518
                if (attribClass != null) {
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   519
                    int[] range = attribClass.getIntRangeValue();
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   520
                    cs = new CopiesSupported(range[0], range[1]);
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   521
                }
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   522
                return cs;
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   523
            } else {
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   524
                return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        } else  if (category == Chromaticity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) ||
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
   530
                !isIPPSupportedImages(flavor.getMimeType())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                Chromaticity[]arr = new Chromaticity[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                arr[0] = Chromaticity.COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                return (arr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        } else if (category == Destination.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    return new Destination((new File("out.ps")).toURI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                        return new Destination(new URI("file:out.ps"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    } catch (URISyntaxException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        } else if (category == Fidelity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            Fidelity []arr = new Fidelity[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            arr[0] = Fidelity.FIDELITY_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            arr[1] = Fidelity.FIDELITY_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        } else if (category == Finishings.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            AttributeClass attribClass = (getAttMap != null) ?
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   559
                getAttMap.get("finishings-supported")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            if (attribClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                int[] finArray = attribClass.getArrayOfIntValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                if ((finArray != null) && (finArray.length > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                    Finishings[] finSup = new Finishings[finArray.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    for (int i=0; i<finArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                        finSup[i] = Finishings.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                        Finishings[] fAll = (Finishings[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                            (new ExtFinishing(100)).getAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                        for (int j=0; j<fAll.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                            if (finArray[i] == fAll[j].getValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                finSup[i] = fAll[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                    return finSup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        } else if (category == JobName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            return new JobName("Java Printing", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        } else if (category == JobSheets.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            JobSheets arr[] = new JobSheets[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            arr[0] = JobSheets.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            arr[1] = JobSheets.STANDARD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        } else if (category == Media.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            Media[] allMedia = new Media[mediaSizeNames.length+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                                        mediaTrays.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            for (int i=0; i<mediaSizeNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                allMedia[i] = mediaSizeNames[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            for (int i=0; i<mediaTrays.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                allMedia[i+mediaSizeNames.length] = mediaTrays[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            if (allMedia.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                allMedia = new Media[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                allMedia[0] = (Media)getDefaultAttributeValue(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            return allMedia;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        } else if (category == MediaPrintableArea.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            MediaPrintableArea[] mpas = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            if (cps != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                mpas = cps.getMediaPrintableArea();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            if (mpas == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                mpas = new MediaPrintableArea[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                mpas[0] = (MediaPrintableArea)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    getDefaultAttributeValue(MediaPrintableArea.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            if ((attributes == null) || (attributes.size() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                ArrayList<MediaPrintableArea> printableList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                                       new ArrayList<MediaPrintableArea>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                for (int i=0; i<mpas.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                    if (mpas[i] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                        printableList.add(mpas[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                if (printableList.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                    mpas  = new MediaPrintableArea[printableList.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                    printableList.toArray(mpas);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                return mpas;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            int match = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            Media media = (Media)attributes.get(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            if (media != null && media instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                MediaSizeName msn = (MediaSizeName)media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                // case when no supported mediasizenames are reported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                // check given media against the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                if (mediaSizeNames.length == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    msn.equals(getDefaultAttributeValue(Media.class))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                    //default printable area is that of default mediasize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                    return mpas;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                for (int i=0; i<mediaSizeNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                    if (msn.equals(mediaSizeNames[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                        match = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            if (match == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                MediaPrintableArea []arr = new MediaPrintableArea[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                arr[0] = mpas[match];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        } else if (category == NumberUp.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            AttributeClass attribClass = (getAttMap != null) ?
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   662
                getAttMap.get("number-up-supported") : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            if (attribClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                int[] values = attribClass.getArrayOfIntValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                if (values != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                    NumberUp[] nUp = new NumberUp[values.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                    for (int i=0; i<values.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                        nUp[i] = new NumberUp(values[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                    return nUp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        } else if (category == OrientationRequested.class) {
3923
b8a16aa12f0b 6848799: Reg-test java/awt/print/PageFormat/PageFormatFromAttributes.java fails on Rhel_5
jgodinez
parents: 2386
diff changeset
   676
            if ((flavor != null) &&
b8a16aa12f0b 6848799: Reg-test java/awt/print/PageFormat/PageFormatFromAttributes.java fails on Rhel_5
jgodinez
parents: 2386
diff changeset
   677
                (flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
b8a16aa12f0b 6848799: Reg-test java/awt/print/PageFormat/PageFormatFromAttributes.java fails on Rhel_5
jgodinez
parents: 2386
diff changeset
   678
                 flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
b8a16aa12f0b 6848799: Reg-test java/awt/print/PageFormat/PageFormatFromAttributes.java fails on Rhel_5
jgodinez
parents: 2386
diff changeset
   679
                 flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) {
2386
7e59f81fd05b 6750383: 2D_PrintingTiger\PrintDocOrientationTest fails, wrong orientated images are printed
jgodinez
parents: 1737
diff changeset
   680
                return null;
7e59f81fd05b 6750383: 2D_PrintingTiger\PrintDocOrientationTest fails, wrong orientated images are printed
jgodinez
parents: 1737
diff changeset
   681
            }
7e59f81fd05b 6750383: 2D_PrintingTiger\PrintDocOrientationTest fails, wrong orientated images are printed
jgodinez
parents: 1737
diff changeset
   682
535
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   683
            boolean revPort = false;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   684
            OrientationRequested[] orientSup = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            AttributeClass attribClass = (getAttMap != null) ?
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   687
              getAttMap.get("orientation-requested-supported")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            if (attribClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                int[] orientArray = attribClass.getArrayOfIntValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                if ((orientArray != null) && (orientArray.length > 0)) {
535
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   692
                    orientSup =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                        new OrientationRequested[orientArray.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    for (int i=0; i<orientArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                        switch (orientArray[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                        case 3 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                            orientSup[i] = OrientationRequested.PORTRAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                        case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                            orientSup[i] = OrientationRequested.LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                        case 5:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                            orientSup[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                                OrientationRequested.REVERSE_LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                        case 6:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                            orientSup[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                                OrientationRequested.REVERSE_PORTRAIT;
535
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   710
                            revPort = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            }
535
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   716
            if (flavor == null ||
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   717
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   718
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   719
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   720
                if (revPort && flavor == null) {
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   721
                    OrientationRequested []orSup = new OrientationRequested[4];
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   722
                    orSup[0] = OrientationRequested.PORTRAIT;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   723
                    orSup[1] = OrientationRequested.LANDSCAPE;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   724
                    orSup[2] = OrientationRequested.REVERSE_LANDSCAPE;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   725
                    orSup[3] = OrientationRequested.REVERSE_PORTRAIT;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   726
                    return orSup;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   727
                } else {
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   728
                    OrientationRequested []orSup = new OrientationRequested[3];
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   729
                    orSup[0] = OrientationRequested.PORTRAIT;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   730
                    orSup[1] = OrientationRequested.LANDSCAPE;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   731
                    orSup[2] = OrientationRequested.REVERSE_LANDSCAPE;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   732
                    return orSup;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   733
                }
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   734
            } else {
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   735
                return orientSup;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
   736
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        } else if (category == PageRanges.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
           if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                PageRanges []arr = new PageRanges[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                arr[0] = new PageRanges(1, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                // Returning null as this is not yet supported in UnixPrintJob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        } else if (category == RequestingUserName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            String userName = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
              userName = System.getProperty("user.name", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            return new RequestingUserName(userName, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        } else if (category == Sides.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            // The printer takes care of Sides so if short-edge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            // is chosen in a job, the rotation is done by the printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            // Orientation is rotated by emulation if pageable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            // or printable so if the document is in Landscape, this may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            // result in double rotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            AttributeClass attribClass = (getAttMap != null) ?
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   762
                getAttMap.get("sides-supported")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            if (attribClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                String[] sidesArray = attribClass.getArrayOfStringValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                if ((sidesArray != null) && (sidesArray.length > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                    Sides[] sidesSup = new Sides[sidesArray.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                    for (int i=0; i<sidesArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                        if (sidesArray[i].endsWith("long-edge")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                            sidesSup[i] = Sides.TWO_SIDED_LONG_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                        } else if (sidesArray[i].endsWith("short-edge")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                            sidesSup[i] = Sides.TWO_SIDED_SHORT_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                            sidesSup[i] = Sides.ONE_SIDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                    return sidesSup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            }
25774
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   780
        } else if (category == PrinterResolution.class) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   781
            PrinterResolution[] supportedRes = getPrintResolutions();
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   782
            if (supportedRes == null) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   783
                return null;
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   784
            }
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   785
            PrinterResolution []arr =
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   786
                new PrinterResolution[supportedRes.length];
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   787
            System.arraycopy(supportedRes, 0, arr, 0, supportedRes.length);
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
   788
            return arr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    //This class is for getting all pre-defined Finishings
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23287
diff changeset
   795
    @SuppressWarnings("serial") // JDK implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    private class ExtFinishing extends Finishings {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        ExtFinishing(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            super(100); // 100 to avoid any conflicts with predefined values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        EnumSyntax[] getAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            EnumSyntax[] es = super.getEnumValueTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            return es;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                                                 AttributeSet attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        if (flavor != null && !isDocFlavorSupported(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            throw new IllegalArgumentException("flavor " + flavor +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                                               "is not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        Attribute attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        AttributeSet unsupp = new HashAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        Attribute []attrs = attributes.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        for (int i=0; i<attrs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                attr = attrs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                if (!isAttributeCategorySupported(attr.getCategory())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                    unsupp.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                } else if (!isAttributeValueSupported(attr, flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                                                      attributes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                    unsupp.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        if (unsupp.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            return unsupp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    public synchronized DocFlavor[] getSupportedDocFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        if (supportedDocFlavors != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            int len = supportedDocFlavors.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                DocFlavor[] copyflavors = new DocFlavor[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                System.arraycopy(supportedDocFlavors, 0, copyflavors, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                return copyflavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        initAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        if ((getAttMap != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            getAttMap.containsKey("document-format-supported")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            AttributeClass attribClass =
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   856
                getAttMap.get("document-format-supported");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            if (attribClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                String mimeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                boolean psSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                String[] docFlavors = attribClass.getArrayOfStringValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                DocFlavor[] flavors;
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   862
                HashSet<Object> docList = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                String hostEnc = DocFlavor.hostEncoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                    toLowerCase(Locale.ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                boolean addHostEncoding = !hostEnc.equals("utf-8") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                    !hostEnc.equals("utf-16") && !hostEnc.equals("utf-16be") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                    !hostEnc.equals("utf-16le") && !hostEnc.equals("us-ascii");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                for (int i = 0; i < docFlavors.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                    for (j=0; j<allDocFlavors.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                        flavors = (DocFlavor[])allDocFlavors[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                        mimeType = flavors[0].getMimeType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                        if (mimeType.startsWith(docFlavors[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                            docList.addAll(Arrays.asList(flavors));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                            if (mimeType.equals("text/plain") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                                addHostEncoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                                docList.add(Arrays.asList(textPlainHost));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                            } else if (mimeType.equals("text/html") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                                       addHostEncoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                                docList.add(Arrays.asList(textHtmlHost));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                            } else if (mimeType.equals("image/png")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                                pngImagesAdded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                            } else if (mimeType.equals("image/gif")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                                gifImagesAdded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                            } else if (mimeType.equals("image/jpeg")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                                jpgImagesAdded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                            } else if (mimeType.indexOf("postscript") != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                                psSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                    // Not added? Create new DocFlavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                    if (j == allDocFlavors.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                        //  make new DocFlavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                        docList.add(new DocFlavor.BYTE_ARRAY(docFlavors[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                        docList.add(new DocFlavor.INPUT_STREAM(docFlavors[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                        docList.add(new DocFlavor.URL(docFlavors[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                // check if we need to add image DocFlavors
1720
539a197aefbd 6731937: javax/print/CheckDupFlavor.java fails
jgodinez
parents: 542
diff changeset
   908
                // and Pageable/Printable flavors
542
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
   909
                if (psSupported || isCupsPrinter) {
1720
539a197aefbd 6731937: javax/print/CheckDupFlavor.java fails
jgodinez
parents: 542
diff changeset
   910
                    /*
539a197aefbd 6731937: javax/print/CheckDupFlavor.java fails
jgodinez
parents: 542
diff changeset
   911
                     Always add Pageable and Printable for CUPS
539a197aefbd 6731937: javax/print/CheckDupFlavor.java fails
jgodinez
parents: 542
diff changeset
   912
                     since it uses Filters to convert from Postscript
539a197aefbd 6731937: javax/print/CheckDupFlavor.java fails
jgodinez
parents: 542
diff changeset
   913
                     to device printer language.
539a197aefbd 6731937: javax/print/CheckDupFlavor.java fails
jgodinez
parents: 542
diff changeset
   914
                    */
539a197aefbd 6731937: javax/print/CheckDupFlavor.java fails
jgodinez
parents: 542
diff changeset
   915
                    docList.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
539a197aefbd 6731937: javax/print/CheckDupFlavor.java fails
jgodinez
parents: 542
diff changeset
   916
                    docList.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
539a197aefbd 6731937: javax/print/CheckDupFlavor.java fails
jgodinez
parents: 542
diff changeset
   917
539a197aefbd 6731937: javax/print/CheckDupFlavor.java fails
jgodinez
parents: 542
diff changeset
   918
                    docList.addAll(Arrays.asList(imageJPG));
539a197aefbd 6731937: javax/print/CheckDupFlavor.java fails
jgodinez
parents: 542
diff changeset
   919
                    docList.addAll(Arrays.asList(imagePNG));
539a197aefbd 6731937: javax/print/CheckDupFlavor.java fails
jgodinez
parents: 542
diff changeset
   920
                    docList.addAll(Arrays.asList(imageGIF));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                supportedDocFlavors = new DocFlavor[docList.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                docList.toArray(supportedDocFlavors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                int len = supportedDocFlavors.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                DocFlavor[] copyflavors = new DocFlavor[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                System.arraycopy(supportedDocFlavors, 0, copyflavors, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                return copyflavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        }
34810
73f1464a9612 8040139: Test closed/javax/print/attribute/Services_getDocFl.java fails with NullpointerException
psadhukhan
parents: 33860
diff changeset
   930
        DocFlavor[] flavor = new DocFlavor[2];
73f1464a9612 8040139: Test closed/javax/print/attribute/Services_getDocFl.java fails with NullpointerException
psadhukhan
parents: 33860
diff changeset
   931
        flavor[0] = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
73f1464a9612 8040139: Test closed/javax/print/attribute/Services_getDocFl.java fails with NullpointerException
psadhukhan
parents: 33860
diff changeset
   932
        flavor[1] = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
36861
6bbb00025fc9 8034239: PrintServiceLookup.lookupPrintServices() returns different amount of services in comparison with lpstat -v
psadhukhan
parents: 34810
diff changeset
   933
        supportedDocFlavors = flavor;
34810
73f1464a9612 8040139: Test closed/javax/print/attribute/Services_getDocFl.java fails with NullpointerException
psadhukhan
parents: 33860
diff changeset
   934
        return flavor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    public boolean isDocFlavorSupported(DocFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        if (supportedDocFlavors == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            getSupportedDocFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        if (supportedDocFlavors != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            for (int f=0; f<supportedDocFlavors.length; f++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                if (flavor.equals(supportedDocFlavors[f])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * Finds matching CustomMediaSizeName of given media.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    public CustomMediaSizeName findCustomMedia(MediaSizeName media) {
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
   957
        if (customMediaSizeNames == null) {
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
   958
            return null;
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
   959
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        for (int i=0; i< customMediaSizeNames.length; i++) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21780
diff changeset
   961
            CustomMediaSizeName custom = customMediaSizeNames[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            MediaSizeName msn = custom.getStandardMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            if (media.equals(msn)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                return customMediaSizeNames[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * Returns the matching standard Media using string comparison of names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    private Media getIPPMedia(String mediaName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        CustomMediaSizeName sampleSize = new CustomMediaSizeName("sample", "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                                                                 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        Media[] sizes = sampleSize.getSuperEnumTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        for (int i=0; i<sizes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            if (mediaName.equals(""+sizes[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                return sizes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        CustomMediaTray sampleTray = new CustomMediaTray("sample", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        Media[] trays = sampleTray.getSuperEnumTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        for (int i=0; i<trays.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            if (mediaName.equals(""+trays[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                return trays[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    private Media[] getSupportedMedia() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        if ((getAttMap != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            getAttMap.containsKey("media-supported")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   997
            AttributeClass attribClass = getAttMap.get("media-supported");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            if (attribClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                String[] mediaVals = attribClass.getArrayOfStringValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                Media msn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                Media[] mediaNames =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                    new Media[mediaVals.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                for (int i=0; i<mediaVals.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                    msn = getIPPMedia(mediaVals[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                    //REMIND: if null, create custom?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                    mediaNames[i] = msn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                return mediaNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        return new Media[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1016
    public synchronized Class<?>[] getSupportedAttributeCategories() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        if (supportedCats != null) {
27082
7ab1aa5e8713 8035162: Service printing service
prr
parents: 25859
diff changeset
  1018
            Class<?> [] copyCats = new Class<?>[supportedCats.length];
7ab1aa5e8713 8035162: Service printing service
prr
parents: 25859
diff changeset
  1019
            System.arraycopy(supportedCats, 0, copyCats, 0, copyCats.length);
7ab1aa5e8713 8035162: Service printing service
prr
parents: 25859
diff changeset
  1020
            return copyCats;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        initAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1025
        ArrayList<Class<?>> catList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        for (int i=0; i < printReqAttribDefault.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            PrintRequestAttribute pra =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                (PrintRequestAttribute)printReqAttribDefault[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            if (getAttMap != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                getAttMap.containsKey(pra.getName()+"-supported")) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1032
                catList.add(pra.getCategory());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        // Some IPP printers like lexc710 do not have list of supported media
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        // but CUPS can get the media from PPD, so we still report as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        // supported category.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        if (isCupsPrinter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            if (!catList.contains(Media.class)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                catList.add(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            // Always add MediaPrintable for cups,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            // because we can get it from PPD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            catList.add(MediaPrintableArea.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            // this is already supported in UnixPrintJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            catList.add(Destination.class);
17676
d76d0c992e34 8012381: [macosx]Unable to print out the defined page for 2D_PrintingTiger/JTablePrintPageRangesTest
jgodinez
parents: 5506
diff changeset
  1050
d76d0c992e34 8012381: [macosx]Unable to print out the defined page for 2D_PrintingTiger/JTablePrintPageRangesTest
jgodinez
parents: 5506
diff changeset
  1051
            // It is unfortunate that CUPS doesn't provide a way to query
d76d0c992e34 8012381: [macosx]Unable to print out the defined page for 2D_PrintingTiger/JTablePrintPageRangesTest
jgodinez
parents: 5506
diff changeset
  1052
            // if printer supports collation but since most printers
d76d0c992e34 8012381: [macosx]Unable to print out the defined page for 2D_PrintingTiger/JTablePrintPageRangesTest
jgodinez
parents: 5506
diff changeset
  1053
            // now supports collation and that most OS has a way
d76d0c992e34 8012381: [macosx]Unable to print out the defined page for 2D_PrintingTiger/JTablePrintPageRangesTest
jgodinez
parents: 5506
diff changeset
  1054
            // of setting it, it is a safe assumption to just always
d76d0c992e34 8012381: [macosx]Unable to print out the defined page for 2D_PrintingTiger/JTablePrintPageRangesTest
jgodinez
parents: 5506
diff changeset
  1055
            // include SheetCollate as supported attribute.
18752
2a4f599c6bff 8016737: After clicking on "Print UNCOLLATED" button, the print out come in order 'Page 1', 'Page 2', 'Page 1'
jgodinez
parents: 17676
diff changeset
  1056
43089
05e2611ebff6 8170352: The collate option is not checked
psadhukhan
parents: 40144
diff changeset
  1057
            catList.add(SheetCollate.class);
05e2611ebff6 8170352: The collate option is not checked
psadhukhan
parents: 40144
diff changeset
  1058
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        // With the assumption that  Chromaticity is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        // ColorSupported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        if (getAttMap != null && getAttMap.containsKey("color-supported")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            catList.add(Chromaticity.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        }
25774
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1066
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1067
        // CUPS does not report printer resolution via IPP but it
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1068
        // may be gleaned from the PPD.
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1069
        PrinterResolution[] supportedRes = getPrintResolutions();
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1070
        if (supportedRes != null && (supportedRes.length > 0)) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1071
            catList.add(PrinterResolution.class);
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1072
        }
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1073
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1074
        supportedCats = new Class<?>[catList.size()];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        catList.toArray(supportedCats);
27082
7ab1aa5e8713 8035162: Service printing service
prr
parents: 25859
diff changeset
  1076
        Class<?>[] copyCats = new Class<?>[supportedCats.length];
7ab1aa5e8713 8035162: Service printing service
prr
parents: 25859
diff changeset
  1077
        System.arraycopy(supportedCats, 0, copyCats, 0, copyCats.length);
7ab1aa5e8713 8035162: Service printing service
prr
parents: 25859
diff changeset
  1078
        return copyCats;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    public boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        isAttributeCategorySupported(Class<? extends Attribute> category)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            throw new NullPointerException("null category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        if (!(Attribute.class.isAssignableFrom(category))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            throw new IllegalArgumentException(category +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                                             " is not an Attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        if (supportedCats == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            getSupportedAttributeCategories();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
535
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1097
        // It is safe to assume that Orientation is always supported
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1098
        // and even if CUPS or an IPP device reports it as not,
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1099
        // our renderer can do portrait, landscape and
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1100
        // reverse landscape.
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1101
        if (category == OrientationRequested.class) {
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1102
            return true;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1103
        }
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1104
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        for (int i=0;i<supportedCats.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            if (category == supportedCats[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1114
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    public synchronized <T extends PrintServiceAttribute>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        T getAttribute(Class<T> category)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            throw new NullPointerException("category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            throw new IllegalArgumentException("Not a PrintServiceAttribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        initAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        if (category == PrinterName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            return (T)(new PrinterName(printer, null));
19013
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1129
        } else if (category == PrinterInfo.class) {
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1130
            PrinterInfo pInfo = new PrinterInfo(printer, null);
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1131
            AttributeClass ac = (getAttMap != null) ?
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1132
                getAttMap.get(pInfo.getName())
19013
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1133
                : null;
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1134
            if (ac != null) {
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1135
                return (T)(new PrinterInfo(ac.getStringValue(), null));
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1136
            }
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1137
            return (T)pInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        } else if (category == QueuedJobCount.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            QueuedJobCount qjc = new QueuedJobCount(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            AttributeClass ac = (getAttMap != null) ?
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1141
                getAttMap.get(qjc.getName())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                qjc = new QueuedJobCount(ac.getIntValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            return (T)qjc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        } else if (category == PrinterIsAcceptingJobs.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            PrinterIsAcceptingJobs accJob =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                PrinterIsAcceptingJobs.ACCEPTING_JOBS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            AttributeClass ac = (getAttMap != null) ?
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1151
                getAttMap.get(accJob.getName())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            if ((ac != null) && (ac.getByteValue() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                accJob = PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            return (T)accJob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        } else if (category == ColorSupported.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            ColorSupported cs = ColorSupported.SUPPORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            AttributeClass ac = (getAttMap != null) ?
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1160
                getAttMap.get(cs.getName())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            if ((ac != null) && (ac.getByteValue() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                cs = ColorSupported.NOT_SUPPORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            return (T)cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        } else if (category == PDLOverrideSupported.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            if (isCupsPrinter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                // Documented: For CUPS this will always be false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                return (T)PDLOverrideSupported.NOT_ATTEMPTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                // REMIND: check attribute values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                return (T)PDLOverrideSupported.NOT_ATTEMPTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            }
21224
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 19013
diff changeset
  1175
        } else if (category == PrinterURI.class) {
58a31574ac84 8022536: closed/javax/print/TextFlavorTest.java fails
jgodinez
parents: 19013
diff changeset
  1176
            return (T)(new PrinterURI(myURI));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    public synchronized PrintServiceAttributeSet getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        // update getAttMap by sending again get-attributes IPP request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        init = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        initAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        HashPrintServiceAttributeSet attrs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            new HashPrintServiceAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        for (int i=0; i < serviceAttributes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            String name = (String)serviceAttributes[i][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            if (getAttMap != null && getAttMap.containsKey(name)) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1194
                @SuppressWarnings("unchecked")
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1195
                Class<PrintServiceAttribute> c = (Class<PrintServiceAttribute>)serviceAttributes[i][0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                PrintServiceAttribute psa = getAttribute(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                if (psa != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                    attrs.add(psa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        return AttributeSetUtilities.unmodifiableView(attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    public boolean isIPPSupportedImages(String mimeType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        if (supportedDocFlavors == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            getSupportedDocFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        if (mimeType.equals("image/png") && pngImagesAdded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        } else if (mimeType.equals("image/gif") && gifImagesAdded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        } else if (mimeType.equals("image/jpeg") && jpgImagesAdded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    private boolean isSupportedCopies(Copies copies) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        CopiesSupported cs = (CopiesSupported)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            getSupportedAttributeValues(Copies.class, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        int[][] members = cs.getMembers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        int min, max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        if ((members.length > 0) && (members[0].length > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            min = members[0][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            max = members[0][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            min = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            max = MAXCOPIES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        int value = copies.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        return (value >= min && value <= max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    private boolean isAutoSense(DocFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        if (flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            flavor.equals(DocFlavor.URL.AUTOSENSE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    private synchronized boolean isSupportedMediaTray(MediaTray msn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        initAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        if (mediaTrays != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            for (int i=0; i<mediaTrays.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
               if (msn.equals(mediaTrays[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    private synchronized boolean isSupportedMedia(MediaSizeName msn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        initAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        if (msn.equals((Media)getDefaultAttributeValue(Media.class))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        for (int i=0; i<mediaSizeNames.length; i++) {
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
  1270
            debug_println(debugPrefix+"isSupportedMedia, mediaSizeNames[i] "+mediaSizeNames[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            if (msn.equals(mediaSizeNames[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    /* Return false if flavor is not null, pageable, nor printable and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * Destination is part of attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    private boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        isDestinationSupported(DocFlavor flavor, AttributeSet attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            if ((attributes != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                    (attributes.get(Destination.class) != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                    !(flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                      flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                      flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
  1295
    public boolean isAttributeValueSupported(Attribute attr,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                                             DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                                             AttributeSet attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            throw new NullPointerException("null attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        if (flavor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            if (!isDocFlavorSupported(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                throw new IllegalArgumentException(flavor +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                                               " is an unsupported flavor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            } else if (isAutoSense(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        }
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1309
        Class<? extends Attribute> category = attr.getCategory();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        if (!isAttributeCategorySupported(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        /* Test if the flavor is compatible with the attributes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        if (!isDestinationSupported(flavor, attributes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        /* Test if the flavor is compatible with the category */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        if (attr.getCategory() == Chromaticity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            if ((flavor == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) ||
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
  1324
                !isIPPSupportedImages(flavor.getMimeType())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                return attr == Chromaticity.COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        } else if (attr.getCategory() == Copies.class) {
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
  1330
            return (flavor == null ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
  1331
                   !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
  1332
                   flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
  1333
                   flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) &&
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
  1334
                isSupportedCopies((Copies)attr);
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 1722
diff changeset
  1335
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        } else if (attr.getCategory() == Destination.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                URI uri = ((Destination)attr).getURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                if ("file".equals(uri.getScheme()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                    !(uri.getSchemeSpecificPart().equals(""))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        } else if (attr.getCategory() == Media.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            if (attr instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                return isSupportedMedia((MediaSizeName)attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            if (attr instanceof MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
                return isSupportedMediaTray((MediaTray)attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        } else if (attr.getCategory() == PageRanges.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
            if (flavor != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        } else if (attr.getCategory() == SheetCollate.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            if (flavor != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        } else if (attr.getCategory() == Sides.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            Sides[] sidesArray = (Sides[])getSupportedAttributeValues(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                                          Sides.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                                          flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                                          attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            if (sidesArray != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                for (int i=0; i<sidesArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                    if (sidesArray[i] == (Sides)attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        } else if (attr.getCategory() == OrientationRequested.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            OrientationRequested[] orientArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                (OrientationRequested[])getSupportedAttributeValues(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                                          OrientationRequested.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                                          flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                                          attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            if (orientArray != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                for (int i=0; i<orientArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                    if (orientArray[i] == (OrientationRequested)attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
            return false;
25774
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1395
        } if (attr.getCategory() == PrinterResolution.class) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1396
            if (attr instanceof PrinterResolution) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1397
                return isSupportedResolution((PrinterResolution)attr);
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1398
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
    public synchronized Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        getDefaultAttributeValue(Class<? extends Attribute> category)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
            throw new NullPointerException("null category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        if (!Attribute.class.isAssignableFrom(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            throw new IllegalArgumentException(category +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                                             " is not an Attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        if (!isAttributeCategorySupported(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        initAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        String catName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        for (int i=0; i < printReqAttribDefault.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            PrintRequestAttribute pra =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                (PrintRequestAttribute)printReqAttribDefault[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            if (pra.getCategory() == category) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                catName = pra.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        String attribName = catName+"-default";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        AttributeClass attribClass = (getAttMap != null) ?
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1431
                getAttMap.get(attribName) : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        if (category == Copies.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            if (attribClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                return new Copies(attribClass.getIntValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                return new Copies(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        } else if (category == Chromaticity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            return Chromaticity.COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        } else if (category == Destination.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                return new Destination((new File("out.ps")).toURI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                    return new Destination(new URI("file:out.ps"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                } catch (URISyntaxException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        } else if (category == Fidelity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
            return Fidelity.FIDELITY_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        } else if (category == Finishings.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
            return Finishings.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        } else if (category == JobName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
            return new JobName("Java Printing", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
        } else if (category == JobSheets.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            if (attribClass != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                attribClass.getStringValue().equals("none")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                return JobSheets.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                return JobSheets.STANDARD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        } else if (category == Media.class) {
25555
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
  1465
            if (defaultMediaIndex == -1) {
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
  1466
                defaultMediaIndex = 0;
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
  1467
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            if (mediaSizeNames.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                String defaultCountry = Locale.getDefault().getCountry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                if (defaultCountry != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                    (defaultCountry.equals("") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                     defaultCountry.equals(Locale.US.getCountry()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                     defaultCountry.equals(Locale.CANADA.getCountry()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                    return MediaSizeName.NA_LETTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                    return MediaSizeName.ISO_A4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            if (attribClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                String name = attribClass.getStringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                if (isCupsPrinter) {
25555
b70a66b5b942 7067052: Default printer media is ignored
jgodinez
parents: 25140
diff changeset
  1483
                    return mediaSizeNames[defaultMediaIndex];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                    for (int i=0; i< mediaSizeNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                        if (mediaSizeNames[i].toString().indexOf(name) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                            defaultMediaIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                            return mediaSizeNames[defaultMediaIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            return mediaSizeNames[defaultMediaIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        } else if (category == MediaPrintableArea.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
            MediaPrintableArea[] mpas;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
             if ((cps != null)  &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                 ((mpas = cps.getMediaPrintableArea()) != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                 if (defaultMediaIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                     // initializes value of defaultMediaIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                     getDefaultAttributeValue(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                 return mpas[defaultMediaIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
             } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                 String defaultCountry = Locale.getDefault().getCountry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                 float iw, ih;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                 if (defaultCountry != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
                     (defaultCountry.equals("") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                      defaultCountry.equals(Locale.US.getCountry()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                      defaultCountry.equals(Locale.CANADA.getCountry()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                     iw = MediaSize.NA.LETTER.getX(Size2DSyntax.INCH) - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                     ih = MediaSize.NA.LETTER.getY(Size2DSyntax.INCH) - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                 } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                     iw = MediaSize.ISO.A4.getX(Size2DSyntax.INCH) - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                     ih = MediaSize.ISO.A4.getY(Size2DSyntax.INCH) - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                 return new MediaPrintableArea(0.25f, 0.25f, iw, ih,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                                               MediaPrintableArea.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        } else if (category == NumberUp.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
            return new NumberUp(1); // for CUPS this is always 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        } else if (category == OrientationRequested.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
            if (attribClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                switch (attribClass.getIntValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                case 3: return OrientationRequested.PORTRAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                case 4: return OrientationRequested.LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                case 5: return OrientationRequested.REVERSE_LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                case 6: return OrientationRequested.REVERSE_PORTRAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                return OrientationRequested.PORTRAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        } else if (category == PageRanges.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
            if (attribClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                int[] range = attribClass.getIntRangeValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                return new PageRanges(range[0], range[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                return new PageRanges(1, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        } else if (category == RequestingUserName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
            String userName = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
              userName = System.getProperty("user.name", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
            return new RequestingUserName(userName, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        } else if (category == SheetCollate.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
            return SheetCollate.UNCOLLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        } else if (category == Sides.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            if (attribClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                if (attribClass.getStringValue().endsWith("long-edge")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                    return Sides.TWO_SIDED_LONG_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                } else if (attribClass.getStringValue().endsWith(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                                                           "short-edge")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                    return Sides.TWO_SIDED_SHORT_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
            return Sides.ONE_SIDED;
25774
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1560
        } else if (category == PrinterResolution.class) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1561
             PrinterResolution[] supportedRes = getPrintResolutions();
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1562
             if ((supportedRes != null) && (supportedRes.length > 0)) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1563
                return supportedRes[0];
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1564
             } else {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1565
                 return new PrinterResolution(300, 300, PrinterResolution.DPI);
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1566
             }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
25774
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1572
    private PrinterResolution[] getPrintResolutions() {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1573
        if (printerResolutions == null) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1574
            if (rawResolutions == null) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1575
              printerResolutions = new PrinterResolution[0];
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1576
            } else {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1577
                int numRes = rawResolutions.length / 2;
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1578
                PrinterResolution[] pres = new PrinterResolution[numRes];
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1579
                for (int i=0; i < numRes; i++) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1580
                    pres[i] =  new PrinterResolution(rawResolutions[i*2],
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1581
                                                     rawResolutions[i*2+1],
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1582
                                                     PrinterResolution.DPI);
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1583
                }
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1584
                printerResolutions = pres;
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1585
            }
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1586
        }
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1587
        return printerResolutions;
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1588
    }
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1589
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1590
    private boolean isSupportedResolution(PrinterResolution res) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1591
        PrinterResolution[] supportedRes = getPrintResolutions();
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1592
        if (supportedRes != null) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1593
            for (int i=0; i<supportedRes.length; i++) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1594
                if (res.equals(supportedRes[i])) {
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1595
                    return true;
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1596
                }
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1597
            }
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1598
        }
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1599
        return false;
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1600
    }
21b78da4b2df 8048328: CUPS Printing does not report supported printer resolutions.
prr
parents: 25555
diff changeset
  1601
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
    public ServiceUIFactory getServiceUIFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
    public void wakeNotifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
            if (notifier != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
                notifier.wake();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
    public void addPrintServiceAttributeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                                 PrintServiceAttributeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
            if (listener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
            if (notifier == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                notifier = new ServiceNotifier(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
            notifier.addListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
    public void removePrintServiceAttributeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                                  PrintServiceAttributeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            if (listener == null || notifier == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
            notifier.removeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
            if (notifier.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                notifier.stopNotifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                notifier = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
19013
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1641
    String getDest() {
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1642
        return printer;
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1643
    }
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1644
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
    public String getName() {
19013
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1646
        /*
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1647
         * Mac is using printer-info IPP attribute for its human-readable printer
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1648
         * name and is also the identifier used in NSPrintInfo:setPrinter.
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1649
         */
27269
1ef2879dc7ad 8055705: Rename UnixPrintServiceLookup and Win32PrintServiceLookup as a platform neutral class name
prr
parents: 25859
diff changeset
  1650
        if (PrintServiceLookupProvider.isMac()) {
19013
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1651
            PrintServiceAttributeSet psaSet = this.getAttributes();
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1652
            if (psaSet != null) {
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1653
                PrinterInfo pName = (PrinterInfo)psaSet.get(PrinterInfo.class);
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1654
                if (pName != null) {
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1655
                    return pName.toString();
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1656
                }
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1657
            }
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 18752
diff changeset
  1658
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
        return printer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1663
    public boolean usesClass(Class<?> c) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        return (c == sun.print.PSPrinterJob.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    public static HttpURLConnection getIPPConnection(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
        HttpURLConnection connection;
21780
aa006e1a6eb9 8028584: sun.net.www.protocol.file.FileURLConnection cannot be cast to java.net.HttpURLConnection
jgodinez
parents: 21224
diff changeset
  1670
        URLConnection urlc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
        try {
21780
aa006e1a6eb9 8028584: sun.net.www.protocol.file.FileURLConnection cannot be cast to java.net.HttpURLConnection
jgodinez
parents: 21224
diff changeset
  1672
            urlc = url.openConnection();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
        } catch (java.io.IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        }
21780
aa006e1a6eb9 8028584: sun.net.www.protocol.file.FileURLConnection cannot be cast to java.net.HttpURLConnection
jgodinez
parents: 21224
diff changeset
  1676
        if (!(urlc instanceof HttpURLConnection)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
        }
21780
aa006e1a6eb9 8028584: sun.net.www.protocol.file.FileURLConnection cannot be cast to java.net.HttpURLConnection
jgodinez
parents: 21224
diff changeset
  1679
        connection = (HttpURLConnection)urlc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
        connection.setUseCaches(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
        connection.setDoInput(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        connection.setDoOutput(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        connection.setRequestProperty("Content-type", "application/ipp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
        return connection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
    public synchronized boolean isPostscript() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
        if (isPS == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
           isPS = Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            if (isCupsPrinter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                    urlConnection = getIPPConnection(
542
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
  1694
                                             new URL(myURL+".ppd"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                   InputStream is = urlConnection.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
                   if (is != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
                       BufferedReader d =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
                           new BufferedReader(new InputStreamReader(is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
                                                          Charset.forName("ISO-8859-1")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                       String lineStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                       while ((lineStr = d.readLine()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                           if (lineStr.startsWith("*cupsFilter:")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                               isPS = Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
                } catch (java.io.IOException e) {
542
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
  1710
                    debug_println(" isPostscript, e= "+e);
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
  1711
                    /* if PPD is not found, this may be a raw printer
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
  1712
                       and in this case it is assumed that it is a
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
  1713
                       Postscript printer */
eb75700cdf75 6678161: Printing to remote non-Postscript printer does not work in Linux
jgodinez
parents: 535
diff changeset
  1714
                    // do nothing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
        return isPS.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
    private void opGetAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
            debug_println(debugPrefix+"opGetAttributes myURI "+myURI+" myURL "+myURL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
            AttributeClass attClNoUri[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                AttributeClass.ATTRIBUTES_CHARSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
            AttributeClass attCl[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                AttributeClass.ATTRIBUTES_CHARSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
                new AttributeClass("printer-uri",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
                                   AttributeClass.TAG_URI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
                                   ""+myURI)};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1737
            OutputStream os = java.security.AccessController.
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1738
                doPrivileged(new java.security.PrivilegedAction<OutputStream>() {
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1739
                    public OutputStream run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
                            return urlConnection.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
            if (os == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
            boolean success = (myURI == null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                writeIPPRequest(os, OP_GET_ATTRIBUTES, attClNoUri) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                writeIPPRequest(os, OP_GET_ATTRIBUTES, attCl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
            if (success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                InputStream is = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                if ((is = urlConnection.getInputStream())!=null) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1758
                    HashMap<String, AttributeClass>[] responseMap = readIPPResponse(is);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
                    if (responseMap != null && responseMap.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                        getAttMap = responseMap[0];
43723
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
  1762
                        // If there is extra hashmap created due to duplicate
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
  1763
                        // key/attribute present in IPPresponse, then use that
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
  1764
                        // map too by appending to getAttMap after removing the
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
  1765
                        // duplicate key/value
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
  1766
                        if (responseMap.length > 1) {
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
  1767
                            for (int i = 1; i < responseMap.length; i++) {
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
  1768
                                for (Map.Entry<String, AttributeClass> entry : responseMap[i].entrySet()) {
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
  1769
                                    if (!getAttMap.containsKey(entry.getValue())) {
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
  1770
                                        getAttMap.put(entry.getKey(), entry.getValue());
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
  1771
                                    }
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
  1772
                                }
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
  1773
                            }
f7a55f9b9bf5 8170578: CUPS Printing is broken with Ubuntu 16.10 (CUPS 2.2)
psadhukhan
parents: 43089
diff changeset
  1774
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                    debug_println(debugPrefix+"opGetAttributes - null input stream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
                is.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            os.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        } catch (java.io.IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
            debug_println(debugPrefix+"opGetAttributes - input/output stream: "+e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
    public static boolean writeIPPRequest(OutputStream os,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                                           String operCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
                                           AttributeClass[] attCl) {
535
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1791
        OutputStreamWriter osw;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1792
        try {
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1793
            osw = new OutputStreamWriter(os, "UTF-8");
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1794
        } catch (java.io.UnsupportedEncodingException exc) {
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
  1795
            debug_println(debugPrefix+"writeIPPRequest, UTF-8 not supported? Exception: "+exc);
535
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1796
            return false;
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1797
        }
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
  1798
        debug_println(debugPrefix+"writeIPPRequest, op code= "+operCode);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
        char[] opCode =  new char[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
        opCode[0] =  (char)Byte.parseByte(operCode.substring(0,2), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
        opCode[1] =  (char)Byte.parseByte(operCode.substring(2,4), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
        char[] bytes = {0x01, 0x01, 0x00, 0x01};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
            osw.write(bytes, 0, 2); // version number
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
            osw.write(opCode, 0, 2); // operation code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
            bytes[0] = 0x00; bytes[1] = 0x00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
            osw.write(bytes, 0, 4); // request ID #1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
            bytes[0] = 0x01; // operation-group-tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            osw.write(bytes[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
            String valStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
            char[] lenStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
            AttributeClass ac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
            for (int i=0; i < attCl.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                ac = attCl[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                osw.write(ac.getType()); // value tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                lenStr = ac.getLenChars();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                osw.write(lenStr, 0, 2); // length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
                osw.write(""+ac, 0, ac.getName().length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                // check if string range (0x35 -> 0x49)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                if (ac.getType() >= AttributeClass.TAG_TEXT_LANGUAGE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                    ac.getType() <= AttributeClass.TAG_MIME_MEDIATYPE){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                    valStr = (String)ac.getObjectValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                    bytes[0] = 0; bytes[1] = (char)valStr.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                    osw.write(bytes, 0, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                    osw.write(valStr, 0, valStr.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                } // REMIND: need to support other value tags but for CUPS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                // string is all we need.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
            osw.write(GRPTAG_END_ATTRIBUTES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
            osw.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
            osw.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
        } catch (java.io.IOException ioe) {
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
  1839
            debug_println(debugPrefix+"writeIPPRequest, IPPPrintService Exception in writeIPPRequest: "+ioe);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1846
    public static HashMap<String, AttributeClass>[] readIPPResponse(InputStream inputStream) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
        if (inputStream == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
        byte response[] = new byte[MAX_ATTRIBUTE_LENGTH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
            DataInputStream ois = new DataInputStream(inputStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
            // read status and ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
            if ((ois.read(response, 0, 8) > -1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                (response[2] == STATUSCODE_SUCCESS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
                ByteArrayOutputStream outObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                int counter=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
                short len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
                String attribStr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
                // assign default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                byte valTagByte = AttributeClass.TAG_KEYWORD;
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1867
                ArrayList<HashMap<String, AttributeClass>> respList = new ArrayList<>();
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1868
                HashMap<String, AttributeClass> responseMap = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
                response[0] = ois.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                // check for group tags
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
                while ((response[0] >= GRPTAG_OP_ATTRIBUTES) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                       (response[0] <= GRPTAG_PRINTER_ATTRIBUTES)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                          && (response[0] != GRPTAG_END_ATTRIBUTES)) {
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
  1876
                    debug_println(debugPrefix+"readIPPResponse, checking group tag,  response[0]= "+
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                                  response[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                    outObj = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                    //make sure counter and attribStr are re-initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                    counter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                    attribStr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                    // read value tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                    response[0] = ois.readByte();
535
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1886
                    while (response[0] >= AttributeClass.TAG_UNSUPPORTED_VALUE &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                           response[0] <= AttributeClass.TAG_MEMBER_ATTRNAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                        // read name length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                        len  = ois.readShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                        // If current value is not part of previous attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                        // then close stream and add it to HashMap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
                        // It is part of previous attribute if name length=0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
                        if ((len != 0) && (attribStr != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                            //last byte is the total # of values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                            outObj.write(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                            outObj.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                            outObj.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
                            byte outArray[] = outObj.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
                            // if key exists, new HashMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                            if (responseMap.containsKey(attribStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                                respList.add(responseMap);
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1904
                                responseMap = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
535
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1907
                            // exclude those that are unknown
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1908
                            if (valTagByte >= AttributeClass.TAG_INT) {
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1909
                                AttributeClass ac =
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1910
                                    new AttributeClass(attribStr,
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1911
                                                       valTagByte,
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1912
                                                       outArray);
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1913
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1914
                                responseMap.put(ac.getName(), ac);
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
  1915
                                debug_println(debugPrefix+ "readIPPResponse "+ac);
535
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
  1916
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                            outObj = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
                            counter = 0; //reset counter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
                        //check if this is new value tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
                        if (counter == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
                            valTagByte = response[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
                        // read attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
                        if (len != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
                            // read "len" characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
                            // make sure it doesn't exceed the maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
                            if (len > MAX_ATTRIBUTE_LENGTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
                                response = new byte[len]; // expand as needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
                            ois.read(response, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
                            attribStr = new String(response, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
                        // read value length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
                        len  = ois.readShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
                        // write name length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                        outObj.write(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                        // read value, make sure it doesn't exceed the maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                        if (len > MAX_ATTRIBUTE_LENGTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                            response = new byte[len]; // expand as needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                        ois.read(response, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
                        // write value of "len" length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
                        outObj.write(response, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                        counter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                        // read next byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
                        response[0] = ois.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                    if (attribStr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                        outObj.write(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                        outObj.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                        outObj.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                        // if key exists in old HashMap, new HashMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                        if ((counter != 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
                            responseMap.containsKey(attribStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
                            respList.add(responseMap);
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1960
                            responseMap = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
                        byte outArray[] = outObj.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
                        AttributeClass ac =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
                            new AttributeClass(attribStr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
                                               valTagByte,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
                                               outArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
                        responseMap.put(ac.getName(), ac);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
                ois.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
                if ((responseMap != null) && (responseMap.size() > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
                    respList.add(responseMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                }
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1976
                @SuppressWarnings({"unchecked", "rawtypes"})
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1977
                HashMap<String, AttributeClass>[] tmp  =
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1978
                    respList.toArray((HashMap<String, AttributeClass>[])new HashMap[respList.size()]);
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1979
                return tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                debug_println(debugPrefix+
23287
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents: 22584
diff changeset
  1982
                          "readIPPResponse client error, IPP status code: 0x"+
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents: 22584
diff changeset
  1983
                          toHex(response[2]) + toHex(response[3]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
        } catch (java.io.IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
            debug_println(debugPrefix+"readIPPResponse: "+e);
1737
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
  1989
            if (debugPrint) {
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
  1990
                e.printStackTrace();
90d4fe987b09 6653384: Variable "initialized" in class CUPSPrinter is static by mistake
jgodinez
parents: 1727
diff changeset
  1991
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
23287
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents: 22584
diff changeset
  1996
    private static String toHex(byte v) {
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents: 22584
diff changeset
  1997
        String s = Integer.toHexString(v&0xff);
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents: 22584
diff changeset
  1998
        return (s.length() == 2) ? s :  "0"+s;
c0f8cdafef56 8032693: javax.print.PrintService does not find any CUPS-Printers on Linux
prr
parents: 22584
diff changeset
  1999
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
        return "IPP Printer : " + getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
        return  (obj == this ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                 (obj instanceof IPPPrintService &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
                  ((IPPPrintService)obj).getName().equals(getName())));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
    }
1722
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents: 1721
diff changeset
  2010
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents: 1721
diff changeset
  2011
    public int hashCode() {
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents: 1721
diff changeset
  2012
        return this.getClass().hashCode()+getName().hashCode();
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents: 1721
diff changeset
  2013
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
}