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