List of usage examples for java.util Properties keys
@Override
public Enumeration<Object> keys()
From source file:org.webdavaccess.LocalFileSystemStorage.java
/** * Delete properties for given resource//from w w w . j a v a 2 s .c om * * @param resourceUri for which to delete properties */ public void deleteProperties(String resourceUri, Properties propertiesToDelete) { resourceUri = normalize(resourceUri); // Try cache first Properties props = (Properties) mPropertiesCache.get(resourceUri); if (props != null) mPropertiesCache.remove(resourceUri); File file = getPropertiesFile(resourceUri); if (file == null || !file.exists()) { return; } InputStream in = null; Properties persisted = new Properties(); try { in = new FileInputStream(file); persisted.loadFromXML(in); } catch (Exception e) { log.warn("Failed to get properties from cache for " + resourceUri); return; } finally { if (in != null) try { in.close(); } catch (Exception e) { } } boolean changed = false; Enumeration en = persisted.keys(); HashMap toRemove = new HashMap(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); if (isResourceProperty(resourceUri, key)) { if (propertiesToDelete != null) { String newKey = getPropertyKey(resourceUri, key); if (propertiesToDelete.getProperty(newKey) != null) toRemove.put(key, persisted.getProperty(key)); } else { toRemove.put(key, persisted.getProperty(key)); } } } changed = !toRemove.isEmpty(); for (Iterator it = toRemove.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); persisted.remove(key); } if (changed) { // Store the updates properties OutputStream os = null; try { os = new FileOutputStream(file); persisted.storeToXML(os, ""); } catch (Exception e) { log.warn("Failed to store properties for " + resourceUri); } finally { if (os != null) try { os.close(); } catch (Exception e) { } } } }
From source file:org.smartfrog.avalanche.client.sf.apps.gt4.security.CertUtils.java
public void gridCertReq(Properties props, String user) throws GT4SecurityException { String cmd = new String(globusBin + File.separatorChar + "grid-cert-request"); Process p = null;/* w w w . j av a 2 s . c o m*/ BufferedReader cmdError = null; BufferedReader cmdOutput = null; String userHome = null; if (user != null) userHome = File.separatorChar + "home" + File.separatorChar + user; else userHome = System.getProperty("user.home"); String[] envs = { "GLOBUS_LOCATION=" + globusLoc, "HOME=" + userHome }; try { if (null == props) { log.info("No arguments passed for grid-cert-req ..."); props = new Properties(); props.setProperty("-force", ""); p = rt.exec(cmd, envs, null); } else { String args = null; props.setProperty("-force", ""); Enumeration e = props.keys(); String val = null; String k = null; if (e.hasMoreElements()) { k = (String) e.nextElement(); val = (String) props.getProperty(k); args = k + " " + val; } log.info("DEBUG: " + args); while (e.hasMoreElements()) { k = (String) e.nextElement(); val = (String) props.getProperty(k); args = args + " " + k + " " + val + " "; } cmd = cmd + " " + args; log.info(cmd); p = rt.exec(cmd, envs, null); } cmdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); cmdOutput = new BufferedReader(new InputStreamReader(p.getInputStream())); int exitVal = 0; exitVal = p.waitFor(); log.info("Exit Value : " + exitVal); if (exitVal != 0) { String line = null; String error = null; if (null != props.getProperty("-host")) error = "Error in requesting host certificate"; else error = "Error in requesting user certificate"; while ((line = cmdError.readLine()) != null) { log.error(line); error = error + "\n" + line; } while ((line = cmdOutput.readLine()) != null) { log.info(line); error = error + "\n" + line; } throw new GT4SecurityException(error); } String out = null; while ((out = cmdOutput.readLine()) != null) { log.info(out); } } catch (IOException ioe) { log.error(ioe); throw new GT4SecurityException(ioe); } catch (InterruptedException ie) { log.error(ie); throw new GT4SecurityException(ie); } }
From source file:com.adito.agent.client.Agent.java
protected static Agent initAgent(AgentArgs agentArgs) throws Throwable { Agent agent = new Agent(agentArgs.getAgentConfiguration()); // Setup the output stream PrintStream consolePrintStream = new PrintStream(agent.getGUI().getConsole()); System.setErr(consolePrintStream); System.setOut(consolePrintStream); System.out.println("Java version " + System.getProperty("java.version")); System.out.println("OS version " + System.getProperty("os.name")); // #ifdef DEBUG if (agentArgs.getLogProperties() != null) { File f = new File(agentArgs.getLogProperties()); InputStream in = new FileInputStream(f); try {/*from w w w . j a v a 2 s . c o m*/ Properties props = new Properties(); props.load(in); File logfile = new File(f.getParent(), "agent.log"); //$NON-NLS-1$ props.put("log4j.appender.logfile.File", logfile.getAbsolutePath()); //$NON-NLS-1$ org.apache.log4j.PropertyConfigurator.configure(props); log = org.apache.commons.logging.LogFactory.getLog(Agent.class); log.info("Configured logging"); //$NON-NLS-1$ } finally { in.close(); } } Properties systemProperties = System.getProperties(); String key; log.info("System properties:"); for (Enumeration e = systemProperties.keys(); e.hasMoreElements();) { key = (String) e.nextElement(); log.info(" " + key + ": " + systemProperties.getProperty(key)); } // #endif agent.setupProxy(agentArgs.getLocalProxyURL(), agentArgs.getUserAgent(), agentArgs.getPluginProxyURL(), agentArgs.getReverseProxyURL()); if (agentArgs.getBrowserCommand() != null && !agentArgs.getBrowserCommand().equals("")) { //$NON-NLS-1$ // #ifdef DEBUG log.info("Setting browser to " + agentArgs.getBrowserCommand()); //$NON-NLS-1$ // #endif BrowserLauncher.setBrowserCommand(agentArgs.getBrowserCommand()); } return agent; }
From source file:com.glaf.core.startup.MultiDBUpdateStartup.java
public void startup(ServletContext context, String text) { logger.debug("-----------------MultiDBUpdateStartup.startup----------------"); if (StringUtils.isNotEmpty(text)) { JSONObject json = JSON.parseObject(text); logger.debug(json.toJSONString()); String sql = json.getString("sql"); String dbName = json.getString("dbName"); if (StringUtils.isNotEmpty(sql) && !DBUtils.isLegalQuerySql(sql)) { logger.error(sql);/*from w w w .ja v a 2 s .co m*/ throw new RuntimeException(" SQL statement illegal "); } if (StringUtils.isNotEmpty(sql) && StringUtils.isNotEmpty(dbName)) { Properties defaultProps = DBConfiguration.getTemplateProperties(Environment.DEFAULT_SYSTEM_NAME); Properties props = DBConfiguration.getTemplateProperties(dbName); logger.debug(dbName + " props:" + props); if (props != null && StringUtils.isNotEmpty(props.getProperty(DBConfiguration.JDBC_URL))) { String old_url = props.getProperty(DBConfiguration.JDBC_URL); Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { conn = DBConnectionFactory.getConnection(); if (conn != null) { DBUpdateThread t = new DBUpdateThread(props); ThreadFactory.run(t); stmt = conn.prepareStatement(sql); rs = stmt.executeQuery(); while (rs.next()) { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); Enumeration<?> e = props.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = props.getProperty(key); dataMap.put(key, value); } String host = rs.getString(1); String databaseName = rs.getString(2); String name = rs.getString(5); if (databaseName.indexOf("$") != -1) { String url_xy = defaultProps.getProperty(DBConfiguration.JDBC_URL); String driver = defaultProps.getProperty(DBConfiguration.JDBC_DRIVER); String db = null; if (StringUtils.equals(driver, "com.microsoft.sqlserver.jdbc.SQLServerDriver")) { db = url_xy.substring(url_xy.lastIndexOf("=") + 1, url_xy.length()); } else if (StringUtils.equals(driver, "net.sourceforge.jtds.jdbc.Driver")) { db = url_xy.substring(url_xy.lastIndexOf("/") + 1, url_xy.length()); } if (db != null) { databaseName = StringTools.replaceIgnoreCase(databaseName, "self", db); } } logger.debug("databaseName:" + databaseName); dataMap.put(DBConfiguration.HOST, host); dataMap.put(DBConfiguration.DATABASE, databaseName); props.put(DBConfiguration.HOST, host); props.put(DBConfiguration.DATABASE, databaseName); props.put(DBConfiguration.JDBC_USER, rs.getString(3)); props.put(DBConfiguration.JDBC_PASSWORD, rs.getString(4)); logger.debug(dataMap); String url = ExpressionTools.evaluate(old_url, dataMap); props.put(DBConfiguration.JDBC_URL, url); host = StringTools.replace(host, ".", "_"); props.put(DBConfiguration.JDBC_NAME, name); /** * ??? */ if (DBConnectionFactory.checkConnection(props)) { logger.debug("SQL......"); DBUpdateThread thread = new DBUpdateThread(props); ThreadFactory.run(thread); } } } } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } finally { JdbcUtils.close(rs); JdbcUtils.close(stmt); JdbcUtils.close(conn); } } } } }
From source file:com.glaf.core.startup.MultiDBStartup.java
public void startup(ServletContext context, String text) { logger.debug("-----------------MultiDBStartup.startup----------------"); if (StringUtils.isNotEmpty(text)) { JSONObject json = JSON.parseObject(text); logger.debug(json.toJSONString()); String sql = json.getString("sql"); String dbName = json.getString("dbName"); if (StringUtils.isNotEmpty(sql) && !DBUtils.isLegalQuerySql(sql)) { logger.error(sql);//from w w w. ja va 2 s.c o m throw new RuntimeException(" SQL statement illegal "); } if (StringUtils.isNotEmpty(sql) && StringUtils.isNotEmpty(dbName)) { Properties defaultProps = DBConfiguration.getTemplateProperties(Environment.DEFAULT_SYSTEM_NAME); Properties props = DBConfiguration.getTemplateProperties(dbName); logger.debug(dbName + " props:" + props); if (props != null && StringUtils.isNotEmpty(props.getProperty(DBConfiguration.JDBC_URL))) { String old_url = props.getProperty(DBConfiguration.JDBC_URL); Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { conn = DBConnectionFactory.getConnection(); if (conn != null) { DBUpdateThread t = new DBUpdateThread(defaultProps); ThreadFactory.run(t); stmt = conn.prepareStatement(sql); rs = stmt.executeQuery(); while (rs.next()) { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); Enumeration<?> e = props.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = props.getProperty(key); dataMap.put(key, value); } String host = rs.getString(1); String databaseName = rs.getString(2); String name = rs.getString(5); if (databaseName.indexOf("$") != -1) { String url_xy = defaultProps.getProperty(DBConfiguration.JDBC_URL); String driver = defaultProps.getProperty(DBConfiguration.JDBC_DRIVER); String db = null; if (StringUtils.equals(driver, "com.microsoft.sqlserver.jdbc.SQLServerDriver")) { db = url_xy.substring(url_xy.lastIndexOf("=") + 1, url_xy.length()); } else if (StringUtils.equals(driver, "net.sourceforge.jtds.jdbc.Driver")) { db = url_xy.substring(url_xy.lastIndexOf("/") + 1, url_xy.length()); } if (db != null) { databaseName = StringTools.replaceIgnoreCase(databaseName, "self", db); } } logger.debug("databaseName:" + databaseName); dataMap.put(DBConfiguration.HOST, host); dataMap.put(DBConfiguration.DATABASE, databaseName); props.put(DBConfiguration.HOST, host); props.put(DBConfiguration.DATABASE, databaseName); props.put(DBConfiguration.JDBC_USER, rs.getString(3)); props.put(DBConfiguration.JDBC_PASSWORD, rs.getString(4)); logger.debug(dataMap); logger.debug("url:" + old_url); String url = ExpressionTools.evaluate(old_url, dataMap); props.put(DBConfiguration.JDBC_URL, url); host = StringTools.replace(host, ".", "_"); props.put(DBConfiguration.JDBC_NAME, name); logger.debug("jdbc url:" + props.getProperty(DBConfiguration.JDBC_URL)); /** * ??? */ if (DBConnectionFactory.checkConnection(props)) { DBConfiguration.addDataSourceProperties(name, props); logger.debug("SQL......"); DBUpdateThread thread = new DBUpdateThread(props); ThreadFactory.run(thread); } } } } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } finally { JdbcUtils.close(rs); JdbcUtils.close(stmt); JdbcUtils.close(conn); } } } } }
From source file:com.glaf.core.startup.MultiDBNativeCmdStartup.java
public void startup(ServletContext context, String text) { logger.debug("-----------------MultiDBNativeCmdStartup.startup----------------"); if (StringUtils.isNotEmpty(text)) { JSONObject json = JSON.parseObject(text); logger.debug(json.toJSONString()); String sql = json.getString("sql"); String dbName = json.getString("dbName"); String cmd = json.getString("cmd"); if (StringUtils.isNotEmpty(sql) && !DBUtils.isLegalQuerySql(sql)) { logger.error(sql);/*from ww w . j av a 2 s .c o m*/ throw new RuntimeException(" SQL statement illegal "); } if (StringUtils.isNotEmpty(sql) && StringUtils.isNotEmpty(dbName) && StringUtils.isNotEmpty(cmd)) { Properties defaultProps = DBConfiguration.getTemplateProperties(Environment.DEFAULT_SYSTEM_NAME); Properties props = DBConfiguration.getTemplateProperties(dbName); logger.debug(dbName + " props:" + props); if (props != null && StringUtils.isNotEmpty(props.getProperty(DBConfiguration.JDBC_URL))) { String old_url = props.getProperty(DBConfiguration.JDBC_URL); Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { conn = DBConnectionFactory.getConnection(); if (conn != null) { DBNativeCmdThread t = new DBNativeCmdThread(cmd, defaultProps); ThreadFactory.run(t); stmt = conn.prepareStatement(sql); rs = stmt.executeQuery(); while (rs.next()) { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); Enumeration<?> e = props.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = props.getProperty(key); dataMap.put(key, value); } String host = rs.getString(1); String databaseName = rs.getString(2); String user = rs.getString(3); String password = rs.getString(4); String name = rs.getString(5); if (databaseName.indexOf("$") != -1) { String url_xy = defaultProps.getProperty(DBConfiguration.JDBC_URL); String driver = defaultProps.getProperty(DBConfiguration.JDBC_DRIVER); String db = null; if (StringUtils.equals(driver, "com.microsoft.sqlserver.jdbc.SQLServerDriver")) { db = url_xy.substring(url_xy.lastIndexOf("=") + 1, url_xy.length()); } else if (StringUtils.equals(driver, "net.sourceforge.jtds.jdbc.Driver")) { db = url_xy.substring(url_xy.lastIndexOf("/") + 1, url_xy.length()); } if (db != null) { databaseName = StringTools.replaceIgnoreCase(databaseName, "self", db); } } logger.debug("databaseName:" + databaseName); dataMap.put(DBConfiguration.HOST, host); dataMap.put(DBConfiguration.DATABASE, databaseName); props.put(DBConfiguration.JDBC_USER, rs.getString(3)); props.put(DBConfiguration.JDBC_PASSWORD, rs.getString(4)); props.put(DBConfiguration.HOST, host); props.put(DBConfiguration.DATABASE, databaseName); props.put(DBConfiguration.JDBC_USER, user); props.put(DBConfiguration.JDBC_PASSWORD, password); logger.debug(dataMap); String url = ExpressionTools.evaluate(old_url, dataMap); props.put(DBConfiguration.JDBC_URL, url); host = StringTools.replace(host, ".", "_"); props.put(DBConfiguration.JDBC_NAME, name); /** * ??? */ if (DBConnectionFactory.checkConnection(props)) { logger.debug("......"); DBNativeCmdThread thread = new DBNativeCmdThread(cmd, props); ThreadFactory.run(thread); } } } } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } finally { JdbcUtils.close(rs); JdbcUtils.close(stmt); JdbcUtils.close(conn); } } } } }
From source file:org.pentaho.reporting.ui.datasources.mondrian.MondrianDataSourceEditor.java
protected void configureConnection(final AbstractMDXDataFactory dataFactory) { final CubeFileProvider cubeFileProvider = ClassicEngineBoot.getInstance().getObjectFactory() .get(CubeFileProvider.class); cubeFileProvider.setDesignTimeFile(getSchemaFileName()); cubeFileProvider.setCubeConnectionName(cubeConnectionNameField.getText()); dataFactory.setCubeFileProvider(cubeFileProvider); dataFactory.setRole(roleText);/*from w ww . j ava 2 s .c o m*/ dataFactory.setRoleField(roleField); dataFactory.setJdbcUser(jdbcUserText); dataFactory.setJdbcUserField(jdbcUserField); dataFactory.setJdbcPassword(jdbcPasswordText); dataFactory.setJdbcPasswordField(jdbcPasswordField); dataFactory.setBaseConnectionProperties(mondrianProperties); final JdbcConnectionDefinition connectionDefinition = (JdbcConnectionDefinition) getDialogModel() .getConnections().getSelectedItem(); dataFactory.setDesignTimeName(connectionDefinition.getName()); if (connectionDefinition instanceof DriverConnectionDefinition) { final DriverConnectionDefinition dcd = (DriverConnectionDefinition) connectionDefinition; final DriverDataSourceProvider dataSourceProvider = new DriverDataSourceProvider(); dataSourceProvider.setUrl(dcd.getConnectionString()); dataSourceProvider.setDriver(dcd.getDriverClass()); final Properties properties = dcd.getProperties(); final Enumeration keys = properties.keys(); while (keys.hasMoreElements()) { final String key = (String) keys.nextElement(); dataSourceProvider.setProperty(key, properties.getProperty(key)); } dataFactory.setDataSourceProvider(dataSourceProvider); } else { final JndiConnectionDefinition jcd = (JndiConnectionDefinition) connectionDefinition; dataFactory.setDataSourceProvider(new JndiDataSourceProvider(jcd.getJndiName())); } }
From source file:org.pentaho.reporting.tools.configeditor.ConfigEditor.java
/** * Loads the report configuration from a user selectable report properties file. *///from w w w . j ava 2 s . com protected void load() { setStatusText(resources.getString("ConfigEditor.USER_LOADING_FILE")); //$NON-NLS-1$ if (fileChooser == null) { fileChooser = new JFileChooser(); final FilesystemFilter filter = new FilesystemFilter(ConfigEditor.PROPERTIES_FILE_EXTENSION, resources.getString("config-editor.file-description.properties")); //$NON-NLS-1$ fileChooser.addChoosableFileFilter(filter); fileChooser.setMultiSelectionEnabled(false); } final int option = fileChooser.showOpenDialog(this); if (option == JFileChooser.APPROVE_OPTION) { final File selFile = fileChooser.getSelectedFile(); String selFileName = selFile.getAbsolutePath(); // Test if ends on .properties if (StringUtils.endsWithIgnoreCase(selFileName, ConfigEditor.PROPERTIES_FILE_EXTENSION) == false) { selFileName = selFileName + ConfigEditor.PROPERTIES_FILE_EXTENSION; } final Properties prop = new Properties(); try { final InputStream in = new BufferedInputStream(new FileInputStream(selFileName)); try { prop.load(in); } finally { in.close(); } } catch (IOException ioe) { ConfigEditor.logger.debug( resources.getString("ConfigEditor.ERROR_0003_FAILED_TO_LOAD_PROPERTIES", ioe.toString()), ioe); //$NON-NLS-1$ setStatusText( resources.getString("ConfigEditor.ERROR_0003_FAILED_TO_LOAD_PROPERTIES", ioe.getMessage())); //$NON-NLS-1$ return; } reset(); final Enumeration keys = prop.keys(); while (keys.hasMoreElements()) { final String key = (String) keys.nextElement(); final String value = prop.getProperty(key); configuration.setConfigProperty(key, value); } editorPane.updateConfiguration(configuration); setStatusText(resources.getString("ConfigEditor.USER_LOAD_PROPS_COMPLETE")); //$NON-NLS-1$ } }
From source file:org.sakaiproject.component.impl.BasicConfigurationService.java
/** * INTERNAL/*from w w w. j a v a 2s .c o m*/ * Adds a set of config items using the data from a set of properties * @param p the properties * @param source the source name */ protected void addProperties(Properties p, String source) { if (p != null) { if (source == null || "".equals(source)) { source = UNKNOWN; } M_log.info("Adding " + p.size() + " properties from " + source); for (Enumeration<Object> e = p.keys(); e.hasMoreElements(); /**/) { String name = (String) e.nextElement(); String value = p.getProperty(name); // KNL-1361 - Add support for system-scoped properties if (name != null && name.endsWith(SAKAI_SYSTEM_PROPERTY_SUFFIX) && name.length() > SAKAI_SYSTEM_PROPERTY_SUFFIX.length()) { name = name.substring(0, name.length() - SAKAI_SYSTEM_PROPERTY_SUFFIX.length()); System.setProperty(name, value); M_log.info("Promoted to system property: " + name); continue; } ConfigItemImpl ci = new ConfigItemImpl(name, value, source); this.addConfigItem(ci, source); } } }
From source file:se.vgregion.usdservice.USDServiceImpl.java
@Override public String createRequest(Properties requestParameters, String userId, Collection<Attachment> attachments) { int sessionID = 0; try {/*from w ww . j av a 2 s . c o m*/ sessionID = getUSDWebService().login(wsUser, wsPassword); String contactHandle = lookupContactHandle(userId, sessionID); if (contactHandle == null) { // Use the wsUser as fallback if the user is unknown contactHandle = lookupContactHandle(wsUser, sessionID); } requestParameters.setProperty("customer", contactHandle); List<String> lAttributes = new ArrayList<String>(); List<String> lAttributeValues = new ArrayList<String>(); for (Enumeration<Object> e = requestParameters.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); lAttributes.add(key); lAttributeValues.add(key); lAttributeValues.add(requestParameters.getProperty(key)); } List<String> properties = Collections.<String>emptyList(); Holder<String> reqHandle = new Holder<String>(""); Holder<String> reqNumber = new Holder<String>(""); String template = ""; Holder<String> result = new Holder<String>(); getUSDWebService().createRequest(sessionID, contactHandle, toArrayOfString(lAttributeValues), toArrayOfString(properties), template, toArrayOfString(lAttributes), reqHandle, reqNumber, result); String handle = null; try { handle = extractHandle(result.toString()); } catch (Exception e) { throw new RuntimeException("Error parsing handle to USD incident from xml response...\n" + result, e); } if (!StringUtils.isEmpty(handle)) { for (Attachment attachment : attachments) { int i = 0; try { createAttachment(sessionID, wsAttachmentRepHandle, handle, "Attachment " + i, attachment); } catch (Exception e) { log.error("Failed to create attachment in USD [" + attachment.getFilename() + "]"); } i++; } } return result.toString(); } finally { getUSDWebService().logout(sessionID); } }