<commit_before>package org.anodyneos.servlet.xsl;

import javax.xml.transform.ErrorListener;
import javax.xml.transform.SourceLocator;
import javax.xml.transform.TransformerException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

/**
 * <meta name="usage" content="general"/>
 * Implement SAX error handler for default reporting.
 */
public class GenericErrorHandler implements ErrorHandler, ErrorListener {

    private static final Log log = LogFactory.getLog(GenericErrorHandler.class);

    public GenericErrorHandler() {}

    public void warning(SAXParseException exception) throws SAXException {
        log.warn(
            "[SAX Warning] " +
            getLocationString(exception) + ": " + exception.getMessage());
    }

    public void error(SAXParseException exception) throws SAXException {
        log.error(
            "[SAX Error] " +
            getLocationString(exception) + ": " + exception.getMessage());
    }

    public void fatalError(SAXParseException exception) throws SAXException {
        log.error(
            "[SAX Fatal Error] " +
            getLocationString(exception) + ": " + exception.getMessage());
        throw exception;
    }

    public void warning(TransformerException exception) throws TransformerException {
        log.warn(
            "[Transformer Warning] " +
            getLocationString(exception) + ": " + exception.getMessage());
    }

    public void error(TransformerException exception) throws TransformerException {
        log.error(
            "[Transformer Error] " +
            getLocationString(exception) + ": " + exception.getMessage());
    }

    public void fatalError(TransformerException exception) throws TransformerException {
        log.error(
            "[Transformer Fatal Error] " +
            getLocationString(exception) + ": " + exception.getMessage());
        throw exception;
    }


    private String getLocationString(SAXParseException ex) {
        StringBuffer str = new StringBuffer();<commit_msg>Now throws exception for SAX error() and transformer error() - is this OK - for some reason I remember there being a problem with Xerces/Xalan and throwing exceptions in one of these two cases, but there are no comments about this.  Reason for this change was that XSL errors such as <xsl:include file="abc"> did not throw an exception when file "abc" didn't exist.<commit_after>package org.anodyneos.servlet.xsl;

import javax.xml.transform.ErrorListener;
import javax.xml.transform.SourceLocator;
import javax.xml.transform.TransformerException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

/**
 * <meta name="usage" content="general"/>
 * Implement SAX error handler for default reporting.
 */
public class GenericErrorHandler implements ErrorHandler, ErrorListener {

    private static final Log log = LogFactory.getLog(GenericErrorHandler.class);

    public GenericErrorHandler() {}

    public void warning(SAXParseException exception) throws SAXException {
        log.warn(
            "[SAX Warning] " +
            getLocationString(exception) + ": " + exception.getMessage());
    }

    public void error(SAXParseException exception) throws SAXException {
        log.error(
            "[SAX Error] " +
            getLocationString(exception) + ": " + exception.getMessage());
        throw exception;
    }

    public void fatalError(SAXParseException exception) throws SAXException {
        log.error(
            "[SAX Fatal Error] " +
            getLocationString(exception) + ": " + exception.getMessage());
        throw exception;
    }

    public void warning(TransformerException exception) throws TransformerException {
        log.warn(
            "[Transformer Warning] " +
            getLocationString(exception) + ": " + exception.getMessage());
    }

    public void error(TransformerException exception) throws TransformerException {
        log.error(
            "[Transformer Error] " +
            getLocationString(exception) + ": " + exception.getMessage());
        throw exception;
    }

    public void fatalError(TransformerException exception) throws TransformerException {
        log.error(
            "[Transformer Fatal Error] " +
            getLocationString(exception) + ": " + exception.getMessage());
        throw exception;
    }


    private String getLocationString(SAXParseException ex) {
        StringBuffer str = new StringBuffer();
{'fraction_non_alphanumeric': 0.09693225394120153, 'fraction_numerical': 0.0, 'mean_word_length': 3.180765805877115, 'pattern_counts': {'":': 12, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '5323363', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1175, 'n_words': 307}