<commit_before>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This 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 software 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 software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.rendering.internal.renderer.event;

import java.util.Iterator;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.xwiki.rendering.listener.Format;
import org.xwiki.rendering.listener.HeaderLevel;
import org.xwiki.rendering.listener.ListType;
import org.xwiki.rendering.listener.MetaData;
import org.xwiki.rendering.listener.chaining.ListenerChain;
import org.xwiki.rendering.listener.reference.ResourceReference;
import org.xwiki.rendering.renderer.AbstractChainingPrintRenderer;
import org.xwiki.rendering.syntax.Syntax;

/**
 * Prints listener event names in a format useful for testing and debugging.
 * 
 * @version $Id$
 * @since 1.8RC1
 */
public class EventsChainingRenderer extends AbstractChainingPrintRenderer
{
    public EventsChainingRenderer(ListenerChain listenerChain)
    {
        setListenerChain(listenerChain);
    }

    // Events

    /**
     * {@inheritDoc}
     * 
     * @since 3.0M2
     */
    @Override
    public void beginDocument(MetaData metaData)
    {
        getPrinter().println("beginDocument" + serializeParameters(metaData.getMetaData()));
    }

    /**
     * {@inheritDoc}
     * 
     * @since 3.0M2
     */
    @Override
    public void endDocument(MetaData metaData)
    {
        getPrinter().print("endDocument" + serializeParameters(metaData.getMetaData()));
    }

    @Override
    public void beginGroup(Map<String, String> parameters)
    {
        getPrinter().println("beginGroup" + serializeParameters(parameters));
    }

    @Override
    public void endGroup(Map<String, String> parameters)
    {
        getPrinter().println("endGroup" + serializeParameters(parameters));
    }

    @Override
    public void beginFormat(Format format, Map<String, String> parameters)
    {
        getPrinter().println("beginFormat [" + format + "]" + serializeParameters(parameters));
    }

    @Override
    public void endFormat(Format format, Map<String, String> parameters)
    {
        getPrinter().println("endFormat [" + format + "]" + serializeParameters(parameters));
    }

    @Override
    public void beginParagraph(Map<String, String> parameters)
    {
        getPrinter().println("beginParagraph" + serializeParameters(parameters));
    }

    @Override
    public void endParagraph(Map<String, String> parameters)
    {
        getPrinter().println("endParagraph" + serializeParameters(parameters));
    }

    @Override
    public void onNewLine()
    {
        getPrinter().println("onNewLine");
    }

    @Override
    public void beginLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
    {
        getPrinter().println(
            "beginLink [" + reference + "] [" + isFreeStandingURI + "]" + serializeParameters(parameters));
    }

    @Override
    public void endLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
    {
        getPrinter().println(
            "endLink [" + reference + "] [" + isFreeStandingURI + "]" + serializeParameters(parameters));
    }

    @Override
    public void onMacro(String id, Map<String, String> parameters, String content, boolean isInline)
    {
        printMacroData("onMacro", id, parameters, content, isInline);
    }

    @Override
    public void beginSection(Map<String, String> parameters)
    {
        getPrinter().println("beginSection" + serializeParameters(parameters));
    }

    @Override
    public void beginHeader(HeaderLevel level, String id, Map<String, String> parameters)
    {
        getPrinter().println("beginHeader [" + level + ", " + id + "]" + serializeParameters(parameters));
    }

    @Override
    public void endSection(Map<String, String> parameters)
    {
        getPrinter().println("endSection" + serializeParameters(parameters));
    }

    @Override
    public void endHeader(HeaderLevel level, String id, Map<String, String> parameters)
    {
        getPrinter().println("endHeader [" + level + ", " + id + "]" + serializeParameters(parameters));
    }

    @Override
    public void onWord(String word)
    {
        getPrinter().println("onWord [" + getEscaped(word) + "]");
    }

    @Override
    public void beginList(ListType listType, Map<String, String> parameters)
    {
        getPrinter().println("beginList [" + listType + "]" + serializeParameters(parameters));
    }

    @Override
    public void beginListItem()
    {
        getPrinter().println("beginListItem");
    }

    @Override
    public void endList(ListType listType, Map<String, String> parameters)
    {
        getPrinter().println("endList [" + listType + "]" + serializeParameters(parameters));
    }

    @Override
    public void endListItem()
    {
        getPrinter().println("endListItem");
    }

    @Override
    public void onSpace()
    {
        getPrinter().println("onSpace");
    }

    @Override
    public void onSpecialSymbol(char symbol)
    {
        getPrinter().println("onSpecialSymbol [" + symbol + "]");
    }
<commit_msg>[Misc] Also escape chars in special symbol event<commit_after>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This 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 software 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 software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.rendering.internal.renderer.event;

import java.util.Iterator;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.xwiki.rendering.listener.Format;
import org.xwiki.rendering.listener.HeaderLevel;
import org.xwiki.rendering.listener.ListType;
import org.xwiki.rendering.listener.MetaData;
import org.xwiki.rendering.listener.chaining.ListenerChain;
import org.xwiki.rendering.listener.reference.ResourceReference;
import org.xwiki.rendering.renderer.AbstractChainingPrintRenderer;
import org.xwiki.rendering.syntax.Syntax;

/**
 * Prints listener event names in a format useful for testing and debugging.
 * 
 * @version $Id$
 * @since 1.8RC1
 */
public class EventsChainingRenderer extends AbstractChainingPrintRenderer
{
    public EventsChainingRenderer(ListenerChain listenerChain)
    {
        setListenerChain(listenerChain);
    }

    // Events

    /**
     * {@inheritDoc}
     * 
     * @since 3.0M2
     */
    @Override
    public void beginDocument(MetaData metaData)
    {
        getPrinter().println("beginDocument" + serializeParameters(metaData.getMetaData()));
    }

    /**
     * {@inheritDoc}
     * 
     * @since 3.0M2
     */
    @Override
    public void endDocument(MetaData metaData)
    {
        getPrinter().print("endDocument" + serializeParameters(metaData.getMetaData()));
    }

    @Override
    public void beginGroup(Map<String, String> parameters)
    {
        getPrinter().println("beginGroup" + serializeParameters(parameters));
    }

    @Override
    public void endGroup(Map<String, String> parameters)
    {
        getPrinter().println("endGroup" + serializeParameters(parameters));
    }

    @Override
    public void beginFormat(Format format, Map<String, String> parameters)
    {
        getPrinter().println("beginFormat [" + format + "]" + serializeParameters(parameters));
    }

    @Override
    public void endFormat(Format format, Map<String, String> parameters)
    {
        getPrinter().println("endFormat [" + format + "]" + serializeParameters(parameters));
    }

    @Override
    public void beginParagraph(Map<String, String> parameters)
    {
        getPrinter().println("beginParagraph" + serializeParameters(parameters));
    }

    @Override
    public void endParagraph(Map<String, String> parameters)
    {
        getPrinter().println("endParagraph" + serializeParameters(parameters));
    }

    @Override
    public void onNewLine()
    {
        getPrinter().println("onNewLine");
    }

    @Override
    public void beginLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
    {
        getPrinter().println(
            "beginLink [" + reference + "] [" + isFreeStandingURI + "]" + serializeParameters(parameters));
    }

    @Override
    public void endLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
    {
        getPrinter().println(
            "endLink [" + reference + "] [" + isFreeStandingURI + "]" + serializeParameters(parameters));
    }

    @Override
    public void onMacro(String id, Map<String, String> parameters, String content, boolean isInline)
    {
        printMacroData("onMacro", id, parameters, content, isInline);
    }

    @Override
    public void beginSection(Map<String, String> parameters)
    {
        getPrinter().println("beginSection" + serializeParameters(parameters));
    }

    @Override
    public void beginHeader(HeaderLevel level, String id, Map<String, String> parameters)
    {
        getPrinter().println("beginHeader [" + level + ", " + id + "]" + serializeParameters(parameters));
    }

    @Override
    public void endSection(Map<String, String> parameters)
    {
        getPrinter().println("endSection" + serializeParameters(parameters));
    }

    @Override
    public void endHeader(HeaderLevel level, String id, Map<String, String> parameters)
    {
        getPrinter().println("endHeader [" + level + ", " + id + "]" + serializeParameters(parameters));
    }

    @Override
    public void onWord(String word)
    {
        getPrinter().println("onWord [" + getEscaped(word) + "]");
    }

    @Override
    public void beginList(ListType listType, Map<String, String> parameters)
    {
        getPrinter().println("beginList [" + listType + "]" + serializeParameters(parameters));
    }

    @Override
    public void beginListItem()
    {
        getPrinter().println("beginListItem");
    }

    @Override
    public void endList(ListType listType, Map<String, String> parameters)
    {
        getPrinter().println("endList [" + listType + "]" + serializeParameters(parameters));
    }

    @Override
    public void endListItem()
    {
        getPrinter().println("endListItem");
    }

    @Override
    public void onSpace()
    {
        getPrinter().println("onSpace");
    }

    @Override
    public void onSpecialSymbol(char symbol)
    {
        getPrinter().println("onSpecialSymbol [" + getEscaped(Character.toString(symbol)) + "]");
    }

{'fraction_non_alphanumeric': 0.11159553953215394, 'fraction_numerical': 0.0038567955059948017, 'mean_word_length': 3.3644346871569706, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '2899612', 'n_tokens_mistral': 3334, 'n_tokens_neox': 3246, 'n_words': 821}