List of usage examples for java.util Properties keys
@Override
public Enumeration<Object> keys()
From source file:org.apache.jmeter.util.JMeterUtils.java
/** * Creates a table of strings for all the properties that start with a * common prefix./* w ww . jav a 2 s .c om*/ * <p> * So if you have {@link Properties} <code>prop</code> with two entries, say * <ul> * <li>this.test</li> * <li>that.something</li> * </ul> * And would call this method with a <code>prefix</code> <em>this</em>, the * result would be a new {@link Hashtable} with one entry, which key would * be <em>test</em>. * * @param properties * input to search * @param prefix * to match against properties * @return a Hashtable where the keys are the original matching keys with * the prefix removed * @deprecated (3.0) not used */ @Deprecated public static Hashtable<String, String> getHashtable(Properties properties, String prefix) { Hashtable<String, String> t = new Hashtable<>(); Enumeration<?> names = properties.keys(); final int length = prefix.length(); while (names.hasMoreElements()) { String prop = (String) names.nextElement(); if (prop.startsWith(prefix)) { t.put(prop.substring(length), properties.getProperty(prop)); } } return t; }
From source file:com.photon.phresco.impl.IPhonePhrescoApplicationProcessor.java
private void storeConfigObjAsPlist(List<Configuration> configuration, String destPlistFile) throws PhrescoException { //FIXME: this logic needs to be revisited and should be fixed with XMLPropertyListConfiguration classes. try {//from ww w .j av a 2 s.c om XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration(); for (Configuration config : configuration) { if (FEATURES.equalsIgnoreCase(config.getType())) { String rootNode = ""; HashMap<String, Object> valueMap = new HashMap(); Properties properties = config.getProperties(); Enumeration em = properties.keys(); while (em.hasMoreElements()) { HashMap<String, Object> tempMap = new HashMap(); String key = (String) em.nextElement(); String value = properties.getProperty(key); String[] keySplited = key.split("\\."); rootNode = keySplited[0]; int length = keySplited.length; if (value != null && value instanceof String && value.toString().startsWith("[") && value.toString().endsWith("]")) { String arrayListvalue = value.toString().replace("[", "").replace("]", ""); String[] split = arrayListvalue.toString().split(","); Map<String, Object> keyValuePair = new HashMap<String, Object>(); List<String> asList = new ArrayList<String>(); for (String string : split) { asList.add(string.trim()); } String rootKey = ""; String arrayListKey = ""; if (length == 3) { rootKey = keySplited[1]; arrayListKey = keySplited[2]; keyValuePair.put(arrayListKey, asList); if (!valueMap.isEmpty()) { if (valueMap.containsKey(keySplited[1])) { HashMap<String, Object> object = (HashMap) valueMap.get(keySplited[1]); tempMap.put(arrayListKey, asList); for (Map.Entry<String, Object> entry : object.entrySet()) { tempMap.put(entry.getKey(), entry.getValue()); } valueMap.put(rootKey, tempMap); } else { valueMap.put(rootKey, keyValuePair); } } else { valueMap.put(rootKey, keyValuePair); } } else if (length == 2) { valueMap.put(keySplited[1], asList); } } else { String arrayListKey = ""; if (length == 2) { arrayListKey = keySplited[1]; valueMap.put(arrayListKey, value); } else if (length == 3) { HashMap localMap = new HashMap(); localMap.put(keySplited[2], value); if (!valueMap.isEmpty()) { if (valueMap.containsKey(keySplited[1])) { HashMap<String, Object> object = (HashMap) valueMap.get(keySplited[1]); tempMap.put(keySplited[2], value); for (Map.Entry<String, Object> entry : object.entrySet()) { tempMap.put(entry.getKey(), entry.getValue()); } valueMap.put(keySplited[1], tempMap); } else { valueMap.put(keySplited[1], localMap); } } else { valueMap.put(keySplited[1], localMap); } } } } plist.addProperty(rootNode, valueMap); } } plist.save(destPlistFile); } catch (ConfigurationException e) { throw new PhrescoException(e); } }
From source file:com.glaf.base.modules.sys.springmvc.LoginController.java
/** * /*from w w w. j a va2 s . c om*/ * * @param request * @param modelMap * @return */ @RequestMapping(params = "method=login") public ModelAndView login(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); HttpSession session = request.getSession(false); if (session == null) { return new ModelAndView("/modules/login", modelMap); } if (StringUtils.isNotEmpty(request.getParameter("systemName"))) { Environment.setCurrentSystemName(request.getParameter("systemName")); } else { Environment.setCurrentSystemName(Environment.DEFAULT_SYSTEM_NAME); } ViewMessages messages = new ViewMessages(); // ?? String account = ParamUtil.getParameter(request, "x"); String password = ParamUtil.getParameter(request, "y"); String rand = (String) session.getAttribute("x_y"); if (rand != null) { password = StringTools.replace(password, rand, ""); } String rand2 = (String) session.getAttribute("x_z"); if (rand2 != null) { password = StringTools.replace(password, rand2, ""); } String pwd = password; try { pwd = DigestUtil.digestString(password, "MD5"); } catch (Exception ex) { } logger.debug(account + " start login........................"); // SysUser bean = authorizeService.authorize(account, pwd); if (bean == null) { // ? messages.add(ViewMessages.GLOBAL_MESSAGE, new ViewMessage("authorize.login_failure")); MessageUtils.addMessages(request, messages); return new ModelAndView("/modules/login", modelMap); } String ipAddr = RequestUtils.getIPAddress(request); SystemProperty p = SystemConfig.getProperty("login_limit"); if (!(StringUtils.equals(ipAddr, "localhost") || StringUtils.equals(ipAddr, "127.0.0.1") || StringUtils.equals(account, "root") || StringUtils.equals(account, "admin"))) { SystemProperty pt = SystemConfig.getProperty("login_time_check"); int timeoutSeconds = 300; if (pt != null && pt.getValue() != null && StringUtils.isNumeric(pt.getValue())) { timeoutSeconds = Integer.parseInt(pt.getValue()); } if (timeoutSeconds < 300) { timeoutSeconds = 300; } if (timeoutSeconds > 3600) { timeoutSeconds = 3600; } /** * ??? */ if (p != null && StringUtils.equals(p.getValue(), "true")) { logger.debug("#################3#########################"); String loginIP = null; UserOnline userOnline = userOnlineService.getUserOnline(account); logger.debug("userOnline:" + userOnline); boolean timeout = false; if (userOnline != null) { loginIP = userOnline.getLoginIP(); if (userOnline.getCheckDateMs() != null && System.currentTimeMillis() - userOnline.getCheckDateMs() > timeoutSeconds * 1000) { timeout = true;// ? } if (userOnline.getLoginDate() != null && System.currentTimeMillis() - userOnline.getLoginDate().getTime() > timeoutSeconds * 1000) { timeout = true;// ? } } logger.info("login IP:" + loginIP); if (!timeout) {// ???? if (loginIP != null && !(StringUtils.equals(ipAddr, loginIP))) {// messages.add(ViewMessages.GLOBAL_MESSAGE, new ViewMessage("authorize.login_failure2")); MessageUtils.addMessages(request, messages); logger.debug("?"); return new ModelAndView("/modules/login", modelMap); } } } } Properties props = CallbackProperties.getProperties(); if (props != null && props.keys().hasMoreElements()) { Enumeration<?> e = props.keys(); while (e.hasMoreElements()) { String className = (String) e.nextElement(); if (className.indexOf("parameter") >= 0) { continue; } try { Object obj = ClassUtils.instantiateObject(className); if (obj instanceof LoginCallback) { LoginCallback callback = (LoginCallback) obj; callback.afterLogin(bean.getAccount(), request, response); } } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } } } if (bean.getLoginCount() != null) { bean.setLoginCount(bean.getLoginCount() + 1); } else { bean.setLoginCount(1); } // ? bean.setLastLoginDate(new Date()); sysUserService.updateUser(bean); // String menus = sysApplicationService.getMenu(3, bean); // bean.setMenus(menus); // request.setAttribute(SysConstants.MENU, menus); ContextUtil.put(bean.getAccount(), bean);// ?? RequestUtils.setLoginUser(request, response, "default", bean.getAccount()); if (p != null && StringUtils.equals(p.getValue(), "true")) { try { UserOnline online = new UserOnline(); online.setActorId(bean.getActorId()); online.setName(bean.getName()); online.setCheckDate(new Date()); online.setLoginDate(new Date()); online.setLoginIP(ipAddr); online.setSessionId(session.getId()); userOnlineService.login(online); } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } } if (bean.getAccountType() == 1) {// return new ModelAndView("/modules/sp_main", modelMap); } else if (bean.getAccountType() == 2) {// return new ModelAndView("/modules/wx_main", modelMap); } else { return new ModelAndView("/modules/main", modelMap); } }
From source file:org.cipango.console.ApplicationManager.java
public Table getDarConfig() throws Exception { Table table = new Table(); table.setTitle("Configuration"); List<Header> headers = new ArrayList<Row.Header>(); headers.add(new Header("Method")); headers.add(new Header("Application name")); headers.add(new Header("Identity")); headers.add(new Header("Routing region")); headers.add(new Header("URI")); headers.add(new Header("Route modifier")); headers.add(new Header("State info")); table.setHeaders(headers);/*ww w . jav a 2 s. c o m*/ String config = (String) _mbsc.getAttribute(DAR, "config"); InputStream is = new ByteArrayInputStream(config.getBytes()); Properties properties = new Properties(); properties.load(is); Enumeration<Object> e = properties.keys(); while (e.hasMoreElements()) { String method = e.nextElement().toString(); String infos = properties.get(method).toString().trim(); int li = infos.indexOf('('); while (li >= 0) { Row row = new Row(); List<Value> values = row.getValues(); Iterator<Header> headerIt = headers.iterator(); int ri = infos.indexOf(')', li); if (ri < 0) throw new ParseException(infos, li); values.add(new Value(method, headerIt.next())); String info = infos.substring(li + 1, ri); li = infos.indexOf('(', ri); InfoIterator it = new InfoIterator(info); while (it.hasNext()) values.add(new Value(it.next(), headerIt.next())); table.add(row); } } return table; }
From source file:org.apache.jmeter.util.JMeterUtils.java
/** * Creates a vector of SampleController plugins. * * @param properties/*from www . j a v a2 s.co m*/ * The properties with information about the samplers * @return The Controllers value * @deprecated (3.0) not used + pre-java 1.2 collection */ // TODO - does not appear to be called directly @Deprecated public static Vector<Object> getControllers(Properties properties) { String name = "controller."; // $NON-NLS-1$ Vector<Object> v = new Vector<>(); Enumeration<?> names = properties.keys(); while (names.hasMoreElements()) { String prop = (String) names.nextElement(); if (prop.startsWith(name)) { Object o = instantiate(properties.getProperty(prop), "org.apache.jmeter.control.SamplerController"); // $NON-NLS-1$ v.addElement(o); } } return v; }
From source file:com.glaf.base.modules.sys.springmvc.MxLoginController.java
/** * /*from w w w . j a va2 s . c o m*/ * * @param request * @param modelMap * @return */ @RequestMapping("/doLogin") public ModelAndView doLogin(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); HttpSession session = request.getSession(false); if (session == null) { return new ModelAndView("/modules/login", modelMap); } if (StringUtils.isNotEmpty(request.getParameter("systemName"))) { Environment.setCurrentSystemName(request.getParameter("systemName")); } else { Environment.setCurrentSystemName(Environment.DEFAULT_SYSTEM_NAME); } ViewMessages messages = new ViewMessages(); // ?? String account = ParamUtil.getParameter(request, "x"); String password = ParamUtil.getParameter(request, "y"); String rand = (String) session.getAttribute("x_y"); if (rand != null) { password = StringTools.replace(password, rand, ""); } String rand2 = (String) session.getAttribute("x_z"); if (rand2 != null) { password = StringTools.replace(password, rand2, ""); } String pwd = password; try { pwd = DigestUtil.digestString(password, "MD5"); } catch (Exception ex) { } logger.debug(account + " start login........................"); // SysUser bean = authorizeService.authorize(account, pwd); if (bean == null) { // ? messages.add(ViewMessages.GLOBAL_MESSAGE, new ViewMessage("authorize.login_failure")); MessageUtils.addMessages(request, messages); return new ModelAndView("/modules/login", modelMap); } String ipAddr = RequestUtils.getIPAddress(request); SystemProperty p = SystemConfig.getProperty("login_limit"); if (!(StringUtils.equals(ipAddr, "localhost") || StringUtils.equals(ipAddr, "127.0.0.1") || StringUtils.equals(account, "root") || StringUtils.equals(account, "admin"))) { SystemProperty pt = SystemConfig.getProperty("login_time_check"); int timeoutSeconds = 300; if (pt != null && pt.getValue() != null && StringUtils.isNumeric(pt.getValue())) { timeoutSeconds = Integer.parseInt(pt.getValue()); } if (timeoutSeconds < 300) { timeoutSeconds = 300; } if (timeoutSeconds > 3600) { timeoutSeconds = 3600; } /** * ??? */ if (p != null && StringUtils.equals(p.getValue(), "true")) { logger.debug("#################3#########################"); String loginIP = null; UserOnline userOnline = userOnlineService.getUserOnline(account); logger.debug("userOnline:" + userOnline); boolean timeout = false; if (userOnline != null) { loginIP = userOnline.getLoginIP(); if (userOnline.getCheckDateMs() != null && System.currentTimeMillis() - userOnline.getCheckDateMs() > timeoutSeconds * 1000) { timeout = true;// ? } if (userOnline.getLoginDate() != null && System.currentTimeMillis() - userOnline.getLoginDate().getTime() > timeoutSeconds * 1000) { timeout = true;// ? } } logger.info("timeout:" + timeout); logger.info("login IP:" + loginIP); if (!timeout) {// ???? if (loginIP != null && !(StringUtils.equals(ipAddr, loginIP))) {// messages.add(ViewMessages.GLOBAL_MESSAGE, new ViewMessage("authorize.login_failure2")); MessageUtils.addMessages(request, messages); logger.debug("?"); return new ModelAndView("/modules/login", modelMap); } } } } Properties props = CallbackProperties.getProperties(); if (props != null && props.keys().hasMoreElements()) { Enumeration<?> e = props.keys(); while (e.hasMoreElements()) { String className = (String) e.nextElement(); try { Object obj = ClassUtils.instantiateObject(className); if (obj instanceof LoginCallback) { LoginCallback callback = (LoginCallback) obj; callback.afterLogin(bean.getAccount(), request, response); } } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } } } if (bean.getLoginCount() != null) { bean.setLoginCount(bean.getLoginCount() + 1); } else { bean.setLoginCount(1); } // ? bean.setLastLoginDate(new Date()); sysUserService.updateUser(bean); ContextUtil.put(bean.getAccount(), bean);// ?? RequestUtils.setLoginUser(request, response, "default", bean.getAccount()); if (p != null && StringUtils.equals(p.getValue(), "true")) { try { UserOnline online = new UserOnline(); online.setActorId(bean.getActorId()); online.setName(bean.getName()); online.setCheckDate(new Date()); online.setLoginDate(new Date()); online.setLoginIP(ipAddr); online.setSessionId(session.getId()); userOnlineService.login(online); } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } } if (bean.getAccountType() == 1) {// return new ModelAndView("/modules/sp_main", modelMap); } else if (bean.getAccountType() == 2) {// return new ModelAndView("/modules/wx_main", modelMap); } else { return new ModelAndView("/modules/main", modelMap); } }
From source file:com.opensource.frameworks.processframework.utils.DefaultPropertiesPersister.java
protected void doStore(Properties props, Writer writer, String header) throws IOException { BufferedWriter out = new BufferedWriter(writer); if (header != null) { out.write("#" + header); out.newLine();// www . j a v a 2 s . c om } out.write("#" + new Date()); out.newLine(); for (Enumeration keys = props.keys(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); String val = props.getProperty(key); out.write(escape(key, true) + "=" + escape(val, false)); out.newLine(); } out.flush(); }
From source file:evyframework.common.DefaultPropertiesPersister.java
protected void doStore(Properties props, Writer writer, String header) throws IOException { BufferedWriter out = new BufferedWriter(writer); if (header != null) { out.write("#" + header); out.newLine();//w w w .j av a2 s . co m } out.write("#" + new Date()); out.newLine(); for (Enumeration<?> keys = props.keys(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); String val = props.getProperty(key); out.write(escape(key, true) + "=" + escape(val, false)); out.newLine(); } out.flush(); }
From source file:org.apache.hive.hcatalog.pig.HCatStorer.java
/** * @param location databaseName.tableName *///from w w w .jav a 2s .c om @Override public void setStoreLocation(String location, Job job) throws IOException { Configuration config = job.getConfiguration(); config.set(INNER_SIGNATURE, INNER_SIGNATURE_PREFIX + "_" + sign); Properties udfProps = UDFContext.getUDFContext().getUDFProperties(this.getClass(), new String[] { sign }); String[] userStr = location.split("\\."); if (udfProps.containsKey(HCatConstants.HCAT_PIG_STORER_LOCATION_SET)) { for (Enumeration<Object> emr = udfProps.keys(); emr.hasMoreElements();) { PigHCatUtil.getConfigFromUDFProperties(udfProps, config, emr.nextElement().toString()); } Credentials crd = jobCredentials.get(INNER_SIGNATURE_PREFIX + "_" + sign); if (crd != null) { job.getCredentials().addAll(crd); } } else { Job clone = new Job(job.getConfiguration()); OutputJobInfo outputJobInfo; if (userStr.length == 2) { outputJobInfo = OutputJobInfo.create(userStr[0], userStr[1], partitions); } else if (userStr.length == 1) { outputJobInfo = OutputJobInfo.create(null, userStr[0], partitions); } else { throw new FrontendException( "location " + location + " is invalid. It must be of the form [db.]table", PigHCatUtil.PIG_EXCEPTION_CODE); } Schema schema = (Schema) ObjectSerializer.deserialize(udfProps.getProperty(PIG_SCHEMA)); if (schema != null) { pigSchema = schema; } if (pigSchema == null) { throw new FrontendException("Schema for data cannot be determined.", PigHCatUtil.PIG_EXCEPTION_CODE); } String externalLocation = (String) udfProps .getProperty(HCatConstants.HCAT_PIG_STORER_EXTERNAL_LOCATION); if (externalLocation != null) { outputJobInfo.setLocation(externalLocation); } try { HCatOutputFormat.setOutput(job, outputJobInfo); } catch (HCatException he) { // pass the message to the user - essentially something about // the table // information passed to HCatOutputFormat was not right throw new PigException(he.getMessage(), PigHCatUtil.PIG_EXCEPTION_CODE, he); } HCatSchema hcatTblSchema = HCatOutputFormat.getTableSchema(job.getConfiguration()); try { doSchemaValidations(pigSchema, hcatTblSchema); } catch (HCatException he) { throw new FrontendException(he.getMessage(), PigHCatUtil.PIG_EXCEPTION_CODE, he); } computedSchema = convertPigSchemaToHCatSchema(pigSchema, hcatTblSchema); HCatOutputFormat.setSchema(job, computedSchema); udfProps.setProperty(COMPUTED_OUTPUT_SCHEMA, ObjectSerializer.serialize(computedSchema)); // We will store all the new /changed properties in the job in the // udf context, so the the HCatOutputFormat.setOutput and setSchema // methods need not be called many times. for (Entry<String, String> keyValue : job.getConfiguration()) { String oldValue = clone.getConfiguration().getRaw(keyValue.getKey()); if ((oldValue == null) || (keyValue.getValue().equals(oldValue) == false)) { udfProps.put(keyValue.getKey(), keyValue.getValue()); } } //Store credentials in a private hash map and not the udf context to // make sure they are not public. jobCredentials.put(INNER_SIGNATURE_PREFIX + "_" + sign, job.getCredentials()); udfProps.put(HCatConstants.HCAT_PIG_STORER_LOCATION_SET, true); } }
From source file:org.apache.cocoon.generation.StatusGenerator.java
private void genProperties() throws SAXException { this.startGroup("System-Properties"); final Properties p = System.getProperties(); final Enumeration e = p.keys(); while (e.hasMoreElements()) { final String key = (String) e.nextElement(); final String value = p.getProperty(key); this.addValue(key, value); }/*w w w . ja v a 2s . c o m*/ this.endGroup(); }