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  * </UL>
 385  * <P>
 386  * The client must itself perform all plain text print data formatting not
 387  * addressed by the above requirements.
 388  *
 389  * <H3>Design Rationale</H3>
 390  * <P>
 391  * Class DocFlavor in package javax.print.data is similar to class
 392  * {@link java.awt.datatransfer.DataFlavor DataFlavor}. Class
 393  * <code>DataFlavor</code>
 394  * is not used in the Java Print Service (JPS) API
 395  * for three reasons which are all rooted in allowing the JPS API to be
 396  * shared by other print services APIs which may need to run on Java profiles
 397  * which do not include all of the Java Platform, Standard Edition.
 398  * <OL TYPE=1>
 399  * <LI>
 400  * The JPS API is designed to be used in Java profiles which do not support
 401  * AWT.
 402  *
 403  * <LI>
 404  * The implementation of class <code>java.awt.datatransfer.DataFlavor</code>
 405  * does not guarantee that equivalent data flavors will have the same
 406  * serialized representation. DocFlavor does, and can be used in services
 407  * which need this.
 408  *
 409  * <LI>
 410  * The implementation of class <code>java.awt.datatransfer.DataFlavor</code>
 411  * includes a human presentable name as part of the serialized representation.
 412  * This is not appropriate as part of a service matching constraint.
 413  * </OL>
 414  * <P>
 415  * Class DocFlavor's serialized representation uses the following
 416  * canonical form of a MIME type string. Thus, two doc flavors with MIME types
 417  * that are not identical but that are equivalent (that have the same
 418  * canonical form) may be considered equal.
 419  * <UL>
 420  * <LI> The media type, media subtype, and parameters are retained, but all
 421  *      comments and whitespace characters are discarded.
 422  * <LI> The media type, media subtype, and parameter names are converted to
 423  *      lowercase.
 424  * <LI> The parameter values retain their original case, except a charset
 425  *      parameter value for a text media type is converted to lowercase.
 426  * <LI> Quote characters surrounding parameter values are removed.
 427  * <LI> Quoting backslash characters inside parameter values are removed.
 428  * <LI> The parameters are arranged in ascending order of parameter name.
 429  * </UL>
 430  * <P>
 431  * Class DocFlavor's serialized representation also contains the
 432  * fully-qualified class <I>name</I> of the representation class
 433  * (a String object), rather than the representation class itself
 434  * (a Class object). This allows a client to examine the doc flavors a
 435  * Java Print Service instance supports without having
 436  * to load the representation classes, which may be problematic for
 437  * limited-resource clients.
 438  *
 439  * @author  Alan Kaminsky
 440  */
 441 public class DocFlavor implements Serializable, Cloneable {
 442 
 443     private static final long serialVersionUID = -4512080796965449721L;
 444 
 445     /**
 446      * A String representing the host operating system encoding.
 447      * This will follow the conventions documented in
 448      * <a href="http://www.ietf.org/rfc/rfc2278.txt">
 449      * <i>RFC&nbsp;2278:&nbsp;IANA Charset Registration Procedures</i></a>
 450      * except where historical names are returned for compatibility with
 451      * previous versions of the Java platform.
 452      * The value returned from method is valid only for the VM which
 453      * returns it, for use in a DocFlavor.
 454      * This is the charset for all the "HOST" pre-defined DocFlavors in
 455      * the executing VM.
 456      */
 457     public static final String hostEncoding;
 458 
 459     static {
 460         hostEncoding =
 461             java.security.AccessController.doPrivileged(
 462                   new sun.security.action.GetPropertyAction("file.encoding"));
 463     }
 464 
 465     /**
 466      * MIME type.
 467      */
 468     private transient MimeType myMimeType;
 469 
 470     /**
 471      * Representation class name.
 472      * @serial
 473      */
 474     private String myClassName;
 475 
 476     /**
 477      * String value for this doc flavor. Computed when needed and cached.
 478      */
 479     private transient String myStringValue = null;
 480 
 481 
 482     /**
 483      * Constructs a new doc flavor object from the given MIME type and
 484      * representation class name. The given MIME type is converted into
 485      * canonical form and stored internally.
 486      *
 487      * @param  mimeType   MIME media type string.
 488      * @param  className  Fully-qualified representation class name.
 489      *
 490      * @exception  NullPointerException
 491      *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null or
 492      *     <CODE>className</CODE> is null.
 493      * @exception  IllegalArgumentException
 494      *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
 495      *     obey the syntax for a MIME media type string.
 496      */
 497     public DocFlavor(String mimeType, String className) {
 498         if (className == null) {
 499             throw new NullPointerException();
 500         }
 501         myMimeType = new MimeType (mimeType);
 502         myClassName = className;
 503     }
 504 
 505     /**
 506      * Returns this doc flavor object's MIME type string based on the
 507      * canonical form. Each parameter value is enclosed in quotes.
 508      * @return the mime type
 509      */
 510     public String getMimeType() {
 511         return myMimeType.getMimeType();
 512     }
 513 
 514     /**
 515      * Returns this doc flavor object's media type (from the MIME type).
 516      * @return the media type
 517      */
 518     public String getMediaType() {
 519         return myMimeType.getMediaType();
 520     }
 521 
 522     /**
 523      * Returns this doc flavor object's media subtype (from the MIME type).
 524      * @return the media sub-type
 525      */
 526     public String getMediaSubtype() {
 527         return myMimeType.getMediaSubtype();
 528     }
 529 
 530     /**
 531      * Returns a <code>String</code> representing a MIME
 532      * parameter.
 533      * Mime types may include parameters which are usually optional.
 534      * The charset for text types is a commonly useful example.
 535      * This convenience method will return the value of the specified
 536      * parameter if one was specified in the mime type for this flavor.
 537      *
 538      * @param paramName the name of the paramater. This name is internally
 539      * converted to the canonical lower case format before performing
 540      * the match.
 541      * @return String representing a mime parameter, or
 542      * null if that parameter is not in the mime type string.
 543      * @exception NullPointerException if paramName is null.
 544      */
 545     public String getParameter(String paramName) {
 546         return
 547             (String)myMimeType.getParameterMap().get(paramName.toLowerCase());
 548     }
 549 
 550     /**
 551      * Returns the name of this doc flavor object's representation class.
 552      * @return the name of the representation class.
 553      */
 554     public String getRepresentationClassName() {
 555         return myClassName;
 556     }
 557 
 558     /**
 559      * Converts this <code>DocFlavor</code> to a string.
 560      *
 561      * @return  MIME type string based on the canonical form. Each parameter
 562      *          value is enclosed in quotes.
 563      *          A "class=" parameter is appended to the
 564      *          MIME type string to indicate the representation class name.
 565      */
 566     public String toString() {
 567         return getStringValue();
 568     }
 569 
 570     /**
 571      * Returns a hash code for this doc flavor object.
 572      */
 573     public int hashCode() {
 574         return getStringValue().hashCode();
 575     }
 576 
 577     /**
 578      * Determines if this doc flavor object is equal to the given object.
 579      * The two are equal if the given object is not null, is an instance
 580      * of <code>DocFlavor</code>, has a MIME type equivalent to this doc
 581      * flavor object's MIME type (that is, the MIME types have the same media
 582      * type, media subtype, and parameters), and has the same representation
 583      * class name as this doc flavor object. Thus, if two doc flavor objects'
 584      * MIME types are the same except for comments, they are considered equal.
 585      * However, two doc flavor objects with MIME types of "text/plain" and
 586      * "text/plain; charset=US-ASCII" are not considered equal, even though
 587      * they represent the same media type (because the default character
 588      * set for plain text is US-ASCII).
 589      *
 590      * @param  obj  Object to test.
 591      *
 592      * @return  True if this doc flavor object equals <CODE>obj</CODE>, false
 593      *          otherwise.
 594      */
 595     public boolean equals(Object obj) {
 596         return
 597             obj != null &&
 598             obj instanceof DocFlavor &&
 599             getStringValue().equals (((DocFlavor) obj).getStringValue());
 600     }
 601 
 602     /**
 603      * Returns this doc flavor object's string value.
 604      */
 605     private String getStringValue() {
 606         if (myStringValue == null) {
 607             myStringValue = myMimeType + "; class=\"" + myClassName + "\"";
 608         }
 609         return myStringValue;
 610     }
 611 
 612     /**
 613      * Write the instance to a stream (ie serialize the object).
 614      */
 615     private void writeObject(ObjectOutputStream s) throws IOException {
 616 
 617         s.defaultWriteObject();
 618         s.writeObject(myMimeType.getMimeType());
 619     }
 620 
 621     /**
 622      * Reconstitute an instance from a stream (that is, deserialize it).
 623      *
 624      * @serialData
 625      * The serialised form of a DocFlavor is the String naming the
 626      * representation class followed by the String representing the canonical
 627      * form of the mime type.
 628      */
 629     private void readObject(ObjectInputStream s)
 630         throws ClassNotFoundException, IOException {
 631 
 632         s.defaultReadObject();
 633         myMimeType = new MimeType((String)s.readObject());
 634     }
 635 
 636     /**
 637      * Class DocFlavor.BYTE_ARRAY provides predefined static constant
 638      * DocFlavor objects for example doc flavors using a byte array
 639      * (<CODE>byte[]</CODE>) as the print data representation class.
 640      *
 641      * @author  Alan Kaminsky
 642      */
 643     public static class BYTE_ARRAY extends DocFlavor {
 644 
 645         private static final long serialVersionUID = -9065578006593857475L;
 646 
 647         /**
 648          * Constructs a new doc flavor with the given MIME type and a print
 649          * data representation class name of <CODE>"[B"</CODE> (byte array).
 650          *
 651          * @param  mimeType   MIME media type string.
 652          *
 653          * @exception  NullPointerException
 654          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
 655          * @exception  IllegalArgumentException
 656          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
 657          *     obey the syntax for a MIME media type string.
 658          */
 659         public BYTE_ARRAY (String mimeType) {
 660             super (mimeType, "[B");
 661         }
 662 
 663         /**
 664          * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
 665          * encoded in the host platform encoding.
 666          * See {@link DocFlavor#hostEncoding hostEncoding}
 667          * Print data representation class name =
 668          * <CODE>"[B"</CODE> (byte array).
 669          */
 670         public static final BYTE_ARRAY TEXT_PLAIN_HOST =
 671             new BYTE_ARRAY ("text/plain; charset="+hostEncoding);
 672 
 673         /**
 674          * Doc flavor with MIME type =
 675          * <CODE>"text/plain; charset=utf-8"</CODE>,
 676          * print data representation class name = <CODE>"[B"</CODE> (byte
 677          * array).
 678          */
 679         public static final BYTE_ARRAY TEXT_PLAIN_UTF_8 =
 680             new BYTE_ARRAY ("text/plain; charset=utf-8");
 681 
 682         /**
 683          * Doc flavor with MIME type =
 684          * <CODE>"text/plain; charset=utf-16"</CODE>,
 685          * print data representation class name = <CODE>"[B"</CODE> (byte
 686          * array).
 687          */
 688         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16 =
 689             new BYTE_ARRAY ("text/plain; charset=utf-16");
 690 
 691 
 692         /**
 693          * Doc flavor with MIME type =
 694          * <CODE>"text/plain; charset=utf-16be"</CODE>
 695          * (big-endian byte ordering),
 696          * print data representation class name = <CODE>"[B"</CODE> (byte
 697          * array).
 698          */
 699         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16BE =
 700             new BYTE_ARRAY ("text/plain; charset=utf-16be");
 701 
 702         /**
 703          * Doc flavor with MIME type =
 704          * <CODE>"text/plain; charset=utf-16le"</CODE>
 705          * (little-endian byte ordering),
 706          * print data representation class name = <CODE>"[B"</CODE> (byte
 707          * array).
 708          */
 709         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16LE =
 710             new BYTE_ARRAY ("text/plain; charset=utf-16le");
 711 
 712         /**
 713          * Doc flavor with MIME type =
 714          * <CODE>"text/plain; charset=us-ascii"</CODE>,
 715          * print data representation class name =
 716          * <CODE>"[B"</CODE> (byte array).
 717          */
 718         public static final BYTE_ARRAY TEXT_PLAIN_US_ASCII =
 719             new BYTE_ARRAY ("text/plain; charset=us-ascii");
 720 
 721 
 722         /**
 723          * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
 724          * encoded in the host platform encoding.
 725          * See {@link DocFlavor#hostEncoding hostEncoding}
 726          * Print data representation class name =
 727          * <CODE>"[B"</CODE> (byte array).
 728          */
 729         public static final BYTE_ARRAY TEXT_HTML_HOST =
 730             new BYTE_ARRAY ("text/html; charset="+hostEncoding);
 731 
 732         /**
 733          * Doc flavor with MIME type =
 734          * <CODE>"text/html; charset=utf-8"</CODE>,
 735          * print data representation class name = <CODE>"[B"</CODE> (byte
 736          * array).
 737          */
 738         public static final BYTE_ARRAY TEXT_HTML_UTF_8 =
 739             new BYTE_ARRAY ("text/html; charset=utf-8");
 740 
 741         /**
 742          * Doc flavor with MIME type =
 743          * <CODE>"text/html; charset=utf-16"</CODE>,
 744          * print data representation class name = <CODE>"[B"</CODE> (byte
 745          * array).
 746          */
 747         public static final BYTE_ARRAY TEXT_HTML_UTF_16 =
 748             new BYTE_ARRAY ("text/html; charset=utf-16");
 749 
 750         /**
 751          * Doc flavor with MIME type =
 752          * <CODE>"text/html; charset=utf-16be"</CODE>
 753          * (big-endian byte ordering),
 754          * print data representation class name = <CODE>"[B"</CODE> (byte
 755          * array).
 756          */
 757         public static final BYTE_ARRAY TEXT_HTML_UTF_16BE =
 758             new BYTE_ARRAY ("text/html; charset=utf-16be");
 759 
 760         /**
 761          * Doc flavor with MIME type =
 762          * <CODE>"text/html; charset=utf-16le"</CODE>
 763          * (little-endian byte ordering),
 764          * print data representation class name = <CODE>"[B"</CODE> (byte
 765          * array).
 766          */
 767         public static final BYTE_ARRAY TEXT_HTML_UTF_16LE =
 768             new BYTE_ARRAY ("text/html; charset=utf-16le");
 769 
 770         /**
 771          * Doc flavor with MIME type =
 772          * <CODE>"text/html; charset=us-ascii"</CODE>,
 773          * print data representation class name =
 774          * <CODE>"[B"</CODE> (byte array).
 775          */
 776         public static final BYTE_ARRAY TEXT_HTML_US_ASCII =
 777             new BYTE_ARRAY ("text/html; charset=us-ascii");
 778 
 779 
 780         /**
 781          * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
 782          * data representation class name = <CODE>"[B"</CODE> (byte array).
 783          */
 784         public static final BYTE_ARRAY PDF = new BYTE_ARRAY ("application/pdf");
 785 
 786         /**
 787          * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
 788          * print data representation class name = <CODE>"[B"</CODE> (byte
 789          * array).
 790          */
 791         public static final BYTE_ARRAY POSTSCRIPT =
 792             new BYTE_ARRAY ("application/postscript");
 793 
 794         /**
 795          * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
 796          * print data representation class name = <CODE>"[B"</CODE> (byte
 797          * array).
 798          */
 799         public static final BYTE_ARRAY PCL =
 800             new BYTE_ARRAY ("application/vnd.hp-PCL");
 801 
 802         /**
 803          * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
 804          * representation class name = <CODE>"[B"</CODE> (byte array).
 805          */
 806         public static final BYTE_ARRAY GIF = new BYTE_ARRAY ("image/gif");
 807 
 808         /**
 809          * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
 810          * representation class name = <CODE>"[B"</CODE> (byte array).
 811          */
 812         public static final BYTE_ARRAY JPEG = new BYTE_ARRAY ("image/jpeg");
 813 
 814         /**
 815          * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
 816          * representation class name = <CODE>"[B"</CODE> (byte array).
 817          */
 818         public static final BYTE_ARRAY PNG = new BYTE_ARRAY ("image/png");
 819 
 820         /**
 821          * Doc flavor with MIME type =
 822          * <CODE>"application/octet-stream"</CODE>,
 823          * print data representation class name = <CODE>"[B"</CODE> (byte
 824          * array). The client must determine that data described
 825          * using this DocFlavor is valid for the printer.
 826          */
 827         public static final BYTE_ARRAY AUTOSENSE =
 828             new BYTE_ARRAY ("application/octet-stream");
 829 
 830     }
 831 
 832     /**
 833      * Class DocFlavor.INPUT_STREAM provides predefined static constant
 834      * DocFlavor objects for example doc flavors using a byte stream ({@link
 835      * java.io.InputStream java.io.InputStream}) as the print
 836      * data representation class.
 837      *
 838      * @author  Alan Kaminsky
 839      */
 840     public static class INPUT_STREAM extends DocFlavor {
 841 
 842         private static final long serialVersionUID = -7045842700749194127L;
 843 
 844         /**
 845          * Constructs a new doc flavor with the given MIME type and a print
 846          * data representation class name of
 847          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 848          *
 849          * @param  mimeType   MIME media type string.
 850          *
 851          * @exception  NullPointerException
 852          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
 853          * @exception  IllegalArgumentException
 854          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
 855          *     obey the syntax for a MIME media type string.
 856          */
 857         public INPUT_STREAM (String mimeType) {
 858             super (mimeType, "java.io.InputStream");
 859         }
 860 
 861         /**
 862          * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
 863          * encoded in the host platform encoding.
 864          * See {@link DocFlavor#hostEncoding hostEncoding}
 865          * Print data representation class name =
 866          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 867          */
 868         public static final INPUT_STREAM TEXT_PLAIN_HOST =
 869             new INPUT_STREAM ("text/plain; charset="+hostEncoding);
 870 
 871         /**
 872          * Doc flavor with MIME type =
 873          * <CODE>"text/plain; charset=utf-8"</CODE>,
 874          * print data representation class name =
 875          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 876          */
 877         public static final INPUT_STREAM TEXT_PLAIN_UTF_8 =
 878             new INPUT_STREAM ("text/plain; charset=utf-8");
 879 
 880         /**
 881          * Doc flavor with MIME type =
 882          * <CODE>"text/plain; charset=utf-16"</CODE>,
 883          * print data representation class name =
 884          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 885          */
 886         public static final INPUT_STREAM TEXT_PLAIN_UTF_16 =
 887             new INPUT_STREAM ("text/plain; charset=utf-16");
 888 
 889         /**
 890          * Doc flavor with MIME type =
 891          * <CODE>"text/plain; charset=utf-16be"</CODE>
 892          * (big-endian byte ordering),
 893          * print data representation class name =
 894          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 895          */
 896         public static final INPUT_STREAM TEXT_PLAIN_UTF_16BE =
 897             new INPUT_STREAM ("text/plain; charset=utf-16be");
 898 
 899         /**
 900          * Doc flavor with MIME type =
 901          * <CODE>"text/plain; charset=utf-16le"</CODE>
 902          * (little-endian byte ordering),
 903          * print data representation class name =
 904          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 905          */
 906         public static final INPUT_STREAM TEXT_PLAIN_UTF_16LE =
 907             new INPUT_STREAM ("text/plain; charset=utf-16le");
 908 
 909         /**
 910          * Doc flavor with MIME type =
 911          * <CODE>"text/plain; charset=us-ascii"</CODE>,
 912          * print data representation class name =
 913          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 914          */
 915         public static final INPUT_STREAM TEXT_PLAIN_US_ASCII =
 916                 new INPUT_STREAM ("text/plain; charset=us-ascii");
 917 
 918         /**
 919          * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
 920          * encoded in the host platform encoding.
 921          * See {@link DocFlavor#hostEncoding hostEncoding}
 922          * Print data representation class name =
 923          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 924          */
 925         public static final INPUT_STREAM TEXT_HTML_HOST =
 926             new INPUT_STREAM ("text/html; charset="+hostEncoding);
 927 
 928         /**
 929          * Doc flavor with MIME type =
 930          * <CODE>"text/html; charset=utf-8"</CODE>,
 931          * print data representation class name =
 932          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 933          */
 934         public static final INPUT_STREAM TEXT_HTML_UTF_8 =
 935             new INPUT_STREAM ("text/html; charset=utf-8");
 936 
 937         /**
 938          * Doc flavor with MIME type =
 939          * <CODE>"text/html; charset=utf-16"</CODE>,
 940          * print data representation class name =
 941          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 942          */
 943         public static final INPUT_STREAM TEXT_HTML_UTF_16 =
 944             new INPUT_STREAM ("text/html; charset=utf-16");
 945 
 946         /**
 947          * Doc flavor with MIME type =
 948          * <CODE>"text/html; charset=utf-16be"</CODE>
 949          * (big-endian byte ordering),
 950          * print data representation class name =
 951          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 952          */
 953         public static final INPUT_STREAM TEXT_HTML_UTF_16BE =
 954             new INPUT_STREAM ("text/html; charset=utf-16be");
 955 
 956         /**
 957          * Doc flavor with MIME type =
 958          * <CODE>"text/html; charset=utf-16le"</CODE>
 959          * (little-endian byte ordering),
 960          * print data representation class name =
 961          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 962          */
 963         public static final INPUT_STREAM TEXT_HTML_UTF_16LE =
 964             new INPUT_STREAM ("text/html; charset=utf-16le");
 965 
 966         /**
 967          * Doc flavor with MIME type =
 968          * <CODE>"text/html; charset=us-ascii"</CODE>,
 969          * print data representation class name =
 970          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 971          */
 972         public static final INPUT_STREAM TEXT_HTML_US_ASCII =
 973             new INPUT_STREAM ("text/html; charset=us-ascii");
 974 
 975 
 976         /**
 977          * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
 978          * data representation class name = <CODE>"java.io.InputStream"</CODE>
 979          * (byte stream).
 980          */
 981         public static final INPUT_STREAM PDF = new INPUT_STREAM ("application/pdf");
 982 
 983         /**
 984          * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
 985          * print data representation class name =
 986          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 987          */
 988         public static final INPUT_STREAM POSTSCRIPT =
 989             new INPUT_STREAM ("application/postscript");
 990 
 991         /**
 992          * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
 993          * print data representation class name =
 994          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 995          */
 996         public static final INPUT_STREAM PCL =
 997             new INPUT_STREAM ("application/vnd.hp-PCL");
 998 
 999         /**
1000          * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
1001          * representation class name =
1002          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1003          */
1004         public static final INPUT_STREAM GIF = new INPUT_STREAM ("image/gif");
1005 
1006         /**
1007          * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
1008          * representation class name =
1009          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1010          */
1011         public static final INPUT_STREAM JPEG = new INPUT_STREAM ("image/jpeg");
1012 
1013         /**
1014          * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
1015          * representation class name =
1016          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1017          */
1018         public static final INPUT_STREAM PNG = new INPUT_STREAM ("image/png");
1019 
1020         /**
1021          * Doc flavor with MIME type =
1022          * <CODE>"application/octet-stream"</CODE>,
1023          * print data representation class name =
1024          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1025          * The client must determine that data described
1026          * using this DocFlavor is valid for the printer.
1027          */
1028         public static final INPUT_STREAM AUTOSENSE =
1029             new INPUT_STREAM ("application/octet-stream");
1030 
1031     }
1032 
1033     /**
1034      * Class DocFlavor.URL provides predefined static constant DocFlavor
1035      * objects.
1036      * For example doc flavors using a Uniform Resource Locator ({@link
1037      * java.net.URL java.net.URL}) as the print data
1038      * representation  class.
1039      *
1040      * @author  Alan Kaminsky
1041      */
1042     public static class URL extends DocFlavor {
1043         private static final long serialVersionUID = 2936725788144902062L;
1044 
1045         /**
1046          * Constructs a new doc flavor with the given MIME type and a print
1047          * data representation class name of <CODE>"java.net.URL"</CODE>.
1048          *
1049          * @param  mimeType   MIME media type string.
1050          *
1051          * @exception  NullPointerException
1052          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1053          * @exception  IllegalArgumentException
1054          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1055          *     obey the syntax for a MIME media type string.
1056          */
1057         public URL (String mimeType) {
1058             super (mimeType, "java.net.URL");
1059         }
1060 
1061         /**
1062          * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
1063          * encoded in the host platform encoding.
1064          * See {@link DocFlavor#hostEncoding hostEncoding}
1065          * Print data representation class name =
1066          * <CODE>"java.net.URL"</CODE> (byte stream).
1067          */
1068         public static final URL TEXT_PLAIN_HOST =
1069             new URL ("text/plain; charset="+hostEncoding);
1070 
1071         /**
1072          * Doc flavor with MIME type =
1073          * <CODE>"text/plain; charset=utf-8"</CODE>,
1074          * print data representation class name =
1075          * <CODE>"java.net.URL"</CODE> (byte stream).
1076          */
1077         public static final URL TEXT_PLAIN_UTF_8 =
1078             new URL ("text/plain; charset=utf-8");
1079 
1080         /**
1081          * Doc flavor with MIME type =
1082          * <CODE>"text/plain; charset=utf-16"</CODE>,
1083          * print data representation class name =
1084          * <CODE>java.net.URL""</CODE> (byte stream).
1085          */
1086         public static final URL TEXT_PLAIN_UTF_16 =
1087             new URL ("text/plain; charset=utf-16");
1088 
1089         /**
1090          * Doc flavor with MIME type =
1091          * <CODE>"text/plain; charset=utf-16be"</CODE>
1092          * (big-endian byte ordering),
1093          * print data representation class name =
1094          * <CODE>"java.net.URL"</CODE> (byte stream).
1095          */
1096         public static final URL TEXT_PLAIN_UTF_16BE =
1097             new URL ("text/plain; charset=utf-16be");
1098 
1099         /**
1100          * Doc flavor with MIME type =
1101          * <CODE>"text/plain; charset=utf-16le"</CODE>
1102          * (little-endian byte ordering),
1103          * print data representation class name =
1104          * <CODE>"java.net.URL"</CODE> (byte stream).
1105          */
1106         public static final URL TEXT_PLAIN_UTF_16LE =
1107             new URL ("text/plain; charset=utf-16le");
1108 
1109         /**
1110          * Doc flavor with MIME type =
1111          * <CODE>"text/plain; charset=us-ascii"</CODE>,
1112          * print data representation class name =
1113          * <CODE>"java.net.URL"</CODE> (byte stream).
1114          */
1115         public static final URL TEXT_PLAIN_US_ASCII =
1116             new URL ("text/plain; charset=us-ascii");
1117 
1118         /**
1119          * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
1120          * encoded in the host platform encoding.
1121          * See {@link DocFlavor#hostEncoding hostEncoding}
1122          * Print data representation class name =
1123          * <CODE>"java.net.URL"</CODE> (byte stream).
1124          */
1125         public static final URL TEXT_HTML_HOST =
1126             new URL ("text/html; charset="+hostEncoding);
1127 
1128         /**
1129          * Doc flavor with MIME type =
1130          * <CODE>"text/html; charset=utf-8"</CODE>,
1131          * print data representation class name =
1132          * <CODE>"java.net.URL"</CODE> (byte stream).
1133          */
1134         public static final URL TEXT_HTML_UTF_8 =
1135             new URL ("text/html; charset=utf-8");
1136 
1137         /**
1138          * Doc flavor with MIME type =
1139          * <CODE>"text/html; charset=utf-16"</CODE>,
1140          * print data representation class name =
1141          * <CODE>"java.net.URL"</CODE> (byte stream).
1142          */
1143         public static final URL TEXT_HTML_UTF_16 =
1144             new URL ("text/html; charset=utf-16");
1145 
1146         /**
1147          * Doc flavor with MIME type =
1148          * <CODE>"text/html; charset=utf-16be"</CODE>
1149          * (big-endian byte ordering),
1150          * print data representation class name =
1151          * <CODE>"java.net.URL"</CODE> (byte stream).
1152          */
1153         public static final URL TEXT_HTML_UTF_16BE =
1154             new URL ("text/html; charset=utf-16be");
1155 
1156         /**
1157          * Doc flavor with MIME type =
1158          * <CODE>"text/html; charset=utf-16le"</CODE>
1159          * (little-endian byte ordering),
1160          * print data representation class name =
1161          * <CODE>"java.net.URL"</CODE> (byte stream).
1162          */
1163         public static final URL TEXT_HTML_UTF_16LE =
1164             new URL ("text/html; charset=utf-16le");
1165 
1166         /**
1167          * Doc flavor with MIME type =
1168          * <CODE>"text/html; charset=us-ascii"</CODE>,
1169          * print data representation class name =
1170          * <CODE>"java.net.URL"</CODE> (byte stream).
1171          */
1172         public static final URL TEXT_HTML_US_ASCII =
1173             new URL ("text/html; charset=us-ascii");
1174 
1175 
1176         /**
1177          * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
1178          * data representation class name = <CODE>"java.net.URL"</CODE>.
1179          */
1180         public static final URL PDF = new URL ("application/pdf");
1181 
1182         /**
1183          * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
1184          * print data representation class name = <CODE>"java.net.URL"</CODE>.
1185          */
1186         public static final URL POSTSCRIPT = new URL ("application/postscript");
1187 
1188         /**
1189          * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
1190          * print data representation class name = <CODE>"java.net.URL"</CODE>.
1191          */
1192         public static final URL PCL = new URL ("application/vnd.hp-PCL");
1193 
1194         /**
1195          * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
1196          * representation class name = <CODE>"java.net.URL"</CODE>.
1197          */
1198         public static final URL GIF = new URL ("image/gif");
1199 
1200         /**
1201          * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
1202          * representation class name = <CODE>"java.net.URL"</CODE>.
1203          */
1204         public static final URL JPEG = new URL ("image/jpeg");
1205 
1206         /**
1207          * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
1208          * representation class name = <CODE>"java.net.URL"</CODE>.
1209          */
1210         public static final URL PNG = new URL ("image/png");
1211 
1212         /**
1213          * Doc flavor with MIME type =
1214          * <CODE>"application/octet-stream"</CODE>,
1215          * print data representation class name = <CODE>"java.net.URL"</CODE>.
1216          *  The client must determine that data described
1217          * using this DocFlavor is valid for the printer.
1218          */
1219         public static final URL AUTOSENSE = new URL ("application/octet-stream");
1220 
1221     }
1222 
1223     /**
1224      * Class DocFlavor.CHAR_ARRAY provides predefined static constant
1225      * DocFlavor objects for example doc flavors using a character array
1226      * (<CODE>char[]</CODE>) as the print data representation class. As such,
1227      * the character set is Unicode.
1228      *
1229      * @author  Alan Kaminsky
1230      */
1231     public static class CHAR_ARRAY extends DocFlavor {
1232 
1233         private static final long serialVersionUID = -8720590903724405128L;
1234 
1235         /**
1236          * Constructs a new doc flavor with the given MIME type and a print
1237          * data representation class name of
1238          * <CODE>"[C"</CODE> (character array).
1239          *
1240          * @param  mimeType  MIME media type string. If it is a text media
1241          *                      type, it is assumed to contain a
1242          *                      <CODE>"charset=utf-16"</CODE> parameter.
1243          *
1244          * @exception  NullPointerException
1245          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1246          * @exception  IllegalArgumentException
1247          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1248          *     obey the syntax for a MIME media type string.
1249          */
1250         public CHAR_ARRAY (String mimeType) {
1251             super (mimeType, "[C");
1252         }
1253 
1254         /**
1255          * Doc flavor with MIME type = <CODE>"text/plain;
1256          * charset=utf-16"</CODE>, print data representation class name =
1257          * <CODE>"[C"</CODE> (character array).
1258          */
1259         public static final CHAR_ARRAY TEXT_PLAIN =
1260             new CHAR_ARRAY ("text/plain; charset=utf-16");
1261 
1262         /**
1263          * Doc flavor with MIME type = <CODE>"text/html;
1264          * charset=utf-16"</CODE>, print data representation class name =
1265          * <CODE>"[C"</CODE> (character array).
1266          */
1267         public static final CHAR_ARRAY TEXT_HTML =
1268             new CHAR_ARRAY ("text/html; charset=utf-16");
1269 
1270     }
1271 
1272     /**
1273      * Class DocFlavor.STRING provides predefined static constant DocFlavor
1274      * objects for example doc flavors using a string ({@link java.lang.String
1275      * java.lang.String}) as the print data representation class.
1276      * As such, the character set is Unicode.
1277      *
1278      * @author  Alan Kaminsky
1279      */
1280     public static class STRING extends DocFlavor {
1281 
1282         private static final long serialVersionUID = 4414407504887034035L;
1283 
1284         /**
1285          * Constructs a new doc flavor with the given MIME type and a print
1286          * data representation class name of <CODE>"java.lang.String"</CODE>.
1287          *
1288          * @param  mimeType  MIME media type string. If it is a text media
1289          *                      type, it is assumed to contain a
1290          *                      <CODE>"charset=utf-16"</CODE> parameter.
1291          *
1292          * @exception  NullPointerException
1293          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1294          * @exception  IllegalArgumentException
1295          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1296          *     obey the syntax for a MIME media type string.
1297          */
1298         public STRING (String mimeType) {
1299             super (mimeType, "java.lang.String");
1300         }
1301 
1302         /**
1303          * Doc flavor with MIME type = <CODE>"text/plain;
1304          * charset=utf-16"</CODE>, print data representation class name =
1305          * <CODE>"java.lang.String"</CODE>.
1306          */
1307         public static final STRING TEXT_PLAIN =
1308             new STRING ("text/plain; charset=utf-16");
1309 
1310         /**
1311          * Doc flavor with MIME type = <CODE>"text/html;
1312          * charset=utf-16"</CODE>, print data representation class name =
1313          * <CODE>"java.lang.String"</CODE>.
1314          */
1315         public static final STRING TEXT_HTML =
1316             new STRING ("text/html; charset=utf-16");
1317     }
1318 
1319     /**
1320      * Class DocFlavor.READER provides predefined static constant DocFlavor
1321      * objects for example doc flavors using a character stream ({@link
1322      * java.io.Reader java.io.Reader}) as the print data
1323      * representation class. As such, the character set is Unicode.
1324      *
1325      * @author  Alan Kaminsky
1326      */
1327     public static class READER extends DocFlavor {
1328 
1329         private static final long serialVersionUID = 7100295812579351567L;
1330 
1331         /**
1332          * Constructs a new doc flavor with the given MIME type and a print
1333          * data representation class name of\
1334          * <CODE>"java.io.Reader"</CODE> (character stream).
1335          *
1336          * @param  mimeType  MIME media type string. If it is a text media
1337          *                      type, it is assumed to contain a
1338          *                      <CODE>"charset=utf-16"</CODE> parameter.
1339          *
1340          * @exception  NullPointerException
1341          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1342          * @exception  IllegalArgumentException
1343          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1344          *     obey the syntax for a MIME media type string.
1345          */
1346         public READER (String mimeType) {
1347             super (mimeType, "java.io.Reader");
1348         }
1349 
1350         /**
1351          * Doc flavor with MIME type = <CODE>"text/plain;
1352          * charset=utf-16"</CODE>, print data representation class name =
1353          * <CODE>"java.io.Reader"</CODE> (character stream).
1354          */
1355         public static final READER TEXT_PLAIN =
1356             new READER ("text/plain; charset=utf-16");
1357 
1358         /**
1359          * Doc flavor with MIME type = <CODE>"text/html;
1360          * charset=utf-16"</CODE>, print data representation class name =
1361          * <CODE>"java.io.Reader"</CODE> (character stream).
1362          */
1363         public static final READER TEXT_HTML =
1364             new READER ("text/html; charset=utf-16");
1365 
1366     }
1367 
1368     /**
1369      * Class DocFlavor.SERVICE_FORMATTED provides predefined static constant
1370      * DocFlavor objects for example doc flavors for service formatted print
1371      * data.
1372      *
1373      * @author  Alan Kaminsky
1374      */
1375     public static class SERVICE_FORMATTED extends DocFlavor {
1376 
1377         private static final long serialVersionUID = 6181337766266637256L;
1378 
1379         /**
1380          * Constructs a new doc flavor with a MIME type of
1381          * <CODE>"application/x-java-jvm-local-objectref"</CODE> indicating
1382          * service formatted print data and the given print data
1383          * representation class name.
1384          *
1385          * @param  className  Fully-qualified representation class name.
1386          *
1387          * @exception  NullPointerException
1388          *     (unchecked exception) Thrown if <CODE>className</CODE> is
1389          *     null.
1390          */
1391         public SERVICE_FORMATTED (String className) {
1392             super ("application/x-java-jvm-local-objectref", className);
1393         }
1394 
1395         /**
1396          * Service formatted print data doc flavor with print data
1397          * representation class name =
1398          * <CODE>"java.awt.image.renderable.RenderableImage"</CODE>
1399          * (renderable image object).
1400          */
1401         public static final SERVICE_FORMATTED RENDERABLE_IMAGE =
1402             new SERVICE_FORMATTED("java.awt.image.renderable.RenderableImage");
1403 
1404         /**
1405          * Service formatted print data doc flavor with print data
1406          * representation class name = <CODE>"java.awt.print.Printable"</CODE>
1407          * (printable object).
1408          */
1409         public static final SERVICE_FORMATTED PRINTABLE =
1410             new SERVICE_FORMATTED ("java.awt.print.Printable");
1411 
1412         /**
1413          * Service formatted print data doc flavor with print data
1414          * representation class name = <CODE>"java.awt.print.Pageable"</CODE>
1415          * (pageable object).
1416          */
1417         public static final SERVICE_FORMATTED PAGEABLE =
1418             new SERVICE_FORMATTED ("java.awt.print.Pageable");
1419 
1420         }
1421 
1422 }