List of usage examples for java.util Properties propertyNames
public Enumeration<?> propertyNames()
From source file:org.nuxeo.theme.editor.Main.java
@POST @Path("expand_css_categories") @SuppressWarnings("unchecked") public void expandCssCategories() { Properties cssStyleCategories = org.nuxeo.theme.editor.Utils.getCssStyleCategories(); List<String> allCssCategories = (List<String>) Collections.list(cssStyleCategories.propertyNames()); SessionManager.setSelectedCssCategories(allCssCategories); }
From source file:org.nuxeo.launcher.config.ConfigurationGenerator.java
/** * Check for deprecated parameters/*from w w w. jav a2s . c o m*/ * * @param properties * @since 5.6 */ protected void checkForDeprecatedParameters(Properties properties) { serverConfigurator.addServerSpecificParameters(parametersMigration); @SuppressWarnings("rawtypes") Enumeration userEnum = properties.propertyNames(); while (userEnum.hasMoreElements()) { String key = (String) userEnum.nextElement(); if (parametersMigration.containsKey(key)) { String value = properties.getProperty(key); properties.setProperty(parametersMigration.get(key), value); // Don't remove the deprecated key yet - more // warnings but old things should keep working // properties.remove(key); if (!hideDeprecationWarnings) { log.warn("Parameter " + key + " is deprecated - please use " + parametersMigration.get(key) + " instead"); } } } }
From source file:org.jboss.dashboard.factory.Component.java
void addProperties(Properties properties, String fileName) { String declaredClass = properties.getProperty(SPECIAL_PROPERTY_PREFFIX + CLASS_PROPERTY); String declaredScope = properties.getProperty(SPECIAL_PROPERTY_PREFFIX + SCOPE_PROPERTY); String declaredDescr = properties.getProperty(SPECIAL_PROPERTY_PREFFIX + DESC_PROPERTY); String declaredEnabled = properties.getProperty(SPECIAL_PROPERTY_PREFFIX + ENABLED_PROPERTY); String declaredAlias = properties.getProperty(SPECIAL_PROPERTY_PREFFIX + ALIAS_PROPERTY); if (declaredClass != null && clazz != null) { try {/* w w w . j av a 2 s . c o m*/ Class currentClass = Class.forName(clazz); Class newClass = Class.forName(declaredClass); if (!currentClass.isAssignableFrom(newClass)) { log.warn("Assigning class " + declaredClass + " to component " + name + " may cause errors. " + "Default system class is " + clazz + ", new class is not descendant."); } } catch (ClassNotFoundException e) { log.error("Error:", e); } } clazz = declaredClass == null ? clazz : declaredClass; alias = declaredAlias == null ? alias : declaredAlias; scope = declaredScope == null ? scope : declaredScope; description = declaredDescr == null ? description : declaredDescr; enabled = declaredEnabled == null ? enabled : Boolean.valueOf(declaredEnabled).booleanValue(); for (Enumeration en = properties.propertyNames(); en.hasMoreElements();) { String propertyName = (String) en.nextElement(); if (propertyName.startsWith(SPECIAL_PROPERTY_PREFFIX)) { continue; } if (!isValidPropertyName(propertyName)) { log.error("Ignoring invalid property name " + propertyName + " in component " + name); continue; } String propertyValue = properties.getProperty(propertyName); storeProperty(propertyName, propertyValue); } propertiesFilesAdded.add(fileName); }
From source file:org.sakaiproject.util.BaseDbFlatStorage.java
/** * The transaction code for writing properties. * //from ww w . j a va2s.c om * @param r * The resource for which properties are to be written. */ protected void writePropertiesTx(String table, String idField, Object id, String extraIdField, String extraId, Properties props, boolean deleteFirst) { String statement; Object[] fields; if (deleteFirst) { // delete what's there statement = flatStorageSql.getDeleteSql(table, idField); fields = new Object[1]; fields[0] = id; // process the delete statement m_sql.dbWrite(statement, fields); } // the SQL statement statement = flatStorageSql.getInsertSql(table, idField, extraIdField); fields = new Object[((extraIdField != null) ? 4 : 3)]; fields[0] = id; // process each property for (Enumeration i = props.propertyNames(); i.hasMoreElements();) { String name = (String) i.nextElement(); String value = props.getProperty(name); fields[1] = name; fields[2] = value; if (extraIdField != null) { fields[3] = extraId; } // don't write it if there's only an empty string for value if (!StringUtils.isEmpty(value)) { m_sql.dbWrite(statement, fields); } } }
From source file:org.oscarehr.common.web.PregnancyAction.java
public ActionForward saveFormAjax(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { int newID = 0; FrmRecord rec = null;//from w ww. j av a 2 s. c o m JSONObject jsonObj = null; try { FrmRecordFactory recorder = new FrmRecordFactory(); rec = recorder.factory(request.getParameter("form_class")); Properties props = new Properties(); boolean bMulPage = request.getParameter("c_lastVisited") != null ? true : false; String name; if (bMulPage) { String curPageNum = request.getParameter("c_lastVisited"); String commonField = request.getParameter("commonField") != null ? request.getParameter("commonField") : "&'"; curPageNum = curPageNum.length() > 3 ? ("" + curPageNum.charAt(0)) : curPageNum; //copy an old record props = rec.getFormRecord(Integer.parseInt(request.getParameter("demographic_no")), Integer.parseInt(request.getParameter("formId"))); //empty the current page Properties currentParam = new Properties(); for (Enumeration varEnum = request.getParameterNames(); varEnum.hasMoreElements();) { name = (String) varEnum.nextElement(); currentParam.setProperty(name, ""); } for (Enumeration varEnum = props.propertyNames(); varEnum.hasMoreElements();) { name = (String) varEnum.nextElement(); // kick off the current page elements, commonField on the current page if (name.startsWith(curPageNum + "_") || (name.startsWith(commonField) && currentParam.containsKey(name))) { props.remove(name); } } } //update the current record for (Enumeration varEnum = request.getParameterNames(); varEnum.hasMoreElements();) { name = (String) varEnum.nextElement(); props.setProperty(name, request.getParameter(name)); } props.setProperty("provider_no", (String) request.getSession().getAttribute("user")); newID = rec.saveFormRecord(props); String ip = request.getRemoteAddr(); LogAction.addLog((String) request.getSession().getAttribute("user"), LogConst.ADD, request.getParameter("form_class"), "" + newID, ip, request.getParameter("demographic_no")); jsonObj = JSONObject.fromObject(new LabelValueBean("result", String.valueOf(newID))); } catch (Exception ex) { MiscUtils.getLogger().error("error", ex); jsonObj = JSONObject.fromObject(new LabelValueBean("result", "error")); } response.getWriter().print(jsonObj.toString()); return null; }
From source file:com.masse.mvn.plugin.BuildJsonFromPropertiesMojo.java
private void buidJsonTargetFile(File inputFile) throws MojoExecutionException { String inputFileString = inputFile.getAbsolutePath() .substring(inputFile.getAbsolutePath().lastIndexOf(SystemUtils.IS_OS_LINUX ? "/" : "\\") + 1); String outputFileString = jsonTargetPath + new String(SystemUtils.IS_OS_LINUX ? "/" : "\\") + inputFileString.substring(0, inputFileString.lastIndexOf(".")) + ".json"; getLog().info("Process file " + inputFileString); if (!inputFile.exists()) { throw new MojoExecutionException("Properties file " + inputFile + " not found !"); }/*from w w w .jav a 2 s . c om*/ TreeMap<String, PropertiesToJson> propertiesJson = new TreeMap<String, PropertiesToJson>(); Properties props = new Properties(); try { FileInputStream inputFileStream = new FileInputStream(inputFile); BufferedReader inputFileBufferedReader = new BufferedReader( new InputStreamReader(inputFileStream, "UTF-8")); File outputTempFile = new File(inputFileString + "-temp"); FileOutputStream outputTempFileStream = new FileOutputStream(outputTempFile); OutputStreamWriter outputTempFileStrWriter = new OutputStreamWriter(outputTempFileStream, "UTF-8"); BufferedWriter writer = new BufferedWriter(outputTempFileStrWriter); String line = ""; while ((line = inputFileBufferedReader.readLine()) != null) { if (!(line.isEmpty() || line.trim().equals("") || line.trim().equals("\n"))) { if (line.startsWith("#")) { continue; } int equalsIndex = line.indexOf("="); if (equalsIndex < 0) { continue; } line = line.replace("\"", """); line = line.replace("\\", "\\\\\\\\"); line = line.replace(" ", ""); writer.write(line + "\n"); } } writer.close(); outputTempFileStrWriter.close(); outputTempFileStream.close(); inputFileBufferedReader.close(); inputFileStream.close(); FileInputStream fis = new FileInputStream(outputTempFile); InputStreamReader isr = new InputStreamReader(fis, "UTF-8"); props.load(isr); isr.close(); fis.close(); outputTempFile.delete(); @SuppressWarnings("rawtypes") Enumeration e = props.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String rootKey = key.split("=")[0]; propertiesJson.put(rootKey, createMap(propertiesJson, key, props.getProperty(key), 1)); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } StringBuffer sb = new StringBuffer(); sb.append(PrintJsonTree(propertiesJson, 0, false)); File outputFile = new File(outputFileString); try { FileOutputStream fos = new FileOutputStream(outputFile); OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8"); BufferedWriter bwr = new BufferedWriter(osw); //write contents of StringBuffer to a file bwr.write(sb.toString()); //flush the stream bwr.flush(); //close the stream bwr.close(); osw.close(); fos.close(); } catch (IOException e) { getLog().error(e); throw new MojoExecutionException("json file creation error", e); } }
From source file:org.jboss.processFlow.knowledgeService.BaseKnowledgeSessionBean.java
/****************************************************************************** * ************* WorkItemHandler Management *********/ public String printWorkItemHandlers() { StringBuilder sBuilder = new StringBuilder("Programmatically Loaded Work Item Handlers :"); for (String name : programmaticallyLoadedWorkItemHandlers.keySet()) { sBuilder.append("\n\t"); sBuilder.append(name);//from w ww . j a v a 2s . com sBuilder.append(" : "); sBuilder.append(programmaticallyLoadedWorkItemHandlers.get(name)); } sBuilder.append("\nWork Item Handlers loaded from drools session template:"); SessionTemplate sTemplate = newSessionTemplate(null); if (sTemplate != null && (sTemplate.getWorkItemHandlers() != null)) { for (Map.Entry<?, ?> entry : sTemplate.getWorkItemHandlers().entrySet()) { Class wiClass = entry.getValue().getClass(); sBuilder.append("\n\t"); sBuilder.append(entry.getKey()); sBuilder.append(" : "); sBuilder.append(wiClass.getClass()); } } else { sBuilder.append("\n\tsessionTemplate not instantiated or is empty... check previous exceptions"); } sBuilder.append("\nConfiguration Loaded Work Item Handlers :"); SessionConfiguration ksConfig = (SessionConfiguration) KnowledgeBaseFactory .newKnowledgeSessionConfiguration(ksconfigProperties); try { Map<String, WorkItemHandler> wiHandlers = ksConfig.getWorkItemHandlers(); if (wiHandlers.size() == 0) { sBuilder.append("\n\t no work item handlers defined"); Properties badProps = createPropsFromDroolsSessionConf(); if (badProps == null) sBuilder.append("\n\tunable to locate " + DROOLS_SESSION_CONF_PATH); else sBuilder.append("\n\tlocated" + DROOLS_SESSION_CONF_PATH); } else { for (String name : wiHandlers.keySet()) { sBuilder.append("\n\t"); sBuilder.append(name); sBuilder.append(" : "); Class wiClass = wiHandlers.get(name).getClass(); sBuilder.append(wiClass); } } } catch (NullPointerException x) { sBuilder.append( "\n\tError intializing at least one of the configured work item handlers via drools.session.conf.\n\tEnsure all space delimited work item handlers listed in drools.session.conf exist on the classpath"); Properties badProps = createPropsFromDroolsSessionConf(); if (badProps == null) { sBuilder.append("\n\tunable to locate " + DROOLS_SESSION_CONF_PATH); } else { try { Enumeration badEnums = badProps.propertyNames(); while (badEnums.hasMoreElements()) { String handlerConfName = (String) badEnums.nextElement(); if (DROOLS_WORK_ITEM_HANDLERS.equals(handlerConfName)) { String[] badHandlerNames = ((String) badProps.get(handlerConfName)).split("\\s"); for (String badHandlerName : badHandlerNames) { sBuilder.append("\n\t\t"); sBuilder.append(badHandlerName); InputStream iStream = this.getClass() .getResourceAsStream("/META-INF/" + badHandlerName); if (iStream != null) { sBuilder.append("\t : found on classpath"); iStream.close(); } else { sBuilder.append("\t : NOT FOUND on classpath !!!!! "); } } } } } catch (Exception y) { y.printStackTrace(); } } } catch (org.mvel2.CompileException x) { sBuilder.append("\n\t located " + DROOLS_SESSION_CONF_PATH); sBuilder.append( "\n\t however, following ClassNotFoundException encountered when instantiating defined work item handlers : \n\t\t"); sBuilder.append(x.getLocalizedMessage()); } sBuilder.append("\n"); return sBuilder.toString(); }
From source file:org.apache.wiki.WikiEngine.java
/** * Returns a collection of all image types that get inlined. * * @return A Collection of Strings with a regexp pattern. *//* w w w .jav a 2s. c om*/ public Collection<String> getAllInlinedImagePatterns() { Properties props = getWikiProperties(); ArrayList<String> ptrnlist = new ArrayList<String>(); for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); if (name.startsWith(PROP_INLINEIMAGEPTRN)) { String ptrn = TextUtil.getStringProperty(props, name, null); ptrnlist.add(ptrn); } } if (ptrnlist.size() == 0) { ptrnlist.add(DEFAULT_INLINEPATTERN); } return ptrnlist; }
From source file:org.hyperic.hq.common.server.session.ServerConfigManagerImpl.java
/** * Set the server Configuration/* ww w.j av a 2s . c o m*/ * @param prefix The config prefix to use when setting properties. The * prefix is used for namespace protection and property scoping. * @param newProps The Properties to set. * @throws ConfigPropertyException - if the props object is missing a key * that's currently in the database * */ @Transactional public void setConfig(AuthzSubject subject, String prefix, Properties newProps) throws ApplicationException, ConfigPropertyException { Properties tempProps = new Properties(); tempProps.putAll(newProps); // get all properties Collection<ConfigProperty> allProps = serverConfigCache.getProps(prefix); createChangeAudits(subject, allProps, newProps); for (ConfigProperty configProp : allProps) { // check if the props object has a key matching String key = configProp.getKey(); if (newProps.containsKey(key)) { tempProps.remove(key); String propValue = (String) newProps.get(key); // delete null values from prefixed properties if (prefix != null && (propValue == null || propValue.equals("NULL"))) { configPropertyDAO.remove(configProp); serverConfigCache.remove(key); } else { // non-prefixed properties never get deleted. configProp.setValue(propValue); serverConfigCache.put(key, propValue); // Fix Bug 1285064/HQ-4793: Save the property in DB configPropertyDAO.save(configProp); if (HQConstants.HQGUID.equals(key)) { // Came from read only method so need to flush the session configPropertyDAO.flushSession(); if (log.isDebugEnabled()) log.debug("Saving HQ-GUID in DB [" + propValue + "]"); } } } else if (prefix == null) { // Bomb out if props are missing for non-prefixed properties throw new ConfigPropertyException("Updated configuration missing required key: " + key); } } // create properties that are still left in tempProps if (tempProps.size() > 0) { Enumeration propsToAdd = tempProps.propertyNames(); while (propsToAdd.hasMoreElements()) { String key = (String) propsToAdd.nextElement(); String propValue = tempProps.getProperty(key); // create the new property configPropertyDAO.create(prefix, key, propValue, propValue); serverConfigCache.put(key, propValue); } } }
From source file:org.apache.flume.channel.jdbc.impl.JdbcChannelProviderImpl.java
/** /*from w ww . ja v a 2 s . com*/ * Initializes the datasource and the underlying connection pool. * @param properties */ private void initializeDataSource(Context context) { driverClassName = getConfigurationString(context, ConfigurationConstants.CONFIG_JDBC_DRIVER_CLASS, ConfigurationConstants.OLD_CONFIG_JDBC_DRIVER_CLASS, null); connectUrl = getConfigurationString(context, ConfigurationConstants.CONFIG_URL, ConfigurationConstants.OLD_CONFIG_URL, null); String userName = getConfigurationString(context, ConfigurationConstants.CONFIG_USERNAME, ConfigurationConstants.OLD_CONFIG_USERNAME, null); String password = getConfigurationString(context, ConfigurationConstants.CONFIG_PASSWORD, ConfigurationConstants.OLD_CONFIG_PASSWORD, null); String jdbcPropertiesFile = getConfigurationString(context, ConfigurationConstants.CONFIG_JDBC_PROPS_FILE, ConfigurationConstants.OLD_CONFIG_JDBC_PROPS_FILE, null); String dbTypeName = getConfigurationString(context, ConfigurationConstants.CONFIG_DATABASE_TYPE, ConfigurationConstants.OLD_CONFIG_DATABASE_TYPE, null); // If connect URL is not specified, use embedded Derby if (connectUrl == null || connectUrl.trim().length() == 0) { LOGGER.warn("No connection URL specified. " + "Using embedded derby database instance."); driverClassName = DEFAULT_DRIVER_CLASSNAME; userName = DEFAULT_USERNAME; password = DEFAULT_PASSWORD; dbTypeName = DEFAULT_DBTYPE; String homePath = System.getProperty("user.home").replace('\\', '/'); String defaultDbDir = homePath + "/.flume/jdbc-channel"; File dbDir = new File(defaultDbDir); String canonicalDbDirPath = null; try { canonicalDbDirPath = dbDir.getCanonicalPath(); } catch (IOException ex) { throw new JdbcChannelException("Unable to find canonical path of dir: " + defaultDbDir, ex); } if (!dbDir.exists()) { if (!dbDir.mkdirs()) { throw new JdbcChannelException("unable to create directory: " + canonicalDbDirPath); } } connectUrl = "jdbc:derby:" + canonicalDbDirPath + "/db;create=true"; // No jdbc properties file will be used jdbcPropertiesFile = null; LOGGER.warn("Overriding values for - driver: " + driverClassName + ", user: " + userName + "connectUrl: " + connectUrl + ", jdbc properties file: " + jdbcPropertiesFile + ", dbtype: " + dbTypeName); } // Right now only Derby and MySQL supported databaseType = DatabaseType.getByName(dbTypeName); switch (databaseType) { case DERBY: case MYSQL: break; default: throw new JdbcChannelException("Database " + databaseType + " not supported at this time"); } // Register driver if (driverClassName == null || driverClassName.trim().length() == 0) { throw new JdbcChannelException("No jdbc driver specified"); } try { Class.forName(driverClassName); } catch (ClassNotFoundException ex) { throw new JdbcChannelException("Unable to load driver: " + driverClassName, ex); } // JDBC Properties Properties jdbcProps = new Properties(); if (jdbcPropertiesFile != null && jdbcPropertiesFile.trim().length() > 0) { File jdbcPropsFile = new File(jdbcPropertiesFile.trim()); if (!jdbcPropsFile.exists()) { throw new JdbcChannelException("Jdbc properties file does not exist: " + jdbcPropertiesFile); } InputStream inStream = null; try { inStream = new FileInputStream(jdbcPropsFile); jdbcProps.load(inStream); } catch (IOException ex) { throw new JdbcChannelException( "Unable to load jdbc properties " + "from file: " + jdbcPropertiesFile, ex); } finally { if (inStream != null) { try { inStream.close(); } catch (IOException ex) { LOGGER.error("Unable to close file: " + jdbcPropertiesFile, ex); } } } } if (userName != null) { Object oldUser = jdbcProps.put("user", userName); if (oldUser != null) { LOGGER.warn("Overriding user from: " + oldUser + " to: " + userName); } } if (password != null) { Object oldPass = jdbcProps.put("password", password); if (oldPass != null) { LOGGER.warn( "Overriding password from the jdbc properties with " + " the one specified explicitly."); } } if (LOGGER.isDebugEnabled()) { StringBuilder sb = new StringBuilder("JDBC Properties {"); boolean first = true; Enumeration<?> propertyKeys = jdbcProps.propertyNames(); while (propertyKeys.hasMoreElements()) { if (first) { first = false; } else { sb.append(", "); } String key = (String) propertyKeys.nextElement(); sb.append(key).append("="); if (key.equalsIgnoreCase("password")) { sb.append("*******"); } else { sb.append(jdbcProps.get(key)); } } sb.append("}"); LOGGER.debug(sb.toString()); } // Transaction Isolation String txIsolation = getConfigurationString(context, ConfigurationConstants.CONFIG_TX_ISOLATION_LEVEL, ConfigurationConstants.OLD_CONFIG_TX_ISOLATION_LEVEL, TransactionIsolation.READ_COMMITTED.getName()); TransactionIsolation txIsolationLevel = TransactionIsolation.getByName(txIsolation); LOGGER.debug("Transaction isolation will be set to: " + txIsolationLevel); // Setup Datasource ConnectionFactory connFactory = new DriverManagerConnectionFactory(connectUrl, jdbcProps); connectionPool = new GenericObjectPool(); String maxActiveConnections = getConfigurationString(context, ConfigurationConstants.CONFIG_MAX_CONNECTIONS, ConfigurationConstants.OLD_CONFIG_MAX_CONNECTIONS, "10"); int maxActive = 10; if (maxActiveConnections != null && maxActiveConnections.length() > 0) { try { maxActive = Integer.parseInt(maxActiveConnections); } catch (NumberFormatException nfe) { LOGGER.warn("Max active connections has invalid value: " + maxActiveConnections + ", Using default: " + maxActive); } } LOGGER.debug("Max active connections for the pool: " + maxActive); connectionPool.setMaxActive(maxActive); statementPool = new GenericKeyedObjectPoolFactory(null); // Creating the factory instance automatically wires the connection pool new PoolableConnectionFactory(connFactory, connectionPool, statementPool, databaseType.getValidationQuery(), false, false, txIsolationLevel.getCode()); dataSource = new PoolingDataSource(connectionPool); txFactory = new JdbcTransactionFactory(dataSource, this); }