1. /*
  2. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. /*
  6. * @(#)SAXTransformerFactory.java 1.11 03/01/23
  7. */
  8. package javax.xml.transform.sax;
  9. import javax.xml.transform.*;
  10. import org.xml.sax.InputSource;
  11. import org.xml.sax.SAXException;
  12. import org.xml.sax.SAXNotSupportedException;
  13. import org.xml.sax.SAXNotRecognizedException;
  14. import org.xml.sax.XMLReader;
  15. import org.xml.sax.XMLFilter;
  16. /**
  17. * This class extends TransformerFactory to provide SAX-specific
  18. * factory methods. It provides two types of ContentHandlers,
  19. * one for creating Transformers, the other for creating Templates
  20. * objects.
  21. *
  22. * <p>If an application wants to set the ErrorHandler or EntityResolver
  23. * for an XMLReader used during a transformation, it should use a URIResolver
  24. * to return the SAXSource which provides (with getXMLReader) a reference to
  25. * the XMLReader.</p>
  26. */
  27. public abstract class SAXTransformerFactory extends TransformerFactory {
  28. /** If {@link javax.xml.transform.TransformerFactory#getFeature}
  29. * returns true when passed this value as an argument,
  30. * the TransformerFactory returned from
  31. * {@link javax.xml.transform.TransformerFactory#newInstance} may
  32. * be safely cast to a SAXTransformerFactory.
  33. */
  34. public static final String FEATURE =
  35. "http://javax.xml.transform.sax.SAXTransformerFactory/feature";
  36. /** If {@link javax.xml.transform.TransformerFactory#getFeature}
  37. * returns true when passed this value as an argument,
  38. * the {@link #newXMLFilter(Source src)}
  39. * and {@link #newXMLFilter(Templates templates)} methods are supported.
  40. */
  41. public static final String FEATURE_XMLFILTER =
  42. "http://javax.xml.transform.sax.SAXTransformerFactory/feature/xmlfilter";
  43. /**
  44. * The default constructor is protected on purpose.
  45. */
  46. protected SAXTransformerFactory() {}
  47. /**
  48. * Get a TransformerHandler object that can process SAX
  49. * ContentHandler events into a Result, based on the transformation
  50. * instructions specified by the argument.
  51. *
  52. * @param src The Source of the transformation instructions.
  53. *
  54. * @return TransformerHandler ready to transform SAX events.
  55. *
  56. * @throws TransformerConfigurationException If for some reason the
  57. * TransformerHandler can not be created.
  58. */
  59. public abstract TransformerHandler newTransformerHandler(Source src)
  60. throws TransformerConfigurationException;
  61. /**
  62. * Get a TransformerHandler object that can process SAX
  63. * ContentHandler events into a Result, based on the Templates argument.
  64. *
  65. * @param templates The compiled transformation instructions.
  66. *
  67. * @return TransformerHandler ready to transform SAX events.
  68. *
  69. * @throws TransformerConfigurationException If for some reason the
  70. * TransformerHandler can not be created.
  71. */
  72. public abstract TransformerHandler newTransformerHandler(
  73. Templates templates) throws TransformerConfigurationException;
  74. /**
  75. * Get a TransformerHandler object that can process SAX
  76. * ContentHandler events into a Result. The transformation
  77. * is defined as an identity (or copy) transformation, for example
  78. * to copy a series of SAX parse events into a DOM tree.
  79. *
  80. * @return A non-null reference to a TransformerHandler, that may
  81. * be used as a ContentHandler for SAX parse events.
  82. *
  83. * @throws TransformerConfigurationException If for some reason the
  84. * TransformerHandler cannot be created.
  85. */
  86. public abstract TransformerHandler newTransformerHandler()
  87. throws TransformerConfigurationException;
  88. /**
  89. * Get a TemplatesHandler object that can process SAX
  90. * ContentHandler events into a Templates object.
  91. *
  92. * @return A non-null reference to a TransformerHandler, that may
  93. * be used as a ContentHandler for SAX parse events.
  94. *
  95. * @throws TransformerConfigurationException If for some reason the
  96. * TemplatesHandler cannot be created.
  97. */
  98. public abstract TemplatesHandler newTemplatesHandler()
  99. throws TransformerConfigurationException;
  100. /**
  101. * Create an XMLFilter that uses the given Source as the
  102. * transformation instructions.
  103. *
  104. * @param src The Source of the transformation instructions.
  105. *
  106. * @return An XMLFilter object, or null if this feature is not supported.
  107. *
  108. * @throws TransformerConfigurationException If for some reason the
  109. * TemplatesHandler cannot be created.
  110. */
  111. public abstract XMLFilter newXMLFilter(Source src)
  112. throws TransformerConfigurationException;
  113. /**
  114. * Create an XMLFilter, based on the Templates argument..
  115. *
  116. * @param templates The compiled transformation instructions.
  117. *
  118. * @return An XMLFilter object, or null if this feature is not supported.
  119. *
  120. * @throws TransformerConfigurationException If for some reason the
  121. * TemplatesHandler cannot be created.
  122. */
  123. public abstract XMLFilter newXMLFilter(Templates templates)
  124. throws TransformerConfigurationException;
  125. }