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>&#183;&nbsp;&nbsp;
 349  * <CODE>("text/plain", "java.io.InputStream")</CODE>
 350  * <BR>&#183;&nbsp;&nbsp;
 351  * <CODE>("text/plain; charset=us-ascii", "java.io.InputStream")</CODE>
 352  * <BR>&#183;&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>&#183;&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 myMimeType.getParameterMap().get(paramName.toLowerCase());
 547     }
 548 
 549     /**
 550      * Returns the name of this doc flavor object's representation class.
 551      * @return the name of the representation class.
 552      */
 553     public String getRepresentationClassName() {
 554         return myClassName;
 555     }
 556 
 557     /**
 558      * Converts this <code>DocFlavor</code> to a string.
 559      *
 560      * @return  MIME type string based on the canonical form. Each parameter
 561      *          value is enclosed in quotes.
 562      *          A "class=" parameter is appended to the
 563      *          MIME type string to indicate the representation class name.
 564      */
 565     public String toString() {
 566         return getStringValue();
 567     }
 568 
 569     /**
 570      * Returns a hash code for this doc flavor object.
 571      */
 572     public int hashCode() {
 573         return getStringValue().hashCode();
 574     }
 575 
 576     /**
 577      * Determines if this doc flavor object is equal to the given object.
 578      * The two are equal if the given object is not null, is an instance
 579      * of <code>DocFlavor</code>, has a MIME type equivalent to this doc
 580      * flavor object's MIME type (that is, the MIME types have the same media
 581      * type, media subtype, and parameters), and has the same representation
 582      * class name as this doc flavor object. Thus, if two doc flavor objects'
 583      * MIME types are the same except for comments, they are considered equal.
 584      * However, two doc flavor objects with MIME types of "text/plain" and
 585      * "text/plain; charset=US-ASCII" are not considered equal, even though
 586      * they represent the same media type (because the default character
 587      * set for plain text is US-ASCII).
 588      *
 589      * @param  obj  Object to test.
 590      *
 591      * @return  True if this doc flavor object equals <CODE>obj</CODE>, false
 592      *          otherwise.
 593      */
 594     public boolean equals(Object obj) {
 595         return
 596             obj != null &&
 597             obj instanceof DocFlavor &&
 598             getStringValue().equals (((DocFlavor) obj).getStringValue());
 599     }
 600 
 601     /**
 602      * Returns this doc flavor object's string value.
 603      */
 604     private String getStringValue() {
 605         if (myStringValue == null) {
 606             myStringValue = myMimeType + "; class=\"" + myClassName + "\"";
 607         }
 608         return myStringValue;
 609     }
 610 
 611     /**
 612      * Write the instance to a stream (ie serialize the object).



 613      */
 614     private void writeObject(ObjectOutputStream s) throws IOException {
 615 
 616         s.defaultWriteObject();
 617         s.writeObject(myMimeType.getMimeType());
 618     }
 619 
 620     /**
 621      * Reconstitute an instance from a stream (that is, deserialize it).
 622      *




 623      * @serialData
 624      * The serialised form of a DocFlavor is the String naming the
 625      * representation class followed by the String representing the canonical
 626      * form of the mime type.
 627      */
 628     private void readObject(ObjectInputStream s)
 629         throws ClassNotFoundException, IOException {
 630 
 631         s.defaultReadObject();
 632         myMimeType = new MimeType((String)s.readObject());
 633     }
 634 
 635     /**
 636      * Class DocFlavor.BYTE_ARRAY provides predefined static constant
 637      * DocFlavor objects for example doc flavors using a byte array
 638      * (<CODE>byte[]</CODE>) as the print data representation class.
 639      *
 640      * @author  Alan Kaminsky
 641      */
 642     public static class BYTE_ARRAY extends DocFlavor {
 643 
 644         private static final long serialVersionUID = -9065578006593857475L;
 645 
 646         /**
 647          * Constructs a new doc flavor with the given MIME type and a print
 648          * data representation class name of <CODE>"[B"</CODE> (byte array).
 649          *
 650          * @param  mimeType   MIME media type string.
 651          *
 652          * @exception  NullPointerException
 653          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
 654          * @exception  IllegalArgumentException
 655          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
 656          *     obey the syntax for a MIME media type string.
 657          */
 658         public BYTE_ARRAY (String mimeType) {
 659             super (mimeType, "[B");
 660         }
 661 
 662         /**
 663          * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
 664          * encoded in the host platform encoding.
 665          * See {@link DocFlavor#hostEncoding hostEncoding}
 666          * Print data representation class name =
 667          * <CODE>"[B"</CODE> (byte array).
 668          */
 669         public static final BYTE_ARRAY TEXT_PLAIN_HOST =
 670             new BYTE_ARRAY ("text/plain; charset="+hostEncoding);
 671 
 672         /**
 673          * Doc flavor with MIME type =
 674          * <CODE>"text/plain; charset=utf-8"</CODE>,
 675          * print data representation class name = <CODE>"[B"</CODE> (byte
 676          * array).
 677          */
 678         public static final BYTE_ARRAY TEXT_PLAIN_UTF_8 =
 679             new BYTE_ARRAY ("text/plain; charset=utf-8");
 680 
 681         /**
 682          * Doc flavor with MIME type =
 683          * <CODE>"text/plain; charset=utf-16"</CODE>,
 684          * print data representation class name = <CODE>"[B"</CODE> (byte
 685          * array).
 686          */
 687         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16 =
 688             new BYTE_ARRAY ("text/plain; charset=utf-16");
 689 
 690 
 691         /**
 692          * Doc flavor with MIME type =
 693          * <CODE>"text/plain; charset=utf-16be"</CODE>
 694          * (big-endian byte ordering),
 695          * print data representation class name = <CODE>"[B"</CODE> (byte
 696          * array).
 697          */
 698         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16BE =
 699             new BYTE_ARRAY ("text/plain; charset=utf-16be");
 700 
 701         /**
 702          * Doc flavor with MIME type =
 703          * <CODE>"text/plain; charset=utf-16le"</CODE>
 704          * (little-endian byte ordering),
 705          * print data representation class name = <CODE>"[B"</CODE> (byte
 706          * array).
 707          */
 708         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16LE =
 709             new BYTE_ARRAY ("text/plain; charset=utf-16le");
 710 
 711         /**
 712          * Doc flavor with MIME type =
 713          * <CODE>"text/plain; charset=us-ascii"</CODE>,
 714          * print data representation class name =
 715          * <CODE>"[B"</CODE> (byte array).
 716          */
 717         public static final BYTE_ARRAY TEXT_PLAIN_US_ASCII =
 718             new BYTE_ARRAY ("text/plain; charset=us-ascii");
 719 
 720 
 721         /**
 722          * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
 723          * encoded in the host platform encoding.
 724          * See {@link DocFlavor#hostEncoding hostEncoding}
 725          * Print data representation class name =
 726          * <CODE>"[B"</CODE> (byte array).
 727          */
 728         public static final BYTE_ARRAY TEXT_HTML_HOST =
 729             new BYTE_ARRAY ("text/html; charset="+hostEncoding);
 730 
 731         /**
 732          * Doc flavor with MIME type =
 733          * <CODE>"text/html; charset=utf-8"</CODE>,
 734          * print data representation class name = <CODE>"[B"</CODE> (byte
 735          * array).
 736          */
 737         public static final BYTE_ARRAY TEXT_HTML_UTF_8 =
 738             new BYTE_ARRAY ("text/html; charset=utf-8");
 739 
 740         /**
 741          * Doc flavor with MIME type =
 742          * <CODE>"text/html; charset=utf-16"</CODE>,
 743          * print data representation class name = <CODE>"[B"</CODE> (byte
 744          * array).
 745          */
 746         public static final BYTE_ARRAY TEXT_HTML_UTF_16 =
 747             new BYTE_ARRAY ("text/html; charset=utf-16");
 748 
 749         /**
 750          * Doc flavor with MIME type =
 751          * <CODE>"text/html; charset=utf-16be"</CODE>
 752          * (big-endian byte ordering),
 753          * print data representation class name = <CODE>"[B"</CODE> (byte
 754          * array).
 755          */
 756         public static final BYTE_ARRAY TEXT_HTML_UTF_16BE =
 757             new BYTE_ARRAY ("text/html; charset=utf-16be");
 758 
 759         /**
 760          * Doc flavor with MIME type =
 761          * <CODE>"text/html; charset=utf-16le"</CODE>
 762          * (little-endian byte ordering),
 763          * print data representation class name = <CODE>"[B"</CODE> (byte
 764          * array).
 765          */
 766         public static final BYTE_ARRAY TEXT_HTML_UTF_16LE =
 767             new BYTE_ARRAY ("text/html; charset=utf-16le");
 768 
 769         /**
 770          * Doc flavor with MIME type =
 771          * <CODE>"text/html; charset=us-ascii"</CODE>,
 772          * print data representation class name =
 773          * <CODE>"[B"</CODE> (byte array).
 774          */
 775         public static final BYTE_ARRAY TEXT_HTML_US_ASCII =
 776             new BYTE_ARRAY ("text/html; charset=us-ascii");
 777 
 778 
 779         /**
 780          * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
 781          * data representation class name = <CODE>"[B"</CODE> (byte array).
 782          */
 783         public static final BYTE_ARRAY PDF = new BYTE_ARRAY ("application/pdf");
 784 
 785         /**
 786          * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
 787          * print data representation class name = <CODE>"[B"</CODE> (byte
 788          * array).
 789          */
 790         public static final BYTE_ARRAY POSTSCRIPT =
 791             new BYTE_ARRAY ("application/postscript");
 792 
 793         /**
 794          * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
 795          * print data representation class name = <CODE>"[B"</CODE> (byte
 796          * array).
 797          */
 798         public static final BYTE_ARRAY PCL =
 799             new BYTE_ARRAY ("application/vnd.hp-PCL");
 800 
 801         /**
 802          * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
 803          * representation class name = <CODE>"[B"</CODE> (byte array).
 804          */
 805         public static final BYTE_ARRAY GIF = new BYTE_ARRAY ("image/gif");
 806 
 807         /**
 808          * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
 809          * representation class name = <CODE>"[B"</CODE> (byte array).
 810          */
 811         public static final BYTE_ARRAY JPEG = new BYTE_ARRAY ("image/jpeg");
 812 
 813         /**
 814          * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
 815          * representation class name = <CODE>"[B"</CODE> (byte array).
 816          */
 817         public static final BYTE_ARRAY PNG = new BYTE_ARRAY ("image/png");
 818 
 819         /**
 820          * Doc flavor with MIME type =
 821          * <CODE>"application/octet-stream"</CODE>,
 822          * print data representation class name = <CODE>"[B"</CODE> (byte
 823          * array). The client must determine that data described
 824          * using this DocFlavor is valid for the printer.
 825          */
 826         public static final BYTE_ARRAY AUTOSENSE =
 827             new BYTE_ARRAY ("application/octet-stream");
 828 
 829     }
 830 
 831     /**
 832      * Class DocFlavor.INPUT_STREAM provides predefined static constant
 833      * DocFlavor objects for example doc flavors using a byte stream ({@link
 834      * java.io.InputStream java.io.InputStream}) as the print
 835      * data representation class.
 836      *
 837      * @author  Alan Kaminsky
 838      */
 839     public static class INPUT_STREAM extends DocFlavor {
 840 
 841         private static final long serialVersionUID = -7045842700749194127L;
 842 
 843         /**
 844          * Constructs a new doc flavor with the given MIME type and a print
 845          * data representation class name of
 846          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 847          *
 848          * @param  mimeType   MIME media type string.
 849          *
 850          * @exception  NullPointerException
 851          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
 852          * @exception  IllegalArgumentException
 853          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
 854          *     obey the syntax for a MIME media type string.
 855          */
 856         public INPUT_STREAM (String mimeType) {
 857             super (mimeType, "java.io.InputStream");
 858         }
 859 
 860         /**
 861          * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
 862          * encoded in the host platform encoding.
 863          * See {@link DocFlavor#hostEncoding hostEncoding}
 864          * Print data representation class name =
 865          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 866          */
 867         public static final INPUT_STREAM TEXT_PLAIN_HOST =
 868             new INPUT_STREAM ("text/plain; charset="+hostEncoding);
 869 
 870         /**
 871          * Doc flavor with MIME type =
 872          * <CODE>"text/plain; charset=utf-8"</CODE>,
 873          * print data representation class name =
 874          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 875          */
 876         public static final INPUT_STREAM TEXT_PLAIN_UTF_8 =
 877             new INPUT_STREAM ("text/plain; charset=utf-8");
 878 
 879         /**
 880          * Doc flavor with MIME type =
 881          * <CODE>"text/plain; charset=utf-16"</CODE>,
 882          * print data representation class name =
 883          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 884          */
 885         public static final INPUT_STREAM TEXT_PLAIN_UTF_16 =
 886             new INPUT_STREAM ("text/plain; charset=utf-16");
 887 
 888         /**
 889          * Doc flavor with MIME type =
 890          * <CODE>"text/plain; charset=utf-16be"</CODE>
 891          * (big-endian byte ordering),
 892          * print data representation class name =
 893          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 894          */
 895         public static final INPUT_STREAM TEXT_PLAIN_UTF_16BE =
 896             new INPUT_STREAM ("text/plain; charset=utf-16be");
 897 
 898         /**
 899          * Doc flavor with MIME type =
 900          * <CODE>"text/plain; charset=utf-16le"</CODE>
 901          * (little-endian byte ordering),
 902          * print data representation class name =
 903          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 904          */
 905         public static final INPUT_STREAM TEXT_PLAIN_UTF_16LE =
 906             new INPUT_STREAM ("text/plain; charset=utf-16le");
 907 
 908         /**
 909          * Doc flavor with MIME type =
 910          * <CODE>"text/plain; charset=us-ascii"</CODE>,
 911          * print data representation class name =
 912          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 913          */
 914         public static final INPUT_STREAM TEXT_PLAIN_US_ASCII =
 915                 new INPUT_STREAM ("text/plain; charset=us-ascii");
 916 
 917         /**
 918          * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
 919          * encoded in the host platform encoding.
 920          * See {@link DocFlavor#hostEncoding hostEncoding}
 921          * Print data representation class name =
 922          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 923          */
 924         public static final INPUT_STREAM TEXT_HTML_HOST =
 925             new INPUT_STREAM ("text/html; charset="+hostEncoding);
 926 
 927         /**
 928          * Doc flavor with MIME type =
 929          * <CODE>"text/html; charset=utf-8"</CODE>,
 930          * print data representation class name =
 931          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 932          */
 933         public static final INPUT_STREAM TEXT_HTML_UTF_8 =
 934             new INPUT_STREAM ("text/html; charset=utf-8");
 935 
 936         /**
 937          * Doc flavor with MIME type =
 938          * <CODE>"text/html; charset=utf-16"</CODE>,
 939          * print data representation class name =
 940          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 941          */
 942         public static final INPUT_STREAM TEXT_HTML_UTF_16 =
 943             new INPUT_STREAM ("text/html; charset=utf-16");
 944 
 945         /**
 946          * Doc flavor with MIME type =
 947          * <CODE>"text/html; charset=utf-16be"</CODE>
 948          * (big-endian byte ordering),
 949          * print data representation class name =
 950          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 951          */
 952         public static final INPUT_STREAM TEXT_HTML_UTF_16BE =
 953             new INPUT_STREAM ("text/html; charset=utf-16be");
 954 
 955         /**
 956          * Doc flavor with MIME type =
 957          * <CODE>"text/html; charset=utf-16le"</CODE>
 958          * (little-endian byte ordering),
 959          * print data representation class name =
 960          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 961          */
 962         public static final INPUT_STREAM TEXT_HTML_UTF_16LE =
 963             new INPUT_STREAM ("text/html; charset=utf-16le");
 964 
 965         /**
 966          * Doc flavor with MIME type =
 967          * <CODE>"text/html; charset=us-ascii"</CODE>,
 968          * print data representation class name =
 969          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 970          */
 971         public static final INPUT_STREAM TEXT_HTML_US_ASCII =
 972             new INPUT_STREAM ("text/html; charset=us-ascii");
 973 
 974 
 975         /**
 976          * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
 977          * data representation class name = <CODE>"java.io.InputStream"</CODE>
 978          * (byte stream).
 979          */
 980         public static final INPUT_STREAM PDF = new INPUT_STREAM ("application/pdf");
 981 
 982         /**
 983          * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
 984          * print data representation class name =
 985          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 986          */
 987         public static final INPUT_STREAM POSTSCRIPT =
 988             new INPUT_STREAM ("application/postscript");
 989 
 990         /**
 991          * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
 992          * print data representation class name =
 993          * <CODE>"java.io.InputStream"</CODE> (byte stream).
 994          */
 995         public static final INPUT_STREAM PCL =
 996             new INPUT_STREAM ("application/vnd.hp-PCL");
 997 
 998         /**
 999          * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
1000          * representation class name =
1001          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1002          */
1003         public static final INPUT_STREAM GIF = new INPUT_STREAM ("image/gif");
1004 
1005         /**
1006          * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
1007          * representation class name =
1008          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1009          */
1010         public static final INPUT_STREAM JPEG = new INPUT_STREAM ("image/jpeg");
1011 
1012         /**
1013          * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
1014          * representation class name =
1015          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1016          */
1017         public static final INPUT_STREAM PNG = new INPUT_STREAM ("image/png");
1018 
1019         /**
1020          * Doc flavor with MIME type =
1021          * <CODE>"application/octet-stream"</CODE>,
1022          * print data representation class name =
1023          * <CODE>"java.io.InputStream"</CODE> (byte stream).
1024          * The client must determine that data described
1025          * using this DocFlavor is valid for the printer.
1026          */
1027         public static final INPUT_STREAM AUTOSENSE =
1028             new INPUT_STREAM ("application/octet-stream");
1029 
1030     }
1031 
1032     /**
1033      * Class DocFlavor.URL provides predefined static constant DocFlavor
1034      * objects.
1035      * For example doc flavors using a Uniform Resource Locator ({@link
1036      * java.net.URL java.net.URL}) as the print data
1037      * representation class.
1038      *
1039      * @author  Alan Kaminsky
1040      */
1041     public static class URL extends DocFlavor {
1042         private static final long serialVersionUID = 2936725788144902062L;
1043 
1044         /**
1045          * Constructs a new doc flavor with the given MIME type and a print
1046          * data representation class name of <CODE>"java.net.URL"</CODE>.
1047          *
1048          * @param  mimeType   MIME media type string.
1049          *
1050          * @exception  NullPointerException
1051          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1052          * @exception  IllegalArgumentException
1053          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1054          *     obey the syntax for a MIME media type string.
1055          */
1056         public URL (String mimeType) {
1057             super (mimeType, "java.net.URL");
1058         }
1059 
1060         /**
1061          * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
1062          * encoded in the host platform encoding.
1063          * See {@link DocFlavor#hostEncoding hostEncoding}
1064          * Print data representation class name =
1065          * <CODE>"java.net.URL"</CODE> (byte stream).
1066          */
1067         public static final URL TEXT_PLAIN_HOST =
1068             new URL ("text/plain; charset="+hostEncoding);
1069 
1070         /**
1071          * Doc flavor with MIME type =
1072          * <CODE>"text/plain; charset=utf-8"</CODE>,
1073          * print data representation class name =
1074          * <CODE>"java.net.URL"</CODE> (byte stream).
1075          */
1076         public static final URL TEXT_PLAIN_UTF_8 =
1077             new URL ("text/plain; charset=utf-8");
1078 
1079         /**
1080          * Doc flavor with MIME type =
1081          * <CODE>"text/plain; charset=utf-16"</CODE>,
1082          * print data representation class name =
1083          * <CODE>java.net.URL""</CODE> (byte stream).
1084          */
1085         public static final URL TEXT_PLAIN_UTF_16 =
1086             new URL ("text/plain; charset=utf-16");
1087 
1088         /**
1089          * Doc flavor with MIME type =
1090          * <CODE>"text/plain; charset=utf-16be"</CODE>
1091          * (big-endian byte ordering),
1092          * print data representation class name =
1093          * <CODE>"java.net.URL"</CODE> (byte stream).
1094          */
1095         public static final URL TEXT_PLAIN_UTF_16BE =
1096             new URL ("text/plain; charset=utf-16be");
1097 
1098         /**
1099          * Doc flavor with MIME type =
1100          * <CODE>"text/plain; charset=utf-16le"</CODE>
1101          * (little-endian byte ordering),
1102          * print data representation class name =
1103          * <CODE>"java.net.URL"</CODE> (byte stream).
1104          */
1105         public static final URL TEXT_PLAIN_UTF_16LE =
1106             new URL ("text/plain; charset=utf-16le");
1107 
1108         /**
1109          * Doc flavor with MIME type =
1110          * <CODE>"text/plain; charset=us-ascii"</CODE>,
1111          * print data representation class name =
1112          * <CODE>"java.net.URL"</CODE> (byte stream).
1113          */
1114         public static final URL TEXT_PLAIN_US_ASCII =
1115             new URL ("text/plain; charset=us-ascii");
1116 
1117         /**
1118          * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
1119          * encoded in the host platform encoding.
1120          * See {@link DocFlavor#hostEncoding hostEncoding}
1121          * Print data representation class name =
1122          * <CODE>"java.net.URL"</CODE> (byte stream).
1123          */
1124         public static final URL TEXT_HTML_HOST =
1125             new URL ("text/html; charset="+hostEncoding);
1126 
1127         /**
1128          * Doc flavor with MIME type =
1129          * <CODE>"text/html; charset=utf-8"</CODE>,
1130          * print data representation class name =
1131          * <CODE>"java.net.URL"</CODE> (byte stream).
1132          */
1133         public static final URL TEXT_HTML_UTF_8 =
1134             new URL ("text/html; charset=utf-8");
1135 
1136         /**
1137          * Doc flavor with MIME type =
1138          * <CODE>"text/html; charset=utf-16"</CODE>,
1139          * print data representation class name =
1140          * <CODE>"java.net.URL"</CODE> (byte stream).
1141          */
1142         public static final URL TEXT_HTML_UTF_16 =
1143             new URL ("text/html; charset=utf-16");
1144 
1145         /**
1146          * Doc flavor with MIME type =
1147          * <CODE>"text/html; charset=utf-16be"</CODE>
1148          * (big-endian byte ordering),
1149          * print data representation class name =
1150          * <CODE>"java.net.URL"</CODE> (byte stream).
1151          */
1152         public static final URL TEXT_HTML_UTF_16BE =
1153             new URL ("text/html; charset=utf-16be");
1154 
1155         /**
1156          * Doc flavor with MIME type =
1157          * <CODE>"text/html; charset=utf-16le"</CODE>
1158          * (little-endian byte ordering),
1159          * print data representation class name =
1160          * <CODE>"java.net.URL"</CODE> (byte stream).
1161          */
1162         public static final URL TEXT_HTML_UTF_16LE =
1163             new URL ("text/html; charset=utf-16le");
1164 
1165         /**
1166          * Doc flavor with MIME type =
1167          * <CODE>"text/html; charset=us-ascii"</CODE>,
1168          * print data representation class name =
1169          * <CODE>"java.net.URL"</CODE> (byte stream).
1170          */
1171         public static final URL TEXT_HTML_US_ASCII =
1172             new URL ("text/html; charset=us-ascii");
1173 
1174 
1175         /**
1176          * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
1177          * data representation class name = <CODE>"java.net.URL"</CODE>.
1178          */
1179         public static final URL PDF = new URL ("application/pdf");
1180 
1181         /**
1182          * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
1183          * print data representation class name = <CODE>"java.net.URL"</CODE>.
1184          */
1185         public static final URL POSTSCRIPT = new URL ("application/postscript");
1186 
1187         /**
1188          * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
1189          * print data representation class name = <CODE>"java.net.URL"</CODE>.
1190          */
1191         public static final URL PCL = new URL ("application/vnd.hp-PCL");
1192 
1193         /**
1194          * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
1195          * representation class name = <CODE>"java.net.URL"</CODE>.
1196          */
1197         public static final URL GIF = new URL ("image/gif");
1198 
1199         /**
1200          * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
1201          * representation class name = <CODE>"java.net.URL"</CODE>.
1202          */
1203         public static final URL JPEG = new URL ("image/jpeg");
1204 
1205         /**
1206          * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
1207          * representation class name = <CODE>"java.net.URL"</CODE>.
1208          */
1209         public static final URL PNG = new URL ("image/png");
1210 
1211         /**
1212          * Doc flavor with MIME type =
1213          * <CODE>"application/octet-stream"</CODE>,
1214          * print data representation class name = <CODE>"java.net.URL"</CODE>.
1215          *  The client must determine that data described
1216          * using this DocFlavor is valid for the printer.
1217          */
1218         public static final URL AUTOSENSE = new URL ("application/octet-stream");
1219 
1220     }
1221 
1222     /**
1223      * Class DocFlavor.CHAR_ARRAY provides predefined static constant
1224      * DocFlavor objects for example doc flavors using a character array
1225      * (<CODE>char[]</CODE>) as the print data representation class. As such,
1226      * the character set is Unicode.
1227      *
1228      * @author  Alan Kaminsky
1229      */
1230     public static class CHAR_ARRAY extends DocFlavor {
1231 
1232         private static final long serialVersionUID = -8720590903724405128L;
1233 
1234         /**
1235          * Constructs a new doc flavor with the given MIME type and a print
1236          * data representation class name of
1237          * <CODE>"[C"</CODE> (character array).
1238          *
1239          * @param  mimeType  MIME media type string. If it is a text media
1240          *                      type, it is assumed to contain a
1241          *                      <CODE>"charset=utf-16"</CODE> parameter.
1242          *
1243          * @exception  NullPointerException
1244          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1245          * @exception  IllegalArgumentException
1246          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1247          *     obey the syntax for a MIME media type string.
1248          */
1249         public CHAR_ARRAY (String mimeType) {
1250             super (mimeType, "[C");
1251         }
1252 
1253         /**
1254          * Doc flavor with MIME type = <CODE>"text/plain;
1255          * charset=utf-16"</CODE>, print data representation class name =
1256          * <CODE>"[C"</CODE> (character array).
1257          */
1258         public static final CHAR_ARRAY TEXT_PLAIN =
1259             new CHAR_ARRAY ("text/plain; charset=utf-16");
1260 
1261         /**
1262          * Doc flavor with MIME type = <CODE>"text/html;
1263          * charset=utf-16"</CODE>, print data representation class name =
1264          * <CODE>"[C"</CODE> (character array).
1265          */
1266         public static final CHAR_ARRAY TEXT_HTML =
1267             new CHAR_ARRAY ("text/html; charset=utf-16");
1268 
1269     }
1270 
1271     /**
1272      * Class DocFlavor.STRING provides predefined static constant DocFlavor
1273      * objects for example doc flavors using a string ({@link java.lang.String
1274      * java.lang.String}) as the print data representation class.
1275      * As such, the character set is Unicode.
1276      *
1277      * @author  Alan Kaminsky
1278      */
1279     public static class STRING extends DocFlavor {
1280 
1281         private static final long serialVersionUID = 4414407504887034035L;
1282 
1283         /**
1284          * Constructs a new doc flavor with the given MIME type and a print
1285          * data representation class name of <CODE>"java.lang.String"</CODE>.
1286          *
1287          * @param  mimeType  MIME media type string. If it is a text media
1288          *                      type, it is assumed to contain a
1289          *                      <CODE>"charset=utf-16"</CODE> parameter.
1290          *
1291          * @exception  NullPointerException
1292          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1293          * @exception  IllegalArgumentException
1294          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1295          *     obey the syntax for a MIME media type string.
1296          */
1297         public STRING (String mimeType) {
1298             super (mimeType, "java.lang.String");
1299         }
1300 
1301         /**
1302          * Doc flavor with MIME type = <CODE>"text/plain;
1303          * charset=utf-16"</CODE>, print data representation class name =
1304          * <CODE>"java.lang.String"</CODE>.
1305          */
1306         public static final STRING TEXT_PLAIN =
1307             new STRING ("text/plain; charset=utf-16");
1308 
1309         /**
1310          * Doc flavor with MIME type = <CODE>"text/html;
1311          * charset=utf-16"</CODE>, print data representation class name =
1312          * <CODE>"java.lang.String"</CODE>.
1313          */
1314         public static final STRING TEXT_HTML =
1315             new STRING ("text/html; charset=utf-16");
1316     }
1317 
1318     /**
1319      * Class DocFlavor.READER provides predefined static constant DocFlavor
1320      * objects for example doc flavors using a character stream ({@link
1321      * java.io.Reader java.io.Reader}) as the print data
1322      * representation class. As such, the character set is Unicode.
1323      *
1324      * @author  Alan Kaminsky
1325      */
1326     public static class READER extends DocFlavor {
1327 
1328         private static final long serialVersionUID = 7100295812579351567L;
1329 
1330         /**
1331          * Constructs a new doc flavor with the given MIME type and a print
1332          * data representation class name of\
1333          * <CODE>"java.io.Reader"</CODE> (character stream).
1334          *
1335          * @param  mimeType  MIME media type string. If it is a text media
1336          *                      type, it is assumed to contain a
1337          *                      <CODE>"charset=utf-16"</CODE> parameter.
1338          *
1339          * @exception  NullPointerException
1340          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1341          * @exception  IllegalArgumentException
1342          *     (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1343          *     obey the syntax for a MIME media type string.
1344          */
1345         public READER (String mimeType) {
1346             super (mimeType, "java.io.Reader");
1347         }
1348 
1349         /**
1350          * Doc flavor with MIME type = <CODE>"text/plain;
1351          * charset=utf-16"</CODE>, print data representation class name =
1352          * <CODE>"java.io.Reader"</CODE> (character stream).
1353          */
1354         public static final READER TEXT_PLAIN =
1355             new READER ("text/plain; charset=utf-16");
1356 
1357         /**
1358          * Doc flavor with MIME type = <CODE>"text/html;
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_HTML =
1363             new READER ("text/html; charset=utf-16");
1364 
1365     }
1366 
1367     /**
1368      * Class DocFlavor.SERVICE_FORMATTED provides predefined static constant
1369      * DocFlavor objects for example doc flavors for service formatted print
1370      * data.
1371      *
1372      * @author  Alan Kaminsky
1373      */
1374     public static class SERVICE_FORMATTED extends DocFlavor {
1375 
1376         private static final long serialVersionUID = 6181337766266637256L;
1377 
1378         /**
1379          * Constructs a new doc flavor with a MIME type of
1380          * <CODE>"application/x-java-jvm-local-objectref"</CODE> indicating
1381          * service formatted print data and the given print data
1382          * representation class name.
1383          *
1384          * @param  className  Fully-qualified representation class name.
1385          *
1386          * @exception  NullPointerException
1387          *     (unchecked exception) Thrown if <CODE>className</CODE> is
1388          *     null.
1389          */
1390         public SERVICE_FORMATTED (String className) {
1391             super ("application/x-java-jvm-local-objectref", className);
1392         }
1393 
1394         /**
1395          * Service formatted print data doc flavor with print data
1396          * representation class name =
1397          * <CODE>"java.awt.image.renderable.RenderableImage"</CODE>
1398          * (renderable image object).
1399          */
1400         public static final SERVICE_FORMATTED RENDERABLE_IMAGE =
1401             new SERVICE_FORMATTED("java.awt.image.renderable.RenderableImage");
1402 
1403         /**
1404          * Service formatted print data doc flavor with print data
1405          * representation class name = <CODE>"java.awt.print.Printable"</CODE>
1406          * (printable object).
1407          */
1408         public static final SERVICE_FORMATTED PRINTABLE =
1409             new SERVICE_FORMATTED ("java.awt.print.Printable");
1410 
1411         /**
1412          * Service formatted print data doc flavor with print data
1413          * representation class name = <CODE>"java.awt.print.Pageable"</CODE>
1414          * (pageable object).
1415          */
1416         public static final SERVICE_FORMATTED PAGEABLE =
1417             new SERVICE_FORMATTED ("java.awt.print.Pageable");
1418 
1419         }
1420 
1421 }
--- EOF ---