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

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

Introduction

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

Prototype

public void load() throws ConfigurationException 

Source Link

Document

Load the configuration from the underlying location.

Usage

From source file:edu.usc.goffish.gopher.impl.Main.java

public static void main(String[] args) {

    Properties properties = new Properties();
    try {/*from   w w  w  .j  a v a2  s .c  o m*/
        properties.load(new FileInputStream(CONFIG_FILE));
    } catch (IOException e) {
        String message = "Error while loading Container Configuration from " + CONFIG_FILE + " Cause -"
                + e.getCause();
        log.warning(message);
    }

    if (args.length == 4) {

        PropertiesConfiguration propertiesConfiguration;
        String url = null;

        URI uri = URI.create(args[3]);

        String dataDir = uri.getPath();

        String currentHost = uri.getHost();
        try {

            propertiesConfiguration = new PropertiesConfiguration(dataDir + "/gofs.config");
            propertiesConfiguration.load();
            url = (String) propertiesConfiguration.getString(DataNode.DATANODE_NAMENODE_LOCATION_KEY);

        } catch (ConfigurationException e) {

            String message = " Error while reading gofs-config cause -" + e.getCause();
            handleException(message);
        }

        URI nameNodeUri = URI.create(url);

        INameNode nameNode = new RemoteNameNode(nameNodeUri);
        int partition = -1;
        try {
            for (URI u : nameNode.getDataNodes()) {
                if (URIHelper.isLocalURI(u)) {
                    IDataNode dataNode = DataNode.create(u);
                    IntCollection partitions = dataNode.getLocalPartitions(args[2]);
                    partition = partitions.iterator().nextInt();
                    break;
                }
            }

            if (partition == -1) {
                String message = "Partition not loaded from uri : " + nameNodeUri;
                handleException(message);
            }

            properties.setProperty(GopherInfraHandler.PARTITION, String.valueOf(partition));

        } catch (Exception e) {
            String message = "Error while loading Partitions from " + nameNodeUri + " Cause -" + e.getMessage();
            e.printStackTrace();
            handleException(message);
        }

        properties.setProperty(Constants.STATIC_PELLET_COUNT, String.valueOf(1));
        FloeRuntimeEnvironment environment = FloeRuntimeEnvironment.getEnvironment();
        environment.setSystemConfig(properties);
        properties.setProperty(Constants.CURRET_HOST, currentHost);
        String managerHost = args[0];
        int managerPort = Integer.parseInt(args[1]);

        Container container = environment.getContainer();
        container.setManager(managerHost, managerPort);

        DefaultClientConfig config = new DefaultClientConfig();
        config.getProperties().put(ClientConfig.FEATURE_DISABLE_XML_SECURITY, true);
        config.getFeatures().put(ClientConfig.FEATURE_DISABLE_XML_SECURITY, true);

        Client c = Client.create(config);

        if (managerHost == null || managerPort == 0) {
            handleException("Manager Host / Port have to be configured in " + args[0]);
        }

        WebResource r = c.resource("http://" + managerHost + ":" + managerPort
                + "/Manager/addContainerInfo/Container=" + container.getContainerInfo().getContainerId()
                + "/Host=" + container.getContainerInfo().getContainerHost());
        c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
        r.post();
        log.log(Level.INFO, "Container started  ");

    } else {

        String message = "Invalid arguments , arg[0]=Manager host, "
                + "arg[1] = mamanger port,arg[2]=graph id,arg[3]=partition uri";

        message += "\n Current Arguments...." + args.length + "\n";
        for (int i = 0; i < args.length; i++) {
            message += "arg " + i + " : " + args[i] + "\n";
        }

        handleException(message);

    }

}

From source file:com.freemedforms.openreact.engine.Configuration.java

public static void loadConfiguration(String defaultConfig, String overrideConfig) {
    logger.trace("Entered loadConfiguration");
    if (compositeConfiguration == null) {
        logger.info("Configuration object not present, instantiating");
        compositeConfiguration = new CompositeConfiguration();

        PropertiesConfiguration defaults = null;
        try {/* w  ww . j  a v a 2 s. c o  m*/
            logger.info("Attempting to create PropertiesConfiguration object for DEFAULT_CONFIG");
            defaults = new PropertiesConfiguration(defaultConfig);
            logger.info("Loading default configuration from " + defaultConfig);
            defaults.load();
        } catch (ConfigurationException e) {
            logger.error("Could not load default configuration from " + defaultConfig);
            logger.error(e);
        }
        if (overrideConfig != null) {
            PropertiesConfiguration overrides = null;
            try {
                logger.info("Attempting to create PropertiesConfiguration object for OVERRIDE_CONFIG");
                overrides = new PropertiesConfiguration();
                logger.info("Setting file for OVERRIDE_CONFIG");
                overrides.setFile(new File(overrideConfig));
                logger.info("Setting reload strategy for OVERRIDE_CONFIG");
                overrides.setReloadingStrategy(new FileChangedReloadingStrategy());
                logger.info("Loading OVERRIDE_CONFIG");
                overrides.load();
            } catch (ConfigurationException e) {
                logger.error("Could not load overrides", e);
            } catch (Exception ex) {
                logger.error(ex);
            }
            if (overrides != null) {
                compositeConfiguration.addConfiguration(overrides);
            }
        }
        // Afterwards, add defaults so they're read second.
        compositeConfiguration.addConfiguration(defaults);
    }
}

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// w  w  w.  j  a  v  a  2  s.  co 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.bskyb.cg.environments.utils.DynamicProperties.java

public DynamicProperties(PropertiesConfiguration dynamicPropertiesConfigurer) throws ConfigurationException {
    this.setConfigure(dynamicPropertiesConfigurer);
    dynamicPropertiesConfigurer.load();

}

From source file:edu.usc.goffish.gopher.impl.client.DeploymentTool.java

public void listDataNodes(String gofsConfig) throws ConfigurationException, IOException {

    PropertiesConfiguration configuration = new PropertiesConfiguration(gofsConfig);
    configuration.load();

    String nameNodeUri = configuration.getString(GoFSFormat.GOFS_NAMENODE_LOCATION_KEY);

    INameNode nameNode = new RemoteNameNode(URI.create(nameNodeUri));

    System.out.println("**********************DATA NODE LIST**********************");
    for (Iterator<URI> it = nameNode.getDataNodes().iterator(); it.hasNext();) {
        URI uri = it.next();//  ww  w.  j  a  va 2  s.  com
        System.out.println(uri);
    }
}

From source file:edu.usc.goffish.gopher.impl.client.DeploymentTool.java

public void setup(String gofsConfig, String managerHost, String coordinatorHost, boolean persist)
        throws IOException, ConfigurationException {

    int numberOfProcessors = 0;

    PropertiesConfiguration gofs = new PropertiesConfiguration(gofsConfig);
    gofs.load();
    String nameNodeRestAPI = gofs.getString(GoFSFormat.GOFS_NAMENODE_LOCATION_KEY);

    INameNode nameNode = new RemoteNameNode(URI.create(nameNodeRestAPI));
    numberOfProcessors = nameNode.getDataNodes().size();

    // generate flow graph.
    FloeGraphGenerator generator = new FloeGraphGenerator();
    OMElement xmlOm = generator.createFloe(numberOfProcessors);
    xmlOm.build();//www.j a v a 2s .  c o m
    try {
        JAXBContext ctx = JAXBContext.newInstance(FloeGraph.class);
        Unmarshaller um = ctx.createUnmarshaller();
        FloeGraph floe = (FloeGraph) um.unmarshal(xmlOm.getXMLStreamReader());

        if (persist) {
            FileOutputStream fileOutputStream = new FileOutputStream(new File(FLOE_GRAPH_PATH));
            ctx.createMarshaller().marshal(floe, fileOutputStream);
        }
        DefaultClientConfig config = new DefaultClientConfig();
        config.getProperties().put(ClientConfig.FEATURE_DISABLE_XML_SECURITY, true);
        config.getFeatures().put(ClientConfig.FEATURE_DISABLE_XML_SECURITY, true);

        Client c = Client.create(config);
        WebResource r = c
                .resource("http://" + coordinatorHost + ":" + COORDINATOR_PORT + "/Coordinator/createFloe");
        c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
        ClientResponse response;
        c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
        response = r.post(ClientResponse.class, floe);
        StartFloeInfo startFloeInfo = response.getEntity(StartFloeInfo.class);

        createClientConfig(startFloeInfo, managerHost, coordinatorHost);

    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

From source file:ke.co.tawi.babblesms.server.servlet.util.PropertiesConfig.java

/**
 * Populate the internal HashMap which will hold configuration keys and values
 *///from  www .j  a v a  2  s .  co  m
private void initConfigHash() {
    PropertiesConfiguration config;
    String key;

    try {
        config = new PropertiesConfiguration();
        config.setListDelimiter('|'); // our array delimiter
        config.setFileName(configFile);
        config.load();

        Iterator<String> keys = config.getKeys();

        while (keys.hasNext()) {
            key = keys.next();
            configHash.put(key, (String) config.getProperty(key));
        }

    } catch (ConfigurationException e) {
        logger.error("ConfigurationException when trying to initialize configuration HashMap");
        logger.error(ExceptionUtils.getStackTrace(e));
    }
}

From source file:com.mirth.connect.server.migration.Migrate3_1_0.java

private void migrateLog4jProperties() {
    PropertiesConfiguration log4jproperties = new PropertiesConfiguration();
    log4jproperties.setDelimiterParsingDisabled(true);
    log4jproperties.setFile(new File(ClassPathResource.getResourceURI("log4j.properties")));
    try {//from  ww w  .j  a  va  2s. com
        log4jproperties.load();

        String level = (String) log4jproperties.getProperty("log4j.logger.shutdown");
        if (level != null) {
            log4jproperties.setProperty("log4j.logger.undeploy", level);
            log4jproperties.clearProperty("log4j.logger.shutdown");
            Logger.getLogger("undeploy").setLevel(Level.toLevel(level));
        }

        level = (String) log4jproperties
                .getProperty("log4j.logger.com.mirth.connect.donkey.server.channel.RecoveryTask");
        if (StringUtils.isBlank(level)) {
            level = "INFO";
            log4jproperties.setProperty("log4j.logger.com.mirth.connect.donkey.server.channel.RecoveryTask",
                    level);
            Logger.getLogger("com.mirth.connect.donkey.server.channel.RecoveryTask")
                    .setLevel(Level.toLevel(level));
        }

        log4jproperties.save();
    } catch (ConfigurationException e) {
        logger.error("Failed to migrate log4j properties.");
    }
}

From source file:com.manydesigns.portofino.i18n.ResourceBundleManager.java

public ResourceBundle getBundle(Locale locale) {
    ConfigurationResourceBundle bundle = resourceBundles.get(locale);
    if (bundle == null) {
        CompositeConfiguration configuration = new CompositeConfiguration();
        Iterator<String> iterator = searchPaths.descendingIterator();
        while (iterator.hasNext()) {
            String path = iterator.next();
            int index = path.lastIndexOf('/') + 1;
            String basePath = path.substring(0, index);
            int suffixIndex = path.length() - ".properties".length();
            String resourceBundleBaseName = path.substring(index, suffixIndex);
            String bundleName = getBundleFileName(resourceBundleBaseName, locale);
            PropertiesConfiguration conf;
            try {
                conf = new PropertiesConfiguration();
                conf.setFileName(basePath + bundleName);
                conf.setDelimiterParsingDisabled(true);
                conf.load();
            } catch (ConfigurationException e) {
                logger.debug("Couldn't load resource bundle for locale " + locale + " from " + basePath, e);
                //Fall back to default .properties without _locale
                try {
                    String defaultBundleName = basePath + resourceBundleBaseName + ".properties";
                    conf = new PropertiesConfiguration();
                    conf.setFileName(defaultBundleName);
                    conf.setDelimiterParsingDisabled(true);
                    conf.load();/* w w w .  j  av  a2 s .  c  o  m*/
                } catch (ConfigurationException e1) {
                    logger.debug("Couldn't load default resource bundle from " + basePath, e1);
                    conf = null;
                }
            }
            if (conf != null) {
                FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
                conf.setReloadingStrategy(reloadingStrategy);
                configuration.addConfiguration(conf);
            }
        }
        bundle = new ConfigurationResourceBundle(configuration, locale);
        //TODO setParent?
        resourceBundles.put(locale, bundle);
    }
    return bundle;
}

From source file:org.freemedsoftware.shim.Configuration.java

/**
 * Load configuration from both template and override properties files.
 *///from ww  w . j  a  va  2  s.co m
public static void loadConfiguration() {
    log.trace("Entered loadConfiguration");
    if (servletContext == null) {
        log.error("servletContext not set!");
    }
    if (compositeConfiguration == null) {
        log.info("Configuration object not present, instantiating");
        compositeConfiguration = new CompositeConfiguration();

        PropertiesConfiguration defaults = null;
        try {
            defaults = new PropertiesConfiguration(
                    servletContext.getServletContext().getRealPath(DEFAULT_CONFIG));
            log.info("Loading default configuration from "
                    + servletContext.getServletContext().getRealPath(DEFAULT_CONFIG));
        } catch (ConfigurationException e) {
            log.error("Could not load default configuration from "
                    + servletContext.getServletContext().getRealPath(DEFAULT_CONFIG));
            // e.printStackTrace();
        }
        if (OVERRIDE_CONFIG != null) {
            PropertiesConfiguration overrides = null;
            try {
                overrides = new PropertiesConfiguration();
                overrides.setFile(new File(OVERRIDE_CONFIG));
                overrides.setReloadingStrategy(new FileChangedReloadingStrategy());
                overrides.load();
            } catch (ConfigurationException e) {
                log.info("Could not load overrides", e);
            }
            compositeConfiguration.addConfiguration(overrides);
        }
        // Afterwards, add defaults so they're read second.
        compositeConfiguration.addConfiguration(defaults);
    }
}