List of usage examples for java.util Properties setProperty
public synchronized Object setProperty(String key, String value)
From source file:mas.MAS_VLDB.java
/** * @param args the command line arguments *//*from w ww . j a v a2 s. c o m*/ // for old version public static void getData(int startIdx, int endIdx) { try { Properties prop = new Properties(); prop.setProperty("AppId", "1df63064-efad-4bbd-a797-1131499b7728"); prop.setProperty("ResultObjects", "publication"); prop.setProperty("DomainID", "22"); prop.setProperty("SubDomainID", "2"); prop.setProperty("YearStart", "2001"); prop.setProperty("YearEnd", "2010"); prop.setProperty("StartIdx", startIdx + ""); prop.setProperty("EndIdx", endIdx + ""); String url_org = "http://academic.research.microsoft.com/json.svc/search"; String url_str = generateURL(url_org, prop); URL url = new URL(url_str); URLConnection yc = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println(inputLine); } in.close(); } catch (MalformedURLException ex) { Logger.getLogger(MAS_VLDB.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MAS_VLDB.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:dk.hippogrif.prettyxml.PrettyPrint.java
static void checkString(String key, Properties prop) { String s = prop.getProperty(key); if (s != null) { s = s.trim();//from w w w . j a v a 2s . co m if (s.length() == 0) { prop.remove(key); } else { prop.setProperty(key, s); } } }
From source file:eu.dnetlib.maven.plugin.properties.WritePredefinedProjectProperties.java
/** * Provides environment variables./* w ww . ja v a 2s .c o m*/ * @return environment variables */ protected static Properties getEnvironmentVariables() { String prefix = "env"; Map<String, String> map = System.getenv(); Properties props = new Properties(); for (String key : map.keySet()) { String newKey = prefix + "." + key; String value = map.get(key); props.setProperty(newKey, value); } return props; }
From source file:com.dicksoft.ocr.Temp.java
private static void setupLog() { System.getProperties().setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Properties properties = new Properties(); InputStream input;//from w ww. j a v a2 s.com try { input = new FileInputStream(LOG4JPROPERTIES); properties.load(input); } catch (FileNotFoundException e) { System.err.println("Log4J properties file not found at " + LOG4JPROPERTIES); } catch (Exception e) { System.err.println("Log4J properties file read error."); } File logDir = new File(LOG4JLOCATION + StringUtil.FS); if (!logDir.exists()) { logDir.mkdirs(); } properties.setProperty("log4j.appender.FILE.File", logDir.getAbsolutePath() + StringUtil.FS + "main.log"); PropertyConfigurator.configure(properties); LOG = LogFactory.getLog(Temp.class); }
From source file:edu.yale.cs.hadoopdb.sms.SQLQueryGenerator.java
/** * Cheats Hive's internal table schema with that to be returned by DBMS */// w ww . j ava2 s.c o m public static void hackMapredWorkSchema(SQLQuery sqlStructure, Table tbl) { Properties schema = tbl.getSchema(); LOG.debug("MetaData Table properties " + tbl + " : " + schema.toString()); // hacking schema.setProperty("columns.types", sqlStructure.getDDLColumnTypes()); schema.setProperty("serialization.ddl", sqlStructure.getSerializationDDL()); schema.setProperty("columns", sqlStructure.getDDLColumns()); LOG.debug("Hacked Table properties " + tbl + " : " + schema.toString()); }
From source file:com.mirth.connect.server.controllers.tests.TestUtils.java
public static Properties getSqlProperties() { PropertiesConfiguration mirthProperties = new PropertiesConfiguration(); try {/*from www. ja va 2 s . c om*/ InputStream is = ResourceUtil.getResourceStream(SqlSession.class, "mirth.properties"); mirthProperties.setDelimiterParsingDisabled(true); mirthProperties.load(is); IOUtils.closeQuietly(is); } catch (Exception e) { e.printStackTrace(); return null; } Properties donkeyProperties = new Properties(); donkeyProperties.setProperty("database.driver", mirthProperties.getString("database.driver")); donkeyProperties.setProperty("database.url", mirthProperties.getString("database.url")); donkeyProperties.setProperty("database.username", mirthProperties.getString("database.username")); if (mirthProperties.containsKey("database.password")) { donkeyProperties.setProperty("database.password", mirthProperties.getString("database.password")); } return donkeyProperties; }
From source file:com.scf.core.context.app.cfg.module.ModuleConfigHandler.java
/** * marges props//from w w w. ja va 2s . co m * * @param marges * @param moduleName * @param props * @return */ @SuppressWarnings("rawtypes") private static ConfigParams loadModuleConfig(Properties marges, String moduleName, Properties props) { if (marges != null) { Enumeration pks = marges.propertyNames(); while (pks.hasMoreElements()) { String pk = (String) pks.nextElement(); String _pk = "module_" + moduleName + "."; if (pk.startsWith(_pk)) { _pk = pk.substring(_pk.length()); _logger.info("Module config override " + pk + " = " + marges.getProperty(pk) + "[default: " + props.getProperty(_pk) + "]"); props.setProperty(_pk, marges.getProperty(pk)); } } } ConfigParams cp = new ConfigParams(); cp.setParams(props); return cp; }
From source file:adalid.util.google.Translator.java
public static Properties translate(Properties properties) { if (properties == null || properties.isEmpty()) { return properties; }/* w ww . ja v a2 s. com*/ String arg, translation; URIBuilder builder = newURIBuilder(); try (CloseableHttpClient client = HttpClients.createDefault()) { Set<String> names = properties.stringPropertyNames(); for (String name : names) { arg = properties.getProperty(name); logger.info(arg); translation = translate(arg, builder, client); logger.info(translation); if (translation != null) { properties.setProperty(name, translation); } } } catch (IOException | URISyntaxException ex) { logger.fatal(ex); } return properties; }
From source file:io.stallion.reflection.PropertyUtils.java
/** * Set a direct or indirect property (dotted property: prop1.prop2.prop3) on the target object. This method tries * to be smart in the way that intermediate properties currently set to null are set if it is possible to create * and set an object. Conversions from propertyValue to the proper destination type are performed when possible. * @param target the target object on which to set the property. * @param propertyName the name of the property to set. * @param propertyValue the value of the property to set. * @throws PropertyException if an error happened while trying to set the property. *//*from w w w . j a va 2s. co m*/ public static void setProperty(Object target, String propertyName, Object propertyValue) throws PropertyException { String[] propertyNames = propertyName.split("\\."); StringBuffer visitedPropertyName = new StringBuffer(); Object currentTarget = target; int i = 0; while (i < propertyNames.length - 1) { String name = propertyNames[i]; Object result = callGetter(currentTarget, name); if (result == null) { // try to instanciate the object & set it in place Class propertyType = getPropertyType(target, name); try { result = propertyType.newInstance(); } catch (InstantiationException ex) { throw new PropertyException("cannot set property '" + propertyName + "' - '" + name + "' is null and cannot be auto-filled", ex); } catch (IllegalAccessException ex) { throw new PropertyException("cannot set property '" + propertyName + "' - '" + name + "' is null and cannot be auto-filled", ex); } callSetter(currentTarget, name, result); } currentTarget = result; visitedPropertyName.append(name); visitedPropertyName.append('.'); i++; // if it's a Properties object -> the non-visited part of the key should be used // as this Properties' object key so stop iterating over the dotted properties. if (currentTarget instanceof Properties) break; } String lastPropertyName = propertyName.substring(visitedPropertyName.length(), propertyName.length()); if (currentTarget instanceof Properties) { Properties p = (Properties) currentTarget; p.setProperty(lastPropertyName, propertyValue.toString()); } else { setDirectProperty(currentTarget, lastPropertyName, propertyValue); } }
From source file:edu.duke.cabig.c3pr.service.impl.RulesDelegationServiceImpl.java
public static void loadConfiguration(Properties props) { ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "classpath:edu/duke/cabig/c3pr/applicationContext-config.xml"); String url = applicationContext.getBean("c3prPropertyConfigurerFromFile[datasource.url]").toString(); String driver = applicationContext.getBean("c3prPropertyConfigurerFromFile[datasource.driver]").toString(); String user = applicationContext.getBean("c3prPropertyConfigurerFromFile[datasource.username]").toString(); String pwd = applicationContext.getBean("c3prPropertyConfigurerFromFile[datasource.password]").toString(); props.setProperty("datasource.driver", driver); props.setProperty("datasource.password", pwd); props.setProperty("datasource.username", user); props.setProperty("datasource.url", url); }