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

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

Introduction

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

Prototype

public void save() throws ConfigurationException 

Source Link

Document

Save the configuration.

Usage

From source file:com.jorge.propiedades.MotorConfiguracion.java

public MotorConfiguracion() {
    try {//from ww w . j  a  va  2s.c o  m
        General general = new General();

        if (general.BaseDatos.equals("oracle")) {

            PropertiesConfiguration configOracle = new PropertiesConfiguration("./quijotelu/Oracle.properties");
            if (configOracle.getProperty("oracle.host") == null) {
                configOracle.setProperty("oracle.host", "127.0.0.1");
                configOracle.save();
            }

            if (configOracle.getProperty("oracle.puerto") == null) {
                configOracle.setProperty("oracle.puerto", "1521");
                configOracle.save();
            }
            if (configOracle.getProperty("oracle.servicio") == null) {
                configOracle.setProperty("oracle.servicio", "xe");
                configOracle.save();
            }
            if (configOracle.getProperty("oracle.usuario") == null) {
                configOracle.setProperty("oracle.usuario", "anita");
                configOracle.save();
            }
            if (configOracle.getProperty("oracle.clave") == null) {
                configOracle.setProperty("oracle.clave", "a");
                configOracle.save();
            }
            Host = (String) configOracle.getProperty("oracle.host");
            Puerto = (String) configOracle.getProperty("oracle.puerto");
            Servicio = (String) configOracle.getProperty("oracle.servicio");
            Usuario = (String) configOracle.getProperty("oracle.usuario");
            Clave = (String) configOracle.getProperty("oracle.clave");
        } else if (general.BaseDatos.equals("sqlserver")) {
            PropertiesConfiguration configSqlServer = new PropertiesConfiguration(
                    "./quijotelu/SqlServer.properties");
            if (configSqlServer.getProperty("sqlserver.host") == null) {
                configSqlServer.setProperty("sqlserver.host", "127.0.0.1");
                configSqlServer.save();
            }
            if (configSqlServer.getProperty("sqlserver.puerto") == null) {
                configSqlServer.setProperty("oracle.puerto", "1521");
                configSqlServer.save();
            }
            if (configSqlServer.getProperty("sqlserver.servicio") == null) {
                configSqlServer.setProperty("sqlserver.servicio", "xe");
                configSqlServer.save();
            }
            if (configSqlServer.getProperty("sqlserver.usuario") == null) {
                configSqlServer.setProperty("sqlserver.usuario", "anita");
                configSqlServer.save();
            }
            if (configSqlServer.getProperty("sqlserver.clave") == null) {
                configSqlServer.setProperty("sqlserver.clave", "a");
                configSqlServer.save();
            }
            Host = (String) configSqlServer.getProperty("sqlserver.host");
            Puerto = (String) configSqlServer.getProperty("sqlserver.puerto");
            Servicio = (String) configSqlServer.getProperty("sqlserver.servicio");
            Usuario = (String) configSqlServer.getProperty("sqlserver.usuario");
            Clave = (String) configSqlServer.getProperty("sqlserver.clave");
        }

    } catch (ConfigurationException ex) {
        Logger.getLogger(MotorConfiguracion.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.jorge.propiedades.General.java

public General() {
    try {//from  w  w w  . ja  v a2s .c  o  m
        PropertiesConfiguration config = new PropertiesConfiguration("./quijotelu/General.properties");
        if (config.getProperty("general.BaseDatos") == null) {
            /*
             Conexin con base de datos:
             oracle, sqlserver
             */
            config.setProperty("general.BaseDatos", "oracle");
            config.save();
        }
        if (config.getProperty("general.Publicidad") == null) {
            config.setProperty("general.Publicidad", "si");
            config.save();
        }
        if (config.getProperty("general.Nombre") == null) {
            config.setProperty("general.Nombre", "QuijoteLu");
            config.save();
        }
        BaseDatos = (String) config.getProperty("general.BaseDatos");
        Publicidad = (String) config.getProperty("general.Publicidad");
        Nombre = (String) config.getProperty("general.Nombre");

    } catch (ConfigurationException ex) {
        Logger.getLogger(General.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:gov.nih.nci.cacisweb.action.SecureFTPAddAction.java

@Override
public String execute() throws Exception {
    log.debug("execute() - START");
    String secureFTPPropertyFileLocation = CaCISUtil
            .getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECFTP_PROPERTIES_FILE_LOCATION);
    String secureFTPKeystoreLocation = CaCISUtil.getPropertyFromPropertiesFile(secureFTPPropertyFileLocation,
            CaCISUtil.getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECFTP_TRUSTSTORE_LOCATION_PROP_NAME));
    String secureFTPKeystorePassword = CaCISUtil.getPropertyFromPropertiesFile(secureFTPPropertyFileLocation,
            CaCISUtil.getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECFTP_TRUSTSTORE_PASSWORD_PROP_NAME));
    try {/*from   w  w  w .  ja  va2 s  . c  om*/
        CaCISUtil caCISUtil = new CaCISUtil();
        KeyStore keystore = caCISUtil.getKeystore(secureFTPKeystoreLocation,
                CaCISWebConstants.COM_KEYSTORE_TYPE_JKS, secureFTPKeystorePassword);

        if (keystore.containsAlias(secureFTPBean.getCertificateAlias())) {
            log.error(getText("secureFTPBean.duplicateKey"));
            addFieldError("secureFTPBean.certificateAlias", getText("secureFTPBean.duplicateKey"));
        }

        if (StringUtils.contains(secureFTPBean.getCertificateAlias(), "ftps")) {
            if (StringUtils.isBlank(secureFTPBean.getCertificateFileName())) {
                log.error(getText("secureFTPBean.certificateRequired"));
                addFieldError("secureFTPBean.certificateFileName",
                        getText("secureFTPBean.certificateRequired"));
                caCISUtil.releaseKeystore();
                return INPUT;
            } else {
                caCISUtil.releaseKeystore();
                FileInputStream certificateStream = new FileInputStream(secureFTPBean.getCertificate());

                CertificateFactory cf = CertificateFactory.getInstance("X.509");
                java.security.cert.Certificate cert = cf.generateCertificate(certificateStream);
                // Add the certificate
                keystore.setCertificateEntry(secureFTPBean.getCertificateAlias(), cert);

                // Save the new keystore contents
                FileOutputStream out = new FileOutputStream(new File(secureFTPKeystoreLocation));
                keystore.store(out, secureFTPKeystorePassword.toCharArray());
                out.close();
            }
        }

        // add the new entry to FTP configuration properties file
        PropertiesConfiguration config = new PropertiesConfiguration(
                CaCISUtil.getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECFTP_CONFIG_FILE_LOCATION));
        config.setProperty(secureFTPBean.getCertificateAlias(), "");
        config.save();
    } catch (KeystoreInstantiationException kie) {
        log.error(kie.getMessage());
        addActionError(getText("exception.keystoreInstantiation"));
        return ERROR;
    } catch (CertificateException ce) {
        log.error(CaCISUtil.getStackTrace(ce));
        addActionError(getText("exception.certification"));
        return INPUT;
    }
    addActionMessage(getText("secureFTPBean.addCertificateSuccessful"));
    log.debug("execute() - END");
    return SUCCESS;
}

From source file:com.runwaysdk.configuration.FlattenedProfileConfigurationTest.java

@Test
public void testActuallyUsingFlattenedProfile() {
    // Change a property so we know we're actually using the flattened ones and
    // not the unflattened
    try {/*from ww w  .  java  2 s . c om*/
        PropertiesConfiguration tprops = new PropertiesConfiguration(
                new File(baseDir + "/target/test-classes/flat/terraframe.properties"));
        String oldValue = tprops.getString("deploy.appname");

        tprops.setProperty("deploy.appname", "Actually Using Flattened Profile");
        tprops.save();

        try {
            CommonProperties.dumpInstance();
            String appName = CommonProperties.getDeployAppName();

            assertEquals("Actually Using Flattened Profile", appName);
        } finally {
            tprops.setProperty("deploy.appname", oldValue);
            tprops.save();

        }
    } catch (ConfigurationException e) {
        throw new RunwayConfigurationException(e);
    }

    CommonProperties.dumpInstance();
}

From source file:gov.nih.nci.cacisweb.action.SecureFTPAction.java

/**
 * /*from  www  . j  a v  a 2s. c o m*/
 * @return
 * @throws Exception
 */
public String delete() throws Exception {
    log.debug("delete() - START");
    String secureFTPPropertyFileLocation = CaCISUtil
            .getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECFTP_PROPERTIES_FILE_LOCATION);
    String secureFTPKeystoreLocation = CaCISUtil.getPropertyFromPropertiesFile(secureFTPPropertyFileLocation,
            CaCISUtil.getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECFTP_TRUSTSTORE_LOCATION_PROP_NAME));
    String secureFTPKeystorePassword = CaCISUtil.getPropertyFromPropertiesFile(secureFTPPropertyFileLocation,
            CaCISUtil.getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECFTP_TRUSTSTORE_PASSWORD_PROP_NAME));
    try {
        CaCISUtil caCISUtil = new CaCISUtil();
        KeyStore keystore = caCISUtil.getKeystore(secureFTPKeystoreLocation,
                CaCISWebConstants.COM_KEYSTORE_TYPE_JKS, secureFTPKeystorePassword);
        caCISUtil.releaseKeystore();
        // Delete the certificate
        keystore.deleteEntry(secureFTPBean.getCertificateAlias());

        // Save the new keystore contents
        FileOutputStream out = new FileOutputStream(new File(secureFTPKeystoreLocation));
        keystore.store(out, secureFTPKeystorePassword.toCharArray());
        out.close();

        // delete the entry from FTP configuration properties file
        PropertiesConfiguration config = new PropertiesConfiguration(
                CaCISUtil.getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECFTP_CONFIG_FILE_LOCATION));
        config.clearProperty(secureFTPBean.getCertificateAlias());
        config.save();
    } catch (KeystoreInstantiationException kie) {
        log.error(kie.getMessage());
        addActionError(getText("exception.keystoreInstantiation"));
        return ERROR;
    }
    addActionMessage(getText("secureFTPBean.deleteCertificateSuccessful"));
    log.debug("delete() - END");
    return SUCCESS;
}

From source file:gov.nih.nci.cacisweb.action.SecureXDSNAVAction.java

/**
 * /*from  w ww. jav  a 2  s  . c  om*/
 * @return
 * @throws Exception
 */
public String delete() throws Exception {
    log.debug("delete() - START");
    String secureXDSNAVKeystoreLocation = CaCISUtil
            .getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECXDSNAV_RECEPIENT_TRUSTSTORE_LOCATION);
    try {
        CaCISUtil caCISUtil = new CaCISUtil();
        KeyStore keystore = caCISUtil.getKeystore(secureXDSNAVKeystoreLocation,
                CaCISWebConstants.COM_KEYSTORE_TYPE_JKS, CaCISUtil.getProperty(
                        CaCISWebConstants.COM_PROPERTY_NAME_SECXDSNAV_RECEPIENT_TRUSTSTORE_PASSWORD));
        caCISUtil.releaseKeystore();
        // Delete the certificate
        keystore.deleteEntry(secureXDSNAVBean.getCertificateAlias());

        // Save the new keystore contents
        FileOutputStream out = new FileOutputStream(new File(secureXDSNAVKeystoreLocation));
        keystore.store(out,
                CaCISUtil
                        .getProperty(
                                CaCISWebConstants.COM_PROPERTY_NAME_SECXDSNAV_RECEPIENT_TRUSTSTORE_PASSWORD)
                        .toCharArray());
        out.close();

        // delete the entry from XDSNAV configuration properties file
        PropertiesConfiguration config = new PropertiesConfiguration(CaCISUtil
                .getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECXDSNAV_RECEPIENT_CONFIG_FILE_LOCATION));
        config.clearProperty(secureXDSNAVBean.getCertificateAlias());
        config.save();
    } catch (KeystoreInstantiationException kie) {
        log.error(kie.getMessage());
        addActionError(getText("exception.keystoreInstantiation"));
        return ERROR;
    }
    addActionMessage(getText("secureXDSNAVBean.deleteCertificateSuccessful"));
    log.debug("delete() - END");
    return SUCCESS;
}

From source file:com.jorge.propiedades.SRIConfiguracion.java

public SRIConfiguracion() {
    try {// w  w  w  .ja va2 s.co  m
        PropertiesConfiguration config = new PropertiesConfiguration("./quijotelu/SRI.properties");
        if (config.getProperty("SRI.ambiente") == null) {
            /*
             Tipo de ambiente
             1=pruebas
             2=produccin
             */
            config.setProperty("SRI.ambiente", "1");
            config.save();
        }

        if (config.getProperty("SRI.tipoEmision") == null) {
            config.setProperty("SRI.tipoEmision", "1");
            config.save();
        }
        if (config.getProperty("SRI.WebServiceEnvio") == null) {
            config.setProperty("SRI.WebServiceEnvio",
                    "https://celcer.sri.gob.ec/comprobantes-electronicos-ws/RecepcionComprobantes?wsdl");
            config.save();
        }
        if (config.getProperty("SRI.WebServiceAutoriza") == null) {
            config.setProperty("SRI.WebServiceAutoriza",
                    "https://celcer.sri.gob.ec/comprobantes-electronicos-ws/AutorizacionComprobantes?wsdl");
            config.save();
        }
        Ambiente = (String) config.getProperty("SRI.ambiente");
        TipoEmision = (String) config.getProperty("SRI.tipoEmision");
        WebServiceEnvio = (String) config.getProperty("SRI.WebServiceEnvio");
        WebServiceAutoriza = (String) config.getProperty("SRI.WebServiceAutoriza");
    } catch (ConfigurationException ex) {
        Logger.getLogger(SRIConfiguracion.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:client.OAuthClient.java

private void updateOAuthToken(String payload) {
    try {//from  w  ww . j  a v  a2  s .co m
        JSONObject jsonTokenObject = new JSONObject(payload);
        String newAccessToken = (String) jsonTokenObject.get(TokenUtils.ACCESS_TOKEN);
        String newRefreshToken = (String) jsonTokenObject.get(TokenUtils.REFRESH_TOKEN);
        if (newAccessToken == null || newRefreshToken == null) {
            log.error("Neither Access-Token nor Refresh-Token was found in the response [" + payload + "].");
        } else {
            this.clientConfig.setAuthToken(newAccessToken);
            this.clientConfig.setRefreshToken(newRefreshToken);

            String deviceConfigFilePath = this.clientConfig.getRootPath()
                    + this.clientConfig.getConfigFileName();
            PropertiesConfiguration propertyFileConfiguration = new PropertiesConfiguration(
                    deviceConfigFilePath);
            propertyFileConfiguration.setProperty("auth-token", newAccessToken);
            propertyFileConfiguration.setProperty("refresh-token", newRefreshToken);
            propertyFileConfiguration.save();
        }

    } catch (JSONException e) {
        log.info(e.getMessage() + ": payload- " + payload);
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:config.Timers.java

private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed

    try {/*from   w w w .j a  v a2 s.  c om*/
        String propFileName = "config.properties";
        PropertiesConfiguration prop = new PropertiesConfiguration(propFileName);

        // set the properties value
        prop.setProperty("OrderTimer", cmbOrderTimer.getSelectedItem().toString());
        prop.setProperty("HistoryTimer", cmbHistoryTimer.getSelectedItem().toString());

        prop.save();

    } catch (ConfigurationException ex) {
        Logger.getLogger(Timers.class.getName()).log(Level.SEVERE, null, ex);
    }

    JOptionPane.showMessageDialog(null, "Timer updated. ");
    dispose();

}

From source file:com.impetus.kundera.ycsb.YCSBBaseTest.java

/**
 * @throws ConfigurationException// w  ww.  j  av a 2  s. c  o m
 * @throws IOException
 * @throws NumberFormatException
 */
protected void onUpdate() throws ConfigurationException, NumberFormatException, IOException {
    String[] workLoadList = config.getStringArray("workload.file");
    for (String workLoad : workLoadList) {
        PropertiesConfiguration workLoadConfig = new PropertiesConfiguration(workLoadPackage + "/" + workLoad);
        workLoadConfig.setProperty("readproportion", "0");
        workLoadConfig.setProperty("updateproportion", "1");
        workLoadConfig.setProperty("scanproportion", "0");
        workLoadConfig.setProperty("insertproportion", "0");
        workLoadConfig.save();
        process();
    }

}