List of usage examples for org.apache.commons.lang StringUtils isNumeric
public static boolean isNumeric(String str)
Checks if the String contains only unicode digits.
From source file:com.emergya.persistenceGeo.web.RestFoldersAdminController.java
/** * This method saves a folder related with a group * // w ww .j a va 2s. c om * @param group */ @RequestMapping(value = "/persistenceGeo/saveFolderByGroup/{groupId}", method = RequestMethod.POST) public @ResponseBody FolderDto saveFolderByGroup(@PathVariable String groupId, @RequestParam("name") String name, @RequestParam("enabled") String enabled, @RequestParam("isChannel") String isChannel, @RequestParam("isPlain") String isPlain, @RequestParam(value = "parentFolder", required = false) String parentFolder) { try { /* * //TODO: Secure with logged user String username = ((UserDetails) * SecurityContextHolder.getContext() * .getAuthentication().getPrincipal()).getUsername(); */ Long idGroup = Long.decode(groupId); FolderDto rootFolder = foldersAdminService.getRootGroupFolder(idGroup); if (StringUtils.isEmpty(parentFolder) || !StringUtils.isNumeric(parentFolder)) { return saveFolderBy(name, enabled, isChannel, isPlain, rootFolder != null ? rootFolder.getId() : null, null, idGroup); } else { return saveFolderBy(name, enabled, isChannel, isPlain, Long.decode(parentFolder), null, idGroup); } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.redhat.rhn.frontend.xmlrpc.LoggingInvocationProcessor.java
/** * Returns true if the given key contains an 'x' which is the separator * character in the session key./*ww w . j a v a 2 s .c o m*/ * @param key Potential key candidate. * @return true if the given key contains an 'x' which is the separator * character in the session key. */ private boolean potentialSessionKey(String key) { if (key == null || key.equals("")) { return false; } // Get the id String[] keyParts = StringUtils.split(key, 'x'); // make sure the id is numeric and can be made into a Long if (!StringUtils.isNumeric(keyParts[0])) { return false; } return true; }
From source file:eu.eidas.node.auth.connector.AUCONNECTORUtil.java
/** * Checks if the configured QAALevel is greater than minQAALevel and less than maxQAALevel. * * @param qaaLevel The QAA Level to validate. * @return True if the qaaLevel is valid. False otherwise. *///from w ww. ja v a 2s . c o m private boolean isValidQAALevel(final String qaaLevel) { return StringUtils.isNumeric(qaaLevel) && Integer.parseInt(qaaLevel) >= this.getMinQAA() && Integer.parseInt(qaaLevel) <= this.getMaxQAA(); }
From source file:fr.paris.lutece.plugins.extend.modules.statistics.web.StatisticsJspBean.java
/** * Gets the view stats./*from ww w .j a v a 2 s .c o m*/ * * @param request the request * @param response the response * @return the view stats * @throws AccessDeniedException the access denied exception */ public IPluginActionResult getViewStats(HttpServletRequest request, HttpServletResponse response) throws AccessDeniedException { setPageTitleProperty(PROPERTY_VIEW_STATS_PAGE_TITLE); // RESOURCE TYPES ReferenceList listResourceTypes = _resourceTypeService.findAllAsRef(AdminUserService.getLocale(request)); listResourceTypes.addItem(StringUtils.EMPTY, I18nService.getLocalizedString(PROPERTY_LABEL_ALL, request.getLocale())); // EXTENDER TYPES ReferenceList listExtenderTypes = _resourceExtenderService.getExtenderTypes(request.getLocale()); listExtenderTypes.addItem(StringUtils.EMPTY, I18nService.getLocalizedString(PROPERTY_LABEL_ALL, request.getLocale())); // RESOURCE EXTENDER HISTORY FILTER initFilter(request); _filter.setGroupByAttributeName(GROUP_BY_ATTRIBUTE); _filter.setSortedAttributeName(request); _filter.setAscSort(request); // PAGINATOR _strCurrentPageIndex = Paginator.getPageIndex(request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex); _nItemsPerPage = Paginator.getItemsPerPage(request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage); int nNbStats = _statService.getNbStats(_filter); if (StringUtils.isNotBlank(_strCurrentPageIndex) && StringUtils.isNumeric(_strCurrentPageIndex)) { // Define the current page index // If the current page index is > ( nCurrentPageIndex - 1 ) * _nItemsPerPage ), then display the first page index int nCurrentPageIndex = Integer.parseInt(_strCurrentPageIndex); if (((nCurrentPageIndex - 1) * _nItemsPerPage) > nNbStats) { nCurrentPageIndex = 1; } _filter.setItemsPerPage(_nItemsPerPage); _filter.setPageIndex(nCurrentPageIndex); } UrlItem url = new UrlItem(AppPathService.getBaseUrl(request) + JSP_URL_VIEW_STATS); url.addParameter(PARAMETER_SESSION, PARAMETER_SESSION); if (_filter.containsAttributeName()) { url.addParameter(Parameters.SORTED_ATTRIBUTE_NAME, _filter.getSortedAttributeName()); url.addParameter(Parameters.SORTED_ASC, Boolean.toString(_filter.isAscSort())); } IPaginator<ResourceExtenderStat> paginator = new LocalizedDelegatePaginator<ResourceExtenderStat>( _statService.findStats(_filter), _nItemsPerPage, url.getUrl(), Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex, nNbStats, request.getLocale()); Map<String, Object> model = new HashMap<String, Object>(); model.put(MARK_LIST_RESOURCE_TYPES, listResourceTypes); model.put(MARK_LIST_EXTENDER_TYPES, listExtenderTypes); model.put(MARK_FILTER, _filter); model.put(MARK_LIST_STATS, paginator.getPageItems()); model.put(MARK_PAGINATOR, paginator); model.put(MARK_NB_ITEMS_PER_PAGE, Integer.toString(paginator.getItemsPerPage())); model.put(MARK_TOTAL_NUMBERS, _statService.getTotalNumbers(_filter)); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_VIEW_STATS, request.getLocale(), model); IPluginActionResult result = new DefaultPluginActionResult(); result.setHtmlContent(getAdminPage(template.getHtml())); return result; }
From source file:com.ctriposs.rest4j.server.Rest4JServlet.java
private int getParseqThreadPoolSize(ServletConfig servletConfig) { int threadPoolSize; String threadPoolSizeStr = servletConfig.getInitParameter(PAR_SEQ_THREAD_POOL_SIZE); if (StringUtils.isNumeric(threadPoolSizeStr) && !threadPoolSizeStr.isEmpty()) { threadPoolSize = Integer.valueOf(threadPoolSizeStr); } else {//from w w w . ja v a 2 s . c o m final int numCores = Runtime.getRuntime().availableProcessors(); threadPoolSize = numCores + 1; } return threadPoolSize; }
From source file:com.ctrip.infosec.rule.util.Emitter.java
/** * ?Counter/*from w ww. ja v a2 s .com*/ */ public static void emit(RiskFact fact, PolicyExecuteResult counterPolicyExecuteResult) { if (counterPolicyExecuteResult.getRuleExecuteResults() == null || counterPolicyExecuteResult.getRuleExecuteResults().isEmpty()) { String resultCode = counterPolicyExecuteResult.getResultCode(); String resultMessage = counterPolicyExecuteResult.getResultMessage(); if (!"000".equals(resultCode)) { emit(fact, resultCode, resultMessage); } } else { boolean _isAsync = MapUtils.getBoolean(fact.ext, Constants.key_isAsync, false); for (CounterRuleExecuteResult ruleExecuteResult : counterPolicyExecuteResult.getRuleExecuteResults()) { if (StringUtils.isNotBlank(ruleExecuteResult.getRuleNo()) && StringUtils.isNumeric(ruleExecuteResult.getResultCode())) { String ruleNo = ruleExecuteResult.getRuleNo(); int riskLevel = NumberUtils.toInt(ruleExecuteResult.getResultCode(), 0); String riskMessage = ruleExecuteResult.getResultMessage(); String scenes = ruleExecuteResult.getScenes(); if (riskLevel > 0) { Map<String, Object> result = Maps.newHashMap(); result.put(Constants.riskLevel, riskLevel); result.put(Constants.riskMessage, riskMessage); result.put(Constants.async, _isAsync); if (StringUtils.isBlank(scenes)) { if (!_isAsync) { result.put(Constants.ruleType, "N"); fact.results.put(ruleNo, result); } else { result.put(Constants.ruleType, "NA"); fact.results4Async.put(ruleNo, result); } } else { List<String> riskScenes = Splitter.on(",").omitEmptyStrings().trimResults() .splitToList(scenes); result.put(Constants.riskScene, riskScenes); if (!_isAsync) { result.put(Constants.ruleType, "S"); fact.resultsGroupByScene.put(ruleNo, result); } else { result.put(Constants.ruleType, "SA"); fact.resultsGroupByScene4Async.put(ruleNo, result); } } boolean withScene = Constants.eventPointsWithScene.contains(fact.eventPoint); TraceLogger.traceLog("[trace] withScene = " + withScene + ", scenes = [" + (scenes == null ? "" : scenes) + "]"); if (!withScene) { if (StringUtils.isNotBlank(scenes)) { TraceLogger.traceLog(">>>> [" + ruleNo + "] : [???] riskLevel = " + riskLevel + ", riskMessage = " + riskMessage + ", riskScene = [" + scenes + "]"); } else { TraceLogger.traceLog(">>>> [" + ruleNo + "] : riskLevel = " + riskLevel + ", riskMessage = " + riskMessage); } } else if (withScene) { if (StringUtils.isBlank(scenes)) { TraceLogger.traceLog(">>>> [" + ruleNo + "] [?]: [?] riskLevel = " + riskLevel + ", riskMessage = " + riskMessage); } else { TraceLogger.traceLog(">>>> [" + ruleNo + "] [?]: riskLevel = " + riskLevel + ", riskMessage = " + riskMessage + ", riskScene = [" + scenes + "]"); } } } } } } }
From source file:fr.paris.lutece.plugins.mylutece.business.attribute.AttributeComboBox.java
/** * {@inheritDoc}/* ww w . ja v a 2 s .c om*/ */ @Override public List<MyLuteceUserField> getUserFieldsData(String[] values, int nIdUser) { List<MyLuteceUserField> listUserFields = new ArrayList<MyLuteceUserField>(); if (values != null) { for (String strValue : values) { MyLuteceUserField userField = new MyLuteceUserField(); AttributeField attributeField; if ((strValue == null) || strValue.equals(EMPTY_STRING)) { strValue = EMPTY_STRING; attributeField = new AttributeField(); attributeField.setAttribute(this); attributeField.setTitle(EMPTY_STRING); attributeField.setValue(EMPTY_STRING); } else if (StringUtils.isNumeric(strValue)) { int nIdField = Integer.parseInt(strValue); Plugin plugin = PluginService.getPlugin(MyLutecePlugin.PLUGIN_NAME); attributeField = AttributeFieldHome.findByPrimaryKey(nIdField, plugin); } else { attributeField = new AttributeField(); attributeField.setAttribute(this); attributeField.setTitle(strValue); attributeField.setValue(strValue); } userField.setUserId(nIdUser); userField.setAttribute(this); userField.setAttributeField(attributeField); userField.setValue(attributeField.getTitle()); listUserFields.add(userField); } } return listUserFields; }
From source file:com.cloud.tags.TaggedResourceManagerImpl.java
@Override public long getResourceId(String resourceId, ResourceObjectType resourceType) { Class<?> clazz = s_typeMap.get(resourceType); Object entity = _entityMgr.findByUuid(clazz, resourceId); if (entity != null) { return ((InternalIdentity) entity).getId(); }//w w w .ja v a2 s. c o m if (!StringUtils.isNumeric(resourceId)) { throw new InvalidParameterValueException( "Unable to find resource by uuid " + resourceId + " and type " + resourceType); } entity = _entityMgr.findById(clazz, resourceId); if (entity != null) { return ((InternalIdentity) entity).getId(); } throw new InvalidParameterValueException( "Unable to find resource by id " + resourceId + " and type " + resourceType); }
From source file:com.flexive.war.servlet.DownloadServlet.java
@Override public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String uri = FxServletUtils.stripSessionId(URLDecoder.decode( request.getRequestURI().substring(request.getContextPath().length() + BASEURL.length()), "UTF-8")); final FxPK pk; String xpath = null;/*from ww w .j a v a 2s .co m*/ if (uri.startsWith("tree")) { // get PK via tree path final String[] parts = StringUtils.split(uri, "/", 3); if (parts.length != 3 || !"tree".equals(parts[0])) { FxServletUtils.sendErrorMessage(response, "Invalid download request: " + uri); return; } // get tree node by FQN path final FxTreeMode treeMode = "edit".equals(parts[1]) ? FxTreeMode.Edit : FxTreeMode.Live; final long nodeId; try { nodeId = EJBLookup.getTreeEngine().getIdByFQNPath(treeMode, FxTreeNode.ROOT_NODE, "/" + parts[2]); } catch (FxApplicationException e) { FxServletUtils.sendErrorMessage(response, "Failed to resolve file path: " + e.getMessage()); return; } if (nodeId == -1) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } // use content associated with tree node try { pk = EJBLookup.getTreeEngine().getNode(treeMode, nodeId).getReference(); } catch (FxApplicationException e) { FxServletUtils.sendErrorMessage(response, "Failed to load tree node " + nodeId + ": " + e.getMessage()); return; } } else { // get PK if (!uri.startsWith("pk")) { FxServletUtils.sendErrorMessage(response, "Invalid download request: " + uri); return; } try { pk = FxPK.fromString(uri.substring(2, uri.indexOf('/'))); } catch (IllegalArgumentException e) { FxServletUtils.sendErrorMessage(response, "Invalid primary key in download request: " + uri); return; } // extract xpath try { xpath = FxSharedUtils.decodeXPath(uri.substring(uri.indexOf('/') + 1, uri.lastIndexOf('/'))); } catch (IndexOutOfBoundsException e) { // no XPath provided, use default binary XPath } } // load content final FxContent content; try { content = EJBLookup.getContentEngine().load(pk); } catch (FxApplicationException e) { FxServletUtils.sendErrorMessage(response, "Failed to load content: " + e.getMessage()); return; } if (xpath == null) { // get default binary XPath from type final FxType type = CacheAdmin.getEnvironment().getType(content.getTypeId()); if (type.getMainBinaryAssignment() != null) { xpath = type.getMainBinaryAssignment().getXPath(); } else { FxServletUtils.sendErrorMessage(response, "Invalid xpath/filename in download request: " + uri); return; } } final String binaryIdParam = request.getParameter("hintBinaryId"); final long hintBinaryId = StringUtils.isNumeric(binaryIdParam) ? Long.parseLong(binaryIdParam) : -1; // get binary descriptor final BinaryDescriptor descriptor; if (hintBinaryId != -1) { final BinaryDescriptor foundDescriptor = findBinaryDescriptor(content, hintBinaryId); if (foundDescriptor == null) { FxServletUtils.sendErrorMessage(response, "Expected binary ID not present in content" + pk + ": " + hintBinaryId); return; } descriptor = foundDescriptor; } else { try { descriptor = (BinaryDescriptor) content.getValue(xpath).getBestTranslation(); } catch (Exception e) { FxServletUtils.sendErrorMessage(response, "Failed to load binary value: " + e.getMessage()); return; } } // stream content try { response.setContentType(descriptor.getMimeType()); response.setContentLength((int) descriptor.getSize()); if (request.getParameter("inline") == null || "false".equals(request.getParameter("inline"))) { response.setHeader("Content-Disposition", "attachment; filename=\"" + descriptor.getName() + "\";"); } descriptor.download(response.getOutputStream()); } catch (Exception e) { FxServletUtils.sendErrorMessage(response, "Download failed: " + e.getMessage()); //noinspection UnnecessaryReturnStatement return; } finally { response.getOutputStream().close(); } }
From source file:com.impetus.client.mongodb.MongoDBClientFactory.java
@Override protected void onValidation(final String contactNode, final String defaultPort) { if (contactNode != null) { // allow configuration as comma-separated list of host:port // addresses without the default port boolean allAddressesHaveHostAndPort = true; for (String node : contactNode.split(Constants.COMMA)) { if (StringUtils.countMatches(node, Constants.COLON) == 1) { // node is given with hostname and port // count == 1 is to exclude IPv6 addresses if (StringUtils.isNumeric(node.split(Constants.COLON)[1])) { continue; }//www . j av a 2 s .c o m } allAddressesHaveHostAndPort = false; break; } if (allAddressesHaveHostAndPort) { return; } } // fall back to the generic validation which requires the default port // to be set super.onValidation(contactNode, defaultPort); }