use of jp.ossc.nimbus.util.ArrayProperties in project nimbus by nimbus-org.
the class ResourceBundlePropertiesFactoryService method setupDirPropList.
//
/**
* Method ディレクトリ指定でプロパティファイルを抽出する.
* @param item
*/
protected void setupDirPropList(String item) {
String dirPath = StringOperator.replaceString(item, C_BK_SRASH, C_SRASH);
if (!item.endsWith(C_SRASH)) {
dirPath = dirPath + C_SRASH;
}
File dirPathFile = new File(dirPath);
int pos = dirPathFile.getAbsolutePath().length();
RecurciveSearchFile file = new RecurciveSearchFile(dirPath);
ExtentionFileFilter filter = new ExtentionFileFilter(C_PROP_EXT, true);
File[] list = file.listAllTreeFiles(filter);
for (int cnt = 0; cnt < list.length; cnt++) {
FileInputStream stream;
try {
stream = new FileInputStream(list[cnt]);
} catch (FileNotFoundException e) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new ServiceException("PROPFACTORY002", "FileNotFoundException name = " + list[cnt], e);
}
ArrayProperties prop = new ArrayProperties(mEncode);
try {
prop.load(stream);
} catch (IOException e) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new ServiceException("PROPFACTORY003", "IOException filename = " + list[cnt], e);
}
try {
stream.close();
} catch (IOException e) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new ServiceException("PROPFACTORY004", "IOException filename = " + list[cnt], e);
}
String path = list[cnt].getAbsolutePath();
path = path.substring(pos + 1, path.length() - C_PROP_EXT.length());
path = StringOperator.replaceString(path, C_BK_SRASH, C_DOT);
path = StringOperator.replaceString(path, C_SRASH, C_DOT);
mPropHash.put(path, prop);
}
}
use of jp.ossc.nimbus.util.ArrayProperties in project nimbus by nimbus-org.
the class ResourceBundlePropertiesFactoryService method setupJarPropList.
/**
* Jarファイルからプロパティの抽出を行う.
* @param item
*/
protected void setupJarPropList(String item) {
String dirPath = StringOperator.replaceString(item, C_BK_SRASH, C_SRASH);
JarFile jar;
try {
jar = new JarFile(dirPath);
} catch (IOException e) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new ServiceException("PROPFACTORY005", "IOException filename = " + dirPath, e);
}
for (Enumeration iterator = jar.entries(); iterator.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) iterator.nextElement();
String name = entry.getName();
if (!entry.isDirectory() && name.endsWith(C_PROP_EXT)) {
InputStream is = null;
try {
is = jar.getInputStream(entry);
} catch (IOException e) {
// $NON-NLS-1$//$NON-NLS-2$
throw new ServiceException("PROPFACTORY006", "IOException filename = " + dirPath, e);
}
ArrayProperties prop = new ArrayProperties(mEncode);
try {
prop.load(is);
} catch (IOException e) {
// $NON-NLS-1$//$NON-NLS-2$
throw new ServiceException("PROPFACTORY007", "IOException filename = " + dirPath, e);
}
name = StringOperator.replaceString(name, C_SRASH, C_DOT);
name = name.substring(0, name.length() - C_PROP_EXT.length());
mPropHash.put(name, prop);
try {
is.close();
} catch (IOException e) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new ServiceException("PROPFACTORY008", "IOException filename = " + dirPath, e);
}
}
}
}
use of jp.ossc.nimbus.util.ArrayProperties in project nimbus by nimbus-org.
the class ResourceBundlePropertiesFactoryService method loadProperties.
/**
* @see jp.ossc.nimbus.service.properties.PropertiesFactory#loadProperties(String, Locale)
*/
public Properties loadProperties(String propName, Locale lo) {
ArrayProperties retProp = null;
synchronized (mPropHash) {
if (this.mRefreshPlanTime.after(this.mRefreshedTime)) {
if (this.mRefreshPlanTime.before(new Date())) {
refresh();
}
}
while (true) {
StringBuilder propKey = new StringBuilder(propName);
// 1baseclass + "_" + language1 + "_" + country1 + "_" + variant1 + ".properties"
propKey.append(C_UNDER_SCORE).append(lo.getLanguage()).append(C_UNDER_SCORE).append(lo.getCountry()).append(C_UNDER_SCORE).append(lo.getVariant());
retProp = (ArrayProperties) mPropHash.get(propKey.toString());
if (retProp != null) {
break;
}
// baseclass + "_" + language1 + "_" + country1 + ".properties"
propKey = new StringBuilder(propName);
propKey.append(C_UNDER_SCORE).append(lo.getLanguage()).append(C_UNDER_SCORE).append(lo.getCountry());
retProp = (ArrayProperties) mPropHash.get(propKey.toString());
if (retProp != null) {
break;
}
// baseclass + "_" + language1 + ".properties"
propKey = new StringBuilder(propName);
propKey.append(C_UNDER_SCORE).append(lo.getLanguage());
retProp = (ArrayProperties) mPropHash.get(propKey.toString());
if (retProp != null) {
break;
}
if (!lo.equals(Locale.getDefault())) {
lo = Locale.getDefault();
propKey = new StringBuilder(propName);
// 1baseclass + "_" + language1 + "_" + country1 + "_" + variant1 + ".properties"
propKey.append(C_UNDER_SCORE).append(lo.getLanguage()).append(C_UNDER_SCORE).append(lo.getCountry()).append(C_UNDER_SCORE).append(lo.getVariant());
retProp = (ArrayProperties) mPropHash.get(propKey.toString());
if (retProp != null) {
break;
}
// baseclass + "_" + language1 + "_" + country1 + ".properties"
propKey = new StringBuilder(propName);
propKey.append(C_UNDER_SCORE).append(lo.getLanguage()).append(C_UNDER_SCORE).append(lo.getCountry());
retProp = (ArrayProperties) mPropHash.get(propKey.toString());
if (retProp != null) {
break;
}
// baseclass + "_" + language1 + ".properties"
propKey = new StringBuilder(propName);
propKey.append(C_UNDER_SCORE).append(lo.getLanguage());
retProp = (ArrayProperties) mPropHash.get(propKey.toString());
if (retProp != null) {
break;
}
}
retProp = (ArrayProperties) mPropHash.get(propName);
break;
}
}
return (Properties) retProp;
}
use of jp.ossc.nimbus.util.ArrayProperties in project nimbus by nimbus-org.
the class ArrayPropertiesTest method testArrayPropertiesEncodedProperties.
/*
* void ArrayProperties のテスト(EncodedProperties)
*/
public void testArrayPropertiesEncodedProperties() throws IOException {
prop = new ArrayProperties();
prop.loadFromFile("src/test/resources/jp/ossc/nimbus/util/test.properties");
ArrayList list = prop.getAryProperty("test");
assertEquals(list.size(), 3);
}
Aggregations