List of usage examples for java.util Properties setProperty
public synchronized Object setProperty(String key, String value)
From source file:com.alibaba.rocketmq.common.MixAll.java
public static Properties commandLine2Properties(final CommandLine commandLine) { Properties properties = new Properties(); Option[] opts = commandLine.getOptions(); if (opts != null) { for (Option opt : opts) { String name = opt.getLongOpt(); String value = commandLine.getOptionValue(name); if (value != null) { properties.setProperty(name, value); }// w w w . jav a 2s .c om } } return properties; }
From source file:com.googleapis.ajax.services.example.ResourceBundleGenerator.java
/** * Process command line./*from w w w .j a v a2 s. co m*/ * * @param line the line * @param options the options */ @SuppressWarnings("unchecked") private static void processCommandLine(CommandLine line, Options options) { if (line.hasOption(HELP_OPTION)) { printHelp(options); } else if (line.hasOption(APPLICATION_KEY_OPTION) && line.hasOption(RESOURCE_OPTION)) { GoogleSearchQueryFactory factory = GoogleSearchQueryFactory .newInstance(line.getOptionValue(APPLICATION_KEY_OPTION)); Properties resourceMessages = loadResourceMessages(line.getOptionValue(RESOURCE_OPTION)); List<String> propertyNames = (List<String>) Collections.list(resourceMessages.propertyNames()); List<Language> targetLanguages = getTargetLanguages(line.getOptionValue(LANGUAGES_OPTION)); for (Language language : targetLanguages) { Properties translatedResources = new Properties(); TranslateLanguageQuery translateQuery = factory.newTranslateLanguageQuery(); translateQuery.withLanguagePair(Language.ENGLISH, language); for (String name : propertyNames) { translateQuery.withQuery(resourceMessages.getProperty(name)); } List<TranslateLanguageResult> result = translateQuery.list(); if (result.size() == propertyNames.size()) { int index = 0; for (String name : propertyNames) { translatedResources.setProperty(name, result.get(index++).getTranslatedText()); } } saveResourceMessages(translatedResources, line.getOptionValue(RESOURCE_OPTION), language); } } else { printHelp(options); } }
From source file:gdt.data.grain.Locator.java
/** * Convert the locator string into the Properties object. * @param locator$ the locator string. * @return the Properties object. /* w w w . ja va 2 s .c o m*/ */ public static Properties toProperties(String locator$) { // System.out.println("Locator:toProperties:locator="+locator$); if (locator$ == null) { //Logger.getLogger(Locator.class.getName()).severe(":toProperties:locator is null"); return null; } Properties props = new Properties(); String[] sa = locator$.split(NAME_DELIMITER); if (sa == null) { Logger.getLogger(Locator.class.getName()).severe(":toProperties:cannot split fields"); return null; } String[] na; for (int i = 0; i < sa.length; i++) { try { na = sa[i].split(VALUE_DELIMITER); if (na == null || na.length < 2) continue; props.setProperty(na[0], na[1]); } catch (Exception e) { Logger.getLogger(Locator.class.getName()).severe(":toProperties:" + e.toString()); } } if (props.isEmpty()) { Logger.getLogger(Locator.class.getName()).severe(":toProperties:empty"); return null; } return props; }
From source file:com.dragoniade.encrypt.EncryptionHelper.java
public static void decrypt(Properties p, String seedKey, String key) { String value = p.getProperty(key); String seed = p.getProperty(seedKey, seedKey); if (value == null || value.length() == 0) { return;//from ww w . ja v a2s . c o m } int index = value.indexOf('{'); switch (index) { case -1: return; case 0: { String toDecode = value.substring(1, value.length() - 1); String decryptStr; try { decryptStr = new String(Base64.decode(toDecode), "UTF-16"); } catch (UnsupportedEncodingException e1) { decryptStr = new String(Base64.decode(toDecode)); } p.setProperty(key, decryptStr); return; } default: String toDecode = value.substring(index + 1, value.length() - 1); String algorithm = value.substring(0, index); byte[] decryptStr = Base64.decode(toDecode); Cipher cipher = getDecrypter(seed, algorithm); String decoded; try { byte[] result = cipher.doFinal(decryptStr); try { decoded = new String(result, "UTF-16"); } catch (UnsupportedEncodingException e1) { decoded = new String(result); } } catch (Exception e) { decoded = ""; } p.setProperty(key, decoded); } }
From source file:com.glaf.core.config.DBConfiguration.java
public static Properties getHibernateDialectMappings() { Properties dialectMappings = new Properties(); dialectMappings.setProperty("h2", "org.hibernate.dialect.H2Dialect"); dialectMappings.setProperty("mysql", "org.hibernate.dialect.MySQL5Dialect"); dialectMappings.setProperty("oracle", "org.hibernate.dialect.Oracle10gDialect"); dialectMappings.setProperty("postgresql", "org.hibernate.dialect.PostgreSQLDialect"); dialectMappings.setProperty("sqlserver", "org.hibernate.dialect.SQLServerDialect"); dialectMappings.setProperty("db2", "org.hibernate.dialect.DB2Dialect"); return dialectMappings; }
From source file:com.glaf.core.config.DBConfiguration.java
public static Properties getDialectMappings() { Properties dialectMappings = new Properties(); dialectMappings.setProperty("h2", "com.glaf.core.dialect.H2Dialect"); dialectMappings.setProperty("mysql", "com.glaf.core.dialect.MySQLDialect"); dialectMappings.setProperty("oracle", "com.glaf.core.dialect.OracleDialect"); dialectMappings.setProperty("postgresql", "com.glaf.core.dialect.PostgreSQLDialect"); dialectMappings.setProperty("sqlserver", "com.glaf.core.dialect.SQLServer2008Dialect"); dialectMappings.setProperty("sqlite", "com.glaf.core.dialect.SQLiteDialect"); dialectMappings.setProperty("db2", "com.glaf.core.dialect.DB2Dialect"); return dialectMappings; }
From source file:net.sf.keystore_explorer.crypto.signing.MidletSigner.java
/** * Read the attributes of the supplied JAD file as properties. * * @param jadFile//from www . ja v a 2s.co m * JAD file * @return JAD file's attributes as properties * @throws IOException * If an I/O problem occurred or supplied file is not a JAD file */ public static Properties readJadFile(File jadFile) throws IOException { LineNumberReader lnr = null; try { Properties jadProperties = new Properties(); lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(jadFile))); String line = null; while ((line = lnr.readLine()) != null) { int index = line.indexOf(": "); if (index == -1) { throw new IOException(res.getString("NoReadJadCorrupt.exception.message")); } String name = line.substring(0, index); String value = line.substring(index + 2); jadProperties.setProperty(name, value); } return jadProperties; } finally { IOUtils.closeQuietly(lnr); } }
From source file:com.intuit.autumn.utils.PropertyFactory.java
private static void fromJar(final String propertyResourceName, @Nullable final Class base, final Properties properties) { if (base == null) { return;//from w ww . j a v a2 s . c o m } CodeSource src = base.getProtectionDomain().getCodeSource(); if (src == null) { return; } Properties propertiesFromJar = getPropertyFromJar(base, propertyResourceName.substring(1), src); for (Entry<Object, Object> entry : propertiesFromJar.entrySet()) { if (!properties.containsKey(entry.getKey())) { LOGGER.debug("overriding key: {}, newValue: {}, originalValue: {}", new Object[] { entry.getKey(), propertiesFromJar, entry.getValue() }); properties.setProperty((String) entry.getKey(), (String) entry.getValue()); } } }
From source file:com.piusvelte.taplock.server.TapLockServer.java
private static void initialize() { (new File(APP_PATH)).mkdir(); if (OS == OS_WIN) Security.addProvider(new BouncyCastleProvider()); System.out.println("APP_PATH: " + APP_PATH); try {/*from w w w. j a v a 2 s . co m*/ sLogFileHandler = new FileHandler(sLog); } catch (SecurityException e) { writeLog("sLogFileHandler init: " + e.getMessage()); } catch (IOException e) { writeLog("sLogFileHandler init: " + e.getMessage()); } File propertiesFile = new File(sProperties); if (!propertiesFile.exists()) { try { propertiesFile.createNewFile(); } catch (IOException e) { writeLog("propertiesFile.createNewFile: " + e.getMessage()); } } Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); if (prop.isEmpty()) { prop.setProperty(sPassphraseKey, sPassphrase); prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); prop.store(new FileOutputStream(sProperties), null); } else { if (prop.containsKey(sPassphraseKey)) sPassphrase = prop.getProperty(sPassphraseKey); else prop.setProperty(sPassphraseKey, sPassphrase); if (prop.containsKey(sDisplaySystemTrayKey)) sDisplaySystemTray = Boolean.parseBoolean(prop.getProperty(sDisplaySystemTrayKey)); else prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); if (prop.containsKey(sDebuggingKey)) sDebugging = Boolean.parseBoolean(prop.getProperty(sDebuggingKey)); else prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); } } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } if (sLogFileHandler != null) { sLogger = Logger.getLogger("TapLock"); sLogger.setUseParentHandlers(false); sLogger.addHandler(sLogFileHandler); SimpleFormatter sf = new SimpleFormatter(); sLogFileHandler.setFormatter(sf); writeLog("service starting"); } if (sDisplaySystemTray && SystemTray.isSupported()) { final SystemTray systemTray = SystemTray.getSystemTray(); Image trayIconImg = Toolkit.getDefaultToolkit() .getImage(TapLockServer.class.getResource("/systemtrayicon.png")); final TrayIcon trayIcon = new TrayIcon(trayIconImg, "Tap Lock"); trayIcon.setImageAutoSize(true); PopupMenu popupMenu = new PopupMenu(); MenuItem aboutItem = new MenuItem("About"); CheckboxMenuItem toggleSystemTrayIcon = new CheckboxMenuItem("Display Icon in System Tray"); toggleSystemTrayIcon.setState(sDisplaySystemTray); CheckboxMenuItem toggleDebugging = new CheckboxMenuItem("Debugging"); toggleDebugging.setState(sDebugging); MenuItem shutdownItem = new MenuItem("Shutdown Tap Lock Server"); popupMenu.add(aboutItem); popupMenu.add(toggleSystemTrayIcon); if (OS == OS_WIN) { MenuItem setPasswordItem = new MenuItem("Set password"); popupMenu.add(setPasswordItem); setPasswordItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel panel = new JPanel(); JLabel label = new JLabel("Enter your Windows account password:"); JPasswordField passField = new JPasswordField(32); panel.add(label); panel.add(passField); String[] options = new String[] { "OK", "Cancel" }; int option = JOptionPane.showOptionDialog(null, panel, "Tap Lock", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (option == 0) { String password = encryptString(new String(passField.getPassword())); if (password != null) { Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); prop.setProperty(sPasswordKey, password); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e1) { writeLog("prop load: " + e1.getMessage()); } catch (IOException e1) { writeLog("prop load: " + e1.getMessage()); } } } } }); } popupMenu.add(toggleDebugging); popupMenu.add(shutdownItem); trayIcon.setPopupMenu(popupMenu); try { systemTray.add(trayIcon); } catch (AWTException e) { writeLog("systemTray.add: " + e.getMessage()); } aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String newline = System.getProperty("line.separator"); newline += newline; JOptionPane.showMessageDialog(null, "Tap Lock" + newline + "Copyright (c) 2012 Bryan Emmanuel" + newline + "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version." + newline + "This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details." + newline + "You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>." + newline + "Bryan Emmanuel piusvelte@gmail.com"); } }); toggleSystemTrayIcon.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { setTrayIconDisplay(e.getStateChange() == ItemEvent.SELECTED); if (!sDisplaySystemTray) systemTray.remove(trayIcon); } }); toggleDebugging.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { setDebugging(e.getStateChange() == ItemEvent.SELECTED); } }); shutdownItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { shutdown(); } }); } synchronized (sConnectionThreadLock) { (sConnectionThread = new ConnectionThread()).start(); } }
From source file:gov.nih.nci.logging.api.util.HibernateUtil.java
/** * This method creates and returns the Hibernate SessionFactory used by CLM's Query API's. * //from ww w .ja v a 2 s .c o m * @return SessionFactory * @throws Exception */ private static SessionFactory createSessionFactory() throws Exception { LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean(); String mappingResources[] = { "gov/nih/nci/logging/api/domain/LogMessage.hbm.xml", "gov/nih/nci/logging/api/domain/ObjectAttribute.hbm.xml" }; localSessionFactoryBean.setMappingResources(mappingResources); /* * BasicDataSource ds = new BasicDataSource(); * ds.setDriverClassName(props.getProperty("CLMDS.driverClassName")); * ds.setUrl(props.getProperty("CLMDS.url")); * ds.setUsername(props.getProperty("CLMDS.username")); * ds.setPassword(props.getProperty("CLMDS.password")); * localSessionFactoryBean.setDataSource(ds); */ if (props == null) { java.io.InputStream inputStream = FileLoader.getInstance().getFileAsStream("clm.properties"); Properties properties = new Properties(); if (inputStream != null) { try { properties.load(inputStream); } catch (IOException e) { e.printStackTrace(); } } if (!properties.isEmpty()) { validateProperties(properties); props = properties; } } if (isDataSourceProperties()) { String jndiName = props.getProperty("CLMDJndiDS.jndiName"); Properties properties = new Properties(); properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); localSessionFactoryBean.setHibernateProperties(props); // set javax.sql.DataSource localSessionFactoryBean.setDataSource(getDataSource(jndiName)); } else { //set JDBC Connection Properties for Hibernate localSessionFactoryBean.setHibernateProperties(props); } try { localSessionFactoryBean.afterPropertiesSet(); } catch (HibernateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } SessionFactory sf = (SessionFactory) localSessionFactoryBean.getObject(); return sf; }