private void loadConfigurationManager() { log.trace(() -> "Initializing configuration cache."); @NotNull Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties() .setFileName(PROPERTIES_FILE)); try { this.config = builder.getConfiguration(); } catch (ConfigurationException e) { log.fatal(e); throw new RuntimeException("Couldnt load configuration file " + PROPERTIES_FILE); } }
/** * Save property for standalone profile. * * @param pair the pair */ public void savePropertyForStandaloneProfile(final Pair<String, String> pair) { try { final File file = getStandaloneProfileConfigurationDirectory(); final Parameters params = new Parameters(); final FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties().setFile(new File(file, getApplicationName() + ".properties"))); final Configuration config = builder.getConfiguration(); config.setProperty(pair.getKey(), pair.getValue()); builder.save(); } catch (final Exception e) { throw Throwables.propagate(e); } }
private static FileBasedConfiguration createPropertiesConfiguration(Reader reader) throws ConfigurationException, IOException { if (reader == null) { throw new NullPointerException("reader: null"); } FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(new Parameters() .properties() .setListDelimiterHandler(new DefaultListDelimiterHandler(','))); FileBasedConfiguration config = builder.getConfiguration(); config.read(reader); return config; }
private static FileBasedConfiguration createConfiguration(Reader reader) throws ConfigurationException { if (reader == null) { throw new NullPointerException("reader: null"); } FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(XMLConfiguration.class) .configure(new Parameters().xml()); FileBasedConfiguration fileBasedConfiguration = builder.getConfiguration(); FileHandler handler = new FileHandler(fileBasedConfiguration); handler.load(reader); return fileBasedConfiguration; }
@Override public void showBoard() { File paramFile = new File("config/mainboardfx.properties"); try { final FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class) .configure( new FileBasedBuilderParametersImpl().setFile(paramFile).setEncoding("utf8")); cfg = builder.getConfiguration(); } catch (ConfigurationException ex) { QLog.l().logger() .error("Не загружен файл конфигурации " + paramFile.getAbsolutePath(), ex); throw new ServerException( "Не загружен файл конфигурации " + paramFile.getAbsolutePath()); } super.showBoard(); }
/** * Instantiates a new config. */ private Config() { try { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class); builder.configure(params.fileBased().setFileName("nlp.properties") .setLocationStrategy(new ClasspathLocationStrategy())); configuration = builder.getConfiguration(); // Adding TEKSTO_HOME path to Configuration String homePath = System.getenv(TEKSTO_HOME); if (homePath != null && !homePath.isEmpty()) { configuration.setProperty(MODEL_PATH, homePath + "/Models"); } } catch (ConfigurationException e) { LOG.error(e, e); } }
@Test public void testOverride() { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties() .setFileName("file.properties")); Configuration config = null; try { config = builder.getConfiguration(); config.setProperty("somekey", "somevalue"); builder.save(); } catch (ConfigurationException e) { e.printStackTrace(); } }
private AliceRecognition() { try { CombinedConfiguration config = new CombinedConfiguration(new MergeCombiner()); config.addConfiguration(new SystemConfiguration()); config.addConfiguration(new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(new Parameters().properties().setFileName(ALICE_PROPERTIES)).getConfiguration()); this.enabled = config.getBoolean(ALICE_ENABLED, false); String url = config.getString(ALICE_SERVICE_URL, null); String accessToken = config.getString(ALICE_ACCESS_TOKEN, null); String command = config.getString(ALICE_COMMAND, null); if(enabled && !StringUtils.isEmpty(url) && !StringUtils.isEmpty(accessToken)) { this.client = new AliceClient(url, command); this.client.setAuthToken(accessToken); this.enabled = this.client.isAvailable(); } } catch (Exception e) { LOGGER.error("Unable to initialize Alice: " + e.getMessage()); } }
public static void init() throws ConfigurationException { configManager = new Configurations(); builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFile(App.appFileUtil.getHotkeysFile())); config = builder.getConfiguration(); loadHotkeys(); }
public static void init(String worldLocation) throws ConfigurationException { log.debug("World Location for properties: " + worldLocation); configManager = new Configurations(); if(worldLocation == null){ builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFileName(defaultWorldPropertiesLocation)); }else { builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFileName(worldLocation)); } config = builder.getConfiguration(); }
public static void init() throws ConfigurationException { configManager = new Configurations(); builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFile(App.appFileUtil.getAppPropFile())); config = builder.getConfiguration(); }
public static void firstInit() throws Exception{ configManager = new Configurations(); builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFileName("src/main/resources/app.properties")); config = builder.getConfiguration(); }
private PropertiesConfigurationSource(FileBasedConfiguration configuration, int priority) { if (configuration == null) { throw new NullPointerException("configuration: null"); } if (priority < 0) { throw new IllegalArgumentException("priority of a configuration cannot be negative"); } this.configuration = configuration; this.priority = priority; }
private XmlConfigurationSource(FileBasedConfiguration configuration, int priority) { if (configuration == null) { throw new NullPointerException("configuration: null"); } if (priority < 0) { throw new IllegalArgumentException("priority of a configuration cannot be negative"); } this.configuration = configuration; this.priority = priority; }
private Config() { // https://issues.apache.org/jira/browse/CONFIGURATION-677 /*BuilderParameters params = new Parameters().properties() .setFileName(CONFIG_NAME) .setLocationStrategy(new HomeDirectoryLocationStrategy()) .setEncoding("UTF-8");*/ // workaround: HomeDirectoryLocationStrategy location = new HomeDirectoryLocationStrategy(); File configFile = new File(location.getHomeDirectory(), CONFIG_NAME); BuilderParameters params = new Parameters().properties() .setFile(configFile) .setEncoding("UTF-8"); builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class, params.getParameters(), true); builder.setAutoSave(true); try { config = builder.getConfiguration(); logger.info("User configuration has been loaded from: {}", configFile); } catch(ConfigurationException cex) { logger.error("Error loading configuration", cex); throw new IllegalStateException("Error loading/creating configuration"); } }
/** * Instantiates a new config. */ private Config() { try { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class); builder.configure(params.fileBased().setFileName("pdf2xml.properties").setLocationStrategy(new ClasspathLocationStrategy())); configuration = builder.getConfiguration(); } catch (ConfigurationException e) { LOG.error(e, e); } }
private Configuration getHeapSpankJarConfiguration() throws ConfigurationException { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties() .setFileName(PROPERTIES_FILE) .setLocationStrategy(new ClasspathLocationStrategy()) ); Configuration config = builder.getConfiguration(); return config; }
private Configuration getHomeFolderConfiguration() throws ConfigurationException { File homeDir = new File( System.getProperty("user.home")); File heapSpankProperties = new File(homeDir, this.PROPERTIES_FILE); Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties() .setFile(heapSpankProperties)); return builder.getConfiguration(); }
private Configuration getCurrentFolderConfiguration() throws ConfigurationException { URL location = ApacheCommonsConfigFile.class.getProtectionDomain().getCodeSource().getLocation(); File heapSpankjarFile = new File(location.getFile()); File dirOfHeapSpankjarFile = new File(location.getFile()).getParentFile(); File heapSpankProperties = new File(dirOfHeapSpankjarFile, this.PROPERTIES_FILE); Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties() .setFile(heapSpankProperties)); return builder.getConfiguration(); }
private ApplicationConfig() { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class) .configure(params.properties() .setFileName("application.properties")); try { config = builder.getConfiguration(); } catch (ConfigurationException e) { logger.error("failed to load application.properties: {}", e, e.getMessage()); } }
/** * Adds the configuration stored on disk to the current set of parameters. The * file <code>fileName</code> must be a valid configuration file as per Javas * <code>Properties</code> class. * * @param fileName */ public static void setConfiguration(String fileName) { try { AptaLogger.log(Level.INFO, Configuration.class, "Reading configuration from file."); builder = new FileBasedConfigurationBuilder<org.apache.commons.configuration2.FileBasedConfiguration>( PropertiesConfiguration.class) .configure(new Parameters().properties().setFileName(fileName) .setListDelimiterHandler(new DefaultListDelimiterHandler(','))); // Create a composite configuration which allows to keep user parameters and defaults separated CompositeConfiguration cc = new CompositeConfiguration(); cc.addConfiguration(builder.getConfiguration(), true); // changes will be saved in the user config cc.addConfiguration(getDefaultParametersBuilder().getConfiguration(), false); parameters = cc; } catch (Exception e) { AptaLogger.log(Level.SEVERE, Configuration.class, "Error, could not read configuration file. Please check it for correctness"); AptaLogger.log(Level.SEVERE, Configuration.class, e); e.printStackTrace(); } // TODO: Sanity checks! }
/** * Creates an empty configuration and configures the class * @param filename location at which the config should be stored in the future */ public static void createConfiguration(Path filePath) { try { builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(new Parameters().properties() //.setFile(filePath.toFile()) .setListDelimiterHandler(new DefaultListDelimiterHandler(','))); org.apache.commons.configuration2.Configuration userParameters = builder.getConfiguration(); //We need to explicitly save the file before setting it in the builder, for whatever reason... builder.getFileHandler().save(filePath.toFile()); builder.getFileHandler().setFile(filePath.toFile()); // Create a composite configuration which allows to keep user parameters and defaults separated CompositeConfiguration cc = new CompositeConfiguration(); cc.addConfiguration(builder.getConfiguration(), true); // changes will be saved in the user config cc.addConfiguration(getDefaultParametersBuilder().getConfiguration(), false); parameters = cc; } catch (Exception e) { AptaLogger.log(Level.SEVERE, Configuration.class, "Error, could not create configuration file."); AptaLogger.log(Level.SEVERE, Configuration.class, e); e.printStackTrace(); } }