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:de.shadowhunt.sonar.plugins.ignorecode.batch.IgnoreIssueFilter.java

static List<IssuePattern> loadPatterns(final Configuration configuration) {
    if (configuration == null) {
        return Collections.emptyList();
    }/*from ww  w  .  j a  va2 s  . c  o m*/

    final String fileLocation = configuration.getString(CONFIG_FILE);
    if (StringUtils.isBlank(fileLocation)) {
        LOGGER.info("no ignore file configured for property: {}", CONFIG_FILE);
        return Collections.emptyList();
    }

    final File ignoreFile = new File(fileLocation);
    if (!ignoreFile.isFile()) {
        LOGGER.error("could not find ignore file: {}", ignoreFile);
        return Collections.emptyList();
    }

    FileInputStream fis = null;
    try {
        fis = new FileInputStream(ignoreFile);
        final List<IssuePattern> patterns = IssuePattern.parse(fis);
        LOGGER.info("loaded {} violation ignores from {}", patterns.size(), ignoreFile);
        return patterns;
    } catch (final Exception e) {
        throw new SonarException("could not load ignores for file: " + ignoreFile, e);
    } finally {
        IOUtils.closeQuietly(fis);
    }
}

From source file:com.beginner.core.utils.PropertyUtil.java

/**
 * org.apache.commons.configuration.Configuration?properties??TestResourcesUtil
 * <p>//from w  ww .  ja  va  2s .c  o  m
 * ????properties?<br>
 * 1?classpathkey=type fileName=beginner.properties             -mysql<br>
 * 2?key=type fileName=/data/app/beginner.properties    -mysql<br>
 * 3?key=type fileName=D:/data/app/beginner.properties    -mysql<br>
 * </p>
 * @param key         key
 * @param fileName      +??+???
 * @return String      keyvalue
 * @throws Exception   IO
 */
public static String getProperties(String key, String fileName) throws Exception {

    if (StringUtils.isBlank(key))
        throw new IllegalArgumentException("The key cannot be null and cannot be empty.");

    if (StringUtils.isBlank(fileName))
        throw new IllegalArgumentException("The fileName cannot be null and cannot be empty.");

    String properties = StringUtils.EMPTY;
    Configuration config = null;
    try {
        config = new PropertiesConfiguration(fileName);
        properties = config.getString(key);
    } catch (Exception e) {
        throw new Exception();
    }
    return properties;
}

From source file:de.shadowhunt.sonar.plugins.ignorecode.batch.IgnoreCoverageDecorator.java

static List<CoveragePattern> loadPatterns(final Configuration configuration) {
    if (configuration == null) {
        return Collections.emptyList();
    }//  w ww.  jav  a2 s  .  c o m

    final String fileLocation = configuration.getString(CONFIG_FILE);
    if (StringUtils.isBlank(fileLocation)) {
        LOGGER.info("no ignore file configured for property: {}", CONFIG_FILE);
        return Collections.emptyList();
    }

    final File ignoreFile = new File(fileLocation);
    if (!ignoreFile.isFile()) {
        LOGGER.error("could not find ignore file: {}", ignoreFile);
        return Collections.emptyList();
    }

    FileInputStream fis = null;
    try {
        fis = new FileInputStream(ignoreFile);
        final List<CoveragePattern> patterns = CoveragePattern.parse(fis);
        LOGGER.info("loaded {} coverage ignores from {}", patterns.size(), ignoreFile);
        return patterns;
    } catch (final Exception e) {
        throw new SonarException("could not load ignores for file: " + ignoreFile, e);
    } finally {
        IOUtils.closeQuietly(fis);
    }
}

From source file:com.steelbridgelabs.oss.neo4j.structure.Neo4JGraphFactory.java

public static Graph open(Configuration configuration) {
    if (null == configuration)
        throw Graph.Exceptions.argumentCanNotBeNull("configuration");
    try {//from   ww  w. j  av a 2s. c  om
        Config config = Config.build().toConfig();
        // graph name
        String graphName = configuration
                .getString(Neo4JGraphConfigurationBuilder.Neo4JGraphNameConfigurationKey);
        // create driver instance
        Driver driver = GraphDatabase.driver(
                configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JUrlConfigurationKey),
                AuthTokens.basic(
                        configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JUsernameConfigurationKey),
                        configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JPasswordConfigurationKey)),
                config);
        // create providers
        Neo4JElementIdProvider<?> vertexIdProvider = loadProvider(configuration
                .getString(Neo4JGraphConfigurationBuilder.Neo4JVertexIdProviderClassNameConfigurationKey));
        Neo4JElementIdProvider<?> edgeIdProvider = loadProvider(configuration
                .getString(Neo4JGraphConfigurationBuilder.Neo4JEdgeIdProviderClassNameConfigurationKey));
        // check a read partition is required
        if (graphName != null)
            return new Neo4JGraph(new AnyLabelReadPartition(graphName), new String[] { graphName }, driver,
                    vertexIdProvider, edgeIdProvider);
        // no partition
        return new Neo4JGraph(driver, vertexIdProvider, edgeIdProvider);
    } catch (Throwable ex) {
        // throw runtime exception
        throw new RuntimeException("Error creating Graph instance from configuration", ex);
    }
}

From source file:dk.itst.oiosaml.sp.service.util.Utils.java

public static Object newInstance(Configuration cfg, String property) {
    String name = cfg.getString(property);
    if (name == null) {
        throw new IllegalArgumentException("Property " + property + " has not been set");
    }//from  ww w  .  j av  a  2s. c o m

    try {
        Class<?> c = Class.forName(name);

        return c.newInstance();
    } catch (Exception e) {
        throw new RuntimeException("Unable to create instance of " + name, e);
    }
}

From source file:com.nesscomputing.config.Config.java

/**
 * Loads the configuration. The no-args method uses system properties to determine which configurations
 * to load.//from ww  w .  j  a  v  a2 s  .  c  om
 *
 * -Dness.config=x/y/z defines a hierarchy of configurations from general
 * to detail.
 *
 * The ness.config.location variable must be set.
 * If the ness.config variable is unset, the default value "default" is used.
 *
 * @throws IllegalStateException If the ness.config.location variable is not set.
 */
public static Config getConfig() {
    final Configuration systemConfig = new SystemConfiguration();
    final String configName = systemConfig.getString(CONFIG_PROPERTY_NAME);
    final String configLocation = systemConfig.getString(CONFIG_LOCATION_PROPERTY_NAME);
    Preconditions.checkState(configLocation != null, "Config location must be set!");
    final ConfigFactory configFactory = new ConfigFactory(URI.create(configLocation), configName);
    return new Config(configFactory.load());
}

From source file:edu.lternet.pasta.client.EventSubscriptionClientTest.java

/**
 * @throws java.lang.Exception// w ww .j  ava  2 s.  c  o m
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {

    ConfigurationListener.configure();
    Configuration options = ConfigurationListener.getOptions();

    if (options == null) {
        fail("Failed to load the DataPortal properties file: 'dataportal.properties'");
    } else {
        uid = options.getString("eventservice.uid");
        if (uid == null) {
            fail("No value found for EventService property: 'eventservice.uid'");
        }
        password = options.getString("eventservice.password");
        if (password == null) {
            fail("No value found for EventService property: 'eventservice.password'");
        }
        token = options.getString("eventservice.token");
        if (token == null) {
            fail("No value found for EventService property: 'eventservice.token'");
        }

    }

}

From source file:com.idocbox.common.config.PropertyUtil.java

/**
 * get string from value from module file.
 * @param module//from  w w  w .  j a va  2 s  .c o m
 * @param key
 * @return
 */
public static String getString(String module, String key) {
    String value = null;
    if (module == null || key == null)
        throw new IllegalArgumentException(MSG_ILLEGAL_ARGUMENT);
    try {
        Configuration configuration = getConfiguration(module);
        if (null != configuration) {
            value = configuration.getString(key);
        }
    } catch (ConfigurationException e) {
        logger.error("Error:", e);
    }

    return value;
}

From source file:co.turnus.analysis.profiler.orcc.code.OrccStaticProfilerOptions.java

private static void setOutputPath(Configuration conf, String customPath) {
    // store the root path for the output.
    File outPath = null;/*from   w  ww .  ja  v  a2  s  . co  m*/
    if (customPath != null && !customPath.isEmpty()) {
        outPath = new File(customPath);
    } else {
        String project = conf.getString(ORCC_PROJECT);
        IProject pojo = EcoreHelper.getProject(project);
        outPath = pojo.getRawLocation().makeAbsolute().toFile();
        outPath = new File(outPath, "turnus");
        outPath = new File(outPath, "code");

    }

    conf.setProperty(OUTPUT_PATH, outPath.getAbsolutePath());

}

From source file:com.knowbout.epg.EPG.java

private static void test(Configuration config) throws IOException {
    HibernateUtil.openSession();//from  w  w w.ja v  a2  s.  c  om
    Configuration provider = config.subset("provider");
    File destinationFolder = new File(provider.getString("destinationFolder"));
    Configuration files = config.subset("files");
    File schedules = new File(destinationFolder, files.getString("schedules"));
    //Test loading

    GZIPInputStream uis = new GZIPInputStream(new FileInputStream(schedules));
    ScheduleParser SkedParser = new ScheduleParser();
    SkedParser.parseSchedule(uis, config);

    try {
        EPGProviderService service = new EPGProviderService();
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, 20);
        //Test date now.
        ScheduledProgram sp = service.getScheduledProgramByNetworkCallSign("P-C", "NBC", new Date());
        System.err.println("IS SP NULL: " + (sp == null));
        if (sp != null) {
            System.err.println("\tSP: " + sp.getProgramTitle() + "  " + sp.getProgramId());
        }

        sp = service.getScheduledProgramByNetworkCallSign("SDTW-C", "NBC", new Date());
        System.err.println("SDTW- IS SP NULL: " + (sp == null));
        if (sp != null) {
            System.err.println("\tSP: " + sp.getProgramTitle() + "  " + sp.getProgramId());
        }

        //      System.err.println("SP is :"  +sp.getProgramTitle());
        //      try {
        //      List<ScheduledProgram> skedProgs = service.getScheduleForShow("P-DC", "Survivorman", new Date(), cal.getTime(), 1);
        //      for (ScheduledProgram prog: skedProgs) {
        //         System.err.println(" limit 1 SHOW: " + prog.getProgramId()+ " " + prog.getEpisodeTitle() + " starts at " + prog.getStartTime() + " " + prog.getNetwork().getStationCallSign());
        //      }
        ////      sp = service.getScheduledProgram("CA04542:DEFAULT", "41", new Date());
        ////      System.err.println("SP is :"  +sp.getProgramTitle());
        //      skedProgs = service.getScheduleForShow("P-DC", "Survivorman", new Date(), cal.getTime(), 0);
        //      for (ScheduledProgram prog: skedProgs) {
        //         System.err.println("NO LIMIT SHOW: " + prog.getProgramId()+ " " + prog.getEpisodeTitle() + "(" + prog.getScheduleId()+")"+ " starts at " + prog.getStartTime()+ " " + prog.getNetwork().getStationCallSign());
        //      }
        //      sp = service.getScheduledProgram("CA04542:DEFAULT", "7", new Date());
        //      System.err.println("SP is :"  +sp.getProgramTitle());
        //      ScheduledProgram next = service.getNextShowing("CA04542:DEFAULT", "EP6856270007");
        //      if (next != null) {
        //         System.err.println("Next - " + next.getEpisodeTitle() + " starts at " + next.getStartTime());
        //      } else {
        //         System.err.println("Unable to find next showing");
        //      }
        //      ScheduledProgram last = service.getLastShowing("CA04542:DEFAULT", "EP6856270007");
        //      if (last != null) {
        //         System.err.println("Last - " + last.getEpisodeTitle() + " starts at " + last.getStartTime());
        //      } else {
        //         System.err.println("Unable to find last showing");
        //      }
        //      
        //      
    } finally {
        HibernateUtil.closeSession();
    }
    if (true) {
        System.exit(-1);
    }
}