All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.supercsv.ext.localization.CsvMessageConverter Maven / Gradle / Ivy

Go to download

CSVのJavaライブラリであるSuperCSVに、アノテーション機能を追加したライブラリです。

There is a newer version: 2.3
Show newest version
/*
 * MessageConverter.java
 * created in 2013/03/09
 *
 * (C) Copyright 2003-2013 GreenDay Project. All rights reserved.
 */
package org.supercsv.ext.localization;

import java.util.ArrayList;
import java.util.List;

/**
 *
 *
 * @author T.TSUCHIE
 *
 */
public class CsvMessageConverter {
    
    private MessageResolver messageResolver;
    
    public CsvMessageConverter() {
        this.messageResolver = new ResourceBundleMessageResolver();
        
    }
    
    public CsvMessageConverter(final MessageResolver messageResolver) {
        this.messageResolver = messageResolver;
    }
    
    public String convertMessage(final CsvMessage error) {
        
        if(error == null) {
            throw new NullPointerException("error should not be null.");
        }
        
        final String msg = messageResolver.getMessage(error.getCode());
        return MapVariableInterpolator.interpolate(msg, error.getVariables());
        
    }
    
    public List convertMessage(final List errors) {
        
        if(errors == null) {
            throw new NullPointerException("errors should not be null.");
        }
        
        List messages = new ArrayList();
        for(CsvMessage error : errors) {
            messages.add(convertMessage(error));
        }
        return messages;
        
    }
    
    public MessageResolver getMessageResolver() {
        return messageResolver;
    }
    
    public void setMessageResolver(final MessageResolver messageResolver) {
        this.messageResolver = messageResolver;
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy