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(URL url) throws ConfigurationException 

Source Link

Document

Creates and loads the extended properties from the specified URL.

Usage

From source file:net.przemkovv.sphinx.compiler.MSVCCompiler.java

public MSVCCompiler() throws InvalidCompilerException, CompilerNonAvailableException {
    Configuration config;//from w w w . j  av a  2s  .  co  m
    try {
        config = new PropertiesConfiguration("net/przemkovv/sphinx/compiler/msvc_compiler.properties");
        String cmds[] = config.getStringArray("net.przemkovv.sphinx.compiler.msvc.cmd");
        String prepare_envs[] = config.getStringArray("net.przemkovv.sphinx.compiler.msvc.prepare_env");
        msvc = null;
        prepare_env = null;
        for (int i = 0; i < cmds.length; i++) {
            File temp_cmd = new File(cmds[i]);
            File temp_prepare_env = new File(prepare_envs[i]);
            if (temp_cmd.exists() && temp_cmd.canExecute()) {
                msvc = temp_cmd;
                prepare_env = temp_prepare_env;
                break;
            }

        }
        if (msvc == null) {
            throw new CompilerNonAvailableException("Compiler MS VC++ is not available.");
        }
        CompilerInfo info = getCompilerInfo();
        if (info != null) {
            logger.debug("Found MS VC++ Compiler. Version: {}, Arch: {}", info.version, info.architecture);
        }
        tmp_dir = System.getProperty("java.io.tmpdir");
        logger.debug("Temporary directory: {}", tmp_dir);
    } catch (ConfigurationException ex) {
        throw new CompilerNonAvailableException("Couldn't find configuration for compiler MS VC++.", ex);
    }

}

From source file:net.sf.mpaxs.spi.server.DrmaaComputeHostLauncher.java

/**
 * Submits a new ComputeHost to the GridEngine.
 * Settings from the Settings class are used and converted to <code>Configuration</code>.
 *
 * @param cfg the configuration to use//from   www  . j a v  a 2s .  c o  m
 * @see net.sf.mpaxs.spi.computeHost.Settings
 */
@Override
public void startComputeHost(Configuration cfg) {
    String drmaaImplementation = SessionFactory.getFactory().getSession().getDrmaaImplementation();
    System.out.println("Drmaa Implementation: " + drmaaImplementation);
    File configLocation = new File(cfg.getString(ConfigurationKeys.KEY_COMPUTE_HOST_WORKING_DIR),
            "computeHost.properties");
    try {
        PropertiesConfiguration pc = new PropertiesConfiguration(configLocation);
        ConfigurationUtils.copy(cfg, pc);
        pc.save();
    } catch (ConfigurationException ex) {
        Logger.getLogger(DrmaaComputeHostLauncher.class.getName()).log(Level.SEVERE, null, ex);
    }

    List<String> arguments = new ArrayList<String>();
    arguments.add("-cp");
    arguments.add(cfg.getString(ConfigurationKeys.KEY_PATH_TO_COMPUTEHOST_JAR));
    arguments.add(cfg.getString(ConfigurationKeys.KEY_COMPUTE_HOST_MAIN_CLASS));
    arguments.add("-c");
    try {
        arguments.add(configLocation.toURI().toURL().toString());
    } catch (MalformedURLException ex) {
        Logger.getLogger(DrmaaComputeHostLauncher.class.getName()).log(Level.SEVERE, null, ex);
    }
    Logger.getLogger(this.getClass().getName()).log(Level.INFO, "ComputeHost configuration: {0}",
            ConfigurationUtils.toString(cfg));
    try {
        SessionFactory factory = SessionFactory.getFactory();
        Session session = factory.getSession();
        Logger.getLogger(this.getClass().getName()).log(Level.INFO,
                "DRM System: {0} Implementation: {1} Version: {2}", new Object[] { session.getDrmSystem(),
                        session.getDrmaaImplementation(), session.getVersion() });
        session.init("");
        JobTemplate jt = session.createJobTemplate();
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Remote command: {0}",
                cfg.getString(ConfigurationKeys.KEY_PATH_TO_JAVA));
        jt.setRemoteCommand(cfg.getString(ConfigurationKeys.KEY_PATH_TO_JAVA));
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Working dir: {0}",
                cfg.getString(ConfigurationKeys.KEY_COMPUTE_HOST_WORKING_DIR));
        jt.setWorkingDirectory(cfg.getString(ConfigurationKeys.KEY_COMPUTE_HOST_WORKING_DIR));
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Arguments: {0}", arguments);
        jt.setArgs(arguments);
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Error path: {0}",
                cfg.getString(ConfigurationKeys.KEY_ERROR_FILE));
        jt.setErrorPath(":" + cfg.getString(ConfigurationKeys.KEY_ERROR_FILE));
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Output path: {0}",
                cfg.getString(ConfigurationKeys.KEY_OUTPUT_FILE));
        jt.setOutputPath(":" + cfg.getString(ConfigurationKeys.KEY_OUTPUT_FILE));
        jt.setNativeSpecification(cfg.getString(ConfigurationKeys.KEY_NATIVE_SPEC, ""));
        jt.setJobName("mpaxs-chost");
        session.runJob(jt);
        session.deleteJobTemplate(jt);
        session.exit();
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Session started!");
    } catch (DrmaaException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:edu.umd.cs.psl.config.ConfigManager.java

public void loadResource(String resource) throws FileNotFoundException, ConfigurationException {
    URL url;// w  w w  .  ja  v  a  2  s . co m
    PropertiesConfiguration newConfig;

    try {
        url = new URL(resource);
    } catch (MalformedURLException ex) {
        url = Loader.getResource(resource);
    }
    if (url != null) {
        newConfig = new PropertiesConfiguration(url);
        masterConfig.append(newConfig);
    } else
        throw new FileNotFoundException();
}

From source file:io.coala.config.ConfigTest.java

@Test
public void testConfigCommons() throws Exception {
    final PropertiesConfiguration config = new PropertiesConfiguration(ConfigUtil.PROPERTIES_FILE);
    config.save(System.out);//from   ww  w .j a v  a 2s.co  m
}

From source file:lp.reminiscens.crawler.FlickrToURL.java

public FlickrToURL() {

    FlickrSearchQuery_url = "http://api.flickr.com/services/rest/?method=flickr.photos.search";
    FlickrGetLocationQuery_url = "http://api.flickr.com/services/rest/?method=flickr.photos.geo.getLocation";

    FlickrGetLocationQuery_id = "&photo_id=";
    FlickrQuery_per_page = "&per_page=100";
    seconds = "+00:00:00";
    FlickrExtraQuery = "&extras=";
    FlickrExtraGeo = "geo";
    FlickrExtraTags = "tags";
    FlickrExtraTakenDate = "date_taken";
    FlickrExtraUploadDate = "date_upload";
    FlickrMin_Taken_Date = "&min_taken_date=";
    FlickrMax_Taken_Date = "&max_taken_date=";
    FlickrQuery_nojsoncallback = "&nojsoncallback=1";
    FlickrQuery_format = "&format=json";
    FlickrQuery_license = "&license=1%2C2%2C4%2C5%2C7"; // creative commons
    FlickrQuery_tag = "&tags=";
    FlickrQuery_key = "&api_key=";

    try {//from w  w  w . j av a  2  s  . co m
        Configuration config = new PropertiesConfiguration("lifecontext.utils.config");
        FlickrApiKey = config.getProperty("flickr.apikey").toString();
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    photos = new HashSet<Media>();
}

From source file:com.technophobia.substeps.model.Configuration.java

/**
 * Implementors of substep libraries should call this with default
 * properties for their library/*from   w w w  .ja v  a 2 s.c om*/
 *
 * @param url  to a properties file containing default values
 * @param name to name of the properties file that is being added
 */
public void addDefaultProperties(final URL url, final String name) {

    if (url != null) {
        try {

            final PropertiesConfiguration defaultProps = new PropertiesConfiguration(url);

            combinedConfig.addConfiguration(defaultProps, name);
        } catch (final ConfigurationException e) {
            logger.error("error loading default properties", e);
            throw new SubstepsConfigurationException(e);
        }
    }
}

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

/**
 * Initialize the system to run a new application.
 * @param gopherConfig Gopher Configuration file Path
 * @param gofsConfig  Gofs Configuration File Path
 * @param graphId   Id of the graph//ww  w.  j ava  2  s . co m
 * @param jarFile  application jar file name
 * @param clzz    application class name
 */
public void initialize(String gopherConfig, String gofsConfig, String graphId, String jarFile, String clzz) {
    /**
     * Assume application jar is copied already
     * Send the init command with data // application_jar:app_class:number_of_processors:graphId,uri
     */

    try {
        gofs = new PropertiesConfiguration(gofsConfig);
        gopher = new XMLConfiguration(gopherConfig);

        gofs.load();
        gopher.load();

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

        nameNode = new RemoteNameNode(URI.create(nameNodeUri));
        int numberOfProcessors = nameNode.getDataNodes().size();

        String data = jarFile + seperator + clzz + seperator + numberOfProcessors + seperator + graphId
                + seperator + nameNodeUri;
        System.out.println("Sending Init message : " + data);
        BSPMessage message = new BSPMessage();
        message.setData(data.getBytes());
        message.setType(BSPMessage.INIT);

        String location = gopher.getString(DeploymentTool.DATA_FLOW_HOST);
        int port = gopher.getInt(DeploymentTool.DATA_FLOW_DATA_PORT);
        int controlPort = gopher.getInt(DeploymentTool.DATA_FLOW_CONTROL_PORT);

        TransportInfoBase otherEndTransportInfo = new TransportInfoBase();
        otherEndTransportInfo.getParams().put(TransportConstants.HOST_ADDR, location);
        otherEndTransportInfo.getParams().put(TransportConstants.TCP_LISTEN_PORT, String.valueOf(port));

        TransportInfoBase otherEndControlInfo = new TransportInfoBase();
        otherEndControlInfo.getParams().put(TransportConstants.HOST_ADDR, location);
        otherEndControlInfo.getParams().put(TransportConstants.TCP_LISTEN_PORT, String.valueOf(controlPort));

        otherEndTransportInfo.setControlChannelInfo(otherEndControlInfo);

        Node.Port otherEndport = new Node.Port();
        otherEndport.setPortName("in");
        otherEndport.setTransportType("TCP");
        otherEndport.setDataTransferMode("Push");

        otherEndport.setTransportInfo(otherEndTransportInfo);

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("KEY", null);
        params.put("QUEUE", null);
        params.put("SERVER_SIDE", "false");

        sender = SenderFactory.createDefaultSender();
        sender.init(params);
        sender.connect(otherEndport, null);

        Message tempMessage = new MessageImpl();
        tempMessage.putPayload(BitConverter.getBytes(message));

        sender.send(tempMessage);

    } catch (ConfigurationException e) {
        String message = "Error Processing configuration";
        handleException(message, e);
    } catch (IOException e) {
        String message = "I/O Error while initializing Gopher client";
        handleException(message, e);
    } catch (ClassNotFoundException e) {
        String message = "Unexpected error while Creating Sender ";
        handleException(message, e);
    } catch (InstantiationException e) {
        String message = "Unexpected error while Creating Sender ";
        handleException(message, e);
    } catch (IllegalAccessException e) {
        String message = "Unexpected error while Creating Sender ";
        handleException(message, e);
    }

}

From source file:com.autentia.tnt.util.ConfigurationUtil.java

/**
 * Constructor//from   w  w w. j a  v  a 2s .co  m
 * 
 * @param jndiPathVar
 *            JNDI variable in which configuration directory is stored
 * @param file
 *            path to configuration file
 */
public ConfigurationUtil(String jndiPathVar, String file) throws ConfigurationException, NamingException {
    Context ctx = new InitialContext();
    configDir = ctx.lookup(jndiPathVar).toString();
    if (!configDir.endsWith("/") && !configDir.endsWith("\\")) {
        configDir = configDir.trim() + "/";
    }
    config = new PropertiesConfiguration(configDir + file);
}

From source file:net.przemkovv.sphinx.compiler.GXXCompiler.java

public GXXCompiler() throws InvalidCompilerException, CompilerNonAvailableException {
    tmp_dir_prefix = "gxx_";
    try {//from w w w  .  ja v a2  s. c  o m

        Configuration config = new PropertiesConfiguration(
                "net/przemkovv/sphinx/compiler/gxx_compiler.properties");
        String cmds[] = config.getStringArray("net.przemkovv.sphinx.compiler.gxx.cmd");
        String prepare_envs[] = config.getStringArray("net.przemkovv.sphinx.compiler.gxx.prepare_env");

        compiler_cmd = null;
        prepare_env_cmd = null;

        for (int i = 0; i < cmds.length; i++) {
            File temp_cmd = new File(cmds[i]);

            if (temp_cmd.exists() && temp_cmd.canExecute()) {
                compiler_cmd = temp_cmd;
                if (!prepare_envs[i].isEmpty()) {
                    prepare_env_cmd = new File(prepare_envs[i]);
                }
                break;
            }
        }
        if (compiler_cmd == null) {
            throw new CompilerNonAvailableException("Compiler G++ is not available.");
        }

        CompilerInfo info = getCompilerInfo();
        if (info != null) {
            logger.debug("Found g++ Compiler. Version: {}, Vendor: {}", info.version, info.vendor);
        }
        tmp_dir = System.getProperty("java.io.tmpdir");
        logger.debug("Temporary directory: {}", tmp_dir);

    } catch (ConfigurationException ex) {
        throw new CompilerNonAvailableException("Couldn't find configuration for compiler compiler G++.", ex);
    }

}

From source file:info.extensiblecatalog.OAIToolkit.utils.ConfigUtil.java

public static PropertiesConfiguration load(String configFileName) throws Exception {
    prglog.info("[PRG] ConfigUtil::load(" + configFileName + ")");
    ClassLoader cloader = ConfigUtil.class.getClassLoader();
    URL configFile = cloader.getResource(configFileName);
    if (null == configFile) {
        File f = new File(configFileName);
        prglog.info("[PRG] load from file: " + f.getAbsolutePath());
        configFile = new URL("file", "", f.getAbsolutePath());
    }//from  w w w .  j  a va  2s .c o  m
    prglog.info("config file: " + configFile.getPath());
    //System.out.println("The config file is " + configFile);
    //System.out.println("The config file name is " + configFileName);

    if (!(new File(configFile.getPath()).exists())) {
        prglog.error("[PRG] Inexistent configuration file: " + configFileName);
        throw new Exception("Inexistent configuration file: " + configFileName);
    }

    BufferedReader re = new BufferedReader(new FileReader(configFile.getPath()));
    /*        String tmpfile = "tmpfile.txt";
            // Create new file
            File temp = new File(tmpfile);
            
            boolean success = temp.createNewFile();
            if (success) {
     System.out.println("Its success");
    //File did not exist and was created
            } else {
     System.out.println("File already exists");
     //File already exists
            }
            
            
             if (!temp.exists())
    throw new IllegalArgumentException("no such file or directory: " + temp);
            
            if (!temp.canWrite())
    throw new IllegalArgumentException("Write protected: " + temp);
            
            System.out.println("Temporary file created. File is " + temp);
            //System.out.println("Temporary file created. Path is " + temp.getPath());
            
            BufferedWriter out = new BufferedWriter(new FileWriter(temp));
            while(true)
            {
    String s = re.readLine();
    //System.out.println(s);
    if(s!=null) {
        s = s.replaceAll("\\\\", "/");
        //System.out.println(s);
        out.write(s + System.getProperty("line.separator"));
        out.flush();
    }
    else
        break;
            }
            out.close();
    */
    try {
        //PropertiesConfiguration prop = new PropertiesConfiguration(temp);
        PropertiesConfiguration prop = new PropertiesConfiguration(configFile.getPath());
        prglog.info("[PRG] successful ConfigUtil::load");
        //temp.deleteOnExit();
        /*boolean dsuccess = temp.delete();
        if (!dsuccess)
        throw new IllegalArgumentException("Delete: deletion failed");*/
        return prop;
    } catch (ConfigurationException e) {
        prglog.error("[PRG] Unable to load properties from configuration file: " + configFileName + ". "
                + e.getMessage());
        throw new Exception(
                "Unable to load properties from configuration file: " + configFileName + ". " + e.getMessage());
    }
}