FileDocCategorySizeDatePackage
JAXPTransformer.javaAPI DocGlassfish v2 API7015Tue May 22 16:54:50 BST 2007oracle.toplink.essentials.platform.xml.jaxp

JAXPTransformer

public class JAXPTransformer extends Object implements XMLTransformer

Fields Summary
private boolean
fragment
private static final String
NO
private static final String
YES
private Transformer
transformer
Constructors Summary
public JAXPTransformer()


      
        super();
        try {
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            transformer = transformerFactory.newTransformer();
        } catch (TransformerConfigurationException e) {
            throw XMLPlatformException.xmlPlatformTransformException(e);
        }
    
Methods Summary
public java.lang.StringgetEncoding()

        return transformer.getOutputProperty(OutputKeys.ENCODING);
    
public java.lang.StringgetVersion()

        return transformer.getOutputProperty(OutputKeys.VERSION);
    
public booleanisFormattedOutput()

        return transformer.getOutputProperty(OutputKeys.INDENT).equals(YES);
    
public booleanisFragment()

        return fragment;
    
public voidsetEncoding(java.lang.String encoding)

        transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
    
public voidsetFormattedOutput(boolean shouldFormat)

        if (shouldFormat) {
            transformer.setOutputProperty(OutputKeys.INDENT, YES);
        } else {
            transformer.setOutputProperty(OutputKeys.INDENT, NO);
        }
    
public voidsetFragment(boolean fragment)

        this.fragment = fragment;
    
public voidsetVersion(java.lang.String version)

        transformer.setOutputProperty(OutputKeys.VERSION, version);
    
public voidtransform(org.w3c.dom.Node sourceNode, javax.xml.transform.Result result)

        DOMSource source = null;
        if ((isFragment()) && (result instanceof SAXResult)) {
            if (sourceNode instanceof Document) {
                source = new DOMSource(((Document)sourceNode).getDocumentElement());
            }
        } else {
            source = new DOMSource(sourceNode);
        }
        transform(source, result);
    
public voidtransform(org.w3c.dom.Node sourceNode, java.io.Writer resultWriter)

        DOMSource source = new DOMSource(sourceNode);
        StreamResult result = new StreamResult(resultWriter);

        if (isFragment()) {
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        }
        transform(source, result);
    
public voidtransform(javax.xml.transform.Source source, javax.xml.transform.Result result)

        try {
            if ((result instanceof StreamResult) && (isFragment())) {
                transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            }
            transformer.transform(source, result);
        } catch (TransformerException e) {
            throw XMLPlatformException.xmlPlatformTransformException(e);
        }
    
public voidtransform(org.w3c.dom.Document sourceDocument, org.w3c.dom.Node resultParentNode, java.net.URL stylesheet)

        try {
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            StreamSource stylesheetSource = new StreamSource(stylesheet.openStream());
            Transformer transformer = transformerFactory.newTransformer(stylesheetSource);
            DOMSource source = new DOMSource(sourceDocument);
            DOMResult result = new DOMResult(resultParentNode);
            transformer.transform(source, result);
        } catch (Exception e) {
            throw XMLPlatformException.xmlPlatformTransformException(e);
        }
    
public voidtransform(org.w3c.dom.Node sourceNode, java.io.OutputStream resultOutputStream)

        DOMSource source = new DOMSource(sourceNode);
        StreamResult result = new StreamResult(resultOutputStream);
        if (isFragment()) {
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        }
        transform(source, result);
    
public voidtransform(org.w3c.dom.Node sourceNode, org.xml.sax.ContentHandler resultContentHandler)

        DOMSource source = new DOMSource(sourceNode);
        SAXResult result = new SAXResult(resultContentHandler);

        transform(source, result);