List of usage examples for org.apache.commons.lang3.math NumberUtils isDigits
public static boolean isDigits(final String str)
Checks whether the String
contains only digit characters.
Null
and empty String will return false
.
From source file:com.alibaba.dubboadmin.web.mvc.governance.WeightsController.java
@RequestMapping("/create") public String create(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception { prepare(request, response, model, "create", "weights"); String addr = request.getParameter("address"); String services = request.getParameter("multiservice"); if (services == null || services.trim().length() == 0) { services = request.getParameter("service"); }/*from w w w. j a va 2 s. com*/ String weight = request.getParameter("weight"); int w = Integer.parseInt(weight); Set<String> addresses = new HashSet<String>(); BufferedReader reader = new BufferedReader(new StringReader(addr)); while (true) { String line = reader.readLine(); if (null == line) break; String[] split = line.split("[\\s,;]+"); for (String s : split) { if (s.length() == 0) continue; String ip = s; String port = null; if (s.indexOf(":") != -1) { ip = s.substring(0, s.indexOf(":")); port = s.substring(s.indexOf(":") + 1, s.length()); if (port.trim().length() == 0) port = null; } if (!IP_PATTERN.matcher(ip).matches()) { model.addAttribute("message", "illegal IP: " + s); model.addAttribute("success", false); model.addAttribute("redirect", "../weights"); return "governance/screen/redirect"; } if (LOCAL_IP_PATTERN.matcher(ip).matches() || ALL_IP_PATTERN.matcher(ip).matches()) { model.addAttribute("message", "local IP or any host ip is illegal: " + s); model.addAttribute("success", false); model.addAttribute("redirect", "../weights"); return "governance/screen/redirect"; } if (port != null) { if (!NumberUtils.isDigits(port)) { model.addAttribute("message", "illegal port: " + s); model.addAttribute("success", false); model.addAttribute("redirect", "../weights"); return "governance/screen/redirect"; } } addresses.add(s); } } Set<String> aimServices = new HashSet<String>(); reader = new BufferedReader(new StringReader(services)); while (true) { String line = reader.readLine(); if (null == line) break; String[] split = line.split("[\\s,;]+"); for (String s : split) { if (s.length() == 0) continue; if (!super.currentUser.hasServicePrivilege(s)) { model.addAttribute("message", getMessage("HaveNoServicePrivilege", s)); model.addAttribute("success", false); model.addAttribute("redirect", "../weights"); return "governance/screen/redirect"; } aimServices.add(s); } } for (String aimService : aimServices) { for (String a : addresses) { Weight wt = new Weight(); wt.setUsername((String) ((BindingAwareModelMap) model).get("operator")); wt.setAddress(Tool.getIP(a)); wt.setService(aimService); wt.setWeight(w); overrideService.saveOverride(OverrideUtils.weightToOverride(wt)); } } model.addAttribute("success", true); model.addAttribute("redirect", "../weights"); return "governance/screen/redirect"; }
From source file:com.moviejukebox.tools.DateTimeTools.java
/** * Convert the string date using DateTools parsing * * @param convertDate/*from w ww . j a va 2 s. c o m*/ * @return */ private static Date convertStringDate(final String convertDate, IDateTimeConfig config) { Date parsedDate = null; String newDate = convertDate.trim(); /* Check to see if the date is only 4 digits and append "01-01" as needed */ if (NumberUtils.isDigits(newDate) && newDate.length() == 4) { newDate = config.isDmyOrder() ? "01-01-" + newDate : newDate + "-01-01"; } try { parsedDate = DateTime.parse(newDate, config).toDate(); LOG.trace("Converted date '{}' using {} order", newDate, (config.isDmyOrder() ? "DMY" : "MDY")); } catch (IllegalArgumentException ex) { LOG.debug("Failed to convert date '{}' using {} order", newDate, (config.isDmyOrder() ? "DMY" : "MDY")); } return parsedDate; }
From source file:com.norconex.collector.http.recrawl.impl.GenericRecrawlableResolver.java
private boolean isRecrawlableFromMinFrequencies(MinFrequency f, PreviousCrawlData prevData) { String value = f.getValue();//from w w w .j a v a2s . c o m if (StringUtils.isBlank(value)) { return true; } if (NumberUtils.isDigits(value)) { DateTime minCrawlDate = new DateTime(prevData.getCrawlDate()); int millis = NumberUtils.toInt(value); minCrawlDate = minCrawlDate.plusMillis(millis); if (minCrawlDate.isBeforeNow()) { if (LOG.isDebugEnabled()) { LOG.debug("Recrawl suggested according to custom " + "directive (min frequency < elapsed " + "time since " + prevData.getCrawlDate() + ") for: " + prevData.getReference()); } return true; } if (LOG.isDebugEnabled()) { LOG.debug("No recrawl suggested according to custom " + "directive (min frequency >= elapsed time since " + prevData.getCrawlDate() + ") for: " + prevData.getReference()); } return false; } SitemapChangeFrequency cf = SitemapChangeFrequency.getChangeFrequency(f.getValue()); return isRecrawlableFromFrequency(cf, prevData, "custom"); }
From source file:com.epam.ngb.cli.manager.command.handler.http.AbstractHTTPCommandHandler.java
/** * Retrieves BiologicalDataItemID for a file from an input String. * If input String might be interpreted as a number, this number will be returned as a result. * If input String isn't a number, method interprets it as a file name and tries to find a file * with such a name in the NGB server and retrieves its ID from a loaded data. * @param strId input String for file identification * @return BiologicalDataItemID of a file * @throws ApplicationException if method fails to find a file */// www.j a va 2 s . c o m protected Long parseFileId(String strId) { if (NumberUtils.isDigits(strId)) { return Long.parseLong(strId); } else { List<BiologicalDataItem> items = loadItemsByName(strId); if (items == null || items.isEmpty()) { throw new ApplicationException(getMessage(ERROR_FILE_NOT_FOUND, strId)); } if (items.size() > 1) { LOGGER.error(getMessage(SEVERAL_RESULTS_FOR_QUERY, strId)); } return items.get(0).getBioDataItemId(); } }
From source file:com.epam.ngb.cli.manager.command.handler.http.AbstractHTTPCommandHandler.java
/** * Loads BiologicalDataItem file from NGB server by an input String. * If input String might be interpreted as a number, item will be loaded by BiologicalDataItemID. * If input String isn't a number, method interprets it as a file name and tries to find a file * with such a name in the NGB server./* w w w . java 2 s .co m*/ * @param strId input String for file identification * @return BiologicalDataItem representing file * @throws ApplicationException if method fails to find a file */ protected BiologicalDataItem loadFileByNameOrBioID(String strId) { if (NumberUtils.isDigits(strId)) { return loadFileByBioID(strId); } else { List<BiologicalDataItem> items = loadItemsByName(strId); if (items == null || items.isEmpty()) { throw new ApplicationException(getMessage(ERROR_FILE_NOT_FOUND, strId)); } if (items.size() > 1) { LOGGER.error(getMessage(SEVERAL_RESULTS_FOR_QUERY, strId)); } return items.get(0); } }
From source file:com.marand.thinkmed.medications.dao.openehr.OpenEhrMedicationsDao.java
private void linkActionsToInstructions(final MedicationOrderComposition composition, final String uid) { for (final MedicationActionAction action : composition.getMedicationDetail().getMedicationAction()) { final LocatableRef actionInstructionId = action.getInstructionDetails().getInstructionId(); if (NumberUtils.isDigits(actionInstructionId.getPath())) { final int instructionIndex = Integer.parseInt(actionInstructionId.getPath()); final MedicationInstructionInstruction instruction = composition.getMedicationDetail() .getMedicationInstruction().get(instructionIndex); final RmPath rmPath = TdoPathable.pathOfItem(composition, instruction); actionInstructionId.setPath(rmPath.getCanonicalString()); final ObjectVersionId objectVersionId = new ObjectVersionId(); objectVersionId.setValue(uid); actionInstructionId.setId(objectVersionId); }//from w w w .j a va 2s .c om } }
From source file:com.xpn.xwiki.internal.filter.output.XWikiDocumentOutputFilterStream.java
private void begin(FilterEventParameters parameters) throws FilterException { DocumentReference documentReference = this.documentEntityResolver.resolve(this.currentEntityReference, getDefaultDocumentReference()); if (this.entity == null) { this.entity = new XWikiDocument(documentReference, this.currentLocale); } else {//from w w w. j a v a 2s. co m this.entity.setDocumentReference(documentReference); this.entity.setLocale(this.currentLocale); } // Find default author DocumentReference defaultAuthorReference; if (this.properties.isAuthorSet()) { defaultAuthorReference = this.properties.getAuthor(); } else { XWikiContext xcontext = xcontextProvider.get(); defaultAuthorReference = xcontext != null ? xcontext.getUserReference() : null; } this.entity.setCreationDate( getDate(WikiDocumentFilter.PARAMETER_CREATION_DATE, this.currentLocaleParameters, null)); this.entity.setCreatorReference(getUserReference(WikiDocumentFilter.PARAMETER_CREATION_AUTHOR, this.currentLocaleParameters, defaultAuthorReference)); this.entity.setDefaultLocale(this.currentDefaultLocale); this.entity.setSyntax(getSyntax(WikiDocumentFilter.PARAMETER_SYNTAX, parameters, null)); this.entity.setParentReference(getEntityReference(WikiDocumentFilter.PARAMETER_PARENT, parameters, null)); this.entity.setCustomClass(getString(WikiDocumentFilter.PARAMETER_CUSTOMCLASS, parameters, null)); this.entity.setTitle(getString(WikiDocumentFilter.PARAMETER_TITLE, parameters, null)); this.entity.setDefaultTemplate(getString(WikiDocumentFilter.PARAMETER_DEFAULTTEMPLATE, parameters, null)); this.entity.setValidationScript(getString(WikiDocumentFilter.PARAMETER_VALIDATIONSCRIPT, parameters, null)); this.entity.setHidden(getBoolean(WikiDocumentFilter.PARAMETER_HIDDEN, parameters, false)); this.entity.setMinorEdit(getBoolean(WikiDocumentFilter.PARAMETER_REVISION_MINOR, parameters, false)); this.entity.setAuthorReference( getUserReference(WikiDocumentFilter.PARAMETER_REVISION_AUTHOR, parameters, defaultAuthorReference)); this.entity.setContentAuthorReference( getUserReference(WikiDocumentFilter.PARAMETER_CONTENT_AUTHOR, parameters, defaultAuthorReference)); String revisions = getString(XWikiWikiDocumentFilter.PARAMETER_JRCSREVISIONS, this.currentLocaleParameters, null); if (revisions != null) { try { this.entity.setDocumentArchive(revisions); } catch (XWikiException e) { throw new FilterException("Failed to set document archive", e); } } if (this.currentVersion != null && this.properties.isVersionPreserved()) { if (VALID_VERSION.matcher(this.currentVersion).matches()) { this.entity.setVersion(this.currentVersion); } else if (NumberUtils.isDigits(this.currentVersion)) { this.entity.setVersion(this.currentVersion + ".1"); } else { // TODO: log something, probably a warning } } this.entity.setDate(getDate(WikiDocumentFilter.PARAMETER_REVISION_DATE, parameters, new Date())); this.entity.setComment(getString(WikiDocumentFilter.PARAMETER_REVISION_COMMENT, parameters, "")); this.entity .setContentUpdateDate(getDate(WikiDocumentFilter.PARAMETER_CONTENT_DATE, parameters, new Date())); // Content if (this.contentListener != null) { // Remember the current rendering context target syntax this.previousTargetSyntax = this.renderingContext.getTargetSyntax(); } if (parameters.containsKey(WikiDocumentFilter.PARAMETER_CONTENT)) { this.entity.setContent(getString(WikiDocumentFilter.PARAMETER_CONTENT, parameters, null)); if (this.contentListener != null) { // Cancel any existing content listener this.currentWikiPrinter = null; this.contentListener.setWrappedListener(null); } } else if (this.contentListener != null) { if (this.properties != null && this.properties.getDefaultSyntax() != null) { this.entity.setSyntax(this.properties.getDefaultSyntax()); } else { // Make sure to set the default syntax if none were provided this.entity.setSyntax(this.entity.getSyntax()); } ComponentManager componentManager = this.componentManagerProvider.get(); String syntaxString = this.entity.getSyntax().toIdString(); if (componentManager.hasComponent(PrintRendererFactory.class, syntaxString)) { PrintRendererFactory rendererFactory; try { rendererFactory = componentManager.getInstance(PrintRendererFactory.class, syntaxString); } catch (ComponentLookupException e) { throw new FilterException(String.format("Failed to find PrintRendererFactory for syntax [%s]", this.entity.getSyntax()), e); } this.currentWikiPrinter = new DefaultWikiPrinter(); ((MutableRenderingContext) this.renderingContext).setTargetSyntax(rendererFactory.getSyntax()); this.contentListener.setWrappedListener(rendererFactory.createRenderer(this.currentWikiPrinter)); } } // Initialize the class getBaseClassOutputFilterStream().setEntity(this.entity.getXClass()); }
From source file:gov.nih.nci.firebird.service.protocol.ProtocolImportDetailServiceBean.java
private Person retrieveInvestigator(ProtocolImportDetail detail, String investigatorExternalId, int column) { if (!NumberUtils.isDigits(investigatorExternalId)) { handleInvalidInvestigatorIdFormat(detail, investigatorExternalId, column); return null; }//from w ww . ja va 2 s. c om Person investigator = lookedUpPersons.get(investigatorExternalId); if (investigator == null) { investigator = lookupInvestigator(detail, investigatorExternalId, column); lookedUpPersons.put(investigatorExternalId, investigator); } return investigator; }
From source file:com.epam.ngb.cli.manager.command.handler.http.AbstractHTTPCommandHandler.java
/** * Retrieves reference ID from an input String. * If input String might be interpreted as a number, this number is assumed to be a BiologicalDataItemID * for a reference and thus a reference is loaded from the server by this BiologicalDataItemID. * If input String isn't a number, method interprets it as a file name, tries to find a reference * with such a name in the NGB server and retrieves its ID from a loaded data. * @param strId input String for reference identification * @return ID of a reference/*from w w w . java 2 s .c o m*/ */ //TODO: remove this method and all connected logic when ID and BiologicalDataItemID are merged on the server protected Long loadReferenceId(String strId) { if (NumberUtils.isDigits(strId)) { BiologicalDataItem reference = loadFileByBioID(strId); return reference.getId(); } else { List<BiologicalDataItem> items = loadItemsByName(strId); checkLoadedItems(strId, items); return items.get(0).getId(); } }
From source file:com.epam.ngb.cli.manager.command.handler.http.AbstractHTTPCommandHandler.java
/** * Retrieves ID for a dataset(project) from an input String. * If input String might be interpreted as a number, this number will be returned as a result. * If input String isn't a number, method interprets it as a dataset name and tries to find a file * with such a name in the NGB server and retrieves its ID from a loaded data. * @param strId input String for dataset identification * @return ID of a dataset/* ww w . j a v a 2 s . c om*/ */ protected Long parseProjectId(String strId) { if (NumberUtils.isDigits(strId)) { return Long.parseLong(strId); } else { Project project = loadProjectByName(strId); return project.getId(); } }