blob: fe727b385562637e14cd7ae1ab76d826e44036c1 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2016 ALL4TEC & CEA LIST.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ALL4TEC & CEA LIST - initial API and implementation
******************************************************************************/
package org.polarsys.esf.core.common.messages;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.apache.commons.lang3.StringUtils;
/**
*
* Class generated by Eclipse to externalise Strings.
*
* @author $Author: jdumont $
* @version $Revision: 83 $
*/
public class Messages {
/** Bundle name. */
public static final String BUNDLE_NAME = "src.main.resources.properties.nls.messages"; //$NON-NLS-1$
/** Formatted error identifier. */
private static final String ERROR_STRING = "!"; //$NON-NLS-1$
/** Resource bundle built on bundle name. */
private ResourceBundle mResourceBundle = null;
/**
* Private constructor to avoid instantiation.
*
* @param pResourceBundle Bundle used to find resource
*/
public Messages(final ResourceBundle pResourceBundle) {
mResourceBundle = pResourceBundle;
}
/**
* Method used to get an externalised string from a key. Return a generic error message if no correspondence found.
*
* @param pKey Key value to search in bundle
* @return An externalised String
*/
public String getString(final String pKey) {
String vResult = StringUtils.EMPTY;
try {
vResult = mResourceBundle.getString(pKey);
} catch (final MissingResourceException pException) {
vResult = ERROR_STRING + pKey + ERROR_STRING;
}
return vResult;
}
/**
* Method used to get an externalised string from a key and substitutions array. Return a generic error message if
* no correspondence is found.
*
* @param pKey Key value to search in bundle
* @param pSubstitutionsArray Array containing all substitution
* @return An externalised String
*/
public String getString(final String pKey, final Object[] pSubstitutionsArray) {
String vResult = StringUtils.EMPTY;
try {
vResult = MessageFormat.format(getString(pKey), pSubstitutionsArray);
} catch (final IllegalArgumentException pException) {
vResult = ERROR_STRING + pKey + ERROR_STRING;
}
return vResult;
}
}