Doc.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* Doc.java --
  2. Copyright (C) 2004, 2006 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.print;
  32. import java.io.IOException;
  33. import java.io.InputStream;
  34. import java.io.Reader;
  35. import javax.print.attribute.DocAttributeSet;
  36. /**
  37. * <code>Doc</code> specifies the interface for print services how to obtain
  38. * the print data and document specific attributes for printing.
  39. * <p>
  40. * The print data is always passed to a {@link javax.print.DocPrintJob} object
  41. * as a <code>Doc</code> object which allows the print services to:
  42. * <ul>
  43. * <li>Determine the actual document format of the supplied print data. This
  44. * is supplied as a {@link javax.print.DocFlavor} object with the MIME type
  45. * and the representation class of the print data.</li>
  46. * <li>Obtain the print data either in its representation class or depending
  47. * on the document format through convenience methods as a
  48. * {@link java.io.Reader} or an {@link java.io.InputStream}.</li>
  49. * <li>Obtain the document's attribute set specifying the attributes which
  50. * apply to this document instance.</li>
  51. * </ul>
  52. * </p><p>
  53. * Every method of a <code>Doc</code> implementation has to return always the
  54. * same object on every method call. Therefore if the print job consumes the
  55. * print data via a stream or a reader object it can read only once the
  56. * supplied print data. Implementations of this interface have to be thread
  57. * safe.
  58. * </p>
  59. *
  60. * @author Michael Koch (konqueror@gmx.de)
  61. */
  62. public interface Doc
  63. {
  64. /**
  65. * Returns the unmodifiable view of the attributes of this doc object.
  66. * <p>
  67. * The attributes of this doc's attributes set overrides attributes of
  68. * the same category in the print job's attribute set. If an attribute
  69. * is not available in this doc's attributes set or <code>null</code>
  70. * is returned the attributes of the same category of the print job are
  71. * used.
  72. * </p>
  73. *
  74. * @return The unmodifiable attributes set, or <code>null</code>.
  75. */
  76. DocAttributeSet getAttributes();
  77. /**
  78. * Returns the flavor of this doc objects print data.
  79. *
  80. * @return The document flavor.
  81. */
  82. DocFlavor getDocFlavor();
  83. /**
  84. * Returns the print data of this doc object.
  85. * <p>
  86. * The returned object is an instance as described by the associated
  87. * document flavor ({@link DocFlavor#getRepresentationClassName()})
  88. * and can be cast to this representation class.
  89. * </p>
  90. *
  91. * @return The print data in the representation class.
  92. * @throws IOException if representation class is a stream and I/O
  93. * exception occures.
  94. */
  95. Object getPrintData() throws IOException;
  96. /**
  97. * Returns a <code>Reader</code> object for extracting character print data
  98. * from this document.
  99. * <p>
  100. * This method is supported if the document flavor is of type:
  101. * <ul>
  102. * <li><code>char[]</code></li>
  103. * <li><code>java.lang.String</code></li>
  104. * <li><code>java.io.Reader</code></li>
  105. * </ul>
  106. * otherwise this method returns <code>null</code>.
  107. * </p>
  108. *
  109. * @return The <code>Reader</code> object, or <code>null</code>.
  110. *
  111. * @throws IOException if an error occurs.
  112. */
  113. Reader getReaderForText() throws IOException;
  114. /**
  115. * Returns an <code>InputStream</code> object for extracting byte print data
  116. * from this document.
  117. * <p>
  118. * This method is supported if the document flavor is of type:
  119. * <ul>
  120. * <li><code>byte[]</code></li>
  121. * <li><code>java.io.InputStream</code></li>
  122. * </ul>
  123. * otherwise this method returns <code>null</code>.
  124. * </p>
  125. *
  126. * @return The <code>InputStream</code> object, or <code>null</code>.
  127. *
  128. * @throws IOException if an error occurs.
  129. */
  130. InputStream getStreamForBytes() throws IOException;
  131. }