javax.print

Class DocFlavor

public class DocFlavor extends Object implements Cloneable, Serializable

DocFlavor provides a description of the format in which the print data will be supplied in a print job to the print service.

A doc flavor consists of two parts:

The DocFlavor class is therefore used in several places in the Java Print Service API. A print service provides its supported document flavors as an array of DocFlavor objects and a print job gets the flavor of its data to print from the Doc object provided as a DocFlavor instance.

It has to be differentiated between client formatted and service formatted print data. Client formatted print data is already provided formatted by the client e.g. in an image format or as postscript. For service formatted print data, the Java Print Service instance produces the formatted print data. Here the doc flavor's representation class name does specify an interface instead of the actual print data source. The print service will call the methods of the given implementation of this interface with a special Graphics object capable of producing formatted print data from the graphics routines inside the interface methods.

Client formatted print data document flavors

The print service uses the representation class of the doc flavor to know how to retrieve the print data. If the representation class is a URL it will open the URL to read the print data from it. If it is a byte[] it will directly use the array and send it to the printer. There are predefined doc flavor as inner class for the most common representation class types:

Service formatted print data document flavors

The print service uses the provided object implementing the interface specified by the representation class to produce the formatted print data. The mime type of service formatted data is always "application/x-java-jvm-local-objectref" to signal the local reference to the print data object implementing the interface. Predefined doc flavor classes exist as an inner class for the three available interface to produce print data:

Nested Class Summary
static classDocFlavor.BYTE_ARRAY
Predefined static DocFlavor objects for document types which use a byte array for the print data representation.
static classDocFlavor.CHAR_ARRAY
Predefined static DocFlavor objects for document types which use a char array for the print data representation.
static classDocFlavor.INPUT_STREAM
Predefined static DocFlavor objects for document types which use an InputStream to retrieve the print data.
static classDocFlavor.READER
Predefined static DocFlavor objects for document types which use an Reader to retrieve the print data.
static classDocFlavor.SERVICE_FORMATTED
Predefined static DocFlavor objects for document types which use service formatted print data.
static classDocFlavor.STRING
Predefined static DocFlavor objects for document types which use a String for the print data representation.
static classDocFlavor.URL
Predefined static DocFlavor objects for document types which have an URL where to retrieve the print data.
Field Summary
static StringhostEncoding
The string representing the host encoding.
Constructor Summary
DocFlavor(String mimeType, String className)
Constructs a DocFlavor object with the given MIME type and representation class name.
Method Summary
booleanequals(Object obj)
Checks if this doc flavor object is equal to the given object.
StringgetMediaSubtype()
Returns the media subtype of this flavor object.
StringgetMediaType()
Returns the media type of this flavor object.
StringgetMimeType()
Returns the mime type of this flavor object.
StringgetParameter(String paramName)
Returns the value for an optional parameter of the mime type of this flavor object.
StringgetRepresentationClassName()
Returns the name of the representation class of this flavor object.
inthashCode()
Returns a hash code for this doc flavor object.
StringtoString()
Returns a string representation of this doc flavor object.

Field Detail

hostEncoding

public static final String hostEncoding
The string representing the host encoding. This is the encoding used in the predefined HOST doc flavors (e.g. {@link BYTE_ARRAY#TEXT_HTML_HOST}).

Constructor Detail

DocFlavor

public DocFlavor(String mimeType, String className)
Constructs a DocFlavor object with the given MIME type and representation class name.

Parameters: mimeType the MIME type string. className the fully-qualified name of the representation class.

Throws: NullPointerException if mimeType or className are null. IllegalArgumentException if given mimeType has syntax errors.

Method Detail

equals

public boolean equals(Object obj)
Checks if this doc flavor object is equal to the given object.

Two doc flavor objects are considered equal if the provided object is not null and an instance of DocFlavor. The MIME types has to be equal in their media type, media subtype, their paramter/value combinations and the representation classname.

Parameters: obj the object to test.

Returns: true if equal, false otherwise.

getMediaSubtype

public String getMediaSubtype()
Returns the media subtype of this flavor object. A mimetype of "text/html; charset=us-ascii" will return "html" as the media subtype.

Returns: The media subtype.

getMediaType

public String getMediaType()
Returns the media type of this flavor object. A mimetype of "text/html; charset=us-ascii" will return "text" as the media type.

Returns: The media type.

getMimeType

public String getMimeType()
Returns the mime type of this flavor object. The mimetype will have every parameter value enclosed in quotes.

Returns: The mime type.

getParameter

public String getParameter(String paramName)
Returns the value for an optional parameter of the mime type of this flavor object.

Parameters: paramName the name of the parameter

Returns: The value for the parameter, or null if none bound.

Throws: NullPointerException if paramName is null.

getRepresentationClassName

public String getRepresentationClassName()
Returns the name of the representation class of this flavor object.

Returns: The representation classname.

hashCode

public int hashCode()
Returns a hash code for this doc flavor object.

Returns: The hashcode.

toString

public String toString()
Returns a string representation of this doc flavor object. The returned string is of the form getMimeType() + "; class=\"" + getRepresentationClassName() + "\"";

Returns: The constructed string representation.