javax.print

Class DocFlavor

Implemented Interfaces:
Cloneable, Serializable
Known Direct Subclasses:
DocFlavor.BYTE_ARRAY, DocFlavor.CHAR_ARRAY, DocFlavor.INPUT_STREAM, DocFlavor.READER, DocFlavor.SERVICE_FORMATTED, DocFlavor.STRING, DocFlavor.URL

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:
See Also:
Serialized Form

Nested Class Summary

static class
DocFlavor.BYTE_ARRAY
Predefined static DocFlavor objects for document types which use a byte array for the print data representation.
static class
DocFlavor.CHAR_ARRAY
Predefined static DocFlavor objects for document types which use a char array for the print data representation.
static class
DocFlavor.INPUT_STREAM
Predefined static DocFlavor objects for document types which use an InputStream to retrieve the print data.
static class
DocFlavor.READER
Predefined static DocFlavor objects for document types which use an Reader to retrieve the print data.
static class
DocFlavor.SERVICE_FORMATTED
Predefined static DocFlavor objects for document types which use service formatted print data.
static class
DocFlavor.STRING
Predefined static DocFlavor objects for document types which use a String for the print data representation.
static class
DocFlavor.URL
Predefined static DocFlavor objects for document types which have an URL where to retrieve the print data.

Field Summary

static String
hostEncoding
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

boolean
equals(Object obj)
Checks if this doc flavor object is equal to the given object.
String
getMediaSubtype()
Returns the media subtype of this flavor object.
String
getMediaType()
Returns the media type of this flavor object.
String
getMimeType()
Returns the mime type of this flavor object.
String
getParameter(String paramName)
Returns the value for an optional parameter of the mime type of this flavor object.
String
getRepresentationClassName()
Returns the name of the representation class of this flavor object.
int
hashCode()
Returns a hash code for this doc flavor object.
String
toString()
Returns a string representation of this doc flavor object.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

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. DocFlavor.BYTE_ARRAY.TEXT_HTML_HOST).

Constructor Details

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 Details

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.

Overrides:
equals in interface Object
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.
Overrides:
hashCode in interface 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() + "\"";
Overrides:
toString in interface Object
Returns:
The constructed string representation.

DocFlavor.java -- Copyright (C) 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.