📄 localesloader.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Created on 2006/09/02
*
* @Author: Xiaojun Chen
* $Revision$ 1.0
*
*/
package eti.bi.common.Locale;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import eti.bi.exception.SysException;
public class LocalesLoader {
private static String m_DefinitionFileName;
private static String basePath;
private static Locales locales = new Locales();
public static void setBasePath(String aBasePath) {
basePath = aBasePath;
}
public static String getBasePath() {
return basePath;
}
public static void setDefinitionFile(String aFileName){
m_DefinitionFileName = aFileName;
}
public static String getDefinitionFile(){
return m_DefinitionFileName;
}
public static String readDefinitionFile() throws SysException
{
BufferedReader aBufferedReader = null;
try {
File aDefinitionFile = new File(m_DefinitionFileName);
if (!aDefinitionFile.exists())
{
throw new SysException("Workspace Definition file [" + aDefinitionFile + "] not found.");
}
aBufferedReader = new BufferedReader(new FileReader(aDefinitionFile));
StringBuffer aFileContent = new StringBuffer();
String aLine = null;
while ((aLine = aBufferedReader.readLine()) != null)
{
aFileContent.append(aLine+"\n");
}
return aFileContent.toString();
} catch (Exception e) {
throw new SysException("Error getting the definition file [" + m_DefinitionFileName +"]", e);
}finally
{
try
{
if (aBufferedReader!=null)
{
aBufferedReader.close();
}
}catch(IOException e)
{}
}
}
public static void loadLocales() throws SysException
{
DefaultHandler aHandler = new LocaleSAXHandler(basePath);
try {
String definitionString = readDefinitionFile();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
StringReader aStringReader = new StringReader(definitionString);
saxParser.parse(new InputSource(aStringReader), aHandler);
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void AddLocale(locale a_locale){
if(!a_locale.isvalid()){
return;
}
locales.AddLocale(a_locale);
}
public static void AddLocaleCurrent(locale a_locale){
if(!a_locale.isvalid()){
return;
}
locales.AddLocaleCurrent(a_locale);
}
public static Locales getLocales(){
return locales;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -