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