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 myMimeType.getParameterMap().get(paramName.toLowerCase());

 549     }
 550 
 551     /**
 552      * Returns the name of this doc flavor object's representation class.
 553      * @return the name of the representation class.
 554      */
 555     public String getRepresentationClassName() {
 556         return myClassName;
 557     }
 558 
 559     /**
 560      * Converts this <code>DocFlavor</code> to a string.
 561      *
 562      * @return  MIME type string based on the canonical form. Each parameter
 563      *          value is enclosed in quotes.
 564      *          A "class=" parameter is appended to the
 565      *          MIME type string to indicate the representation class name.
 566      */
 567     public String toString() {
 568         return getStringValue();
 569     }
 570 
 571     /**
 572      * Returns a hash code for this doc flavor object.
 573      */
 574     public int hashCode() {
 575         return getStringValue().hashCode();
 576     }
 577 
 578     /**
 579      * Determines if this doc flavor object is equal to the given object.
 580      * The two are equal if the given object is not null, is an instance
 581      * of <code>DocFlavor</code>, has a MIME type equivalent to this doc
 582      * flavor object's MIME type (that is, the MIME types have the same media
 583      * type, media subtype, and parameters), and has the same representation
 584      * class name as this doc flavor object. Thus, if two doc flavor objects'
 585      * MIME types are the same except for comments, they are considered equal.
 586      * However, two doc flavor objects with MIME types of "text/plain" and
 587      * "text/plain; charset=US-ASCII" are not considered equal, even though
 588      * they represent the same media type (because the default character
 589      * set for plain text is US-ASCII).
 590      *
 591      * @param  obj  Object to test.
 592      *
 593      * @return  True if this doc flavor object equals <CODE>obj</CODE>, false
 594      *          otherwise.
 595      */
 596     public boolean equals(Object obj) {
 597         return
 598             obj != null &&
 599             obj instanceof DocFlavor &&
 600             getStringValue().equals (((DocFlavor) obj).getStringValue());
 601     }
 602 
 603     /**
 604      * Returns this doc flavor object's string value.
 605      */
 606     private String getStringValue() {
 607         if (myStringValue == null) {
 608             myStringValue = myMimeType + "; class=\"" + myClassName + "\"";
 609         }
 610         return myStringValue;
 611     }
 612 
 613     /**
 614      * Write the instance to a stream (ie serialize the object).
 615      */
 616     private void writeObject(ObjectOutputStream s) throws IOException {
 617 
 618         s.defaultWriteObject();
 619         s.writeObject(myMimeType.getMimeType());
 620     }
 621 
 622     /**
 623      * Reconstitute an instance from a stream (that is, deserialize it).
 624      *
 625      * @serialData
 626      * The serialised form of a DocFlavor is the String naming the
 627      * representation class followed by the String representing the canonical
 628      * form of the mime type.
 629      */
 630     private void readObject(ObjectInputStream s)
 631         throws ClassNotFoundException, IOException {
 632 
 633         s.defaultReadObject();
 634         myMimeType = new MimeType((String)s.readObject());
 635     }
 636 
 637     /**
 638      * Class DocFlavor.BYTE_ARRAY provides predefined static constant
 639      * DocFlavor objects for example doc flavors using a byte array
 640      * (<CODE>byte[]</CODE>) as the print data representation class.
 641      * <P>
 642      *
 643      * @author  Alan Kaminsky
 644      */
 645     public static class BYTE_ARRAY extends DocFlavor {
 646 
 647         private static final long serialVersionUID = -9065578006593857475L;
 648 
 649         /**
 650          * Constructs a new doc flavor with the given MIME type and a print
 651          * data representation class name of <CODE>"[B"</CODE> (byte array).
 652          *
 653          * @param  mimeType   MIME media type string.
 654          *
 655          * @exception  NullPointerException
 656          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
 657          * @exception  IllegalArgumentException
 658          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
 659          *     obey the syntax for a MIME media type string.
 660          */
 661         public BYTE_ARRAY (String mimeType) {
 662             super (mimeType, "[B");
 663         }
 664 
 665         /**
 666          * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
 667          * encoded in the host platform encoding.
 668          * See {@link DocFlavor#hostEncoding hostEncoding}
 669          * Print data representation class name =
 670          * <CODE>"[B"</CODE> (byte array).
 671          */
 672         public static final BYTE_ARRAY TEXT_PLAIN_HOST =
 673             new BYTE_ARRAY ("text/plain; charset="+hostEncoding);
 674 
 675         /**
 676          * Doc flavor with MIME type =
 677          * <CODE>"text/plain; charset=utf-8"</CODE>,
 678          * print data representation class name = <CODE>"[B"</CODE> (byte
 679          * array).
 680          */
 681         public static final BYTE_ARRAY TEXT_PLAIN_UTF_8 =
 682             new BYTE_ARRAY ("text/plain; charset=utf-8");
 683 
 684         /**
 685          * Doc flavor with MIME type =
 686          * <CODE>"text/plain; charset=utf-16"</CODE>,
 687          * print data representation class name = <CODE>"[B"</CODE> (byte
 688          * array).
 689          */
 690         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16 =
 691             new BYTE_ARRAY ("text/plain; charset=utf-16");
 692 
 693 
 694         /**
 695          * Doc flavor with MIME type =
 696          * <CODE>"text/plain; charset=utf-16be"</CODE>
 697          * (big-endian byte ordering),
 698          * print data representation class name = <CODE>"[B"</CODE> (byte
 699          * array).
 700          */
 701         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16BE =
 702             new BYTE_ARRAY ("text/plain; charset=utf-16be");
 703 
 704         /**
 705          * Doc flavor with MIME type =
 706          * <CODE>"text/plain; charset=utf-16le"</CODE>
 707          * (little-endian byte ordering),
 708          * print data representation class name = <CODE>"[B"</CODE> (byte
 709          * array).
 710          */
 711         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16LE =
 712             new BYTE_ARRAY ("text/plain; charset=utf-16le");
 713 
 714         /**
 715          * Doc flavor with MIME type =
 716          * <CODE>"text/plain; charset=us-ascii"</CODE>,
 717          * print data representation class name =
 718          * <CODE>"[B"</CODE> (byte array).
 719          */
 720         public static final BYTE_ARRAY TEXT_PLAIN_US_ASCII =
 721             new BYTE_ARRAY ("text/plain; charset=us-ascii");
 722 
 723 
 724         /**
 725          * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
 726          * encoded in the host platform encoding.
 727          * See {@link DocFlavor#hostEncoding hostEncoding}
 728          * Print data representation class name =
 729          * <CODE>"[B"</CODE> (byte array).
 730          */
 731         public static final BYTE_ARRAY TEXT_HTML_HOST =
 732             new BYTE_ARRAY ("text/html; charset="+hostEncoding);
 733 
 734         /**
 735          * Doc flavor with MIME type =
 736          * <CODE>"text/html; charset=utf-8"</CODE>,
 737          * print data representation class name = <CODE>"[B"</CODE> (byte
 738          * array).
 739          */
 740         public static final BYTE_ARRAY TEXT_HTML_UTF_8 =
 741             new BYTE_ARRAY ("text/html; charset=utf-8");
 742 
 743         /**
 744          * Doc flavor with MIME type =
 745          * <CODE>"text/html; charset=utf-16"</CODE>,
 746          * print data representation class name = <CODE>"[B"</CODE> (byte
 747          * array).
 748          */
 749         public static final BYTE_ARRAY TEXT_HTML_UTF_16 =
 750             new BYTE_ARRAY ("text/html; charset=utf-16");
 751 
 752         /**
 753          * Doc flavor with MIME type =
 754          * <CODE>"text/html; charset=utf-16be"</CODE>
 755          * (big-endian byte ordering),
 756          * print data representation class name = <CODE>"[B"</CODE> (byte
 757          * array).
 758          */
 759         public static final BYTE_ARRAY TEXT_HTML_UTF_16BE =
 760             new BYTE_ARRAY ("text/html; charset=utf-16be");
 761 
 762         /**
 763          * Doc flavor with MIME type =
 764          * <CODE>"text/html; charset=utf-16le"</CODE>
 765          * (little-endian byte ordering),
 766          * print data representation class name = <CODE>"[B"</CODE> (byte
 767          * array).
 768          */
 769         public static final BYTE_ARRAY TEXT_HTML_UTF_16LE =
 770             new BYTE_ARRAY ("text/html; charset=utf-16le");
 771 
 772         /**
 773          * Doc flavor with MIME type =
 774          * <CODE>"text/html; charset=us-ascii"</CODE>,
 775          * print data representation class name =
 776          * <CODE>"[B"</CODE> (byte array).
 777          */
 778         public static final BYTE_ARRAY TEXT_HTML_US_ASCII =
 779             new BYTE_ARRAY ("text/html; charset=us-ascii");
 780 
 781 
 782         /**
 783          * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
 784          * data representation class name = <CODE>"[B"</CODE> (byte array).
 785          */
 786         public static final BYTE_ARRAY PDF = new BYTE_ARRAY ("application/pdf");
 787 
 788         /**
 789          * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
 790          * print data representation class name = <CODE>"[B"</CODE> (byte
 791          * array).
 792          */
 793         public static final BYTE_ARRAY POSTSCRIPT =
 794             new BYTE_ARRAY ("application/postscript");
 795 
 796         /**
 797          * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
 798          * print data representation class name = <CODE>"[B"</CODE> (byte
 799          * array).
 800          */
 801         public static final BYTE_ARRAY PCL =
 802             new BYTE_ARRAY ("application/vnd.hp-PCL");
 803 
 804         /**
 805          * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
 806          * representation class name = <CODE>"[B"</CODE> (byte array).
 807          */
 808         public static final BYTE_ARRAY GIF = new BYTE_ARRAY ("image/gif");
 809 
 810         /**
 811          * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
 812          * representation class name = <CODE>"[B"</CODE> (byte array).
 813          */
 814         public static final BYTE_ARRAY JPEG = new BYTE_ARRAY ("image/jpeg");
 815 
 816         /**
 817          * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
 818          * representation class name = <CODE>"[B"</CODE> (byte array).
 819          */
 820         public static final BYTE_ARRAY PNG = new BYTE_ARRAY ("image/png");
 821 
 822         /**
 823          * Doc flavor with MIME type =
 824          * <CODE>"application/octet-stream"</CODE>,
 825          * print data representation class name = <CODE>"[B"</CODE> (byte
 826          * array). The client must determine that data described
 827          * using this DocFlavor is valid for the printer.
 828          */
 829         public static final BYTE_ARRAY AUTOSENSE =
 830             new BYTE_ARRAY ("application/octet-stream");
 831 
 832     }
 833 
 834     /**
 835      * Class DocFlavor.INPUT_STREAM provides predefined static constant
 836      * DocFlavor objects for example doc flavors using a byte stream ({@link
 837      * java.io.InputStream java.io.InputStream}) as the print
 838      * data representation class.
 839      * <P>
 840      *
 841      * @author  Alan Kaminsky
 842      */
 843     public static class INPUT_STREAM extends DocFlavor {
 844 
 845         private static final long serialVersionUID = -7045842700749194127L;
 846 
 847         /**
 848          * Constructs a new doc flavor with the given MIME type and a print
 849          * data representation class name of
 850          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 851          *
 852          * @param  mimeType   MIME media type string.
 853          *
 854          * @exception  NullPointerException
 855          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
 856          * @exception  IllegalArgumentException
 857          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
 858          *     obey the syntax for a MIME media type string.
 859          */
 860         public INPUT_STREAM (String mimeType) {
 861             super (mimeType, "java.io.InputStream");
 862         }
 863 
 864         /**
 865          * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
 866          * encoded in the host platform encoding.
 867          * See {@link DocFlavor#hostEncoding hostEncoding}
 868          * Print data representation class name =
 869          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 870          */
 871         public static final INPUT_STREAM TEXT_PLAIN_HOST =
 872             new INPUT_STREAM ("text/plain; charset="+hostEncoding);
 873 
 874         /**
 875          * Doc flavor with MIME type =
 876          * <CODE>"text/plain; charset=utf-8"</CODE>,
 877          * print data representation class name =
 878          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 879          */
 880         public static final INPUT_STREAM TEXT_PLAIN_UTF_8 =
 881             new INPUT_STREAM ("text/plain; charset=utf-8");
 882 
 883         /**
 884          * Doc flavor with MIME type =
 885          * <CODE>"text/plain; charset=utf-16"</CODE>,
 886          * print data representation class name =
 887          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 888          */
 889         public static final INPUT_STREAM TEXT_PLAIN_UTF_16 =
 890             new INPUT_STREAM ("text/plain; charset=utf-16");
 891 
 892         /**
 893          * Doc flavor with MIME type =
 894          * <CODE>"text/plain; charset=utf-16be"</CODE>
 895          * (big-endian byte ordering),
 896          * print data representation class name =
 897          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 898          */
 899         public static final INPUT_STREAM TEXT_PLAIN_UTF_16BE =
 900             new INPUT_STREAM ("text/plain; charset=utf-16be");
 901 
 902         /**
 903          * Doc flavor with MIME type =
 904          * <CODE>"text/plain; charset=utf-16le"</CODE>
 905          * (little-endian byte ordering),
 906          * print data representation class name =
 907          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 908          */
 909         public static final INPUT_STREAM TEXT_PLAIN_UTF_16LE =
 910             new INPUT_STREAM ("text/plain; charset=utf-16le");
 911 
 912         /**
 913          * Doc flavor with MIME type =
 914          * <CODE>"text/plain; charset=us-ascii"</CODE>,
 915          * print data representation class name =
 916          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 917          */
 918         public static final INPUT_STREAM TEXT_PLAIN_US_ASCII =
 919                 new INPUT_STREAM ("text/plain; charset=us-ascii");
 920 
 921         /**
 922          * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
 923          * encoded in the host platform encoding.
 924          * See {@link DocFlavor#hostEncoding hostEncoding}
 925          * Print data representation class name =
 926          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 927          */
 928         public static final INPUT_STREAM TEXT_HTML_HOST =
 929             new INPUT_STREAM ("text/html; charset="+hostEncoding);
 930 
 931         /**
 932          * Doc flavor with MIME type =
 933          * <CODE>"text/html; charset=utf-8"</CODE>,
 934          * print data representation class name =
 935          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 936          */
 937         public static final INPUT_STREAM TEXT_HTML_UTF_8 =
 938             new INPUT_STREAM ("text/html; charset=utf-8");
 939 
 940         /**
 941          * Doc flavor with MIME type =
 942          * <CODE>"text/html; charset=utf-16"</CODE>,
 943          * print data representation class name =
 944          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 945          */
 946         public static final INPUT_STREAM TEXT_HTML_UTF_16 =
 947             new INPUT_STREAM ("text/html; charset=utf-16");
 948 
 949         /**
 950          * Doc flavor with MIME type =
 951          * <CODE>"text/html; charset=utf-16be"</CODE>
 952          * (big-endian byte ordering),
 953          * print data representation class name =
 954          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 955          */
 956         public static final INPUT_STREAM TEXT_HTML_UTF_16BE =
 957             new INPUT_STREAM ("text/html; charset=utf-16be");
 958 
 959         /**
 960          * Doc flavor with MIME type =
 961          * <CODE>"text/html; charset=utf-16le"</CODE>
 962          * (little-endian byte ordering),
 963          * print data representation class name =
 964          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 965          */
 966         public static final INPUT_STREAM TEXT_HTML_UTF_16LE =
 967             new INPUT_STREAM ("text/html; charset=utf-16le");
 968 
 969         /**
 970          * Doc flavor with MIME type =
 971          * <CODE>"text/html; charset=us-ascii"</CODE>,
 972          * print data representation class name =
 973          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 974          */
 975         public static final INPUT_STREAM TEXT_HTML_US_ASCII =
 976             new INPUT_STREAM ("text/html; charset=us-ascii");
 977 
 978 
 979         /**
 980          * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
 981          * data representation class name = <CODE>"java.io.InputStream"</CODE>
 982          * (byte stream).
 983          */
 984         public static final INPUT_STREAM PDF = new INPUT_STREAM ("application/pdf");
 985 
 986         /**
 987          * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
 988          * print data representation class name =
 989          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 990          */
 991         public static final INPUT_STREAM POSTSCRIPT =
 992             new INPUT_STREAM ("application/postscript");
 993 
 994         /**
 995          * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
 996          * print data representation class name =
 997          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 998          */
 999         public static final INPUT_STREAM PCL =
1000             new INPUT_STREAM ("application/vnd.hp-PCL");
1001 
1002         /**
1003          * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
1004          * representation class name =
1005          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1006          */
1007         public static final INPUT_STREAM GIF = new INPUT_STREAM ("image/gif");
1008 
1009         /**
1010          * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
1011          * representation class name =
1012          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1013          */
1014         public static final INPUT_STREAM JPEG = new INPUT_STREAM ("image/jpeg");
1015 
1016         /**
1017          * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
1018          * representation class name =
1019          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1020          */
1021         public static final INPUT_STREAM PNG = new INPUT_STREAM ("image/png");
1022 
1023         /**
1024          * Doc flavor with MIME type =
1025          * <CODE>"application/octet-stream"</CODE>,
1026          * print data representation class name =
1027          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1028          * The client must determine that data described
1029          * using this DocFlavor is valid for the printer.
1030          */
1031         public static final INPUT_STREAM AUTOSENSE =
1032             new INPUT_STREAM ("application/octet-stream");
1033 
1034     }
1035 
1036     /**
1037      * Class DocFlavor.URL provides predefined static constant DocFlavor
1038      * objects.
1039      * For example doc flavors using a Uniform Resource Locator ({@link
1040      * java.net.URL java.net.URL}) as the print data
1041      * representation  class.
1042      * <P>
1043      *
1044      * @author  Alan Kaminsky
1045      */
1046     public static class URL extends DocFlavor {
1047         private static final long serialVersionUID = 2936725788144902062L;
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 }
--- EOF ---