Example usage for org.apache.commons.configuration MapConfiguration interpolatedConfiguration

List of usage examples for org.apache.commons.configuration MapConfiguration interpolatedConfiguration

Introduction

In this page you can find the example usage for org.apache.commons.configuration MapConfiguration interpolatedConfiguration.

Prototype

public Configuration interpolatedConfiguration() 

Source Link

Document

Returns a configuration with the same content as this configuration, but with all variables replaced by their actual values.

Usage

From source file:com.tribloom.reposize.GetRepoSize.java

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    if (logger.isDebugEnabled()) {
        logger.debug("Entering GetRepoSize.executeImpl()");
    }// ww w.  jav  a2 s . co  m

    Map<String, Object> model = new HashMap<String, Object>();

    // Use Apache Configuration library to perform variable interpolation if
    // necessary
    MapConfiguration config = (MapConfiguration) ConfigurationConverter.getConfiguration(globalProperties);
    Configuration intConfig = config.interpolatedConfiguration();

    String contentStore = (String) intConfig.getProperty("dir.contentstore");
    String indexes = (String) intConfig.getProperty("dir.indexes");
    String indexesBackup = (String) intConfig.getProperty("dir.indexes.backup");

    if (logger.isDebugEnabled()) {
        logger.debug(" contentStorePath = " + contentStore);
        logger.debug(" indexes = " + indexes);
        logger.debug(" indexesBackup = " + indexesBackup);
    }

    try {
        /**
         * TODO: Figure if there's a need and a way to perform this size request on multiple
         * stores, configured with the Content Selector Service
         * 
         * Can do nodeService.getStores() to get the StoreRef's, but how
         * to retrieve contentService for these refs? Or does contentService
         * intelligently handle this?
         */
        long storeFreeSpace = contentService.getStoreFreeSpace();
        long storeTotalSpace = contentService.getStoreTotalSpace();

        if (logger.isDebugEnabled()) {
            logger.debug(" storeFreeSpace = " + storeFreeSpace);
            logger.debug(" storeTotalSpace = " + storeTotalSpace);
        }

        long contentStoreSize = getFileSize(new File(contentStore));

        if (logger.isDebugEnabled()) {
            logger.debug(" contentStoreSize = " + contentStoreSize);
        }

        long indexesSize = getFileSize(new File(indexes));
        long indexesBackupSize = getFileSize(new File(indexesBackup));

        if (logger.isDebugEnabled()) {
            logger.debug(" indexesSize = " + indexesSize);
            logger.debug(" indexesBackupSize = " + indexesBackupSize);
        }

        model.put("contentStorePath", contentStore);
        model.put("contentStoreSize", contentStoreSize);
        model.put("storeFreeSpace", storeFreeSpace);
        model.put("storeTotalSpace", storeTotalSpace);
        model.put("indexesPath", indexes);
        model.put("indexesSize", indexesSize);
        model.put("indexesBackupPath", indexesBackup);
        model.put("indexesBackupSize", indexesBackupSize);

    } catch (Exception e) {
        logger.error("Exception encountered during GetRepoSize webscript processing: ", e);
        status.setCode(Status.STATUS_INTERNAL_SERVER_ERROR);
        status.setException(e);
        status.setMessage(e.getMessage());
        status.setRedirect(false);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Exiting GetRepoSize.executeImpl()");
    }
    return model;
}