Example usage for org.apache.commons.configuration Configuration getString

List of usage examples for org.apache.commons.configuration Configuration getString

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getString.

Prototype

String getString(String key);

Source Link

Document

Get a string associated with the given configuration key.

Usage

From source file:com.yahoo.ads.pb.PistachiosServer.java

public static void main(String[] args) {
    try {// w ww.  j av a 2  s . c  o m
        reporter.start();

        // embed helix controller
        Configuration conf = ConfigurationManager.getConfiguration();
        helixManager = HelixManagerFactory.getZKHelixManager("PistachiosCluster",
                InetAddress.getLocalHost().getHostName(), //conf.getString(PROFILE_HELIX_INSTANCE_ID),
                InstanceType.CONTROLLER, conf.getString(ZOOKEEPER_SERVER));
        helixManager.connect();
        controller = new GenericHelixController();
        helixManager.addConfigChangeListener(controller);
        helixManager.addLiveInstanceChangeListener(controller);
        helixManager.addIdealStateChangeListener(controller);
        helixManager.addExternalViewChangeListener(controller);
        helixManager.addControllerListener(controller);

        instance = new PistachiosServer();
        instance.init();
        handler = new PistachiosHandler();
        processor = new Pistachios.Processor(handler);

        Runnable simple = new Runnable() {
            public void run() {
                simple(processor);
            }
        };

        new Thread(simple).start();
    } catch (Exception x) {
        x.printStackTrace();
    }
}

From source file:au.edu.flinders.ehl.filmweekly.FwImporter.java

/**
 * Main method for the class//  w  ww  .j a  v  a2  s.  c o  m
 * 
 * @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:com.manydesigns.elements.configuration.CommonsConfigurationFunctions.java

public static String getString(Configuration configuration, String key) {
    return configuration.getString(key);
}

From source file:net.pms.configuration.ConfigurationUtil.java

/**
 * Return the <code>String</code> value for a given configuration key if the
 * value is non-blank (i.e. not null, not an empty string, not all whitespace).
 * Otherwise return the supplied default value.
 * The value is returned with leading and trailing whitespace removed in both cases.
 * @param configuration The configuration to look up the key in.
 * @param key The key to look up.//from w  w w .j  av a2s . com
 * @param def The default value to return when no valid key value can be found.
 * @return The value configured for the key.
 */

// package-private
static String getNonBlankConfigurationString(Configuration configuration, String key, String def) {
    String value = configuration.getString(key);

    if (StringUtils.isNotBlank(value)) {
        return value.trim();
    } else if (def != null) {
        return def.trim();
    } else {
        return def;
    }
}

From source file:com.trivago.mail.pigeon.queue.ConnectionPool.java

public static Connection getConnection() {
    if (connection == null) {
        ConnectionFactory factory = new ConnectionFactory();
        Configuration configuration = settings.getConfiguration();

        factory.setUsername(configuration.getString("rabbit.username"));
        factory.setPassword(configuration.getString("rabbit.password"));
        factory.setVirtualHost(configuration.getString("rabbit.vhost"));
        factory.setHost(configuration.getString("rabbit.hostname"));
        factory.setPort(configuration.getInt("rabbit.port"));

        try {/* w  w  w  . j  a  v a 2  s  .c o m*/
            connection = factory.newConnection();
        } catch (IOException e) {
            log.error(e);
            throw new RuntimeException(e);
        }
    }
    return connection;
}

From source file:com.boozallen.cognition.ingest.accumulo.utils.AccumuloConnectionUtils.java

public static AccumuloConnectionConfig extractConnectionConfiguration(Configuration conf) {
    AccumuloConnectionConfig config = new AccumuloConnectionConfig();
    config.instance = conf.getString(INSTANCE);
    config.zooServers = conf.getString(ZOO_SERVERS);
    config.user = conf.getString(USER);/*w w  w .  j a  va  2  s  .  c  o m*/
    config.key = conf.getString(KEY);
    config.maxMem = conf.getLong(MAX_MEM, MAX_MEM_DEFAULT);
    config.maxLatency = conf.getLong(MAX_LATENCY, MAX_LATENCY_DEFAULT);
    config.maxWriteThreads = conf.getInt(MAX_WRITE_THREADS, MAX_WRITE_THREADS_DEFAULT);
    return config;
}

From source file:com.blazegraph.gremlin.structure.EmbeddedBlazeGraphProvider.java

public static BlazeGraphEmbedded open(final Configuration config) {
    final String name = config.getString(Options.REPOSITORY_NAME);
    final BigdataSailRepository repo = getRepository(name);
    return BlazeGraphEmbedded.open(repo, config);
}

From source file:io.wcm.caravan.io.http.impl.CaravanHttpServiceConfigValidator.java

/**
 * Checks if a valid configuration exists for the given service ID. This does not mean that the host
 * name is correct or returns correct responses, it only checks that the minimum required configuration
 * properties are set to a value.//from w w  w. ja  v  a  2  s . co  m
 * @param serviceId Service ID
 * @return true if configuration is valid
 */
public static boolean hasValidConfiguration(String serviceId) {
    Configuration archaiusConfig = ArchaiusConfig.getConfiguration();
    return StringUtils.isNotEmpty(archaiusConfig.getString(serviceId + RIBBON_PARAM_LISTOFSERVERS));
}

From source file:com.linkedin.pinot.broker.broker.AccessControlFactory.java

public static AccessControlFactory loadFactory(Configuration configuration) {
    AccessControlFactory accessControlFactory;
    String accessControlFactoryClassName = configuration.getString(ACCESS_CONTROL_CLASS_CONFIG);
    if (accessControlFactoryClassName == null) {
        accessControlFactoryClassName = AllowAllAccessControlFactory.class.getName();
    }//w ww . ja va2 s  .co  m
    try {
        LOGGER.info("Instantiating Access control factory class {}", accessControlFactoryClassName);
        accessControlFactory = (AccessControlFactory) Class.forName(accessControlFactoryClassName)
                .newInstance();
        LOGGER.info("Initializing Access control factory class {}", accessControlFactoryClassName);
        accessControlFactory.init(configuration);
        return accessControlFactory;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.wingnest.blueprints.impls.jpa.internal.wrappers.EntityManagerFactoryWrapper.java

private static String getUnitName(Configuration configuration) {
    return configuration.getString("blueprints.jpagraph.unit-name");
}