jdk/src/solaris/classes/sun/print/UnixPrintService.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 1727 5e5e0235b14f
child 22603 816588059f9d
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1727
diff changeset
     2
 * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1727
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1727
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1727
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1727
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1727
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.print;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.URISyntaxException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.print.DocFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.print.DocPrintJob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.print.PrintService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.print.ServiceUIFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.print.attribute.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.print.attribute.AttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.print.attribute.AttributeSetUtilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.print.attribute.HashAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.print.attribute.PrintServiceAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.print.attribute.PrintServiceAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.print.attribute.HashPrintServiceAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.print.attribute.Size2DSyntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.print.attribute.standard.PrinterName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.print.attribute.standard.PrinterIsAcceptingJobs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.print.attribute.standard.QueuedJobCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.print.attribute.standard.JobName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.print.attribute.standard.JobSheets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.print.attribute.standard.RequestingUserName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.print.attribute.standard.Chromaticity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.print.attribute.standard.ColorSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.print.attribute.standard.Copies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.print.attribute.standard.CopiesSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.print.attribute.standard.Destination;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.print.attribute.standard.Fidelity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import javax.print.attribute.standard.Media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import javax.print.attribute.standard.MediaPrintableArea;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import javax.print.attribute.standard.MediaSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import javax.print.attribute.standard.MediaSizeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import javax.print.attribute.standard.OrientationRequested;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import javax.print.attribute.standard.PageRanges;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import javax.print.attribute.standard.PrinterState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import javax.print.attribute.standard.PrinterStateReason;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import javax.print.attribute.standard.PrinterStateReasons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import javax.print.attribute.standard.Severity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import javax.print.attribute.standard.SheetCollate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import javax.print.attribute.standard.Sides;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import javax.print.event.PrintServiceAttributeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
public class UnixPrintService implements PrintService, AttributeUpdater,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                         SunPrinterJobService {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /* define doc flavors for text types in the default encoding of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * this platform since we can always read those.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static String encoding = "ISO8859_1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static DocFlavor textByteFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static DocFlavor[] supportedDocFlavors = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final DocFlavor[] supportedDocFlavorsInit = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
         DocFlavor.BYTE_ARRAY.POSTSCRIPT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         DocFlavor.INPUT_STREAM.POSTSCRIPT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
         DocFlavor.URL.POSTSCRIPT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
         DocFlavor.BYTE_ARRAY.GIF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         DocFlavor.INPUT_STREAM.GIF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         DocFlavor.URL.GIF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         DocFlavor.BYTE_ARRAY.JPEG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         DocFlavor.INPUT_STREAM.JPEG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         DocFlavor.URL.JPEG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         DocFlavor.BYTE_ARRAY.PNG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         DocFlavor.INPUT_STREAM.PNG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         DocFlavor.URL.PNG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         DocFlavor.CHAR_ARRAY.TEXT_PLAIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         DocFlavor.READER.TEXT_PLAIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
         DocFlavor.STRING.TEXT_PLAIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
         DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
         DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_16BE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
         DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_16LE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         DocFlavor.BYTE_ARRAY.TEXT_PLAIN_US_ASCII,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
         DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_16BE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_16LE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         DocFlavor.URL.TEXT_PLAIN_UTF_8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         DocFlavor.URL.TEXT_PLAIN_UTF_16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
         DocFlavor.URL.TEXT_PLAIN_UTF_16BE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
         DocFlavor.URL.TEXT_PLAIN_UTF_16LE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         DocFlavor.URL.TEXT_PLAIN_US_ASCII,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         DocFlavor.SERVICE_FORMATTED.PAGEABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         DocFlavor.SERVICE_FORMATTED.PRINTABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
         DocFlavor.BYTE_ARRAY.AUTOSENSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         DocFlavor.URL.AUTOSENSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         DocFlavor.INPUT_STREAM.AUTOSENSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private static final DocFlavor[] supportedHostDocFlavors = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        DocFlavor.BYTE_ARRAY.TEXT_PLAIN_HOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        DocFlavor.URL.TEXT_PLAIN_HOST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    String[] lpcStatusCom = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
      "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
      "| grep -E '^[ 0-9a-zA-Z_-]*@' | awk '{print $2, $3}'"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    String[] lpcQueueCom = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
      "| grep -E '^[ 0-9a-zA-Z_-]*@' | awk '{print $4}'"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        encoding = java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            new sun.security.action.GetPropertyAction("file.encoding"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /* let's try to support a few of these */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private static final Class[] serviceAttrCats = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        PrinterName.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        PrinterIsAcceptingJobs.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        QueuedJobCount.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /*  it turns out to be inconvenient to store the other categories
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *  separately because many attributes are in multiple categories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private static final Class[] otherAttrCats = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        Chromaticity.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        Copies.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        Destination.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        Fidelity.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        JobName.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        JobSheets.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        Media.class, /* have to support this somehow ... */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        MediaPrintableArea.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        OrientationRequested.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        PageRanges.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        RequestingUserName.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        SheetCollate.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        Sides.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    private static int MAXCOPIES = 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    private static final MediaSizeName mediaSizes[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        MediaSizeName.NA_LETTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        MediaSizeName.TABLOID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        MediaSizeName.LEDGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        MediaSizeName.NA_LEGAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        MediaSizeName.EXECUTIVE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        MediaSizeName.ISO_A3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        MediaSizeName.ISO_A4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        MediaSizeName.ISO_A5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        MediaSizeName.ISO_B4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        MediaSizeName.ISO_B5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private String printer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private PrinterName name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private boolean isInvalid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    transient private PrintServiceAttributeSet lastSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    transient private ServiceNotifier notifier = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    UnixPrintService(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            throw new IllegalArgumentException("null printer name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        printer = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        isInvalid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public void invalidateService() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        isInvalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return printer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    private PrinterName getPrinterName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            name = new PrinterName(printer, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsSysV() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        String command = "/usr/bin/lpstat -a " + printer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        String results[]= UnixPrintServiceLookup.execCmd(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (results != null && results.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            if (results[0].startsWith(printer + " accepting requests")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            else if (results[0].startsWith(printer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                /* As well as "myprinter accepting requests", look for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                 * "myprinter@somehost accepting requests".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                int index = printer.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                String str = results[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                if (str.length() > index &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    str.charAt(index) == '@' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    str.indexOf(" accepting requests", index) > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    str.indexOf(" not accepting requests", index) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                   return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsBSD() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (UnixPrintServiceLookup.cmdIndex ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            UnixPrintServiceLookup.UNINITIALIZED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            UnixPrintServiceLookup.cmdIndex =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                UnixPrintServiceLookup.getBSDCommandIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        String command = "/usr/sbin/lpc status " + printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            + lpcStatusCom[UnixPrintServiceLookup.cmdIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        String results[]= UnixPrintServiceLookup.execCmd(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (results != null && results.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            if (UnixPrintServiceLookup.cmdIndex ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                UnixPrintServiceLookup.BSD_LPD_NG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                if (results[0].startsWith("enabled enabled")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    return PrinterIsAcceptingJobs.ACCEPTING_JOBS ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                if ((results[1].trim().startsWith("queuing is enabled") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    results[2].trim().startsWith("printing is enabled")) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    (results.length >= 4 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                     results[2].trim().startsWith("queuing is enabled") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                     results[3].trim().startsWith("printing is enabled"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    return PrinterIsAcceptingJobs.ACCEPTING_JOBS ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private PrinterIsAcceptingJobs getPrinterIsAcceptingJobs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (UnixPrintServiceLookup.isSysV()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            return getPrinterIsAcceptingJobsSysV();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        } else if (UnixPrintServiceLookup.isBSD()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            return getPrinterIsAcceptingJobsBSD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
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 PrinterState getPrinterState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (isInvalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            return PrinterState.STOPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    private PrinterStateReasons getPrinterStateReasons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (isInvalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            PrinterStateReasons psr = new PrinterStateReasons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            psr.put(PrinterStateReason.SHUTDOWN, Severity.ERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            return psr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    private QueuedJobCount getQueuedJobCountSysV() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        String command = "/usr/bin/lpstat -R " + printer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        String results[]= UnixPrintServiceLookup.execCmd(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        int qlen = (results == null) ? 0 : results.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return new QueuedJobCount(qlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    private QueuedJobCount getQueuedJobCountBSD() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        if (UnixPrintServiceLookup.cmdIndex ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            UnixPrintServiceLookup.UNINITIALIZED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            UnixPrintServiceLookup.cmdIndex =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                UnixPrintServiceLookup.getBSDCommandIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        int qlen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        String command = "/usr/sbin/lpc status " + printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            + lpcQueueCom[UnixPrintServiceLookup.cmdIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        String results[] = UnixPrintServiceLookup.execCmd(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (results != null && results.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            String queued;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            if (UnixPrintServiceLookup.cmdIndex ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                UnixPrintServiceLookup.BSD_LPD_NG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                queued = results[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                queued = results[3].trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                if (queued.startsWith("no")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    return new QueuedJobCount(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    queued = queued.substring(0, queued.indexOf(' '));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                qlen = Integer.parseInt(queued);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return new QueuedJobCount(qlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    private QueuedJobCount getQueuedJobCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (UnixPrintServiceLookup.isSysV()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            return getQueuedJobCountSysV();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        } else if (UnixPrintServiceLookup.isBSD()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            return getQueuedJobCountBSD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            return new QueuedJobCount(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    private PrintServiceAttributeSet getSysVServiceAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        attrs.add(getQueuedJobCountSysV());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        attrs.add(getPrinterIsAcceptingJobsSysV());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        return attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    private PrintServiceAttributeSet getBSDServiceAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        attrs.add(getQueuedJobCountBSD());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        attrs.add(getPrinterIsAcceptingJobsBSD());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    private boolean isSupportedCopies(Copies copies) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        int numCopies = copies.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return (numCopies > 0 && numCopies < MAXCOPIES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    private boolean isSupportedMedia(MediaSizeName msn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        for (int i=0; i<mediaSizes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            if (msn.equals(mediaSizes[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public DocPrintJob createPrintJob() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
      SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
      if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        security.checkPrintJobAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        return new UnixPrintJob(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    private PrintServiceAttributeSet getDynamicAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (UnixPrintServiceLookup.isSysV()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            return getSysVServiceAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            return getBSDServiceAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public PrintServiceAttributeSet getUpdatedAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        PrintServiceAttributeSet currSet = getDynamicAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        if (lastSet == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            lastSet = currSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            return AttributeSetUtilities.unmodifiableView(currSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            PrintServiceAttributeSet updates =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                new HashPrintServiceAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            Attribute []attrs = currSet.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            Attribute attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            for (int i=0; i<attrs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                attr = attrs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                if (!lastSet.containsValue(attr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    updates.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            lastSet = currSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            return AttributeSetUtilities.unmodifiableView(updates);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public void wakeNotifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            if (notifier != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                notifier.wake();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public void addPrintServiceAttributeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                 PrintServiceAttributeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            if (listener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            if (notifier == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                notifier = new ServiceNotifier(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            notifier.addListener(listener);
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 void removePrintServiceAttributeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                                  PrintServiceAttributeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            if (listener == null || notifier == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            notifier.removeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            if (notifier.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                notifier.stopNotifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                notifier = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    public <T extends PrintServiceAttribute>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        T getAttribute(Class<T> category)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            throw new NullPointerException("category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            throw new IllegalArgumentException("Not a PrintServiceAttribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        if (category == PrinterName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            return (T)getPrinterName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        } else if (category == PrinterState.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            return (T)getPrinterState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        } else if (category == PrinterStateReasons.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            return (T)getPrinterStateReasons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        } else if (category == QueuedJobCount.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            return (T)getQueuedJobCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        } else if (category == PrinterIsAcceptingJobs.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            return (T)getPrinterIsAcceptingJobs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    public PrintServiceAttributeSet getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        attrs.add(getPrinterName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        attrs.add(getPrinterIsAcceptingJobs());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        PrinterState prnState = getPrinterState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        if (prnState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            attrs.add(prnState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        PrinterStateReasons prnStateReasons = getPrinterStateReasons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (prnStateReasons != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            attrs.add(prnStateReasons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        attrs.add(getQueuedJobCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        return AttributeSetUtilities.unmodifiableView(attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    private void initSupportedDocFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        String hostEnc = DocFlavor.hostEncoding.toLowerCase(Locale.ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if (!hostEnc.equals("utf-8") && !hostEnc.equals("utf-16") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            !hostEnc.equals("utf-16be") && !hostEnc.equals("utf-16le") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            !hostEnc.equals("us-ascii")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            int len = supportedDocFlavorsInit.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            DocFlavor[] flavors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                new DocFlavor[len + supportedHostDocFlavors.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            // copy host encoding flavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            System.arraycopy(supportedHostDocFlavors, 0, flavors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                             len, supportedHostDocFlavors.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            System.arraycopy(supportedDocFlavorsInit, 0, flavors, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            supportedDocFlavors = flavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            supportedDocFlavors = supportedDocFlavorsInit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public DocFlavor[] getSupportedDocFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if (supportedDocFlavors == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            initSupportedDocFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        int len = supportedDocFlavors.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        DocFlavor[] flavors = new DocFlavor[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        System.arraycopy(supportedDocFlavors, 0, flavors, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        return flavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    public boolean isDocFlavorSupported(DocFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        if (supportedDocFlavors == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            initSupportedDocFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        for (int f=0; f<supportedDocFlavors.length; f++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            if (flavor.equals(supportedDocFlavors[f])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    public Class[] getSupportedAttributeCategories() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        int totalCats = otherAttrCats.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        Class [] cats = new Class[totalCats];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        System.arraycopy(otherAttrCats, 0, cats, 0, otherAttrCats.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        return cats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    public boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        isAttributeCategorySupported(Class<? extends Attribute> category)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            throw new NullPointerException("null category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if (!(Attribute.class.isAssignableFrom(category))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            throw new IllegalArgumentException(category +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                             " is not an Attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        for (int i=0;i<otherAttrCats.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            if (category == otherAttrCats[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    /* return defaults for all attributes for which there is a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    public Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        getDefaultAttributeValue(Class<? extends Attribute> category)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            throw new NullPointerException("null category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        if (!Attribute.class.isAssignableFrom(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            throw new IllegalArgumentException(category +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                                             " is not an Attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        if (!isAttributeCategorySupported(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        if (category == Copies.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            return new Copies(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        } else if (category == Chromaticity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            return Chromaticity.COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        } else if (category == Destination.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                return new Destination((new File("out.ps")).toURI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                    return new Destination(new URI("file:out.ps"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                } catch (URISyntaxException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        } else if (category == Fidelity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            return Fidelity.FIDELITY_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        } else if (category == JobName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            return new JobName("Java Printing", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        } else if (category == JobSheets.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            return JobSheets.STANDARD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        } else if (category == Media.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            String defaultCountry = Locale.getDefault().getCountry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            if (defaultCountry != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                (defaultCountry.equals("") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                 defaultCountry.equals(Locale.US.getCountry()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                 defaultCountry.equals(Locale.CANADA.getCountry()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                return MediaSizeName.NA_LETTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                 return MediaSizeName.ISO_A4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        } else if (category == MediaPrintableArea.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            String defaultCountry = Locale.getDefault().getCountry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            float iw, ih;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            if (defaultCountry != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                (defaultCountry.equals("") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                 defaultCountry.equals(Locale.US.getCountry()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                 defaultCountry.equals(Locale.CANADA.getCountry()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                iw = MediaSize.NA.LETTER.getX(Size2DSyntax.INCH) - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                ih = MediaSize.NA.LETTER.getY(Size2DSyntax.INCH) - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                iw = MediaSize.ISO.A4.getX(Size2DSyntax.INCH) - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                ih = MediaSize.ISO.A4.getY(Size2DSyntax.INCH) - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            return new MediaPrintableArea(0.25f, 0.25f, iw, ih,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                                          MediaPrintableArea.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        } else if (category == OrientationRequested.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            return OrientationRequested.PORTRAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        } else if (category == PageRanges.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            return new PageRanges(1, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        } else if (category == RequestingUserName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            String userName = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
              userName = System.getProperty("user.name", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            return new RequestingUserName(userName, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        } else if (category == SheetCollate.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            return SheetCollate.UNCOLLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        } else if (category == Sides.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            return Sides.ONE_SIDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    private boolean isAutoSense(DocFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if (flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            flavor.equals(DocFlavor.URL.AUTOSENSE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    public Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        getSupportedAttributeValues(Class<? extends Attribute> category,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                                    DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                                    AttributeSet attributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            throw new NullPointerException("null category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        if (!Attribute.class.isAssignableFrom(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            throw new IllegalArgumentException(category +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                                             " does not implement Attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        if (flavor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            if (!isDocFlavorSupported(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                throw new IllegalArgumentException(flavor +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                                               " is an unsupported flavor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            } else if (isAutoSense(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        if (!isAttributeCategorySupported(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        if (category == Chromaticity.class) {
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   689
            if (flavor == null || isServiceFormattedFlavor(flavor)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                Chromaticity[]arr = new Chromaticity[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                arr[0] = Chromaticity.COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                return (arr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        } else if (category == Destination.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                return new Destination((new File("out.ps")).toURI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                    return new Destination(new URI("file:out.ps"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                } catch (URISyntaxException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        } else if (category == JobName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            return new JobName("Java Printing", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        } else if (category == JobSheets.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            JobSheets arr[] = new JobSheets[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            arr[0] = JobSheets.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            arr[1] = JobSheets.STANDARD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        } else if (category == RequestingUserName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            String userName = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
              userName = System.getProperty("user.name", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            return new RequestingUserName(userName, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        } else if (category == OrientationRequested.class) {
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   721
            if (flavor == null || isServiceFormattedFlavor(flavor)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                OrientationRequested []arr = new OrientationRequested[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                arr[0] = OrientationRequested.PORTRAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                arr[1] = OrientationRequested.LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                arr[2] = OrientationRequested.REVERSE_LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        } else if ((category == Copies.class) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                   (category == CopiesSupported.class)) {
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   732
            if (flavor == null ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   733
                !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   734
                  flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   735
                  flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) {
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   736
                return new CopiesSupported(1, MAXCOPIES);
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   737
            } else {
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   738
                return null;
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   739
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        } else if (category == Media.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            Media []arr = new Media[mediaSizes.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            System.arraycopy(mediaSizes, 0, arr, 0, mediaSizes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        } else if (category == Fidelity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            Fidelity []arr = new Fidelity[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            arr[0] = Fidelity.FIDELITY_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            arr[1] = Fidelity.FIDELITY_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        } else if (category == MediaPrintableArea.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            /* The code below implements the behaviour that if no Media or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
             * MediaSize attribute is specified, return an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
             * MediaPrintableArea, one for each supported Media.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
             * If a MediaSize is specified, return a MPA consistent for that,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
             * and if a Media is specified locate its MediaSize and return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
             * its MPA, and if none is found, return an MPA for the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
             * Media for this service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                return getAllPrintableAreas();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            MediaSize mediaSize = (MediaSize)attributes.get(MediaSize.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            Media media = (Media)attributes.get(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            MediaPrintableArea []arr = new MediaPrintableArea[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            if (mediaSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                if (media instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                    MediaSizeName msn = (MediaSizeName)media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                    mediaSize = MediaSize.getMediaSizeForName(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                    if (mediaSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                        /* try to get a size from the default media */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                        media = (Media)getDefaultAttributeValue(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                        if (media instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                            msn = (MediaSizeName)media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                            mediaSize = MediaSize.getMediaSizeForName(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                        if (mediaSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                            /* shouldn't happen, return a default */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                            arr[0] = new MediaPrintableArea(0.25f, 0.25f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                                                            8f, 10.5f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                                                            MediaSize.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                    return getAllPrintableAreas();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            /* If reach here MediaSize is non-null */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            assert mediaSize != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            arr[0] = new MediaPrintableArea(0.25f, 0.25f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                                mediaSize.getX(MediaSize.INCH)-0.5f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                                mediaSize.getY(MediaSize.INCH)-0.5f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                                MediaSize.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        } else if (category == PageRanges.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                PageRanges []arr = new PageRanges[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                arr[0] = new PageRanges(1, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        } else if (category == SheetCollate.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                SheetCollate []arr = new SheetCollate[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                arr[0] = SheetCollate.UNCOLLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                arr[1] = SheetCollate.COLLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        } else if (category == Sides.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                Sides []arr = new Sides[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                arr[0] = Sides.ONE_SIDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                arr[1] = Sides.TWO_SIDED_LONG_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                arr[2] = Sides.TWO_SIDED_SHORT_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    private static MediaPrintableArea[] mpas = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    private MediaPrintableArea[] getAllPrintableAreas() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        if (mpas == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                                                                 null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            mpas = new MediaPrintableArea[media.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            for (int i=0; i< mpas.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                if (media[i] instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                    MediaSizeName msn = (MediaSizeName)media[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                    if (mediaSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                        mpas[i] = (MediaPrintableArea)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                            getDefaultAttributeValue(MediaPrintableArea.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                                        MediaSize.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        return mpasCopy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    /* Is this one of the flavors that this service explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * generates postscript for, and so can control how it is rendered?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    private boolean isServiceFormattedFlavor(DocFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            flavor.equals(DocFlavor.BYTE_ARRAY.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            flavor.equals(DocFlavor.INPUT_STREAM.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            flavor.equals(DocFlavor.URL.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            flavor.equals(DocFlavor.INPUT_STREAM.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            flavor.equals(DocFlavor.URL.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            flavor.equals(DocFlavor.BYTE_ARRAY.PNG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            flavor.equals(DocFlavor.INPUT_STREAM.PNG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            flavor.equals(DocFlavor.URL.PNG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    public boolean isAttributeValueSupported(Attribute attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                                             DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                                             AttributeSet attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            throw new NullPointerException("null attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        if (flavor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            if (!isDocFlavorSupported(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                throw new IllegalArgumentException(flavor +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                                               " is an unsupported flavor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            } else if (isAutoSense(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        Class category = attr.getCategory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        if (!isAttributeCategorySupported(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        else if (attr.getCategory() == Chromaticity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            if (flavor == null || isServiceFormattedFlavor(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                return attr == Chromaticity.COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        else if (attr.getCategory() == Copies.class) {
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   904
            return (flavor == null ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   905
                   !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   906
                     flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   907
                     flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                isSupportedCopies((Copies)attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        } else if (attr.getCategory() == Destination.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            URI uri = ((Destination)attr).getURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                if ("file".equals(uri.getScheme()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                    !(uri.getSchemeSpecificPart().equals(""))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        } else if (attr.getCategory() == Media.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            if (attr instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                return isSupportedMedia((MediaSizeName)attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        } else if (attr.getCategory() == OrientationRequested.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            if (attr == OrientationRequested.REVERSE_PORTRAIT ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                (flavor != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                !isServiceFormattedFlavor(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        } else if (attr.getCategory() == PageRanges.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            if (flavor != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        } else if (attr.getCategory() == SheetCollate.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            if (flavor != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        } else if (attr.getCategory() == Sides.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            if (flavor != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                return false;
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 true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                                                 AttributeSet attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        if (flavor != null && !isDocFlavorSupported(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            throw new IllegalArgumentException("flavor " + flavor +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                                               "is not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        Attribute attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        AttributeSet unsupp = new HashAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        Attribute []attrs = attributes.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        for (int i=0; i<attrs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                attr = attrs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                if (!isAttributeCategorySupported(attr.getCategory())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                    unsupp.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                } else if (!isAttributeValueSupported(attr, flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                                                      attributes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                    unsupp.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        if (unsupp.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            return unsupp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    public ServiceUIFactory getServiceUIFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        return "Unix Printer : " + getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        return  (obj == this ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                 (obj instanceof UnixPrintService &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                  ((UnixPrintService)obj).getName().equals(getName())));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        return this.getClass().hashCode()+getName().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    public boolean usesClass(Class c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        return (c == sun.print.PSPrinterJob.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
}