Example usage for java.util Properties Properties

List of usage examples for java.util Properties Properties

Introduction

In this page you can find the example usage for java.util Properties Properties.

Prototype

public Properties() 

Source Link

Document

Creates an empty property list with no default values.

Usage

From source file:gov.nih.nci.cabig.ctms.tools.spring.HibernatePropertiesFactoryBean.java

public HibernatePropertiesFactoryBean() {
    properties = new Properties();
}

From source file:com.croer.javaaccess.Structure.java

public Structure(Object object) {
    Properties properties = new Properties();
    try {/*  www. j ava  2  s  .c o m*/
        String fileProps = System.getProperty("user.dir") + "\\target\\classes\\entityStruc.properties";
        FileInputStream input = new FileInputStream(fileProps);
        properties.load(input);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Structure.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Structure.class.getName()).log(Level.SEVERE, null, ex);
    }

    String type = object.getClass().getName();
    String key = properties.getProperty(type + ".key");
    String context = properties.getProperty(type + ".context");

    if (key == null || context == null) {
        throw new IllegalArgumentException(
                "Properties missing for type: " + type + " key " + key + " context " + context);
    }

    keyList = Arrays.asList(StringUtils.split(key, "|"));
    contextList = Arrays.asList(StringUtils.split(context, "|"));
}

From source file:com.handany.base.generator.Generator.java

public static List<TableBean> getTables() {
    Properties p = new Properties();
    try {//  w  w  w  .  j  ava 2  s.  c  om
        p.load(new FileInputStream(new File("src/main/java/com/handany/base/generator/generator.properties")));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    List<TableBean> tableBeanList = jdbcTemplate.query("select * from TABLES where table_schema = ?",
            new Object[] { SCHEMA_NAME }, new RowMapper<TableBean>() {
                @Override
                public TableBean mapRow(ResultSet rs, int i) throws SQLException {
                    TableBean bean = new TableBean();
                    String tableName = rs.getString("table_name");
                    bean.setTableName(tableName);
                    bean.setTableNameNoDash(delDash(tableName));
                    bean.setTableNameCapitalized(StringUtils.capitalize(bean.getTableNameNoDash()));
                    bean.setTableComment(rs.getString("table_comment"));
                    return bean;
                }
            });

    for (TableBean tableBean : tableBeanList) {
        tableBean.setColumnBeanList(getColumns(tableBean));
    }

    return tableBeanList;
}

From source file:framework.classes.connectionDB.java

public static void init_BasicDataSourceFactory() {
    Properties propiedades = new Properties();
    /*/*from w w  w  . j av a2s.  co  m*/
    setMaxActive(): N mx de conexiones que se pueden abrir simultneamente.
    setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms.
    setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando.
    */
    propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver");
    propiedades.setProperty("url", "jdbc:mysql://localhost:3306/app");
    propiedades.setProperty("maxActive", "10");
    propiedades.setProperty("maxIdle", "8");
    propiedades.setProperty("minIdle", "0");
    propiedades.setProperty("maxWait", "500");
    propiedades.setProperty("initialSize", "5");
    propiedades.setProperty("defaultAutoCommit", "true");
    propiedades.setProperty("username", "root");
    propiedades.setProperty("password", "root");
    propiedades.setProperty("validationQuery", "select 1");
    propiedades.setProperty("validationQueryTimeout", "100");
    propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2");
    propiedades.setProperty("poolPreparedStatements", "true");
    propiedades.setProperty("maxOpenPreparedStatements", "10");

    try {

        dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:App.classes.BD_Connection.java

/**
 * public Connection AbrirConexion() {//from w  w  w .  ja v a2  s.  c o  m
 *
 * Connection con = null; try { Class.forName("com.mysql.jdbc.Driver");
 * String urlOdbc = "jdbc:mysql://127.0.0.1:3306/db_admin"; con =
 * (java.sql.DriverManager.getConnection(urlOdbc, "root", ""));
 *
 * } catch (Exception e) {
 *
 *
 * //e.printStackTrace(); JOptionPane.showMessageDialog(null, "Ha sido
 * imposible establecer la conexion!"); } return con; }
 *
 * /**
 * cerramos la conexion en la bd
 *
 * @param con
 */
/*
        
        
public void CerrarConexion(Connection con) {
try {
    if (con != null) {
        con.close();
    }
} catch (SQLException e) {
        
    JOptionPane.showMessageDialog(null, "Ha sido imposible cerrar la conexion!");
}
}
        
 */
public static void initialize_BasicDataSourceFactory() {
    Properties propiedades = new Properties();
    /*
    setMaxActive(): N mx de conexiones que se pueden abrir simultneamente.
    setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms.
    setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando.
     */
    propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver");
    propiedades.setProperty("url", "jdbc:mysql://localhost:3306/mysql");
    propiedades.setProperty("maxActive", "10");
    propiedades.setProperty("maxIdle", "8");
    propiedades.setProperty("minIdle", "0");
    propiedades.setProperty("maxWait", "5000");
    propiedades.setProperty("initialSize", "5");
    propiedades.setProperty("defaultAutoCommit", "true");
    propiedades.setProperty("username", "root");
    propiedades.setProperty("password", "");
    propiedades.setProperty("validationQuery", "select 1");
    propiedades.setProperty("validationQueryTimeout", "10000");
    propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2");
    propiedades.setProperty("poolPreparedStatements", "true");
    propiedades.setProperty("maxOpenPreparedStatements", "10");

    try {
        //propiedades.load(new FileInputStream("src/config/datasource_config.properties"));
        Singleton_App.dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:frameworkcontentspeed.Utils.SendEmailAtachament.java

public static void sendGRUP(String from, String password, String bcc, String sub, String msg, String filename)
        throws Exception {
    //Get properties object    
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");
    //get Session   
    Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(from, password);
        }/*from   ww  w.j  a  va 2s  . c o m*/
    });
    //compose message    
    try {
        MimeMessage message = new MimeMessage(session);
        //message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        message.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc));

        message.setSubject(sub);
        message.setText(msg);

        BodyPart messageBodyPart = new MimeBodyPart();

        messageBodyPart.setText("Raport teste automat");

        Multipart multipart = new MimeMultipart();

        multipart.addBodyPart(messageBodyPart);

        messageBodyPart = new MimeBodyPart();

        DataSource source = new FileDataSource(filename);

        messageBodyPart.setDataHandler(new DataHandler(source));

        messageBodyPart.setFileName(filename);

        multipart.addBodyPart(messageBodyPart);

        //message.setContent(multipart);
        StringWriter writer = new StringWriter();
        IOUtils.copy(new FileInputStream(new File(filename)), writer);

        message.setContent(writer.toString(), "text/html");

        //send message  
        Transport.send(message);
        System.out.println("message sent successfully");
    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }

}

From source file:com.baidu.qa.service.test.util.MysqlDatabaseManager.java

/**
 * ?mysql db??/*www  .  j av  a 2  s  .  c  om*/
 * @param dbname
 * @return
 * @throws SQLException
 */
static public Connection getCon(String dbname) throws SQLException {

    String host = "";
    String user = "";
    String database = "";
    String password = "";
    String driverClass = "";
    String useUnicode = "";
    try {
        // ????
        InputStream in = new BufferedInputStream(
                new FileInputStream(ServiceInterfaceCaseTest.CASEPATH + Constant.FILENAME_DB));

        Properties Info = new Properties();
        Info.load(in);

        host = Info.getProperty(dbname + "_DB_Host");
        user = Info.getProperty(dbname + "_DB_User");
        database = Info.getProperty(dbname + "_DB_DataBase");
        password = Info.getProperty(dbname + "_DB_Password");
        driverClass = Info.getProperty(dbname + "_DB_DriverClass");
        useUnicode = Info.getProperty(dbname + "_DB_UseUnicode");
    } catch (Exception e) {
        log.error("[mysql configure file for" + dbname + "error]:", e);
        throw new AssertionError("[get mysql database config error from properties file]");
    }
    if (host == null) {
        log.error("[load configure file for " + dbname + " error]:");
        return null;
    }

    // 
    String url = "jdbc:mysql://" + host.trim() + "/" + ((database != null) ? database.trim() : "")
            + "?useUnicode=" + ((useUnicode != null) ? useUnicode.trim() : "true&characterEncoding=gbk");

    try {
        Class.forName(driverClass);
    } catch (ClassNotFoundException e) {
        log.error("[class not found]:", e);
        throw new AssertionError("[class not found]");
    }
    Connection con = null;
    try {
        con = DriverManager.getConnection(url, user, password);
    } catch (SQLException a) {
        log.error("[mysql connection exception] ", a);
        throw new AssertionError("[mysql connection exception]");
    }

    return con;

}

From source file:com.intouch.processor.RequestProcessor.java

public JSONObject processRequest(HttpServletRequest request) throws Exception {
    InputStream inputStream = request.getServletContext()
            .getResourceAsStream("/WEB-INF/resourse/properties/prop.properties");
    Properties properties = new Properties();
    properties.load(inputStream);/* w w  w.  j av  a2  s.  c o  m*/
    Class cls = Class.forName(properties.getProperty(request.getParameter("method")));
    Processor processor = (Processor) cls.newInstance();
    inputStream.close();
    return processor.processRequest(request.getParameterMap());
}

From source file:gov.nih.nci.integration.catissue.CaTissueConsentIntegrationTest.java

/**
 * To initialize the things/*  www.ja  va2  s.  c  om*/
 * @throws IOException 
 */
@BeforeClass
public static void initialize() throws IOException {
    try {
        Properties props = new Properties();
        props.load(Thread.currentThread().getContextClassLoader()
                .getResourceAsStream("transcend-ihub-test.properties"));

        String catissueUserName = props.getProperty("catissue.api.login.username");
        String catissuePassword = props.getProperty("catissue.api.login.password");

        caTissueParticipantClient = new CaTissueParticipantClient(catissueUserName, catissuePassword);
        caTissueSpecimenClient = new CaTissueSpecimenClient(catissueUserName, catissuePassword);
        caTissueConsentClient = new CaTissueConsentClient(catissueUserName, catissuePassword);
    } catch (BeansException e) {
        LOG.error("CaTissueConsentIntegrationTest-BeansException inside initialize() ", e);
    } catch (MalformedURLException e) {
        LOG.error("CaTissueConsentIntegrationTest-ApplicationException inside initialize() ", e);
    }

}

From source file:Main.java

public Properties readProperties() throws Exception {
    Properties properties = new Properties();
    FileInputStream fis = new FileInputStream("configuration.xml");
    properties.loadFromXML(fis);//w w  w . j  av a2 s . c o  m

    return properties;
}