Java XML Transform transform(String xmlInputFile, String xsltInputFile, OutputStream outputStream)

Here you can find the source of transform(String xmlInputFile, String xsltInputFile, OutputStream outputStream)

Description

Transform.

License

Apache License

Parameter

Parameter Description
xmlInputFile the xml input file
xsltInputFile the xslt input file
outputStream the output stream

Exception

Parameter Description
TransformerFactoryConfigurationError the transformer factory configuration error
TransformerConfigurationException the transformer configuration exception
TransformerException the transformer exception

Declaration

public static void transform(String xmlInputFile, String xsltInputFile, OutputStream outputStream)
        throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException 

Method Source Code

//package com.java2s;
/**// w w  w  . j a v a  2  s.c o m
 * Copyright (C) 2007 Asterios Raptis
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.File;
import java.io.OutputStream;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class Main {
    /** The Constant TRANSFORMER_FACTORY. */
    private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance();

    /**
     * Transform.
     *
     * @param xmlInputFile
     *            the xml input file
     * @param xsltInputFile
     *            the xslt input file
     * @param outputStream
     *            the output stream
     * @throws TransformerFactoryConfigurationError
     *             the transformer factory configuration error
     * @throws TransformerConfigurationException
     *             the transformer configuration exception
     * @throws TransformerException
     *             the transformer exception
     */
    public static void transform(String xmlInputFile, String xsltInputFile, OutputStream outputStream)
            throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException {
        File xmlFile = new File(xmlInputFile);
        File xsltFile = new File(xsltInputFile);
        transform(xmlFile, xsltFile, outputStream);
    }

    /**
     * Transform.
     *
     * @param xmlFile
     *            the xml file
     * @param xsltFile
     *            the xslt file
     * @param outputStream
     *            the output stream
     * @throws TransformerFactoryConfigurationError
     *             the transformer factory configuration error
     * @throws TransformerConfigurationException
     *             the transformer configuration exception
     * @throws TransformerException
     *             the transformer exception
     */
    public static void transform(File xmlFile, File xsltFile, OutputStream outputStream)
            throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException {
        Source xmlSource = new StreamSource(xmlFile);
        Source xsltSource = new StreamSource(xsltFile);
        transform(xmlSource, xsltSource, outputStream);
    }

    /**
     * Transform.
     *
     * @param xmlSource
     *            the xml source
     * @param xsltSource
     *            the xslt source
     * @param outputStream
     *            the output stream
     * @throws TransformerFactoryConfigurationError
     *             the transformer factory configuration error
     * @throws TransformerConfigurationException
     *             the transformer configuration exception
     * @throws TransformerException
     *             the transformer exception
     */
    public static void transform(Source xmlSource, Source xsltSource, OutputStream outputStream)
            throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException {
        Transformer transformer = getTransformer(xsltSource);

        transformer.transform(xmlSource, new StreamResult(outputStream));
    }

    /**
     * Gets a new instance from a Transformer object.
     *
     * @param xsltSource
     *            the xslt source
     * @return the transformer
     * @throws TransformerFactoryConfigurationError
     *             the transformer factory configuration error
     * @throws TransformerConfigurationException
     *             the transformer configuration exception
     */
    public static Transformer getTransformer(Source xsltSource)
            throws TransformerFactoryConfigurationError, TransformerConfigurationException {
        return TRANSFORMER_FACTORY.newTransformer(xsltSource);
    }

    /**
     * Gets the transformer.
     *
     * @param xsltFile
     *            the xslt file
     * @return the transformer
     * @throws TransformerFactoryConfigurationError
     *             the transformer factory configuration error
     * @throws TransformerConfigurationException
     *             the transformer configuration exception
     */
    public static Transformer getTransformer(File xsltFile)
            throws TransformerFactoryConfigurationError, TransformerConfigurationException {
        return getTransformer(new StreamSource(xsltFile));
    }

    /**
     * Gets the transformer.
     *
     * @param xsltInputFile
     *            the xslt input file
     * @return the transformer
     * @throws TransformerFactoryConfigurationError
     *             the transformer factory configuration error
     * @throws TransformerConfigurationException
     *             the transformer configuration exception
     */
    public static Transformer getTransformer(String xsltInputFile)
            throws TransformerFactoryConfigurationError, TransformerConfigurationException {
        return getTransformer(new File(xsltInputFile));
    }
}

Related

  1. transform(Source source, Source stylesheet, Map params, Properties outputProperties)
  2. transform(Source source, Templates cachedXSLT)
  3. transform(Source xmlSource, Result outputTarget)
  4. transform(Source xmlSource, Templates template, Result result, Map parameters)
  5. transform(Source xsl, Source xml, Result result)
  6. transform(String xmlInURI, String xslInURI)
  7. transform(String xmlsource, File xsltfile)
  8. transform(String xslSource, Node original)
  9. transform(Transformer transformer, Node element)