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