List of usage examples for org.apache.commons.configuration PropertiesConfiguration getFileName
public String getFileName()
From source file:com.xemantic.tadedon.configuration.Configurations.java
public static void merge(PropertiesConfiguration defaultConf, PropertiesConfiguration conf) { LOG.debug("Merging: {} <-> {}", defaultConf.getURL(), conf.getURL()); for (@SuppressWarnings("unchecked") Iterator<String> iterator = defaultConf.getKeys(); iterator.hasNext();) { String key = iterator.next(); if (!conf.containsKey(key)) { copyProperty(key, defaultConf, conf); }/*from w w w. jav a2 s .co m*/ } try { conf.save(); } catch (ConfigurationException e) { throw new RuntimeException("Could no save configuration file: " + conf.getFileName(), e); } }
From source file:org.w3.i18n.I18nTestRunnerTest.java
private static List<I18nTest> interpretTests(String prefix, PropertiesConfiguration configuration) throws TestsFileParsingException { List<I18nTest> i18nTests = new ArrayList<>(); /* Possible properties for a test: * (name)//w ww .j a v a2 s . co m * 'id' * 'url' * 'test_for' * 'info_charset' * 'info_lang' * 'info_dir' * 'info_classId' * 'info_headers' * 'reports' * 'warning' * 'applicableOnlyTo' */ // Retrieve required details from the properties files. String propertyDescription = configuration.containsKey(prefix) ? configuration.getString(prefix).replace("\"", "") : null; String propertyId = configuration.containsKey(prefix + "_id") ? configuration.getString(prefix + "_id").replace("\"", "") : null; String propertyUrl = configuration.containsKey(prefix + "_url") ? configuration.getString(prefix + "_url").replace("\"", "") : null; String propertyTestFor = configuration.containsKey(prefix + "_test_for") ? configuration.getString(prefix + "_test_for") : null; String[] propertyReport = configuration.containsKey(prefix + "_report[]") ? configuration.getStringArray(prefix + "_report[]") : null; if (propertyReport == null) { String singlePropertyReport = configuration.containsKey(prefix + "_report") ? configuration.getString(prefix + "_report") : null; if (singlePropertyReport != null) { propertyReport = new String[] { singlePropertyReport }; } } // Check that vital details are set ('_testFor' and '_report[]'). boolean useableTest = propertyTestFor != null && !propertyTestFor.isEmpty() && propertyReport != null && propertyReport.length != 0; // Check that there's at least one non-empty report definition. if (useableTest) { propertyTestFor = propertyTestFor.replaceAll("\"", ""); if (propertyTestFor.isEmpty()) { useableTest = false; } } if (useableTest) { // Check that there's at least one non-empty report definition. useableTest = true; int i = 0; while (i < propertyReport.length) { propertyReport[i] = propertyReport[i].replace("\"", ""); if (propertyReport[i].isEmpty()) { useableTest = false; } i++; } } if (useableTest) { // Validate the given URL if present. URL givenUrl = null; if (propertyUrl != null) { try { givenUrl = new URL(propertyUrl); } catch (MalformedURLException ex) { throw new TestsFileParsingException("Invalid URL given" + " by property. Propety name: \"" + prefix + "_url\", extracted URL: " + propertyUrl + ", file: '" + configuration.getFileName() + "'.", ex); } } // Create a list of assertions from the expected reports. List<Assertion> expectedAssertions = new ArrayList<>(); for (String report : propertyReport) { if (!report.isEmpty()) { report = report.replace("}", ""); String[] reportSplit = report.replace("}", "").split("\\{"); String reportId = reportSplit[0]; // MESSAGE levels are not compared. Assertion.Level level = Assertion.Level.MESSAGE; /* Look for additional details for each '_report[]' * (e.g. "{severity:warning,tags:2}"). */ if (reportSplit.length != 1) { String[] details = reportSplit[1].split(","); for (String detail : details) { switch (detail.trim()) { case "severity:info": level = Assertion.Level.INFO; break; case "severity:warning": level = Assertion.Level.WARNING; break; case "severity:error": level = Assertion.Level.ERROR; break; } } } expectedAssertions.add(new Assertion(reportId, level, "", "", new ArrayList<String>())); } } if (expectedAssertions.isEmpty()) { throw new TestsFileParsingException("Could not create any Assertions from the reports" + " property for \"" + prefix + "\". Interpreted" + " reports property: " + Arrays.toString(propertyReport) + ", file: '" + configuration.getFileName() + "'."); } Collections.sort(expectedAssertions); // Prepare URLs and create I18nTests for each format and servaAs. for (String testFor : propertyTestFor.split(",")) { testFor = testFor.replace("\"", ""); String[] testForSplit = testFor.split(":"); String format = testForSplit[0]; String serveAs = testForSplit.length != 1 ? testForSplit[1] : "html"; URL testUrl; if (givenUrl == null) { try { testUrl = assembleTestUrl(propertyId, format, serveAs); } catch (MalformedURLException ex) { throw new TestsFileParsingException("Could not" + " construct a URL from testFor property." + " TestConfig.TEST_RUNNER_URL: " + TestConfig.TEST_RUNNER_URL + ", propety name:" + " \"" + prefix + "_test_for\", file: '" + configuration.getFileName() + "'.", ex); } } else { testUrl = givenUrl; } i18nTests.add(new I18nTest(prefix, propertyDescription, propertyId, testUrl, format, serveAs, expectedAssertions)); } } return i18nTests; }