diff options
Diffstat (limited to 'javax/print')
27 files changed, 1430 insertions, 208 deletions
diff --git a/javax/print/CancelablePrintJob.java b/javax/print/CancelablePrintJob.java index 94e9475e5..39a25440e 100644 --- a/javax/print/CancelablePrintJob.java +++ b/javax/print/CancelablePrintJob.java @@ -1,5 +1,5 @@ /* CancelablePrintJob.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,14 +39,29 @@ exception statement from your version. */ package javax.print; /** + * <code>CancelablePrintJob</code> represents a print job which can be + * canceled. + * <p> + * It is implemented by <code>DocPrintJob</code>s which support to cancel + * a print job during processing. Clients need to explicitly test if a given + * <code>DocPrintJob</code> object from a print service implementes this + * interface and therefore supports cancelling. + * </p><p> + * Implementor of java print services should implement this interface if + * cancelling is supported by the underlying print system. If implemented the + * corresponding print job event + * {@link javax.print.event.PrintJobEvent#JOB_CANCELED} should be delivered to + * registered clients. Implementations have to be thread-safe. + * </p> + * * @author Michael Koch (konqueror@gmx.de) */ public interface CancelablePrintJob extends DocPrintJob { /** - * Cancel print job. + * Cancel the print job. * - * @exception PrintException if an error occured + * @exception PrintException if an error during cancellation occurs. */ void cancel() throws PrintException; } diff --git a/javax/print/Doc.java b/javax/print/Doc.java index 00e9dc986..c489de1b6 100644 --- a/javax/print/Doc.java +++ b/javax/print/Doc.java @@ -1,5 +1,5 @@ /* Doc.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,51 +45,102 @@ import java.io.Reader; import javax.print.attribute.DocAttributeSet; /** + * <code>Doc</code> specifies the interface for print services how to obtain + * the print data and document specific attributes for printing. + * <p> + * The print data is always passed to a {@link javax.print.DocPrintJob} object + * as a <code>Doc</code> object which allows the print services to: + * <ul> + * <li>Determine the actual document format of the supplied print data. This + * is supplied as a {@link javax.print.DocFlavor} object with the MIME type + * and the representation class of the print data.</li> + * <li>Obtain the print data either in its representation class or depending + * on the document format through convenience methods as a + * {@link java.io.Reader} or an {@link java.io.InputStream}.</li> + * <li>Obtain the document's attribute set specifying the attributes which + * apply to this document instance.</li> + * </ul> + * </p><p> + * Every method of a <code>Doc</code> implementation has to return always the + * same object on every method call. Therefore if the print job consumes the + * print data via a stream or a reader object it can read only once the + * supplied print data. Implementations of this interface have to be thread + * safe. + * </p> + * * @author Michael Koch (konqueror@gmx.de) */ public interface Doc { /** - * Returns a set of attributes applying to this document. + * Returns the unmodifiable view of the attributes of this doc object. + * <p> + * The attributes of this doc's attributes set overrides attributes of + * the same category in the print job's attribute set. If an attribute + * is not available in this doc's attributes set or <code>null</code> + * is returned the attributes of the same category of the print job are + * used. + * </p> * - * @return the attributes + * @return The unmodifiable attributes set, or <code>null</code>. */ DocAttributeSet getAttributes(); /** - * Returns the flavor in which this document will provide its print data. - * - * @return the document flavor for printing + * Returns the flavor of this doc objects print data. + * + * @return The document flavor. */ DocFlavor getDocFlavor(); /** - * Returns the print data of this document represented in a format that supports - * the document flavor. - * - * @return the print data + * Returns the print data of this doc object. + * <p> + * The returned object is an instance as described by the associated + * document flavor ({@link DocFlavor#getRepresentationClassName()}) + * and can be cast to this representation class. + * </p> * - * @throws IOException if an error occurs + * @return The print data in the representation class. + * @throws IOException if representation class is a stream and I/O + * exception occures. */ Object getPrintData() throws IOException; /** * Returns a <code>Reader</code> object for extracting character print data * from this document. + * <p> + * This method is supported if the document flavor is of type: + * <ul> + * <li><code>char[]</code></li> + * <li><code>java.lang.String</code></li> + * <li><code>java.io.Reader</code></li> + * </ul> + * otherwise this method returns <code>null</code>. + * </p> * - * @return the <code>Reader</code> object + * @return The <code>Reader</code> object, or <code>null</code>. * - * @throws IOException if an error occurs + * @throws IOException if an error occurs. */ Reader getReaderForText() throws IOException; /** * Returns an <code>InputStream</code> object for extracting byte print data * from this document. + * <p> + * This method is supported if the document flavor is of type: + * <ul> + * <li><code>byte[]</code></li> + * <li><code>java.io.InputStream</code></li> + * </ul> + * otherwise this method returns <code>null</code>. + * </p> * - * @return the <code>InputStream</code> object + * @return The <code>InputStream</code> object, or <code>null</code>. * - * @throws IOException if an error occurs + * @throws IOException if an error occurs. */ InputStream getStreamForBytes() throws IOException; }
\ No newline at end of file diff --git a/javax/print/DocFlavor.java b/javax/print/DocFlavor.java index 1e96a70c0..603059525 100644 --- a/javax/print/DocFlavor.java +++ b/javax/print/DocFlavor.java @@ -1,5 +1,5 @@ /* DocFlavor.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,17 +38,108 @@ exception statement from your version. */ package javax.print; +import java.io.IOException; +import java.io.ObjectInputStream; import java.io.Serializable; -import java.util.HashMap; +import java.io.StreamTokenizer; +import java.io.StringReader; +import java.nio.charset.Charset; import java.util.Iterator; import java.util.Map; +import java.util.TreeMap; /** + * <code>DocFlavor</code> provides a description of the format in which the + * print data will be supplied in a print job to the print service. + * <p> + * A doc flavor consists of two parts: + * <ul> + * <li> + * The MIME type (Multipurpose Internet Mail Extensions types as described + * in RFC 2045/2046) specifying the media format of the print data. + * </li><li> + * The representation class name which is the fully qualified name of the + * class providing the print data to the print job. For example if the print + * data is supplied as a byte array the representation class name will be + * <code>"[B"</code> or for an input stream <code>"java.io.InputStream"</code>. + * </li> + * </ul> + * The <code>DocFlavor</code> 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 <code>Doc</code> object provided as a DocFlavor + * instance. + * </p> + * <p> + * It has to be differentiated between <b>client formatted</b> and <b>service + * formatted</b> 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. + * </p> + * <p> + * <h3>Client formatted print data document flavors</h3> + * 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 + * <code>URL</code> it will open the URL to read the print data from it. If it is + * a <code>byte[]</code> 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: + * <ul> + * <li>Character arrays (<code>char[]</code>): The characters of the array + * represent the print data.</li> + * <li>Character streams (<code>java.io.Reader</code>): The whole characters + * read from the stream represent the print data.</li> + * <li>String (<code>java.lang.String</code>): The characters of the String + * represent the print data.</li> + * <li>Byte arrays (<code>byte[]</code>): The bytes of the array represent the + * print data. Encoding if text content is given in the mime type.</li> + * <li>Byte streams (<code>java.io.InputStream</code>): The whole bytes read + * from the stream represent the print data. If text content the encoding is + * specified in the mime type.</li> + * <li>Uniform Resource Locator (<code>java.net.URL</code>): The bytes read + * from the stream through opening of the URL represent the print data. + * If text content the encoding is specified in the mime type.</li></li> + * </ul> + * </p> + * <p> + * <h3>Service formatted print data document flavors</h3> + * 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 + * <code>"application/x-java-jvm-local-objectref"</code> 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: + * <ul> + * <li>Pageable object (<code>java.awt.print.Pageable</code>): A pageable object + * is supplied to the print service. The print service will call the methods of + * the interface with a Grahics object to produce the formatted print data.</li> + * <li>Printable object (<code>java.awt.print.Printable</code>): A printable object + * is supplied to the print service. The print service will call the methods of + * the interface with a Grahics object to produce the formatted print data.</li> + * <li>Renderable Image object + * (<code>java.awt.image.renderable.RenderableImage</code>): A renderable image + * object is supplied to the print service. The print service calls methods of + * this interface to obtain the image to be printed.</li> + * </ul> + * </p> + * * @author Michael Koch (konqueror@gmx.de) + * @author Wolfgang Baer (WBaer@gmx.de) */ public class DocFlavor implements Cloneable, Serializable { /** + * Predefined static <code>DocFlavor</code> objects for document + * types which use a byte array for the print data representation. + * <p>All the defined doc flavors have a print data representation + * classname of "[B" (byte array).</p> + * * @author Michael Koch (konqueror@gmx.de) */ public static class BYTE_ARRAY @@ -56,26 +147,92 @@ public class DocFlavor implements Cloneable, Serializable { private static final long serialVersionUID = -9065578006593857475L; + /** + * Byte array doc flavor with a MIME Type of "application/octet-stream". + */ public static final BYTE_ARRAY AUTOSENSE = new BYTE_ARRAY("application/octet-stream"); + /** + * Byte array doc flavor with a MIME Type of "image/gif". + */ public static final BYTE_ARRAY GIF = new BYTE_ARRAY("image/gif"); + /** + * Byte array doc flavor with a MIME Type of "image/jpeg". + */ public static final BYTE_ARRAY JPEG = new BYTE_ARRAY("image/jpeg"); + /** + * Byte array doc flavor with a MIME Type of "application/vnd.hp-PCL". + */ public static final BYTE_ARRAY PCL = new BYTE_ARRAY("application/vnd.hp-PCL"); + /** + * Byte array doc flavor with a MIME Type of "application/pdf". + */ public static final BYTE_ARRAY PDF = new BYTE_ARRAY("application/pdf"); + /** + * Byte array doc flavor with a MIME Type of "image/png". + */ public static final BYTE_ARRAY PNG = new BYTE_ARRAY("image/png"); + /** + * Byte array doc flavor with a MIME Type of "application/postscript". + */ public static final BYTE_ARRAY POSTSCRIPT = new BYTE_ARRAY("application/postscript"); - public static final BYTE_ARRAY TEXT_HTML_HOST = new BYTE_ARRAY("text/html"); + /** + * Byte array doc flavor with a MIME Type of "text/html" in the host encoding. + */ + public static final BYTE_ARRAY TEXT_HTML_HOST = new BYTE_ARRAY("text/html; charset=" + hostEncoding); + /** + * Byte array doc flavor with a MIME Type of "text/html; charset=us-ascii". + */ public static final BYTE_ARRAY TEXT_HTML_US_ASCII = new BYTE_ARRAY("text/html; charset=us-ascii"); + /** + * Byte array doc flavor with a MIME Type of "text/html; charset=utf-16". + */ public static final BYTE_ARRAY TEXT_HTML_UTF_16 = new BYTE_ARRAY("text/html; charset=utf-16"); + /** + * Byte array doc flavor with a MIME Type of "text/html; charset=utf-16be". + */ public static final BYTE_ARRAY TEXT_HTML_UTF_16BE = new BYTE_ARRAY("text/html; charset=utf-16be"); + /** + * Byte array doc flavor with a MIME Type of "text/html; charset=utf-16le". + */ public static final BYTE_ARRAY TEXT_HTML_UTF_16LE = new BYTE_ARRAY("text/html; charset=utf-16le"); + /** + * Byte array doc flavor with a MIME Type of "text/html; charset=utf-8". + */ public static final BYTE_ARRAY TEXT_HTML_UTF_8 = new BYTE_ARRAY("text/html; charset=utf-8"); - public static final BYTE_ARRAY TEXT_PLAIN_HOST = new BYTE_ARRAY("text/plain"); - public static final BYTE_ARRAY TEXT_PLAIN_US_ASCII = new BYTE_ARRAY("text/plain; charset=us-ascii"); + /** + * Byte array doc flavor with a MIME Type of "text/plain" in the host encoding. + */ + public static final BYTE_ARRAY TEXT_PLAIN_HOST = new BYTE_ARRAY("text/plain; charset=" + hostEncoding); + /** + * Byte array doc flavor with a MIME Type of "text/plain; charset=us-ascii". + */ + public static final BYTE_ARRAY TEXT_PLAIN_US_ASCII = new BYTE_ARRAY("text/plain; charset=us-ascii"); + /** + * Byte array doc flavor with a MIME Type of "text/plain; charset=utf-16". + */ public static final BYTE_ARRAY TEXT_PLAIN_UTF_16 = new BYTE_ARRAY("text/plain; charset=utf-16"); + /** + * Byte array doc flavor with a MIME Type of "text/plain; charset=utf-16be". + */ public static final BYTE_ARRAY TEXT_PLAIN_UTF_16BE = new BYTE_ARRAY("text/plain; charset=utf-16be"); + /** + * Byte array doc flavor with a MIME Type of "text/plain; charset=utf-16le". + */ public static final BYTE_ARRAY TEXT_PLAIN_UTF_16LE = new BYTE_ARRAY("text/plain; charset=utf-16le"); + /** + * Byte array doc flavor with a MIME Type of "text/plain; charset=utf-8". + */ public static final BYTE_ARRAY TEXT_PLAIN_UTF_8 = new BYTE_ARRAY("text/plain; charset=utf-8"); + /** + * Constructor for doc flavor objects with the given MIME type + * and a print data representation class name of "[B". + * + * @param mimeType the mime type string + * + * @throws NullPointerException if mimeType is <code>null</code>. + * @throws IllegalArgumentException if mimeType has the wrong syntax. + */ public BYTE_ARRAY(String mimeType) { super(mimeType, "[B"); @@ -83,6 +240,11 @@ public class DocFlavor implements Cloneable, Serializable } /** + * Predefined static <code>DocFlavor</code> objects for document + * types which use a char array for the print data representation. + * <p>All the defined doc flavors have a print data representation + * classname of "[C" (char array).</p> + * * @author Michael Koch (konqueror@gmx.de) */ public static class CHAR_ARRAY @@ -90,9 +252,24 @@ public class DocFlavor implements Cloneable, Serializable { private static final long serialVersionUID = -8720590903724405128L; + /** + * Char array doc flavor with a MIME Type of "text/html; charset=utf-16". + */ public static final DocFlavor.CHAR_ARRAY TEXT_HTML = new CHAR_ARRAY("text/html; charset=utf-16"); + /** + * Char array doc flavor with a MIME Type of "text/plain; charset=utf-16". + */ public static final DocFlavor.CHAR_ARRAY TEXT_PLAIN = new CHAR_ARRAY("text/plain; charset=utf-16"); + /** + * Constructor for doc flavor objects with the given MIME type + * and a print data representation class name of "[C". + * + * @param mimeType the mime type string + * + * @throws NullPointerException if mimeType is <code>null</code>. + * @throws IllegalArgumentException if mimeType has the wrong syntax. + */ public CHAR_ARRAY(String mimeType) { super(mimeType, "[C"); @@ -100,6 +277,11 @@ public class DocFlavor implements Cloneable, Serializable } /** + * Predefined static <code>DocFlavor</code> objects for document + * types which use an InputStream to retrieve the print data. + * <p>All the defined doc flavors have a print data representation + * classname of "java.io.InputStream".</p> + * * @author Michael Koch (konqueror@gmx.de) */ public static class INPUT_STREAM @@ -107,26 +289,92 @@ public class DocFlavor implements Cloneable, Serializable { private static final long serialVersionUID = -7045842700749194127L; + /** + * InputStream doc flavor with a MIME Type of "application/octet-stream". + */ public static final INPUT_STREAM AUTOSENSE = new INPUT_STREAM("application/octet-stream"); + /** + * InputStream doc flavor with a MIME Type of "image/gif". + */ public static final INPUT_STREAM GIF = new INPUT_STREAM("image/gif"); + /** + * InputStream doc flavor with a MIME Type of "image/jpeg". + */ public static final INPUT_STREAM JPEG = new INPUT_STREAM("image/jpeg"); + /** + * InputStream doc flavor with a MIME Type of "application/vnd.hp-PCL". + */ public static final INPUT_STREAM PCL = new INPUT_STREAM("application/vnd.hp-PCL"); + /** + * InputStream doc flavor with a MIME Type of "application/pdf". + */ public static final INPUT_STREAM PDF = new INPUT_STREAM("application/pdf"); + /** + * InputStream doc flavor with a MIME Type of "image/png". + */ public static final INPUT_STREAM PNG = new INPUT_STREAM("image/png"); + /** + * InputStream doc flavor with a MIME Type of "application/postscript". + */ public static final INPUT_STREAM POSTSCRIPT = new INPUT_STREAM("application/postscript"); - public static final INPUT_STREAM TEXT_HTML_HOST = new INPUT_STREAM("text/html"); + /** + * InputStream doc flavor with a MIME Type of "text/html" in the host encoding. + */ + public static final INPUT_STREAM TEXT_HTML_HOST = new INPUT_STREAM("text/html; charset=" + hostEncoding); + /** + * InputStream doc flavor with a MIME Type of "text/html; charset=us-ascii". + */ public static final INPUT_STREAM TEXT_HTML_US_ASCII = new INPUT_STREAM("text/html; charset=us-ascii"); + /** + * InputStream doc flavor with a MIME Type of "text/html; charset=utf-16". + */ public static final INPUT_STREAM TEXT_HTML_UTF_16 = new INPUT_STREAM("text/html; charset=utf-16"); + /** + * InputStream doc flavor with a MIME Type of "text/html; charset=utf-16be". + */ public static final INPUT_STREAM TEXT_HTML_UTF_16BE = new INPUT_STREAM("text/html; charset=utf-16be"); + /** + * InputStream doc flavor with a MIME Type of "text/html; charset=utf-16le". + */ public static final INPUT_STREAM TEXT_HTML_UTF_16LE = new INPUT_STREAM("text/html; charset=utf-16le"); + /** + * InputStream doc flavor with a MIME Type of "text/html; charset=utf-8". + */ public static final INPUT_STREAM TEXT_HTML_UTF_8 = new INPUT_STREAM("text/html; charset=utf-8"); - public static final INPUT_STREAM TEXT_PLAIN_HOST = new INPUT_STREAM("text/plain"); + /** + * InputStream doc flavor with a MIME Type of "text/plain" in the host encoding. + */ + public static final INPUT_STREAM TEXT_PLAIN_HOST = new INPUT_STREAM("text/plain; charset=" + hostEncoding); + /** + * InputStream doc flavor with a MIME Type of "text/plain; charset=us-ascii". + */ public static final INPUT_STREAM TEXT_PLAIN_US_ASCII = new INPUT_STREAM("text/plain; charset=us-ascii"); + /** + * InputStream doc flavor with a MIME Type of "text/plain; charset=utf-16". + */ public static final INPUT_STREAM TEXT_PLAIN_UTF_16 = new INPUT_STREAM("text/plain; charset=utf-16"); + /** + * InputStream doc flavor with a MIME Type of "text/plain; charset=utf-16be". + */ public static final INPUT_STREAM TEXT_PLAIN_UTF_16BE = new INPUT_STREAM("text/plain; charset=utf-16be"); + /** + * InputStream doc flavor with a MIME Type of "text/plain; charset=utf-16le". + */ public static final INPUT_STREAM TEXT_PLAIN_UTF_16LE = new INPUT_STREAM("text/plain; charset=utf-16le"); + /** + * InputStream doc flavor with a MIME Type of "text/plain; charset=utf-8". + */ public static final INPUT_STREAM TEXT_PLAIN_UTF_8 = new INPUT_STREAM("text/plain; charset=utf-8"); + /** + * Constructor for doc flavor objects with the given MIME type + * and a print data representation class name of "java.io.InputStream". + * + * @param mimeType the mime type string + * + * @throws NullPointerException if mimeType is <code>null</code>. + * @throws IllegalArgumentException if mimeType has the wrong syntax. + */ public INPUT_STREAM(String mimeType) { super(mimeType, "java.io.InputStream"); @@ -134,6 +382,11 @@ public class DocFlavor implements Cloneable, Serializable } /** + * Predefined static <code>DocFlavor</code> objects for document + * types which use an Reader to retrieve the print data. + * <p>All the defined doc flavors have a print data representation + * classname of "java.io.Reader".</p> + * * @author Michael Koch (konqueror@gmx.de) */ public static class READER @@ -141,9 +394,24 @@ public class DocFlavor implements Cloneable, Serializable { private static final long serialVersionUID = 7100295812579351567L; + /** + * Reader doc flavor with a MIME Type of "text/html; charset=utf-16". + */ public static final DocFlavor.READER TEXT_HTML = new READER("text/html; charset=utf-16"); + /** + * Reader doc flavor with a MIME Type of "text/plain; charset=utf-16". + */ public static final DocFlavor.READER TEXT_PLAIN = new READER("text/plain; charset=utf-16"); + /** + * Constructor for doc flavor objects with the given MIME type + * and a print data representation class name of "java.io.Reader". + * + * @param mimeType the mime type string + * + * @throws NullPointerException if mimeType is <code>null</code>. + * @throws IllegalArgumentException if mimeType has the wrong syntax. + */ public READER(String mimeType) { super(mimeType, "java.io.Reader"); @@ -151,6 +419,11 @@ public class DocFlavor implements Cloneable, Serializable } /** + * Predefined static <code>DocFlavor</code> objects for document + * types which use service formatted print data. + * <p>All the defined doc flavors have a MIME type of + * "application/x-java-jvm-local-objectref".</p> + * * @author Michael Koch (konqueror@gmx.de) */ public static class SERVICE_FORMATTED @@ -158,10 +431,31 @@ public class DocFlavor implements Cloneable, Serializable { private static final long serialVersionUID = 6181337766266637256L; + /** + * Service formatted doc flavor with a representation class of + * "java.awt.print.Pageable". + */ public static final DocFlavor.SERVICE_FORMATTED PAGEABLE = new SERVICE_FORMATTED("java.awt.print.Pageable"); + /** + * Service formatted doc flavor with a representation class of + * "java.awt.print.Printable". + */ public static final DocFlavor.SERVICE_FORMATTED PRINTABLE = new SERVICE_FORMATTED("java.awt.print.Printable"); + /** + * Service formatted doc flavor with a representation class of + * "java.awt.image.renderable.RenderableImage". + */ public static final DocFlavor.SERVICE_FORMATTED RENDERABLE_IMAGE = new SERVICE_FORMATTED("java.awt.image.renderable.RenderableImage"); + /** + * Constructor for doc flavor objects with a MIME type of + * "application/x-java-jvm-local-objectref" and the given + * print data representation classname. + * + * @param className the representation classname + * + * @throws NullPointerException if className is <code>null</code>. + */ public SERVICE_FORMATTED(String className) { super("application/x-java-jvm-local-objectref", className); @@ -169,6 +463,11 @@ public class DocFlavor implements Cloneable, Serializable } /** + * Predefined static <code>DocFlavor</code> objects for document + * types which use a String for the print data representation. + * <p>All the defined doc flavors have a print data representation + * classname of "java.lang.String".</p> + * * @author Michael Koch (konqueror@gmx.de) */ public static class STRING @@ -176,9 +475,24 @@ public class DocFlavor implements Cloneable, Serializable { private static final long serialVersionUID = 4414407504887034035L; + /** + * String doc flavor with a MIME Type of "text/html; charset=utf-16". + */ public static final DocFlavor.STRING TEXT_HTML = new STRING("text/html; charset=utf-16"); + /** + * String doc flavor with a MIME Type of "text/plain; charset=utf-16". + */ public static final DocFlavor.STRING TEXT_PLAIN = new STRING("text/plain; charset=utf-16"); + /** + * Constructor for doc flavor objects with the given MIME type + * and a print data representation class name of "java.lang.String". + * + * @param mimeType the mime type string + * + * @throws NullPointerException if mimeType is <code>null</code>. + * @throws IllegalArgumentException if mimeType has the wrong syntax. + */ public STRING(String mimeType) { super(mimeType, "java.lang.String"); @@ -186,6 +500,11 @@ public class DocFlavor implements Cloneable, Serializable } /** + * Predefined static <code>DocFlavor</code> objects for document + * types which have an URL where to retrieve the print data. + * <p>All the defined doc flavors have a print data representation + * classname of "java.net.URL".</p> + * * @author Michael Koch (konqueror@gmx.de) */ public static class URL @@ -193,26 +512,92 @@ public class DocFlavor implements Cloneable, Serializable { private static final long serialVersionUID = 2936725788144902062L; + /** + * URL doc flavor with a MIME Type of "application/octet-stream". + */ public static final DocFlavor.URL AUTOSENSE = new URL("application/octet-stream"); + /** + * URL doc flavor with a MIME Type of "image/gif". + */ public static final DocFlavor.URL GIF = new URL("image/gif"); + /** + * URL doc flavor with a MIME Type of "image/jpeg". + */ public static final DocFlavor.URL JPEG = new URL("image/jpeg"); + /** + * URL doc flavor with a MIME Type of "application/vnd.hp-PCL". + */ public static final DocFlavor.URL PCL = new URL("application/vnd.hp-PCL"); + /** + * URL doc flavor with a MIME Type of "application/pdf". + */ public static final DocFlavor.URL PDF = new URL("application/pdf"); + /** + * URL doc flavor with a MIME Type of "image/png". + */ public static final DocFlavor.URL PNG = new URL("image/png"); + /** + * URL doc flavor with a MIME Type of "application/postscript". + */ public static final DocFlavor.URL POSTSCRIPT = new URL("application/postscript"); - public static final DocFlavor.URL TEXT_HTML_HOST = new URL("text/html"); + /** + * URL doc flavor with a MIME Type of "text/html" in the host encoding. + */ + public static final DocFlavor.URL TEXT_HTML_HOST = new URL("text/html; charset=" + hostEncoding); + /** + * URL doc flavor with a MIME Type of "text/html; charset=us-ascii". + */ public static final DocFlavor.URL TEXT_HTML_US_ASCII = new URL("text/html; charset=us-ascii"); + /** + * URL doc flavor with a MIME Type of "text/html; charset=utf-16". + */ public static final DocFlavor.URL TEXT_HTML_UTF_16 = new URL("text/html; charset=utf-16"); + /** + * URL doc flavor with a MIME Type of "text/html; charset=utf-16be". + */ public static final DocFlavor.URL TEXT_HTML_UTF_16BE = new URL("text/html; charset=utf-16be"); + /** + * URL doc flavor with a MIME Type of "text/html; charset=utf-16le". + */ public static final DocFlavor.URL TEXT_HTML_UTF_16LE = new URL("text/html; charset=utf-16le"); + /** + * URL doc flavor with a MIME Type of "text/html; charset=utf-8". + */ public static final DocFlavor.URL TEXT_HTML_UTF_8 = new URL("text/html; charset=utf-8"); - public static final DocFlavor.URL TEXT_PLAIN_HOST = new URL("text/plain"); + /** + * URL doc flavor with a MIME Type of "text/plain" in the host encoding. + */ + public static final DocFlavor.URL TEXT_PLAIN_HOST = new URL("text/plain; charset=" + hostEncoding); + /** + * URL doc flavor with a MIME Type of "text/plain; charset=us-ascii". + */ public static final DocFlavor.URL TEXT_PLAIN_US_ASCII = new URL("text/plain; charset=us-ascii"); + /** + * URL doc flavor with a MIME Type of "text/plain; charset=utf-16". + */ public static final DocFlavor.URL TEXT_PLAIN_UTF_16 = new URL("text/plain; charset=utf-16"); + /** + * URL doc flavor with a MIME Type of "text/plain; charset=utf-16be". + */ public static final DocFlavor.URL TEXT_PLAIN_UTF_16BE = new URL("text/plain; charset=utf-16be"); + /** + * URL doc flavor with a MIME Type of "text/plain; charset=utf-16le". + */ public static final DocFlavor.URL TEXT_PLAIN_UTF_16LE = new URL("text/plain; charset=utf-16le"); + /** + * URL doc flavor with a MIME Type of "text/plain; charset=utf-8". + */ public static final DocFlavor.URL TEXT_PLAIN_UTF_8 = new URL("text/plain; charset=utf-8"); + /** + * Constructor for doc flavor objects with the given MIME type + * and a print data representation class name of "java.net.URL". + * + * @param mimeType the mime type string + * + * @throws NullPointerException if mimeType is <code>null</code>. + * @throws IllegalArgumentException if mimeType has the wrong syntax. + */ public URL(String mimeType) { super(mimeType, "java.net.URL"); @@ -221,47 +606,191 @@ public class DocFlavor implements Cloneable, Serializable private static final long serialVersionUID = -4512080796965449721L; - // FIXME: Get the host encoding from somewhere. Note that the new String is to make - // sure the field won't be a compile time constant. - public static final String hostEncoding = new String("US-ASCII"); - - private String mediaSubtype; - private String mediaType; - private String className; - private HashMap params = new HashMap(); + /** + * 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}). + */ + public static final String hostEncoding = Charset.defaultCharset().name(); + + private transient String mediaSubtype; + private transient String mediaType; + private transient TreeMap params; + // name as defined in Serialized Form JDK 1.4 + private String myClassName; + + /** + * Constructs a <code>DocFlavor</code> object with the given MIME type and + * representation class name. + * + * @param mimeType the MIME type string. + * @param className the fully-qualified name of the representation class. + * + * @throws NullPointerException if mimeType or className are <code>null</code>. + * @throws IllegalArgumentException if given mimeType has syntax errors. + */ public DocFlavor(String mimeType, String className) { if (mimeType == null || className == null) throw new NullPointerException(); + params = new TreeMap(); parseMimeType(mimeType); - this.className = className; + + myClassName = className; } - + + /** + * Parses the given string as MIME type. + * The mediatype, mediasubtype and all parameter/value + * combinations are extracted, comments are dropped. + * + * @param mimeType the string to parse + * @throws IllegalArgumentException if not conformant. + */ private void parseMimeType(String mimeType) { - // FIXME: This method is know to be not completely correct, but it works for now. + int MEDIA = 1; + int MEDIASUB = 2; + int PARAM_NAME = 3; + int PARAM_VALUE = 4; + int COMMENT_START = 5; - int pos = mimeType.indexOf(';'); - - if (pos != -1) + int state = 0; + int lastState = 0; // keeps track of state before comment + int tok; + + try { - String tmp = mimeType.substring(pos + 2); - mimeType = mimeType.substring(0, pos); - pos = tmp.indexOf('='); - params.put(tmp.substring(0, pos), tmp.substring(pos + 1)); + String paramName = null; + StreamTokenizer in = new StreamTokenizer(new StringReader(mimeType)); + in.resetSyntax(); + // Allowed characters are anything except: + // SPACE, CTLs (= Unicode characters U+0000 - U+001F and U+007F) + // and tspecials ( ) < > @ , ; : \ " / [ ] ? = + in.whitespaceChars(0x00, 0x20); + in.whitespaceChars(0x7F, 0x7F); + in.wordChars('A', 'Z'); + in.wordChars('a', 'z'); + in.wordChars('0', '9'); + in.wordChars(0xA0, 0xFF); + in.wordChars(0x21, 0x21); + in.wordChars(0x23, 0x27); + in.wordChars(0x2A, 0x2B); + in.wordChars(0x2D, 0x2E); + in.wordChars(0x5E, 0x60); + in.wordChars(0x7B, 0x7E); + in.quoteChar('"'); + + while ((tok = in.nextToken()) != StreamTokenizer.TT_EOF) + { + switch (tok) + { + case StreamTokenizer.TT_WORD: + if (state == 0) + { + mediaType = in.sval.toLowerCase(); + state = MEDIA; + break; + } + if (state == MEDIA) + { + mediaSubtype = in.sval.toLowerCase(); + state = MEDIASUB; + break; + } + // begin of parameters is either after mediasub or a parameter value + if (state == MEDIASUB || state == PARAM_VALUE) + { + paramName = in.sval.toLowerCase(); + state = PARAM_NAME; + break; + } + // a parameter always needs to follow a value + if (state == PARAM_NAME) + { + String paramValue = in.sval; + // if a charset param the value needs to be stored lowercase + if (paramName.equals("charset")) + paramValue = paramValue.toLowerCase(); + + state = PARAM_VALUE; + params.put(paramName, paramValue); + break; + } + if (state == COMMENT_START) + { + // ignore; + break; + } + break; + case '/': + // may only occur after the mediatype + if (state != MEDIA) + throw new IllegalArgumentException(); + + break; + case '=': + // may only occur after a parameter + if (state != PARAM_NAME) + throw new IllegalArgumentException(); + + break; + case ';': + // differentiates mime type and parameters/value combinations + if (state != MEDIASUB && state != PARAM_VALUE) + throw new IllegalArgumentException(); + + break; + case '(': // begin comment + lastState = state; + state = COMMENT_START; + break; + case ')': // end comment + state = lastState; + break; + // a parameter always needs to follow a value / or quoted value + case '"': + if (state == PARAM_NAME) + { + String paramValue = in.sval; + // if a charset param the value needs to be stored lowercase + if (paramName.equals("charset")) + paramValue = paramValue.toLowerCase(); + + state = PARAM_VALUE; + params.put(paramName, paramValue); + break; + } + + // only values may be quoted + throw new IllegalArgumentException(); + default: + // if any other char is observed its not allowed + throw new IllegalArgumentException(); + } + } + } + catch (IOException e) + { + // should not happen as mimetype str cannot be null + throw new InternalError("IOException during parsing String " + mimeType); } - - pos = mimeType.indexOf('/'); - - if (pos == -1) - throw new IllegalArgumentException(); - - mediaType = mimeType.substring(0, pos); - mediaSubtype = mimeType.substring(pos + 1); } + /** + * Checks if this doc flavor object is equal to the given object. + * <p> + * Two doc flavor objects are considered equal if the provided object is not + * <code>null</code> and an instance of <code>DocFlavor</code>. The MIME + * types has to be equal in their media type, media subtype, their + * paramter/value combinations and the representation classname. + * </p> + * + * @param obj the object to test. + * @return <code>true</code> if equal, <code>false</code> otherwise. + */ public boolean equals(Object obj) { if (! (obj instanceof DocFlavor)) @@ -273,20 +802,39 @@ public class DocFlavor implements Cloneable, Serializable && getRepresentationClassName().equals(tmp.getRepresentationClassName())); } + /** + * Returns the media subtype of this flavor object. + * A mimetype of "text/html; charset=us-ascii" will + * return "html" as the media subtype. + * + * @return The media subtype. + */ public String getMediaSubtype() { return mediaSubtype; } + /** + * Returns the media type of this flavor object. + * A mimetype of "text/html; charset=us-ascii" will + * return "text" as the media type. + * + * @return The media type. + */ public String getMediaType() { return mediaType; } + /** + * Returns the mime type of this flavor object. + * The mimetype will have every parameter value + * enclosed in quotes. + * + * @return The mime type. + */ public String getMimeType() { - // FIXME: Check if this algorithm is correct. - String mimeType = getMediaType() + "/" + getMediaSubtype(); Iterator it = params.entrySet().iterator(); @@ -299,28 +847,69 @@ public class DocFlavor implements Cloneable, Serializable return mimeType; } + /** + * Returns the value for an optional parameter of the mime type of this + * flavor object. + * + * @param paramName the name of the parameter + * @return The value for the parameter, or <code>null</code> if none bound. + * @throws NullPointerException if paramName is <code>null</code>. + */ public String getParameter(String paramName) { if (paramName == null) throw new NullPointerException(); - return (String) params.get(paramName); + return (String) params.get(paramName.toLowerCase()); } + /** + * Returns the name of the representation class of this flavor object. + * + * @return The representation classname. + */ public String getRepresentationClassName() { - return className; + return myClassName; } + /** + * Returns a hash code for this doc flavor object. + * + * @return The hashcode. + */ public int hashCode() { return ((mediaType.hashCode() * mediaSubtype.hashCode() - * className.hashCode()) ^ params.hashCode()); + * myClassName.hashCode()) ^ params.hashCode()); } + /** + * Returns a string representation of this doc flavor object. + * The returned string is of the form + * getMimeType() + "; class=\"" + getRepresentationClassName() + "\""; + * + * @return The constructed string representation. + */ public String toString() { - return getMimeType(); + return getMimeType() + "; class=\"" + getRepresentationClassName() + "\""; + } + + // needs special treatment for serialization + private void readObject(ObjectInputStream stream) + throws IOException, ClassNotFoundException + { + params = new TreeMap(); + myClassName = (String) stream.readObject(); + parseMimeType((String) stream.readObject()); + } + + private void writeObject(java.io.ObjectOutputStream stream) + throws IOException + { + stream.writeObject(myClassName); + stream.writeObject(getMimeType()); } } diff --git a/javax/print/DocPrintJob.java b/javax/print/DocPrintJob.java index f7d361594..eec4e2afc 100644 --- a/javax/print/DocPrintJob.java +++ b/javax/print/DocPrintJob.java @@ -1,5 +1,5 @@ /* DocPrintJob.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,61 +44,105 @@ import javax.print.event.PrintJobAttributeListener; import javax.print.event.PrintJobListener; /** + * <code>DocPrintJob</code> represents a print job which supports printing + * of a single document. + * <p> + * An instance can be obtained from every <code>PrintService</code> available + * by calling the {@link javax.print.PrintService#createPrintJob()} method. + * A print job is bound to the print service it is created from. + * </p> + * * @author Michael Koch (konqueror@gmx.de) */ public interface DocPrintJob { /** - * Registers a listener for changes in the specified attributes. + * Registers a listener for changes in the specified attribute set + * during processing of this print job. + * <p> + * If the given attribute set is empty no changes will be reported. + * If the set is <code>null</code> all attributes are monitored. + * </p> * - * @param listener the listener to add - * @param attributes the attributes to observe + * @param listener the listener to register. + * @param attributes the attributes to observe. + * + * @see #removePrintJobAttributeListener(PrintJobAttributeListener) */ void addPrintJobAttributeListener(PrintJobAttributeListener listener, PrintJobAttributeSet attributes); /** - * Registers a listener for events occuring during this print job. + * Registers a listener for events occuring during processing + * of this print job. + * + * @param listener the listener to add, if <code>null</code> nothing is done. * - * @param listener the listener to add + * @see #removePrintJobListener(PrintJobListener) */ void addPrintJobListener(PrintJobListener listener); /** - * Returns the print job's attributes. + * Returns the print job's attributes. + * <p> + * The returned set of attributes is a snapshot at the time of calling this + * method and will not be updated if changes to the print job's attributes + * happens. To monitor changes register a print job listener. + * </p> * - * @return the attributes of this print job + * @return The attributes of this print job, + * may be empty but never <code>null</code>. */ PrintJobAttributeSet getAttributes(); /** * Returns the <code>PrintService</code> object this print job is bound to. * - * @return the print service + * @return The print service. */ PrintService getPrintService(); /** * Prints a document with the specified print job attributes. * + * <p> + * If the doc flavor provided by the <code>Doc</code> implementation is + * not supported by this print service a <code>PrintException</code> + * implementing the <code>FlavorException</code> interface will be thrown. + * </p> + * * @param doc the document to print - * @param attributes the attributes to use + * @param attributes the job attributes to use. If <code>null</code> the + * default attribute values of the print service will be used. + * + * @throws PrintException if an error occurs. The thrown exception may + * implement refining print exception interface to provide more detail of + * the error. * - * @throws PrintException if an error occurs + * @see AttributeException + * @see FlavorException */ void print(Doc doc, PrintRequestAttributeSet attributes) throws PrintException; /** - * De-registers an attribute listener. + * Removes the given listener from the listeners registered for changes + * in their provided attribute set during processing of this print job. * - * @param listener the listener to remove - */ + * @param listener the listener to remove, if <code>null</code> or not + * registered nothing will be done. + * + * @see #addPrintJobAttributeListener(PrintJobAttributeListener, PrintJobAttributeSet) + */ void removePrintJobAttributeListener(PrintJobAttributeListener listener); /** - * De-registers a print job listener. + * Removes the given listener from the listeners registered for events + * occuring during processing of this print job. + * + * @param listener the listener to remove, if <code>null</code> or not + * registered nothing will be done. * - * @param listener the listener to remove + * @see #addPrintJobListener(PrintJobListener) */ void removePrintJobListener(PrintJobListener listener); }
\ No newline at end of file diff --git a/javax/print/PrintService.java b/javax/print/PrintService.java index 1a9953166..125d27083 100644 --- a/javax/print/PrintService.java +++ b/javax/print/PrintService.java @@ -1,5 +1,5 @@ /* PrintService.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,14 +45,25 @@ import javax.print.attribute.PrintServiceAttributeSet; import javax.print.event.PrintServiceAttributeListener; /** + * A <code>PrintService</code> represents a printer available for printing. + * <p> + * The print service hereby may be a real physical printer device, a printer + * group with same capabilities or a logical print service (like for example + * a PDF writer). The print service is used to query the capabilities of the + * represented printer instance. If a suitable print service is found it is + * used to create a print job for the actual printing process. + * </p> + * @see javax.print.DocPrintJob + * * @author Michael Koch (konqueror@gmx.de) */ public interface PrintService { /** - * Returns a new print job capable to handle all supported document flavors. + * Creates and returns a new print job which is capable to handle all + * the document flavors supported by this print service. * - * @return the new print job + * @return The created print job object. */ DocPrintJob createPrintJob(); @@ -61,39 +72,54 @@ public interface PrintService * * @param obj the service to check against * - * @return <code>true</code> if both services refer to the sam underlying - * service, <code>false</code> otherwise + * @return <code>true</code> if both services refer to the same underlying + * service, <code>false</code> otherwise. */ boolean equals(Object obj); /** - * Returns the value of a single specified attribute. + * Returns the value of the single specified attribute. * * @param category the category of a <code>PrintServiceAttribute</code> * - * @return the value of the attribute + * @return The value of the attribute, or <code>null</code> if the attribute + * category is not supported by this print service implementation. * - * @throws NullPointerException if category is null + * @throws NullPointerException if category is <code>null</code>. * @throws IllegalArgumentException if category is not a class that - * implements <code>PrintServiceAttribute</code> + * implements <code>PrintServiceAttribute</code>. */ <T extends PrintServiceAttribute> T getAttribute(Class<T> category); /** - * Returns all attributes of this printer service - * - * @return all attributes of this print service + * Returns the attributes describing this print service. The returned + * attributes set is unmodifiable and represents the current state of + * the print service. As some print service attributes may change + * (depends on the print service implementation) a subsequent call to + * this method may return a different set. To monitor changes a + * <code>PrintServiceAttributeListener</code> may be registered. + * + * @return All the description attributes of this print service. + * @see #addPrintServiceAttributeListener(PrintServiceAttributeListener) */ PrintServiceAttributeSet getAttributes(); /** - * Returns the service's default value for a given attribute. + * Determines and returns the default value for a given attribute category + * of this print service. + * <p> + * A return value of <code>null</code> means either that the print service + * does not support the attribute category or there is no default value + * available for this category. To distinguish these two case one can test + * with {@link #isAttributeCategorySupported(Class)} if the category is + * supported. + * </p> * * @param category the category of the attribute * - * @return the default value + * @return The default value, or <code>null</code>. * - * @throws NullPointerException if <code>category</code> is null + * @throws NullPointerException if <code>category</code> is <code>null</code> * @throws IllegalArgumentException if <code>category</code> is a class * not implementing <code>Attribute</code> */ @@ -101,36 +127,50 @@ public interface PrintService /** * Returns the name of this print service. + * This may be the value of the <code>PrinterName</code> attribute. * - * @return the name + * @return The print service name. */ String getName(); /** - * Returns a factory for UI components. + * Returns a factory for UI components if supported by the print service. * - * @return the factory + * @return A factory for UI components or <code>null</code>. */ ServiceUIFactory getServiceUIFactory(); /** * Returns all supported attribute categories. * - * @return an array of all supported attribute categories + * @return The class array of all supported attribute categories. */ Class<?>[] getSupportedAttributeCategories(); /** - * Returns all supported attribute values a client can use when setting up - * a print job with this service. + * Determines and returns all supported attribute values of a given + * attribute category a client can use when setting up a print job + * for this print service. + * <p> + * The returned object may be one of the following types: + * <ul> + * <li>A single instance of the attribute category to indicate that any + * value will be supported.</li> + * <li>An array of the same type as the attribute category to test, + * containing all the supported values for this category.</li> + * <li>A single object (of any other type than the attribute category) + * which indicates bounds on the supported values.</li> + * </ul> + * </p> * * @param category the attribute category to test - * @param flavor the document flavor to use, or null - * @param attributes set of printing attributes for a supposed job, or null + * @param flavor the document flavor to use, or <code>null</code> + * @param attributes set of attributes for a supposed job, + * or <code>null</code> * - * @return object indicating supported values for <code>category</code>, - * or null if this print service doesnt support specifying doc-level or - * job-level attribute in a print request. + * @return A object (as defined above) indicating the supported values + * for the given attribute category, or <code>null</code> if this print + * service doesn't support the given attribute category at all. * * @throws NullPointerException if <code>category</code> is null * @throws IllegalArgumentException if <code>category</code> is a class not @@ -142,73 +182,101 @@ public interface PrintService AttributeSet attributes); /** - * Returns an array of all supproted document flavors. + * Determines and returns an array of all supported document flavors which + * can be used to supply print data to this print service. + * <p> + * The supported attribute categories may differ between the supported + * document flavors. To test for supported attributes one can use the + * {@link #getUnsupportedAttributes(DocFlavor, AttributeSet)} method with + * the specific doc flavor and attributes set. + * </p> * * @return the supported document flavors */ DocFlavor[] getSupportedDocFlavors(); /** - * Returns all attributes that are unsupported for a print request in the - * context of a particular document flavor. - * - * @param flavor document flavor to test, or null + * Identifies all the unsupported attributes of the given set of attributes + * in the context of the specified document flavor. + * <p> + * The given flavor has to be supported by the print service (use + * {@link #isDocFlavorSupported(DocFlavor)} to verify). The method will + * return <code>null</code> if all given attributes are supported. Otherwise + * a set of unsupported attributes are returned. The attributes in the + * returned set may be completely unsupported or only the specific requested + * value. If flavor is <code>null</code> the default document flavor of the + * print service is used in the identification process. + * </p> + * + * @param flavor document flavor to test, or <code>null</code>. * @param attributes set of printing attributes for a supposed job * - * @return null if this <code>PrintService</code> supports the print request - * specification, else the unsupported attributes + * @return <code>null</code> if this print service supports all the given + * attributes for the specified doc flavor. Otherwise the set of unsupported + * attributes are returned. * * @throws IllegalArgumentException if <code>flavor</code> is unsupported */ AttributeSet getUnsupportedAttributes(DocFlavor flavor, AttributeSet attributes); + /** - * Returns a hashcode for this printer service. + * Returns a hashcode for this print service. * - * @return the hashcode + * @return The hashcode. */ int hashCode(); /** - * Determines a given attribute category is supported or not. + * Determines a given attribute category is supported by this + * print service implementation. This only tests for the category + * not for any specific values of this category nor in the context + * of a specific document flavor. * * @param category the category to check * * @return <code>true</code> if <code>category</code> is supported, - * <code>false</code> otherwise + * <code>false</code> otherwise. * - * @throws NullPointerException if <code>category</code> is null + * @throws NullPointerException if <code>category</code> is <code>null</code> * @throws IllegalArgumentException if <code>category</code> is a class not * implementing <code>Attribute</code>. */ boolean isAttributeCategorySupported(Class<? extends Attribute> category); /** - * Determines a given attribute value is supported when creating a print job - * for this print service. + * Determines if a given attribute value is supported when creating a print + * job for this print service. + * <p> + * If either the document flavor or the provided attributes are + * <code>null</code> it is determined if the given attribute value is + * supported in some combination of the available document flavors and + * attributes of the print service. Otherwise it is checked for the + * specific context of the given document flavor/attributes set. + * </p> * * @param attrval the attribute value to check - * @param flavor the document flavor to use, or null - * @param attributes set of printing attributes to use, or null + * @param flavor the document flavor to use, or <code>null</code>. + * @param attributes set of attributes to use, or <code>null</code>. * - * @return <code>true</code> if the attribute value is supported, - * <code>false</code> otherwise + * @return <code>true</code> if the attribute value is supported in the + * requested context, <code>false</code> otherwise. * - * @throws NullPointerException if <code>attrval</code> is null + * @throws NullPointerException if <code>attrval</code> is <code>null</code>. * @throws IllegalArgumentException if <code>flavor</code> is not supported * by this print service */ boolean isAttributeValueSupported(Attribute attrval, DocFlavor flavor, AttributeSet attributes); /** - * Determines a given document flavor is supported or not. + * Determines if a given document flavor is supported or not. * * @param flavor the document flavor to check * * @return <code>true</code> if <code>flavor</code> is supported, - * <code>false</code> otherwise + * <code>false</code> otherwise. * - * @throws NullPointerException if <code>flavor</code> is null + * @throws NullPointerException if <code>flavor</code> is null. */ boolean isDocFlavorSupported(DocFlavor flavor); diff --git a/javax/print/SimpleDoc.java b/javax/print/SimpleDoc.java new file mode 100644 index 000000000..a49406bcb --- /dev/null +++ b/javax/print/SimpleDoc.java @@ -0,0 +1,223 @@ +/* SimpleDoc.java -- + Copyright (C) 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. */ + + +package javax.print; + +import java.io.ByteArrayInputStream; +import java.io.CharArrayReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.io.StringReader; + +import javax.print.attribute.AttributeSetUtilities; +import javax.print.attribute.DocAttributeSet; + +/** + * Simple implementation of the <code>Doc</code> interface capable of handling + * the predefined document flavors of <code>DocFlavor</code>. + * <p> + * This implementation can construct a reader or stream for the service from + * the print data and ensures that always the same object is returned on each + * method call. It does simple checks that the supplied data matches the + * specified flavor of the doc object and supports thread safe access. + * </p> + * + * @author Wolfgang Baer (WBaer@gmx.de) + */ +public final class SimpleDoc implements Doc +{ + private final Object printData; + private final DocFlavor flavor; + private final DocAttributeSet attributes; + + private InputStream stream; + private Reader reader; + + /** + * Constructs a SimpleDoc with the specified print data, doc flavor and doc attribute set. + * @param printData the object with the data to print. + * @param flavor the document flavor of the print data. + * @param attributes the attributes of the doc (may be <code>null</code>). + * + * @throws IllegalArgumentException if either <code>printData</code> or + * <code>flavor</code> are <code>null</code>, or the print data is not + * supplied in the document format specified by the given flavor object. + */ + public SimpleDoc(Object printData, DocFlavor flavor, + DocAttributeSet attributes) + { + if (printData == null || flavor == null) + throw new IllegalArgumentException("printData/flavor may not be null"); + + if (! (printData.getClass().getName().equals( + flavor.getRepresentationClassName()) + || flavor.getRepresentationClassName().equals("java.io.Reader") + && printData instanceof Reader + || flavor.getRepresentationClassName().equals("java.io.InputStream") + && printData instanceof InputStream)) + { + throw new IllegalArgumentException("data is not of declared flavor type"); + } + + this.printData = printData; + this.flavor = flavor; + + if (attributes != null) + this.attributes = AttributeSetUtilities.unmodifiableView(attributes); + else + this.attributes = null; + + stream = null; + reader = null; + } + + /** + * Returns the unmodifiable view of the attributes of this doc object. + * <p> + * The attributes of this doc's attributes set overrides attributes of + * the same category in the print job's attribute set. If an attribute + * is not available in this doc's attributes set or <code>null</code> + * is returned the attributes of the same category of the print job are + * used. + * </p> + * + * @return The unmodifiable attributes set, or <code>null</code>. + */ + public DocAttributeSet getAttributes() + { + return attributes; + } + + /** + * Returns the flavor of this doc objects print data. + * + * @return The document flavor. + */ + public DocFlavor getDocFlavor() + { + return flavor; + } + + /** + * Returns the print data of this doc object. + * <p> + * The returned object is an instance as described by the associated + * document flavor ({@link DocFlavor#getRepresentationClassName()}) + * and can be cast to this representation class. + * </p> + * + * @return The print data in the representation class. + * @throws IOException if representation class is a stream and I/O + * exception occures. + */ + public Object getPrintData() throws IOException + { + return printData; + } + + /** + * Returns a <code>Reader</code> object for extracting character print data + * from this document. + * <p> + * This method is supported if the document flavor is of type: + * <ul> + * <li><code>char[]</code></li> + * <li><code>java.lang.String</code></li> + * <li><code>java.io.Reader</code></li> + * </ul> + * otherwise this method returns <code>null</code>. + * </p> + * + * @return The <code>Reader</code> object, or <code>null</code>. + * + * @throws IOException if an error occurs. + */ + public Reader getReaderForText() throws IOException + { + synchronized (this) + { + // construct the reader if applicable on request + if (reader == null) + { + if (flavor instanceof DocFlavor.CHAR_ARRAY) + reader = new CharArrayReader((char[]) printData); + else if (flavor instanceof DocFlavor.STRING) + reader = new StringReader((String) printData); + else if (flavor instanceof DocFlavor.READER) + reader = (Reader) printData; + } + + return reader; + } + } + + /** + * Returns an <code>InputStream</code> object for extracting byte print data + * from this document. + * <p> + * This method is supported if the document flavor is of type: + * <ul> + * <li><code>byte[]</code></li> + * <li><code>java.io.InputStream</code></li> + * </ul> + * otherwise this method returns <code>null</code>. + * </p> + * + * @return The <code>InputStream</code> object, or <code>null</code>. + * + * @throws IOException if an error occurs. + */ + public InputStream getStreamForBytes() throws IOException + { + synchronized (this) + { + // construct the stream if applicable on request + if (stream == null) + { + if (flavor instanceof DocFlavor.BYTE_ARRAY) + stream = new ByteArrayInputStream((byte[]) printData); + else if (flavor instanceof DocFlavor.INPUT_STREAM) + stream = (InputStream) printData; + } + + return stream; + } + } + +} diff --git a/javax/print/StreamPrintService.java b/javax/print/StreamPrintService.java index 9246ea47e..8398a734c 100644 --- a/javax/print/StreamPrintService.java +++ b/javax/print/StreamPrintService.java @@ -1,5 +1,5 @@ /* StreamPrintService.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,6 +42,15 @@ import java.io.OutputStream; /** + * <code>StreamPrintService</code> is a special print service capable of + * printing into a supplied output stream. + * <p> + * Beside providing the same functionality as a print service it additionally + * allows to specify the output stream for the print data. A stream print + * service is obtained via the {@link javax.print.StreamPrintServiceFactory} + * by looking for services supporting a given output format type. + * </p> + * * @author Michael Koch (konqueror@gmx.de) */ public abstract class StreamPrintService implements PrintService @@ -68,16 +77,18 @@ public abstract class StreamPrintService implements PrintService } /** - * Returns the document format emited by this print service. + * Returns the document format emitted by this print service. + * The returned string is a MIME type compatible with the + * {@link DocFlavor} class. * - * @return the document format + * @return The document format of the output. */ public abstract String getOutputFormat(); /** * Returns the <code>OutputStream</code> of this object. * - * @return the <code>OutputStream</code> + * @return The <code>OutputStream</code> */ public OutputStream getOutputStream() { diff --git a/javax/print/StreamPrintServiceFactory.java b/javax/print/StreamPrintServiceFactory.java new file mode 100644 index 000000000..90496b36a --- /dev/null +++ b/javax/print/StreamPrintServiceFactory.java @@ -0,0 +1,130 @@ +/* StreamPrintServiceFactory.java -- + Copyright (C) 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. */ + + +package javax.print; + +import gnu.classpath.ServiceFactory; + +import java.io.OutputStream; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; + +/** + * <code>StreamPrintServiceFactory</code> provides a static method to lookup + * registered factories to construct <code>StreamPrintService</code> instances. + * <p> + * <code>StreamPrintService</code> are used to print into a provided output + * stream in the document format provided by the stream print service + * implementation. + * </p><p> + * Implementations are located and loaded automatically through the SPI JAR + * file specification. Therefore implementation classes must provide a default + * constructor for instantiation. + * </p> + * + * @author Wolfgang Baer (WBaer@gmx.de) + */ +public abstract class StreamPrintServiceFactory +{ + /** + * Default public constructor. + * Used for automatic loading and instantiation through + * the SPI jar file specification. + */ + public StreamPrintServiceFactory() + { + // nothing to do + } + + /** + * Searches for matching factories providing stream print services that + * support the printing of documents with the given document flavor into + * the given output mime type. + * + * @param flavor the document flavor needed, <code>null</code> doesn't + * constrain the lookup result. + * @param outputMimeType the mime type needed, <code>null</code> doesn't + * constrain the lookup result. + * + * @return The matching <code>StreamPrintServiceFactory</code> instances. + */ + public static StreamPrintServiceFactory[] lookupStreamPrintServiceFactories( + DocFlavor flavor, String outputMimeType) + { + HashSet set = new HashSet(); + + Iterator it = + ServiceFactory.lookupProviders(StreamPrintServiceFactory.class); + + while (it.hasNext()) + { + StreamPrintServiceFactory tmp = (StreamPrintServiceFactory) it.next(); + if (tmp.getOutputFormat().equals(outputMimeType) + && Arrays.asList(tmp.getSupportedDocFlavors()).contains(flavor)) + set.add(tmp); + } + + StreamPrintServiceFactory[] tmp = new StreamPrintServiceFactory[set.size()]; + return (StreamPrintServiceFactory[]) set.toArray(tmp); + } + + /** + * Returns the output format supported by this factory. + * + * @return The mime type of the output format as string representation. + */ + public abstract String getOutputFormat(); + + /** + * Returns the document flavors this factory supports as flavors + * for the input documents. + * + * @return The array of supported document flavors. + */ + public abstract DocFlavor[] getSupportedDocFlavors(); + + /** + * Constructs a <code>StreamPrintService</code> which directs its output + * the given output stream. + * + * @param out the output stream for the produced document. + * @return The constructed stream print service. + */ + public abstract StreamPrintService getPrintService(OutputStream out); +} diff --git a/javax/print/attribute/AttributeSetUtilities.java b/javax/print/attribute/AttributeSetUtilities.java index 95b4cc553..95c11a6ed 100644 --- a/javax/print/attribute/AttributeSetUtilities.java +++ b/javax/print/attribute/AttributeSetUtilities.java @@ -1,5 +1,5 @@ /* AttributeSetUtilities.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -78,14 +78,14 @@ public final class AttributeSetUtilities private static class UnmodifiableAttributeSet implements AttributeSet, Serializable { - private AttributeSet set; + private AttributeSet attrset; public UnmodifiableAttributeSet(AttributeSet attributeSet) { if (attributeSet == null) throw new NullPointerException("attributeSet may not be null"); - this.set = attributeSet; + this.attrset = attributeSet; } public boolean add(Attribute attribute) @@ -105,32 +105,32 @@ public final class AttributeSetUtilities public boolean containsKey(Class category) { - return set.containsKey(category); + return attrset.containsKey(category); } public boolean containsValue(Attribute attribute) { - return set.containsValue(attribute); + return attrset.containsValue(attribute); } public boolean equals(Object obj) { - return set.equals(obj); + return attrset.equals(obj); } public Attribute get(Class interfaceName) { - return set.get(interfaceName); + return attrset.get(interfaceName); } public int hashCode() { - return set.hashCode(); + return attrset.hashCode(); } public boolean isEmpty() { - return set.isEmpty(); + return attrset.isEmpty(); } public boolean remove(Class category) @@ -145,12 +145,12 @@ public final class AttributeSetUtilities public int size() { - return set.size(); + return attrset.size(); } public Attribute[] toArray() { - return set.toArray(); + return attrset.toArray(); } } @@ -197,79 +197,79 @@ public final class AttributeSetUtilities private static class SynchronizedAttributeSet implements AttributeSet, Serializable { - private AttributeSet set; + private AttributeSet attrset; public SynchronizedAttributeSet(AttributeSet attributeSet) { if (attributeSet == null) throw new NullPointerException("attributeSet may not be null"); - this.set = attributeSet; + attrset = attributeSet; } public synchronized boolean add(Attribute attribute) { - return set.add(attribute); + return attrset.add(attribute); } public synchronized boolean addAll(AttributeSet attributes) { - return set.addAll(attributes); + return attrset.addAll(attributes); } public synchronized void clear() { - set.clear(); + attrset.clear(); } public synchronized boolean containsKey(Class category) { - return set.containsKey(category); + return attrset.containsKey(category); } public synchronized boolean containsValue(Attribute attribute) { - return set.containsValue(attribute); + return attrset.containsValue(attribute); } public synchronized boolean equals(Object obj) { - return set.equals(obj); + return attrset.equals(obj); } public synchronized Attribute get(Class interfaceName) { - return set.get(interfaceName); + return attrset.get(interfaceName); } public synchronized int hashCode() { - return set.hashCode(); + return attrset.hashCode(); } public synchronized boolean isEmpty() { - return set.isEmpty(); + return attrset.isEmpty(); } public synchronized boolean remove(Class category) { - return set.remove(category); + return attrset.remove(category); } public synchronized boolean remove(Attribute attribute) { - return set.remove(attribute); + return attrset.remove(attribute); } public synchronized int size() { - return set.size(); + return attrset.size(); } public synchronized Attribute[] toArray() { - return set.toArray(); + return attrset.toArray(); } } diff --git a/javax/print/attribute/DateTimeSyntax.java b/javax/print/attribute/DateTimeSyntax.java index d59193265..8cff70219 100644 --- a/javax/print/attribute/DateTimeSyntax.java +++ b/javax/print/attribute/DateTimeSyntax.java @@ -102,4 +102,14 @@ public abstract class DateTimeSyntax implements Cloneable, Serializable { return value.hashCode(); } + + /** + * Returns the string representation for this object. + * + * @return The string representation. + */ + public String toString() + { + return value.toString(); + } } diff --git a/javax/print/attribute/HashAttributeSet.java b/javax/print/attribute/HashAttributeSet.java index cdf333a27..0f6b00730 100644 --- a/javax/print/attribute/HashAttributeSet.java +++ b/javax/print/attribute/HashAttributeSet.java @@ -1,5 +1,5 @@ /* HashAttributeSet.java -- - Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,6 +37,9 @@ exception statement from your version. */ package javax.print.attribute; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.HashMap; import java.util.Iterator; @@ -49,8 +52,8 @@ public class HashAttributeSet implements AttributeSet, Serializable { private static final long serialVersionUID = 5311560590283707917L; - private Class interfaceName; - private HashMap attributeMap = new HashMap(); + private Class myInterface; + private transient HashMap attributeMap = new HashMap(); /** * Creates an empty <code>HashAttributeSet</code> object. @@ -112,7 +115,7 @@ public class HashAttributeSet implements AttributeSet, Serializable if (interfaceName == null) throw new NullPointerException("interfaceName may not be null"); - this.interfaceName = interfaceName; + myInterface = interfaceName; } /** @@ -192,7 +195,7 @@ public class HashAttributeSet implements AttributeSet, Serializable */ public boolean add(Attribute attribute) { - return addInternal(attribute, interfaceName); + return addInternal(attribute, myInterface); } private boolean addInternal(Attribute attribute, Class interfaceName) @@ -201,7 +204,7 @@ public class HashAttributeSet implements AttributeSet, Serializable throw new NullPointerException("attribute may not be null"); AttributeSetUtilities.verifyAttributeCategory(interfaceName, - this.interfaceName); + myInterface); Object old = attributeMap.put (attribute.getCategory(), AttributeSetUtilities.verifyAttributeValue @@ -220,7 +223,7 @@ public class HashAttributeSet implements AttributeSet, Serializable */ public boolean addAll(AttributeSet attributes) { - return addAllInternal(attributes, interfaceName); + return addAllInternal(attributes, myInterface); } private boolean addAllInternal(AttributeSet attributes, Class interfaceName) @@ -393,4 +396,24 @@ public class HashAttributeSet implements AttributeSet, Serializable return array; } + + // Implemented as specified in serialized form + private void readObject(ObjectInputStream s) + throws ClassNotFoundException, IOException + { + myInterface = (Class) s.readObject(); + int size = s.readInt(); + attributeMap = new HashMap(size); + for (int i=0; i < size; i++) + add((Attribute) s.readObject()); + } + + private void writeObject(ObjectOutputStream s) throws IOException + { + s.writeObject(myInterface); + s.writeInt(size()); + Iterator it = attributeMap.values().iterator(); + while (it.hasNext()) + s.writeObject(it.next()); + } } diff --git a/javax/print/attribute/standard/Compression.java b/javax/print/attribute/standard/Compression.java index 388281216..f2f4f1cc1 100644 --- a/javax/print/attribute/standard/Compression.java +++ b/javax/print/attribute/standard/Compression.java @@ -1,5 +1,5 @@ /* Compression.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -102,7 +102,7 @@ public class Compression extends EnumSyntax * * @return The name "compression". */ - public String getName() + public final String getName() { return "compression"; } diff --git a/javax/print/attribute/standard/Finishings.java b/javax/print/attribute/standard/Finishings.java index 78ca3f454..cd8f6753b 100644 --- a/javax/print/attribute/standard/Finishings.java +++ b/javax/print/attribute/standard/Finishings.java @@ -1,5 +1,5 @@ /* Finishings.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -249,7 +249,7 @@ public class Finishings extends EnumSyntax * * @return The name "finishings". */ - public String getName() + public final String getName() { return "finishings"; } diff --git a/javax/print/attribute/standard/JobMediaSheets.java b/javax/print/attribute/standard/JobMediaSheets.java index 2b5e12d24..17cf96f33 100644 --- a/javax/print/attribute/standard/JobMediaSheets.java +++ b/javax/print/attribute/standard/JobMediaSheets.java @@ -1,5 +1,5 @@ /* JobMediaSheets.java -- - Copyright (C) 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 2003, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -118,7 +118,7 @@ public class JobMediaSheets extends IntegerSyntax * * @return The name "job-media-sheets". */ - public String getName() + public final String getName() { return "job-media-sheets"; } diff --git a/javax/print/attribute/standard/JobSheets.java b/javax/print/attribute/standard/JobSheets.java index 59460ab25..a930f63cf 100644 --- a/javax/print/attribute/standard/JobSheets.java +++ b/javax/print/attribute/standard/JobSheets.java @@ -1,5 +1,5 @@ /* JobSheets.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -99,7 +99,7 @@ public class JobSheets extends EnumSyntax * * @return The name "job-sheets". */ - public String getName() + public final String getName() { return "job-sheets"; } diff --git a/javax/print/attribute/standard/JobState.java b/javax/print/attribute/standard/JobState.java index 8304b8b30..fa769bbf3 100644 --- a/javax/print/attribute/standard/JobState.java +++ b/javax/print/attribute/standard/JobState.java @@ -1,5 +1,5 @@ /* JobState.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -148,7 +148,7 @@ public class JobState extends EnumSyntax * * @return The name "job-state". */ - public String getName() + public final String getName() { return "job-state"; } diff --git a/javax/print/attribute/standard/JobStateReason.java b/javax/print/attribute/standard/JobStateReason.java index 3981d94a2..b8420b180 100644 --- a/javax/print/attribute/standard/JobStateReason.java +++ b/javax/print/attribute/standard/JobStateReason.java @@ -1,5 +1,5 @@ /* JobStateReason.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -272,7 +272,7 @@ public class JobStateReason extends EnumSyntax * * @return The name "job-state-reason". */ - public String getName() + public final String getName() { return "job-state-reason"; } diff --git a/javax/print/attribute/standard/Media.java b/javax/print/attribute/standard/Media.java index 5ac204bf6..4c0af0ed1 100644 --- a/javax/print/attribute/standard/Media.java +++ b/javax/print/attribute/standard/Media.java @@ -1,5 +1,5 @@ /* Media.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -116,7 +116,7 @@ public abstract class Media extends EnumSyntax * * @return The name "media". */ - public String getName() + public final String getName() { return "media"; } diff --git a/javax/print/attribute/standard/MediaPrintableArea.java b/javax/print/attribute/standard/MediaPrintableArea.java index 6ef0de109..84ebd61ce 100644 --- a/javax/print/attribute/standard/MediaPrintableArea.java +++ b/javax/print/attribute/standard/MediaPrintableArea.java @@ -1,5 +1,5 @@ /* MediaPrintableArea.java -- - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -96,9 +96,9 @@ public final class MediaPrintableArea /** y in micrometers. */ private int y; /** width in micrometers. */ - private int width; + private int w; /** height in micrometers. */ - private int height; + private int h; /** * Creates a new <code>MediaPrintableArea</code> object with the given @@ -120,8 +120,8 @@ public final class MediaPrintableArea this.x = (int) (x * units + 0.5f); this.y = (int) (y * units + 0.5f); - this.width = (int) (w * units + 0.5f); - this.height = (int) (h * units + 0.5f); + this.w = (int) (w * units + 0.5f); + this.h = (int) (h * units + 0.5f); } /** @@ -144,8 +144,8 @@ public final class MediaPrintableArea this.x = x * units; this.y = y * units; - this.width = w * units; - this.height = h * units; + this.w = w * units; + this.h = h * units; } /** @@ -181,7 +181,7 @@ public final class MediaPrintableArea if (units < 1) throw new IllegalArgumentException("units may not be less than 1"); - return height / ((float)units); + return h / ((float)units); } /** @@ -197,7 +197,7 @@ public final class MediaPrintableArea if (units < 1) throw new IllegalArgumentException("units may not be less than 1"); - return width / ((float)units); + return w / ((float)units); } /** @@ -249,7 +249,7 @@ public final class MediaPrintableArea MediaPrintableArea tmp = (MediaPrintableArea) obj; return (x == tmp.getX(1) && y == tmp.getY(1) - && width == tmp.getWidth(1) && height == tmp.getHeight(1)); + && w == tmp.getWidth(1) && h == tmp.getHeight(1)); } /** @@ -271,7 +271,7 @@ public final class MediaPrintableArea */ public int hashCode() { - return x ^ y + width ^ height; + return x ^ y + w ^ h; } /** diff --git a/javax/print/attribute/standard/MediaSize.java b/javax/print/attribute/standard/MediaSize.java index bf17d3cd3..be3f15678 100644 --- a/javax/print/attribute/standard/MediaSize.java +++ b/javax/print/attribute/standard/MediaSize.java @@ -1,5 +1,5 @@ /* MediaSize.java -- - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -73,6 +73,13 @@ public class MediaSize extends Size2DSyntax { mediaCache = new ArrayList<MediaSize>(); + // We call one instance of every container class to make sure it gets + // loaded during class initialization and therefore all other static + // fields of this container class also. + + // This is needed to put all MediaSize instance into the mediaCache + // for use by the static methods in this class. + MediaSize tmp = MediaSize.ISO.A0; tmp = MediaSize.JIS.B0; tmp = MediaSize.Engineering.A; @@ -80,16 +87,21 @@ public class MediaSize extends Size2DSyntax tmp = MediaSize.Other.EXECUTIVE; } - private MediaSizeName media; + private MediaSizeName mediaName; /** - * Creates a <code>MediaSize</code> object. + * Creates a <code>MediaSize</code> object. The created object will be added + * to an internal cache used in the static methods of this class for lookup + * of available <code>MediaSize</code> instances. * * @param x the size in x direction * @param y the size in y direction * @param units the units to use for the sizes * * @exception IllegalArgumentException if x or y < 0 or units < 1 + * + * @see #findMedia(float, float, int) + * @see #getMediaSizeForName(MediaSizeName) */ public MediaSize(float x, float y, int units) { @@ -99,7 +111,9 @@ public class MediaSize extends Size2DSyntax /** * Creates a <code>MediaSize</code> object associated with the given - * media name. + * media name. The created object will be added to an internal cache used + * in the static methods of this class for lookup of available + * <code>MediaSize</code> instances. * * @param x the size in x direction * @param y the size in y direction @@ -107,22 +121,30 @@ public class MediaSize extends Size2DSyntax * @param media the media name to associate * * @exception IllegalArgumentException if x or y < 0 or units < 1 + * + * @see #findMedia(float, float, int) + * @see #getMediaSizeForName(MediaSizeName) */ public MediaSize(float x, float y, int units, MediaSizeName media) { super(x, y, units); - this.media = media; + mediaName = media; mediaCache.add(this); } /** - * Creates a <code>MediaSize</code> object. + * Creates a <code>MediaSize</code> object. The created object will be added + * to an internal cache used in the static methods of this class for lookup + * of available <code>MediaSize</code> instances. * * @param x the size in x direction * @param y the size in y direction * @param units the units to use for the sizes * * @exception IllegalArgumentException if x or y < 0 or units < 1 + * + * @see #findMedia(float, float, int) + * @see #getMediaSizeForName(MediaSizeName) */ public MediaSize(int x, int y, int units) { @@ -132,7 +154,9 @@ public class MediaSize extends Size2DSyntax /** * Creates a <code>MediaSize</code> object associated with the given - * media name. + * media name. The created object will be added to an internal cache used + * in the static methods of this class for lookup of available + * <code>MediaSize</code> instances. * * @param x the size in x direction * @param y the size in y direction @@ -140,11 +164,14 @@ public class MediaSize extends Size2DSyntax * @param media the media name to associate * * @exception IllegalArgumentException if x or y < 0 or units < 1 + * + * @see #findMedia(float, float, int) + * @see #getMediaSizeForName(MediaSizeName) */ public MediaSize(int x, int y, int units, MediaSizeName media) { super(x, y, units); - this.media = media; + mediaName = media; mediaCache.add(this); } @@ -247,7 +274,7 @@ public class MediaSize extends Size2DSyntax */ public MediaSizeName getMediaSizeName() { - return media; + return mediaName; } /** @@ -255,7 +282,7 @@ public class MediaSize extends Size2DSyntax * * @return The name "media-size". */ - public String getName() + public final String getName() { return "media-size"; } @@ -267,7 +294,11 @@ public class MediaSize extends Size2DSyntax */ public static final class ISO { - + private ISO() + { + // prevent instantiation + } + /** * ISO A0 paper, 841 mm x 1189 mm. */ @@ -416,6 +447,11 @@ public class MediaSize extends Size2DSyntax */ public static final class NA { + private NA() + { + // prevent instantiation + } + /** * US Legal paper size, 8.5 inch x 14 inch */ @@ -531,6 +567,11 @@ public class MediaSize extends Size2DSyntax */ public static final class Engineering { + private Engineering() + { + // prevent instantiation + } + /** * ANSI A paper size. 8.5 inch x 11 inch */ @@ -569,6 +610,11 @@ public class MediaSize extends Size2DSyntax */ public static final class JIS { + private JIS() + { + // prevent instantiation + } + /** * JIS B0 paper. 1030 mm x 1456 mm * Note: The JIS B-series is not identical to the ISO B-series. @@ -763,6 +809,11 @@ public class MediaSize extends Size2DSyntax */ public static final class Other { + private Other() + { + // prevent instantiation + } + /** * US Executive paper size, 7.25 inch x 10.5 inch */ @@ -821,6 +872,13 @@ public class MediaSize extends Size2DSyntax * Japanese double postcard, 148 mm x 200 mm */ public static final MediaSize JAPANESE_DOUBLE_POSTCARD = new MediaSize(148, 200, MediaSize.MM, MediaSizeName.JAPANESE_DOUBLE_POSTCARD); + + /** + * Tabloid size, 11 inch x 17 inch. + * @since 1.5 + */ + public static final MediaSize TABLOID = + new MediaSize(11, 17, Size2DSyntax.INCH, MediaSizeName.TABLOID); } } diff --git a/javax/print/attribute/standard/MultipleDocumentHandling.java b/javax/print/attribute/standard/MultipleDocumentHandling.java index 4da904398..3ee1b4126 100644 --- a/javax/print/attribute/standard/MultipleDocumentHandling.java +++ b/javax/print/attribute/standard/MultipleDocumentHandling.java @@ -1,5 +1,5 @@ /* MultipleDocumentHandling.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -119,7 +119,7 @@ public class MultipleDocumentHandling extends EnumSyntax * * @return The name "multiple-document-handling". */ - public String getName() + public final String getName() { return "multiple-document-handling"; } diff --git a/javax/print/attribute/standard/PDLOverrideSupported.java b/javax/print/attribute/standard/PDLOverrideSupported.java index 6e5ab11d4..02c9c198c 100644 --- a/javax/print/attribute/standard/PDLOverrideSupported.java +++ b/javax/print/attribute/standard/PDLOverrideSupported.java @@ -1,5 +1,5 @@ /* PDLOverrideSupported.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -102,7 +102,7 @@ public class PDLOverrideSupported extends EnumSyntax * * @return The name "pdl-override-supported". */ - public String getName() + public final String getName() { return "pdl-override-supported"; } diff --git a/javax/print/attribute/standard/PrintQuality.java b/javax/print/attribute/standard/PrintQuality.java index af7ec8f50..bc94d532b 100644 --- a/javax/print/attribute/standard/PrintQuality.java +++ b/javax/print/attribute/standard/PrintQuality.java @@ -1,5 +1,5 @@ /* PrintQuality.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -103,7 +103,7 @@ public class PrintQuality extends EnumSyntax * * @return The name "print-quality". */ - public String getName() + public final String getName() { return "print-quality"; } diff --git a/javax/print/attribute/standard/PrinterIsAcceptingJobs.java b/javax/print/attribute/standard/PrinterIsAcceptingJobs.java index d87bf784e..1c9c39930 100644 --- a/javax/print/attribute/standard/PrinterIsAcceptingJobs.java +++ b/javax/print/attribute/standard/PrinterIsAcceptingJobs.java @@ -56,7 +56,7 @@ import javax.print.attribute.PrintServiceAttribute; * @author Michael Koch (konqueror@gmx.de) * @author Wolfgang Baer (WBaer@gmx.de) */ -public class PrinterIsAcceptingJobs extends EnumSyntax +public final class PrinterIsAcceptingJobs extends EnumSyntax implements PrintServiceAttribute { private static final long serialVersionUID = -5052010680537678061L; diff --git a/javax/print/attribute/standard/PrinterStateReason.java b/javax/print/attribute/standard/PrinterStateReason.java index 754e448ce..1abb7c6aa 100644 --- a/javax/print/attribute/standard/PrinterStateReason.java +++ b/javax/print/attribute/standard/PrinterStateReason.java @@ -1,5 +1,5 @@ /* PrinterStateReason.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -303,7 +303,7 @@ public class PrinterStateReason extends EnumSyntax * * @return The name "printer-state-reason". */ - public String getName() + public final String getName() { return "printer-state-reason"; } diff --git a/javax/print/attribute/standard/PrinterStateReasons.java b/javax/print/attribute/standard/PrinterStateReasons.java index d8e9f9fc1..c58dd5379 100644 --- a/javax/print/attribute/standard/PrinterStateReasons.java +++ b/javax/print/attribute/standard/PrinterStateReasons.java @@ -178,7 +178,7 @@ public final class PrinterStateReasons if (severity == null) throw new NullPointerException("severity is null"); - return put((PrinterStateReason) reason, (Severity) severity); + return super.put((PrinterStateReason) reason, (Severity) severity); } /** diff --git a/javax/print/attribute/standard/ReferenceUriSchemesSupported.java b/javax/print/attribute/standard/ReferenceUriSchemesSupported.java index 59afa667a..9d2354bd6 100644 --- a/javax/print/attribute/standard/ReferenceUriSchemesSupported.java +++ b/javax/print/attribute/standard/ReferenceUriSchemesSupported.java @@ -1,5 +1,5 @@ /* ReferenceUriSchemesSupported.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -138,7 +138,7 @@ public class ReferenceUriSchemesSupported extends EnumSyntax * * @return The name "reference-uri-schemes-supported". */ - public String getName() + public final String getName() { return "reference-uri-schemes-supported"; } |