List of usage examples for org.apache.commons.configuration Configuration containsKey
boolean containsKey(String key);
From source file:au.edu.flinders.ehl.filmweekly.FwImporter.java
/** * Main method for the class/*www.java 2s . com*/ * * @param args array of command line arguments */ public static void main(String[] args) { // before we do anything, output some useful information for (int i = 0; i < APP_HEADER.length; i++) { System.out.println(APP_HEADER[i]); } // parse the command line options CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(createOptions(), args); } catch (org.apache.commons.cli.ParseException e) { // something bad happened so output help message printCliHelp("Error in parsing options:\n" + e.getMessage()); } // get and check on the log4j properties path option if required if (cmd.hasOption("log4j") == true) { String log4jPath = cmd.getOptionValue("log4j"); if (FileUtils.isAccessible(log4jPath) == false) { printCliHelp("Unable to access the specified log4j properties file\n " + log4jPath); } // configure the log4j framework PropertyConfigurator.configure(log4jPath); } // get and check on the properties path option String propertiesPath = cmd.getOptionValue("properties"); if (FileUtils.isAccessible(propertiesPath) == false) { printCliHelp("Unable to access the specified properties file\n " + propertiesPath); } // get and check on the input file path option String inputPath = cmd.getOptionValue("input"); if (FileUtils.isAccessible(inputPath) == false) { printCliHelp("Unable to access the specified input file"); } // open the properties file Configuration config = null; try { config = new PropertiesConfiguration(propertiesPath); } catch (ConfigurationException e) { printCliHelp("Unable to read the properties file file: \n" + e.getMessage()); } // check to make sure all of the required configuration properties are present for (int i = 0; i < REQD_PROPERTIES.length; i++) { if (config.containsKey(REQD_PROPERTIES[i]) == false) { printCliHelp("Unable to find the required property: " + REQD_PROPERTIES[i]); } } if (cmd.hasOption("debug_coord_list") == true) { // output debug info logger.debug("undertaking the debug-coord-list task"); // undertake the debug coordinate list task if (FileUtils.doesFileExist(cmd.getOptionValue("debug_coord_list")) == true) { printCliHelp("the debug_coord_list file already exists"); } else { CoordList list = new CoordList(inputPath, cmd.getOptionValue("debug_coord_list")); try { list.openFiles(); list.doTask(); } catch (IOException e) { logger.error("unable to undertake the debug-coord-list task", e); errorExit(); } System.out.println("Task completed"); System.exit(0); } } if (cmd.hasOption("debug_json_list") == true) { // output debug info logger.debug("undertaking the debug-json-list task"); // undertake the debug coordinate list task if (FileUtils.doesFileExist(cmd.getOptionValue("debug_json_list")) == true) { printCliHelp("the debug_json_list file already exists"); } else { JsonList list = new JsonList(inputPath, cmd.getOptionValue("debug_json_list")); try { list.openFiles(); list.doTask(); } catch (IOException e) { logger.error("unable to undertake the debug_json_list task", e); errorExit(); } System.out.println("Task completed"); System.exit(0); } } // if no debug options present assume import System.out.println("Importing data into the database."); System.out.println( "*Note* if this input file has been processed before duplicate records *will* be created."); // get a connection to the database try { Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (Exception e) { logger.error("unable to load the MySQL database classes", e); errorExit(); } Connection database = null; //private static final String[] REQD_PROPERTIES = {"db-host", "db-user", "db-password", "db-name"}; String connectionString = "jdbc:mysql://" + config.getString(REQD_PROPERTIES[0]) + "/" + config.getString(REQD_PROPERTIES[1]) + "?user=" + config.getString(REQD_PROPERTIES[2]) + "&password=" + config.getString(REQD_PROPERTIES[3]); try { database = DriverManager.getConnection(connectionString); } catch (SQLException e) { logger.error("unable to connect to the MySQL database", e); errorExit(); } // do the import DataImporter importer = new DataImporter(database, inputPath); try { importer.openFiles(); importer.doTask(); System.out.println("Task completed"); System.exit(0); } catch (IOException e) { logger.error("unable to complete the import"); errorExit(); } catch (ImportException e) { logger.error("unable to complete the import"); errorExit(); } finally { // play nice and tidy up try { database.close(); } catch (SQLException e) { logger.error("Unable to close the database connection: ", e); } } }
From source file:edu.berkeley.sparrow.daemon.util.ConfigUtil.java
/** * Parses the list of backends from a {@link Configuration}. * * Returns a map of address of backends to a {@link TResourceVector} describing the * total resource capacity for that backend. *///from ww w . j ava 2s .c o m public static Set<InetSocketAddress> parseBackends(Configuration conf) { if (!conf.containsKey(SparrowConf.STATIC_NODE_MONITORS)) { throw new RuntimeException("Missing configuration node monitor list"); } Set<InetSocketAddress> backends = new HashSet<InetSocketAddress>(); for (String node : conf.getStringArray(SparrowConf.STATIC_NODE_MONITORS)) { Optional<InetSocketAddress> addr = Serialization.strToSocket(node); if (!addr.isPresent()) { LOG.warn("Bad backend address: " + node); continue; } backends.add(addr.get()); } return backends; }
From source file:ch.epfl.eagle.daemon.util.ConfigUtil.java
/** * Parses the list of backends from a {@link Configuration}. * * Returns a map of address of backends to a {@link TResourceVector} describing the * total resource capacity for that backend. *///from w w w . ja v a 2 s . c om public static Set<InetSocketAddress> parseBackends(Configuration conf) { if (!conf.containsKey(EagleConf.STATIC_NODE_MONITORS)) { throw new RuntimeException("Missing configuration node monitor list"); } Set<InetSocketAddress> backends = new HashSet<InetSocketAddress>(); for (String node : conf.getStringArray(EagleConf.STATIC_NODE_MONITORS)) { Optional<InetSocketAddress> addr = Serialization.strToSocket(node); if (!addr.isPresent()) { LOG.warn("Bad backend address: " + node); continue; } backends.add(addr.get()); } return backends; }
From source file:com.manydesigns.elements.configuration.CommonsConfigurationFunctions.java
public static boolean containsKey(Configuration configuration, String key) { return configuration.containsKey(key); }
From source file:edu.cornell.med.icb.R.RConfigurationUtils.java
/** * Gets the configuration for the RServe processes. * @return A url that for the RConnectionPool configuration file. *//*from www . ja v a 2 s . c o m*/ static URL getConfigurationURL() { URL poolConfigURL; // if the user defined a configuration, use it final ResourceFinder resourceFinder = new ResourceFinder(".", "config"); final Configuration systemConfiguration = new SystemConfiguration(); if (systemConfiguration.containsKey(DEFAULT_CONFIGURATION_KEY)) { final String poolConfig = systemConfiguration.getString(DEFAULT_CONFIGURATION_KEY); try { // First see if we have a URL from the system configuration poolConfigURL = new URL(poolConfig); } catch (MalformedURLException e) { // resource is not a URL, attempt to get the resource from the class path poolConfigURL = resourceFinder.findResource(poolConfig); } } else { poolConfigURL = resourceFinder.findResource(DEFAULT_XML_CONFIGURATION_FILE); } return poolConfigURL; }
From source file:com.gs.obevo.db.apps.reveng.DbMergeInfo.java
public static MutableCollection<DbMergeInfo> parseFromProperties(Configuration config) { Set<String> dbs = new HashSet<String>(config.getList("instances")); MutableList<DbMergeInfo> dbMergeInfos = Lists.mutable.empty(); for (String db : dbs) { Configuration subset = config.subset(db); if (subset.containsKey("inputDir")) { File inputDir = new File(subset.getString("inputDir")); DbMergeInfo mergeInfo = new DbMergeInfo(db, inputDir); if (subset.containsKey("driverClassName")) { mergeInfo.setDriverClassName(subset.getString("driverClassName")); mergeInfo.setUrl(subset.getString("url")); mergeInfo.setUsername(subset.getString("username")); mergeInfo.setPassword(subset.getString("password")); mergeInfo.setPhysicalSchema(subset.getString("physicalSchema")); }//from w ww. j a v a2s .c o m dbMergeInfos.add(mergeInfo); } } return dbMergeInfos; }
From source file:com.zavakid.mushroom.impl.ConfigUtil.java
static void assertEq(Configuration expected, Configuration actual) { // Check that the actual config contains all the properties of the expected for (Iterator<?> it = expected.getKeys(); it.hasNext();) { String key = (String) it.next(); assertTrue("actual should contain " + key, actual.containsKey(key)); assertEquals("value of " + key, expected.getProperty(key), actual.getProperty(key)); }//from ww w . j a v a2 s . co m // Check that the actual config has no extra properties for (Iterator<?> it = actual.getKeys(); it.hasNext();) { String key = (String) it.next(); assertTrue("expected should contain " + key, expected.containsKey(key)); } }
From source file:com.cloudera.whirr.cm.integration.BaseITServer.java
private static int clusterBootstrap(Map<String, String> configuration) { int returnValue = 0; try {//from ww w . j a va 2s . c o m if (!isClusterBootstrapped()) { log.logOperationStartedSync("ClusterBootstrap"); Configuration configurationAggregate = clusterConfig(); for (String key : configuration.keySet()) { if (configurationAggregate.containsKey(key)) { configurationAggregate.clearProperty(key); } configurationAggregate.addProperty(key, configuration.get(key)); } new ClusterController().launchCluster(ClusterSpec.withNoDefaults(configurationAggregate)); log.logOperationFinishedSync("ClusterBootstrap"); } } catch (Exception exception) { returnValue = 1; } return returnValue; }
From source file:com.github.mbredel.commons.configuration.ConfigurationAssert.java
/** * Checks the content of a configuration. * * @param expected the expected properties * @param actual the configuration to check */// w w w .j a va2s .c om @SuppressWarnings("unused") public static void assertEquals(Configuration expected, Configuration actual) { // check that the actual configuration contains all the properties of the expected configuration for (Iterator<String> it = expected.getKeys(); it.hasNext();) { String key = it.next(); Assert.assertTrue("The actual configuration doesn't contain the expected key '" + key + "'", actual.containsKey(key)); Assert.assertEquals("Value of the '" + key + "' property", expected.getProperty(key), actual.getProperty(key)); } // check that the actual configuration has no extra properties for (Iterator<String> it = actual.getKeys(); it.hasNext();) { String key = it.next(); Assert.assertTrue("The actual configuration contains an extra key '" + key + "'", expected.containsKey(key)); } }
From source file:de.tudarmstadt.ukp.dariah.pipeline.RunPipeline.java
private static void parseConfig(String configFile) throws ConfigurationException, ClassNotFoundException { Configuration config = new PropertiesConfiguration(configFile); if (config.containsKey("useSegmenter")) optSegmenter = config.getBoolean("useSegmenter", true); if (config.containsKey("segmenter")) optSegmenterCls = getClassFromConfig(config, "segmenter"); if (config.containsKey("segmenterArguments")) optSegmenterArguments = parseParameters(config, "segmenterArguments"); if (config.containsKey("usePosTagger")) optPOSTagger = config.getBoolean("usePosTagger", true); if (config.containsKey("posTagger")) optPOSTaggerCls = getClassFromConfig(config, "posTagger"); if (config.containsKey("posTaggerArguments")) optPOSTaggerArguments = parseParameters(config, "posTaggerArguments"); if (config.containsKey("useLemmatizer")) optLemmatizer = config.getBoolean("useLemmatizer", true); if (config.containsKey("lemmatizer")) optLemmatizerCls = getClassFromConfig(config, "lemmatizer"); if (config.containsKey("lemmatizerArguments")) optLemmatizerArguments = parseParameters(config, "lemmatizerArguments"); if (config.containsKey("useChunker")) optChunker = config.getBoolean("useChunker", true); if (config.containsKey("chunker")) optChunkerCls = getClassFromConfig(config, "chunker"); if (config.containsKey("chunkerArguments")) optChunkerArguments = parseParameters(config, "chunkerArguments"); if (config.containsKey("useMorphTagger")) optMorphTagger = config.getBoolean("useMorphTagger", true); if (config.containsKey("morphTagger")) optMorphTaggerCls = getClassFromConfig(config, "morphTagger"); if (config.containsKey("morphTaggerArguments")) optMorphTaggerArguments = parseParameters(config, "morphTaggerArguments"); if (config.containsKey("useHyphenation")) optHyphenation = config.getBoolean("useHyphenation", true); if (config.containsKey("hyphenationAlgorithm")) optHyphenationCls = getClassFromConfig(config, "hyphenationAlgorithm"); if (config.containsKey("hyphenationArguments")) optHyphenationArguments = parseParameters(config, "hyphenationArguments"); if (config.containsKey("useDependencyParser")) optDependencyParser = config.getBoolean("useDependencyParser", true); if (config.containsKey("dependencyParser")) optDependencyParserCls = getClassFromConfig(config, "dependencyParser"); if (config.containsKey("dependencyParserArguments")) optDependencyParserArguments = parseParameters(config, "dependencyParserArguments"); if (config.containsKey("useConstituencyParser")) optConstituencyParser = config.getBoolean("useConstituencyParser", true); if (config.containsKey("constituencyParser")) optConstituencyParserCls = getClassFromConfig(config, "constituencyParser"); if (config.containsKey("constituencyParserArguments")) optConstituencyParserArguments = parseParameters(config, "constituencyParserArguments"); if (config.containsKey("useNER")) optNER = config.getBoolean("useNER", true); if (config.containsKey("ner")) optNERCls = getClassFromConfig(config, "ner"); if (config.containsKey("nerArguments")) optNERArguments = parseParameters(config, "nerArguments"); if (config.containsKey("useSRL")) optSRL = config.getBoolean("useSRL", true); if (config.containsKey("srl")) optSRLCls = getClassFromConfig(config, "srl"); if (config.containsKey("srlArguments")) optSRLArguments = parseParameters(config, "srlArguments"); if (config.containsKey("useCoref")) optCoref = config.getBoolean("useCoref", true); if (config.containsKey("coref")) optCorefCls = getClassFromConfig(config, "coref"); if (config.containsKey("corefArguments")) optCorefArguments = parseParameters(config, "corefArguments"); if (config.containsKey("splitParagraphOnSingleLineBreak")) optParagraphSingleLineBreak = config.getBoolean("splitParagraphOnSingleLineBreak", false); if (config.containsKey("startingQuotes")) optStartQuote = config.getString("startingQuotes", "\""); if (config.containsKey("language")) optLanguage = config.getString("language"); }