Java XML Transform createTransformerHandler(int indent)

Here you can find the source of createTransformerHandler(int indent)

Description

create Transformer Handler

License

Open Source License

Declaration

private static synchronized TransformerHandler createTransformerHandler(int indent) throws SAXException 

Method Source Code

//package com.java2s;
/*****************************************************************************
 * Copyright (c) 2006-2013, Cloudsmith Inc.
 * The code, documentation and other materials contained herein have been
 * licensed under the Eclipse Public License - v 1.0 by the copyright holder
 * listed above, as the Initial Contributor under such license. The text of
 * such license is available at www.eclipse.org.
 *****************************************************************************/

import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;

import org.xml.sax.SAXException;

public class Main {
    private static SAXTransformerFactory saxTransformerFactory;

    private static synchronized TransformerHandler createTransformerHandler(int indent) throws SAXException {
        if (saxTransformerFactory == null) {
            TransformerFactory tf = TransformerFactory.newInstance();
            if (!tf.getFeature(SAXTransformerFactory.FEATURE))
                throw new SAXException("The TransformerFactory is not a SAXTransformerFactory"); //$NON-NLS-1$

            saxTransformerFactory = (SAXTransformerFactory) tf;
        }/*from ww w . j ava2s . c om*/
        try {
            saxTransformerFactory.setAttribute("indent-number", Integer.toString(indent)); //$NON-NLS-1$
        } catch (IllegalArgumentException e) {
            // This transformer doesn't support ident-number. We dont' consider
            // that an error
        }

        try {
            return saxTransformerFactory.newTransformerHandler();
        } catch (TransformerConfigurationException e) {
            throw new SAXException(e.getMessage());
        }
    }
}

Related

  1. createTransformer()
  2. createTransformer()
  3. createTransformer()
  4. createTransformer()
  5. createTransformer(final File xsltFile)
  6. createTXT(Transformer xf, Node doc)
  7. exceptionToString(TransformerException exception, boolean showSystemId)
  8. getDefaultTransformerFactoryThreadLocal()
  9. getNewTransformer()