package failchat.core;

import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MessageObjectCleaner implements MessageHandler {

    public static final Pattern pattern = Pattern.compile("\\{!\\d{1,3}\\}");
    private static volatile MessageObjectCleaner instance;


    private MessageObjectCleaner() {

    }

    public static MessageObjectCleaner getInstance() {
        MessageObjectCleaner localInstance = instance;
        if (localInstance == null) {
            synchronized (MessageObjectCleaner.class) {
                localInstance = instance;
                if (localInstance == null) {
                    instance = localInstance = new MessageObjectCleaner();
                }
            }
        }
        return localInstance;
    }

    private static final Logger logger = Logger.getLogger(MessageObjectCleaner.class.getName());

    @Override
    public void handleMessage(Message message) {
        Matcher m = pattern.matcher(message.getText());
        if (m.find()) {
            logger.fine("Message cleaned - " + message.getAuthor() + ": " + message.getText());
            message.setText(m.replaceAll(""));
        }
    }
}
package failchat.core;

import java.util.logging.Logger;
/**
 * Заменяет символы { и } на html entity
 * */
public class MessageObjectCleaner implements MessageHandler {
    private static volatile MessageObjectCleaner instance;
    private static final Logger logger = Logger.getLogger(MessageObjectCleaner.class.getName());

    private MessageObjectCleaner() {

    }

    public static MessageObjectCleaner getInstance() {
        MessageObjectCleaner localInstance = instance;
        if (localInstance == null) {
            synchronized (MessageObjectCleaner.class) {
                localInstance = instance;
                if (localInstance == null) {
                    instance = localInstance = new MessageObjectCleaner();
                }
            }
        }
        return localInstance;
    }

    @Override
    public void handleMessage(Message message) {
        String mes = message.getText();
        mes = mes.replaceAll("\\{", "&#123;");
        mes = mes.replaceAll("}", "&#125;");
        message.setText(mes);
    }
}
Replace characters { and } for html entities
Replace characters { and } for html entities
