<commit_before>/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2001-06 The eXist Project
 *  http://exist-db.org
 *
 *  This program 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
 *  of the License, or (at your option) any later version.
 *
 *  This program 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *  $Id: TransformerFactoryAllocator.java 0000 2006-08-10 22:39:00 +0000 (Thu, 10 Aug 2006) deliriumsky $
 */
package org.exist.xslt;

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

import org.apache.log4j.Logger;
import org.exist.storage.DBBroker;

/**
 * Allows the TransformerFactory that is used for XSLT to be
 * chosen through configuration settings in conf.xml
 *
 * Within eXist this class should be used instead of
 * directly calling SAXTransformerFactory.newInstance() directly
 *
 * @author <NAME> <<EMAIL>>
 */

public class TransformerFactoryAllocator {
    /*
     * problem is that even when a Xalan is defined in conf.xml, if Saxon JAR's 
     * are on the classpath then when we create a Xalan TransformerFactory and 
     * newInstance() is called on it, it returns a Saxon TransformerFactory :-(
     */
    
    private final static Logger LOG = Logger.getLogger(TransformerFactoryAllocator.class);
    
    //private constructor
    private TransformerFactoryAllocator() {
    }
    
    /**
     * Get the TransformerFactory defined in conf.xml
     * If the class can't be found or the given class doesn't implement
     * the required interface, the default factory is returned.
     *
     * @param broker A database broker, used for reading the conf.xml configuration
     *
     * @return  A SAXTransformerFactory, for which newInstance() can then be called
     *
     *
     * Typical usage:
     *
     * Instead of SAXTransformerFactory.newInstance() use
     * TransformerFactoryAllocator.getTransformerFactory(broker).newInstance()
     */
    public static SAXTransformerFactory getTransformerFactory(DBBroker broker) {
        SAXTransformerFactory factory;
        
        //get the transformer class name from conf.xml
        String transformerFactoryClassName =
                (String)broker.getConfiguration().getProperty("transformer.class");
        
        LOG.debug("transformerFactoryClassName=" + transformerFactoryClassName);
        LOG.debug("javax.xml.transform.TransformerFactory="
                + System.getProperty("javax.xml.transform.TransformerFactory"));
        
        
        //was a TransformerFactory class specified
        if(transformerFactoryClassName == null) {<commit_msg>Too much logging/trash in this class. Adam, is this OK for you ?<commit_after>/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2001-06 The eXist Project
 *  http://exist-db.org
 *
 *  This program 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
 *  of the License, or (at your option) any later version.
 *
 *  This program 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *  $Id: TransformerFactoryAllocator.java 0000 2006-08-10 22:39:00 +0000 (Thu, 10 Aug 2006) deliriumsky $
 */
package org.exist.xslt;

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

import org.apache.log4j.Logger;
import org.exist.storage.DBBroker;

/**
 * Allows the TransformerFactory that is used for XSLT to be
 * chosen through configuration settings in conf.xml
 *
 * Within eXist this class should be used instead of
 * directly calling SAXTransformerFactory.newInstance() directly
 *
 * @author <NAME> <<EMAIL>>
 */

public class TransformerFactoryAllocator {
    /*
     * problem is that even when a Xalan is defined in conf.xml, if Saxon JAR's 
     * are on the classpath then when we create a Xalan TransformerFactory and 
     * newInstance() is called on it, it returns a Saxon TransformerFactory :-(
     */
    
    private final static Logger LOG = Logger.getLogger(TransformerFactoryAllocator.class);
    
    //private constructor
    private TransformerFactoryAllocator() {
    }
    
    /**
     * Get the TransformerFactory defined in conf.xml
     * If the class can't be found or the given class doesn't implement
     * the required interface, the default factory is returned.
     *
     * @param broker A database broker, used for reading the conf.xml configuration
     *
     * @return  A SAXTransformerFactory, for which newInstance() can then be called
     *
     *
     * Typical usage:
     *
     * Instead of SAXTransformerFactory.newInstance() use
     * TransformerFactoryAllocator.getTransformerFactory(broker).newInstance()
     */
    public static SAXTransformerFactory getTransformerFactory(DBBroker broker) {
        SAXTransformerFactory factory;
        
        //get the transformer class name from conf.xml
        String transformerFactoryClassName =
                (String)broker.getConfiguration().getProperty("transformer.class");
        
//        LOG.debug("transformerFactoryClassName=" + transformerFactoryClassName);
//        LOG.debug("javax.xml.transform.TransformerFactory="
//                + System.getProperty("javax.xml.transform.TransformerFactory"));
        
        
        //was a TransformerFactory class specified
        if(transformerFactoryClassName == null) {
{'fraction_non_alphanumeric': 0.07379729098552079, 'fraction_numerical': 0.014634905807255176, 'mean_word_length': 3.2124590163934426, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3516138', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1670, 'n_words': 640}