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:edu.lternet.pasta.client.ReportUtilityTest.java

/**
 * @throws java.lang.Exception//from   w  w  w  .j  a va  2s  . 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 {

        testReport = options.getString("qualityreportutility.testreport");
        if (testReport == null) {
            fail("No value found for test report: 'qualityreportutility.testreport'");
        }

        xslPath = options.getString("qualityreportutility.xslpath");
        if (xslPath == null) {
            fail("No value found for XSL path: 'qualityreportutility.xslpath");
        }

        testPackageId = options.getString("qualityreportutility.testpackageid");
        if (testPackageId == null) {
            fail("No value found for test Package Id: 'qualityreportutility.testpackageid");
        }

    }

    // Read test report XML from file to string
    cwd = System.getProperty("user.dir");
    xmlFile = new File(cwd + testReport);
    xmlString = FileUtils.readFileToString(xmlFile);

    // Create new QualityRerportUtitliy object
    qru = new ReportUtility(xmlString);

}

From source file:edu.usc.goffish.gofs.namenode.NameNodeProvider.java

public static IInternalNameNode loadNameNodeFromConfig(Configuration config, String nameNodeTypeKey,
        String nameNodeLocationKey) throws ClassNotFoundException, ReflectiveOperationException {
    // retrieve name node type
    Class<? extends IInternalNameNode> nameNodeType;
    {/* w  w  w . j a v a  2  s . c om*/
        String nameNodeTypeString = config.getString(nameNodeTypeKey);
        if (nameNodeTypeString == null) {
            throw new ConversionException("Config must contain key " + nameNodeTypeKey);
        }

        try {
            nameNodeType = NameNodeProvider.loadNameNodeType(nameNodeTypeString);
        } catch (ReflectiveOperationException e) {
            throw new ConversionException(
                    "Config key " + nameNodeTypeKey + " has invalid format - " + e.getMessage());
        }
    }

    // retrieve name node location
    URI nameNodeLocation;
    {
        String nameNodeLocationString = config.getString(nameNodeLocationKey);
        if (nameNodeLocationString == null) {
            throw new ConversionException("Config must contain key " + nameNodeLocationKey);
        }

        try {
            nameNodeLocation = new URI(nameNodeLocationString);
        } catch (URISyntaxException e) {
            throw new ConversionException(
                    "Config key " + nameNodeLocationKey + " has invalid format - " + e.getMessage());
        }
    }

    return loadNameNode(nameNodeType, nameNodeLocation);
}

From source file:com.manydesigns.mail.quartz.MailScheduler.java

public static void setupMailScheduler(MailQueueSetup mailQueueSetup, String group) {
    Configuration mailConfiguration = mailQueueSetup.getMailConfiguration();
    if (mailConfiguration != null) {
        if (mailConfiguration.getBoolean(MailProperties.MAIL_QUARTZ_ENABLED, false)) {
            logger.info("Scheduling mail sends with Quartz job");
            try {
                String serverUrl = mailConfiguration.getString(MailProperties.MAIL_SENDER_SERVER_URL);
                logger.info("Scheduling mail sends using URL: {}", serverUrl);

                Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
                JobDetail job = JobBuilder.newJob(URLInvokeJob.class).withIdentity("mail.sender", group)
                        .usingJobData(URLInvokeJob.URL_KEY, serverUrl).build();

                int pollInterval = mailConfiguration.getInt(MailProperties.MAIL_SENDER_POLL_INTERVAL,
                        DEFAULT_POLL_INTERVAL);

                Trigger trigger = TriggerBuilder.newTrigger().withIdentity("mail.sender.trigger", group)
                        .startNow().withSchedule(SimpleScheduleBuilder.simpleSchedule()
                                .withIntervalInMilliseconds(pollInterval).repeatForever())
                        .build();//from w ww. jav  a2s.  c  o  m

                scheduler.scheduleJob(job, trigger);
            } catch (Exception e) {
                logger.error("Could not schedule mail sender job", e);
            }
        } else {
            logger.info("Mail scheduling using Quartz is disabled");
        }
    }
}

From source file:dk.itst.oiosaml.sp.metadata.SPMetadata.java

public static SPMetadata getInstance() {
    if (instance == null) {
        Configuration conf = SAMLConfiguration.getSystemConfiguration();
        String directory = SAMLConfiguration.getStringPrefixedWithBRSHome(conf, METADATA_DIRECTORY);
        String fileName = conf.getString(METADATA_FILE);
        try {// w  w  w. j av  a 2s. c  o m
            instance = new SPMetadata(
                    (EntityDescriptor) SAMLUtil.unmarshallElementFromFile(directory + "/" + fileName),
                    conf.getString(Constants.PROP_PROTOCOL));
        } catch (Exception e) {
            log.error("Cannot load the metadata file: " + fileName + " - " + e.getMessage(), e);
            throw new IllegalArgumentException(e.getMessage());
        }
    }
    return instance;
}

From source file:com.github.anba.test262.environment.Environments.java

/**
 * Creates a new Rhino environment/*  w  ww.ja v  a2  s.  c o  m*/
 */
public static <T extends GlobalObject> EnvironmentProvider<T> rhino(final Configuration configuration) {
    final int version = configuration.getInt("rhino.version", Context.VERSION_DEFAULT);
    final String compiler = configuration.getString("rhino.compiler.default");
    List<?> enabledFeatures = configuration.getList("rhino.features.enabled", emptyList());
    List<?> disabledFeatures = configuration.getList("rhino.features.disabled", emptyList());
    final Set<Integer> enabled = intoCollection(filterMap(enabledFeatures, notEmptyString, toInteger),
            new HashSet<Integer>());
    final Set<Integer> disabled = intoCollection(filterMap(disabledFeatures, notEmptyString, toInteger),
            new HashSet<Integer>());

    /**
     * Initializes the global {@link ContextFactory} according to the
     * supplied configuration
     * 
     * @see ContextFactory#initGlobal(ContextFactory)
     */
    final ContextFactory factory = new ContextFactory() {
        @Override
        protected boolean hasFeature(Context cx, int featureIndex) {
            if (enabled.contains(featureIndex)) {
                return true;
            } else if (disabled.contains(featureIndex)) {
                return false;
            }
            return super.hasFeature(cx, featureIndex);
        }

        @Override
        protected Context makeContext() {
            Context context = super.makeContext();
            context.setLanguageVersion(version);
            return context;
        }
    };

    EnvironmentProvider<RhinoGlobalObject> provider = new EnvironmentProvider<RhinoGlobalObject>() {
        @Override
        public RhinoEnv<RhinoGlobalObject> environment(final String testsuite, final String sourceName,
                final Test262Info info) {
            Configuration c = configuration.subset(testsuite);
            final boolean strictSupported = c.getBoolean("strict", false);
            final String encoding = c.getString("encoding", "UTF-8");
            final String libpath = c.getString("lib_path");

            final Context cx = factory.enterContext();
            final AtomicReference<RhinoGlobalObject> $global = new AtomicReference<>();

            final RhinoEnv<RhinoGlobalObject> environment = new RhinoEnv<RhinoGlobalObject>() {
                @Override
                public RhinoGlobalObject global() {
                    return $global.get();
                }

                @Override
                protected String getEvaluator() {
                    return compiler;
                }

                @Override
                protected String getCharsetName() {
                    return encoding;
                }

                @Override
                public void exit() {
                    Context.exit();
                }
            };

            @SuppressWarnings({ "serial" })
            final RhinoGlobalObject global = new RhinoGlobalObject() {
                {
                    cx.initStandardObjects(this, false);
                }

                @Override
                protected boolean isStrictSupported() {
                    return strictSupported;
                }

                @Override
                protected String getDescription() {
                    return info.getDescription();
                }

                @Override
                protected void failure(String message) {
                    failWith(message, sourceName);
                }

                @Override
                protected void include(Path path) throws IOException {
                    // resolve the input file against the library path
                    Path file = Paths.get(libpath).resolve(path);
                    InputStream source = Files.newInputStream(file);
                    environment.eval(file.getFileName().toString(), source);
                }
            };

            $global.set(global);

            return environment;
        }
    };

    @SuppressWarnings("unchecked")
    EnvironmentProvider<T> p = (EnvironmentProvider<T>) provider;

    return p;
}

From source file:com.comcast.viper.flume2storm.connection.parameters.KryoNetConnectionParameters.java

/**
 * @param config//  w  ww .j av  a  2  s  .co m
 *          The configuration to use
 * @return The newly constructed {@link KryoNetConnectionParameters} based on
 *         the {@link Configuration} specified
 * @throws F2SConfigurationException
 *           If the configuration specified is invalid
 */
public static KryoNetConnectionParameters from(Configuration config) throws F2SConfigurationException {
    KryoNetConnectionParameters result = new KryoNetConnectionParameters();
    try {
        String hostname = config.getString(ADDRESS);
        if (hostname == null) {
            try {
                hostname = InetAddress.getLocalHost().getHostAddress();
            } catch (final UnknownHostException e) {
                hostname = ADDRESS_DEFAULT;
            }
        }
        assert hostname != null;
        result.setAddress(hostname);
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, ADDRESS, e);
    }
    try {
        result.setServerPort(config.getInt(PORT, PORT_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, PORT, e);
    }
    try {
        result.setObjectBufferSize(config.getInt(OBJECT_BUFFER_SZ, OBJECT_BUFFER_SIZE_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, OBJECT_BUFFER_SZ, e);
    }
    try {
        result.setWriteBufferSize(config.getInt(WRITE_BUFFER_SZ, WRITE_BUFFER_SIZE_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, WRITE_BUFFER_SZ, e);
    }
    return result;
}

From source file:com.boozallen.cognition.ingest.storm.util.ConfigurationMapEntryUtils.java

/**
 * Extracts Map&lt;String, String&gt; from XML of the format:
 * <pre>/*from   w ww  .j a v a  2 s .c  om*/
 * {@code <mapName>
 *     <entry>
 *       <key>k0</key>
 *       <value>v0</value>
 *     </entry>
 *     <entry>
 *       <key>k1</key>
 *       <value>v1</value>
 *     </entry>
 *   </mapName>
 * }
 * </pre>
 *
 * @param conf
 * @param mapName
 * @param entry
 * @param key
 * @param value
 * @return
 */
public static Map<String, String> extractSimpleMap(final Configuration conf, final String mapName,
        final String entry, final String key, final String value) {
    List<Object> fieldsList = conf.getList(mapName + "." + entry + "." + key);
    LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
    for (int i = 0; i < fieldsList.size(); i++) {
        String relevanceField = conf.getString(mapName + "." + entry + "(" + i + ")." + value);
        map.put(fieldsList.get(i).toString(), relevanceField);
    }
    return map;
}

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

/**
 * Loads the configuration. The no-args method uses system properties to determine which configurations
 * to load.// w w  w  .java  2 s  . c  om
 *
 * -Dot.config=x/y/z defines a hierarchy of configurations from general
 * to detail.
 *
 * The ot.config.location variable must be set.
 * If the ot.config variable is unset, the default value "default" is used.
 *
 * @throws IllegalStateException If the ot.config.location variable is not set.
 */
public static Config getConfig() {
    final Configuration systemConfig = new SystemConfiguration();
    final String configName = StringUtils.join(systemConfig.getList(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:com.salesmanager.core.util.CurrencyUtil.java

public static String getDefaultCurrency() {

    Configuration conf = PropertiesUtil.getConfiguration();
    String def = conf.getString("core.system.defaultcurrency");
    if (def == null) {
        def = Constants.CURRENCY_CODE_USD;
    }/*from  w w  w.ja  va 2s  .  c  om*/

    return def;
}

From source file:cz.cas.lib.proarc.common.export.Kramerius4ExportOptions.java

public static Kramerius4ExportOptions from(Configuration config) {
    Kramerius4ExportOptions options = new Kramerius4ExportOptions();

    String[] excludeIds = config.getStringArray(PROP_EXCLUDE_DATASTREAM_ID);
    options.setExcludeDatastreams(new HashSet<String>(Arrays.asList(excludeIds)));

    Configuration renames = config.subset(PROP_RENAME_PREFIX);
    HashMap<String, String> dsIdMap = new HashMap<String, String>();
    // use RAW if FULL ds is not available
    dsIdMap.put(BinaryEditor.RAW_ID, "IMG_FULL");
    for (Iterator<String> it = renames.getKeys(); it.hasNext();) {
        String dsId = it.next();/*from  ww w  . j a  v  a2  s. c  om*/
        String newDsId = renames.getString(dsId);
        dsIdMap.put(dsId, newDsId);
    }
    options.setDsIdMap(dsIdMap);

    String policy = config.getString(PROP_POLICY);
    if (policy != null && !policy.isEmpty()) {
        options.setPolicy(policy);
    }
    return options;
}