List of usage examples for org.apache.commons.configuration PropertiesConfiguration getProperty
public Object getProperty(String key)
From source file:net.sf.mpaxs.spi.server.settings.Settings.java
private void addConfigFile(String path) { if (path != null) { PropertiesConfiguration prop; try {/* w ww. j a va2 s. c om*/ prop = new PropertiesConfiguration(path); Iterator keyIter = prop.getKeys(); while (keyIter.hasNext()) { Object obj = keyIter.next(); String s = (String) obj; config.setProperty(s, prop.getProperty(s)); } } catch (ConfigurationException ex) { Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:eu.trentorise.game.managers.DroolsEngine.java
private StatelessKieSession loadGameConstants(StatelessKieSession kSession, String gameId) { // load game constants InputStream constantsFileStream = null; Game g = gameSrv.loadGameDefinitionById(gameId); if (g != null && g.getRules() != null) { for (String ruleUrl : g.getRules()) { Rule r = gameSrv.loadRule(gameId, ruleUrl); if ((r != null && r.getName() != null && r.getName().equals("constants")) || r instanceof UrlRule && ((UrlRule) r).getUrl().contains("constants")) { try { constantsFileStream = r.getInputStream(); } catch (IOException e) { logger.error("Exception loading constants file", e); }//from w w w .ja v a 2s .c o m } } } if (constantsFileStream != null) { try { PropertiesConfiguration constants = new PropertiesConfiguration(); constants.load(constantsFileStream); constants.setListDelimiter(','); logger.debug("constants file loaded for game {}", gameId); Iterator<String> constantsIter = constants.getKeys(); while (constantsIter.hasNext()) { String constant = constantsIter.next(); kSession.setGlobal(constant, numberConversion(constants.getProperty(constant))); logger.debug("constant {} loaded", constant); } } catch (ConfigurationException e) { logger.error("constants loading exception"); } } else { logger.info("Rule constants file not found"); } return kSession; }
From source file:com.aurel.track.dbase.MigrateTo37.java
private Connection getConnection() { try {/*from www.j a v a 2 s . c om*/ PropertiesConfiguration tcfg = new PropertiesConfiguration(); tcfg = HandleHome.getTorqueProperties(servletContext, false); String jdbcURL = (String) tcfg.getProperty("torque.dsfactory.track.connection.url"); String jdbcUser = (String) tcfg.getProperty("torque.dsfactory.track.connection.user"); String jdbcPassword = (String) tcfg.getProperty("torque.dsfactory.track.connection.password"); String jdbcDriver = (String) tcfg.getProperty("torque.dsfactory.track.connection.driver"); System.err.println("Using this username: " + jdbcUser); System.err.println("Using this password: " + jdbcPassword != null); System.err.println("Using this JDBC URL: " + jdbcURL); try { Class.forName(jdbcDriver); } catch (ClassNotFoundException e) { System.err.println("Loading the jdbcDriver " + jdbcDriver + " failed with " + e.getMessage()); System.err.println(ExceptionUtils.getStackTrace(e)); } // establish a connection return DriverManager.getConnection(jdbcURL, jdbcUser, jdbcPassword); } catch (Exception e) { System.err.println("Getting the JDBC connection failed with " + e.getMessage()); System.err.println(ExceptionUtils.getStackTrace(e)); } return null; }
From source file:com.aurel.track.ApplicationStarter.java
private void printSystemInfo() { LOGGER.info("Java: " + System.getProperty("java.vendor") + " " + System.getProperty("java.version")); LOGGER.info("Operating System: " + System.getProperty("os.name") + " " + System.getProperty("os.arch")); Locale loc = Locale.getDefault(); LOGGER.info("Default locale: " + loc.getDisplayName()); ServletContext application = ApplicationBean.getInstance().getServletContext(); try {/* www. jav a 2 s. c om*/ LOGGER.info("Servlet real path: " + application.getRealPath(File.separator)); } catch (Exception ex) { LOGGER.error("Error trying to obtain getRealPath()"); } LOGGER.info("Servlet container: " + application.getServerInfo()); Connection conn = null; try { PropertiesConfiguration pc = ApplicationBean.getInstance().getDbConfig(); LOGGER.info("Configured database type: " + pc.getProperty("torque.database.track.adapter")); LOGGER.info( "Configured database driver: " + pc.getProperty("torque.dsfactory.track.connection.driver")); LOGGER.info("Configured JDBC URL: " + pc.getProperty("torque.dsfactory.track.connection.url")); conn = Torque.getConnection(BaseTSitePeer.DATABASE_NAME); DatabaseMetaData dbm = conn.getMetaData(); LOGGER.info("Database type: " + dbm.getDatabaseProductName() + " " + dbm.getDatabaseProductVersion()); LOGGER.info("Driver info: " + dbm.getDriverName() + " " + dbm.getDriverVersion()); Statement stmt = conn.createStatement(); Date d1 = new Date(); stmt.executeQuery("SELECT * FROM TSTATE"); Date d2 = new Date(); stmt.close(); LOGGER.info("Database test query done in " + (d2.getTime() - d1.getTime()) + " milliseconds "); } catch (Exception e) { System.err.println("Problem retrieving meta data"); LOGGER.error("Problem retrieving meta data"); } finally { if (conn != null) { Torque.closeConnection(conn); } } }
From source file:com.aurel.track.ApplicationStarter.java
private void setVersionFromVersionProperties(ServletContext servletContext) { ApplicationBean applicationBean = ApplicationBean.getInstance(); String appTypeString = ""; Integer appType = -1;//from ww w .j a va 2 s . c om String theVersion = ""; String theBuild = ""; String theVersionDate = ""; Integer theVersionNo = 370; try { URL versionURL = servletContext.getResource("/WEB-INF/Version.properties"); PropertiesConfiguration vcfg = new PropertiesConfiguration(); InputStream in = versionURL.openStream(); vcfg.load(in); theVersion = (String) vcfg.getProperty("version"); theBuild = (String) vcfg.getProperty("build"); if (theVersion == null) { theVersion = "4.X"; } if (theBuild == null) { theBuild = "1"; } theVersionDate = (String) vcfg.getProperty("date"); if (theVersionDate == null) { theVersionDate = "2015-01-01"; } theVersionNo = new Integer((String) vcfg.getProperty("app.version")); try { appType = new Integer((String) vcfg.getProperty("ntype")); } catch (Exception e) { appType = ApplicationBean.APPTYPE_FULL; } appTypeString = (String) vcfg.getProperty("type"); if (appTypeString == null) { appTypeString = "Genji"; } } catch (Exception e) { theVersion = "1.x"; theBuild = "0"; theVersionDate = "2015-01-01"; } applicationBean.setServletContext(servletContext); applicationBean.setVersion(theVersion); applicationBean.setVersionNo(theVersionNo); applicationBean.setBuild(theBuild); applicationBean.setVersionDate(theVersionDate); applicationBean.setAppType(appType); applicationBean.setAppTypeString(appTypeString); }
From source file:com.aurel.track.ApplicationStarter.java
private List<String> createInstallProblemMessage(Exception e) { List<String> msg = new ArrayList<String>(); try {/*from ww w. jav a 2 s. c om*/ PropertiesConfiguration pc = ApplicationBean.getInstance().getDbConfig(); msg.add("Database user name: (see Torque.properties file)"); msg.add("Database password: (see Torque.properties file)"); msg.add("Database type: " + pc.getProperty("torque.database.track.adapter")); msg.add("Database JDBC driver: " + pc.getProperty("torque.dsfactory.track.connection.driver")); msg.add("Database connection URL: " + pc.getProperty("torque.dsfactory.track.connection.url")); msg.add("The system gives this error message: " + e.getMessage()); } catch (Exception ex) { LOGGER.debug(ex); // Nothing to be done about this here } return msg; }
From source file:com.aurel.track.ApplicationStarter.java
private void emergencyExit(Exception e) { // We need this to show a proper install problem page ApplicationBean applicationBean = ApplicationBean.getInstance(); getServletConfig().getServletContext().setAttribute(Constants.APPLICATION_BEAN, applicationBean); PropertiesConfiguration pc = ApplicationBean.getInstance().getDbConfig(); LOGGER.error("Something went wrong here."); LOGGER.error("Please have a look at the previous error messagesand stack traces."); LOGGER.error("Most likely the database connection does not work."); LOGGER.error("Please check if the user name, password and JDBC URL in the "); LOGGER.error("WEB-INF/Torque.properties file are set correctly."); LOGGER.error("Please check that you have only one Database type enabled in the"); LOGGER.error("Torque.properties file. Please also check that the database server"); LOGGER.error("is running and is accessible from this machine. If the database server is"); LOGGER.error("running on a different machine, check that there are no firewall issues."); LOGGER.error("Please also check that you have run all SQL scripts to set up the database."); LOGGER.error(""); LOGGER.error("For your information, your settings in Torque.properties are: "); LOGGER.error("Database user name: " + pc.getProperty("torque.dsfactory.track.connection.user")); String password = (String) pc.getProperty("torque.dsfactory.track.connection.password"); if (password != null) { password = password.replaceAll(".", "*"); LOGGER.error("Database password: " + password + "(see Torque.properties file)"); }/*w w w . ja va 2 s . c o m*/ LOGGER.error("Database type: " + pc.getProperty("torque.database.track.adapter")); LOGGER.error("Database JDBC driver: " + pc.getProperty("torque.dsfactory.track.connection.driver")); LOGGER.error("Database connection URL: " + pc.getProperty("torque.dsfactory.track.connection.url")); LOGGER.error("Exiting..."); LOGGER.error(""); LOGGER.error(""); LOGGER.error(ExceptionUtils.getStackTrace(e)); }
From source file:net.sf.zekr.common.config.ApplicationConfig.java
@SuppressWarnings("unchecked") private void loadConfig() { logger.info("Load Zekr configuration file."); File uc = new File(ApplicationPath.USER_CONFIG); boolean createConfig = false; String confFile = ApplicationPath.USER_CONFIG; if (!uc.exists()) { logger.info("User config does not exist at " + ApplicationPath.USER_CONFIG); logger.info("Will make user config with default values at " + ApplicationPath.MAIN_CONFIG); confFile = ApplicationPath.MAIN_CONFIG; createConfig = true;/*from w w w . ja v a 2 s. c om*/ } try { logger.debug("Load " + confFile); props = ConfigUtils.loadConfig(new File(confFile), ApplicationPath.CONFIG_DIR, "UTF-8"); String version = props.getString("version"); if (!GlobalConfig.ZEKR_VERSION.equals(version)) { logger.info("User config version (" + version + ") does not match " + GlobalConfig.ZEKR_VERSION); if (StringUtils.isBlank(version) || !isCompatibleVersion(version)) { // config file is too old logger.info(String.format("Previous version (%s) is too old and not compatible with %s", version, GlobalConfig.ZEKR_VERSION)); logger.info("Cannot migrate old settings. Will reset settings."); props = ConfigUtils.loadConfig(new File(ApplicationPath.MAIN_CONFIG), "UTF-8"); } else { logger.info("Will initialize user config with default values, overriding with old config."); PropertiesConfiguration oldProps = props; props = ConfigUtils.loadConfig(new File(ApplicationPath.MAIN_CONFIG), "UTF-8"); for (Iterator<String> iter = oldProps.getKeys(); iter.hasNext();) { String key = iter.next(); if (key.equals("version")) { continue; } props.setProperty(key, oldProps.getProperty(key)); } } createConfig = true; } } catch (Exception e) { logger.warn("IO Error in loading/reading config file " + ApplicationPath.MAIN_CONFIG); logger.log(e); } if (createConfig) { runtime.clearAll(); // create config dir new File(Naming.getConfigDir()).mkdirs(); saveConfig(); } // load shortcuts logger.info("Loading keyboard shortcuts."); File userShortcut = new File(ApplicationPath.USER_SHORTCUT); Document doc = null; if (userShortcut.exists()) { try { logger.info("Loading user keyboard shortcuts: " + ApplicationPath.USER_SHORTCUT); Document userDoc = new XmlReader(userShortcut).getDocument(); String version = userDoc.getDocumentElement().getAttribute("version"); if (GlobalConfig.ZEKR_VERSION.equals(version)) { doc = userDoc; } else { logger.info("User shortcut file version (" + version + ") does not match with " + GlobalConfig.ZEKR_VERSION); List<String> userList = new ArrayList<String>(); Element userRoot = userDoc.getDocumentElement(); NodeList userMappings = userRoot.getElementsByTagName("mapping"); for (int i = 0; i < userMappings.getLength(); i++) { Element mapping = (Element) userMappings.item(i); String action = mapping.getAttribute("action"); userList.add(action); } File mainShortcut = new File(ApplicationPath.MAIN_SHORTCUT); Element mainRoot = new XmlReader(mainShortcut).getDocument().getDocumentElement(); NodeList mainMappings = mainRoot.getElementsByTagName("mapping"); for (int i = 0; i < mainMappings.getLength(); i++) { Element mapping = (Element) mainMappings.item(i); String action = mapping.getAttribute("action"); if (!userList.contains(action)) { logger.debug("Adding new shortcut mapping for action: " + action); Element newMapping = userDoc.createElement("mapping"); newMapping.setAttribute("action", mapping.getAttribute("action")); newMapping.setAttribute("key", mapping.getAttribute("key")); newMapping.setAttribute("rtlKey", mapping.getAttribute("rtlKey")); userRoot.appendChild(newMapping); } } userRoot.setAttribute("version", GlobalConfig.ZEKR_VERSION); doc = userDoc; XmlUtils.writeXml(userDoc, userShortcut); } } catch (Exception e) { logger.warn("Error loading user shortcuts: " + ApplicationPath.USER_SHORTCUT); logger.log(e); } } else { try { logger.info("Loading keyboard shortcuts from original location: " + ApplicationPath.MAIN_SHORTCUT); File mainShortcut = new File(ApplicationPath.MAIN_SHORTCUT); doc = new XmlReader(mainShortcut).getDocument(); FileUtils.copyFile(mainShortcut, new File(ApplicationPath.USER_SHORTCUT)); } catch (Exception e) { logger.log(e); } } if (doc != null) { logger.info("Initialize keyboard shortcuts and mappings."); shortcut = new KeyboardShortcut(props, doc); shortcut.init(); } }
From source file:com.linkedin.pinot.queries.TestingServerPropertiesBuilder.java
public PropertiesConfiguration build() throws IOException { final File file = new File("/tmp/" + TestingServerPropertiesBuilder.class.toString()); if (file.exists()) { FileUtils.deleteDirectory(file); }/*from www . j ava 2 s . c o m*/ file.mkdir(); final File bootsDir = new File(file, "bootstrap"); final File dataDir = new File(file, "data"); bootsDir.mkdir(); dataDir.mkdir(); final PropertiesConfiguration config = new PropertiesConfiguration(); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "id"), "0"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "bootstrap.segment.dir"), bootsDir.getAbsolutePath()); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "dataDir"), dataDir.getAbsolutePath()); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "bootstrap.segment.dir"), "0"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "data.manager.class"), "com.linkedin.pinot.core.data.manager.InstanceDataManager"); config.addProperty( StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "segment.metadata.loader.class"), "com.linkedin.pinot.core.indexsegment.columnar.ColumnarSegmentMetadataLoader"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, "tableName"), StringUtils.join(tableNames, ",")); for (final String table : tableNames) { config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, table, "dataManagerType"), "offline"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, table, "readMode"), "heap"); config.addProperty( StringUtil.join(".", PINOT_SERVER_PREFIX, INSTANCE_PREFIC, table, "numQueryExecutorThreads"), "50"); } config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, EXECUTOR_PREFIX, "class"), "com.linkedin.pinot.core.query.executor.ServerQueryExecutor"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, EXECUTOR_PREFIX, "timeout"), "150000"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, "requestHandlerFactory.class"), "com.linkedin.pinot.server.request.SimpleRequestHandlerFactory"); config.addProperty(StringUtil.join(".", PINOT_SERVER_PREFIX, "netty.port"), "8882"); config.setDelimiterParsingDisabled(true); final Iterator<String> keys = config.getKeys(); while (keys.hasNext()) { final String key = keys.next(); System.out.println(key + " : " + config.getProperty(key)); } return config; }
From source file:net.emotivecloud.scheduler.drp4one.DRP4OVF.java
private HashMap<String, String> getPropsFromFile(String fileName, String vmId) { Object product_propsList = ""; HashMap<String, String> hmap = new HashMap<String, String>(); String[] product_props = {};/*from www . j a v a2 s . com*/ try { PropertiesConfiguration props_config = new PropertiesConfiguration(new File(fileName)); if (props_config.containsKey(vmId)) { log.debug("getting the product properties for vm: " + vmId); product_propsList = props_config.getProperty(vmId); if (product_propsList.toString().contains(",")) { product_props = product_propsList.toString() .substring(1, product_propsList.toString().length() - 1).split(","); for (String product_prop : product_props) { if (product_prop.contains("=")) { String[] product_property = product_prop.split("="); hmap.put(product_property[0], product_property[1]); log.debug("adding product property " + product_property[0] + " " + product_property[1]); } } } else { String[] product_property = product_propsList.toString() .substring(1, product_propsList.toString().length() - 1).split("="); if (product_property.length == 2) { hmap.put(product_property[0], product_property[1]); log.debug("adding product property " + product_property[0] + " " + product_property[1]); } else { log.error("error in the product property, does nt contain a valid key value pair.."); } } } else { log.debug("no such key exists " + vmId); } } catch (Exception e) { log.error(e.getMessage(), e); } return hmap; }