001 /* Doc.java --
002 Copyright (C) 2004, 2006 Free Software Foundation, Inc.
003
004 This file is part of GNU Classpath.
005
006 GNU Classpath is free software; you can redistribute it and/or modify
007 it under the terms of the GNU General Public License as published by
008 the Free Software Foundation; either version 2, or (at your option)
009 any later version.
010
011 GNU Classpath is distributed in the hope that it will be useful, but
012 WITHOUT ANY WARRANTY; without even the implied warranty of
013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 General Public License for more details.
015
016 You should have received a copy of the GNU General Public License
017 along with GNU Classpath; see the file COPYING. If not, write to the
018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019 02110-1301 USA.
020
021 Linking this library statically or dynamically with other modules is
022 making a combined work based on this library. Thus, the terms and
023 conditions of the GNU General Public License cover the whole
024 combination.
025
026 As a special exception, the copyright holders of this library give you
027 permission to link this library with independent modules to produce an
028 executable, regardless of the license terms of these independent
029 modules, and to copy and distribute the resulting executable under
030 terms of your choice, provided that you also meet, for each linked
031 independent module, the terms and conditions of the license of that
032 module. An independent module is a module which is not derived from
033 or based on this library. If you modify this library, you may extend
034 this exception to your version of the library, but you are not
035 obligated to do so. If you do not wish to do so, delete this
036 exception statement from your version. */
037
038
039 package javax.print;
040
041 import java.io.IOException;
042 import java.io.InputStream;
043 import java.io.Reader;
044
045 import javax.print.attribute.DocAttributeSet;
046
047 /**
048 * <code>Doc</code> specifies the interface for print services how to obtain
049 * the print data and document specific attributes for printing.
050 * <p>
051 * The print data is always passed to a {@link javax.print.DocPrintJob} object
052 * as a <code>Doc</code> object which allows the print services to:
053 * <ul>
054 * <li>Determine the actual document format of the supplied print data. This
055 * is supplied as a {@link javax.print.DocFlavor} object with the MIME type
056 * and the representation class of the print data.</li>
057 * <li>Obtain the print data either in its representation class or depending
058 * on the document format through convenience methods as a
059 * {@link java.io.Reader} or an {@link java.io.InputStream}.</li>
060 * <li>Obtain the document's attribute set specifying the attributes which
061 * apply to this document instance.</li>
062 * </ul>
063 * </p><p>
064 * Every method of a <code>Doc</code> implementation has to return always the
065 * same object on every method call. Therefore if the print job consumes the
066 * print data via a stream or a reader object it can read only once the
067 * supplied print data. Implementations of this interface have to be thread
068 * safe.
069 * </p>
070 *
071 * @author Michael Koch (konqueror@gmx.de)
072 */
073 public interface Doc
074 {
075 /**
076 * Returns the unmodifiable view of the attributes of this doc object.
077 * <p>
078 * The attributes of this doc's attributes set overrides attributes of
079 * the same category in the print job's attribute set. If an attribute
080 * is not available in this doc's attributes set or <code>null</code>
081 * is returned the attributes of the same category of the print job are
082 * used.
083 * </p>
084 *
085 * @return The unmodifiable attributes set, or <code>null</code>.
086 */
087 DocAttributeSet getAttributes();
088
089 /**
090 * Returns the flavor of this doc objects print data.
091 *
092 * @return The document flavor.
093 */
094 DocFlavor getDocFlavor();
095
096 /**
097 * Returns the print data of this doc object.
098 * <p>
099 * The returned object is an instance as described by the associated
100 * document flavor ({@link DocFlavor#getRepresentationClassName()})
101 * and can be cast to this representation class.
102 * </p>
103 *
104 * @return The print data in the representation class.
105 * @throws IOException if representation class is a stream and I/O
106 * exception occures.
107 */
108 Object getPrintData() throws IOException;
109
110 /**
111 * Returns a <code>Reader</code> object for extracting character print data
112 * from this document.
113 * <p>
114 * This method is supported if the document flavor is of type:
115 * <ul>
116 * <li><code>char[]</code></li>
117 * <li><code>java.lang.String</code></li>
118 * <li><code>java.io.Reader</code></li>
119 * </ul>
120 * otherwise this method returns <code>null</code>.
121 * </p>
122 *
123 * @return The <code>Reader</code> object, or <code>null</code>.
124 *
125 * @throws IOException if an error occurs.
126 */
127 Reader getReaderForText() throws IOException;
128
129 /**
130 * Returns an <code>InputStream</code> object for extracting byte print data
131 * from this document.
132 * <p>
133 * This method is supported if the document flavor is of type:
134 * <ul>
135 * <li><code>byte[]</code></li>
136 * <li><code>java.io.InputStream</code></li>
137 * </ul>
138 * otherwise this method returns <code>null</code>.
139 * </p>
140 *
141 * @return The <code>InputStream</code> object, or <code>null</code>.
142 *
143 * @throws IOException if an error occurs.
144 */
145 InputStream getStreamForBytes() throws IOException;
146 }