List of usage examples for org.apache.commons.lang3 StringUtils isNumeric
public static boolean isNumeric(final CharSequence cs)
Checks if the CharSequence contains only Unicode digits.
From source file:org.hscieripple.common.service.AbstractHSCIEService.java
protected Long convertPatientIdToLong(String patientId) { boolean nullOrEmpty = StringUtils.isBlank(patientId); boolean numeric = StringUtils.isNumeric(patientId); return (nullOrEmpty || !numeric) ? null : Long.valueOf(patientId); }
From source file:org.igov.service.business.action.task.core.ActionTaskService.java
public String getSeparator(String sID_BP, String nASCI_Spliter) { if (nASCI_Spliter == null) { return String.valueOf(Character.toChars(DEFAULT_REPORT_FIELD_SPLITTER)); }/*from w w w . j a va2s . co m*/ if (!StringUtils.isNumeric(nASCI_Spliter)) { LOG.error("ASCI code is not a number {}", nASCI_Spliter); throw new ActivitiObjectNotFoundException( "Statistics for the business task with name '" + sID_BP + "' not found. Wrong splitter.", Task.class); } return String.valueOf(Character.toChars(Integer.valueOf(nASCI_Spliter))); }
From source file:org.imsglobal.lti.toolProvider.ResourceLink.java
private boolean checkValueType(Outcome ltiOutcome, List<String> supportedTypes) { if (supportedTypes == null) { supportedTypes = new ArrayList<String>(); String[] supportedTypesArray = StringUtils.split(",", StringUtils.replace(/* w w w. j a v a2 s. c o m*/ (this.getSetting("ext_ims_lis_resultvalue_sourcedids", EXT_TYPE_DECIMAL)).toLowerCase(), " ", "")); for (String t : supportedTypesArray) { supportedTypes.add(t); } } String type = ltiOutcome.getType(); String value = ltiOutcome.getValue(); // Check whether the type is supported or there is no value boolean ok = supportedTypes.contains(type) || (value.length() <= 0); if (!ok) { // Convert numeric values to decimal if (type.equals(EXT_TYPE_PERCENTAGE)) { if (value.substring(value.length()).equals("%")) { value = value.substring(0, value.length() - 1); } ok = StringUtils.isNumeric(value) && (Double.valueOf(value) >= 0) && (Double.valueOf(value) <= 100); if (ok) { ltiOutcome.setValue(String.valueOf(Double.valueOf(value) / 100)); ltiOutcome.setType(EXT_TYPE_DECIMAL); } } else if (type.equals(EXT_TYPE_RATIO)) { String[] parts = StringUtils.split(value, '/'); ok = (parts.length == 2) && StringUtils.isNumeric(parts[0]) && StringUtils.isNumeric(parts[1]) && (Double.valueOf(parts[0]) >= 0) && (Double.valueOf(parts[1]) > 0); if (ok) { ltiOutcome.setValue(String.valueOf(Double.valueOf(parts[0]) / Double.valueOf(parts[1]))); ltiOutcome.setType(EXT_TYPE_DECIMAL); } // Convert letter_af to letter_af_plus or text } else if (type.equals(EXT_TYPE_LETTER_AF)) { if (supportedTypes.contains(EXT_TYPE_LETTER_AF_PLUS)) { ok = true; ltiOutcome.setType(EXT_TYPE_LETTER_AF_PLUS); } else if (supportedTypes.contains(EXT_TYPE_TEXT)) { ok = true; ltiOutcome.setType(EXT_TYPE_TEXT); } // Convert letter_af_plus to letter_af or text } else if (type.equals(EXT_TYPE_LETTER_AF_PLUS)) { if (supportedTypes.contains(EXT_TYPE_LETTER_AF) && (value.length() == 1)) { ok = true; ltiOutcome.setType(EXT_TYPE_LETTER_AF); } else if (supportedTypes.contains(EXT_TYPE_TEXT)) { ok = true; ltiOutcome.setType(EXT_TYPE_TEXT); } // Convert text to decimal } else if (type == EXT_TYPE_TEXT) { ok = StringUtils.isNumeric(value) && (Double.valueOf(value) >= 0) && (Double.valueOf(value) <= 1); if (ok) { ltiOutcome.setType(EXT_TYPE_DECIMAL); } else if (value.substring(value.length() - 1).equals("%")) { value = value.substring(0, -1); ok = StringUtils.isNumeric(value) && (Double.valueOf(value) >= 0) && (Double.valueOf(value) <= 100); if (ok) { if (supportedTypes.contains(EXT_TYPE_PERCENTAGE)) { ltiOutcome.setType(EXT_TYPE_PERCENTAGE); } else { ltiOutcome.setValue(String.valueOf(Double.valueOf(value) / 100)); ltiOutcome.setType(EXT_TYPE_DECIMAL); } } } } } return ok; }
From source file:org.jbpm.formModeler.core.config.FormSerializationManagerImpl.java
public Field deserializeField(Form form, Node nodeField, Map<String, Properties> resources) throws Exception { if (!nodeField.getNodeName().equals(NODE_FIELD)) return null; Field field = new Field(); field.setId(Long.valueOf(nodeField.getAttributes().getNamedItem(ATTR_ID).getNodeValue())); field.setFieldName(nodeField.getAttributes().getNamedItem(ATTR_NAME).getNodeValue()); field.setPosition(Integer.parseInt(nodeField.getAttributes().getNamedItem(ATTR_POSITION).getNodeValue())); field.setFieldType(//from www . j ava 2 s . c om fieldTypeManager.getTypeByCode(nodeField.getAttributes().getNamedItem(ATTR_TYPE).getNodeValue())); Node bag = nodeField.getAttributes().getNamedItem(ATTR_BAG_TYPE); if (bag != null) { field.setBag(bag.getNodeValue()); } NodeList fieldPropsNodes = nodeField.getChildNodes(); for (int j = 0; j < fieldPropsNodes.getLength(); j++) { Node nodeFieldProp = fieldPropsNodes.item(j); if (nodeFieldProp.getNodeName().equals(NODE_PROPERTY)) { String propName = nodeFieldProp.getAttributes().getNamedItem(ATTR_NAME).getNodeValue(); String value = StringEscapeUtils .unescapeXml(nodeFieldProp.getAttributes().getNamedItem(ATTR_VALUE).getNodeValue()); if (propName != null && value != null) { if ("fieldRequired".equals(propName)) { field.setFieldRequired(Boolean.valueOf(value)); } else if ("groupWithPrevious".equals(propName)) { field.setGroupWithPrevious(Boolean.valueOf(value)); } else if ("height".equals(propName)) { field.setHeight(value); } else if ("labelCSSClass".equals(propName)) { field.setLabelCSSClass(value); } else if ("labelCSSStyle".equals(propName)) { field.setLabelCSSStyle(value); } else if ("label".equals(propName)) { field.setLabel(deserializeI18nEntrySet(value)); } else if ("errorMessage".equals(propName)) { field.setErrorMessage(deserializeI18nEntrySet(value)); } else if ("title".equals(propName)) { field.setTitle(deserializeI18nEntrySet(value)); } else if ("readonly".equals(propName)) { field.setReadonly(Boolean.valueOf(value)); } else if ("size".equals(propName)) { if (!StringUtils.isEmpty(value) && StringUtils.isNumeric(value)) field.setSize(Long.valueOf(value)); } else if ("formula".equals(propName)) { field.setFormula(value); } else if ("rangeFormula".equals(propName)) { field.setRangeFormula(value); } else if ("pattern".equals(propName)) { field.setPattern(value); } else if ("maxlength".equals(propName)) { if (!StringUtils.isEmpty(value) && StringUtils.isNumeric(value)) field.setMaxlength(Long.valueOf(value)); } else if ("styleclass".equals(propName)) { field.setStyleclass(value); } else if ("cssStyle".equals(propName)) { field.setCssStyle(value); } else if ("tabindex".equals(propName)) { if (!StringUtils.isEmpty(value) && StringUtils.isNumeric(value)) field.setTabindex(Long.valueOf(value)); } else if ("accesskey".equals(propName)) { field.setAccesskey(value); } else if ("isHTML".equals(propName)) { field.setIsHTML(Boolean.valueOf(value)); } else if ("htmlContent".equals(propName)) { field.setHtmlContent(deserializeHMLI18nEntrySet(value)); } else if ("hideContent".equals(propName)) { field.setHideContent(Boolean.valueOf(value)); } else if ("defaultValueFormula".equals(propName)) { field.setDefaultValueFormula(value); } else if ("defaultSubform".equals(propName)) { field.setDefaultSubform(value); } else if ("previewSubform".equals(propName)) { field.setPreviewSubform(value); } else if ("tableSubform".equals(propName)) { field.setTableSubform(value); } else if ("newItemText".equals(propName)) { field.setNewItemText(deserializeI18nEntrySet(value)); } else if ("addItemText".equals(propName)) { field.setAddItemText(deserializeI18nEntrySet(value)); } else if ("cancelItemText".equals(propName)) { field.setCancelItemText(deserializeI18nEntrySet(value)); } else if ("deleteItems".equals(propName)) { field.setDeleteItems(Boolean.valueOf(value)); } else if ("updateItems".equals(propName)) { field.setUpdateItems(Boolean.valueOf(value)); } else if ("visualizeItems".equals(propName)) { field.setVisualizeItem(Boolean.valueOf(value)); } else if ("hideCreateItem".equals(propName)) { field.setHideCreateItem(Boolean.valueOf(value)); } else if ("expanded".equals(propName)) { field.setExpanded(Boolean.valueOf(value)); } else if ("enableTableEnterData".equals(propName)) { field.setEnableTableEnterData(Boolean.valueOf(value)); } else if ("inputBinding".equals(propName)) { field.setInputBinding(value); } else if ("outputBinding".equals(propName)) { field.setOutputBinding(value); } else if ("customFieldType".equals(propName)) { field.setCustomFieldType(value); } else if ("param1".equals(propName)) { field.setParam1(value); } else if ("param2".equals(propName)) { field.setParam2(value); } else if ("param3".equals(propName)) { field.setParam3(value); } else if ("param4".equals(propName)) { field.setParam4(value); } else if ("param5".equals(propName)) { field.setParam5(value); } else if ("fieldClass".equals(propName)) { field.getFieldType().setFieldClass(value); } else if ("onChangeScript".equals(propName)) { field.setOnChangeScript(value); } } } } if (resources != null) { field.setTitle(new I18nSet()); field.setLabel(new I18nSet()); field.setErrorMessage(new I18nSet()); if (resources.containsKey("default")) { resources.put(localeManager.getDefaultLang(), resources.remove("default")); } for (String lang : resources.keySet()) { Properties props = resources.get(lang); String value = getFieldProperty(form.getName(), field.getFieldName(), "title", props); if (!StringUtils.isEmpty(value)) field.getTitle().setValue(lang, value); value = getFieldProperty(form.getName(), field.getFieldName(), "label", props); if (!StringUtils.isEmpty(value)) field.getLabel().setValue(lang, value); value = getFieldProperty(form.getName(), field.getFieldName(), "errorMessage", props); if (!StringUtils.isEmpty(value)) field.getErrorMessage().setValue(lang, value); } } return field; }
From source file:org.jbpm.formModeler.core.processing.fieldHandlers.mocks.SubformFinderServiceMock.java
@Override public Form getFormByPath(String formPath, String ctxUID) { if (!StringUtils.isEmpty(formPath) && StringUtils.isNumeric(formPath)) { Form result = testForms.get(Long.valueOf(formPath)); if (result != null) { return result; }//from w ww .j a va 2s . c o m } return new Form(); }
From source file:org.jraf.irondad.handler.quote.QuoteHandler.java
@Override public void handleChannelMessage(Connection connection, String channel, String fromNickname, String text, List<String> textAsList, Message message, HandlerContext handlerContext) throws Exception { DbManager dbManager = getDbManager(channel, handlerContext); String displayText;/*w ww .j a v a 2 s. c om*/ if (textAsList.size() == 1) { // Random Quote randomQuote = dbManager.getRandom(channel); if (randomQuote == null) { displayText = "No quotes currently in db."; } else { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US); displayText = "\"" + randomQuote.text + "\" - " + sdf.format(randomQuote.date) + " (#" + randomQuote.id + ")"; } } else if (textAsList.size() == 2) { if (textAsList.get(1).startsWith("#")) { // Find quote by id String id = textAsList.get(1); if (id.length() < 2) { displayText = "Could not find this quote."; } else { id = id.substring(1); if (!StringUtils.isNumeric(id)) { displayText = "Could not find this quote."; } else { long idLong = Long.valueOf(id); Quote quote = dbManager.getQuote(idLong); if (quote == null) { displayText = "Could not find this quote."; } else { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US); displayText = "\"" + quote.text + "\" - " + sdf.format(quote.date) + " (#" + quote.id + ")"; } } } } else { // Find quote by text search String query = textAsList.get(1); Quote quote = dbManager.getQuote(query); if (quote == null) { displayText = "Could not find this quote."; } else { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US); displayText = "\"" + quote.text + "\" - " + sdf.format(quote.date) + " (#" + quote.id + ")"; } } } else { // New quote long latestQuoteDate = dbManager.getLatestQuoteDate(channel); if (System.currentTimeMillis() - latestQuoteDate < MIN_DELAY_BETWEEN_QUOTES) { // Throttled displayText = "Try again in a bit."; } else { // Check for black list String nameUserHost = message.origin.toFormattedString(); boolean blackListed = false; QuoteHandlerConfig quoteHandlerConfig = (QuoteHandlerConfig) handlerContext.getHandlerConfig(); for (String item : quoteHandlerConfig.getBlackList()) { if (nameUserHost.matches(item)) { if (Config.LOGD) Log.d(TAG, "handleChannelMessage " + nameUserHost + " matches " + item + " - blacklisted"); blackListed = true; break; } } if (blackListed) { displayText = "Did not add quote."; } else { // Add the new quote long id = dbManager.insert(channel, message.origin.toFormattedString(), text.substring(text.indexOf(' ') + 1)); switch ((int) id) { case DbManager.ERR_SQL_PROBLEM: displayText = "Could not add quote."; break; case DbManager.ERR_QUOTE_ALREADY_EXISTS: displayText = "This quote already exists!"; break; default: displayText = "Quote #" + id + " added."; break; } } } } connection.send(Command.PRIVMSG, channel, displayText); }
From source file:org.jraf.irondad.protocol.Command.java
public static Command from(String commandStr) { if (StringUtils.isNumeric(commandStr)) { // Reply (numeric command) return from(Integer.valueOf(commandStr)); }//from w w w .jav a 2s . co m // Message (string command) Command res = sCommandByName.get(commandStr); if (res == null) return UNKNOWN; return res; }
From source file:org.kawanfw.commons.client.http.HttpHostPartsExtractor.java
/** * Constructor/*from ww w . ja v a 2 s. c o m*/ * @param httpHost A HTTP Host in the format "http://www.site.com:8080" */ public HttpHostPartsExtractor(String httpHost) { if (httpHost == null) { throw new IllegalArgumentException("httpHost can not be null!"); } if (!httpHost.startsWith("http://") && !httpHost.startsWith("https://")) { throw new IllegalArgumentException( "httpHost must start with \"http://\" or \"https://\". passed httpUrl is invalid: " + this.httpHost); } String hostname = StringUtils.substringAfter(httpHost, "://"); if (hostname.contains("/")) { throw new IllegalArgumentException("httpHost can not contain / separator"); } if (hostname.contains(":")) { String portStr = StringUtils.substringAfter(hostname, ":"); if (!StringUtils.isNumeric(portStr)) { throw new IllegalArgumentException("port is not numeric: " + httpHost); } } this.httpHost = httpHost; }
From source file:org.kawanfw.sql.api.client.RemoteDriverUtil.java
/** * Create a Proxy instance from a Proxy.toString() representation * Example: HTTP @ www.kawansoft.com/195.154.226.82:8080 * @param proxyToString the proxy in Proxy.toString() format * @return the build proxy//from w ww . j a v a 2s. c o m */ public static Proxy buildProxy(String proxyToString) { if (proxyToString == null) { throw new NullPointerException("ip is null!"); } if (!proxyToString.contains(" @ ")) { throw new IllegalArgumentException("Malformed Proxy.toString() format: @ separator is missing."); } // Get the type String type = StringUtils.substringBefore(proxyToString, " @ "); if (type == null) { throw new IllegalArgumentException("Malformed Proxy.toString() format: no Type"); } type = type.trim(); debug("Proxy.Type.DIRECT: " + Proxy.Type.DIRECT.toString()); if (!type.equals(Proxy.Type.DIRECT.toString()) && !type.equals(Proxy.Type.HTTP.toString()) && !type.equals(Proxy.Type.SOCKS.toString())) { throw new IllegalArgumentException( "Malformed Proxy.toString() format: Type does not contain DIRECT / HTTP / SOCKS: " + type + ":"); } String hostname = null; String portStr = null; int port = 0; if (proxyToString.contains("@ /")) { // Case 1 : HTTP @ /195.154.226.82:8080 // no hostname IP only hostname = StringUtils.substringBetween(proxyToString, "/", ":"); } else { // Case 2 : HTTP @ localhost/127.0.0.1:8080 // hostname followed by ip or /subaddress hostname = StringUtils.substringBetween(proxyToString, " @ ", "/"); String ip = StringUtils.substringBetween(proxyToString, "/", ":"); // if ip string is in IP format, dont take in account the ip after / // If not, following / is the hostname if (validateIpFormat(ip)) { hostname = StringUtils.substringBetween(proxyToString, " @ ", "/"); } else { hostname = StringUtils.substringBetween(proxyToString, " @ ", ":"); } } portStr = StringUtils.substringAfter(proxyToString, ":"); if (StringUtils.isNumeric(portStr)) { port = Integer.parseInt(portStr); } else { throw new IllegalArgumentException( "Malformed Proxy.toString() format: does not contain numeric port: " + proxyToString); } Proxy proxy = new Proxy(Type.valueOf(type), new InetSocketAddress(hostname, port)); return proxy; }
From source file:org.kie.workbench.common.forms.migration.legacy.services.impl.FormSerializationManagerImpl.java
public Field deserializeField(Node nodeField) throws Exception { if (!nodeField.getNodeName().equals(NODE_FIELD)) { return null; }/*from w ww . j a v a 2 s.co m*/ Field field = new Field(); field.setId(Long.valueOf(nodeField.getAttributes().getNamedItem(ATTR_ID).getNodeValue())); field.setFieldName(nodeField.getAttributes().getNamedItem(ATTR_NAME).getNodeValue()); field.setPosition(Integer.parseInt(nodeField.getAttributes().getNamedItem(ATTR_POSITION).getNodeValue())); field.setFieldType( fieldTypeManager.getTypeByCode(nodeField.getAttributes().getNamedItem(ATTR_TYPE).getNodeValue())); Node bag = nodeField.getAttributes().getNamedItem(ATTR_BAG_TYPE); if (bag != null) { field.setBag(bag.getNodeValue()); } NodeList fieldPropsNodes = nodeField.getChildNodes(); for (int j = 0; j < fieldPropsNodes.getLength(); j++) { Node nodeFieldProp = fieldPropsNodes.item(j); if (nodeFieldProp.getNodeName().equals(NODE_PROPERTY)) { String propName = nodeFieldProp.getAttributes().getNamedItem(ATTR_NAME).getNodeValue(); String value = StringEscapeUtils .unescapeXml(nodeFieldProp.getAttributes().getNamedItem(ATTR_VALUE).getNodeValue()); if (propName != null && value != null) { if ("fieldRequired".equals(propName)) { field.setFieldRequired(Boolean.valueOf(value)); } else if ("groupWithPrevious".equals(propName)) { field.setGroupWithPrevious(Boolean.valueOf(value)); } else if ("height".equals(propName)) { field.setHeight(value); } else if ("labelCSSClass".equals(propName)) { field.setLabelCSSClass(value); } else if ("labelCSSStyle".equals(propName)) { field.setLabelCSSStyle(value); } else if ("label".equals(propName)) { field.setLabel(deserializeI18nEntrySet(value)); } else if ("errorMessage".equals(propName)) { field.setErrorMessage(deserializeI18nEntrySet(value)); } else if ("title".equals(propName)) { field.setTitle(deserializeI18nEntrySet(value)); } else if ("readonly".equals(propName)) { field.setReadonly(Boolean.valueOf(value)); } else if ("size".equals(propName)) { if (!StringUtils.isEmpty(value) && StringUtils.isNumeric(value)) { field.setSize(Long.valueOf(value)); } } else if ("formula".equals(propName)) { field.setFormula(value); } else if ("rangeFormula".equals(propName)) { field.setRangeFormula(value); } else if ("pattern".equals(propName)) { field.setPattern(value); } else if ("maxlength".equals(propName)) { if (!StringUtils.isEmpty(value) && StringUtils.isNumeric(value)) { field.setMaxlength(Long.valueOf(value)); } } else if ("styleclass".equals(propName)) { field.setStyleclass(value); } else if ("cssStyle".equals(propName)) { field.setCssStyle(value); } else if ("tabindex".equals(propName)) { if (!StringUtils.isEmpty(value) && StringUtils.isNumeric(value)) { field.setTabindex(Long.valueOf(value)); } } else if ("accesskey".equals(propName)) { field.setAccesskey(value); } else if ("isHTML".equals(propName)) { field.setIsHTML(Boolean.valueOf(value)); } else if ("htmlContent".equals(propName)) { field.setHtmlContent(deserializeI18nEntrySet(value)); } else if ("hideContent".equals(propName)) { field.setHideContent(Boolean.valueOf(value)); } else if ("defaultValueFormula".equals(propName)) { field.setDefaultValueFormula(value); } else if ("defaultSubform".equals(propName)) { field.setDefaultSubform(value); } else if ("previewSubform".equals(propName)) { field.setPreviewSubform(value); } else if ("tableSubform".equals(propName)) { field.setTableSubform(value); } else if ("newItemText".equals(propName)) { field.setNewItemText(deserializeI18nEntrySet(value)); } else if ("addItemText".equals(propName)) { field.setAddItemText(deserializeI18nEntrySet(value)); } else if ("cancelItemText".equals(propName)) { field.setCancelItemText(deserializeI18nEntrySet(value)); } else if ("deleteItems".equals(propName)) { field.setDeleteItems(Boolean.valueOf(value)); } else if ("updateItems".equals(propName)) { field.setUpdateItems(Boolean.valueOf(value)); } else if ("visualizeItems".equals(propName)) { field.setVisualizeItem(Boolean.valueOf(value)); } else if ("hideCreateItem".equals(propName)) { field.setHideCreateItem(Boolean.valueOf(value)); } else if ("expanded".equals(propName)) { field.setExpanded(Boolean.valueOf(value)); } else if ("enableTableEnterData".equals(propName)) { field.setEnableTableEnterData(Boolean.valueOf(value)); } else if ("inputBinding".equals(propName)) { field.setInputBinding(value); } else if ("outputBinding".equals(propName)) { field.setOutputBinding(value); } else if ("customFieldType".equals(propName)) { field.setCustomFieldType(value); } else if ("param1".equals(propName)) { field.setParam1(value); } else if ("param2".equals(propName)) { field.setParam2(value); } else if ("param3".equals(propName)) { field.setParam3(value); } else if ("param4".equals(propName)) { field.setParam4(value); } else if ("param5".equals(propName)) { field.setParam5(value); } else if ("fieldClass".equals(propName)) { field.getFieldType().setFieldClass(value); } else if ("onChangeScript".equals(propName)) { field.setOnChangeScript(value); } else if ("movedToForm".equals(propName) && value != null) { field.setMovedToForm(value); } else if ("sourceLink".equals(propName) && value != null) { field.setSourceLink(value); } } } } return field; }