List of usage examples for java.util Properties Properties
public Properties()
From source file:Classes.DBConnection.java
/** * Initialize the connections configuration *//* www . j a v a 2 s . com*/ public static void init_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/prog"); 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", "12345"); 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) { e.printStackTrace(); JOptionPane.showMessageDialog(null, e.toString()); } }
From source file:net.firejack.platform.core.utils.MiscUtils.java
/** * @param properties/*from w w w . ja v a2 s . c o m*/ * @param checkFileExists * @param property * @param value * @throws java.io.IOException */ public static void setProperties(File properties, boolean checkFileExists, String property, String value) throws IOException { if (checkFileExists && !properties.exists()) { logger.error("Properties file [" + properties.getAbsolutePath() + "] does not exist."); throw new FileNotFoundException("Properties file does not found."); // IOHelper.delete(dbProperties); } Properties props = new Properties(); if (properties.exists()) { FileReader reader = new FileReader(properties); props.load(reader); reader.close(); } props.put(property, value); FileWriter writer = new FileWriter(properties); props.store(writer, null); writer.flush(); writer.close(); }
From source file:XMLUtils.java
/** * Returns a Properties object matching the given node. * @param ns the namespace.// www. j a v a 2 s .c o m * @param base the element from where to search. * @param name of the element to get. * @return the value of this element. */ public static Properties getPropertiesValueElement(final String ns, final Element base, final String name) { Properties returnedProperties = new Properties(); // Get element NodeList list = base.getElementsByTagNameNS(ns, name); if (list.getLength() == 1) { Element element = (Element) list.item(0); // Get property element NodeList properties = element.getElementsByTagNameNS(ns, "property"); // If properties is present, analyze them and add them if (properties.getLength() > 0) { for (int i = 0; i < properties.getLength(); i++) { Element elemProperty = (Element) properties.item(i); String pName = getAttributeValue(elemProperty, "name"); String pValue = getAttributeValue(elemProperty, "value"); if (pName != null && pValue != null) { returnedProperties.setProperty(pName, pValue); } } } } else if (list.getLength() > 1) { throw new IllegalStateException("Element '" + name + "' on '" + base + "' should be unique but there are '" + list.getLength() + "' elements"); } return returnedProperties; }
From source file:lk.ijse.thogakade.dao.ConnectionFactory.java
private ConnectionFactory() { try {/*from w w w . j a v a 2s. co m*/ Properties dbproperties = new Properties(); FileReader reader = null; File file = new File("settings/dbsettings.properties"); reader = new FileReader(file); dbproperties.load(reader); bds = new BasicDataSource(); bds.setUsername((String) dbproperties.getProperty("username")); bds.setPassword((String) dbproperties.getProperty("password")); System.out.println((String) dbproperties.getProperty("url")); bds.setUrl((String) dbproperties.getProperty("url")); bds.setDriverClassName((String) dbproperties.getProperty("driver")); bds.setInitialSize(10); bds.setMaxTotal(10); bds.setMaxIdle(10); bds.setMinIdle(10); } catch (FileNotFoundException ex) { Logger.getLogger(ConnectionFactory.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ConnectionFactory.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:la.kosmos.app.EmailConfiguration.java
public EmailConfiguration(String host, String from, String port, String username, String password) { props = new Properties(); mailSender = new JavaMailSenderImpl(); props.put("mail.smtp.host", host); props.put("mail.from", from); props.put("mail.smtp.socketFactory.port", port); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.socketFactory.fallback", "false"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", port); mailSender.setJavaMailProperties(props); mailSender.setUsername(username);//w ww .j a va 2 s . co m mailSender.setPassword(password); }
From source file:se.ivankrizsan.messagecowboy.ProductionPropertyOverrides.java
/** * Overrides properties configured on beans. *///w ww.j a v a 2s . c o m @Bean() @Lazy(false) @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) public static BeanFactoryPostProcessor propertyOverrideConfigurer() { PropertyOverrideConfigurer theOverrideConfigurer = new PropertyOverrideConfigurer(); final Properties thePropertiesHolder = new Properties(); /* Task refresh interval. */ thePropertiesHolder.put("starterService.taskReschedulingCronExpression", "0/20 * * * * ?"); /* Transport service configuration refresh interval. */ thePropertiesHolder.put("starterService.transportServiceConfigurationRefreshCronExpression", "0/30 * * * * ?"); /* Task execution status reports cleanup interval. */ thePropertiesHolder.put("starterService.taskExecutionStatusCleanupCronExpression", "0/30 0/15 * * * ?"); theOverrideConfigurer.setProperties(thePropertiesHolder); theOverrideConfigurer.setIgnoreInvalidKeys(false); theOverrideConfigurer.setIgnoreResourceNotFound(false); theOverrideConfigurer.setOrder(0); return theOverrideConfigurer; }
From source file:com.googlecode.fascinator.DBIntegrationTestSuite.java
@AfterClass public static void tearDown() throws IOException, BeansException, SQLException { Properties prop = new Properties(); prop.load(new FileInputStream("src/test/resources/database.properties")); String dbString = prop.getProperty("jdbc.databaseurl"); try {/* w w w . j a v a 2 s . c o m*/ DriverManager.getConnection(dbString + ";shutdown=true"); } catch (SQLNonTransientConnectionException exception) { } catch (SQLException e) { } FileUtils.deleteDirectory(new File("target/database")); }
From source file:com.tilab.fiware.metaware.service.CompanyServiceTest.java
@BeforeClass public static void setUpClass() { testProperties = new Properties(); testProperties.setProperty("db.host", "localhost"); testProperties.setProperty("db.port", "27017"); testProperties.setProperty("db.name", "MetadataRepoTest"); // DB test INSTANCE.setManualProperties(testProperties); INSTANCE.createCoreObjects();/*ww w .ja v a2 s. com*/ comp1 = new Company("company test name 1", "company test description 1", "company.one@test.com", "123456", "Via Reiss Romoli, 274 Torino", "company.test.one.com"); comp2 = new Company("company test name 2", "company test description 2", "company.two@test.com", "654321", "Via Reiss Romoli, 274 Torino", "company.test.two.com"); }
From source file:br.com.ingenieux.jenkins.plugins.awsebdeployment.Utils.java
public static String getVersion() { if (DEFAULT_VERSION.equals(VERSION)) { try (InputStream is = Utils.class.getResourceAsStream("version.properties")) { Properties p = new Properties(); p.load(is);//from w w w. j a va2s. c om VERSION = p.getProperty("awseb-deployer-plugin.version"); } catch (Exception exc) { throw new RuntimeException(exc); } } return VERSION; }
From source file:hpmonitoringaudit.sftp.java
public boolean startFTP(String propertiesFilename, String fileToDownload) { props = new Properties(); StandardFileSystemManager manager = new StandardFileSystemManager(); try {/*from w w w . jav a2s .c o m*/ props.load(new FileInputStream("properties/" + propertiesFilename)); String serverAddress = props.getProperty("serverAddress").trim(); String userId = props.getProperty("userId").trim(); String password = props.getProperty("password").trim(); String remoteDirectory = props.getProperty("remoteDirectory").trim(); String localDirectory = props.getProperty("localDirectory").trim(); //Initializes the file manager manager.init(); //Setup our SFTP configuration FileSystemOptions opts = new FileSystemOptions(); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000); //Create the SFTP URI using the host name, userid, password, remote path and file name String sftpUri = "sftp://" + userId + ":" + password + "@" + serverAddress + "/" + remoteDirectory + fileToDownload; // Create local file object String filepath = localDirectory + fileToDownload; File file = new File(filepath); FileObject localFile = manager.resolveFile(file.getAbsolutePath()); // Create remote file object FileObject remoteFile = manager.resolveFile(sftpUri, opts); // Copy local file to sftp server localFile.copyFrom(remoteFile, Selectors.SELECT_SELF); System.out.println("File download successful"); } catch (Exception ex) { ex.printStackTrace(); return false; } finally { manager.close(); } return true; }