001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thomas Roger
016 */
017
018package org.nuxeo.ecm.csv;
019
020import java.io.Serializable;
021import java.util.Locale;
022
023import org.nuxeo.common.utils.i18n.I18NUtils;
024
025/**
026 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
027 * @since 5.7
028 */
029public class CSVImportLog implements Serializable {
030
031    private static final long serialVersionUID = 1L;
032
033    public enum Status {
034        SUCCESS, SKIPPED, ERROR
035    }
036
037    protected final long line;
038
039    protected final Status status;
040
041    protected final String message;
042
043    protected final String localizedMessage;
044
045    protected final String[] params;
046
047    public CSVImportLog(long line, Status status, String message, String localizedMessage, String... params) {
048        this.line = line;
049        this.status = status;
050        this.message = message;
051        this.localizedMessage = localizedMessage;
052        this.params = params;
053    }
054
055    public long getLine() {
056        return line;
057    }
058
059    public Status getStatus() {
060        return status;
061    }
062
063    public String getMessage() {
064        return message;
065    }
066
067    public String getLocalizedMessage() {
068        return localizedMessage;
069    }
070
071    public Object[] getLocalizedMessageParams() {
072        return params;
073    }
074
075    public String getI18nMessage(Locale locale) {
076        return I18NUtils.getMessageString("messages", getLocalizedMessage(), getLocalizedMessageParams(), locale);
077    }
078
079    public String getI18nMessage() {
080        return getI18nMessage(Locale.ENGLISH);
081    }
082
083    public boolean isSuccess() {
084        return status == Status.SUCCESS;
085    }
086
087    public boolean isSkipped() {
088        return status == Status.SKIPPED;
089    }
090
091    public boolean isError() {
092        return status == Status.ERROR;
093    }
094}