List of usage examples for java.util Properties setProperty
public synchronized Object setProperty(String key, String value)
From source file:com.datastax.dse.demos.solr.Wikipedia.java
public static void indexWikipedia() { HttpSolrServer solrClient = null;/* ww w . j av a 2s .c om*/ try { Properties p = new Properties(); p.setProperty("keep.image.only.docs", "false"); p.setProperty("docs.file", wikifile); Config config = new Config(p); source = new EnwikiContentSource(); source.setConfig(config); source.resetInputs(); solrClient = new HttpSolrServer(url); if (null != user && null != password) { AbstractHttpClient httpClient = (AbstractHttpClient) solrClient.getHttpClient(); httpClient.addRequestInterceptor(new PreEmptiveBasicAuthenticator(user, password)); } DocData docData = new DocData(); String firstName = null; SolrInputDocument doc = new SolrInputDocument(); int i = 0; for (int x = 0; x < limit; x++) { if (i > 0 && i % 1000 == 0) System.out.println("Indexed " + i++); docData = source.getNextDocData(docData); if (firstName == null) firstName = docData.getName(); else if (firstName.equals(docData.getName())) break; //looped if (addDoc(doc, docData)) { solrClient.add(doc); i++; } } } catch (NoMoreDataException e) { } catch (Exception e) { e.printStackTrace(); } finally { try { if (solrClient != null) solrClient.commit(); source.close(); } catch (Throwable t) { } } }
From source file:io.druid.data.input.orc.OrcHadoopInputRowParser.java
public static Properties getTablePropertiesFromStructTypeInfo(StructTypeInfo structTypeInfo) { Properties table = new Properties(); table.setProperty("columns", StringUtils.join(structTypeInfo.getAllStructFieldNames(), ",")); table.setProperty("columns.types", StringUtils.join( Lists.transform(structTypeInfo.getAllStructFieldTypeInfos(), new Function<TypeInfo, String>() { @Nullable/*from w w w . j av a2 s . c o m*/ @Override public String apply(@Nullable TypeInfo typeInfo) { return typeInfo.getTypeName(); } }), ",")); return table; }
From source file:com.github.sparkfy.util.Log4jPropertyHelper.java
public static void updateLog4jConfiguration(/*Class<?> targetClass,*/ String log4jPath) throws Exception { Properties customProperties = new Properties(); FileInputStream fs = null;//from w w w .j a v a 2 s . c om InputStream is = null; try { fs = new FileInputStream(log4jPath); // is = targetClass.getResourceAsStream("/log4j.properties"); is = Utils.getClassLoader().getResourceAsStream("com/github/sparkfy/log4j-defaults.properties"); customProperties.load(fs); Properties originalProperties = new Properties(); originalProperties.load(is); for (Entry<Object, Object> entry : customProperties.entrySet()) { originalProperties.setProperty(entry.getKey().toString(), entry.getValue().toString()); } LogManager.resetConfiguration(); PropertyConfigurator.configure(originalProperties); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(fs); } }
From source file:com.xeiam.datasets.common.business.DatasetsDAO.java
public static void init(String poolName, String dbName, String dataFilesDir, String dataFileURL, String propsFileURL, String scriptFileURL, String lobsFileURL, boolean requiresManualDownload) { // 1. create data dir // 1b. Clean up any stragglers FileUtils.deleteQuietly(new File(dataFilesDir + "/" + dbName + ".tmp")); FileUtils.deleteQuietly(new File(dataFilesDir + "/" + dbName + ".lck")); FileUtils.deleteQuietly(new File(dataFilesDir + "/" + dbName + ".log")); // 2. check if files are already available File dataFile = new File(dataFilesDir + "/" + dbName + ".data"); File propsFile = new File(dataFilesDir + "/" + dbName + ".properties"); File scriptFile = new File(dataFilesDir + "/" + dbName + ".script"); File lobsFile = new File(dataFilesDir + "/" + dbName + ".lobs"); // if the files don't yet exist, then download them if (!dataFile.exists() || !propsFile.exists() || !scriptFile.exists()) { logger.info("Saving DB files in: " + dataFilesDir); URL url;/*from w w w .j a v a 2 s. co m*/ try { // props logger.info("Downloading props file..."); url = new URL(GoogleDriveURLPart1 + propsFileURL); org.apache.commons.io.FileUtils.copyURLToFile(url, propsFile, 5000, 10000); } catch (Exception e) { throw new RuntimeException( "Something went wrong while downloading the database files. Perhaps try again and if all else fails, download the files manually (https://drive.google.com/folderview?id=0ByP7_A9vXm17VXhuZzBrcnNubEE&usp=sharing) and place in the directory you specified.", e); } try { // script logger.info("Downloading script file..."); url = new URL(GoogleDriveURLPart1 + scriptFileURL); org.apache.commons.io.FileUtils.copyURLToFile(url, scriptFile, 5000, 10000); } catch (Exception e) { throw new RuntimeException( "Something went wrong while downloading the database files. Perhaps try again and if all else fails, download the files manually (https://drive.google.com/folderview?id=0ByP7_A9vXm17VXhuZzBrcnNubEE&usp=sharing) and place in the directory you specified.", e); } // data if (!requiresManualDownload) { try { logger.info("Downloading data file... (this could take a while so be patient!)"); url = new URL(GoogleDriveURLPart1 + dataFileURL); org.apache.commons.io.FileUtils.copyURLToFile(url, dataFile, 5000, 10000); } catch (Exception e) { throw new RuntimeException( "Something went wrong while downloading the database files. Perhaps try again and if all else fails, download the files manually (https://drive.google.com/folderview?id=0ByP7_A9vXm17VXhuZzBrcnNubEE&usp=sharing) and place in the directory you specified.", e); } } else { throw new RuntimeException( "The data file is too big to download automatically! Please manually download it from: " + (GoogleDriveURLPart1 + dataFileURL) + " and place it in: " + dataFilesDir); } } else { logger.info("Database files already exist in local directory. Skipping download."); } if (lobsFileURL != null && !lobsFile.exists()) { throw new RuntimeException( "The data file is too big to download automatically! Please manually download it from: " + (GoogleDriveURLPart1 + lobsFileURL) + " and place it in: " + dataFilesDir); } // 3. setup HSQLDB Properties dbProps = new Properties(); dbProps.setProperty("driverclassname", "org.hsqldb.jdbcDriver"); dbProps.setProperty(poolName + ".url", "jdbc:hsqldb:file:" + dataFilesDir + File.separatorChar + dbName + ";shutdown=true;readonly=true"); dbProps.setProperty(poolName + ".user", "sa"); dbProps.setProperty(poolName + ".password", ""); dbProps.setProperty(poolName + ".maxconn", "10"); DBConnectionManager.INSTANCE.init(dbProps); }
From source file:eu.forgestore.ws.util.EmailUtil.java
public static void SendRegistrationActivationEmail(String email, String messageBody) { Properties props = new Properties(); // Session session = Session.getDefaultInstance(props, null); props.setProperty("mail.transport.protocol", "smtp"); if ((FStoreRepository.getPropertyByName("mailhost").getValue() != null) && (!FStoreRepository.getPropertyByName("mailhost").getValue().isEmpty())) props.setProperty("mail.host", FStoreRepository.getPropertyByName("mailhost").getValue()); if ((FStoreRepository.getPropertyByName("mailuser").getValue() != null) && (!FStoreRepository.getPropertyByName("mailuser").getValue().isEmpty())) props.setProperty("mail.user", FStoreRepository.getPropertyByName("mailuser").getValue()); if ((FStoreRepository.getPropertyByName("mailpassword").getValue() != null) && (!FStoreRepository.getPropertyByName("mailpassword").getValue().isEmpty())) props.setProperty("mail.password", FStoreRepository.getPropertyByName("mailpassword").getValue()); String adminemail = FStoreRepository.getPropertyByName("adminEmail").getValue(); String subj = FStoreRepository.getPropertyByName("activationEmailSubject").getValue(); logger.info("adminemail = " + adminemail); logger.info("subj = " + subj); Session mailSession = Session.getDefaultInstance(props, null); Transport transport;/* w ww .jav a 2s . c om*/ try { transport = mailSession.getTransport(); MimeMessage msg = new MimeMessage(mailSession); msg.setSentDate(new Date()); msg.setFrom(new InternetAddress(adminemail, adminemail)); msg.setSubject(subj); msg.setContent(messageBody, "text/html; charset=ISO-8859-1"); msg.addRecipient(Message.RecipientType.TO, new InternetAddress(email, email)); transport.connect(); transport.sendMessage(msg, msg.getRecipients(Message.RecipientType.TO)); transport.close(); } catch (NoSuchProviderException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MessagingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:gr.upatras.ece.nam.baker.util.EmailUtil.java
public static void SendRegistrationActivationEmail(String email, String messageBody) { Properties props = new Properties(); // Session session = Session.getDefaultInstance(props, null); props.setProperty("mail.transport.protocol", "smtp"); if ((BakerRepository.getPropertyByName("mailhost").getValue() != null) && (!BakerRepository.getPropertyByName("mailhost").getValue().isEmpty())) props.setProperty("mail.host", BakerRepository.getPropertyByName("mailhost").getValue()); if ((BakerRepository.getPropertyByName("mailuser").getValue() != null) && (!BakerRepository.getPropertyByName("mailuser").getValue().isEmpty())) props.setProperty("mail.user", BakerRepository.getPropertyByName("mailuser").getValue()); if ((BakerRepository.getPropertyByName("mailpassword").getValue() != null) && (!BakerRepository.getPropertyByName("mailpassword").getValue().isEmpty())) props.setProperty("mail.password", BakerRepository.getPropertyByName("mailpassword").getValue()); String adminemail = BakerRepository.getPropertyByName("adminEmail").getValue(); String subj = BakerRepository.getPropertyByName("activationEmailSubject").getValue(); logger.info("adminemail = " + adminemail); logger.info("subj = " + subj); Session mailSession = Session.getDefaultInstance(props, null); Transport transport;/*ww w . ja v a 2 s. c o m*/ try { transport = mailSession.getTransport(); MimeMessage msg = new MimeMessage(mailSession); msg.setSentDate(new Date()); msg.setFrom(new InternetAddress(adminemail, adminemail)); msg.setSubject(subj); msg.setContent(messageBody, "text/html; charset=ISO-8859-1"); msg.addRecipient(Message.RecipientType.TO, new InternetAddress(email, email)); transport.connect(); transport.sendMessage(msg, msg.getRecipients(Message.RecipientType.TO)); transport.close(); } catch (NoSuchProviderException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MessagingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.rpgsheet.xcom.PimpMyXcom.java
private static void createApplicationProperties(File appPropertiesFile) throws IOException { // if we've already got one, skip this creation step if (appPropertiesFile.exists()) return;/*from w ww . ja v a 2s. c om*/ // otherwise, create a default set of properties Properties appProperties = new Properties(); appProperties.setProperty("xcom.lang", APPLICATION_DEFAULT_LANG); appProperties.setProperty("xcom.path", APPLICATION_DEFAULT_PATH); // and write them to the disk saveApplicationProperties(appProperties); }
From source file:com.foilen.smalltools.tools.Hibernate4Tools.java
/** * Generate the SQL file. This is based on the code in {@link LocalSessionFactoryBuilder#scanPackages(String...)} * * @param dialect/*w w w . j av a 2 s . c o m*/ * the dialect (e.g: org.hibernate.dialect.MySQL5InnoDBDialect ) * @param outputSqlFile * where to put the generated SQL file * @param useUnderscore * true: to have tables names like "employe_manager" ; false: to have tables names like "employeManager" * @param packagesToScan * the packages where your entities are */ @SuppressWarnings("deprecation") public static void generateSqlSchema(Class<? extends Dialect> dialect, String outputSqlFile, boolean useUnderscore, String... packagesToScan) { // Configuration Configuration configuration = new Configuration(); if (useUnderscore) { configuration.setNamingStrategy(new ImprovedNamingStrategy()); } Properties properties = new Properties(); properties.setProperty(AvailableSettings.DIALECT, dialect.getName()); // Scan packages Set<String> classNames = new TreeSet<String>(); Set<String> packageNames = new TreeSet<String>(); try { for (String pkg : packagesToScan) { String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(pkg) + RESOURCE_PATTERN; Resource[] resources = resourcePatternResolver.getResources(pattern); MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(resourcePatternResolver); for (Resource resource : resources) { if (resource.isReadable()) { MetadataReader reader = readerFactory.getMetadataReader(resource); String className = reader.getClassMetadata().getClassName(); if (matchesEntityTypeFilter(reader, readerFactory)) { classNames.add(className); } else if (className.endsWith(PACKAGE_INFO_SUFFIX)) { packageNames .add(className.substring(0, className.length() - PACKAGE_INFO_SUFFIX.length())); } } } } } catch (IOException ex) { throw new MappingException("Failed to scan classpath for unlisted classes", ex); } try { for (String className : classNames) { configuration.addAnnotatedClass(resourcePatternResolver.getClassLoader().loadClass(className)); } for (String packageName : packageNames) { configuration.addPackage(packageName); } } catch (ClassNotFoundException ex) { throw new MappingException("Failed to load annotated classes from classpath", ex); } // Exportation SchemaExport schemaExport = new SchemaExport(configuration, properties); schemaExport.setOutputFile(outputSqlFile); schemaExport.setDelimiter(";"); schemaExport.setFormat(true); schemaExport.execute(true, false, false, true); }
From source file:com.founder.fix.fixflow.I18N.PropertiesUtil.java
/** * //from w w w . ja v a 2s .co m * @param path * @param key * @param value */ public static void setProperty(String path, String key, String value) { Properties prop = propsMap.get(path); if (prop == null) prop = load(path); if (prop != null) { prop.setProperty(key, value); propsMap.put(path, prop); } }
From source file:OCCIConnectionServlet.java
public static ConnectionPoolDataSource getConnectionPoolDataSource(String baseName) { Context context = null;// w w w . ja v a 2s .c o m ConnectionPoolDataSource cpds = null; try { Properties properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); properties.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC"); context = new InitialContext(properties); cpds = (ConnectionPoolDataSource) context.lookup(baseName); } catch (NamingException e) { System.err.println(e.getMessage() + " creating JNDI context for " + baseName); } return cpds; }