Example usage for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration

List of usage examples for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration

Introduction

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

Prototype

public PropertiesConfiguration() 

Source Link

Document

Creates an empty PropertyConfiguration object which can be used to synthesize a new Properties file by adding values and then saving().

Usage

From source file:cross.osgi.CrossActivator.java

@Override
public void start(BundleContext context) throws Exception {
    setupLogging();//from  w  w w . j  a  v  a 2s.  c o  m
    Dictionary props = new Properties();
    IFactory factory = Factory.getInstance();
    PropertiesConfiguration cfg = new PropertiesConfiguration();
    factory.configure(cfg);
    services = new LinkedList<ServiceRegistration>();
    services.add(context.registerService(Factory.class.getName(), factory, props));
    Collection<? extends AFragmentCommand> commands = Lookup.getDefault().lookupAll(AFragmentCommand.class);
    log.info("Found {} fragment commands!", commands.size());
    for (AFragmentCommand cmd : commands) {
        services.add(context.registerService(AFragmentCommand.class.getName(), cmd, props));
    }
    Collection<? extends IDataSource> dataSources = Lookup.getDefault().lookupAll(IDataSource.class);
    log.info("Found {} data sources!", dataSources.size());
    for (IDataSource ds : dataSources) {
        services.add(context.registerService(IDataSource.class.getName(), ds, props));
    }
    Collection<? extends IControlledVocabularyProvider> cvProviders = Lookup.getDefault()
            .lookupAll(IControlledVocabularyProvider.class);
    log.info("Found {} cvProviders!", cvProviders.size());
    for (IControlledVocabularyProvider icv : cvProviders) {
        services.add(context.registerService(IControlledVocabularyProvider.class.getName(), icv, props));
    }
}

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

private DataNode(Path dataNodePath) throws IOException {
    _dataNodePath = dataNodePath.normalize().toAbsolutePath();
    _dataNodeSliceDirPath = _dataNodePath.resolve(DATANODE_SLICE_DIR);

    _config = new PropertiesConfiguration();
    _config.setDelimiterParsingDisabled(true);
    try {/*from  w  w w.j a  va 2  s.com*/
        _config.load(Files.newInputStream(_dataNodePath.resolve(DATANODE_CONFIG)));
    } catch (ConfigurationException e) {
        throw new IOException(e);
    }

    // ensure this is valid data node
    boolean installed = _config.getBoolean(DATANODE_INSTALLED_KEY);
    if (!installed) {
        throw new InvalidPropertiesFormatException(
                "data node config must contain key " + DATANODE_INSTALLED_KEY);
    }

    // retrieve localhost uri
    {
        String localhostString = _config.getString(DATANODE_LOCALHOSTURI_KEY);
        if (localhostString == null) {
            throw new InvalidPropertiesFormatException(
                    "data node config must contain key " + DATANODE_LOCALHOSTURI_KEY);
        }

        try {
            _localhostURI = new URI(localhostString);
        } catch (URISyntaxException e) {
            throw new InvalidPropertiesFormatException("data node config key " + DATANODE_LOCALHOSTURI_KEY
                    + " has invalid format - " + e.getMessage());
        }
    }

    // retrieve name node
    try {
        _nameNode = NameNodeProvider.loadNameNodeFromConfig(_config, DATANODE_NAMENODE_TYPE_KEY,
                DATANODE_NAMENODE_LOCATION_KEY);
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException("Unable to load name node", e);
    }

    // retrieve slice manager
    _sliceSerializer = _nameNode.getSerializer();
}

From source file:com.pinterest.terrapin.server.OnlineOfflineStateModelFactoryTest.java

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    this.stateModel = (OnlineOfflineStateModelFactory.OnlineOfflineStateModel) new OnlineOfflineStateModelFactory(
            new PropertiesConfiguration(), mockResourcePartitionMap, mockReaderFactory)
                    .createNewStateModel("resource", "OnlineOffline");
}

From source file:io.s4.S4Module.java

private void loadProperties(Binder binder) {

    try {/*from  w ww . j  a v a  2s. c o m*/
        InputStream is = this.getClass().getResourceAsStream(S4_PROPERTIES_FILE);
        config = new PropertiesConfiguration();
        config.load(is);

        System.out.println(ConfigurationUtils.toString(config));
        // TODO - validate properties.

        /* Make all properties injectable. Do we need this? */
        Names.bindProperties(binder, ConfigurationConverter.getProperties(config));
    } catch (ConfigurationException e) {
        binder.addError(e);
        e.printStackTrace();
    }
}

From source file:com.linkedin.pinot.common.segment.fetcher.SegmentFetcherFactoryTest.java

License:asdf

@Test
public void testCustomizedSegmentFetcherFactory() throws Exception {
    Configuration config = new PropertiesConfiguration();
    config.addProperty("something", "abc");
    config.addProperty("protocols", Arrays.asList("http", "https", "test"));
    config.addProperty("http.other", "some config");
    config.addProperty("https.class", NoOpFetcher.class.getName());
    config.addProperty("test.class", TestSegmentFetcher.class.getName());
    _segmentFetcherFactory.init(config);

    Assert.assertTrue(_segmentFetcherFactory.containsProtocol("http"));
    Assert.assertTrue(_segmentFetcherFactory.containsProtocol("https"));
    Assert.assertTrue(_segmentFetcherFactory.containsProtocol("test"));
    SegmentFetcher testSegmentFetcher = _segmentFetcherFactory.getSegmentFetcherBasedOnURI("test://something");
    Assert.assertTrue(testSegmentFetcher instanceof TestSegmentFetcher);
    Assert.assertEquals(((TestSegmentFetcher) testSegmentFetcher).getInitCalled(), 1);
}

From source file:it.geosolutions.opensdi2.configurations.OSDIConfigurationConverterTest.java

@Test
public void propertiesValues2OSDIconfPositiveTest() {
    OSDIConfigConverter builder = new PropertiesConfigurationConverter();
    Configuration config = new PropertiesConfiguration();
    config.addProperty("key1", "value1");
    config.addProperty("key2", "value2");
    config.addProperty("key3", "value3");
    OSDIConfiguration conf = builder.buildConfig(config, "scopeIDtest", "instanceIDtest");
    assertTrue(conf instanceof OSDIConfigurationKVP);
    assertEquals(3, ((OSDIConfigurationKVP) conf).getNumberOfProperties());
    assertEquals("value1", ((OSDIConfigurationKVP) conf).getValue("key1"));
    assertEquals("value2", ((OSDIConfigurationKVP) conf).getValue("key2"));
    assertEquals("value3", ((OSDIConfigurationKVP) conf).getValue("key3"));
}

From source file:com.linkedin.pinot.server.starter.SingleNodeServerStarter.java

/**
 * Construct from config file path/* w w  w . ja v a  2 s  . c  om*/
 * @param configFilePath Path to the config file
 * @throws Exception
 */
public static void buildServerConfig(File configFilePath) throws Exception {
    if (!configFilePath.exists()) {
        LOGGER.error("configuration file: " + configFilePath.getAbsolutePath() + " does not exist.");
        throw new ConfigurationException(
                "configuration file: " + configFilePath.getAbsolutePath() + " does not exist.");
    }

    // build _serverConf
    final PropertiesConfiguration serverConf = new PropertiesConfiguration();
    serverConf.setDelimiterParsingDisabled(false);
    serverConf.load(configFilePath);
    _serverConf = new ServerConf(serverConf);
}

From source file:com.easyvalidation.xml.processor.XMLProcessor.java

/**
 * Parse the XML & return list of rules.
 * /*ww  w  .ja v  a2 s  .  c o  m*/
 * @param fileNames
 * @return
 * @throws ValidationException
 */
public static Map<String, List<Rule>> parseXML(String[] fileNames) throws ValidationException {
    Map<String, List<Rule>> validationMap = new HashMap<String, List<Rule>>();

    com.easyvalidation.xml.config.EasyValidationXmlConfiguration configuration = new com.easyvalidation.xml.config.EasyValidationXmlConfiguration();
    //System.out.println("Have we came here?");
    configuration.setAutoSave(false);
    //System.out.println("Have we came here?");
    configuration.clear();
    //System.out.println("Have we came here?");
    configuration.setValidating(true);

    try {
        for (String fileName : fileNames) {
            //System.out.println("Have we came here4?");
            configuration.load(fileName);
            //System.out.println("Have we came here5?");
        }
        //System.out.println("Have we came here?");
        boolean isMessageFromKeyAllowed = false;

        Map<String, PropertiesConfiguration> propertiesMap = new HashMap<String, PropertiesConfiguration>();
        int propertiesSize = configuration.getMaxIndex(Nodes.PROPERTIES);
        for (int propertiesIndex = 0; propertiesIndex <= propertiesSize; propertiesIndex++) {

            String locale = configuration.getString(RuleElementPathUtil.getPropsFileLocale(propertiesIndex));

            PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
            propertiesConfiguration.setAutoSave(false);
            propertiesConfiguration.clear();

            HierarchicalConfiguration subConfig = configuration
                    .configurationAt(RuleElementPathUtil.getPropertiesPath(propertiesIndex));
            //System.out.println("Have we came here6?");
            int propFileSize = subConfig.getMaxIndex(Nodes.FILE);
            for (int propFileIndex = 0; propFileIndex <= propFileSize; propFileIndex++) {
                String propFileName = subConfig.getString(RuleElementPathUtil.getPropsFilePath(propFileIndex));
                if (!Utils.isEmpty(propFileName)) {
                    propertiesConfiguration.load(propFileName);
                }
            }
            propertiesMap.put(locale, propertiesConfiguration);
        }
        //System.out.println("Have we came here7?");
        if (!propertiesMap.isEmpty()) {
            isMessageFromKeyAllowed = true;
        }

        int validationSize = configuration.getMaxIndex(Nodes.VALIDATION);

        for (int validationIndex = 0; validationIndex <= validationSize; validationIndex++) {
            String name = configuration.getString(RuleElementPathUtil.getValidationName(validationIndex));

            HierarchicalConfiguration subConfig = configuration
                    .configurationAt(RuleElementPathUtil.getValidation(validationIndex));

            int ruleSize = subConfig.getMaxIndex(Nodes.RULE);
            List<Rule> ruleList = new ArrayList<Rule>();
            for (int ruleIndex = 0; ruleIndex <= ruleSize; ruleIndex++) {
                String ruleType = subConfig.getString(RuleElementPathUtil.getRuleType(ruleIndex));

                String property = subConfig.getString(RuleElementPathUtil.getRuleFieldName(ruleIndex));

                String message = subConfig.getString(RuleElementPathUtil.getRuleMessage(ruleIndex));

                String min = subConfig.getString(RuleElementPathUtil.getRuleMin(ruleIndex));

                String max = subConfig.getString(RuleElementPathUtil.getRuleMax(ruleIndex));

                String dateFormat = subConfig.getString(RuleElementPathUtil.getRuleDateFormat(ruleIndex));

                String key = subConfig.getString(RuleElementPathUtil.getMessageKey(ruleIndex));

                String useAttributePlaceHolder = subConfig
                        .getString(RuleElementPathUtil.getMessageUseAttributePlaceHolder(ruleIndex));

                String regEx = subConfig.getString(RuleElementPathUtil.getRuleRegEx(ruleIndex));

                String expression = subConfig.getString(RuleElementPathUtil.getRuleExpression(ruleIndex));

                Rule rule = new Rule(ruleType);

                rule.setProperty(property);
                rule.setMessage(message);
                rule.setMin(min);
                rule.setMax(max);
                rule.setDateFormat(dateFormat);
                rule.setKey(key);
                rule.setUseAttributePlaceHolder(Boolean.valueOf(useAttributePlaceHolder));
                rule.setRegEx(Boolean.valueOf(regEx));
                rule.setExpression(expression);
                if (isMessageFromKeyAllowed) {
                    rule.setPropertiesMap(propertiesMap);
                }

                rule.populateRule();
                ruleList.add(rule);
            }
            validationMap.put(name, ruleList);
        }
    } catch (Exception ex) {
        throw new ValidationException(ex);
    }

    return validationMap;
}

From source file:ch.descabato.browser.BackupBrowser.java

public static void main2(final String[] args)
        throws InterruptedException, InvocationTargetException, SecurityException, IOException {
    if (args.length > 1)
        throw new IllegalArgumentException(
                "SYNTAX:  java... " + BackupBrowser.class.getName() + " [initialPath]");

    SwingUtilities.invokeAndWait(new Runnable() {

        @Override/*from   ww w  .  ja  v a 2s . c o  m*/
        public void run() {
            tryLoadSubstanceLookAndFeel();
            final JFrame f = new JFrame("OtrosVfsBrowser demo");
            f.addWindowListener(finishedListener);
            Container contentPane = f.getContentPane();
            contentPane.setLayout(new BorderLayout());
            DataConfiguration dc = null;
            final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
            File favoritesFile = new File("favorites.properties");
            propertiesConfiguration.setFile(favoritesFile);
            if (favoritesFile.exists()) {
                try {
                    propertiesConfiguration.load();
                } catch (ConfigurationException e) {
                    e.printStackTrace();
                }
            }
            dc = new DataConfiguration(propertiesConfiguration);
            propertiesConfiguration.setAutoSave(true);
            final VfsBrowser comp = new VfsBrowser(dc, (args.length > 0) ? args[0] : null);
            comp.setSelectionMode(SelectionMode.FILES_ONLY);
            comp.setMultiSelectionEnabled(true);
            comp.setApproveAction(new AbstractAction(Messages.getMessage("demo.showContentButton")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    FileObject[] selectedFiles = comp.getSelectedFiles();
                    System.out.println("Selected files count=" + selectedFiles.length);
                    for (FileObject selectedFile : selectedFiles) {
                        try {
                            FileSize fileSize = new FileSize(selectedFile.getContent().getSize());
                            System.out.println(selectedFile.getName().getURI() + ": " + fileSize.toString());
                            Desktop.getDesktop()
                                    .open(new File(new URI(selectedFile.getURL().toExternalForm())));
                            //                byte[] bytes = readBytes(selectedFile.getContent().getInputStream(), 150 * 1024l);
                            //                JScrollPane sp = new JScrollPane(new JTextArea(new String(bytes)));
                            //                JDialog d = new JDialog(f);
                            //                d.setTitle("Content of file: " + selectedFile.getName().getFriendlyURI());
                            //                d.getContentPane().add(sp);
                            //                d.setSize(600, 400);
                            //                d.setVisible(true);
                        } catch (Exception e1) {
                            LOGGER.error("Failed to read file", e1);
                            JOptionPane.showMessageDialog(f,
                                    (e1.getMessage() == null) ? e1.toString() : e1.getMessage(), "Error",
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
            });

            comp.setCancelAction(new AbstractAction(Messages.getMessage("general.cancelButtonText")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    f.dispose();
                    try {
                        propertiesConfiguration.save();
                    } catch (ConfigurationException e1) {
                        e1.printStackTrace();
                    }
                    System.exit(0);
                }
            });
            contentPane.add(comp);

            f.pack();
            f.setVisible(true);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        }
    });
    while (!finished)
        Thread.sleep(100);
}

From source file:com.linkedin.pinot.core.data.manager.config.TableDataManagerConfig.java

public static TableDataManagerConfig getDefaultHelixTableDataManagerConfig(
        InstanceDataManagerConfig _instanceDataManagerConfig, String tableName) throws ConfigurationException {
    TableType tableType = TableNameBuilder.getTableTypeFromTableName(tableName);

    Configuration defaultConfig = new PropertiesConfiguration();
    defaultConfig.addProperty(TABLE_DATA_MANAGER_NAME, tableName);
    String dataDir = _instanceDataManagerConfig.getInstanceDataDir() + "/" + tableName;
    defaultConfig.addProperty(TABLE_DATA_MANAGER_DATA_DIRECTORY, dataDir);
    if (_instanceDataManagerConfig.getReadMode() != null) {
        defaultConfig.addProperty(READ_MODE, _instanceDataManagerConfig.getReadMode().toString());
    } else {//from w  ww.j  av  a  2 s . c om
        defaultConfig.addProperty(READ_MODE, ReadMode.heap);
    }
    if (_instanceDataManagerConfig.getSegmentFormatVersion() != null) {
        defaultConfig.addProperty(IndexLoadingConfigMetadata.KEY_OF_SEGMENT_FORMAT_VERSION,
                _instanceDataManagerConfig.getSegmentFormatVersion());
    }
    if (_instanceDataManagerConfig.isEnableDefaultColumns()) {
        defaultConfig.addProperty(IndexLoadingConfigMetadata.KEY_OF_ENABLE_DEFAULT_COLUMNS, true);
    }
    defaultConfig.addProperty(TABLE_DATA_MANAGER_NUM_QUERY_EXECUTOR_THREADS, 20);
    TableDataManagerConfig tableDataManagerConfig = new TableDataManagerConfig(defaultConfig);

    switch (tableType) {
    case OFFLINE:
        defaultConfig.addProperty(TABLE_DATA_MANAGER_TYPE, "offline");
        break;
    case REALTIME:
        defaultConfig.addProperty(TABLE_DATA_MANAGER_TYPE, "realtime");
        break;

    default:
        throw new UnsupportedOperationException("Not supported table type for - " + tableName);
    }
    return tableDataManagerConfig;
}