1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: Serializer.java,v 1.2 2004/02/17 04:18:19 minchau Exp $
  18. */
  19. package com.sun.org.apache.xml.internal.serializer;
  20. import java.io.Writer;
  21. import java.io.OutputStream;
  22. import java.io.IOException;
  23. import java.util.Properties;
  24. import com.sun.org.apache.xml.internal.serializer.DOMSerializer;
  25. import org.xml.sax.ContentHandler;
  26. /**
  27. * The Serializer interface is implemented by Serializers to publish methods to
  28. * get and set streams and writers, to set the output properties, and get the
  29. * Serializer as a ContentHandler or DOMSerializer.
  30. */
  31. public interface Serializer {
  32. /**
  33. * Specifies an output stream to which the document should be
  34. * serialized. This method should not be called while the
  35. * serializer is in the process of serializing a document.
  36. * <p>
  37. * The encoding specified in the output {@link Properties} is used, or
  38. * if no encoding was specified, the default for the selected
  39. * output method.
  40. *
  41. * @param output The output stream
  42. */
  43. public void setOutputStream(OutputStream output);
  44. /**
  45. * Get the output stream where the events will be serialized to.
  46. *
  47. * @return reference to the result stream, or null of only a writer was
  48. * set.
  49. */
  50. public OutputStream getOutputStream();
  51. /**
  52. * Specifies a writer to which the document should be serialized.
  53. * This method should not be called while the serializer is in
  54. * the process of serializing a document.
  55. * <p>
  56. * The encoding specified for the output {@link Properties} must be
  57. * identical to the output format used with the writer.
  58. *
  59. * @param writer The output writer stream
  60. */
  61. public void setWriter(Writer writer);
  62. /**
  63. * Get the character stream where the events will be serialized to.
  64. *
  65. * @return Reference to the result Writer, or null.
  66. */
  67. public Writer getWriter();
  68. /**
  69. * Specifies an output format for this serializer. It the
  70. * serializer has already been associated with an output format,
  71. * it will switch to the new format. This method should not be
  72. * called while the serializer is in the process of serializing
  73. * a document.
  74. *
  75. * @param format The output format to use
  76. */
  77. public void setOutputFormat(Properties format);
  78. /**
  79. * Returns the output format properties for this serializer.
  80. *
  81. * @return The output format in use
  82. */
  83. public Properties getOutputFormat();
  84. /**
  85. * Return a {@link ContentHandler} interface into this serializer.
  86. * If the serializer does not support the {@link ContentHandler}
  87. * interface, it should return null.
  88. *
  89. * @return A {@link ContentHandler} interface into this serializer,
  90. * or null if the serializer is not SAX 2 capable
  91. * @throws IOException An I/O exception occured
  92. */
  93. public ContentHandler asContentHandler() throws IOException;
  94. /**
  95. * Return a {@link DOMSerializer} interface into this serializer.
  96. * If the serializer does not support the {@link DOMSerializer}
  97. * interface, it should return null.
  98. *
  99. * @return A {@link DOMSerializer} interface into this serializer,
  100. * or null if the serializer is not DOM capable
  101. * @throws IOException An I/O exception occured
  102. */
  103. public DOMSerializer asDOMSerializer() throws IOException;
  104. /**
  105. * Resets the serializer. If this method returns true, the
  106. * serializer may be used for subsequent serialization of new
  107. * documents. It is possible to change the output format and
  108. * output stream prior to serializing, or to use the existing
  109. * output format and output stream.
  110. *
  111. * @return True if serializer has been reset and can be reused
  112. */
  113. public boolean reset();
  114. }