Search in sources :

Example 1 with ArrayProperties

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);
    }
}
Also used : RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) ServiceException(jp.ossc.nimbus.lang.ServiceException) ArrayProperties(jp.ossc.nimbus.util.ArrayProperties) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File) RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) ExtentionFileFilter(jp.ossc.nimbus.io.ExtentionFileFilter) FileInputStream(java.io.FileInputStream)

Example 2 with ArrayProperties

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);
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ServiceException(jp.ossc.nimbus.lang.ServiceException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayProperties(jp.ossc.nimbus.util.ArrayProperties) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) JarFile(java.util.jar.JarFile)

Example 3 with ArrayProperties

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;
}
Also used : ArrayProperties(jp.ossc.nimbus.util.ArrayProperties) Properties(java.util.Properties) ArrayProperties(jp.ossc.nimbus.util.ArrayProperties) EncodedProperties(jp.ossc.nimbus.util.EncodedProperties) Date(java.util.Date)

Example 4 with ArrayProperties

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);
}
Also used : ArrayProperties(jp.ossc.nimbus.util.ArrayProperties)

Aggregations

ArrayProperties (jp.ossc.nimbus.util.ArrayProperties)4 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 JarFile (java.util.jar.JarFile)2 ServiceException (jp.ossc.nimbus.lang.ServiceException)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 Enumeration (java.util.Enumeration)1 Properties (java.util.Properties)1 ZipEntry (java.util.zip.ZipEntry)1 ExtentionFileFilter (jp.ossc.nimbus.io.ExtentionFileFilter)1 RecurciveSearchFile (jp.ossc.nimbus.io.RecurciveSearchFile)1 EncodedProperties (jp.ossc.nimbus.util.EncodedProperties)1