Example usage for org.springframework.util PropertiesPersister loadFromXml

List of usage examples for org.springframework.util PropertiesPersister loadFromXml

Introduction

In this page you can find the example usage for org.springframework.util PropertiesPersister loadFromXml.

Prototype

void loadFromXml(Properties props, InputStream is) throws IOException;

Source Link

Document

Load properties from the given XML InputStream into the given Properties object.

Usage

From source file:com.sfxie.extension.spring4.properties.PropertiesLoaderUtils.java

/**
 * Actually load properties from the given EncodedResource into the given Properties instance.
 * @param props the Properties instance to load into
 * @param resource the resource to load from
 * @param persister the PropertiesPersister to use
 * @throws IOException in case of I/O errors
 *//*from   w  w w .  j av  a  2  s.c  om*/
static void fillProperties(Properties props, EncodedResource resource, PropertiesPersister persister)
        throws IOException {

    InputStream stream = null;
    Reader reader = null;
    try {
        String filename = resource.getResource().getFilename();
        if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) {
            stream = resource.getInputStream();
            persister.loadFromXml(props, stream);
        } else if (resource.requiresReader()) {
            reader = resource.getReader();
            persister.load(props, reader);
        } else {
            stream = resource.getInputStream();
            persister.load(props, stream);
        }
    } finally {
        if (stream != null) {
            stream.close();
        }
        if (reader != null) {
            reader.close();
        }
    }
}