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