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