List of usage examples for org.apache.commons.lang3 StringUtils substringAfter
public static String substringAfter(final String str, final String separator)
Gets the substring after the first occurrence of a separator.
From source file:org.openhab.binding.echonetlite.internal.ECHONETLiteGenericBindingProvider.java
@Override public String getEdt(String itemName, Command command) { ECHONETLiteBindingConfig config = (ECHONETLiteBindingConfig) bindingConfigs.get(itemName); //return config != null ? config.get(command).edt : new String(""); if (config != null) { if (config.get(command) != null) { return config.get(command).edt; } else {//w w w .j a v a 2s. com return StringUtils.substringAfter(command.toString(), "value="); } } else { return new String(""); } }
From source file:org.openhab.binding.echonetlite.internal.ECHONETLiteGenericBindingProvider.java
@Override public String getValue(String itemName, Command command) { ECHONETLiteBindingConfig config = (ECHONETLiteBindingConfig) bindingConfigs.get(itemName); //return config != null ? config.get(command).value : null; if (config != null) { if (config.get(command) != null) { return config.get(command).edt; } else {// w ww .j av a 2 s .c o m return StringUtils.substringAfter(command.toString(), "value="); } } else { return new String(""); } }
From source file:org.openhab.binding.IEEE1888.server.FIAPServer.java
private Point buidPoint(URI id, String valueStr) throws ParseException { // analyze value HashMap<String, String> keyValueMap = new HashMap<>(); if (valueStr != null) { String[] values = StringUtils.split(valueStr, "&"); if (values != null) { for (String value : values) { keyValueMap.put(StringUtils.substringBefore(value, "="), StringUtils.substringAfter(value, "=")); }/*from w w w .j ava 2 s . c o m*/ } } // [point] Point point = new Point(); point.setId(id); Value value = new Value(); // [time] Calendar timeValue = Calendar.getInstance(); if (StringUtils.isNotBlank(keyValueMap.get("time"))) { Date dateTime = DateUtils.parseDate(keyValueMap.get("time"), TIME_FORMAT); timeValue.setTime(dateTime); } value.setTime(timeValue); // [value] String v; if (keyValueMap.containsKey("value")) { v = keyValueMap.get("value"); } else { v = valueStr; } if (v == null) { v = ""; } value.setString(v); point.addValue(value); return point; }
From source file:org.openhab.binding.IEEE1888.trap.TrapManager.java
/** * If there are any updates, data were sened. * * @param itemName//from w w w .j av a2s . co m * @param newState */ public static void putTrapData(String itemName, State newState) throws ParseException { if (!trapMap.containsKey(itemName)) { // If there is not trap, trap is never processed. return; } TrapInfo trapInfo = trapMap.get(itemName); Value pointValue = trapInfo.getPoint().getValue()[0]; String newValue = newState.toString(); Pattern STATE_CONFIG_PATTERN = Pattern.compile("(.*?)\\=(.*?)\\&(.*?)\\=(.*?)"); // analyze state Matcher matcher = STATE_CONFIG_PATTERN.matcher(newValue); if (matcher.find()) { String[] values = StringUtils.split(newValue, "&"); HashMap<String, String> keyValueMap = new HashMap<>(); for (String value : values) { keyValueMap.put(StringUtils.substringBefore(value, "="), StringUtils.substringAfter(value, "=")); } Calendar timeValue = Calendar.getInstance(); if (StringUtils.isNotBlank(keyValueMap.get("time"))) { Date dateTime = DateUtils.parseDate(keyValueMap.get("time"), TIME_FORMAT); timeValue.setTime(dateTime); } if ((timeValue.compareTo(pointValue.getTime()) == 0) && StringUtils.equals(keyValueMap.get("value"), pointValue.getString())) { // If state was not changed, trap is not processed. return; } pointValue.setString(keyValueMap.get("value")); pointValue.setTime(timeValue); } else { if (StringUtils.equals(newValue, pointValue.getString())) { // If state was not changed, trap is not processed. return; } pointValue.setString(newValue); pointValue.setTime(Calendar.getInstance()); } // send data Map<String, Date> CallbackURLMap = trapInfo.getCallbackURLMap(); CallbackURLMap.keySet().forEach(key -> new Thread(() -> { sendData(key, trapInfo); }).start()); }
From source file:org.pac4j.oauth.client.PayPalClient.java
@Override protected PayPalProfile extractUserProfile(final String body) { final PayPalProfile profile = new PayPalProfile(); final JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { final String userId = (String) JsonHelper.get(json, "user_id"); profile.setId(StringUtils.substringAfter(userId, "/user/")); for (final String attribute : OAuthAttributesDefinitions.payPalDefinition.getAllAttributes()) { profile.addAttribute(attribute, JsonHelper.get(json, attribute)); }/* w ww . j a va 2s. co m*/ } return profile; }
From source file:org.paxml.bean.EmailTag.java
private String findHost() { if (StringUtils.isBlank(host)) { return "smtp." + StringUtils.substringAfter(from, "@"); } else {// www . j a v a2 s. c o m return host; } }
From source file:org.paxml.launch.InteractivePaxml.java
public void run(String planFile) { printHelp();/* w ww. ja va 2s.c o m*/ println("paxml interactive mode started. Please type paxml tags to execute:"); BufferedReader reader = new BufferedReader(new InputStreamReader(streams.getInputStream())); String line; StringBuilder sb = null; if (StringUtils.isNotBlank(planFile)) { if (log.isInfoEnabled()) { log.info("Running with planfile: " + planFile); } try { LaunchModel model = paxml.executePlanFile(planFile, System.getProperties()); paxml.addStaticConfig(model.getConfig()); properties.putAll(model.getGlobalSettings().getProperties()); } catch (Exception e) { e.printStackTrace(new PrintStream(streams.getOutputStream(true))); } } else { if (log.isInfoEnabled()) { log.info("Running without plan file"); } } Context context = makeNewContext(); while ((line = readLine(reader)) != null) { if (line.equals(CMD_HELP)) { printHelp(); } else if (line.equals(CMD_RESET)) { paxml.callEntityExitListener(context); context = makeNewContext(); sb = null; println("Context reset"); } else if (line.startsWith(CMD_ADD_TAG_LIBRARY)) { String cls = StringUtils.substringAfter(line, " ").trim(); paxml.getParser().addTagLibrary((ITagLibrary) ReflectUtils.createObject(cls, null), false); println("Tag library added: " + cls); } else if (line.equals(CMD_QUIT)) { println("Goodbye"); break; } else if (line.endsWith("\\")) { sb = new StringBuilder(); sb.append(line.substring(0, line.length() - 1)).append("\r\n"); } else if (sb == null) { // execute the line execute(line, context); } else { // execute multiple lines execute(sb.toString(), context); sb = null; } } }
From source file:org.pepstock.jem.ant.ScriptFactory.java
/** * //from www . j a v a 2s .c o m * @param key * @param value * @return * @throws AntException */ private String createDataDescription(String key, String value) throws AntException { String ddName = StringUtils.substringAfter(key, AntKeys.ANT_DATA_DESCRIPTION_PREFIX); if (ddName == null || ddName.trim().length() == 0) { throw new AntException(AntMessage.JEMA005E); } DataDescription dd = new DataDescription(); dd.setName(ddName.trim()); ValueParser.loadDataDescription(dd, value); if (dd.isMultiDataset()) { throw new AntException(AntMessage.JEMA006E, dd.getName(), dd.getDisposition()); } StringBuilder sb = new StringBuilder(); sb.append("<dataDescription"); sb.append(" name=\"").append(dd.getName()).append("\" "); if (dd.isSysout()) { sb.append(" disposition=\"NEW\">"); sb.append(" sysout=\"true\"/>"); } else { sb.append(" disposition=\"").append(dd.getDisposition()).append("\">"); if (!dd.getDatasets().isEmpty()) { DataSet ds = dd.getDatasets().get(0); sb.append("<dataSet"); if (ds.isInline()) { sb.append(">").append(ds.getText().toString()).append("</dataSet>"); } else { if (ds.isGdg()) { sb.append(" name=\"").append(ds.getName()).append("(").append(ds.getOffset()).append(")") .append("\""); } else { sb.append(" name=\"").append(ds.getName()).append("\""); } sb.append("/>"); } } sb.append("</dataDescription>"); } return sb.toString(); }
From source file:org.pepstock.jem.ant.tasks.AntBatchSecurityManager.java
@Override public void checkPermission(Permission perm) { // checks if someone add a security manager if (perm instanceof RuntimePermission && "setSecurityManager".equalsIgnoreCase(perm.getName())) { if (!isAllowedSetSecurityManager()) { LogAppl.getInstance().emit(NodeMessage.JEMC274E); throw new SecurityException(NodeMessage.JEMC274E.toMessage().getMessage()); }//w w w. j ava 2 s .com return; } // this check is necessary to avoid that someone // set jem properties, accessing outside of GFS if (perm instanceof PropertyPermission && "write".equalsIgnoreCase(perm.getActions()) && perm.getName().startsWith("jem")) { LogAppl.getInstance().emit(NodeMessage.JEMC127E); throw new SecurityException(NodeMessage.JEMC127E.toMessage().getMessage()); } // checks is administrator. if true return. if (isAdministrator() || isInternalAction()) { return; } // checks the file access // calling the right method, in according // with the action of permission if (perm instanceof FilePermission) { if ("read".equalsIgnoreCase(perm.getActions())) { checkRead(perm.getName()); } else if ("write".equalsIgnoreCase(perm.getActions())) { checkWrite(perm.getName()); } else if ("delete".equalsIgnoreCase(perm.getActions())) { checkDelete(perm.getName()); } else { checkRead(perm.getName()); } } else if (perm instanceof SocketPermission) { // checks the RMI access. // checks to RMI is not allowed if you're not a admin SocketPermission sperm = (SocketPermission) perm; int port = Parser.parseInt(StringUtils.substringAfter(sperm.getName(), ":"), Integer.MAX_VALUE); int portRmi = Parser.parseInt(System.getProperty(RmiKeys.JEM_RMI_PORT), Integer.MIN_VALUE); // if is going to RMI port and // is not executing JEM code and is not grantor if (port == portRmi && !isInternalAction() && !isGrantor()) { // extracts host name String hostname = StringUtils.substringBefore(sperm.getName(), ":"); try { // gets hostname and localhost String resolved = InetAddress.getByName(hostname).getHostAddress(); String localhost = InetAddress.getLocalHost().getHostAddress(); // if they are equals and the user // desn't have the internal service permission // EXCEPTION!! if (resolved.equalsIgnoreCase(localhost) && !checkBatchPermission(Permissions.INTERNAL_SERVICES)) { LogAppl.getInstance().emit(NodeMessage.JEMC128E); throw new SecurityException(NodeMessage.JEMC128E.toMessage().getMessage()); } } catch (UnknownHostException e) { // if there is an error on resolving the hostname LogAppl.getInstance().emit(NodeMessage.JEMC128E); throw new SecurityException(NodeMessage.JEMC128E.toMessage().getMessage(), e); } } } }
From source file:org.pepstock.jem.ant.tasks.DataSetManager.java
/** * Creates a file wrapper, normalizing the name. That's necessary due to you can write on ANT JCL * both the relative or the absolute file name. * /* w ww .j a v a2 s . com*/ * @param ds dataset instance * @return a file wrapper instance * @throws BuildException if dataPath is null, returns ann exception */ private static FileWrapper getFile(DataSet ds, String disposition) throws BuildException { // gets the data path and checks // if dataset name starts String dataPath = DataPathsContainer.getInstance().getAbsoluteDataPath(ds.getName()); File file = null; String fileName = null; //checks if the Dsname is a absolute file name // if absolute path is equals return the file // otherwise checks datapath if (dataPath != null) { // if name is absolute // creates a new FILE object with full pathname file = new File(ds.getName()); // normalizes using UNIX rules fileName = FilenameUtils.normalize(file.getAbsolutePath(), true); // extract the short name, taking the string after dataPath fileName = StringUtils.substringAfter(fileName, dataPath); // removes the first / of the filename fileName = fileName.substring(1); // we must check if full is correct in disposition NEW (only for new allocation) if (Disposition.NEW.equalsIgnoreCase(disposition)) { try { // checks all paths PathsContainer paths = DataPathsContainer.getInstance().getPaths(fileName); // creates a file with dataPath as parent, plus file name file = new File(paths.getCurrent().getContent(), fileName); } catch (InvalidDatasetNameException e) { throw new BuildException(e); } } } else { // should be relative file = new File(ds.getName()); // normalizes the full path and checks again with the name // if equals means that is absolute because the previuos checks only if it's using the // data paths. here the absolute path IS NOT a data path if (FilenameUtils.normalize(file.getAbsolutePath(), true).equalsIgnoreCase(ds.getName())) { // normalizes using UNIX rules fileName = FilenameUtils.normalize(file.getAbsolutePath(), true); } else { try { // checks all paths PathsContainer paths = DataPathsContainer.getInstance().getPaths(ds.getName()); // is relative! // creates a file with dataPath as parent, plus file name file = new File(paths.getCurrent().getContent(), ds.getName()); // if disposition is not in new allocation and the file with current path doesn't exists, // try to use the old path is exist if (!Disposition.NEW.equalsIgnoreCase(disposition) && !file.exists() && paths.getOld() != null) { file = new File(paths.getOld().getContent(), ds.getName()); } // normalizes using UNIX rules fileName = FilenameUtils.normalize(ds.getName(), true); } catch (InvalidDatasetNameException e) { throw new BuildException(e); } } } return new FileWrapper(file, fileName); }