List of usage examples for java.util.regex Matcher reset
public Matcher reset()
From source file:org.openhab.binding.energenie.internal.EnergenieBinding.java
/** * @{inheritDoc}//www .jav a 2s. c o m */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; } Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { logger.debug("given config key '" + key + "' does not follow the expected pattern '<id>.<host|password>'"); continue; } matcher.reset(); matcher.find(); String deviceId = matcher.group(1); DeviceConfig deviceConfig = deviceConfigs.get(deviceId); if (deviceConfig == null) { deviceConfig = new DeviceConfig(deviceId); deviceConfigs.put(deviceId, deviceConfig); } String configKey = matcher.group(2); String value = (String) config.get(key); if ("host".equals(configKey)) { deviceConfig.host = value; pmsIpConfig.put(deviceId, value); } else if ("password".equals(configKey)) { deviceConfig.password = value; pmsPasswordConfig.put(deviceId, value); } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } String refreshIntervalString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } setProperlyConfigured(true); } }
From source file:org.openhab.persistence.sql.internal.SqlPersistenceService.java
/** * @{inheritDoc//w w w . j a v a2 s .c o m */ public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { continue; } matcher.reset(); matcher.find(); if (!matcher.group(1).equals("sqltype")) continue; String itemType = matcher.group(2).toUpperCase() + "ITEM"; String value = (String) config.get(key); sqlTypes.put(itemType, value); } driverClass = (String) config.get("driverClass"); if (StringUtils.isBlank(driverClass)) { throw new ConfigurationException("sql:driverClass", "The SQL driver class is missing - please configure the sql:driverClass parameter in openhab.cfg"); } url = (String) config.get("url"); if (StringUtils.isBlank(url)) { throw new ConfigurationException("sql:url", "The SQL database URL is missing - please configure the sql:url parameter in openhab.cfg"); } user = (String) config.get("user"); if (StringUtils.isBlank(user)) { throw new ConfigurationException("sql:user", "The SQL user is missing - please configure the sql:user parameter in openhab.cfg"); } password = (String) config.get("password"); if (StringUtils.isBlank(password)) { throw new ConfigurationException("sql:password", "The SQL password is missing. Attempting to connect without password. To specify a password configure the sql:password parameter in openhab.cfg."); } String errorThresholdString = (String) config.get("reconnectCnt"); if (StringUtils.isNotBlank(errorThresholdString)) { errReconnectThreshold = Integer.parseInt(errorThresholdString); } disconnectFromDatabase(); connectToDatabase(); // connection has been established ... initialization completed! initialized = true; } }
From source file:org.openhab.binding.hdanywhere.internal.HDanywhereBinding.java
@SuppressWarnings("rawtypes") @Override//from ww w. jav a 2 s . c om public void updated(Dictionary config) throws ConfigurationException { if (config != null) { Enumeration keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); Matcher matcher = EXTRACT_HDANYWHERE_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { logger.debug("given hdanywhere-config-key '" + key + "' does not follow the expected pattern '<host_IP_Address>.ports'"); continue; } matcher.reset(); matcher.find(); String hostIP = matcher.group(1) + "." + matcher.group(2) + "." + matcher.group(3) + "." + matcher.group(4); String configKey = matcher.group(5); String value = (String) config.get(key); if ("ports".equals(configKey)) { matrixCache.put(hostIP, Integer.valueOf(value)); } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } } setProperlyConfigured(true); }
From source file:org.lunifera.ecview.xtext.builder.participant.impl.I18nRegistry.java
/** * Computes the access url./* ww w .ja va2 s .co m*/ * <p> * Following order will be used: * <ol> * <li>Use given locale</li> * <li>Create more specific locale and repeat until default locale is * reached.</li> * </ul> </li> * </ol> * * @param locale * @param packageName * @param key * @return */ private AccessPath computeAccessPath(Locale locale, String key) { Matcher valueMatcher = null; if (key != null && !key.equals("")) { key = Pattern.quote(key); Pattern valuePattern = Pattern.compile(key.toString()); valueMatcher = valuePattern.matcher(""); valueMatcher.reset(); } AccessPath url = new AccessPath(); int prio = 0; List<Locale> computedLocales = computeLocales(locale); for (Locale computedLocale : computedLocales) { Accessor accessor = new Accessor(computedLocale, ++prio, key, valueMatcher); url.addAccessor(accessor); } return url; }
From source file:org.openhab.binding.echonetlite.internal.ECHONETLiteGenericBindingProvider.java
/** * {@inheritDoc}//from w w w . j a v a2 s . c o m */ @Override public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException { super.processBindingConfiguration(context, item, bindingConfig); if (bindingConfig != null) { ECHONETLiteBindingConfig newConfig = new ECHONETLiteBindingConfig(); Matcher matcher = BASE_CONFIG_PATTERN.matcher(bindingConfig); if (!matcher.matches()) { throw new BindingConfigParseException( "bindingConfig '" + bindingConfig + "' doesn't contain a valid binding configuration"); } matcher.reset(); while (matcher.find()) { String bindingConfigPart = matcher.group(1); if (StringUtils.isNotBlank(bindingConfigPart)) { parseBindingConfig(newConfig, item, bindingConfigPart); } } addBindingConfig(item, newConfig); } else { logger.warn("bindingConfig is NULL (item=" + item + ") -> processing bindingConfig aborted!"); } }
From source file:org.openhab.binding.squeezebox.internal.SqueezeboxBinding.java
@Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { disconnectSqueezeServer();// www . j a v a 2s . c om int cliport = DEFAULT_CLI_PORT; int webport = DEFAULT_WEB_PORT; String host = DEFAULT_HOST; Map<String, String> tmpPlayerMap = new HashMap<String, String>(); Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; } Matcher serverMatcher = EXTRACT_SERVER_CONFIG_PATTERN.matcher(key); Matcher playerMatcher = EXTRACT_PLAYER_CONFIG_PATTERN.matcher(key); String value = (String) config.get(key); if (serverMatcher.matches()) { serverMatcher.reset(); serverMatcher.find(); if ("host".equals(serverMatcher.group(2))) { host = value; } else if ("cliport".equals(serverMatcher.group(2))) { cliport = Integer.valueOf(value); } else if ("webport".equals(serverMatcher.group(2))) { webport = Integer.valueOf(value); } } else if (playerMatcher.matches()) { tmpPlayerMap.put(value.toString(), playerMatcher.group(1)); } } connectSqueezeServer(host, cliport, webport, tmpPlayerMap); } }
From source file:org.openhab.binding.snmp.internal.SnmpGenericBindingProvider.java
/** * {@inheritDoc}/* w w w . j a va 2 s .com*/ */ @Override public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException { super.processBindingConfiguration(context, item, bindingConfig); if (bindingConfig != null) { SnmpBindingConfig newConfig = new SnmpBindingConfig(); Matcher matcher = BASE_CONFIG_PATTERN.matcher(bindingConfig); if (!matcher.matches()) { throw new BindingConfigParseException( "bindingConfig '" + bindingConfig + "' doesn't contain a valid binding configuration"); } matcher.reset(); while (matcher.find()) { String bindingConfigPart = matcher.group(1); if (StringUtils.isNotBlank(bindingConfigPart)) { parseBindingConfig(newConfig, item, bindingConfigPart); } } addBindingConfig(item, newConfig); } else { logger.warn("bindingConfig is NULL (item=" + item + ") -> processing bindingConfig aborted!"); } }
From source file:org.openhab.binding.plclogo.internal.PLCLogoBinding.java
@Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { Boolean configured = false;/*from ww w . j av a 2s . c o m*/ if (config != null) { String refreshIntervalString = Objects.toString(config.get("refresh"), null); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } if (controllers == null) { controllers = new HashMap<String, PLCLogoConfig>(); } Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; } Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { continue; } matcher.reset(); matcher.find(); String controllerName = matcher.group(1); PLCLogoConfig deviceConfig = controllers.get(controllerName); if (deviceConfig == null) { deviceConfig = new PLCLogoConfig(); controllers.put(controllerName, deviceConfig); logger.info("Create new config for {}", controllerName); } if (matcher.group(2).equals("host")) { String ip = config.get(key).toString(); deviceConfig.setIP(ip); logger.info("Set host of {}: {}", controllerName, ip); configured = true; } if (matcher.group(2).equals("remoteTSAP")) { String tsap = config.get(key).toString(); deviceConfig.setRemoteTSAP(Integer.decode(tsap)); logger.info("Set remote TSAP for {}: {}", controllerName, tsap); } if (matcher.group(2).equals("localTSAP")) { String tsap = config.get(key).toString(); deviceConfig.setLocalTSAP(Integer.decode(tsap)); logger.info("Set local TSAP for {}: {}", controllerName, tsap); } if (matcher.group(2).equals("model")) { PLCLogoModel model = null; String modelName = config.get(key).toString(); if (modelName.equalsIgnoreCase("0BA7")) { model = PLCLogoModel.LOGO_MODEL_0BA7; } else if (modelName.equalsIgnoreCase("0BA8")) { model = PLCLogoModel.LOGO_MODEL_0BA8; } else { logger.info("Found unknown model for {}: {}", controllerName, modelName); } if (model != null) { deviceConfig.setModel(model); logger.info("Set model for {}: {}", controllerName, modelName); } } } // while Iterator<Entry<String, PLCLogoConfig>> entries = controllers.entrySet().iterator(); while (entries.hasNext()) { Entry<String, PLCLogoConfig> thisEntry = entries.next(); String controllerName = thisEntry.getKey(); PLCLogoConfig deviceConfig = thisEntry.getValue(); S7Client LogoS7Client = deviceConfig.getS7Client(); if (LogoS7Client == null) { LogoS7Client = new Moka7.S7Client(); } else { LogoS7Client.Disconnect(); } LogoS7Client.SetConnectionParams(deviceConfig.getlogoIP(), deviceConfig.getlocalTSAP(), deviceConfig.getremoteTSAP()); logger.info("About to connect to {}", controllerName); if ((LogoS7Client.Connect() == 0) && LogoS7Client.Connected) { logger.info("Connected to PLC LOGO! device {}", controllerName); } else { logger.error("Could not connect to PLC LOGO! device {} : {}", controllerName, S7Client.ErrorText(LogoS7Client.LastError)); throw new ConfigurationException("Could not connect to PLC LOGO! device ", controllerName + " " + deviceConfig.getlogoIP()); } deviceConfig.setS7Client(LogoS7Client); } setProperlyConfigured(configured); } else { logger.info("No configuration for PLCLogoBinding"); } }
From source file:org.diorite.impl.command.CommandImpl.java
protected void execute(final CommandSender sender, final String label, final Matcher matchedPattern, final String[] args) { if (this.commandExecutor != null) { Objects.requireNonNull(sender, "sender can't be null"); Objects.requireNonNull(label, "label can't be null"); Objects.requireNonNull(matchedPattern, "matchedPattern can't be null"); Objects.requireNonNull(args, "args can't be null"); matchedPattern.reset(); matchedPattern.find();//from w w w. j a v a2s .c o m this.commandExecutor.runCommand(sender, this, label, matchedPattern, new Arguments(args)); } }
From source file:org.openhab.binding.powerdoglocalapi.internal.PowerDogLocalApiBinding.java
/** * Parse PowerDog Openhab configuration// w ww . j av a 2 s .c o m * * @param config * PowerDog configuration string */ private void parseConfiguration(Map<String, Object> config) { logger.debug("PowerDogLocalApi:parseConfiguration() method is called!"); if (config != null) { Set<String> keyset = config.keySet(); // create server list of not yet available if (serverList == null) { serverList = new HashMap<String, PowerDogLocalApiServerConfig>(); } // check keys of config set for (Iterator<String> keys = keyset.iterator(); keys.hasNext();) { String key = keys.next(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; } else if ("event.topics".equals(key)) { continue; } else if ("component.name".equals(key)) { continue; } else if ("component.id".equals(key)) { continue; } else if ("objectClass".equals(key)) { continue; } // check if key matches powerdog-regex Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { continue; } matcher.reset(); matcher.find(); // get serverId as first item String serverId = matcher.group(1); // create config item for this specific powerdog unit PowerDogLocalApiServerConfig deviceConfig = serverList.get(serverId); if (deviceConfig == null) { deviceConfig = new PowerDogLocalApiServerConfig(); serverList.put(serverId, deviceConfig); } // extract values for host, port, password or refresh String configKey = matcher.group(2); String value = (String) config.get(key); if ("host".equals(configKey)) { deviceConfig.host = value; logger.debug("value: {}", value); } else if ("port".equals(configKey)) { if (StringUtils.isNotBlank(value)) { deviceConfig.port = (int) Long.parseLong(value); logger.debug("value: {}", value); } } else if ("password".equals(configKey)) { deviceConfig.password = value; } else if ("refresh".equals(configKey)) { if (StringUtils.isNotBlank(value)) { // refresh cannot be lower than refresh interval deviceConfig.refresh = (int) Math.max(Long.parseLong(value), refreshInterval); logger.debug("value: {}", value); } } else { // cannot throw new ConfigurationException(configKey, // "The given PowerDogLocalApi configKey '" + configKey + // "' is unknown"); logger.warn("The given PowerDogLocalApi configKey '{}' is unknown", configKey); } logger.debug("New Server config: {}", deviceConfig.toString()); } setProperlyConfigured(true); logger.debug("PowerDogLocalApi:parseConfiguration() method is terminated"); } }