use of java.text.MessageFormat in project translationstudio8 by heartsome.
the class AbstractShieldCommandStartup method readUnusedCommandFromFile.
@SuppressWarnings("unchecked")
protected Set<String> readUnusedCommandFromFile(String relativePath) {
Set<String> set = Collections.EMPTY_SET;
File file = ShieldActivator.getFile(relativePath);
if (file != null) {
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line = null;
set = new HashSet<String>();
while ((line = br.readLine()) != null) {
// 忽略以 # 开头注释行
if (line.startsWith("#"))
continue;
line = line.trim();
// 忽略空行
if (line.length() == 0)
continue;
set.add(line);
}
} catch (FileNotFoundException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("shield.AbstractShieldCommandStartup.logger1");
Object[] args = { file.getAbsolutePath() };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (IOException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("shield.AbstractShieldCommandStartup.logger2");
Object[] args = { file.getAbsolutePath() };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("shield.AbstractShieldCommandStartup.logger3");
Object[] args = { file.getAbsolutePath() };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
}
}
}
}
return set;
}
use of java.text.MessageFormat in project translationstudio8 by heartsome.
the class ShieldActivator method getFile.
/**
* 根据相对于插件根目录的相对路径,在插件中查找相应的文件,查找成功则返回对应的文件对象
* @param relativePath
* 对于插件根目录的相对路径
* @return 查找成功则返回对应的文件对象,否则返回 NULL;
*/
public static File getFile(String relativePath) {
File file = null;
URL langCodesURL = plugin.getBundle().getEntry(relativePath);
if (langCodesURL != null) {
try {
file = new File(FileLocator.toFileURL(langCodesURL).getPath());
} catch (Exception e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("shield.ShieldActivator.logger1");
Object[] args = { relativePath };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
}
}
return file;
}
use of java.text.MessageFormat in project translationstudio8 by heartsome.
the class TextUtil method loadISOLang.
private static void loadISOLang(String strLangFile) {
if (strLangFile == null) {
return;
}
ISOLang = new Hashtable<String, String>();
VTDGen vg = new VTDGen();
// vg.setDoc(strLangFile.getBytes());
try {
vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(strLangFile)));
vg.parse(true);
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/languages/lang");
int codeIndex;
String code = null;
String langName;
while ((ap.evalXPath()) != -1) {
codeIndex = vn.getAttrVal("code");
if (codeIndex != -1) {
code = vn.toString(codeIndex);
}
langName = vu.getElementPureText();
if (code != null && langName != null) {
ISOLang.put(code, langName);
}
}
ap.resetXPath();
} catch (NavException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathEvalException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EncodingException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EOFException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EntityException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (ParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (IOException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} finally {
vg.clear();
}
}
use of java.text.MessageFormat in project translationstudio8 by heartsome.
the class TextUtil method loadLanguages.
private static void loadLanguages() {
descriptions = null;
isBidi = null;
descriptions = new Hashtable<String, String>();
isBidi = new Hashtable<String, String>();
String strFile = CoreActivator.LANGUAGE_CODE_PATH;
VTDGen vg = new VTDGen();
try {
vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(strFile)));
vg.parse(true);
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/languages/lang");
int codeIndex;
String code = null;
int bidiIndex;
String bidi = null;
String langName;
while ((ap.evalXPath()) != -1) {
codeIndex = vn.getAttrVal("code");
if (codeIndex != -1) {
code = vn.toString(codeIndex);
}
bidiIndex = vn.getAttrVal("bidi");
if (bidiIndex != -1) {
bidi = vn.toString(bidiIndex);
}
langName = vu.getElementPureText();
if (code != null && langName != null) {
descriptions.put(code, langName);
}
if (code != null && bidi != null) {
isBidi.put(code, bidi);
}
}
ap.resetXPath();
} catch (NavException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathEvalException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EncodingException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EOFException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EntityException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (ParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (IOException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} finally {
vg.clear();
}
}
use of java.text.MessageFormat in project translationstudio8 by heartsome.
the class TextUtil method loadCountries.
private static void loadCountries() {
String strFile = CoreActivator.ISO3166_1_PAHT;
countries = new Hashtable<String, String>();
VTDGen vg = new VTDGen();
try {
vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(strFile)));
vg.parse(true);
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/ISO_3166-1_List_en/ISO_3166-1_Entry");
while ((ap.evalXPath()) != -1) {
countries.put(vu.getChildContent("ISO_3166-1_Alpha-2_Code_element"), vu.getChildContent("ISO_3166-1_Country_name"));
}
ap.resetXPath();
} catch (NavException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathEvalException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EncodingException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EOFException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EntityException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (ParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (IOException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} finally {
vg.clear();
}
}
Aggregations