public Swagger2MarkupConfigBuilder() { this(new PropertiesConfiguration()); }
public static void setOption(String pName, String sValue) { SXOPTIONS.setProperty(pName, sValue); }
@Override public synchronized String currentConfig() { PropertiesConfiguration saver = new PropertiesConfiguration(); StringWriter writer = new StringWriter(); saver.copy(config); try { saver.write(writer); } catch (Exception e) { throw new MetricsConfigException("Error stringify config", e); } return writer.toString(); }
for (String fname : fileNames) { try { PropertiesConfiguration pcf = new PropertiesConfiguration(); FileHandler fh = new FileHandler(pcf); fh.setFileName(fname); fh.load(); Configuration cf = pcf.interpolatedConfiguration(); LOG.info("Loaded properties from {}", fname); if (LOG.isDebugEnabled()) { Joiner.on(",").join(fileNames)); return new MetricsConfig(new PropertiesConfiguration(), prefix);
@Override public void scrubRegistrationProperties() { if (!exist()) { return; } try { PropertiesConfiguration config = new PropertiesConfiguration(); config.setIOFactory(new FilteringOutputWriterFactory()); PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(); layout.setLineSeparator("\n"); layout.load(config, reader()); try (FileWriter out = new FileWriter(this.configFile)) { layout.save(config, out); } loadProperties(); } catch (ConfigurationException | IOException e) { LOG.warn("[Agent Auto Registration] Unable to scrub registration key.", e); } }
public static void loadResource(InputStream stream, String resourceName) { try { PropertiesConfiguration props = new PropertiesConfiguration(); props.read(new InputStreamReader(stream)); config.append(props); } catch (IOException | ConfigurationException ex) { throw new RuntimeException("Failed to load config resource: " + resourceName, ex); } log.debug("Configuration stream loaded: {}", resourceName); }
public BinanceAutoBlacklist() { cache = new HashMap<>(); scheduler = Executors.newSingleThreadScheduledExecutor(); settings = new PropertiesConfiguration(); PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(); settings.setLayout(layout); if (!settingsFile.exists()) { settings.setProperty("enabled", enabled = true); settings.setProperty("interval", interval = 30); settings.setProperty("market", market = "BTC"); settings.setProperty("days", days = 14); settings.setProperty("clear", clear = true); try (FileWriter fw = new FileWriter(settingsFile, false)) { settings.write(fw); } catch (ConfigurationException | IOException e) { LOGGER.log(Level.WARNING, "Failed to save " + settingsFile.getName(), e); } LOGGER.info("Created " + settingsFile.getPath()); currentInterval = interval; start(); } else { updateSettings(); } }
private void writeNLP(final String name, final boolean zipConfig, final String projectVersion, final String productVersion) throws IOException { File nlp = new File(nlProjectFolder, name + ".nlp"); if (!nlp.exists() && !nlp.createNewFile()) { logger.error("Error, cannot create the NLP file"); } if (!nlp.isFile()) { throw new IllegalArgumentException("NLP file must be a file"); } PropertiesConfiguration nlpProperties = new PropertiesConfiguration(); nlpProperties.getLayout().setGlobalSeparator("="); nlpProperties.addProperty("project.name", name); nlpProperties.addProperty("project.version", projectVersion); nlpProperties.addProperty("project.original.version", projectVersion); nlpProperties.addProperty("product.name", "NeoLoad"); nlpProperties.addProperty("product.original.name", "NeoLoad"); nlpProperties.addProperty("product.version", productVersion); nlpProperties.addProperty("product.original.version", productVersion); nlpProperties.addProperty("project.id", UUID.randomUUID().toString()); nlpProperties.addProperty("project.config.path", zipConfig ? CONFIG_ZIP : CONFIG_FOLDER); nlpProperties.addProperty("project.config.storage", zipConfig ? "ZIP" : "FOLDER"); nlpProperties.addProperty("team.server.enabled", "false"); try (final Writer out = new FileWriter(nlp)) { nlpProperties.setHeader("Project description file"); nlpProperties.write(out); } catch (ConfigurationException e) { logger.error("Error while saving NLP file", e); } }
public Map<String, String> getKeysAndValues() { Map<String, String> kvp = newLinkedHashMap(); PropertiesConfiguration config = new PropertiesConfiguration(); PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(); try (InputStream input = new FileInputStream(props)) { layout.load(config, new InputStreamReader(input, UTF_8)); config.getKeys().forEachRemaining(item -> kvp.put(item, config.getString(item))); } catch (Exception e) { LOGGER.error(e.getMessage()); } return kvp; }
public void setValue(String property, String propertyValue) { PropertiesConfiguration config = new PropertiesConfiguration(); PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(); try (InputStream input = new FileInputStream(props)) { layout.load(config, new InputStreamReader(input, UTF_8)); config.setProperty(property, propertyValue); layout.save(config, new FileWriter(props, false)); } catch (Exception e) { LOGGER.error(e.getMessage()); } } }
public String getValue(String property) { String propertyValue = EMPTY; PropertiesConfiguration config = new PropertiesConfiguration(); PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(); try (InputStream input = new FileInputStream(props)) { layout.load(config, new InputStreamReader(input, UTF_8)); propertyValue = config.getString(property); } catch (Exception e) { LOGGER.error(e.getMessage()); } return propertyValue; }
@Override public Configuration getConfiguration(RepositoryFileReference ref) { Path path = this.ref2AbsolutePath(ref); PropertiesConfiguration configuration = new PropertiesConfiguration(); if (Files.exists(path)) { try (Reader r = Files.newBufferedReader(path, Charset.defaultCharset())) { configuration.read(r); } catch (ConfigurationException | IOException e) { FilebasedRepository.LOGGER.error("Could not read config file", e); throw new IllegalStateException("Could not read config file", e); } } configuration.addEventListener(ConfigurationEvent.ANY, new AutoSaveListener(path, configuration)); // We do NOT implement reloading as the configuration is only accessed // in JAX-RS resources, which are created on a per-request basis return configuration; }
/** * @param resourcePath Path of overlapping properties files * @param classLoader Class loader where the resources are loaded * @return Configuration result * @throws IOException allows IO exceptions. */ public static Configuration loadFromOverlappingResources(String resourcePath, ClassLoader classLoader) throws IOException { Validate.notNull(resourcePath, "Resource path can't be NULL"); Validate.notNull(classLoader, "ClassLoader can't be NULL"); PropertiesConfiguration props = new PropertiesConfiguration(); props.setListDelimiterHandler(new DefaultListDelimiterHandler(',')); Enumeration<URL> resources = classLoader.getResources(resourcePath); while (resources.hasMoreElements()) { InputStream resource = resources.nextElement().openStream(); Reader reader = new InputStreamReader(resource); try { props.read(reader); } catch (ConfigurationException e) { throw new IOException(e); } finally { reader.close(); } } return props; }
/** * Creates application composite configuration. * * @return Application composite configuration. */ private CompositeConfiguration createApplicationConfiguration() { CompositeConfiguration cc = new CompositeConfiguration(); SystemConfiguration systemConfiguration = new SystemConfiguration(); PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.setThrowExceptionOnMissing(true); propertiesConfiguration.setListDelimiterHandler(new DefaultListDelimiterHandler(';')); propertiesConfiguration.setIncludesAllowed(false); FileLocator locator = FileLocatorUtils.fileLocator() .fileName("testlinkjavaapi.propertiesxml") .create(); propertiesConfiguration.initFileLocator(locator); cc.addConfiguration(systemConfiguration); cc.addConfiguration(propertiesConfiguration); return cc; }
private static void mergeExtraOptions(PropertiesConfiguration baseOptions, PropertiesConfiguration extraOptions) { if (isNull(extraOptions) || extraOptions.size() == 0) { return; } trace("loadOptions: have to merge extra Options"); Iterator<String> allKeys = extraOptions.getKeys(); while (allKeys.hasNext()) { String key = allKeys.next(); if ("sxversion".equals(key)) { baseOptions.setProperty("sxversion_saved", extraOptions.getProperty(key)); continue; } if ("sxbuild".equals(key)) { baseOptions.setProperty("sxbuild_saved", extraOptions.getProperty(key)); continue; } Object value = baseOptions.getProperty(key); if (isNull(value)) { baseOptions.addProperty(key, extraOptions.getProperty(key)); trace("Option added: %s", key); } else { Object extraValue = extraOptions.getProperty(key); if (!value.getClass().getName().equals(extraValue.getClass().getName()) || !value.toString().equals(extraValue.toString())) { baseOptions.setProperty(key, extraValue); trace("Option changed: %s = %s", key, extraValue); } } } }
private void removeRoles(String username) { Iterator<String> iterKeys = roleConfig.getKeys(); String theRole = iterKeys.next(); List<String> userList = roleConfig.getList(String.class, theRole); List<String> newList = new ArrayList<>(); while (iterUpdate.hasNext()) { Pair<String, List<String>> entry = iterUpdate.next(); roleConfig.clearProperty(entry.getA()); if (entry.getB().size() > 0) { roleConfig.addProperty(entry.getA(), entry.getB());
long age = Duration.between(now, entry.getValue()).abs().toDays(); if (age <= days) { if (props != null && !props.containsKey(propsKey)) { props.setProperty(propsKey, "true"); modifiedPairs = true; LOGGER.info("Enabled sell-only mode for " + entry.getKey() if (props != null && props.containsKey(propsKey)) { props.clearProperty(propsKey); modifiedPairs = true; LOGGER.info("Disabled sell-only mode for " + entry.getKey() props.write(bw); } catch (ConfigurationException | IOException e) { LOGGER.log(Level.WARNING, "Failed to save " + pairsFile.getPath(), e);
void updateUser(String username, String password, String[] roles) { String oldPassword = (String) userConfig.getProperty(username); if (oldPassword == null) { throw new IllegalArgumentException("user " + username + " doesn't exist."); } if (password != null) { userConfig.setProperty(username, password); } if (roles != null && roles.length > 0) { removeRoles(username); addRoles(username, roles); } }
public static boolean isOption(String pName, Boolean bDefault) { if (SXOPTIONS == null) { return bDefault; } String pVal = SXOPTIONS.getString(pName, bDefault.toString()).toLowerCase(); if (pVal.contains("yes") || pVal.contains("true") || pVal.contains("on")) { return true; } return false; }
public static Map<String, String> getOptions() { Map<String, String> mapOptions = new HashMap<String, String>(); if (hasOptions()) { Iterator<String> allKeys = SXOPTIONS.getKeys(); while (allKeys.hasNext()) { String key = allKeys.next(); mapOptions.put(key, getOption(key)); } } return mapOptions; }