Java XML Transform getDefaultTransformerFactoryThreadLocal()

Here you can find the source of getDefaultTransformerFactoryThreadLocal()

Description

get Default Transformer Factory Thread Local

License

Open Source License

Declaration

public static Transformer getDefaultTransformerFactoryThreadLocal() 

Method Source Code

//package com.java2s;
/**//w w w . ja  v  a2s . com
 * Copyright (c) 2010 EBM Websourcing, http://www.ebmwebsourcing.com/
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * -------------------------------------------------------------------------
 * $id.java
 * -------------------------------------------------------------------------
 */

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;

import javax.xml.transform.TransformerFactory;

public class Main {
    /**
     * <p>
     * {@link Transformer} as thread local.
     * </p>
     * <p>
     * The Transformer is the default one provided by the classpath (no property
     * set).
     * </p>
     */
    private static final ThreadLocal<Transformer> DEFAULT_TRANSFORMER_THREAD_LOCAL = new ThreadLocal<Transformer>() {

        @Override
        protected Transformer initialValue() {
            try {

                return TransformerFactory.newInstance().newTransformer();

            } catch (TransformerConfigurationException e) {
                throw new RuntimeException("Failed to create Transformer",
                        e);
            }
        }
    };

    public static Transformer getDefaultTransformerFactoryThreadLocal() {
        return DEFAULT_TRANSFORMER_THREAD_LOCAL.get();
    }
}

Related

  1. createTransformer()
  2. createTransformer(final File xsltFile)
  3. createTransformerHandler(int indent)
  4. createTXT(Transformer xf, Node doc)
  5. exceptionToString(TransformerException exception, boolean showSystemId)
  6. getNewTransformer()
  7. getThreadedIdentityTransformer( boolean omitXmlDeclaration)
  8. getThreadedIdentityTransformer(final boolean omitXmlDeclaration)
  9. getThreadedTransformer(final boolean omitXmlDeclaration, final boolean standalone, final Map threadMap, final String xslURL)