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.ijuru.kwibuka.WordSequence.java
/** * Formats this sequence as a string// ww w .j a v a2 s .co m * @return the string */ public String format() { StringBuilder sb = new StringBuilder(); boolean previousWasNumeric = false; for (String token : this) { boolean isNumeric = StringUtils.isNumeric(token); if (sb.length() > 0 && !(isNumeric && previousWasNumeric)) { sb.append("-"); } sb.append(token); previousWasNumeric = isNumeric; } return sb.toString(); }
From source file:minor.commodity.CommodityQuote.java
@Override public void validate() { if (StringUtils.isEmpty(getCticker())) { addFieldError("cticker", "Commodity Quote cannot be blank"); }/*from w w w .j a va2 s.c om*/ if (StringUtils.isNumeric(getCticker())) { addFieldError("cticker", "Commodity Quote cannot be numeric"); } if (StringUtils.length(getCticker()) > 12) { addFieldError("cticker", "Invalid Ticker length"); } }
From source file:controller.Parameter.java
/** * Validates if parameter isn't empty, set number to true to check if it's a * string/*w w w. ja v a 2 s . co m*/ * * @param parameter * @param number * @return * @throws ParameterException * @throws MisformedParameterException */ public String validate(String parameter, boolean number) throws ParameterException { if (parameter == null || parameter.equals("")) { ParameterException exception = new ParameterException("Missing a parameter"); throw exception; } else if (!StringUtils.isNumeric(parameter) && number) { throw new ParameterException("Input should be numeric"); } else { return parameter; } }
From source file:cn.vlabs.clb.api.document.DocPair.java
public DocPair(int docid, String version) throws InvalidArgument { this.docid = docid; if (StringUtils.isNumeric(version)) { this.version = version; } else if (LATEST_VERSION.equals(version)) { this.version = LATEST_VERSION; } else {//from www . ja va 2 s . c o m throw new InvalidArgument(ErrorCode.INVALID_ARGUMENT, "The version argument should be Integer.toString() or \"latest\", but you input '" + version + "'."); } }
From source file:ch.cyberduck.core.PermissionOverwrite.java
public PermissionOverwrite fromOctal(final String input) { if (StringUtils.isBlank(input)) { return null; }// w ww . j a v a 2 s. c o m if (StringUtils.length(input) != 3) { return null; } if (!StringUtils.isNumeric(input)) { return null; } this.user.parse(input.charAt(0)); this.group.parse(input.charAt(1)); this.other.parse(input.charAt(2)); return this; }
From source file:badminton.common.Util.StringUtil.java
/** * <p>/*w w w . ja v a 2 s . c om*/ * Checks if the String contains only unicode digits. An empty String * (length()=0) will return <code>true</code>. * </p> * * @param str * the String to check, may be null * @return <code>true</code> if only contains digits, and is non-null */ public static boolean isNumeric(final String str) { return StringUtils.isNumeric(str); }
From source file:mesclasses.controller.PageController.java
public static final void markAsHour(TextField field) { field.textProperty().addListener((observable, oldValue, newValue) -> { if (StringUtils.isBlank(newValue)) { return; }/*from w w w. j a v a2s . co m*/ if (!StringUtils.isNumeric(newValue.substring(newValue.length() - 1))) { field.setText(newValue.substring(0, newValue.length() - 1)); return; } if (newValue.length() > 2) { field.setText(oldValue); return; } if (Integer.parseInt(newValue) > 23) { field.setText("23"); } }); }
From source file:edu.usu.sdl.openstorefront.core.view.DateParam.java
public DateParam(String input) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss"); try {/*from w w w .jav a 2 s . c o m*/ date = sdf.parse(input); } catch (ParseException e) { sdf = new SimpleDateFormat("yyyy-MM-dd"); try { date = sdf.parse(input); } catch (ParseException ex) { sdf = new SimpleDateFormat("MM/dd/yyyy"); try { date = sdf.parse(input); } catch (ParseException exc) { if (StringUtils.isNumeric(input)) { try { date = new Date(Long.parseLong(input)); } catch (Exception exception) { //Don't throw error here it's to low level. (it will get wrapped several times) //if the date is not expected to be null handle error there. log.log(Level.FINE, MessageFormat.format("Unsupport date format: {0}", input)); } } else { log.log(Level.FINE, MessageFormat.format("Unsupport date format: {0}", input)); } } } } }
From source file:com.omertron.traileraddictapi.tools.TrailerAddictParser.java
public static List<Trailer> getTrailers(URL url) { Document doc;//from w ww . j a v a 2 s.c o m List<Trailer> trailers = new ArrayList<Trailer>(); try { LOG.trace("Attempting to get trailer XML from {}", url.toString()); doc = DOMHelper.getEventDocFromUrl(url.toString()); } catch (TrailerAddictException ex) { LOG.trace("Exception processing document: {}", url.toString(), ex); return trailers; } NodeList nlTrailers = doc.getElementsByTagName("trailer"); Node nTrailer; Element eTrailer; Trailer trailer; for (int loop = 0; loop < nlTrailers.getLength(); loop++) { nTrailer = nlTrailers.item(loop); if (nTrailer.getNodeType() == Node.ELEMENT_NODE) { eTrailer = (Element) nTrailer; trailer = new Trailer(); trailer.setCombinedTitle(DOMHelper.getValueFromElement(eTrailer, "title")); trailer.setLink(DOMHelper.getValueFromElement(eTrailer, "link")); String trailerId = DOMHelper.getValueFromElement(eTrailer, "trailer_id"); if (StringUtils.isNumeric(trailerId)) { trailer.setTrailerId(Integer.parseInt(trailerId)); } trailer.setPublishDate(DOMHelper.getValueFromElement(eTrailer, "pubDate")); trailer.addEmbed(DOMHelper.getValueFromElement(eTrailer, "embed")); // Simple API stuff here trailer.setTrailerTitle(DOMHelper.getValueFromElement(eTrailer, "video_title")); trailer.setDescription(DOMHelper.getValueFromElement(eTrailer, "description")); trailer.setFilmTitle(DOMHelper.getValueFromElement(eTrailer, "film")); trailer.addEmbed(TrailerSize.STANDARD, DOMHelper.getValueFromElement(eTrailer, "embed_standard")); trailer.addEmbed(TrailerSize.SMALL, DOMHelper.getValueFromElement(eTrailer, "embed_small")); trailer.addEmbed(TrailerSize.MEDIUM, DOMHelper.getValueFromElement(eTrailer, "embed_medium")); trailer.addEmbed(TrailerSize.LARGE, DOMHelper.getValueFromElement(eTrailer, "embed_large")); trailer.setDirectors(DOMHelper.getValueFromElement(eTrailer, "director")); trailer.setWriters(DOMHelper.getValueFromElement(eTrailer, "writer")); trailer.setCast(DOMHelper.getValueFromElement(eTrailer, "cast")); trailer.setStudio(DOMHelper.getValueFromElement(eTrailer, "studio")); trailer.setReleaseDate(DOMHelper.getValueFromElement(eTrailer, "release_date")); // Add the trailer to the list trailers.add(trailer); } } LOG.trace("Found {} trailers for {}", trailers.size(), url.toString()); return trailers; }
From source file:foam.nanos.auth.email.EmailVerificationWebAgent.java
@Override public void execute(X x) { String message = "Your email has now been verified."; PrintWriter out = x.get(PrintWriter.class); DAO userDAO = (DAO) x.get("localUserDAO"); EmailTokenService emailToken = (EmailTokenService) x.get("emailToken"); HttpServletRequest request = x.get(HttpServletRequest.class); HttpServletResponse response = x.get(HttpServletResponse.class); String token = request.getParameter("token"); String userId = request.getParameter("userId"); String redirect = request.getParameter("redirect"); User user = (User) userDAO.find(Long.valueOf(userId)); try {/*from ww w . j a v a 2 s. c om*/ if (token == null || "".equals(token)) { throw new Exception("Token not found"); } if ("".equals(userId) || !StringUtils.isNumeric(userId)) { throw new Exception("User not found."); } if (user.getEmailVerified()) { throw new Exception("Email already verified."); } emailToken.processToken(x, user, token); } catch (Throwable t) { message = "Problem verifying your email.<br>" + t.getMessage(); } finally { if (config_ == null) { config_ = EnvironmentConfigurationBuilder.configuration().resources().resourceLoaders() .add(new TypedResourceLoader("dao", new DAOResourceLoader(x, (String) user.getGroup()))) .and().and().build(); } EmailTemplate emailTemplate = DAOResourceLoader.findTemplate(x, "verify-email-link", (String) user.getGroup()); JtwigTemplate template = JtwigTemplate.inlineTemplate(emailTemplate.getBody(), config_); JtwigModel model = JtwigModel.newModel(Collections.<String, Object>singletonMap("msg", message)); out.write(template.render(model)); if (!redirect.equals("null")) { try { response.addHeader("REFRESH", "2;URL=" + redirect); } catch (Exception e) { e.printStackTrace(); } } } }