/*
Copyright (C) 2000-2010  Ministere de la culture et de la communication (France), AJLSM
See LICENCE file
*/
package fr.gouv.culture.sdx.search.lucene.analysis;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

import fr.gouv.culture.sdx.utils.SAXUtils;
import fr.gouv.culture.sdx.utils.Utilities;
import fr.gouv.culture.sdx.utils.constants.Node;

/**
 * An abstract implementation of a SDX analyzer.
 *
 * <p>
 * It handles properly the logging and configuring
 * methods. For configuration, it does nothing.
 */
public abstract class AbstractAnalyzer extends org.apache.lucene.analysis.Analyzer implements Analyzer {

    /** Avalon super.getLog() to write information. */
    protected transient org.apache.avalon.framework.logger.Logger logger;
    
    protected abstract String getAnalyzerType();
    /**
     * Sets the super.getLog().
     *
     * @param   logger     The super.getLog() to use.
     */
    public void enableLogging(org.apache.avalon.framework.logger.Logger logger) {
        this.logger = logger;
    }

    /**
     * Configures this analyzer, currently has no function, only in its subclasses.
     */
    public void configure(Configuration configuration) throws ConfigurationException {
    }

	public void toSAX(ContentHandler handler) throws SAXException {
		handler.startElement(Node.Uri.SDX, "analyzer", Utilities.prefixNodeNameSDX("analyzer"),new AttributesImpl());
		
		handler.startElement(Node.Uri.SDX, "type", Utilities.prefixNodeNameSDX("type"),new AttributesImpl());
		SAXUtils.sendElementContent(handler, this.getClass().getName());
		handler.endElement(Node.Uri.SDX, "type", Utilities.prefixNodeNameSDX("type"));
		
        handler.endElement(Node.Uri.SDX, "analyzer", Utilities.prefixNodeNameSDX("analyzer"));
    }

}
