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