0001 /*
0002 * Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved.
0003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0004 *
0005 * This code is free software; you can redistribute it and/or modify it
0006 * under the terms of the GNU General Public License version 2 only, as
0007 * published by the Free Software Foundation. Sun designates this
0008 * particular file as subject to the "Classpath" exception as provided
0009 * by Sun in the LICENSE file that accompanied this code.
0010 *
0011 * This code is distributed in the hope that it will be useful, but WITHOUT
0012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0014 * version 2 for more details (a copy is included in the LICENSE file that
0015 * accompanied this code).
0016 *
0017 * You should have received a copy of the GNU General Public License version
0018 * 2 along with this work; if not, write to the Free Software Foundation,
0019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0020 *
0021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0022 * CA 95054 USA or visit www.sun.com if you need additional information or
0023 * have any questions.
0024 */
0025
0026 package javax.print;
0027
0028 import java.io.IOException;
0029 import java.io.ObjectInputStream;
0030 import java.io.ObjectOutputStream;
0031 import java.io.Serializable;
0032
0033 import java.util.Map;
0034
0035 /**
0036 * Class <code>DocFlavor</code> encapsulates an object that specifies the
0037 * format in which print data is supplied to a {@link DocPrintJob}.
0038 * "Doc" is a short, easy-to-pronounce term that means "a piece of print data."
0039 * The print data format, or "doc flavor", consists of two things:
0040 * <UL>
0041 * <LI>
0042 * <B>MIME type.</B> This is a Multipurpose Internet Mail Extensions (MIME)
0043 * media type (as defined in <A HREF="http://www.ietf.org/rfc/rfc2045.txt">RFC
0044 * 2045</A> and <A HREF="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</A>)
0045 * that specifies how the print data is to be interpreted.
0046 * The charset of text data should be the IANA MIME-preferred name, or its
0047 * canonical name if no preferred name is specified. Additionally a few
0048 * historical names supported by earlier versions of the Java platform may
0049 * be recognized.
0050 * See <a href="../../java/lang/package-summary.html#charenc">
0051 * character encodings</a> for more information on the character encodings
0052 * supported on the Java platform.
0053 * <P>
0054 * <LI>
0055 * <B>Representation class name.</B> This specifies the fully-qualified name of
0056 * the class of the object from which the actual print data comes, as returned
0057 * by the {@link java.lang.Class#getName() <CODE>Class.getName()</CODE>} method.
0058 * (Thus the class name for <CODE>byte[]</CODE> is <CODE>"[B"</CODE>, for
0059 * <CODE>char[]</CODE> it is <CODE>"[C"</CODE>.)
0060 * </UL>
0061 * <P>
0062 * A <code>DocPrintJob</code> obtains its print data by means of interface
0063 * {@link Doc Doc}. A <code>Doc</code> object lets the <code>DocPrintJob</code>
0064 * determine the doc flavor the client can supply. A <code>Doc</code> object
0065 * also lets the <code>DocPrintJob</code> obtain an instance of the doc flavor's
0066 * representation class, from which the <code>DocPrintJob</code> then obtains
0067 * the actual print data.
0068 * <P>
0069 * <HR>
0070 * <H3>Client Formatted Print Data</H3>
0071 * There are two broad categories of print data, client formatted print data
0072 * and service formatted print data.
0073 * <P>
0074 * For <B>client formatted print data</B>, the client determines or knows the
0075 * print data format.
0076 * For example the client may have a JPEG encoded image, a URL for
0077 * HTML code, or a disk file containing plain text in some encoding,
0078 * possibly obtained from an external source, and
0079 * requires a way to describe the data format to the print service.
0080 * <p>
0081 * The doc flavor's representation class is a conduit for the JPS
0082 * <code>DocPrintJob</code> to obtain a sequence of characters or
0083 * bytes from the client. The
0084 * doc flavor's MIME type is one of the standard media types telling how to
0085 * interpret the sequence of characters or bytes. For a list of standard media
0086 * types, see the Internet Assigned Numbers Authority's (IANA's) <A
0087 * HREF="http://www.isi.edu/in-notes/iana/assignments/media-types/">Media Types
0088 * Directory</A>. Interface {@link Doc Doc} provides two utility operations,
0089 * {@link Doc#getReaderForText() getReaderForText} and
0090 * {@link Doc#getStreamForBytes() getStreamForBytes()}, to help a
0091 * <code>Doc</code> object's client extract client formatted print data.
0092 * <P>
0093 * For client formatted print data, the print data representation class is
0094 * typically one of the following (although other representation classes are
0095 * permitted):
0096 * <UL>
0097 * <LI>
0098 * Character array (<CODE>char[]</CODE>) -- The print data consists of the
0099 * Unicde characters in the array.
0100 * <P>
0101 * <LI>
0102 * <code>String</code> --
0103 * The print data consists of the Unicode characters in the string.
0104 * <P>
0105 * <LI>
0106 * Character stream ({@link java.io.Reader java.io.Reader})
0107 * -- The print data consists of the Unicode characters read from the stream
0108 * up to the end-of-stream.
0109 * <P>
0110 * <LI>
0111 * Byte array (<CODE>byte[]</CODE>) -- The print data consists of the bytes in
0112 * the array. The bytes are encoded in the character set specified by the doc
0113 * flavor's MIME type. If the MIME type does not specify a character set, the
0114 * default character set is US-ASCII.
0115 * <P>
0116 * <LI>
0117 * Byte stream ({@link java.io.InputStream java.io.InputStream}) --
0118 * The print data consists of the bytes read from the stream up to the
0119 * end-of-stream. The bytes are encoded in the character set specified by the
0120 * doc flavor's MIME type. If the MIME type does not specify a character set,
0121 * the default character set is US-ASCII.
0122
0123 * <LI>
0124 * Uniform Resource Locator ({@link java.net.URL URL})
0125 * -- The print data consists of the bytes read from the URL location.
0126 * The bytes are encoded in the character set specified by the doc flavor's
0127 * MIME type. If the MIME type does not specify a character set, the default
0128 * character set is US-ASCII.
0129 * <P>
0130 * When the representation class is a URL, the print service itself accesses
0131 * and downloads the document directly from its URL address, without involving
0132 * the client. The service may be some form of network print service which
0133 * is executing in a different environment.
0134 * This means you should not use a URL print data flavor to print a
0135 * document at a restricted URL that the client can see but the printer cannot
0136 * see. This also means you should not use a URL print data flavor to print a
0137 * document stored in a local file that is not available at a URL
0138 * accessible independently of the client.
0139 * For example, a file that is not served up by an HTTP server or FTP server.
0140 * To print such documents, let the client open an input stream on the URL
0141 * or file and use an input stream data flavor.
0142 * </UL>
0143 * <p>
0144 * <HR>
0145 * <h3>Default and Platform Encodings</h3>
0146 * <P>
0147 * For byte print data where the doc flavor's MIME type does not include a
0148 * <CODE>charset</CODE> parameter, the Java Print Service instance assumes the
0149 * US-ASCII character set by default. This is in accordance with
0150 * <A HREF="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</A>, which says the
0151 * default character set is US-ASCII. Note that US-ASCII is a subset of
0152 * UTF-8, so in the future this may be widened if a future RFC endorses
0153 * UTF-8 as the default in a compatible manner.
0154 * <p>
0155 * Also note that this is different than the behaviour of the Java runtime
0156 * when interpreting a stream of bytes as text data. That assumes the
0157 * default encoding for the user's locale. Thus, when spooling a file in local
0158 * encoding to a Java Print Service it is important to correctly specify
0159 * the encoding. Developers working in the English locales should
0160 * be particularly conscious of this, as their platform encoding corresponds
0161 * to the default mime charset. By this coincidence that particular
0162 * case may work without specifying the encoding of platform data.
0163 * <p>
0164 * Every instance of the Java virtual machine has a default character encoding
0165 * determined during virtual-machine startup and typically depends upon the
0166 * locale and charset being used by the underlying operating system.
0167 * In a distributed environment there is no gurantee that two VM's share
0168 * the same default encoding. Thus clients which want to stream platform
0169 * encoded text data from the host platform to a Java Print Service instance
0170 * must explicitly declare the charset and not rely on defaults.
0171 * <p>
0172 * The preferred form is the official IANA primary name for an encoding.
0173 * Applications which stream text data should always specify the charset
0174 * in the mime type, which necessitates obtaining the encoding of the host
0175 * platform for data (eg files) stored in that platform's encoding.
0176 * A CharSet which corresponds to this and is suitable for use in a
0177 * mime-type for a DocFlavor can be obtained
0178 * from {@link DocFlavor#hostEncoding <CODE>DocFlavor.hostEncoding</CODE>}
0179 * This may not always be the primary IANA name but is guaranteed to be
0180 * understood by this VM.
0181 * For common flavors, the pre-defined *HOST DocFlavors may be used.
0182 * <p>
0183 * <p>
0184 * See <a href="../../java/lang/package-summary.html#charenc">
0185 * character encodings</a> for more information on the character encodings
0186 * supported on the Java platform.
0187 * <p>
0188 * <HR>
0189 * <h3>Recommended DocFlavors</h3>
0190 * <P>
0191 * The Java Print Service API does not define any mandatorily supported
0192 * DocFlavors.
0193 * However, here are some examples of MIME types that a Java Print Service
0194 * instance might support for client formatted print data.
0195 * Nested classes inside class DocFlavor declare predefined static
0196 * constant DocFlavor objects for these example doc flavors; class DocFlavor's
0197 * constructor can be used to create an arbitrary doc flavor.
0198 * <UL>
0199 * <LI>Preformatted text
0200 * <P>
0201 * <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 SUMMARY="MIME-Types and their descriptions">
0202 * <TR>
0203 * <TH>MIME-Type</TH><TH>Description</TH>
0204 * </TR>
0205 * <TR>
0206 * <TD><CODE>"text/plain"</CODE></TD>
0207 * <TD>Plain text in the default character set (US-ASCII)</TD>
0208 * </TR>
0209 * <TR>
0210 * <TD><CODE>"text/plain; charset=<I>xxx</I>"</CODE></TD>
0211 * <TD>Plain text in character set <I>xxx</I></TD>
0212 * </TR>
0213 * <TR>
0214 * <TD><CODE>"text/html"</CODE></TD>
0215 * <TD>HyperText Markup Language in the default character set (US-ASCII)</TD>
0216 * </TR>
0217 * <TR>
0218 * <TD><CODE>"text/html; charset=<I>xxx</I>"</CODE></TD>
0219 * <TD>HyperText Markup Language in character set <I>xxx</I></TD>
0220 * </TR>
0221 * </TABLE>
0222 * <P>
0223 * In general, preformatted text print data is provided either in a character
0224 * oriented representation class (character array, String, Reader) or in a
0225 * byte oriented representation class (byte array, InputStream, URL).
0226 * <P>
0227 * <LI>Preformatted page description language (PDL) documents
0228 *<P>
0229 * <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 SUMMARY="MIME-Types and their descriptions">
0230 * <TR>
0231 * <TH>MIME-Type</TH><TH>Description</TH>
0232 * </TR>
0233 *<TR>
0234 * <TD><CODE>"application/pdf"</CODE></TD>
0235 * <TD>Portable Document Format document</TD>
0236 * </TR>
0237 * <TR>
0238 * <TD><CODE>"application/postscript"</CODE></TD>
0239 * <TD>PostScript document</TD>
0240 * </TR>
0241 * <TR>
0242 * <TD><CODE>"application/vnd.hp-PCL"</CODE></TD>
0243 * <TD>Printer Control Language document</TD>
0244 * </TR>
0245 * </TABLE>
0246 * <P>
0247 * In general, preformatted PDL print data is provided in a byte oriented
0248 * representation class (byte array, InputStream, URL).
0249 * <P>
0250 * <LI>Preformatted images
0251 *<P>
0252 * <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 SUMMARY="MIME-Types and their descriptions">
0253 * <TR>
0254 * <TH>MIME-Type</TH><TH>Description</TH>
0255 * </TR>
0256 *
0257 * <TR>
0258 * <TD><CODE>"image/gif"</CODE></TD>
0259 * <TD>Graphics Interchange Format image</TD>
0260 * </TR>
0261 * <TR>
0262 * <TD><CODE>"image/jpeg"</CODE></TD>
0263 * <TD>Joint Photographic Experts Group image</TD>
0264 * </TR>
0265 * <TR>
0266 * <TD><CODE>"image/png"</CODE></TD>
0267 * <TD>Portable Network Graphics image</TD>
0268 * </TR>
0269 * </TABLE>
0270 * <P>
0271 * In general, preformatted image print data is provided in a byte oriented
0272 * representation class (byte array, InputStream, URL).
0273 * <P>
0274 * <LI>Preformatted autosense print data
0275 * <P>
0276 * <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 SUMMARY="MIME-Types and their descriptions">
0277 * <TR>
0278 * <TH>MIME-Type</TH><TH>Description</TH>
0279 * </TR>
0280 *
0281 * <TR>
0282 * <TD><CODE>"application/octet-stream"</CODE></TD>
0283 * <TD>The print data format is unspecified (just an octet stream)</TD>
0284 * </TABLE>
0285 * <P>
0286 * The printer decides how to interpret the print data; the way this
0287 * "autosensing" works is implementation dependent. In general, preformatted
0288 * autosense print data is provided in a byte oriented representation class
0289 * (byte array, InputStream, URL).
0290 *
0291 * <P>
0292 * <HR>
0293 * <H3>Service Formatted Print Data</H3>
0294 * <P>
0295 * For <B>service formatted print data</B>, the Java Print Service instance
0296 * determines the print data format. The doc flavor's representation class
0297 * denotes an interface whose methods the <code>DocPrintJob</code> invokes to
0298 * determine the content to be printed -- such as a renderable image
0299 * interface or a Java printable interface.
0300 * The doc flavor's MIME type is the special value
0301 * <CODE>"application/x-java-jvm-local-objectref"</CODE> indicating the client
0302 * will supply a reference to a Java object that implements the interface
0303 * named as the representation class.
0304 * This MIME type is just a placeholder; what's
0305 * important is the print data representation class.
0306 * <P>
0307 * For service formatted print data, the print data representation class is
0308 * typically one of the following (although other representation classes are
0309 * permitted). Nested classes inside class DocFlavor declare predefined static
0310 * constant DocFlavor objects for these example doc flavors; class DocFlavor's
0311 * constructor can be used to create an arbitrary doc flavor.
0312 * <UL>
0313 * <LI>
0314 * Renderable image object -- The client supplies an object that implements
0315 * interface
0316 * {@link java.awt.image.renderable.RenderableImage RenderableImage}. The
0317 * printer calls methods
0318 * in that interface to obtain the image to be printed.
0319 * <P>
0320 * <LI>
0321 * Printable object -- The client supplies an object that implements interface
0322 * {@link java.awt.print.Printable Printable}.
0323 * The printer calls methods in that interface to obtain the pages to be
0324 * printed, one by one.
0325 * For each page, the printer supplies a graphics context, and whatever the
0326 * client draws in that graphics context gets printed.
0327 * <P>
0328 * <LI>
0329 * Pageable object -- The client supplies an object that implements interface
0330 * {@link java.awt.print.Pageable Pageable}. The printer calls
0331 * methods in that interface to obtain the pages to be printed, one by one.
0332 * For each page, the printer supplies a graphics context, and whatever
0333 * the client draws in that graphics context gets printed.
0334 * </UL>
0335 * <P>
0336 * <HR>
0337 * <P>
0338 * <HR>
0339 * <H3>Pre-defined Doc Flavors</H3>
0340 * A Java Print Service instance is not <B><I>required</I></B> to support the
0341 * following print data formats and print data representation classes. In
0342 * fact, a developer using this class should <b>never</b> assume that a
0343 * particular print service supports the document types corresponding to
0344 * these pre-defined doc flavors. Always query the print service
0345 * to determine what doc flavors it supports. However,
0346 * developers who have print services that support these doc flavors are
0347 * encouraged to refer to the predefined singleton instances created here.
0348 * <UL>
0349 * <LI>
0350 * Plain text print data provided through a byte stream. Specifically, the
0351 * following doc flavors are recommended to be supported:
0352 * <BR>·
0353 * <CODE>("text/plain", "java.io.InputStream")</CODE>
0354 * <BR>·
0355 * <CODE>("text/plain; charset=us-ascii", "java.io.InputStream")</CODE>
0356 * <BR>·
0357 * <CODE>("text/plain; charset=utf-8", "java.io.InputStream")</CODE>
0358 * <P>
0359 * <LI>
0360 * Renderable image objects. Specifically, the following doc flavor is
0361 * recommended to be supported:
0362 * <BR>·
0363 * <CODE>("application/x-java-jvm-local-objectref", "java.awt.image.renderable.RenderableImage")</CODE>
0364 * </UL>
0365 * <P>
0366 * A Java Print Service instance is allowed to support any other doc flavors
0367 * (or none) in addition to the above mandatory ones, at the implementation's
0368 * choice.
0369 * <P>
0370 * Support for the above doc flavors is desirable so a printing client can rely
0371 * on being able to print on any JPS printer, regardless of which doc flavors
0372 * the printer supports. If the printer doesn't support the client's preferred
0373 * doc flavor, the client can at least print plain text, or the client can
0374 * convert its data to a renderable image and print the image.
0375 * <P>
0376 * Furthermore, every Java Print Service instance must fulfill these
0377 * requirements for processing plain text print data:
0378 * <UL>
0379 * <LI>
0380 * The character pair carriage return-line feed (CR-LF) means
0381 * "go to column 1 of the next line."
0382 * <LI>
0383 * A carriage return (CR) character standing by itself means
0384 * "go to column 1 of the next line."
0385 * <LI>
0386 * A line feed (LF) character standing by itself means
0387 * "go to column 1 of the next line."
0388 * <LI>
0389 * </UL>
0390 * <P>
0391 * The client must itself perform all plain text print data formatting not
0392 * addressed by the above requirements.
0393 * <P>
0394 * <H3>Design Rationale</H3>
0395 * <P>
0396 * Class DocFlavor in package javax.print.data is similar to class
0397 * {@link java.awt.datatransfer.DataFlavor DataFlavor}. Class
0398 * <code>DataFlavor</code>
0399 * is not used in the Java Print Service (JPS) API
0400 * for three reasons which are all rooted in allowing the JPS API to be
0401 * shared by other print services APIs which may need to run on Java profiles
0402 * which do not include all of the Java Platform, Standard Edition.
0403 * <OL TYPE=1>
0404 * <LI>
0405 * The JPS API is designed to be used in Java profiles which do not support
0406 * AWT.
0407 * <P>
0408 * <LI>
0409 * The implementation of class <code>java.awt.datatransfer.DataFlavor</code>
0410 * does not guarantee that equivalent data flavors will have the same
0411 * serialized representation. DocFlavor does, and can be used in services
0412 * which need this.
0413 * <P>
0414 * <LI>
0415 * The implementation of class <code>java.awt.datatransfer.DataFlavor</code>
0416 * includes a human presentable name as part of the serialized representation.
0417 * This is not appropriate as part of a service matching constraint.
0418 * </OL>
0419 * <P>
0420 * Class DocFlavor's serialized representation uses the following
0421 * canonical form of a MIME type string. Thus, two doc flavors with MIME types
0422 * that are not identical but that are equivalent (that have the same
0423 * canonical form) may be considered equal.
0424 * <UL>
0425 * <LI> The media type, media subtype, and parameters are retained, but all
0426 * comments and whitespace characters are discarded.
0427 * <LI> The media type, media subtype, and parameter names are converted to
0428 * lowercase.
0429 * <LI> The parameter values retain their original case, except a charset
0430 * parameter value for a text media type is converted to lowercase.
0431 * <LI> Quote characters surrounding parameter values are removed.
0432 * <LI> Quoting backslash characters inside parameter values are removed.
0433 * <LI> The parameters are arranged in ascending order of parameter name.
0434 * </UL>
0435 * <P>
0436 * Class DocFlavor's serialized representation also contains the
0437 * fully-qualified class <I>name</I> of the representation class
0438 * (a String object), rather than the representation class itself
0439 * (a Class object). This allows a client to examine the doc flavors a
0440 * Java Print Service instance supports without having
0441 * to load the representation classes, which may be problematic for
0442 * limited-resource clients.
0443 * <P>
0444 *
0445 * @author Alan Kaminsky
0446 */
0447 public class DocFlavor implements Serializable, Cloneable {
0448
0449 private static final long serialVersionUID = -4512080796965449721L;
0450
0451 /**
0452 * A String representing the host operating system encoding.
0453 * This will follow the conventions documented in
0454 * <a href="http://ietf.org/rfc/rfc2278.txt">
0455 * <i>RFC 2278: IANA Charset Registration Procedures</i></a>
0456 * except where historical names are returned for compatibility with
0457 * previous versions of the Java platform.
0458 * The value returned from method is valid only for the VM which
0459 * returns it, for use in a DocFlavor.
0460 * This is the charset for all the "HOST" pre-defined DocFlavors in
0461 * the executing VM.
0462 */
0463 public static final String hostEncoding;
0464
0465 static {
0466 hostEncoding = (String) java.security.AccessController
0467 .doPrivileged(new sun.security.action.GetPropertyAction(
0468 "file.encoding"));
0469 }
0470
0471 /**
0472 * MIME type.
0473 */
0474 private transient MimeType myMimeType;
0475
0476 /**
0477 * Representation class name.
0478 * @serial
0479 */
0480 private String myClassName;
0481
0482 /**
0483 * String value for this doc flavor. Computed when needed and cached.
0484 */
0485 private transient String myStringValue = null;
0486
0487 /**
0488 * Constructs a new doc flavor object from the given MIME type and
0489 * representation class name. The given MIME type is converted into
0490 * canonical form and stored internally.
0491 *
0492 * @param mimeType MIME media type string.
0493 * @param className Fully-qualified representation class name.
0494 *
0495 * @exception NullPointerException
0496 * (unchecked exception) Thrown if <CODE>mimeType</CODE> is null or
0497 * <CODE>className</CODE> is null.
0498 * @exception IllegalArgumentException
0499 * (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
0500 * obey the syntax for a MIME media type string.
0501 */
0502 public DocFlavor(String mimeType, String className) {
0503 if (className == null) {
0504 throw new NullPointerException();
0505 }
0506 myMimeType = new MimeType(mimeType);
0507 myClassName = className;
0508 }
0509
0510 /**
0511 * Returns this doc flavor object's MIME type string based on the
0512 * canonical form. Each parameter value is enclosed in quotes.
0513 * @return the mime type
0514 */
0515 public String getMimeType() {
0516 return myMimeType.getMimeType();
0517 }
0518
0519 /**
0520 * Returns this doc flavor object's media type (from the MIME type).
0521 * @return the media type
0522 */
0523 public String getMediaType() {
0524 return myMimeType.getMediaType();
0525 }
0526
0527 /**
0528 * Returns this doc flavor object's media subtype (from the MIME type).
0529 * @return the media sub-type
0530 */
0531 public String getMediaSubtype() {
0532 return myMimeType.getMediaSubtype();
0533 }
0534
0535 /**
0536 * Returns a <code>String</code> representing a MIME
0537 * parameter.
0538 * Mime types may include parameters which are usually optional.
0539 * The charset for text types is a commonly useful example.
0540 * This convenience method will return the value of the specified
0541 * parameter if one was specified in the mime type for this flavor.
0542 * <p>
0543 * @param paramName the name of the paramater. This name is internally
0544 * converted to the canonical lower case format before performing
0545 * the match.
0546 * @return String representing a mime parameter, or
0547 * null if that parameter is not in the mime type string.
0548 * @exception throws NullPointerException if paramName is null.
0549 */
0550 public String getParameter(String paramName) {
0551 return (String) myMimeType.getParameterMap().get(
0552 paramName.toLowerCase());
0553 }
0554
0555 /**
0556 * Returns the name of this doc flavor object's representation class.
0557 * @return the name of the representation class.
0558 */
0559 public String getRepresentationClassName() {
0560 return myClassName;
0561 }
0562
0563 /**
0564 * Converts this <code>DocFlavor</code> to a string.
0565 *
0566 * @return MIME type string based on the canonical form. Each parameter
0567 * value is enclosed in quotes.
0568 * A "class=" parameter is appended to the
0569 * MIME type string to indicate the representation class name.
0570 */
0571 public String toString() {
0572 return getStringValue();
0573 }
0574
0575 /**
0576 * Returns a hash code for this doc flavor object.
0577 */
0578 public int hashCode() {
0579 return getStringValue().hashCode();
0580 }
0581
0582 /**
0583 * Determines if this doc flavor object is equal to the given object.
0584 * The two are equal if the given object is not null, is an instance
0585 * of <code>DocFlavor</code>, has a MIME type equivalent to this doc
0586 * flavor object's MIME type (that is, the MIME types have the same media
0587 * type, media subtype, and parameters), and has the same representation
0588 * class name as this doc flavor object. Thus, if two doc flavor objects'
0589 * MIME types are the same except for comments, they are considered equal.
0590 * However, two doc flavor objects with MIME types of "text/plain" and
0591 * "text/plain; charset=US-ASCII" are not considered equal, even though
0592 * they represent the same media type (because the default character
0593 * set for plain text is US-ASCII).
0594 *
0595 * @param obj Object to test.
0596 *
0597 * @return True if this doc flavor object equals <CODE>obj</CODE>, false
0598 * otherwise.
0599 */
0600 public boolean equals(Object obj) {
0601 return obj != null
0602 && obj instanceof DocFlavor
0603 && getStringValue().equals(
0604 ((DocFlavor) obj).getStringValue());
0605 }
0606
0607 /**
0608 * Returns this doc flavor object's string value.
0609 */
0610 private String getStringValue() {
0611 if (myStringValue == null) {
0612 myStringValue = myMimeType + "; class=\"" + myClassName
0613 + "\"";
0614 }
0615 return myStringValue;
0616 }
0617
0618 /**
0619 * Write the instance to a stream (ie serialize the object).
0620 */
0621 private void writeObject(ObjectOutputStream s) throws IOException {
0622
0623 s.defaultWriteObject();
0624 s.writeObject(myMimeType.getMimeType());
0625 }
0626
0627 /**
0628 * Reconstitute an instance from a stream (that is, deserialize it).
0629 *
0630 * @serialData
0631 * The serialised form of a DocFlavor is the String naming the
0632 * representation class followed by the String representing the canonical
0633 * form of the mime type.
0634 */
0635 private void readObject(ObjectInputStream s)
0636 throws ClassNotFoundException, IOException {
0637
0638 s.defaultReadObject();
0639 myMimeType = new MimeType((String) s.readObject());
0640 }
0641
0642 /**
0643 * Class DocFlavor.BYTE_ARRAY provides predefined static constant
0644 * DocFlavor objects for example doc flavors using a byte array
0645 * (<CODE>byte[]</CODE>) as the print data representation class.
0646 * <P>
0647 *
0648 * @author Alan Kaminsky
0649 */
0650 public static class BYTE_ARRAY extends DocFlavor {
0651
0652 private static final long serialVersionUID = -9065578006593857475L;
0653
0654 /**
0655 * Constructs a new doc flavor with the given MIME type and a print
0656 * data representation class name of <CODE>"[B"</CODE> (byte array).
0657 *
0658 * @param mimeType MIME media type string.
0659 *
0660 * @exception NullPointerException
0661 * (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
0662 * @exception IllegalArgumentException
0663 * (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
0664 * obey the syntax for a MIME media type string.
0665 */
0666 public BYTE_ARRAY(String mimeType) {
0667 super (mimeType, "[B");
0668 }
0669
0670 /**
0671 * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
0672 * encoded in the host platform encoding.
0673 * See {@link DocFlavor#hostEncoding <CODE>hostEncoding</CODE>}
0674 * Print data representation class name =
0675 * <CODE>"[B"</CODE> (byte array).
0676 */
0677 public static final BYTE_ARRAY TEXT_PLAIN_HOST = new BYTE_ARRAY(
0678 "text/plain; charset=" + hostEncoding);
0679
0680 /**
0681 * Doc flavor with MIME type =
0682 * <CODE>"text/plain; charset=utf-8"</CODE>,
0683 * print data representation class name = <CODE>"[B"</CODE> (byte
0684 * array).
0685 */
0686 public static final BYTE_ARRAY TEXT_PLAIN_UTF_8 = new BYTE_ARRAY(
0687 "text/plain; charset=utf-8");
0688
0689 /**
0690 * Doc flavor with MIME type =
0691 * <CODE>"text/plain; charset=utf-16"</CODE>,
0692 * print data representation class name = <CODE>"[B"</CODE> (byte
0693 * array).
0694 */
0695 public static final BYTE_ARRAY TEXT_PLAIN_UTF_16 = new BYTE_ARRAY(
0696 "text/plain; charset=utf-16");
0697
0698 /**
0699 * Doc flavor with MIME type =
0700 * <CODE>"text/plain; charset=utf-16be"</CODE>
0701 * (big-endian byte ordering),
0702 * print data representation class name = <CODE>"[B"</CODE> (byte
0703 * array).
0704 */
0705 public static final BYTE_ARRAY TEXT_PLAIN_UTF_16BE = new BYTE_ARRAY(
0706 "text/plain; charset=utf-16be");
0707
0708 /**
0709 * Doc flavor with MIME type =
0710 * <CODE>"text/plain; charset=utf-16le"</CODE>
0711 * (little-endian byte ordering),
0712 * print data representation class name = <CODE>"[B"</CODE> (byte
0713 * array).
0714 */
0715 public static final BYTE_ARRAY TEXT_PLAIN_UTF_16LE = new BYTE_ARRAY(
0716 "text/plain; charset=utf-16le");
0717
0718 /**
0719 * Doc flavor with MIME type =
0720 * <CODE>"text/plain; charset=us-ascii"</CODE>,
0721 * print data representation class name =
0722 * <CODE>"[B"</CODE> (byte array).
0723 */
0724 public static final BYTE_ARRAY TEXT_PLAIN_US_ASCII = new BYTE_ARRAY(
0725 "text/plain; charset=us-ascii");
0726
0727 /**
0728 * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
0729 * encoded in the host platform encoding.
0730 * See {@link DocFlavor#hostEncoding <CODE>hostEncoding</CODE>}
0731 * Print data representation class name =
0732 * <CODE>"[B"</CODE> (byte array).
0733 */
0734 public static final BYTE_ARRAY TEXT_HTML_HOST = new BYTE_ARRAY(
0735 "text/html; charset=" + hostEncoding);
0736
0737 /**
0738 * Doc flavor with MIME type =
0739 * <CODE>"text/html; charset=utf-8"</CODE>,
0740 * print data representation class name = <CODE>"[B"</CODE> (byte
0741 * array).
0742 */
0743 public static final BYTE_ARRAY TEXT_HTML_UTF_8 = new BYTE_ARRAY(
0744 "text/html; charset=utf-8");
0745
0746 /**
0747 * Doc flavor with MIME type =
0748 * <CODE>"text/html; charset=utf-16"</CODE>,
0749 * print data representation class name = <CODE>"[B"</CODE> (byte
0750 * array).
0751 */
0752 public static final BYTE_ARRAY TEXT_HTML_UTF_16 = new BYTE_ARRAY(
0753 "text/html; charset=utf-16");
0754
0755 /**
0756 * Doc flavor with MIME type =
0757 * <CODE>"text/html; charset=utf-16be"</CODE>
0758 * (big-endian byte ordering),
0759 * print data representation class name = <CODE>"[B"</CODE> (byte
0760 * array).
0761 */
0762 public static final BYTE_ARRAY TEXT_HTML_UTF_16BE = new BYTE_ARRAY(
0763 "text/html; charset=utf-16be");
0764
0765 /**
0766 * Doc flavor with MIME type =
0767 * <CODE>"text/html; charset=utf-16le"</CODE>
0768 * (little-endian byte ordering),
0769 * print data representation class name = <CODE>"[B"</CODE> (byte
0770 * array).
0771 */
0772 public static final BYTE_ARRAY TEXT_HTML_UTF_16LE = new BYTE_ARRAY(
0773 "text/html; charset=utf-16le");
0774
0775 /**
0776 * Doc flavor with MIME type =
0777 * <CODE>"text/html; charset=us-ascii"</CODE>,
0778 * print data representation class name =
0779 * <CODE>"[B"</CODE> (byte array).
0780 */
0781 public static final BYTE_ARRAY TEXT_HTML_US_ASCII = new BYTE_ARRAY(
0782 "text/html; charset=us-ascii");
0783
0784 /**
0785 * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
0786 * data representation class name = <CODE>"[B"</CODE> (byte array).
0787 */
0788 public static final BYTE_ARRAY PDF = new BYTE_ARRAY(
0789 "application/pdf");
0790
0791 /**
0792 * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
0793 * print data representation class name = <CODE>"[B"</CODE> (byte
0794 * array).
0795 */
0796 public static final BYTE_ARRAY POSTSCRIPT = new BYTE_ARRAY(
0797 "application/postscript");
0798
0799 /**
0800 * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
0801 * print data representation class name = <CODE>"[B"</CODE> (byte
0802 * array).
0803 */
0804 public static final BYTE_ARRAY PCL = new BYTE_ARRAY(
0805 "application/vnd.hp-PCL");
0806
0807 /**
0808 * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
0809 * representation class name = <CODE>"[B"</CODE> (byte array).
0810 */
0811 public static final BYTE_ARRAY GIF = new BYTE_ARRAY("image/gif");
0812
0813 /**
0814 * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
0815 * representation class name = <CODE>"[B"</CODE> (byte array).
0816 */
0817 public static final BYTE_ARRAY JPEG = new BYTE_ARRAY(
0818 "image/jpeg");
0819
0820 /**
0821 * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
0822 * representation class name = <CODE>"[B"</CODE> (byte array).
0823 */
0824 public static final BYTE_ARRAY PNG = new BYTE_ARRAY("image/png");
0825
0826 /**
0827 * Doc flavor with MIME type =
0828 * <CODE>"application/octet-stream"</CODE>,
0829 * print data representation class name = <CODE>"[B"</CODE> (byte
0830 * array). The client must determine that data described
0831 * using this DocFlavor is valid for the printer.
0832 */
0833 public static final BYTE_ARRAY AUTOSENSE = new BYTE_ARRAY(
0834 "application/octet-stream");
0835
0836 }
0837
0838 /**
0839 * Class DocFlavor.INPUT_STREAM provides predefined static constant
0840 * DocFlavor objects for example doc flavors using a byte stream ({@link
0841 * java.io.InputStream <CODE>java.io.InputStream</CODE>}) as the print
0842 * data representation class.
0843 * <P>
0844 *
0845 * @author Alan Kaminsky
0846 */
0847 public static class INPUT_STREAM extends DocFlavor {
0848
0849 private static final long serialVersionUID = -7045842700749194127L;
0850
0851 /**
0852 * Constructs a new doc flavor with the given MIME type and a print
0853 * data representation class name of
0854 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0855 *
0856 * @param mimeType MIME media type string.
0857 *
0858 * @exception NullPointerException
0859 * (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
0860 * @exception IllegalArgumentException
0861 * (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
0862 * obey the syntax for a MIME media type string.
0863 */
0864 public INPUT_STREAM(String mimeType) {
0865 super (mimeType, "java.io.InputStream");
0866 }
0867
0868 /**
0869 * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
0870 * encoded in the host platform encoding.
0871 * See {@link DocFlavor#hostEncoding <CODE>hostEncoding</CODE>}
0872 * Print data representation class name =
0873 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0874 */
0875 public static final INPUT_STREAM TEXT_PLAIN_HOST = new INPUT_STREAM(
0876 "text/plain; charset=" + hostEncoding);
0877
0878 /**
0879 * Doc flavor with MIME type =
0880 * <CODE>"text/plain; charset=utf-8"</CODE>,
0881 * print data representation class name =
0882 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0883 */
0884 public static final INPUT_STREAM TEXT_PLAIN_UTF_8 = new INPUT_STREAM(
0885 "text/plain; charset=utf-8");
0886
0887 /**
0888 * Doc flavor with MIME type =
0889 * <CODE>"text/plain; charset=utf-16"</CODE>,
0890 * print data representation class name =
0891 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0892 */
0893 public static final INPUT_STREAM TEXT_PLAIN_UTF_16 = new INPUT_STREAM(
0894 "text/plain; charset=utf-16");
0895
0896 /**
0897 * Doc flavor with MIME type =
0898 * <CODE>"text/plain; charset=utf-16be"</CODE>
0899 * (big-endian byte ordering),
0900 * print data representation class name =
0901 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0902 */
0903 public static final INPUT_STREAM TEXT_PLAIN_UTF_16BE = new INPUT_STREAM(
0904 "text/plain; charset=utf-16be");
0905
0906 /**
0907 * Doc flavor with MIME type =
0908 * <CODE>"text/plain; charset=utf-16le"</CODE>
0909 * (little-endian byte ordering),
0910 * print data representation class name =
0911 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0912 */
0913 public static final INPUT_STREAM TEXT_PLAIN_UTF_16LE = new INPUT_STREAM(
0914 "text/plain; charset=utf-16le");
0915
0916 /**
0917 * Doc flavor with MIME type =
0918 * <CODE>"text/plain; charset=us-ascii"</CODE>,
0919 * print data representation class name =
0920 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0921 */
0922 public static final INPUT_STREAM TEXT_PLAIN_US_ASCII = new INPUT_STREAM(
0923 "text/plain; charset=us-ascii");
0924
0925 /**
0926 * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
0927 * encoded in the host platform encoding.
0928 * See {@link DocFlavor#hostEncoding <CODE>hostEncoding</CODE>}
0929 * Print data representation class name =
0930 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0931 */
0932 public static final INPUT_STREAM TEXT_HTML_HOST = new INPUT_STREAM(
0933 "text/html; charset=" + hostEncoding);
0934
0935 /**
0936 * Doc flavor with MIME type =
0937 * <CODE>"text/html; charset=utf-8"</CODE>,
0938 * print data representation class name =
0939 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0940 */
0941 public static final INPUT_STREAM TEXT_HTML_UTF_8 = new INPUT_STREAM(
0942 "text/html; charset=utf-8");
0943
0944 /**
0945 * Doc flavor with MIME type =
0946 * <CODE>"text/html; charset=utf-16"</CODE>,
0947 * print data representation class name =
0948 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0949 */
0950 public static final INPUT_STREAM TEXT_HTML_UTF_16 = new INPUT_STREAM(
0951 "text/html; charset=utf-16");
0952
0953 /**
0954 * Doc flavor with MIME type =
0955 * <CODE>"text/html; charset=utf-16be"</CODE>
0956 * (big-endian byte ordering),
0957 * print data representation class name =
0958 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0959 */
0960 public static final INPUT_STREAM TEXT_HTML_UTF_16BE = new INPUT_STREAM(
0961 "text/html; charset=utf-16be");
0962
0963 /**
0964 * Doc flavor with MIME type =
0965 * <CODE>"text/html; charset=utf-16le"</CODE>
0966 * (little-endian byte ordering),
0967 * print data representation class name =
0968 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0969 */
0970 public static final INPUT_STREAM TEXT_HTML_UTF_16LE = new INPUT_STREAM(
0971 "text/html; charset=utf-16le");
0972
0973 /**
0974 * Doc flavor with MIME type =
0975 * <CODE>"text/html; charset=us-ascii"</CODE>,
0976 * print data representation class name =
0977 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0978 */
0979 public static final INPUT_STREAM TEXT_HTML_US_ASCII = new INPUT_STREAM(
0980 "text/html; charset=us-ascii");
0981
0982 /**
0983 * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
0984 * data representation class name = <CODE>"java.io.InputStream"</CODE>
0985 * (byte stream).
0986 */
0987 public static final INPUT_STREAM PDF = new INPUT_STREAM(
0988 "application/pdf");
0989
0990 /**
0991 * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
0992 * print data representation class name =
0993 * <CODE>"java.io.InputStream"</CODE> (byte stream).
0994 */
0995 public static final INPUT_STREAM POSTSCRIPT = new INPUT_STREAM(
0996 "application/postscript");
0997
0998 /**
0999 * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
1000 * print data representation class name =
1001 * <CODE>"java.io.InputStream"</CODE> (byte stream).
1002 */
1003 public static final INPUT_STREAM PCL = new INPUT_STREAM(
1004 "application/vnd.hp-PCL");
1005
1006 /**
1007 * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
1008 * representation class name =
1009 * <CODE>"java.io.InputStream"</CODE> (byte stream).
1010 */
1011 public static final INPUT_STREAM GIF = new INPUT_STREAM(
1012 "image/gif");
1013
1014 /**
1015 * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
1016 * representation class name =
1017 * <CODE>"java.io.InputStream"</CODE> (byte stream).
1018 */
1019 public static final INPUT_STREAM JPEG = new INPUT_STREAM(
1020 "image/jpeg");
1021
1022 /**
1023 * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
1024 * representation class name =
1025 * <CODE>"java.io.InputStream"</CODE> (byte stream).
1026 */
1027 public static final INPUT_STREAM PNG = new INPUT_STREAM(
1028 "image/png");
1029
1030 /**
1031 * Doc flavor with MIME type =
1032 * <CODE>"application/octet-stream"</CODE>,
1033 * print data representation class name =
1034 * <CODE>"java.io.InputStream"</CODE> (byte stream).
1035 * The client must determine that data described
1036 * using this DocFlavor is valid for the printer.
1037 */
1038 public static final INPUT_STREAM AUTOSENSE = new INPUT_STREAM(
1039 "application/octet-stream");
1040
1041 }
1042
1043 /**
1044 * Class DocFlavor.URL provides predefined static constant DocFlavor
1045 * objects.
1046 * For example doc flavors using a Uniform Resource Locator ({@link
1047 * java.net.URL <CODE>java.net.URL</CODE>}) as the print data
1048 * representation class.
1049 * <P>
1050 *
1051 * @author Alan Kaminsky
1052 */
1053 public static class URL extends DocFlavor {
1054
1055 /**
1056 * Constructs a new doc flavor with the given MIME type and a print
1057 * data representation class name of <CODE>"java.net.URL"</CODE>.
1058 *
1059 * @param mimeType MIME media type string.
1060 *
1061 * @exception NullPointerException
1062 * (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1063 * @exception IllegalArgumentException
1064 * (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1065 * obey the syntax for a MIME media type string.
1066 */
1067 public URL(String mimeType) {
1068 super (mimeType, "java.net.URL");
1069 }
1070
1071 /**
1072 * Doc flavor with MIME type = <CODE>"text/plain"</CODE>,
1073 * encoded in the host platform encoding.
1074 * See {@link DocFlavor#hostEncoding <CODE>hostEncoding</CODE>}
1075 * Print data representation class name =
1076 * <CODE>"java.net.URL"</CODE> (byte stream).
1077 */
1078 public static final URL TEXT_PLAIN_HOST = new URL(
1079 "text/plain; charset=" + hostEncoding);
1080
1081 /**
1082 * Doc flavor with MIME type =
1083 * <CODE>"text/plain; charset=utf-8"</CODE>,
1084 * print data representation class name =
1085 * <CODE>"java.net.URL"</CODE> (byte stream).
1086 */
1087 public static final URL TEXT_PLAIN_UTF_8 = new URL(
1088 "text/plain; charset=utf-8");
1089
1090 /**
1091 * Doc flavor with MIME type =
1092 * <CODE>"text/plain; charset=utf-16"</CODE>,
1093 * print data representation class name =
1094 * <CODE>java.net.URL""</CODE> (byte stream).
1095 */
1096 public static final URL TEXT_PLAIN_UTF_16 = new URL(
1097 "text/plain; charset=utf-16");
1098
1099 /**
1100 * Doc flavor with MIME type =
1101 * <CODE>"text/plain; charset=utf-16be"</CODE>
1102 * (big-endian byte ordering),
1103 * print data representation class name =
1104 * <CODE>"java.net.URL"</CODE> (byte stream).
1105 */
1106 public static final URL TEXT_PLAIN_UTF_16BE = new URL(
1107 "text/plain; charset=utf-16be");
1108
1109 /**
1110 * Doc flavor with MIME type =
1111 * <CODE>"text/plain; charset=utf-16le"</CODE>
1112 * (little-endian byte ordering),
1113 * print data representation class name =
1114 * <CODE>"java.net.URL"</CODE> (byte stream).
1115 */
1116 public static final URL TEXT_PLAIN_UTF_16LE = new URL(
1117 "text/plain; charset=utf-16le");
1118
1119 /**
1120 * Doc flavor with MIME type =
1121 * <CODE>"text/plain; charset=us-ascii"</CODE>,
1122 * print data representation class name =
1123 * <CODE>"java.net.URL"</CODE> (byte stream).
1124 */
1125 public static final URL TEXT_PLAIN_US_ASCII = new URL(
1126 "text/plain; charset=us-ascii");
1127
1128 /**
1129 * Doc flavor with MIME type = <CODE>"text/html"</CODE>,
1130 * encoded in the host platform encoding.
1131 * See {@link DocFlavor#hostEncoding <CODE>hostEncoding</CODE>}
1132 * Print data representation class name =
1133 * <CODE>"java.net.URL"</CODE> (byte stream).
1134 */
1135 public static final URL TEXT_HTML_HOST = new URL(
1136 "text/html; charset=" + hostEncoding);
1137
1138 /**
1139 * Doc flavor with MIME type =
1140 * <CODE>"text/html; charset=utf-8"</CODE>,
1141 * print data representation class name =
1142 * <CODE>"java.net.URL"</CODE> (byte stream).
1143 */
1144 public static final URL TEXT_HTML_UTF_8 = new URL(
1145 "text/html; charset=utf-8");
1146
1147 /**
1148 * Doc flavor with MIME type =
1149 * <CODE>"text/html; charset=utf-16"</CODE>,
1150 * print data representation class name =
1151 * <CODE>"java.net.URL"</CODE> (byte stream).
1152 */
1153 public static final URL TEXT_HTML_UTF_16 = new URL(
1154 "text/html; charset=utf-16");
1155
1156 /**
1157 * Doc flavor with MIME type =
1158 * <CODE>"text/html; charset=utf-16be"</CODE>
1159 * (big-endian byte ordering),
1160 * print data representation class name =
1161 * <CODE>"java.net.URL"</CODE> (byte stream).
1162 */
1163 public static final URL TEXT_HTML_UTF_16BE = new URL(
1164 "text/html; charset=utf-16be");
1165
1166 /**
1167 * Doc flavor with MIME type =
1168 * <CODE>"text/html; charset=utf-16le"</CODE>
1169 * (little-endian byte ordering),
1170 * print data representation class name =
1171 * <CODE>"java.net.URL"</CODE> (byte stream).
1172 */
1173 public static final URL TEXT_HTML_UTF_16LE = new URL(
1174 "text/html; charset=utf-16le");
1175
1176 /**
1177 * Doc flavor with MIME type =
1178 * <CODE>"text/html; charset=us-ascii"</CODE>,
1179 * print data representation class name =
1180 * <CODE>"java.net.URL"</CODE> (byte stream).
1181 */
1182 public static final URL TEXT_HTML_US_ASCII = new URL(
1183 "text/html; charset=us-ascii");
1184
1185 /**
1186 * Doc flavor with MIME type = <CODE>"application/pdf"</CODE>, print
1187 * data representation class name = <CODE>"java.net.URL"</CODE>.
1188 */
1189 public static final URL PDF = new URL("application/pdf");
1190
1191 /**
1192 * Doc flavor with MIME type = <CODE>"application/postscript"</CODE>,
1193 * print data representation class name = <CODE>"java.net.URL"</CODE>.
1194 */
1195 public static final URL POSTSCRIPT = new URL(
1196 "application/postscript");
1197
1198 /**
1199 * Doc flavor with MIME type = <CODE>"application/vnd.hp-PCL"</CODE>,
1200 * print data representation class name = <CODE>"java.net.URL"</CODE>.
1201 */
1202 public static final URL PCL = new URL("application/vnd.hp-PCL");
1203
1204 /**
1205 * Doc flavor with MIME type = <CODE>"image/gif"</CODE>, print data
1206 * representation class name = <CODE>"java.net.URL"</CODE>.
1207 */
1208 public static final URL GIF = new URL("image/gif");
1209
1210 /**
1211 * Doc flavor with MIME type = <CODE>"image/jpeg"</CODE>, print data
1212 * representation class name = <CODE>"java.net.URL"</CODE>.
1213 */
1214 public static final URL JPEG = new URL("image/jpeg");
1215
1216 /**
1217 * Doc flavor with MIME type = <CODE>"image/png"</CODE>, print data
1218 * representation class name = <CODE>"java.net.URL"</CODE>.
1219 */
1220 public static final URL PNG = new URL("image/png");
1221
1222 /**
1223 * Doc flavor with MIME type =
1224 * <CODE>"application/octet-stream"</CODE>,
1225 * print data representation class name = <CODE>"java.net.URL"</CODE>.
1226 * The client must determine that data described
1227 * using this DocFlavor is valid for the printer.
1228 */
1229 public static final URL AUTOSENSE = new URL(
1230 "application/octet-stream");
1231
1232 }
1233
1234 /**
1235 * Class DocFlavor.CHAR_ARRAY provides predefined static constant
1236 * DocFlavor objects for example doc flavors using a character array
1237 * (<CODE>char[]</CODE>) as the print data representation class. As such,
1238 * the character set is Unicode.
1239 * <P>
1240 *
1241 * @author Alan Kaminsky
1242 */
1243 public static class CHAR_ARRAY extends DocFlavor {
1244
1245 private static final long serialVersionUID = -8720590903724405128L;
1246
1247 /**
1248 * Constructs a new doc flavor with the given MIME type and a print
1249 * data representation class name of
1250 * <CODE>"[C"</CODE> (character array).
1251 *
1252 * @param mimeType MIME media type string. If it is a text media
1253 * type, it is assumed to contain a
1254 * <CODE>"charset=utf-16"</CODE> parameter.
1255 *
1256 * @exception NullPointerException
1257 * (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1258 * @exception IllegalArgumentException
1259 * (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1260 * obey the syntax for a MIME media type string.
1261 */
1262 public CHAR_ARRAY(String mimeType) {
1263 super (mimeType, "[C");
1264 }
1265
1266 /**
1267 * Doc flavor with MIME type = <CODE>"text/plain;
1268 * charset=utf-16"</CODE>, print data representation class name =
1269 * <CODE>"[C"</CODE> (character array).
1270 */
1271 public static final CHAR_ARRAY TEXT_PLAIN = new CHAR_ARRAY(
1272 "text/plain; charset=utf-16");
1273
1274 /**
1275 * Doc flavor with MIME type = <CODE>"text/html;
1276 * charset=utf-16"</CODE>, print data representation class name =
1277 * <CODE>"[C"</CODE> (character array).
1278 */
1279 public static final CHAR_ARRAY TEXT_HTML = new CHAR_ARRAY(
1280 "text/html; charset=utf-16");
1281
1282 }
1283
1284 /**
1285 * Class DocFlavor.STRING provides predefined static constant DocFlavor
1286 * objects for example doc flavors using a string ({@link java.lang.String
1287 * <CODE>java.lang.String</CODE>}) as the print data representation class.
1288 * As such, the character set is Unicode.
1289 * <P>
1290 *
1291 * @author Alan Kaminsky
1292 */
1293 public static class STRING extends DocFlavor {
1294
1295 private static final long serialVersionUID = 4414407504887034035L;
1296
1297 /**
1298 * Constructs a new doc flavor with the given MIME type and a print
1299 * data representation class name of <CODE>"java.lang.String"</CODE>.
1300 *
1301 * @param mimeType MIME media type string. If it is a text media
1302 * type, it is assumed to contain a
1303 * <CODE>"charset=utf-16"</CODE> parameter.
1304 *
1305 * @exception NullPointerException
1306 * (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1307 * @exception IllegalArgumentException
1308 * (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1309 * obey the syntax for a MIME media type string.
1310 */
1311 public STRING(String mimeType) {
1312 super (mimeType, "java.lang.String");
1313 }
1314
1315 /**
1316 * Doc flavor with MIME type = <CODE>"text/plain;
1317 * charset=utf-16"</CODE>, print data representation class name =
1318 * <CODE>"java.lang.String"</CODE>.
1319 */
1320 public static final STRING TEXT_PLAIN = new STRING(
1321 "text/plain; charset=utf-16");
1322
1323 /**
1324 * Doc flavor with MIME type = <CODE>"text/html;
1325 * charset=utf-16"</CODE>, print data representation class name =
1326 * <CODE>"java.lang.String"</CODE>.
1327 */
1328 public static final STRING TEXT_HTML = new STRING(
1329 "text/html; charset=utf-16");
1330 }
1331
1332 /**
1333 * Class DocFlavor.READER provides predefined static constant DocFlavor
1334 * objects for example doc flavors using a character stream ({@link
1335 * java.io.Reader <CODE>java.io.Reader</CODE>}) as the print data
1336 * representation class. As such, the character set is Unicode.
1337 * <P>
1338 *
1339 * @author Alan Kaminsky
1340 */
1341 public static class READER extends DocFlavor {
1342
1343 private static final long serialVersionUID = 7100295812579351567L;
1344
1345 /**
1346 * Constructs a new doc flavor with the given MIME type and a print
1347 * data representation class name of\
1348 * <CODE>"java.io.Reader"</CODE> (character stream).
1349 *
1350 * @param mimeType MIME media type string. If it is a text media
1351 * type, it is assumed to contain a
1352 * <CODE>"charset=utf-16"</CODE> parameter.
1353 *
1354 * @exception NullPointerException
1355 * (unchecked exception) Thrown if <CODE>mimeType</CODE> is null.
1356 * @exception IllegalArgumentException
1357 * (unchecked exception) Thrown if <CODE>mimeType</CODE> does not
1358 * obey the syntax for a MIME media type string.
1359 */
1360 public READER(String mimeType) {
1361 super (mimeType, "java.io.Reader");
1362 }
1363
1364 /**
1365 * Doc flavor with MIME type = <CODE>"text/plain;
1366 * charset=utf-16"</CODE>, print data representation class name =
1367 * <CODE>"java.io.Reader"</CODE> (character stream).
1368 */
1369 public static final READER TEXT_PLAIN = new READER(
1370 "text/plain; charset=utf-16");
1371
1372 /**
1373 * Doc flavor with MIME type = <CODE>"text/html;
1374 * charset=utf-16"</CODE>, print data representation class name =
1375 * <CODE>"java.io.Reader"</CODE> (character stream).
1376 */
1377 public static final READER TEXT_HTML = new READER(
1378 "text/html; charset=utf-16");
1379
1380 }
1381
1382 /**
1383 * Class DocFlavor.SERVICE_FORMATTED provides predefined static constant
1384 * DocFlavor objects for example doc flavors for service formatted print
1385 * data.
1386 * <P>
1387 *
1388 * @author Alan Kaminsky
1389 */
1390 public static class SERVICE_FORMATTED extends DocFlavor {
1391
1392 private static final long serialVersionUID = 6181337766266637256L;
1393
1394 /**
1395 * Constructs a new doc flavor with a MIME type of
1396 * <CODE>"application/x-java-jvm-local-objectref"</CODE> indicating
1397 * service formatted print data and the given print data
1398 * representation class name.
1399 *
1400 * @param className Fully-qualified representation class name.
1401 *
1402 * @exception NullPointerException
1403 * (unchecked exception) Thrown if <CODE>className</CODE> is
1404 * null.
1405 */
1406 public SERVICE_FORMATTED(String className) {
1407 super ("application/x-java-jvm-local-objectref", className);
1408 }
1409
1410 /**
1411 * Service formatted print data doc flavor with print data
1412 * representation class name =
1413 * <CODE>"java.awt.image.renderable.RenderableImage"</CODE>
1414 * (renderable image object).
1415 */
1416 public static final SERVICE_FORMATTED RENDERABLE_IMAGE = new SERVICE_FORMATTED(
1417 "java.awt.image.renderable.RenderableImage");
1418
1419 /**
1420 * Service formatted print data doc flavor with print data
1421 * representation class name = <CODE>"java.awt.print.Printable"</CODE>
1422 * (printable object).
1423 */
1424 public static final SERVICE_FORMATTED PRINTABLE = new SERVICE_FORMATTED(
1425 "java.awt.print.Printable");
1426
1427 /**
1428 * Service formatted print data doc flavor with print data
1429 * representation class name = <CODE>"java.awt.print.Pageable"</CODE>
1430 * (pageable object).
1431 */
1432 public static final SERVICE_FORMATTED PAGEABLE = new SERVICE_FORMATTED(
1433 "java.awt.print.Pageable");
1434
1435 }
1436
1437 }
|