1 /*
   2  * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.print;
  27 
  28 import java.io.IOException;
  29 import java.io.ObjectInputStream;
  30 import java.io.ObjectOutputStream;
  31 import java.io.Serializable;
  32 
  33 
  34 /**
  35  * Class <code>DocFlavor</code> encapsulates an object that specifies the
  36  * format in which print data is supplied to a {@link DocPrintJob}.
  37  * "Doc" is a short, easy-to-pronounce term that means "a piece of print data."
  38  * The print data format, or "doc flavor", consists of two things:
  39  * <UL>
  40  * <LI>
  41  * <B>MIME type.</B> This is a Multipurpose Internet Mail Extensions (MIME)
  42  * media type (as defined in <A HREF="http://www.ietf.org/rfc/rfc2045.txt">RFC
  43  * 2045</A> and <A HREF="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</A>)
  44  * that specifies how the print data is to be interpreted.
  45  * The charset of text data should be the IANA MIME-preferred name, or its
  46  * canonical name if no preferred name is specified. Additionally a few
  47  * historical names supported by earlier versions of the Java platform may
  48  * be recognized.
  49  * See <a href="../../java/lang/package-summary.html#charenc">
  50  * character encodings</a> for more information on the character encodings
  51  * supported on the Java platform.
  52  *
  53  * <LI>
  54  * <B>Representation class name.</B> This specifies the fully-qualified name of
  55  * the class of the object from which the actual print data comes, as returned
  56  * by the {@link java.lang.Class#getName() Class.getName()} method.
  57  * (Thus the class name for <CODE>byte[]</CODE> is <CODE>"[B"</CODE>, for
  58  * <CODE>char[]</CODE> it is <CODE>"[C"</CODE>.)
  59  * </UL>
  60  * <P>
  61  * A <code>DocPrintJob</code> obtains its print data by means of interface
  62  * {@link Doc Doc}. A <code>Doc</code> object lets the <code>DocPrintJob</code>
  63  * determine the doc flavor the client can supply.  A <code>Doc</code> object
  64  * also lets the <code>DocPrintJob</code> obtain an instance of the doc flavor's
  65  * representation class, from which the <code>DocPrintJob</code> then obtains
  66  * the actual print data.
  67  *
  68  * <HR>
  69  * <H3>Client Formatted Print Data</H3>
  70  * There are two broad categories of print data, client formatted print data
  71  * and service formatted print data.
  72  * <P>
  73  * For <B>client formatted print data</B>, the client determines or knows the
  74  * print data format.
  75  * For example the client may have a JPEG encoded image, a URL for
  76  * HTML code, or a disk file containing plain text in some encoding,
  77  * possibly obtained from an external source, and
  78  * requires a way to describe the data format to the print service.
  79  * <p>
  80  * The doc flavor's representation class is a conduit for the JPS
  81  * <code>DocPrintJob</code> to obtain a sequence of characters or
  82  * bytes from the client. The
  83  * doc flavor's MIME type is one of the standard media types telling how to
  84  * interpret the sequence of characters or bytes. For a list of standard media
  85  * types, see the Internet Assigned Numbers Authority's (IANA's) <A
  86  * HREF="http://www.iana.org/assignments/media-types/">Media Types
  87  * Directory</A>. Interface {@link Doc Doc} provides two utility operations,
  88  * {@link Doc#getReaderForText() getReaderForText} and
  89  * {@link Doc#getStreamForBytes() getStreamForBytes()}, to help a
  90  * <code>Doc</code> object's client extract client formatted print data.
  91  * <P>
  92  * For client formatted print data, the print data representation class is
  93  * typically one of the following (although other representation classes are
  94  * permitted):
  95  * <UL>
  96  * <LI>
  97  * Character array (<CODE>char[]</CODE>) -- The print data consists of the
  98  * Unicode characters in the array.
  99  *
 100  * <LI>
 101  * <code>String</code>  --
 102  * The print data consists of the Unicode characters in the string.
 103  *
 104  * <LI>
 105  * Character stream ({@link java.io.Reader java.io.Reader})
 106  * -- The print data consists of the Unicode characters read from the stream
 107  * up to the end-of-stream.
 108  *
 109  * <LI>
 110  * Byte array (<CODE>byte[]</CODE>) -- The print data consists of the bytes in
 111  * the array. The bytes are encoded in the character set specified by the doc
 112  * flavor's MIME type. If the MIME type does not specify a character set, the
 113  * default character set is US-ASCII.
 114  *
 115  * <LI>
 116  * Byte stream ({@link java.io.InputStream java.io.InputStream}) --
 117  * The print data consists of the bytes read from the stream up to the
 118  * end-of-stream. The bytes are encoded in the character set specified by the
 119  * doc flavor's MIME type. If the MIME type does not specify a character set,
 120  * the default character set is US-ASCII.
 121 
 122  * <LI>
 123  * Uniform Resource Locator ({@link java.net.URL URL})
 124  * -- The print data consists of the bytes read from the URL location.
 125  * The bytes are encoded in the character set specified by the doc flavor's
 126  * MIME type. If the MIME type does not specify a character set, the default
 127  * character set is US-ASCII.
 128  * <P>
 129  * When the representation class is a URL, the print service itself accesses
 130  * and downloads the document directly from its URL address, without involving
 131  * the client. The service may be some form of network print service which
 132  * is executing in a different environment.
 133  * This means you should not use a URL print data flavor to print a
 134  * document at a restricted URL that the client can see but the printer cannot
 135  * see. This also means you should not use a URL print data flavor to print a
 136  * document stored in a local file that is not available at a URL
 137  * accessible independently of the client.
 138  * For example, a file that is not served up by an HTTP server or FTP server.
 139  * To print such documents, let the client open an input stream on the URL
 140  * or file and use an input stream data flavor.
 141  * </UL>
 142  *
 143  * <HR>
 144  * <h3>Default and Platform Encodings</h3>
 145  * <P>
 146  * For byte print data where the doc flavor's MIME type does not include a
 147  * <CODE>charset</CODE> parameter, the Java Print Service instance assumes the
 148  * US-ASCII character set by default. This is in accordance with
 149  * <A HREF="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</A>, which says the
 150  * default character set is US-ASCII. Note that US-ASCII is a subset of
 151  * UTF-8, so in the future this may be widened if a future RFC endorses
 152  * UTF-8 as the default in a compatible manner.
 153  * <p>
 154  * Also note that this is different than the behaviour of the Java runtime
 155  * when interpreting a stream of bytes as text data. That assumes the
 156  * default encoding for the user's locale. Thus, when spooling a file in local
 157  * encoding to a Java Print Service it is important to correctly specify
 158  * the encoding. Developers working in the English locales should
 159  * be particularly conscious of this, as their platform encoding corresponds
 160  * to the default mime charset. By this coincidence that particular
 161  * case may work without specifying the encoding of platform data.
 162  * <p>
 163  * Every instance of the Java virtual machine has a default character encoding
 164  * determined during virtual-machine startup and typically depends upon the
 165  * locale and charset being used by the underlying operating system.
 166  * In a distributed environment there is no guarantee that two VM share
 167  * the same default encoding. Thus clients which want to stream platform
 168  * encoded text data from the host platform to a Java Print Service instance
 169  * must explicitly declare the charset and not rely on defaults.
 170  * <p>
 171  * The preferred form is the official IANA primary name for an encoding.
 172  * Applications which stream text data should always specify the charset
 173  * in the mime type, which necessitates obtaining the encoding of the host
 174  * platform for data (eg files) stored in that platform's encoding.
 175  * A CharSet which corresponds to this and is suitable for use in a
 176  * mime-type for a DocFlavor can be obtained
 177  * from {@link DocFlavor#hostEncoding DocFlavor.hostEncoding}
 178  * This may not always be the primary IANA name but is guaranteed to be
 179  * understood by this VM.
 180  * For common flavors, the pre-defined *HOST DocFlavors may be used.
 181  * <p>
 182  * See <a href="../../java/lang/package-summary.html#charenc">
 183  * character encodings</a> for more information on the character encodings
 184  * supported on the Java platform.
 185  * <HR>
 186  * <h3>Recommended DocFlavors</h3>
 187  * <P>
 188  * The Java Print Service API does not define any mandatorily supported
 189  * DocFlavors.
 190  * However, here are some examples of MIME types that a Java Print Service
 191  * instance might support for client formatted print data.
 192  * Nested classes inside class DocFlavor declare predefined static
 193  * constant DocFlavor objects for these example doc flavors; class DocFlavor's
 194  * constructor can be used to create an arbitrary doc flavor.
 195  * <UL>
 196  * <LI>Preformatted text
 197  * <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 SUMMARY="MIME-Types and their descriptions">
 198  * <TR>
 199  *  <TH>MIME-Type</TH><TH>Description</TH>
 200  * </TR>
 201  * <TR>
 202  * <TD><CODE>"text/plain"</CODE></TD>
 203  * <TD>Plain text in the default character set (US-ASCII)</TD>
 204  * </TR>
 205  * <TR>
 206  * <TD><CODE>"text/plain; charset=<I>xxx</I>"</CODE></TD>
 207  * <TD>Plain text in character set <I>xxx</I></TD>
 208  * </TR>
 209  * <TR>
 210  * <TD><CODE>"text/html"</CODE></TD>
 211  * <TD>HyperText Markup Language in the default character set (US-ASCII)</TD>
 212  * </TR>
 213  * <TR>
 214  * <TD><CODE>"text/html; charset=<I>xxx</I>"</CODE></TD>
 215  * <TD>HyperText Markup Language in character set <I>xxx</I></TD>
 216  * </TR>
 217  * </TABLE>
 218  * <P>
 219  * In general, preformatted text print data is provided either in a character
 220  * oriented representation class (character array, String, Reader) or in a
 221  * byte oriented representation class (byte array, InputStream, URL).
 222  *
 223  *  <LI>Preformatted page description language (PDL) documents
 224  *
 225  * <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 SUMMARY="MIME-Types and their descriptions">
 226  * <TR>
 227  *  <TH>MIME-Type</TH><TH>Description</TH>
 228  * </TR>
 229  *<TR>
 230  * <TD><CODE>"application/pdf"</CODE></TD>
 231  * <TD>Portable Document Format document</TD>
 232  * </TR>
 233  * <TR>
 234  * <TD><CODE>"application/postscript"</CODE></TD>
 235  * <TD>PostScript document</TD>
 236  * </TR>
 237  * <TR>
 238  * <TD><CODE>"application/vnd.hp-PCL"</CODE></TD>
 239  * <TD>Printer Control Language document</TD>
 240  * </TR>
 241  * </TABLE>
 242  * <P>
 243  * In general, preformatted PDL print data is provided in a byte oriented
 244  * representation class (byte array, InputStream, URL).
 245  *
 246  *  <LI>Preformatted images
 247  *
 248  * <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 SUMMARY="MIME-Types and their descriptions">
 249  * <TR>
 250  *  <TH>MIME-Type</TH><TH>Description</TH>
 251  * </TR>
 252  *
 253  * <TR>
 254  * <TD><CODE>"image/gif"</CODE></TD>
 255  * <TD>Graphics Interchange Format image</TD>
 256  * </TR>
 257  * <TR>
 258  * <TD><CODE>"image/jpeg"</CODE></TD>
 259  * <TD>Joint Photographic Experts Group image</TD>
 260  * </TR>
 261  * <TR>
 262  * <TD><CODE>"image/png"</CODE></TD>
 263  * <TD>Portable Network Graphics image</TD>
 264  * </TR>
 265  * </TABLE>
 266  * <P>
 267  * In general, preformatted image print data is provided in a byte oriented
 268  * representation class (byte array, InputStream, URL).
 269  *
 270  *  <LI>Preformatted autosense print data
 271  *
 272  * <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 SUMMARY="MIME-Types and their descriptions">
 273  * <TR>
 274  *  <TH>MIME-Type</TH><TH>Description</TH>
 275  * </TR>
 276  *
 277  * <TR>
 278  * <TD><CODE>"application/octet-stream"</CODE></TD>
 279  * <TD>The print data format is unspecified (just an octet stream)</TD>
 280  * </TABLE>
 281  * <P>
 282  * The printer decides how to interpret the print data; the way this
 283  * "autosensing" works is implementation dependent. In general, preformatted
 284  * autosense print data is provided in a byte oriented representation class
 285  * (byte array, InputStream, URL).
 286  * </UL>
 287  *
 288  * <HR>
 289  * <H3>Service Formatted Print Data</H3>
 290  * <P>
 291  * For <B>service formatted print data</B>, the Java Print Service instance
 292  * determines the print data format. The doc flavor's representation class
 293  * denotes an interface whose methods the <code>DocPrintJob</code> invokes to
 294  * determine the content to be printed -- such as a renderable image
 295  * interface or a Java printable interface.
 296  * The doc flavor's MIME type is the special value
 297  * <CODE>"application/x-java-jvm-local-objectref"</CODE> indicating the client
 298  * will supply a reference to a Java object that implements the interface
 299  * named as the representation class.
 300  * This MIME type is just a placeholder; what's
 301  * important is the print data representation class.
 302  * <P>
 303  * For service formatted print data, the print data representation class is
 304  * typically one of the following (although other representation classes are
 305  * permitted). Nested classes inside class DocFlavor declare predefined static
 306  * constant DocFlavor objects for these example doc flavors; class DocFlavor's
 307  * constructor can be used to create an arbitrary doc flavor.
 308  * <UL>
 309  * <LI>
 310  * Renderable image object -- The client supplies an object that implements
 311  * interface
 312  * {@link java.awt.image.renderable.RenderableImage RenderableImage}. The
 313  * printer calls methods
 314  * in that interface to obtain the image to be printed.
 315  *
 316  * <LI>
 317  * Printable object -- The client supplies an object that implements interface
 318  * {@link java.awt.print.Printable Printable}.
 319  * The printer calls methods in that interface to obtain the pages to be
 320  * printed, one by one.
 321  * For each page, the printer supplies a graphics context, and whatever the
 322  * client draws in that graphics context gets printed.
 323  *
 324  * <LI>
 325  * Pageable object -- The client supplies an object that implements interface
 326  * {@link java.awt.print.Pageable Pageable}. The printer calls
 327  * methods in that interface to obtain the pages to be printed, one by one.
 328  * For each page, the printer supplies a graphics context, and whatever
 329  * the client draws in that graphics context gets printed.
 330  * </UL>
 331  *
 332  * <HR>
 333  *
 334  * <HR>
 335  * <H3>Pre-defined Doc Flavors</H3>
 336  * A Java Print Service instance is not <B><I>required</I></B> to support the
 337  * following print data formats and print data representation classes.  In
 338  * fact, a developer using this class should <b>never</b> assume that a
 339  * particular print service supports the document types corresponding to
 340  * these pre-defined doc flavors.  Always query the print service
 341  * to determine what doc flavors it supports.  However,
 342  * developers who have print services that support these doc flavors are
 343  * encouraged to refer to the predefined singleton instances created here.
 344  * <UL>
 345  * <LI>
 346  * Plain text print data provided through a byte stream. Specifically, the
 347  * following doc flavors are recommended to be supported:
 348  * <BR>·&nbsp;&nbsp;
 349  * <CODE>("text/plain", "java.io.InputStream")</CODE>
 350  * <BR>·&nbsp;&nbsp;
 351  * <CODE>("text/plain; charset=us-ascii", "java.io.InputStream")</CODE>
 352  * <BR>·&nbsp;&nbsp;
 353  * <CODE>("text/plain; charset=utf-8", "java.io.InputStream")</CODE>
 354  *
 355  * <LI>
 356  * Renderable image objects. Specifically, the following doc flavor is
 357  * recommended to be supported:
 358  * <BR>·&nbsp;&nbsp;
 359  * <CODE>("application/x-java-jvm-local-objectref", "java.awt.image.renderable.RenderableImage")</CODE>
 360  * </UL>
 361  * <P>
 362  * A Java Print Service instance is allowed to support any other doc flavors
 363  * (or none) in addition to the above mandatory ones, at the implementation's
 364  * choice.
 365  * <P>
 366  * Support for the above doc flavors is desirable so a printing client can rely
 367  * on being able to print on any JPS printer, regardless of which doc flavors
 368  * the printer supports. If the printer doesn't support the client's preferred
 369  * doc flavor, the client can at least print plain text, or the client can
 370  * convert its data to a renderable image and print the image.
 371  * <P>
 372  * Furthermore, every Java Print Service instance must fulfill these
 373  * requirements for processing plain text print data:
 374  * <UL>
 375  * <LI>
 376  * The character pair carriage return-line feed (CR-LF) means
 377  * "go to column 1 of the next line."
 378  * <LI>
 379  * A carriage return (CR) character standing by itself means
 380  * "go to column 1 of the next line."
 381  * <LI>
 382  * A line feed (LF) character standing by itself means
 383  * "go to column 1 of the next line."
 384  * <LI>
 385  * </UL>
 386  * <P>
 387  * The client must itself perform all plain text print data formatting not
 388  * addressed by the above requirements.
 389  *
 390  * <H3>Design Rationale</H3>
 391  * <P>
 392  * Class DocFlavor in package javax.print.data is similar to class
 393  * {@link java.awt.datatransfer.DataFlavor DataFlavor}. Class
 394  * <code>DataFlavor</code>
 395  * is not used in the Java Print Service (JPS) API
 396  * for three reasons which are all rooted in allowing the JPS API to be
 397  * shared by other print services APIs which may need to run on Java profiles
 398  * which do not include all of the Java Platform, Standard Edition.
 399  * <OL TYPE=1>
 400  * <LI>
 401  * The JPS API is designed to be used in Java profiles which do not support
 402  * AWT.
 403  *
 404  * <LI>
 405  * The implementation of class <code>java.awt.datatransfer.DataFlavor</code>
 406  * does not guarantee that equivalent data flavors will have the same
 407  * serialized representation. DocFlavor does, and can be used in services
 408  * which need this.
 409  *
 410  * <LI>
 411  * The implementation of class <code>java.awt.datatransfer.DataFlavor</code>
 412  * includes a human presentable name as part of the serialized representation.
 413  * This is not appropriate as part of a service matching constraint.
 414  * </OL>
 415  * <P>
 416  * Class DocFlavor's serialized representation uses the following
 417  * canonical form of a MIME type string. Thus, two doc flavors with MIME types
 418  * that are not identical but that are equivalent (that have the same
 419  * canonical form) may be considered equal.
 420  * <UL>
 421  * <LI> The media type, media subtype, and parameters are retained, but all
 422  *      comments and whitespace characters are discarded.
 423  * <LI> The media type, media subtype, and parameter names are converted to
 424  *      lowercase.
 425  * <LI> The parameter values retain their original case, except a charset
 426  *      parameter value for a text media type is converted to lowercase.
 427  * <LI> Quote characters surrounding parameter values are removed.
 428  * <LI> Quoting backslash characters inside parameter values are removed.
 429  * <LI> The parameters are arranged in ascending order of parameter name.
 430  * </UL>
 431  * <P>
 432  * Class DocFlavor's serialized representation also contains the
 433  * fully-qualified class <I>name</I> of the representation class
 434  * (a String object), rather than the representation class itself
 435  * (a Class object). This allows a client to examine the doc flavors a
 436  * Java Print Service instance supports without having
 437  * to load the representation classes, which may be problematic for
 438  * limited-resource clients.
 439  * <P>
 440  *
 441  * @author  Alan Kaminsky
 442  */
 443 public class DocFlavor implements Serializable, Cloneable {
 444 
 445     private static final long serialVersionUID = -4512080796965449721L;
 446 
 447     /**
 448      * A String representing the host operating system encoding.
 449      * This will follow the conventions documented in
 450      * <a href="http://www.ietf.org/rfc/rfc2278.txt">
 451      * <i>RFC&nbsp;2278:&nbsp;IANA Charset Registration Procedures</i></a>
 452      * except where historical names are returned for compatibility with
 453      * previous versions of the Java platform.
 454      * The value returned from method is valid only for the VM which
 455      * returns it, for use in a DocFlavor.
 456      * This is the charset for all the "HOST" pre-defined DocFlavors in
 457      * the executing VM.
 458      */
 459     public static final String hostEncoding;
 460 
 461     static {
 462         hostEncoding =
 463             java.security.AccessController.doPrivileged(
 464                   new sun.security.action.GetPropertyAction("file.encoding"));
 465     }
 466 
 467     /**
 468      * MIME type.
 469      */
 470     private transient MimeType myMimeType;
 471 
 472     /**
 473      * Representation class name.
 474      * @serial
 475      */
 476     private String myClassName;
 477 
 478     /**
 479      * String value for this doc flavor. Computed when needed and cached.
 480      */
 481     private transient String myStringValue = null;
 482 
 483 
 484     /**
 485      * Constructs a new doc flavor object from the given MIME type and
 486      * representation class name. The given MIME type is converted into
 487      * canonical form and stored internally.
 488      *
 489      * @param  mimeType   MIME media type string.
 490      * @param  className  Fully-qualified representation class name.
 491      *
 492      * @exception  NullPointerException
 493      *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null or
 494      *     <CODE>className</CODE> is null.
 495      * @exception  IllegalArgumentException
 496      *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
 497      *     obey the syntax for a MIME media type string.
 498      */
 499     public DocFlavor(String mimeType, String className) {
 500         if (className == null) {
 501             throw new NullPointerException();
 502         }
 503         myMimeType = new MimeType (mimeType);
 504         myClassName = className;
 505     }
 506 
 507     /**
 508      * Returns this doc flavor object's MIME type string based on the
 509      * canonical form. Each parameter value is enclosed in quotes.
 510      * @return the mime type
 511      */
 512     public String getMimeType() {
 513         return myMimeType.getMimeType();
 514     }
 515 
 516     /**
 517      * Returns this doc flavor object's media type (from the MIME type).
 518      * @return the media type
 519      */
 520     public String getMediaType() {
 521         return myMimeType.getMediaType();
 522     }
 523 
 524     /**
 525      * Returns this doc flavor object's media subtype (from the MIME type).
 526      * @return the media sub-type
 527      */
 528     public String getMediaSubtype() {
 529         return myMimeType.getMediaSubtype();
 530     }
 531 
 532     /**
 533      * Returns a <code>String</code> representing a MIME
 534      * parameter.
 535      * Mime types may include parameters which are usually optional.
 536      * The charset for text types is a commonly useful example.
 537      * This convenience method will return the value of the specified
 538      * parameter if one was specified in the mime type for this flavor.
 539      * <p>
 540      * @param paramName the name of the paramater. This name is internally
 541      * converted to the canonical lower case format before performing
 542      * the match.
 543      * @return String representing a mime parameter, or
 544      * null if that parameter is not in the mime type string.
 545      * @exception NullPointerException if paramName is null.
 546      */
 547     public String getParameter(String paramName) {
 548         return
 549             (String)myMimeType.getParameterMap().get(paramName.toLowerCase());
 550     }
 551 
 552     /**
 553      * Returns the name of this doc flavor object's representation class.
 554      * @return the name of the representation class.
 555      */
 556     public String getRepresentationClassName() {
 557         return myClassName;
 558     }
 559 
 560     /**
 561      * Converts this <code>DocFlavor</code> to a string.
 562      *
 563      * @return  MIME type string based on the canonical form. Each parameter
 564      *          value is enclosed in quotes.
 565      *          A "class=" parameter is appended to the
 566      *          MIME type string to indicate the representation class name.
 567      */
 568     public String toString() {
 569         return getStringValue();
 570     }
 571 
 572     /**
 573      * Returns a hash code for this doc flavor object.
 574      */
 575     public int hashCode() {
 576         return getStringValue().hashCode();
 577     }
 578 
 579     /**
 580      * Determines if this doc flavor object is equal to the given object.
 581      * The two are equal if the given object is not null, is an instance
 582      * of <code>DocFlavor</code>, has a MIME type equivalent to this doc
 583      * flavor object's MIME type (that is, the MIME types have the same media
 584      * type, media subtype, and parameters), and has the same representation
 585      * class name as this doc flavor object. Thus, if two doc flavor objects'
 586      * MIME types are the same except for comments, they are considered equal.
 587      * However, two doc flavor objects with MIME types of "text/plain" and
 588      * "text/plain; charset=US-ASCII" are not considered equal, even though
 589      * they represent the same media type (because the default character
 590      * set for plain text is US-ASCII).
 591      *
 592      * @param  obj  Object to test.
 593      *
 594      * @return  True if this doc flavor object equals <CODE>obj</CODE>, false
 595      *          otherwise.
 596      */
 597     public boolean equals(Object obj) {
 598         return
 599             obj != null &&
 600             obj instanceof DocFlavor &&
 601             getStringValue().equals (((DocFlavor) obj).getStringValue());
 602     }
 603 
 604     /**
 605      * Returns this doc flavor object's string value.
 606      */
 607     private String getStringValue() {
 608         if (myStringValue == null) {
 609             myStringValue = myMimeType + "; class=\"" + myClassName + "\"";
 610         }
 611         return myStringValue;
 612     }
 613 
 614     /**
 615      * Write the instance to a stream (ie serialize the object).
 616      */
 617     private void writeObject(ObjectOutputStream s) throws IOException {
 618 
 619         s.defaultWriteObject();
 620         s.writeObject(myMimeType.getMimeType());
 621     }
 622 
 623     /**
 624      * Reconstitute an instance from a stream (that is, deserialize it).
 625      *
 626      * @serialData
 627      * The serialised form of a DocFlavor is the String naming the
 628      * representation class followed by the String representing the canonical
 629      * form of the mime type.
 630      */
 631     private void readObject(ObjectInputStream s)
 632         throws ClassNotFoundException, IOException {
 633 
 634         s.defaultReadObject();
 635         myMimeType = new MimeType((String)s.readObject());
 636     }
 637 
 638     /**
 639      * Class DocFlavor.BYTE_ARRAY provides predefined static constant
 640      * DocFlavor objects for example doc flavors using a byte array
 641      * (<CODE>byte[]</CODE>) as the print data representation class.
 642      * <P>
 643      *
 644      * @author  Alan Kaminsky
 645      */
 646     public static class BYTE_ARRAY extends DocFlavor {
 647 
 648         private static final long serialVersionUID = -9065578006593857475L;
 649 
 650         /**
 651          * Constructs a new doc flavor with the given MIME type and a print
 652          * data representation class name of <CODE>"[B"</CODE> (byte array).
 653          *
 654          * @param  mimeType   MIME media type string.
 655          *
 656          * @exception  NullPointerException
 657          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
 658          * @exception  IllegalArgumentException
 659          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
 660          *     obey the syntax for a MIME media type string.
 661          */
 662         public BYTE_ARRAY (String mimeType) {
 663             super (mimeType, "[B");
 664         }
 665 
 666         /**
 667          * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
 668          * encoded in the host platform encoding.
 669          * See {@link DocFlavor#hostEncoding hostEncoding}
 670          * Print data representation class name =
 671          * <CODE>"[B"</CODE> (byte array).
 672          */
 673         public static final BYTE_ARRAY TEXT_PLAIN_HOST =
 674             new BYTE_ARRAY ("text/plain; charset="+hostEncoding);
 675 
 676         /**
 677          * Doc flavor with MIME type =
 678          * <CODE>"text/plain; charset=utf-8"</CODE>,
 679          * print data representation class name = <CODE>"[B"</CODE> (byte
 680          * array).
 681          */
 682         public static final BYTE_ARRAY TEXT_PLAIN_UTF_8 =
 683             new BYTE_ARRAY ("text/plain; charset=utf-8");
 684 
 685         /**
 686          * Doc flavor with MIME type =
 687          * <CODE>"text/plain; charset=utf-16"</CODE>,
 688          * print data representation class name = <CODE>"[B"</CODE> (byte
 689          * array).
 690          */
 691         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16 =
 692             new BYTE_ARRAY ("text/plain; charset=utf-16");
 693 
 694 
 695         /**
 696          * Doc flavor with MIME type =
 697          * <CODE>"text/plain; charset=utf-16be"</CODE>
 698          * (big-endian byte ordering),
 699          * print data representation class name = <CODE>"[B"</CODE> (byte
 700          * array).
 701          */
 702         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16BE =
 703             new BYTE_ARRAY ("text/plain; charset=utf-16be");
 704 
 705         /**
 706          * Doc flavor with MIME type =
 707          * <CODE>"text/plain; charset=utf-16le"</CODE>
 708          * (little-endian byte ordering),
 709          * print data representation class name = <CODE>"[B"</CODE> (byte
 710          * array).
 711          */
 712         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16LE =
 713             new BYTE_ARRAY ("text/plain; charset=utf-16le");
 714 
 715         /**
 716          * Doc flavor with MIME type =
 717          * <CODE>"text/plain; charset=us-ascii"</CODE>,
 718          * print data representation class name =
 719          * <CODE>"[B"</CODE> (byte array).
 720          */
 721         public static final BYTE_ARRAY TEXT_PLAIN_US_ASCII =
 722             new BYTE_ARRAY ("text/plain; charset=us-ascii");
 723 
 724 
 725         /**
 726          * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
 727          * encoded in the host platform encoding.
 728          * See {@link DocFlavor#hostEncoding hostEncoding}
 729          * Print data representation class name =
 730          * <CODE>"[B"</CODE> (byte array).
 731          */
 732         public static final BYTE_ARRAY TEXT_HTML_HOST =
 733             new BYTE_ARRAY ("text/html; charset="+hostEncoding);
 734 
 735         /**
 736          * Doc flavor with MIME type =
 737          * <CODE>"text/html; charset=utf-8"</CODE>,
 738          * print data representation class name = <CODE>"[B"</CODE> (byte
 739          * array).
 740          */
 741         public static final BYTE_ARRAY TEXT_HTML_UTF_8 =
 742             new BYTE_ARRAY ("text/html; charset=utf-8");
 743 
 744         /**
 745          * Doc flavor with MIME type =
 746          * <CODE>"text/html; charset=utf-16"</CODE>,
 747          * print data representation class name = <CODE>"[B"</CODE> (byte
 748          * array).
 749          */
 750         public static final BYTE_ARRAY TEXT_HTML_UTF_16 =
 751             new BYTE_ARRAY ("text/html; charset=utf-16");
 752 
 753         /**
 754          * Doc flavor with MIME type =
 755          * <CODE>"text/html; charset=utf-16be"</CODE>
 756          * (big-endian byte ordering),
 757          * print data representation class name = <CODE>"[B"</CODE> (byte
 758          * array).
 759          */
 760         public static final BYTE_ARRAY TEXT_HTML_UTF_16BE =
 761             new BYTE_ARRAY ("text/html; charset=utf-16be");
 762 
 763         /**
 764          * Doc flavor with MIME type =
 765          * <CODE>"text/html; charset=utf-16le"</CODE>
 766          * (little-endian byte ordering),
 767          * print data representation class name = <CODE>"[B"</CODE> (byte
 768          * array).
 769          */
 770         public static final BYTE_ARRAY TEXT_HTML_UTF_16LE =
 771             new BYTE_ARRAY ("text/html; charset=utf-16le");
 772 
 773         /**
 774          * Doc flavor with MIME type =
 775          * <CODE>"text/html; charset=us-ascii"</CODE>,
 776          * print data representation class name =
 777          * <CODE>"[B"</CODE> (byte array).
 778          */
 779         public static final BYTE_ARRAY TEXT_HTML_US_ASCII =
 780             new BYTE_ARRAY ("text/html; charset=us-ascii");
 781 
 782 
 783         /**
 784          * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
 785          * data representation class name = <CODE>"[B"</CODE> (byte array).
 786          */
 787         public static final BYTE_ARRAY PDF = new BYTE_ARRAY ("application/pdf");
 788 
 789         /**
 790          * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
 791          * print data representation class name = <CODE>"[B"</CODE> (byte
 792          * array).
 793          */
 794         public static final BYTE_ARRAY POSTSCRIPT =
 795             new BYTE_ARRAY ("application/postscript");
 796 
 797         /**
 798          * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
 799          * print data representation class name = <CODE>"[B"</CODE> (byte
 800          * array).
 801          */
 802         public static final BYTE_ARRAY PCL =
 803             new BYTE_ARRAY ("application/vnd.hp-PCL");
 804 
 805         /**
 806          * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
 807          * representation class name = <CODE>"[B"</CODE> (byte array).
 808          */
 809         public static final BYTE_ARRAY GIF = new BYTE_ARRAY ("image/gif");
 810 
 811         /**
 812          * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
 813          * representation class name = <CODE>"[B"</CODE> (byte array).
 814          */
 815         public static final BYTE_ARRAY JPEG = new BYTE_ARRAY ("image/jpeg");
 816 
 817         /**
 818          * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
 819          * representation class name = <CODE>"[B"</CODE> (byte array).
 820          */
 821         public static final BYTE_ARRAY PNG = new BYTE_ARRAY ("image/png");
 822 
 823         /**
 824          * Doc flavor with MIME type =
 825          * <CODE>"application/octet-stream"</CODE>,
 826          * print data representation class name = <CODE>"[B"</CODE> (byte
 827          * array). The client must determine that data described
 828          * using this DocFlavor is valid for the printer.
 829          */
 830         public static final BYTE_ARRAY AUTOSENSE =
 831             new BYTE_ARRAY ("application/octet-stream");
 832 
 833     }
 834 
 835     /**
 836      * Class DocFlavor.INPUT_STREAM provides predefined static constant
 837      * DocFlavor objects for example doc flavors using a byte stream ({@link
 838      * java.io.InputStream java.io.InputStream}) as the print
 839      * data representation class.
 840      * <P>
 841      *
 842      * @author  Alan Kaminsky
 843      */
 844     public static class INPUT_STREAM extends DocFlavor {
 845 
 846         private static final long serialVersionUID = -7045842700749194127L;
 847 
 848         /**
 849          * Constructs a new doc flavor with the given MIME type and a print
 850          * data representation class name of
 851          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 852          *
 853          * @param  mimeType   MIME media type string.
 854          *
 855          * @exception  NullPointerException
 856          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
 857          * @exception  IllegalArgumentException
 858          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
 859          *     obey the syntax for a MIME media type string.
 860          */
 861         public INPUT_STREAM (String mimeType) {
 862             super (mimeType, "java.io.InputStream");
 863         }
 864 
 865         /**
 866          * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
 867          * encoded in the host platform encoding.
 868          * See {@link DocFlavor#hostEncoding hostEncoding}
 869          * Print data representation class name =
 870          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 871          */
 872         public static final INPUT_STREAM TEXT_PLAIN_HOST =
 873             new INPUT_STREAM ("text/plain; charset="+hostEncoding);
 874 
 875         /**
 876          * Doc flavor with MIME type =
 877          * <CODE>"text/plain; charset=utf-8"</CODE>,
 878          * print data representation class name =
 879          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 880          */
 881         public static final INPUT_STREAM TEXT_PLAIN_UTF_8 =
 882             new INPUT_STREAM ("text/plain; charset=utf-8");
 883 
 884         /**
 885          * Doc flavor with MIME type =
 886          * <CODE>"text/plain; charset=utf-16"</CODE>,
 887          * print data representation class name =
 888          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 889          */
 890         public static final INPUT_STREAM TEXT_PLAIN_UTF_16 =
 891             new INPUT_STREAM ("text/plain; charset=utf-16");
 892 
 893         /**
 894          * Doc flavor with MIME type =
 895          * <CODE>"text/plain; charset=utf-16be"</CODE>
 896          * (big-endian byte ordering),
 897          * print data representation class name =
 898          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 899          */
 900         public static final INPUT_STREAM TEXT_PLAIN_UTF_16BE =
 901             new INPUT_STREAM ("text/plain; charset=utf-16be");
 902 
 903         /**
 904          * Doc flavor with MIME type =
 905          * <CODE>"text/plain; charset=utf-16le"</CODE>
 906          * (little-endian byte ordering),
 907          * print data representation class name =
 908          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 909          */
 910         public static final INPUT_STREAM TEXT_PLAIN_UTF_16LE =
 911             new INPUT_STREAM ("text/plain; charset=utf-16le");
 912 
 913         /**
 914          * Doc flavor with MIME type =
 915          * <CODE>"text/plain; charset=us-ascii"</CODE>,
 916          * print data representation class name =
 917          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 918          */
 919         public static final INPUT_STREAM TEXT_PLAIN_US_ASCII =
 920                 new INPUT_STREAM ("text/plain; charset=us-ascii");
 921 
 922         /**
 923          * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
 924          * encoded in the host platform encoding.
 925          * See {@link DocFlavor#hostEncoding hostEncoding}
 926          * Print data representation class name =
 927          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 928          */
 929         public static final INPUT_STREAM TEXT_HTML_HOST =
 930             new INPUT_STREAM ("text/html; charset="+hostEncoding);
 931 
 932         /**
 933          * Doc flavor with MIME type =
 934          * <CODE>"text/html; charset=utf-8"</CODE>,
 935          * print data representation class name =
 936          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 937          */
 938         public static final INPUT_STREAM TEXT_HTML_UTF_8 =
 939             new INPUT_STREAM ("text/html; charset=utf-8");
 940 
 941         /**
 942          * Doc flavor with MIME type =
 943          * <CODE>"text/html; charset=utf-16"</CODE>,
 944          * print data representation class name =
 945          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 946          */
 947         public static final INPUT_STREAM TEXT_HTML_UTF_16 =
 948             new INPUT_STREAM ("text/html; charset=utf-16");
 949 
 950         /**
 951          * Doc flavor with MIME type =
 952          * <CODE>"text/html; charset=utf-16be"</CODE>
 953          * (big-endian byte ordering),
 954          * print data representation class name =
 955          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 956          */
 957         public static final INPUT_STREAM TEXT_HTML_UTF_16BE =
 958             new INPUT_STREAM ("text/html; charset=utf-16be");
 959 
 960         /**
 961          * Doc flavor with MIME type =
 962          * <CODE>"text/html; charset=utf-16le"</CODE>
 963          * (little-endian byte ordering),
 964          * print data representation class name =
 965          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 966          */
 967         public static final INPUT_STREAM TEXT_HTML_UTF_16LE =
 968             new INPUT_STREAM ("text/html; charset=utf-16le");
 969 
 970         /**
 971          * Doc flavor with MIME type =
 972          * <CODE>"text/html; charset=us-ascii"</CODE>,
 973          * print data representation class name =
 974          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 975          */
 976         public static final INPUT_STREAM TEXT_HTML_US_ASCII =
 977             new INPUT_STREAM ("text/html; charset=us-ascii");
 978 
 979 
 980         /**
 981          * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
 982          * data representation class name = <CODE>"java.io.InputStream"</CODE>
 983          * (byte stream).
 984          */
 985         public static final INPUT_STREAM PDF = new INPUT_STREAM ("application/pdf");
 986 
 987         /**
 988          * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
 989          * print data representation class name =
 990          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 991          */
 992         public static final INPUT_STREAM POSTSCRIPT =
 993             new INPUT_STREAM ("application/postscript");
 994 
 995         /**
 996          * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
 997          * print data representation class name =
 998          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 999          */
1000         public static final INPUT_STREAM PCL =
1001             new INPUT_STREAM ("application/vnd.hp-PCL");
1002 
1003         /**
1004          * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
1005          * representation class name =
1006          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1007          */
1008         public static final INPUT_STREAM GIF = new INPUT_STREAM ("image/gif");
1009 
1010         /**
1011          * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
1012          * representation class name =
1013          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1014          */
1015         public static final INPUT_STREAM JPEG = new INPUT_STREAM ("image/jpeg");
1016 
1017         /**
1018          * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
1019          * representation class name =
1020          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1021          */
1022         public static final INPUT_STREAM PNG = new INPUT_STREAM ("image/png");
1023 
1024         /**
1025          * Doc flavor with MIME type =
1026          * <CODE>"application/octet-stream"</CODE>,
1027          * print data representation class name =
1028          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1029          * The client must determine that data described
1030          * using this DocFlavor is valid for the printer.
1031          */
1032         public static final INPUT_STREAM AUTOSENSE =
1033             new INPUT_STREAM ("application/octet-stream");
1034 
1035     }
1036 
1037     /**
1038      * Class DocFlavor.URL provides predefined static constant DocFlavor
1039      * objects.
1040      * For example doc flavors using a Uniform Resource Locator ({@link
1041      * java.net.URL java.net.URL}) as the print data
1042      * representation  class.
1043      * <P>
1044      *
1045      * @author  Alan Kaminsky
1046      */
1047     public static class URL extends DocFlavor {
1048 
1049         /**
1050          * Constructs a new doc flavor with the given MIME type and a print
1051          * data representation class name of <CODE>"java.net.URL"</CODE>.
1052          *
1053          * @param  mimeType   MIME media type string.
1054          *
1055          * @exception  NullPointerException
1056          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1057          * @exception  IllegalArgumentException
1058          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1059          *     obey the syntax for a MIME media type string.
1060          */
1061         public URL (String mimeType) {
1062             super (mimeType, "java.net.URL");
1063         }
1064 
1065         /**
1066          * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
1067          * encoded in the host platform encoding.
1068          * See {@link DocFlavor#hostEncoding hostEncoding}
1069          * Print data representation class name =
1070          * <CODE>"java.net.URL"</CODE> (byte stream).
1071          */
1072         public static final URL TEXT_PLAIN_HOST =
1073             new URL ("text/plain; charset="+hostEncoding);
1074 
1075         /**
1076          * Doc flavor with MIME type =
1077          * <CODE>"text/plain; charset=utf-8"</CODE>,
1078          * print data representation class name =
1079          * <CODE>"java.net.URL"</CODE> (byte stream).
1080          */
1081         public static final URL TEXT_PLAIN_UTF_8 =
1082             new URL ("text/plain; charset=utf-8");
1083 
1084         /**
1085          * Doc flavor with MIME type =
1086          * <CODE>"text/plain; charset=utf-16"</CODE>,
1087          * print data representation class name =
1088          * <CODE>java.net.URL""</CODE> (byte stream).
1089          */
1090         public static final URL TEXT_PLAIN_UTF_16 =
1091             new URL ("text/plain; charset=utf-16");
1092 
1093         /**
1094          * Doc flavor with MIME type =
1095          * <CODE>"text/plain; charset=utf-16be"</CODE>
1096          * (big-endian byte ordering),
1097          * print data representation class name =
1098          * <CODE>"java.net.URL"</CODE> (byte stream).
1099          */
1100         public static final URL TEXT_PLAIN_UTF_16BE =
1101             new URL ("text/plain; charset=utf-16be");
1102 
1103         /**
1104          * Doc flavor with MIME type =
1105          * <CODE>"text/plain; charset=utf-16le"</CODE>
1106          * (little-endian byte ordering),
1107          * print data representation class name =
1108          * <CODE>"java.net.URL"</CODE> (byte stream).
1109          */
1110         public static final URL TEXT_PLAIN_UTF_16LE =
1111             new URL ("text/plain; charset=utf-16le");
1112 
1113         /**
1114          * Doc flavor with MIME type =
1115          * <CODE>"text/plain; charset=us-ascii"</CODE>,
1116          * print data representation class name =
1117          * <CODE>"java.net.URL"</CODE> (byte stream).
1118          */
1119         public static final URL TEXT_PLAIN_US_ASCII =
1120             new URL ("text/plain; charset=us-ascii");
1121 
1122         /**
1123          * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
1124          * encoded in the host platform encoding.
1125          * See {@link DocFlavor#hostEncoding hostEncoding}
1126          * Print data representation class name =
1127          * <CODE>"java.net.URL"</CODE> (byte stream).
1128          */
1129         public static final URL TEXT_HTML_HOST =
1130             new URL ("text/html; charset="+hostEncoding);
1131 
1132         /**
1133          * Doc flavor with MIME type =
1134          * <CODE>"text/html; charset=utf-8"</CODE>,
1135          * print data representation class name =
1136          * <CODE>"java.net.URL"</CODE> (byte stream).
1137          */
1138         public static final URL TEXT_HTML_UTF_8 =
1139             new URL ("text/html; charset=utf-8");
1140 
1141         /**
1142          * Doc flavor with MIME type =
1143          * <CODE>"text/html; charset=utf-16"</CODE>,
1144          * print data representation class name =
1145          * <CODE>"java.net.URL"</CODE> (byte stream).
1146          */
1147         public static final URL TEXT_HTML_UTF_16 =
1148             new URL ("text/html; charset=utf-16");
1149 
1150         /**
1151          * Doc flavor with MIME type =
1152          * <CODE>"text/html; charset=utf-16be"</CODE>
1153          * (big-endian byte ordering),
1154          * print data representation class name =
1155          * <CODE>"java.net.URL"</CODE> (byte stream).
1156          */
1157         public static final URL TEXT_HTML_UTF_16BE =
1158             new URL ("text/html; charset=utf-16be");
1159 
1160         /**
1161          * Doc flavor with MIME type =
1162          * <CODE>"text/html; charset=utf-16le"</CODE>
1163          * (little-endian byte ordering),
1164          * print data representation class name =
1165          * <CODE>"java.net.URL"</CODE> (byte stream).
1166          */
1167         public static final URL TEXT_HTML_UTF_16LE =
1168             new URL ("text/html; charset=utf-16le");
1169 
1170         /**
1171          * Doc flavor with MIME type =
1172          * <CODE>"text/html; charset=us-ascii"</CODE>,
1173          * print data representation class name =
1174          * <CODE>"java.net.URL"</CODE> (byte stream).
1175          */
1176         public static final URL TEXT_HTML_US_ASCII =
1177             new URL ("text/html; charset=us-ascii");
1178 
1179 
1180         /**
1181          * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
1182          * data representation class name = <CODE>"java.net.URL"</CODE>.
1183          */
1184         public static final URL PDF = new URL ("application/pdf");
1185 
1186         /**
1187          * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
1188          * print data representation class name = <CODE>"java.net.URL"</CODE>.
1189          */
1190         public static final URL POSTSCRIPT = new URL ("application/postscript");
1191 
1192         /**
1193          * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
1194          * print data representation class name = <CODE>"java.net.URL"</CODE>.
1195          */
1196         public static final URL PCL = new URL ("application/vnd.hp-PCL");
1197 
1198         /**
1199          * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
1200          * representation class name = <CODE>"java.net.URL"</CODE>.
1201          */
1202         public static final URL GIF = new URL ("image/gif");
1203 
1204         /**
1205          * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
1206          * representation class name = <CODE>"java.net.URL"</CODE>.
1207          */
1208         public static final URL JPEG = new URL ("image/jpeg");
1209 
1210         /**
1211          * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
1212          * representation class name = <CODE>"java.net.URL"</CODE>.
1213          */
1214         public static final URL PNG = new URL ("image/png");
1215 
1216         /**
1217          * Doc flavor with MIME type =
1218          * <CODE>"application/octet-stream"</CODE>,
1219          * print data representation class name = <CODE>"java.net.URL"</CODE>.
1220          *  The client must determine that data described
1221          * using this DocFlavor is valid for the printer.
1222          */
1223         public static final URL AUTOSENSE = new URL ("application/octet-stream");
1224 
1225     }
1226 
1227     /**
1228      * Class DocFlavor.CHAR_ARRAY provides predefined static constant
1229      * DocFlavor objects for example doc flavors using a character array
1230      * (<CODE>char[]</CODE>) as the print data representation class. As such,
1231      * the character set is Unicode.
1232      * <P>
1233      *
1234      * @author  Alan Kaminsky
1235      */
1236     public static class CHAR_ARRAY extends DocFlavor {
1237 
1238         private static final long serialVersionUID = -8720590903724405128L;
1239 
1240         /**
1241          * Constructs a new doc flavor with the given MIME type and a print
1242          * data representation class name of
1243          * <CODE>"[C"</CODE> (character array).
1244          *
1245          * @param  mimeType  MIME media type string. If it is a text media
1246          *                      type, it is assumed to contain a
1247          *                      <CODE>"charset=utf-16"</CODE> parameter.
1248          *
1249          * @exception  NullPointerException
1250          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1251          * @exception  IllegalArgumentException
1252          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1253          *     obey the syntax for a MIME media type string.
1254          */
1255         public CHAR_ARRAY (String mimeType) {
1256             super (mimeType, "[C");
1257         }
1258 
1259         /**
1260          * Doc flavor with MIME type = <CODE>"text/plain;
1261          * charset=utf-16"</CODE>, print data representation class name =
1262          * <CODE>"[C"</CODE> (character array).
1263          */
1264         public static final CHAR_ARRAY TEXT_PLAIN =
1265             new CHAR_ARRAY ("text/plain; charset=utf-16");
1266 
1267         /**
1268          * Doc flavor with MIME type = <CODE>"text/html;
1269          * charset=utf-16"</CODE>, print data representation class name =
1270          * <CODE>"[C"</CODE> (character array).
1271          */
1272         public static final CHAR_ARRAY TEXT_HTML =
1273             new CHAR_ARRAY ("text/html; charset=utf-16");
1274 
1275     }
1276 
1277     /**
1278      * Class DocFlavor.STRING provides predefined static constant DocFlavor
1279      * objects for example doc flavors using a string ({@link java.lang.String
1280      * java.lang.String}) as the print data representation class.
1281      * As such, the character set is Unicode.
1282      * <P>
1283      *
1284      * @author  Alan Kaminsky
1285      */
1286     public static class STRING extends DocFlavor {
1287 
1288         private static final long serialVersionUID = 4414407504887034035L;
1289 
1290         /**
1291          * Constructs a new doc flavor with the given MIME type and a print
1292          * data representation class name of <CODE>"java.lang.String"</CODE>.
1293          *
1294          * @param  mimeType  MIME media type string. If it is a text media
1295          *                      type, it is assumed to contain a
1296          *                      <CODE>"charset=utf-16"</CODE> parameter.
1297          *
1298          * @exception  NullPointerException
1299          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1300          * @exception  IllegalArgumentException
1301          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1302          *     obey the syntax for a MIME media type string.
1303          */
1304         public STRING (String mimeType) {
1305             super (mimeType, "java.lang.String");
1306         }
1307 
1308         /**
1309          * Doc flavor with MIME type = <CODE>"text/plain;
1310          * charset=utf-16"</CODE>, print data representation class name =
1311          * <CODE>"java.lang.String"</CODE>.
1312          */
1313         public static final STRING TEXT_PLAIN =
1314             new STRING ("text/plain; charset=utf-16");
1315 
1316         /**
1317          * Doc flavor with MIME type = <CODE>"text/html;
1318          * charset=utf-16"</CODE>, print data representation class name =
1319          * <CODE>"java.lang.String"</CODE>.
1320          */
1321         public static final STRING TEXT_HTML =
1322             new STRING ("text/html; charset=utf-16");
1323     }
1324 
1325     /**
1326      * Class DocFlavor.READER provides predefined static constant DocFlavor
1327      * objects for example doc flavors using a character stream ({@link
1328      * java.io.Reader java.io.Reader}) as the print data
1329      * representation class. As such, the character set is Unicode.
1330      * <P>
1331      *
1332      * @author  Alan Kaminsky
1333      */
1334     public static class READER extends DocFlavor {
1335 
1336         private static final long serialVersionUID = 7100295812579351567L;
1337 
1338         /**
1339          * Constructs a new doc flavor with the given MIME type and a print
1340          * data representation class name of\
1341          * <CODE>"java.io.Reader"</CODE> (character stream).
1342          *
1343          * @param  mimeType  MIME media type string. If it is a text media
1344          *                      type, it is assumed to contain a
1345          *                      <CODE>"charset=utf-16"</CODE> parameter.
1346          *
1347          * @exception  NullPointerException
1348          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1349          * @exception  IllegalArgumentException
1350          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1351          *     obey the syntax for a MIME media type string.
1352          */
1353         public READER (String mimeType) {
1354             super (mimeType, "java.io.Reader");
1355         }
1356 
1357         /**
1358          * Doc flavor with MIME type = <CODE>"text/plain;
1359          * charset=utf-16"</CODE>, print data representation class name =
1360          * <CODE>"java.io.Reader"</CODE> (character stream).
1361          */
1362         public static final READER TEXT_PLAIN =
1363             new READER ("text/plain; charset=utf-16");
1364 
1365         /**
1366          * Doc flavor with MIME type = <CODE>"text/html;
1367          * charset=utf-16"</CODE>, print data representation class name =
1368          * <CODE>"java.io.Reader"</CODE> (character stream).
1369          */
1370         public static final READER TEXT_HTML =
1371             new READER ("text/html; charset=utf-16");
1372 
1373     }
1374 
1375     /**
1376      * Class DocFlavor.SERVICE_FORMATTED provides predefined static constant
1377      * DocFlavor objects for example doc flavors for service formatted print
1378      * data.
1379      * <P>
1380      *
1381      * @author  Alan Kaminsky
1382      */
1383     public static class SERVICE_FORMATTED extends DocFlavor {
1384 
1385         private static final long serialVersionUID = 6181337766266637256L;
1386 
1387         /**
1388          * Constructs a new doc flavor with a MIME type of
1389          * <CODE>"application/x-java-jvm-local-objectref"</CODE> indicating
1390          * service formatted print data and the given print data
1391          * representation class name.
1392          *
1393          * @param  className  Fully-qualified representation class name.
1394          *
1395          * @exception  NullPointerException
1396          *     (unchecked exception) Thrown if <CODE>className</CODE> is
1397          *     null.
1398          */
1399         public SERVICE_FORMATTED (String className) {
1400             super ("application/x-java-jvm-local-objectref", className);
1401         }
1402 
1403         /**
1404          * Service formatted print data doc flavor with print data
1405          * representation class name =
1406          * <CODE>"java.awt.image.renderable.RenderableImage"</CODE>
1407          * (renderable image object).
1408          */
1409         public static final SERVICE_FORMATTED RENDERABLE_IMAGE =
1410             new SERVICE_FORMATTED("java.awt.image.renderable.RenderableImage");
1411 
1412         /**
1413          * Service formatted print data doc flavor with print data
1414          * representation class name = <CODE>"java.awt.print.Printable"</CODE>
1415          * (printable object).
1416          */
1417         public static final SERVICE_FORMATTED PRINTABLE =
1418             new SERVICE_FORMATTED ("java.awt.print.Printable");
1419 
1420         /**
1421          * Service formatted print data doc flavor with print data
1422          * representation class name = <CODE>"java.awt.print.Pageable"</CODE>
1423          * (pageable object).
1424          */
1425         public static final SERVICE_FORMATTED PAGEABLE =
1426             new SERVICE_FORMATTED ("java.awt.print.Pageable");
1427 
1428         }
1429 
1430 }