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:com.stratio.ingestion.sink.cassandra.EventParser.java
private static Date parseDate(final String rawValue) { if (StringUtils.isNumeric(rawValue)) { return new Date(Long.parseLong(rawValue)); } else {/*from w w w . j av a 2 s. co m*/ return ISODateTimeFormat.dateOptionalTimeParser().parseDateTime(rawValue).toDate(); } }
From source file:io.stallion.users.OAuthApprovalController.java
public OAuthUserLogin tokenToUser(String accessToken, boolean ignoreExpires) { if (!accessToken.contains("-")) { throw new ClientException("Invalid access token format"); }/*from w ww.ja v a 2s . c o m*/ String[] parts = StringUtils.split(accessToken, "-", 2); if (!StringUtils.isNumeric(parts[0])) { throw new ClientException("Invalid access token format"); } long userId = Long.parseLong(parts[0]); IUser user = UserController.instance().forId(userId); if (user == null) { throw new ClientException("User not found for access token"); } String decrypted = Encrypter.decryptString(user.getEncryptionSecret(), parts[1]); OAuthAccesTokenData data = JSON.parse(decrypted, OAuthAccesTokenData.class); if (data.getUserId() != userId) { throw new ClientException("Invalid access token"); } if (!ignoreExpires && data.getExpires() < mils()) { throw new ClientException("Access token has expired"); } if (Settings.instance().getoAuth().getAlwaysCheckAccessTokenValid()) { OAuthApproval approval = OAuthApprovalController.instance().forId(data.getApprovalId()); if (approval == null || approval.isRevoked() || (!ignoreExpires && approval.getAccessTokenExpiresAt() < mils())) { throw new ClientException("Invalid approval"); } } OAuthUserLogin login = new OAuthUserLogin().setScoped(data.isScoped()).setUser(user) .setApprovalId(data.getApprovalId()).setScopes(data.getScopes()); return login; }
From source file:com.glaf.jbpm.model.Extension.java
public double getDoubleFieldValue(String name) { if (fields != null) { ExtensionField extensionField = fields.get(name); if (extensionField != null && extensionField.getValue() != null) { String value = extensionField.getValue(); if (StringUtils.isNumeric(value)) { return Double.parseDouble(value); }//from w w w .j av a 2 s .co m } } return 0; }
From source file:com.shenit.commons.utils.DataUtils.java
@SuppressWarnings("unchecked") public static <T> Collection<T> parseNumbers(Collection<?> vals, Function<String, T> func) { if (vals == null || vals.isEmpty()) return null; ArrayList<T> results = new ArrayList<T>(); String str;//from www. j a va 2 s . c om for (Object val : vals) { str = DataUtils.toString(val); if (StringUtils.isNumeric(str)) results.add(func.apply(str)); } return (Collection<T>) Arrays.asList(results.toArray()); }
From source file:com.shenit.commons.utils.ShenStrings.java
/** * ?IP// w w w.ja v a2 s.c o m * @param str * @return */ public static boolean isIp(String str) { if (str.indexOf(DELIMITER_DOT) < 0) return false; String[] secs = str.split(DELIMITER_DOT); //we don't support IPv6 yet!! if (secs.length != 4) return false; boolean isIp = true; int ipSec; for (String sec : secs) { if (StringUtils.isNumeric(sec)) { ipSec = Integer.parseInt(sec); isIp = !ValidationUtils.in(ipSec, 0, 255); } if (!isIp) break; } return isIp; }
From source file:com.glaf.dts.util.XmlReader.java
public DataTransfer read(java.io.InputStream inputStream) { DataTransfer tableModel = new DataTransfer(); SAXReader xmlReader = new SAXReader(); try {//from w w w .j a va 2 s . c o m Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); Element element = root.element("entity"); if (element != null) { List<?> attrs = element.attributes(); if (attrs != null && !attrs.isEmpty()) { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); dataMap.put(attr.getName(), attr.getStringValue()); tableModel.addProperty(attr.getName(), attr.getStringValue()); } Tools.populate(tableModel, dataMap); } tableModel.setEntityName(element.attributeValue("name")); tableModel.setPrimaryKey(element.attributeValue("primaryKey")); tableModel.setTableName(element.attributeValue("table")); tableModel.setTitle(element.attributeValue("title")); tableModel.setStopWord(element.attributeValue("stopWord")); tableModel.setPackageName(element.attributeValue("package")); tableModel.setEnglishTitle(element.attributeValue("englishTitle")); tableModel.setFilePrefix(element.attributeValue("filePrefix")); tableModel.setParseType(element.attributeValue("parseType")); tableModel.setParseClass(element.attributeValue("parseClass")); tableModel.setAggregationKeys(element.attributeValue("aggregationKeys")); tableModel.setSplit(element.attributeValue("split")); if (StringUtils.equals(element.attributeValue("insertOnly"), "true")) { tableModel.setInsertOnly("true"); } String startRow = element.attributeValue("startRow"); if (StringUtils.isNotEmpty(startRow) && StringUtils.isNumeric(startRow)) { tableModel.setStartRow(Integer.parseInt(startRow)); } String stopSkipRow = element.attributeValue("stopSkipRow"); if (StringUtils.isNotEmpty(stopSkipRow) && StringUtils.isNumeric(stopSkipRow)) { tableModel.setStopSkipRow(Integer.parseInt(stopSkipRow)); } String batchSize = element.attributeValue("batchSize"); if (StringUtils.isNotEmpty(batchSize) && StringUtils.isNumeric(batchSize)) { tableModel.setBatchSize(Integer.parseInt(batchSize)); } List<?> excludes = element.elements("excludes"); if (excludes != null && excludes.size() > 0) { Iterator<?> iterator = excludes.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); tableModel.addExclude(elem.getStringValue()); } } List<?> rows = element.elements("property"); if (rows != null && rows.size() > 0) { Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); ColumnDefinition field = new ColumnDefinition(); this.readField(elem, field); tableModel.addColumn(field); if (StringUtils.equalsIgnoreCase(tableModel.getPrimaryKey(), field.getColumnName())) { tableModel.setIdColumn(field); } } } } } catch (Exception ex) { throw new RuntimeException(ex); } return tableModel; }
From source file:com.omertron.yamjtrakttv.tools.CompleteMoviesTools.java
/** * Get the season and episode information from the files section for TV * Shows/* w w w . ja v a 2 s . c o m*/ * * @param eVideo * @return */ private static List<Episode> parseTvFiles(Element eVideo) { List<Episode> episodes = new ArrayList<>(); NodeList nlFile = eVideo.getElementsByTagName("file"); if (nlFile.getLength() > 0) { Node nFile; Element eFile; for (int loop = 0; loop < nlFile.getLength(); loop++) { nFile = nlFile.item(loop); if (nFile.getNodeType() == Node.ELEMENT_NODE) { eFile = (Element) nFile; int season = Integer.parseInt(DOMHelper.getValueFromElement(eFile, "season")); int firstPart = Integer.parseInt(eFile.getAttribute("firstPart")); int lastPart = Integer.parseInt(eFile.getAttribute("lastPart")); boolean watched = Boolean.parseBoolean(DOMHelper.getValueFromElement(eFile, "watched")); Date watchedDate; String stringDate = DOMHelper.getValueFromElement(eVideo, "watchedDate"); if (StringUtils.isNumeric(stringDate)) { watchedDate = new Date(Long.parseLong(stringDate)); } else { watchedDate = new Date(); } for (int episode = firstPart; episode <= lastPart; episode++) { episodes.add(new Episode(season, episode, watched, watchedDate)); } } } } return episodes; }
From source file:fredboat.command.music.control.PlayCommand.java
@Override public void onInvoke(Guild guild, TextChannel channel, Member invoker, Message message, String[] args) { if (!invoker.getVoiceState().inVoiceChannel()) { channel.sendMessage(I18n.get(guild).getString("playerUserNotInChannel")).queue(); return;/*from w ww. j av a 2 s .c om*/ } if (!message.getAttachments().isEmpty()) { GuildPlayer player = PlayerRegistry.get(guild); player.setCurrentTC(channel); for (Attachment atc : message.getAttachments()) { player.queue(atc.getUrl(), channel, invoker); } player.setPause(false); return; } if (args.length < 2) { handleNoArguments(guild, channel, invoker, message); return; } //What if we want to select a selection instead? if (args.length == 2 && StringUtils.isNumeric(args[1])) { SelectCommand.select(guild, channel, invoker, message, args); return; } //Search youtube for videos and let the user select a video if (!args[1].startsWith("http")) { try { searchForVideos(guild, channel, invoker, message, args); } catch (RateLimitedException e) { throw new RuntimeException(e); } return; } GuildPlayer player = PlayerRegistry.get(guild); player.setCurrentTC(channel); player.queue(args[1], channel, invoker); player.setPause(false); try { message.delete().queue(); } catch (Exception ignored) { } }
From source file:forge.properties.ForgeProfileProperties.java
private static int getInt(final Properties props, final String propertyKey, final int defaultValue) { final String strValue = props.getProperty(propertyKey, "").trim(); if (StringUtils.isNotBlank(strValue) && StringUtils.isNumeric(strValue)) { return Integer.parseInt(strValue); }//w w w. j a v a2 s . c om return defaultValue; }
From source file:cn.cnic.bigdatalab.flume.sink.mongodb.EventParser.java
public Object parseValue(final FieldDefinition fd, final String stringValue) { if (fd == null || fd.getType() == null) { try {// ww w . j a v a 2s . com return JSON.parse(stringValue); } catch (JSONParseException ex) { // XXX: Default to String log.trace("Could not parse as JSON, defaulting to String: {}", stringValue); return stringValue; } } switch (fd.getType()) { case DOUBLE: return Double.parseDouble(stringValue); case STRING: return stringValue; case OBJECT: case ARRAY: // TODO: should we use customizable array representation? // TODO: should we check that the result is indeed an array or object? return JSON.parse(stringValue); case BINARY: SimpleFieldDefinition sfd = (SimpleFieldDefinition) fd; final String encoding = (sfd.getEncoding() == null) ? DEFAULT_BINARY_ENCODING : sfd.getEncoding().toLowerCase(Locale.ENGLISH); if ("base64".equals(encoding)) { return BaseEncoding.base64().decode(stringValue); } else { throw new UnsupportedOperationException("Unsupported encoding for binary type: " + encoding); } // TODO: case "UNDEFINED": case OBJECTID: return new ObjectId(stringValue); case BOOLEAN: return Boolean.parseBoolean(stringValue); case DATE: DateFormat dateFormat = ((DateFieldDefinition) fd).getDateFormat(); if (dateFormat == null) { if (StringUtils.isNumeric(stringValue)) { return new Date(Long.parseLong(stringValue)); } else { return ISODateTimeFormat.dateOptionalTimeParser().parseDateTime(stringValue).toDate(); } } else { try { return dateFormat.parse(stringValue); } catch (ParseException ex) { // XXX: Default to string log.warn("Could not parse date, defaulting to String: {}", stringValue); return stringValue; } } case NULL: // TODO: Check if this is valid return null; // TODO: case "REGEX": // TODO: case "JAVASCRIPT": // TODO: case "SYMBOL": // TODO: case "JAVASCRIPT_SCOPE": case INT32: return Integer.parseInt(stringValue); case INT64: return Long.parseLong(stringValue); case DOCUMENT: return populateDocument((DocumentFieldDefinition) fd, stringValue); default: throw new UnsupportedOperationException("Unsupported type: " + fd.getType().name()); } }