Class Transformer

java.lang.Object
org.zkoss.idom.transform.Transformer

public class Transformer extends Object
Transforms an iDOM Document.
Author:
andrewho@potix.com, tomyeh
  • Constructor Details

    • Transformer

      public Transformer() throws TransformerConfigurationException
      Transformer constructor without stylesheet.
      Throws:
      TransformerConfigurationException
    • Transformer

      public Transformer(Source source) throws TransformerConfigurationException
      Constructs a transformer with a stylesheet in form of Source.

      Examples:

      File file
      new Transformer(new javax.xml.transform.stream.StreamSource(file));
      Reader reader
      new Transformer(new javax.xml.transform.stream.StreamSource(reader));
      URL url
      new Transformer(new javax.xml.transform.stream.StreamSource(url.openStream()));
      iDOM or DOM dom
      new Transformer(new javax.xml.transform.dom.DOMSource(dom));

      See javax.xml.transform.stream.StreamSource and javax.xml.transform.dom.DOMSource

      Throws:
      TransformerConfigurationException
  • Method Details

    • enableOutputDocType

      public final void enableOutputDocType(boolean enable)
      Sets whether to output the doc type. Default: true.

      Useful only if Document is used in transform(), e.g., transform(Document, Result). If not, you have to set OutputKeys.DOCTYPE_SYSTEM and OutputKeys.DOCTYPE_PUBLIC explicitly (thru getTransformer()).

    • getTransformer

      public final Transformer getTransformer()
      Returns the JAXP transformer encapsulated by this object. Then, you can use it to set properties, listener and so on.

      Notice: OutputKeys.DOCTYPE_SYSTEM and OutputKeys.DOCTYPE_PUBLIC are set automatically if outDocType is true when constructing this object and Document is used to transform.

    • transform

      public final void transform(Source source, Result result) throws TransformerException
      Transforms from a source to a result. and javax.xml.transform.dom.DOMSource
      Parameters:
      source - the source
      result - the result
      Throws:
      TransformerException
      See Also:
    • transform

      public final void transform(Document doc, Result result) throws TransformerException
      Transforms from an iDOM document to a result.

      Examples:

      File file
      transformer.transform(doc, new javax.xml.transform.stream.StreamResult(file));
      Writer writer
      transformer.transform(doc, new javax.xml.transform.stream.StreamResult(writer));
      URL url
      No simple way yet.
      iDOM or DOM dom
      transform(Source) and transform(Document).
      String systemId
      transformer.transform(doc, new javax.xml.transform.stream.StreamResult(systemId));

      See javax.xml.transform.stream.StreamResult and javax.xml.transform.dom.DOMResult

      Parameters:
      doc - the source document
      result - the result
      Throws:
      TransformerException
      See Also:
    • transform

      public final void transform(Element elm, Result result) throws TransformerException
      Transforms from an iDOM element to a result.
      Parameters:
      elm - the source element
      result - the result
      Throws:
      TransformerException
    • transform

      public final Document transform(Source source) throws TransformerException
      Transforms a source and returns the transformed result as an iDOM Document.
      Parameters:
      source - the source
      Returns:
      the transformed result in an iDOM document
      Throws:
      TransformerException
    • transform

      public final Document transform(Document doc) throws TransformerException
      Transforms an iDOM document and returns the transformed result as another iDOM Document.
      Parameters:
      doc - the source document
      Returns:
      the transformed result in an iDOM document
      Throws:
      TransformerException
    • transform

      public final Document transform(Element elm) throws TransformerException
      Transforms an iDOM element and returns the transformed result as another iDOM Document.
      Parameters:
      elm - the source element
      Returns:
      the transformed result in an iDOM document
      Throws:
      TransformerException
    • getOutputProperties

      public final Properties getOutputProperties()
      Get a copy of the output properties for the transformation.
    • getOutputProperty

      public final String getOutputProperty(String name)
      Get an output property that is in effect for the transformation.
    • setOutputProperty

      public final void setOutputProperty(String name, String value)
      Set an output property that will be in effect for the transformation.
    • setOutputProperties

      public final void setOutputProperties(Properties props)
      Set the output properties for the transformation.
    • getErrorListener

      public final ErrorListener getErrorListener()
      Get the error event handler in effect for the transformation.
    • setErrorListener

      public final void setErrorListener(ErrorListener listener)
      Set the error event listener in effect for the transformation.