<commit_before>package de.hatoka.common.capi.resource;

import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import de.hatoka.common.capi.app.xslt.Localizer;

public class ResourceLocalizer implements Localizer
{
    private final LocalizationBundle bundle;
    private final String dateFormat;

    public ResourceLocalizer(LocalizationBundle bundle)
    {
        this(bundle, "yyyy/MM/dd");
    }

    public ResourceLocalizer(LocalizationBundle bundle, String dateFormat)
    {
        this.bundle = bundle;
        this.dateFormat = dateFormat;
    }

    @Override
    public String formatDate(String dateString)
    {
        // 2014-11-25T09:45:55.624+01:00
        Date date;
        try
        {
            date = new SimpleDateFormat(LocalizationConstants.XML_DATEFORMAT).parse(dateString);
        }
        catch(ParseException e)
        {
            return dateString;
        }
        return new SimpleDateFormat(dateFormat).format(date);
    }

    @Override
    public String getText(String key, String defaultText, Object... arguments)
    {
        String pattern = bundle.getText(key, null);
        if (pattern == null)
        {
            return defaultText;
        }
        MessageFormat messageFormat = new MessageFormat(pattern, bundle.getLocal());
        return messageFormat.format(arguments, new StringBuffer(), null).toString();
    }

}<commit_msg>throw exception in case of wrong format * return empty string for null date<commit_after>package de.hatoka.common.capi.resource;

import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import de.hatoka.common.capi.app.xslt.Localizer;

public class ResourceLocalizer implements Localizer
{
    private final LocalizationBundle bundle;
    private final String dateFormat;

    public ResourceLocalizer(LocalizationBundle bundle)
    {
        this(bundle, "yyyy/MM/dd");
    }

    public ResourceLocalizer(LocalizationBundle bundle, String dateFormat)
    {
        this.bundle = bundle;
        this.dateFormat = dateFormat;
    }

    @Override
    public String formatDate(String dateString)
    {
        if (dateString == null || dateString.isEmpty())
        {
            return "";
        }
        // convert xml format 2014-11-25T09:45:55.624+01:00 to target
        try
        {
            return new SimpleDateFormat(dateFormat).format(new SimpleDateFormat(LocalizationConstants.XML_DATEFORMAT).parse(dateString));
        }
        catch(ParseException e)
        {
            throw new IllegalArgumentException("Illegal source date string: '" + dateString + "'", e);
        }
    }

    @Override
    public String getText(String key, String defaultText, Object... arguments)
    {
        String pattern = bundle.getText(key, null);
        if (pattern == null)
        {
            return defaultText;
        }
        MessageFormat messageFormat = new MessageFormat(pattern, bundle.getLocal());
        return messageFormat.format(arguments, new StringBuffer(), null).toString();
    }

}
{'fraction_non_alphanumeric': 0.09143407122232916, 'fraction_numerical': 0.013474494706448507, 'mean_word_length': 2.6899408284023667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '7593769', 'n_tokens_mistral': 862, 'n_tokens_neox': 822, 'n_words': 194}