package com.vci.server.base.exception; import java.util.Locale; import com.vci.common.exception.LocaleCommonDisplay; import com.vci.common.exception.VciException; import com.vci.corba.common.VCIError; import com.vci.server.base.persistence.dao.HibernateSessionFactory; public class ExceptionLocalHandler { private static ExceptionLocalHandler instance = null; private ExceptionLocalHandler() { } public static synchronized ExceptionLocalHandler getInstance() { if (instance == null) { instance = new ExceptionLocalHandler(); } return instance; } public VCIError getClientString(VCIError vciError, String fileName) { VciException exp = new VciException(vciError.code, vciError.messages); String str = LocaleCommonDisplay.getI18nString(exp, fileName, getClientLocale()); vciError.code = str; return vciError; } /** * 获取国际化的错误提示信息,将其设置到PLMError的key中 * @param plmError * @return */ public VCIError getLocalString(VCIError vciError, String fileName) { VciException exp = new VciException(vciError.code, vciError.messages); String str = LocaleCommonDisplay.getI18nString(exp, fileName, getClientLocale()); vciError.code = str; return vciError; } private Locale getClientLocale() { Locale locale = null; try { if (HibernateSessionFactory.getVciSessionInfo() == null) { return Locale.getDefault(); } String language = HibernateSessionFactory.getVciSessionInfo().language; if (language == null || language.trim().equals("")) { language = Locale.getDefault().getLanguage(); } String country = HibernateSessionFactory.getVciSessionInfo().country; if (country == null || country.trim().equals("")) { country = Locale.getDefault().getCountry(); } locale = new Locale(language, country); } catch (Exception e) { e.printStackTrace(); locale = Locale.getDefault(); } return locale; } }