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;
  6. import java.util.Properties;
  7. /**
  8. * An instance of this abstract class can transform a
  9. * source tree into a result tree.
  10. *
  11. * <p>An instance of this class can be obtained with the <code>
  12. * {@link TransformerFactory#newTransformer TransformerFactory.newTransformer}
  13. * method. This instance may then be used to process XML from a
  14. * variety of sources and write the transformation output to a
  15. * variety of sinks.</p>
  16. *
  17. * <p>An object of this class may not be used in multiple threads
  18. * running concurrently. Different Transformers may be used
  19. * concurrently by different threads.</p>
  20. *
  21. * <p>A <code>Transformer</code> may be used multiple times. Parameters and
  22. * output properties are preserved across transformations.</p>
  23. */
  24. public abstract class Transformer {
  25. /**
  26. * Default constructor is protected on purpose.
  27. */
  28. protected Transformer() {}
  29. /**
  30. * Process the source tree to the output result.
  31. * @param xmlSource The input for the source tree.
  32. * @param outputTarget The output target.
  33. *
  34. * @throws TransformerException If an unrecoverable error occurs
  35. * during the course of the transformation.
  36. */
  37. public abstract void transform(Source xmlSource, Result outputTarget)
  38. throws TransformerException;
  39. /**
  40. * Add a parameter for the transformation.
  41. *
  42. * <p>Pass a qualified name as a two-part string, the namespace URI
  43. * enclosed in curly braces ({}), followed by the local name. If the
  44. * name has a null URL, the String only contain the local name. An
  45. * application can safely check for a non-null URI by testing to see if the first
  46. * character of the name is a '{' character.</p>
  47. * <p>For example, if a URI and local name were obtained from an element
  48. * defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>,
  49. * then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that
  50. * no prefix is used.</p>
  51. *
  52. * @param name The name of the parameter, which may begin with a namespace URI
  53. * in curly braces ({}).
  54. * @param value The value object. This can be any valid Java object. It is
  55. * up to the processor to provide the proper object coersion or to simply
  56. * pass the object on for use in an extension.
  57. */
  58. public abstract void setParameter(String name, Object value);
  59. /**
  60. * Get a parameter that was explicitly set with setParameter
  61. * or setParameters.
  62. *
  63. * <p>This method does not return a default parameter value, which
  64. * cannot be determined until the node context is evaluated during
  65. * the transformation process.
  66. *
  67. * @return A parameter that has been set with setParameter.
  68. */
  69. public abstract Object getParameter(String name);
  70. /**
  71. * Clear all parameters set with setParameter.
  72. */
  73. public abstract void clearParameters();
  74. /**
  75. * Set an object that will be used to resolve URIs used in
  76. * document().
  77. *
  78. * <p>If the resolver argument is null, the URIResolver value will
  79. * be cleared, and the default behavior will be used.</p>
  80. *
  81. * @param resolver An object that implements the URIResolver interface,
  82. * or null.
  83. */
  84. public abstract void setURIResolver(URIResolver resolver);
  85. /**
  86. * Get an object that will be used to resolve URIs used in
  87. * document(), etc.
  88. *
  89. * @return An object that implements the URIResolver interface,
  90. * or null.
  91. */
  92. public abstract URIResolver getURIResolver();
  93. /**
  94. * Set the output properties for the transformation. These
  95. * properties will override properties set in the Templates
  96. * with xsl:output.
  97. *
  98. * <p>If argument to this function is null, any properties
  99. * previously set are removed, and the value will revert to the value
  100. * defined in the templates object.</p>
  101. *
  102. * <p>Pass a qualified property key name as a two-part string, the namespace URI
  103. * enclosed in curly braces ({}), followed by the local name. If the
  104. * name has a null URL, the String only contain the local name. An
  105. * application can safely check for a non-null URI by testing to see if the first
  106. * character of the name is a '{' character.</p>
  107. * <p>For example, if a URI and local name were obtained from an element
  108. * defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>,
  109. * then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that
  110. * no prefix is used.</p>
  111. *
  112. * @param oformat A set of output properties that will be
  113. * used to override any of the same properties in affect
  114. * for the transformation.
  115. *
  116. * @see javax.xml.transform.OutputKeys
  117. * @see java.util.Properties
  118. *
  119. * @throws IllegalArgumentException if any of the argument keys are not
  120. * recognized and are not namespace qualified.
  121. */
  122. public abstract void setOutputProperties(Properties oformat)
  123. throws IllegalArgumentException;
  124. /**
  125. * Get a copy of the output properties for the transformation.
  126. *
  127. * <p>The properties returned should contain properties set by the user,
  128. * and properties set by the stylesheet, and these properties
  129. * are "defaulted" by default properties specified by <a href="http://www.w3.org/TR/xslt#output">section 16 of the
  130. * XSL Transformations (XSLT) W3C Recommendation</a>. The properties that
  131. * were specifically set by the user or the stylesheet should be in the base
  132. * Properties list, while the XSLT default properties that were not
  133. * specifically set should be the default Properties list. Thus,
  134. * getOutputProperties().getProperty(String key) will obtain any
  135. * property in that was set by {@link #setOutputProperty},
  136. * {@link #setOutputProperties}, in the stylesheet, <em>or</em> the default
  137. * properties, while
  138. * getOutputProperties().get(String key) will only retrieve properties
  139. * that were explicitly set by {@link #setOutputProperty},
  140. * {@link #setOutputProperties}, or in the stylesheet.</p>
  141. *
  142. * <p>Note that mutation of the Properties object returned will not
  143. * effect the properties that the transformation contains.</p>
  144. *
  145. * <p>If any of the argument keys are not recognized and are not
  146. * namespace qualified, the property will be ignored. In other words the
  147. * behaviour is not orthogonal with setOutputProperties.</p>
  148. *
  149. * @returns A copy of the set of output properties in effect
  150. * for the next transformation.
  151. *
  152. * @see javax.xml.transform.OutputKeys
  153. * @see java.util.Properties
  154. */
  155. public abstract Properties getOutputProperties();
  156. /**
  157. * Set an output property that will be in effect for the
  158. * transformation.
  159. *
  160. * <p>Pass a qualified property name as a two-part string, the namespace URI
  161. * enclosed in curly braces ({}), followed by the local name. If the
  162. * name has a null URL, the String only contain the local name. An
  163. * application can safely check for a non-null URI by testing to see if the first
  164. * character of the name is a '{' character.</p>
  165. * <p>For example, if a URI and local name were obtained from an element
  166. * defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>,
  167. * then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that
  168. * no prefix is used.</p>
  169. *
  170. * <p>The Properties object that was passed to {@link #setOutputProperties} won't
  171. * be effected by calling this method.</p>
  172. *
  173. * @param name A non-null String that specifies an output
  174. * property name, which may be namespace qualified.
  175. * @param value The non-null string value of the output property.
  176. *
  177. * @throws IllegalArgumentException If the property is not supported, and is
  178. * not qualified with a namespace.
  179. *
  180. * @see javax.xml.transform.OutputKeys
  181. */
  182. public abstract void setOutputProperty(String name, String value)
  183. throws IllegalArgumentException;
  184. /**
  185. * Get an output property that is in effect for the
  186. * transformation. The property specified may be a property
  187. * that was set with setOutputProperty, or it may be a
  188. * property specified in the stylesheet.
  189. *
  190. * @param name A non-null String that specifies an output
  191. * property name, which may be namespace qualified.
  192. *
  193. * @return The string value of the output property, or null
  194. * if no property was found.
  195. *
  196. * @throws IllegalArgumentException If the property is not supported.
  197. *
  198. * @see javax.xml.transform.OutputKeys
  199. */
  200. public abstract String getOutputProperty(String name)
  201. throws IllegalArgumentException;
  202. /**
  203. * Set the error event listener in effect for the transformation.
  204. *
  205. * @param listener The new error listener.
  206. * @throws IllegalArgumentException if listener is null.
  207. */
  208. public abstract void setErrorListener(ErrorListener listener)
  209. throws IllegalArgumentException;
  210. /**
  211. * Get the error event handler in effect for the transformation.
  212. *
  213. * @return The current error handler, which should never be null.
  214. */
  215. public abstract ErrorListener getErrorListener();
  216. }