Example usage for org.apache.commons.configuration FileConfiguration getFile

List of usage examples for org.apache.commons.configuration FileConfiguration getFile

Introduction

In this page you can find the example usage for org.apache.commons.configuration FileConfiguration getFile.

Prototype

File getFile();

Source Link

Document

Return the file where the configuration is stored.

Usage

From source file:com.twitter.distributedlog.config.ConfigurationSubscription.java

@VisibleForTesting
void reload() {/*w  ww.j  a va2s  . com*/
    // No-op if already loaded.
    if (!initConfig()) {
        return;
    }
    // Reload if config exists.
    Set<String> confKeys = Sets.newHashSet();
    for (FileConfiguration fileConfig : fileConfigs) {
        LOG.debug("Check and reload config, file={}, lastModified={}", fileConfig.getFile(),
                fileConfig.getFile().lastModified());
        fileConfig.reload();
        // load keys
        Iterator keyIter = fileConfig.getKeys();
        while (keyIter.hasNext()) {
            String key = (String) keyIter.next();
            confKeys.add(key);
        }
    }
    // clear unexisted keys
    Iterator viewIter = viewConfig.getKeys();
    while (viewIter.hasNext()) {
        String key = (String) viewIter.next();
        if (!confKeys.contains(key)) {
            clearViewProperty(key);
        }
    }
    LOG.info("Reload features : {}", confKeys);
    // load keys from files
    for (FileConfiguration fileConfig : fileConfigs) {
        try {
            loadView(fileConfig);
        } catch (Exception ex) {
            if (!fileNotFound(ex)) {
                LOG.error("Config reload failed for file {}", fileConfig.getFileName(), ex);
            }
        }
    }
    for (ConfigurationListener listener : confListeners) {
        listener.onReload(viewConfig);
    }
}

From source file:com.manydesigns.portofino.actions.admin.SettingsAction.java

@Button(list = "settings", key = "update", order = 1, type = Button.TYPE_PRIMARY)
public Resolution update() {
    setupFormAndBean();//from   w w w  . ja  va  2s.c o m
    form.readFromRequest(context.getRequest());
    if (form.validate()) {
        logger.debug("Applying settings to model");
        try {
            FileConfiguration fileConfiguration = (FileConfiguration) configuration;
            Settings settings = new Settings();
            form.writeToObject(settings);
            fileConfiguration.setProperty(PortofinoProperties.APP_NAME, settings.appName);
            fileConfiguration.setProperty(PortofinoProperties.LANDING_PAGE, settings.landingPage);
            fileConfiguration.setProperty(PortofinoProperties.LOGIN_PAGE, settings.loginPage);
            if (!settings.preloadGroovyPages
                    || fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES) != null) {
                fileConfiguration.setProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES,
                        settings.preloadGroovyPages);
            }
            if (!settings.preloadGroovyClasses
                    || fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES) != null) {
                fileConfiguration.setProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES,
                        settings.preloadGroovyClasses);
            }
            fileConfiguration.save();
            logger.info("Configuration saved to " + fileConfiguration.getFile().getAbsolutePath());
        } catch (Exception e) {
            logger.error("Configuration not saved", e);
            SessionMessages
                    .addErrorMessage(ElementsThreadLocals.getText("the.configuration.could.not.be.saved"));
            return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp");
        }
        SessionMessages.addInfoMessage(ElementsThreadLocals.getText("configuration.updated.successfully"));
        return new RedirectResolution(this.getClass());
    } else {
        return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp");
    }
}

From source file:nl.isaac.dotcms.plugin.configuration.ConfigurationFactory.java

/**
 * Create a configuration via an id (<code>key</code>, only used for logging), the files to load configuration (<code>main</code>), the various property providers (<code>propertyProviders</code>) and configuration providers (<code>configurationProviders</code>).
 * @param key/*from ww w .  ja va 2s  . c o  m*/
 * @param main
 * @param propertyProviders
 * @param configurationProviders
 * @return
 * @throws ConfigurationException
 */
public static CustomConfiguration createConfiguration(String key, String main,
        Map<String, StrLookup> propertyProviders, Map<String, ConfigurationProvider> configurationProviders)
        throws ConfigurationException {
    CustomConfigurationBuilder confBuilder = new CustomConfigurationBuilder();
    confBuilder.setAutoSave(false);

    for (Map.Entry<String, ConfigurationProvider> provider : configurationProviders.entrySet()) {
        confBuilder.addConfigurationProvider(provider.getKey(), provider.getValue());
    }

    for (Map.Entry<String, StrLookup> provider : propertyProviders.entrySet()) {
        confBuilder.getInterpolator().registerLookup(provider.getKey(), provider.getValue());
    }

    main = String.valueOf(PropertyConverter.interpolate(main, confBuilder));
    confBuilder.load(main);

    CustomConfiguration conf = new CustomConfiguration(confBuilder.getConfiguration(false));
    for (FileConfiguration f : conf.getLoadedFileConfigurations()) {
        Logger.debug(ConfigurationService.class, "Loaded configuration file: " + f.getFile() + " for: " + key);
    }
    Logger.debug(ConfigurationService.class, "Loaded " + key + "configuration: " + conf.toStringTree());

    return conf;
}

From source file:org.betaconceptframework.astroboa.engine.definition.ContentDefinitionConfiguration.java

private void feedParserWithUserDefinedSchemas(XSOMParser xsomParser,
        List<FileConfiguration> repositoryDefinitionFileConfigurations) {

    List<String> absolutePathsOfFilesToExclude = new ArrayList<String>();

    boolean feedParser = true;

    while (feedParser) {

        feedParser = false;/*w  w w .  j a  va2 s  .  c  o m*/

        //Create XSOM Parser
        if (xsomParser == null) {
            xsomParser = createXsomParser();
        }

        for (FileConfiguration fileConf : repositoryDefinitionFileConfigurations) {
            if (fileConf.getFile() == null) {
                logger.warn(
                        "Found empty file configuration. This means that one of the XSD provided is not a valid xml. Parsing will continue for the rest of the xsds");
            } else {

                String absolutePath = fileConf.getFile().getAbsolutePath();

                if (!absolutePathsOfFilesToExclude.contains(absolutePath)) {

                    logger.debug("Reloadding and parsing file {}", absolutePath);

                    try {
                        fileConf.reload();
                        xsomParser.parse(fileConf.getFile());
                        definitionVisitor.addXMLSchemaDefinitionForFileName(
                                FileUtils.readFileToByteArray(fileConf.getFile()),
                                StringUtils.substringAfterLast(absolutePath, File.separator));
                    } catch (Exception e) {
                        //Just issue a warning
                        logger.warn("Parse error for definition file " + absolutePath
                                + " This file is excluded from building Astroboa Definitions", e);

                        //we need to feed parser again since it sets an error flag to true 
                        //and does not produce any schemas at all.
                        feedParser = true;
                        absolutePathsOfFilesToExclude.add(absolutePath);
                        xsomParser = null;
                        definitionVisitor.clear();
                        break;
                    }
                }
            }
        }
    }

}

From source file:org.glite.slcs.shibclient.metadata.ShibbolethClientMetadata.java

/**
 * Parses the <ShibbolethClientMetadata> element and return a map of (id,idpObject)
 * @return a Map of (idpID,idpObject)/*from   w w  w .j  a va 2  s. c o m*/
 * @throws SLCSConfigurationException
 */
private Map<String, Provider> parseProviders() throws SLCSConfigurationException {
    Map<String, Provider> entities = new HashMap<String, Provider>();
    LOG.debug("get configuration subset: ShibbolethClientMetadata");
    Configuration metadata = getConfiguration().subset("ShibbolethClientMetadata");
    // external metadata defined with filename= attribute?
    String metadataFilename = metadata.getString("[@filename]");
    LOG.debug("metadata filename=" + metadataFilename);
    String metadataUrl = metadata.getString("[@url]");
    LOG.debug("metadata url=" + metadataUrl);
    if (metadataFilename != null) {
        // load external metadata file       
        try {
            LOG.info("load metadata from file: " + metadataFilename);
            FileConfiguration metadataFileConfiguration = loadConfiguration(metadataFilename);
            metadataSource_ = metadataFileConfiguration.getFile().getAbsolutePath();
            metadata = metadataFileConfiguration;
        } catch (SLCSConfigurationException e) {
            LOG.error("Failed to load external ShibbolethClientMetadata: " + metadataFilename, e);
            throw e;
        }
    }
    // check for metadata url and download
    else if (metadataUrl != null) {
        // download external metadata file
        try {
            URL url = new URL(metadataUrl);
            LOG.info("download metadata from url: " + url);
            // httpclient is used to download the config
            metadata = downloadConfiguration(url);
            metadataSource_ = metadataUrl;
        } catch (MalformedURLException mue) {
            LOG.error("Invalid URL for external ShibbolethClientMetadata: " + metadataUrl, mue);
            throw new SLCSConfigurationException(
                    "ShibbolethClientMetadata url=" + metadataUrl + " parameter is invalid", mue);
        } catch (SLCSConfigurationException sce) {
            LOG.error("Failed to download ShibbolethClientMetadata from: " + metadataUrl, sce);
            throw sce;
        }
    } else {
        LOG.info("inline metadata from: " + getFilename());
        metadataSource_ = getFilename();

    }
    // process metadata
    String name = null;
    String url = null;
    String id = null;
    Configuration config = null;
    // SLCS SP
    config = metadata.subset("ServiceProvider");
    if (!config.isEmpty()) {
        LOG.debug("ServiceProvider element found");
        id = config.getString("[@id]");
        if (id == null || id.equals("")) {
            id = DEFAULT_SLCS_PROVIDERID;
        }
        this.slcsProviderId_ = id;
        name = config.getString("name");
        url = config.getString("url");
        ServiceProvider sp = new ServiceProvider(id, name, url);
        LOG.debug("add " + sp);
        entities.put(id, sp);
    } else {
        throw new SLCSConfigurationException("ServiceProvider element not found in metadata");
    }
    // All IdPs
    Configuration idpsConfig = metadata.subset("IdentityProviders");
    if (idpsConfig.isEmpty()) {
        throw new SLCSConfigurationException("IdentityProviders element not found in metadata");
    }
    List<String> idps = idpsConfig.getList("IdentityProvider[@id]");
    int nIdp = idps.size();
    if (nIdp < 1) {
        throw new SLCSConfigurationException("No IdentityProvider element found in metadata");
    }
    LOG.debug(nIdp + " IdentityProvider elements found");
    for (int i = 0; i < nIdp; i++) {
        config = idpsConfig.subset("IdentityProvider(" + i + ")");
        id = config.getString("[@id]");
        name = config.getString("name");
        url = config.getString("url");
        String authTypeName = config.getString("authentication[@type]");
        String authUrl = config.getString("authentication.url");
        if (authUrl == null) {
            authUrl = url;
        }
        IdentityProvider idp = new IdentityProvider(id, name, url, authTypeName, authUrl);
        // optional entityID for SAML2 support
        String entityID = config.getString("[@entityID]");
        if (entityID != null) {
            idp.setEntityID(entityID);
        }
        if (idp.getAuthType() == IdentityProvider.SSO_AUTHTYPE_CAS
                || idp.getAuthType() == IdentityProvider.SSO_AUTHTYPE_PUBCOOKIE
                || idp.getAuthType() == IdentityProvider.SSO_AUTHTYPE_FORM) {
            // read form name and username and password field names
            String formName = config.getString("authentication.form[@name]", "");
            idp.setAuthFormName(formName);
            String formUsername = config.getString("authentication.form.username");
            idp.setAuthFormUsername(formUsername);
            String formPassword = config.getString("authentication.form.password");
            idp.setAuthFormPassword(formPassword);
        } else {
            // basic or ntlm
            String realm = config.getString("authentication.realm");
            idp.setAuthRealm(realm);
        }
        LOG.debug("add " + idp);
        entities.put(id, idp);
    }
    return entities;
}

From source file:org.soaplab.services.Config.java

/**************************************************************************
 *
 **************************************************************************/
private static boolean isExistingConfig(FileConfiguration cfg) {
    if (cfg.getFile() == null)
        return false;
    String filename = cfg.getFile().getAbsolutePath();
    if (configFilenames.contains(filename))
        return true;
    configFilenames.add(filename);/*from  w ww . j  a va2 s. c om*/
    return false;
}