List of usage examples for org.apache.commons.configuration PropertiesConfiguration setAutoSave
public void setAutoSave(boolean autoSave)
From source file:com.github.fengtan.sophie.beans.Config.java
/** * Read properties file and load it in a configuration object. * // ww w .j av a2 s .c o m * @return Configuration object. * @throws ConfigurationException * If the configuration could not be loaded. */ private static Configuration getConfiguration() throws ConfigurationException { String filepath = System.getProperty("user.home") + File.separator + filename; File file = new File(filepath); PropertiesConfiguration configuration = new PropertiesConfiguration(file); configuration.setAutoSave(true); return configuration; }
From source file:com.easyvalidation.xml.processor.XMLProcessor.java
/** * Parse the XML & return list of rules. * // ww w.ja va 2s.c o m * @param fileNames * @return * @throws ValidationException */ public static Map<String, List<Rule>> parseXML(String[] fileNames) throws ValidationException { Map<String, List<Rule>> validationMap = new HashMap<String, List<Rule>>(); com.easyvalidation.xml.config.EasyValidationXmlConfiguration configuration = new com.easyvalidation.xml.config.EasyValidationXmlConfiguration(); //System.out.println("Have we came here?"); configuration.setAutoSave(false); //System.out.println("Have we came here?"); configuration.clear(); //System.out.println("Have we came here?"); configuration.setValidating(true); try { for (String fileName : fileNames) { //System.out.println("Have we came here4?"); configuration.load(fileName); //System.out.println("Have we came here5?"); } //System.out.println("Have we came here?"); boolean isMessageFromKeyAllowed = false; Map<String, PropertiesConfiguration> propertiesMap = new HashMap<String, PropertiesConfiguration>(); int propertiesSize = configuration.getMaxIndex(Nodes.PROPERTIES); for (int propertiesIndex = 0; propertiesIndex <= propertiesSize; propertiesIndex++) { String locale = configuration.getString(RuleElementPathUtil.getPropsFileLocale(propertiesIndex)); PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.setAutoSave(false); propertiesConfiguration.clear(); HierarchicalConfiguration subConfig = configuration .configurationAt(RuleElementPathUtil.getPropertiesPath(propertiesIndex)); //System.out.println("Have we came here6?"); int propFileSize = subConfig.getMaxIndex(Nodes.FILE); for (int propFileIndex = 0; propFileIndex <= propFileSize; propFileIndex++) { String propFileName = subConfig.getString(RuleElementPathUtil.getPropsFilePath(propFileIndex)); if (!Utils.isEmpty(propFileName)) { propertiesConfiguration.load(propFileName); } } propertiesMap.put(locale, propertiesConfiguration); } //System.out.println("Have we came here7?"); if (!propertiesMap.isEmpty()) { isMessageFromKeyAllowed = true; } int validationSize = configuration.getMaxIndex(Nodes.VALIDATION); for (int validationIndex = 0; validationIndex <= validationSize; validationIndex++) { String name = configuration.getString(RuleElementPathUtil.getValidationName(validationIndex)); HierarchicalConfiguration subConfig = configuration .configurationAt(RuleElementPathUtil.getValidation(validationIndex)); int ruleSize = subConfig.getMaxIndex(Nodes.RULE); List<Rule> ruleList = new ArrayList<Rule>(); for (int ruleIndex = 0; ruleIndex <= ruleSize; ruleIndex++) { String ruleType = subConfig.getString(RuleElementPathUtil.getRuleType(ruleIndex)); String property = subConfig.getString(RuleElementPathUtil.getRuleFieldName(ruleIndex)); String message = subConfig.getString(RuleElementPathUtil.getRuleMessage(ruleIndex)); String min = subConfig.getString(RuleElementPathUtil.getRuleMin(ruleIndex)); String max = subConfig.getString(RuleElementPathUtil.getRuleMax(ruleIndex)); String dateFormat = subConfig.getString(RuleElementPathUtil.getRuleDateFormat(ruleIndex)); String key = subConfig.getString(RuleElementPathUtil.getMessageKey(ruleIndex)); String useAttributePlaceHolder = subConfig .getString(RuleElementPathUtil.getMessageUseAttributePlaceHolder(ruleIndex)); String regEx = subConfig.getString(RuleElementPathUtil.getRuleRegEx(ruleIndex)); String expression = subConfig.getString(RuleElementPathUtil.getRuleExpression(ruleIndex)); Rule rule = new Rule(ruleType); rule.setProperty(property); rule.setMessage(message); rule.setMin(min); rule.setMax(max); rule.setDateFormat(dateFormat); rule.setKey(key); rule.setUseAttributePlaceHolder(Boolean.valueOf(useAttributePlaceHolder)); rule.setRegEx(Boolean.valueOf(regEx)); rule.setExpression(expression); if (isMessageFromKeyAllowed) { rule.setPropertiesMap(propertiesMap); } rule.populateRule(); ruleList.add(rule); } validationMap.put(name, ruleList); } } catch (Exception ex) { throw new ValidationException(ex); } return validationMap; }
From source file:ch.descabato.browser.BackupBrowser.java
public static void main2(final String[] args) throws InterruptedException, InvocationTargetException, SecurityException, IOException { if (args.length > 1) throw new IllegalArgumentException( "SYNTAX: java... " + BackupBrowser.class.getName() + " [initialPath]"); SwingUtilities.invokeAndWait(new Runnable() { @Override//www .j a v a 2s. c o m public void run() { tryLoadSubstanceLookAndFeel(); final JFrame f = new JFrame("OtrosVfsBrowser demo"); f.addWindowListener(finishedListener); Container contentPane = f.getContentPane(); contentPane.setLayout(new BorderLayout()); DataConfiguration dc = null; final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); File favoritesFile = new File("favorites.properties"); propertiesConfiguration.setFile(favoritesFile); if (favoritesFile.exists()) { try { propertiesConfiguration.load(); } catch (ConfigurationException e) { e.printStackTrace(); } } dc = new DataConfiguration(propertiesConfiguration); propertiesConfiguration.setAutoSave(true); final VfsBrowser comp = new VfsBrowser(dc, (args.length > 0) ? args[0] : null); comp.setSelectionMode(SelectionMode.FILES_ONLY); comp.setMultiSelectionEnabled(true); comp.setApproveAction(new AbstractAction(Messages.getMessage("demo.showContentButton")) { @Override public void actionPerformed(ActionEvent e) { FileObject[] selectedFiles = comp.getSelectedFiles(); System.out.println("Selected files count=" + selectedFiles.length); for (FileObject selectedFile : selectedFiles) { try { FileSize fileSize = new FileSize(selectedFile.getContent().getSize()); System.out.println(selectedFile.getName().getURI() + ": " + fileSize.toString()); Desktop.getDesktop() .open(new File(new URI(selectedFile.getURL().toExternalForm()))); // byte[] bytes = readBytes(selectedFile.getContent().getInputStream(), 150 * 1024l); // JScrollPane sp = new JScrollPane(new JTextArea(new String(bytes))); // JDialog d = new JDialog(f); // d.setTitle("Content of file: " + selectedFile.getName().getFriendlyURI()); // d.getContentPane().add(sp); // d.setSize(600, 400); // d.setVisible(true); } catch (Exception e1) { LOGGER.error("Failed to read file", e1); JOptionPane.showMessageDialog(f, (e1.getMessage() == null) ? e1.toString() : e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } }); comp.setCancelAction(new AbstractAction(Messages.getMessage("general.cancelButtonText")) { @Override public void actionPerformed(ActionEvent e) { f.dispose(); try { propertiesConfiguration.save(); } catch (ConfigurationException e1) { e1.printStackTrace(); } System.exit(0); } }); contentPane.add(comp); f.pack(); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }); while (!finished) Thread.sleep(100); }
From source file:de.chaosfisch.uploader.UploaderModule.java
@Override protected void configure() { bind(String.class).annotatedWith(Names.named(IPersistenceService.PERSISTENCE_FOLDER)) .toInstance(String.format("%s/%s", ApplicationData.DATA_DIR, ApplicationData.VERSION)); try {/*www . j av a 2 s . c o m*/ final String configFile = ApplicationData.DATA_DIR + "/config.properties"; if (!Files.exists(Paths.get(configFile))) { Files.createFile(Paths.get(configFile)); } final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(configFile); propertiesConfiguration.setAutoSave(true); bind(Configuration.class).toInstance(propertiesConfiguration); } catch (IOException | ConfigurationException e) { throw new RuntimeException(e); } install(new PersistenceModule()); install(new GoogleModule()); final Multibinder<UploadPreProcessor> preProcessorMultibinder = Multibinder.newSetBinder(binder(), UploadPreProcessor.class); preProcessorMultibinder.addBinding().to(PlaceholderPreProcessor.class); final Multibinder<UploadPostProcessor> uploadPostProcessorMultibinder = Multibinder.newSetBinder(binder(), UploadPostProcessor.class); uploadPostProcessorMultibinder.addBinding().to(ExportPostProcessor.class); bind(ResourceBundle.class).annotatedWith(Names.named("i18n-resources")) .toInstance(ResourceBundle.getBundle("de.chaosfisch.uploader.resources.application")); mapServices(); mapUtil(); }
From source file:eu.ascetic.zabbixdatalogger.datasource.hostvmfilter.NamedList.java
/** * This creates a name filter that checks to see if the start of a host name * matches particular criteria or not. if it does then it will indicate * accordingly that the "Zabbix JSON API host" is a host or VM. *//*from w w w .j a v a 2 s. c o m*/ public NamedList() { try { PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. namedSet = config.getString("data.logger.filter.names", namedSet); config.setProperty("data.logger.filter.names", namedSet); hostNames.addAll(Arrays.asList(namedSet.split(","))); } catch (ConfigurationException ex) { Logger.getLogger(NameBeginsFilter.class.getName()).log(Level.INFO, "Error loading the configuration of the named list filter"); } }
From source file:eu.ascetic.zabbixdatalogger.datasource.hostvmfilter.NameEndsFilter.java
/** * This creates a name filter that checks to see if the end of a host name * matches particular criteria or not. if it does then it will indicate accordingly * that the "Zabbix JSON API host" is a host or VM. *///from www .j a v a2 s. co m public NameEndsFilter() { try { PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. ends = config.getString("data.logger.filter.begins", ends); config.setProperty("data.logger.filter.begins", ends); isHost = config.getBoolean("data.logger.filter.isHost", isHost); config.setProperty("data.logger.filter.isHost", isHost); } catch (ConfigurationException ex) { Logger.getLogger(NameBeginsFilter.class.getName()).log(Level.INFO, "Error loading the configuration of the name ends filter"); } }
From source file:eu.ascetic.zabbixdatalogger.datasource.hostvmfilter.NameBeginsFilter.java
/** * This creates a name filter that checks to see if the start of a host name * matches particular criteria or not. if it does then it will indicate accordingly * that the "Zabbix JSON API host" is a host or VM. *///from w ww .j a va2 s .c o m public NameBeginsFilter() { try { PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. begins = config.getString("data.logger.filter.begins", begins); config.setProperty("data.logger.filter.begins", begins); isHost = config.getBoolean("data.logger.filter.isHost", isHost); config.setProperty("data.logger.filter.isHost", isHost); } catch (ConfigurationException ex) { Logger.getLogger(NameBeginsFilter.class.getName()).log(Level.INFO, "Error loading the configuration of the name begins filter"); } }
From source file:eu.tango.energymodeller.energypredictor.workloadpredictor.CpuRecentHistoryWorkloadPredictor.java
/** * This sets up a CPU Recent History Workload Predictor. The main need is to * establish the time window by which the workload predictor must work. *//* www . j av a 2 s . co m*/ public CpuRecentHistoryWorkloadPredictor() { try { PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. readSettings(config); } catch (ConfigurationException ex) { Logger.getLogger(CpuOnlyEnergyPredictor.class.getName()).log(Level.SEVERE, "Taking the default load from the settings file did not work", ex); } }
From source file:eu.tango.energymodeller.energypredictor.AveragePowerEnergyPredictor.java
/** * This creates a new average power energy predictor. The predictor when * running takes the last power reading and makes the assumption no change * will occur. An observation time window is used for taking the measurement, * which is set via a configuration file. *///from w w w .j a v a2 s . c o m public AveragePowerEnergyPredictor() { try { if (database == null) { database = new DefaultDatabaseConnector(); } PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. powerObservationTimeMin = config.getInt( "energy.modeller.energy.predictor.cpu.utilisation.observe_time.min", powerObservationTimeMin); config.setProperty("energy.modeller.energy.predictor.cpu.utilisation.observe_time.min", powerObservationTimeMin); powerObservationTimeSec = config.getInt( "energy.modeller.energy.predictor.cpu.utilisation.observe_time.sec", powerObservationTimeSec); config.setProperty("energy.modeller.energy.predictor.cpu.utilisation.observe_time.sec", powerObservationTimeSec); observationTime = powerObservationTimeSec + (int) TimeUnit.MINUTES.toSeconds(powerObservationTimeMin); } catch (ConfigurationException ex) { Logger.getLogger(AveragePowerEnergyPredictor.class.getName()).log(Level.SEVERE, "The average power energy predictor failed to initialise", ex); } }
From source file:eu.tango.energymodeller.energypredictor.AbstractEnergyPredictor.java
/** * This creates a new abstract energy predictor. * * It will create a energy-modeller-predictor properties file if it doesn't * exist.//from w ww. j av a 2 s .co m * * The main property: energy.modeller.energy.predictor.cpu.default_load * should be in the range 0..1 or -1. This indicates the predictor's default * assumption on how much load is been induced. -1 measures the CPU's * current load and uses that to forecast into the future. * * In the case of using -1 as a parameter to additional parameters are used: * energy.modeller.energy.predictor.cpu.utilisation.observe_time.sec * energy.modeller.energy.predictor.cpu.utilisation.observe_time.min * * These indicate the window of how long the CPU should be monitored for, to * determine the current load. */ public AbstractEnergyPredictor() { try { PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. readSettings(config); } catch (ConfigurationException ex) { Logger.getLogger(CpuOnlyEnergyPredictor.class.getName()).log(Level.SEVERE, "Taking the default load from the settings file did not work", ex); } }