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.redhat.rhn.frontend.action.multiorg.SystemEntitlementOrgsAction.java
private ActionErrors updateSubscriptions(Org org, HttpServletRequest request, Entitlement ent, String newCount) {/*from w w w . jav a2 s. c om*/ if (org.getId().equals(OrgFactory.getSatelliteOrg().getId())) { createErrorMessage(request, "org.entitlements.system.defaultorg", null); return null; } ActionErrors errors = new ActionErrors(); //Validate if its a numeric value if (!StringUtils.isNumeric(newCount)) { ValidatorError error = new ValidatorError("softwareEntitlementSubs.invalidInput"); errors.add(RhnValidationHelper.validatorErrorToActionErrors(error)); return errors; } Long count; try { count = Long.parseLong(newCount); if (count < 0) { throw new NumberFormatException(); } } catch (NumberFormatException numEx) { ValidatorError error = new ValidatorError("softwareEntitlementSubs.invalidInput"); errors.add(RhnValidationHelper.validatorErrorToActionErrors(error)); return errors; } // Store/update db UpdateOrgSystemEntitlementsCommand updateCmd = new UpdateOrgSystemEntitlementsCommand(ent, org, count); ValidatorError ve = updateCmd.store(); if (ve != null) { errors.add(RhnValidationHelper.validatorErrorToActionErrors(ve)); } return errors; }
From source file:com.greenline.hrs.admin.web.war.cache.redis.RedisConnConfigController.java
/** * /*from w w w . j av a 2 s . c o m*/ * * @param paramsMap ?,redisid. * @return JSON?, ???. */ @RequestMapping(value = "/del", method = RequestMethod.POST, produces = { "application/json;charset=UTF-8" }) @ResponseBody public String deleteRedisConnection(@RequestBody MultiValueMap<String, String> paramsMap) { String uidStr = paramsMap.getFirst("rid"); //redisid??, if (!StringUtils.isNumeric(uidStr)) { LOG.info(UserResponseConst.ADD_USER_FAIL + uidStr); return JSONResponseUtil.failString(RedisResponseConst.CONNECTION_DEL_ERROR); } redisConnConfService.delete(Long.valueOf(uidStr)); return JSONResponseUtil.successString(RedisResponseConst.CONNECTION_DEL_SUCCESS); }
From source file:com.flexive.faces.javascript.AutoCompleteProvider.java
/** * <p>Submits a query for contents, either by primary key (if a numeric value is given) * or by a prefix match on the caption. The output value has the format</p> * <code>"id.version - caption"</code> * * @param request the current request (injected) * @param rawQuery the query, either a number (matching an instance ID) or a fulltext query * @param typeId the type filter (set to -1 to disable) * @return the autocomplete response/*from w ww. j a va 2 s .c o m*/ * @throws com.flexive.shared.exceptions.FxApplicationException on application errors * @throws java.io.IOException if the response could not be created */ public String pkQuery(HttpServletRequest request, String rawQuery, long typeId) throws FxApplicationException, IOException { // get the actual text query also for "encoded" queries (that include the PK, which we don't need here) final String query = ReferenceQueryInputMapper.getReferencedContent(URLDecoder.decode(rawQuery, "UTF-8")) .getCaption(); final SqlQueryBuilder builder = new SqlQueryBuilder().select("@pk", "caption").orderBy("caption", SortDirection.ASCENDING); // filter by content type if (typeId != -1) { builder.type(typeId); } // prefix search in the caption property builder.orSub().condition("caption", PropertyValueComparator.LIKE, query + "%"); if (StringUtils.isNumeric(query)) { // query by ID builder.condition("id", PropertyValueComparator.EQ, Long.parseLong(query)); } builder.closeSub(); final List<ResponseLine> result = new ArrayList<ResponseLine>(MAX_ITEMS); for (FxResultRow row : builder.maxRows(MAX_ITEMS).getResult().getResultRows()) { final FxPK pk = row.getPk(1); final String caption = row.getString(2); final String value = pk + " - " + caption; final String label = "<div class=\"pkAutoComplete\"><img src=\"" + request.getContextPath() + ThumbnailServlet.getLink(pk, BinaryDescriptor.PreviewSizes.PREVIEW1) + "\"/>" + "<div class=\"caption\">" + caption + "</div>" + "<div class=\"property\">" + pk + "</div>" + "</div>"; result.add(new ResponseLine(value, label)); } return writeAutocompleteResponse(result); }
From source file:fr.paris.lutece.plugins.appointment.modules.resource.service.workflow.TaskSetAppointmentResource.java
/** * {@inheritDoc}/*from w ww. ja va2 s . c om*/ */ @Override public void processTask(int nIdResourceHistory, HttpServletRequest request, Locale locale) { ResourceHistory resourceHistory = _resourceHistoryService.findByPrimaryKey(nIdResourceHistory); TaskSetAppointmentResourceConfig config = _taskSetAppointmentResourceConfigService .findByPrimaryKey(this.getId()); if (config == null) { return; } String strIdResource = request.getParameter(PARAMETER_ID_RESOURCE + config.getIdFormResourceType()); if (StringUtils.isNotEmpty(strIdResource)) { Appointment appointment = AppointmentHome.findByPrimaryKey(resourceHistory.getIdResource()); AppointmentResource appResource = AppointmentResourceHome .findByPrimaryKey(appointment.getIdAppointment(), config.getIdFormResourceType()); if (appResource != null) { appResource.setIdResource(strIdResource); AppointmentResourceHome.update(appResource); } else { appResource = new AppointmentResource(); appResource.setIdAppointment(appointment.getIdAppointment()); appResource.setIdAppointmentFormResourceType(config.getIdFormResourceType()); appResource.setIdResource(strIdResource); AppointmentResourceHome.insert(appResource); } AppointmentFormResourceType formResourceType = AppointmentFormResourceTypeHome .findByPrimaryKey(config.getIdFormResourceType()); if (formResourceType.getIsAppointmentAdminUser() && StringUtils.isNumeric(strIdResource)) { int nIdAdminUser = Integer.parseInt(strIdResource); if (appointment.getIdAppointment() != nIdAdminUser) { appointment.setIdAdminUser(nIdAdminUser); AppointmentHome.update(appointment); } } if (formResourceType.getIsLocation()) { IResource resource = ResourceService.getInstance().getResource(strIdResource, formResourceType.getResourceTypeName()); if ((resource != null) && StringUtils.isNotEmpty(resource.getResourceName())) { appointment.setLocation(resource.getResourceName()); AppointmentHome.update(appointment); } } SetAppointmentResourceHistory history = new SetAppointmentResourceHistory(); history.setIdHistory(nIdResourceHistory); history.setIdAppointment(appResource.getIdAppointment()); history.setIdFormResourceType(appResource.getIdAppointmentFormResourceType()); history.setIdResource(appResource.getIdResource()); SetAppointmentResourceHistoryHome.create(history); } }
From source file:com.hpe.application.automation.bamboo.tasks.RunFromAlmTaskConfigurator.java
public void validate(@NotNull final ActionParametersMap params, @NotNull final ErrorCollection errorCollection) { super.validate(params, errorCollection); I18nBean textProvider = getI18nBean(); params.put(ALM_SERVER, trimEnd(params.getString(ALM_SERVER), '/')); if (StringUtils.isEmpty(params.getString(ALM_SERVER))) { errorCollection.addError(ALM_SERVER, textProvider.getText("Alm.error.ALMServerIsEmpty")); }/*ww w . j av a2 s . co m*/ if (StringUtils.isEmpty(params.getString(USER_NAME))) { errorCollection.addError(USER_NAME, textProvider.getText("Alm.error.userNameIsEmpty")); } if (StringUtils.isEmpty(params.getString(DOMAIN))) { errorCollection.addError(DOMAIN, textProvider.getText("Alm.error.domainIsEmpty")); } if (StringUtils.isEmpty(params.getString(PROJECT))) { errorCollection.addError(PROJECT, textProvider.getText("Alm.error.projectIsEmpty")); } if (StringUtils.isEmpty(params.getString(TESTS_PATH))) { errorCollection.addError(TESTS_PATH, textProvider.getText("Alm.error.testsetIsEmpty")); } String timeoutParameter = params.getString(TIMEOUT); if (!StringUtils.isEmpty(timeoutParameter)) { if (!StringUtils.isNumeric(timeoutParameter) || Integer.parseInt(timeoutParameter) < 0 | Integer.parseInt(timeoutParameter) > 30) { errorCollection.addError(TIMEOUT, textProvider.getText("Alm.error.timeoutIsNotCorrect")); } } }
From source file:com.mikenimer.familydam.services.photos.ThumbnailService.java
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws SlingServletException, IOException { if (ResourceUtil.isNonExistingResource(request.getResource())) { throw new ResourceNotFoundException("No data to render."); }//from w w w . jav a 2 s. co m try { Session session = request.getResourceResolver().adaptTo(Session.class); Node parentNode = session.getNode(request.getResource().getPath()); Resource resource = request.getResource(); // first see if the etag header exists and we can skip processing. if (checkAndSetCacheHeaders(request, response, resource)) return; // check for a size selector int width = -1; int height = -1; //-1 means ignore and only set the width to resize final String[] selectors = request.getRequestPathInfo().getSelectors(); if (selectors != null && selectors.length > 0) { final String selector = selectors[selectors.length - 1].toLowerCase().trim(); if (selector.startsWith("w:")) { width = Integer.parseInt(selector.substring(2)); } if (selector.startsWith("h:")) { height = Integer.parseInt(selector.substring(2)); } } // check cache first if (checkForCachedImage(request, response)) return; //resize image //InputStream stream = node.getProperty("jcr:data").getBinary().getStream(); InputStream stream = resource.adaptTo(InputStream.class); int orientation = 1; if (stream != null) { try { Node n = parentNode.getNode("metadata"); if (n != null) { String _orientation = n.getProperty("orientation").getString(); if (StringUtils.isNumeric(_orientation)) { orientation = new Integer(_orientation); } } } catch (Exception ex) { } BufferedImage bi = ImageIO.read(stream); BufferedImage scaledImage = getScaledImage(bi, orientation, width, height); // cache the image long modTime = System.currentTimeMillis(); imageCache.put(request.getPathInfo(), scaledImage); timeGeneratedCache.put(request.getPathInfo(), modTime); //return the image response.setContentType("image/png"); response.setHeader(HttpConstants.HEADER_LAST_MODIFIED, new Long(modTime).toString()); //write bytes and png thumbnail ImageIO.write(scaledImage, "png", response.getOutputStream()); stream.close(); response.getOutputStream().flush(); } } catch (Exception ex) { // return original file. Resource resource = request.getResource(); InputStream stream = resource.adaptTo(InputStream.class); response.setContentType(resource.getResourceMetadata().getContentType()); response.setContentLength(new Long(resource.getResourceMetadata().getContentLength()).intValue()); //write bytes OutputStream out = response.getOutputStream(); byte[] buffer = new byte[1024]; while (true) { int bytesRead = stream.read(buffer); if (bytesRead < 0) break; out.write(buffer, 0, bytesRead); } stream.close(); response.getOutputStream().flush(); } }
From source file:com.greenline.guahao.web.module.home.controllers.mobile.MobileHealthTopicController.java
@MethodRemark(value = "remark=?? id=?id") @RequestMapping(value = "/mobile/jkx/view/{id}") public String view(ModelMap map, @PathVariable("id") String id) { if (!StringUtils.isNumeric(id)) { map.put("message", "????"); return MobileConstants.M_ERROR; }/*www. ja va 2s .co m*/ HealthTopicsDO healthTopicsDO = healthTopicsManager.getHealthTopicsById(Integer.valueOf(id)); if (null == healthTopicsDO) { map.put("message", "????"); return MobileConstants.M_ERROR; } List<HealthTopicsContentDO> contentList = healthTopicsManager.queryShortVideosList(healthTopicsDO.getId()); if (null != contentList) { List<HealthTopicsContentDO> videosList = new ArrayList<HealthTopicsContentDO>(); List<HealthTopicsContentDO> articleList = new ArrayList<HealthTopicsContentDO>(); for (HealthTopicsContentDO healthTopicsContentDO : contentList) { if (healthTopicsContentDO.getType() == 0) { videosList.add(healthTopicsContentDO); } else if (healthTopicsContentDO.getType() == 1) { articleList.add(healthTopicsContentDO); } } map.put("videosList", videosList); map.put("articleList", articleList); } int count = healthTopicsManager.getHealthTopicsCount(); map.put("count", count); map.put("topic", healthTopicsDO); return "mobile/jkx/jkx_detail"; }
From source file:com.hmsinc.epicenter.model.util.ModelUtils.java
/** * Checks a zipcode for validity./*from www. ja va 2 s .c o m*/ * * @param zipcode * @return * @throws InvalidZipcodeException */ public static String validateZipcode(String zipcode) throws InvalidZipcodeException { String newZip = null; if (zipcode != null) { final String cleanedZip = zipcode.length() >= 5 ? zipcode.substring(0, 5) : zipcode; if (StringUtils.isNumeric(cleanedZip) && cleanedZip.length() == 5) { newZip = cleanedZip; } else { throw new InvalidZipcodeException("Invalid zipcode in message (was: " + zipcode + ")"); } } return newZip; }
From source file:com.impetus.client.redis.RedisClientFactory.java
@Override protected Object createPoolOrConnection() { logger.info("Initializing Redis connection pool"); final byte WHEN_EXHAUSTED_FAIL = 0; PersistenceUnitMetadata puMetadata = kunderaMetadata.getApplicationMetadata() .getPersistenceUnitMetadata(getPersistenceUnit()); Properties props = puMetadata.getProperties(); String contactNode = null;//w ww . ja v a2 s.com String defaultPort = null; String password = null; String maxActivePerNode = null; String maxIdlePerNode = null; String minIdlePerNode = null; String maxTotal = null; String txTimeOut = null; if (externalProperties != null) { contactNode = (String) externalProperties.get(PersistenceProperties.KUNDERA_NODES); defaultPort = (String) externalProperties.get(PersistenceProperties.KUNDERA_PORT); password = (String) externalProperties.get(PersistenceProperties.KUNDERA_PASSWORD); maxActivePerNode = (String) externalProperties.get(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_ACTIVE); maxIdlePerNode = (String) externalProperties.get(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_IDLE); minIdlePerNode = (String) externalProperties.get(PersistenceProperties.KUNDERA_POOL_SIZE_MIN_IDLE); maxTotal = (String) externalProperties.get(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_TOTAL); txTimeOut = (String) externalProperties.get(PersistenceProperties.KUNDERA_TRANSACTION_TIMEOUT); } if (contactNode == null) { contactNode = RedisPropertyReader.rsmd.getHost() != null ? RedisPropertyReader.rsmd.getHost() : (String) props.get(PersistenceProperties.KUNDERA_NODES); } if (defaultPort == null) { defaultPort = RedisPropertyReader.rsmd.getPort() != null ? RedisPropertyReader.rsmd.getPort() : (String) props.get(PersistenceProperties.KUNDERA_PORT); } if (password == null) { password = RedisPropertyReader.rsmd.getPassword() != null ? RedisPropertyReader.rsmd.getPassword() : (String) props.get(PersistenceProperties.KUNDERA_PASSWORD); } if (maxActivePerNode == null) { maxActivePerNode = props.getProperty(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_ACTIVE); } if (maxIdlePerNode == null) { maxIdlePerNode = props.getProperty(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_IDLE); } if (minIdlePerNode == null) { minIdlePerNode = props.getProperty(PersistenceProperties.KUNDERA_POOL_SIZE_MIN_IDLE); } if (maxTotal == null) { maxTotal = props.getProperty(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_TOTAL); } if (txTimeOut == null) { txTimeOut = props.getProperty(PersistenceProperties.KUNDERA_TRANSACTION_TIMEOUT); } JedisPoolConfig poolConfig = onPoolConfig(WHEN_EXHAUSTED_FAIL, maxActivePerNode, maxIdlePerNode, minIdlePerNode, maxTotal); JedisPool pool = null; onValidation(contactNode, defaultPort); if (poolConfig != null) { if (password != null) { pool = new JedisPool(poolConfig, contactNode, Integer.parseInt(defaultPort), txTimeOut != null && StringUtils.isNumeric(txTimeOut) ? Integer.parseInt(txTimeOut) : -1, password); } else { pool = new JedisPool(poolConfig, contactNode, Integer.parseInt(defaultPort), txTimeOut != null && StringUtils.isNumeric(txTimeOut) ? Integer.parseInt(txTimeOut) : -1); } return pool; } else { // Jedis connection = new Jedis(contactNode, // Integer.valueOf(defaultPort)); // if (password != null) // { // // connection.auth(password); // } // connection.connect(); // Connection to made available at the time of getConnection(). YCSB // performance fixes and ideally it is needed at that time only. // No need to cache it at factory level as needed to managed within // entity manager boundary! return null; } }
From source file:net.mindengine.oculus.frontend.service.runs.JdbcTestRunDAO.java
/** * Collecting all the conditions/*from w w w. j ava 2 s . c om*/ * * @param filter * @return * @throws IOException */ @SuppressWarnings("unchecked") public SqlSearchCondition createCondition(SearchFilter filter) throws IOException { SqlSearchCondition condition = new SqlSearchCondition(); // TestName String testName = filter.getTestCaseName(); if (testName != null && !testName.isEmpty()) { testName = testName.trim(); // checking whether it is an id of test or just a name if (StringUtils.isNumeric(testName)) { // The id of a test was provided condition.append(condition.createSimpleCondition(false, "t.id", testName)); } else { if (testName.contains(",")) { condition.append(condition.createArrayCondition(testName, "t.name", "tr.name")); } else { condition.append(condition.createSimpleCondition(testName, true, "t.name", "tr.name")); } } } // TestRun Statuses List<String> statuses = (List<String>) filter.getTestCaseStatusList(); if (statuses != null && statuses.size() > 0) { String statusColumns[] = new String[statuses.size() * 2]; int j = 0; for (int i = 0; i < statuses.size(); i++) { j = i * 2; String value = statuses.get(i); statusColumns[j] = "tr.status"; statusColumns[j + 1] = value; } condition.append(condition.createSimpleCondition(false, statusColumns)); } // TestRun Reason String reason = filter.getTestRunReason(); if (reason != null && !reason.isEmpty()) { reason = "*" + reason + "*"; condition.append(condition.createSimpleCondition(reason, true, "tr.reasons")); } // Root Project Id { String parentProject = filter.getRootProject(); if (parentProject != null && !parentProject.isEmpty()) { // checking whether it is an id of project or just a name if (StringUtils.isNumeric(parentProject)) { Long projectId = Long.parseLong(parentProject); if (projectId > 0) { // The id of a project was provided condition.append(condition.createSimpleCondition(false, "pp.id", parentProject)); } } } } // Project Name { String project = filter.getProject(); if (project != null && !project.isEmpty()) { // checking whether it is an id of project or just a name if (StringUtils.isNumeric(project)) { // The id of a project was provided condition.append(condition.createSimpleCondition(false, "p.id", project)); } else { if (project.contains(",")) { condition.append(condition.createArrayCondition(project, "p.name")); } else { condition.append(condition.createSimpleCondition(project, true, "p.name")); } } } } // Suite Run Name { String suiteRunName = filter.getSuite(); if (suiteRunName != null && !suiteRunName.isEmpty()) { if (suiteRunName.contains(",")) { if (StringUtils.isNumeric(suiteRunName.replace(",", ""))) { condition.append(condition.createArrayCondition(suiteRunName, "sr.id")); } else { condition.append(condition.createArrayCondition(suiteRunName, "sr.name")); } } else { if (StringUtils.isNumeric(suiteRunName)) { condition.append(condition.createSimpleCondition(suiteRunName, true, "sr.id")); } else { condition.append(condition.createSimpleCondition(suiteRunName, true, "sr.name")); } } } } // Suite Run Start Time { String dateAfter = filter.getSuiteRunTimeAfter(); if (dateAfter != null && !dateAfter.isEmpty()) { if (!dateAfter.contains(":")) { dateAfter += " 00:00:00"; } // Checking whether the string is in date format try { Timestamp.valueOf(dateAfter); condition.append("tr.start_time >= '" + dateAfter + "'"); } catch (Exception ex) { ex.printStackTrace(); } } String dateBefore = filter.getSuiteRunTimeBefore(); if (dateBefore != null && !dateBefore.isEmpty()) { if (!dateBefore.contains(":")) { dateBefore += " 00:00:00"; } // Checking whether the string is in date format try { Timestamp.valueOf(dateBefore); condition.append("tr.start_time <= '" + dateBefore + "'"); } catch (Exception ex) { ex.printStackTrace(); } } } // Suite Run Parameters { String suiteRunParameters = filter.getSuiteRunParameters(); if (suiteRunParameters != null && !suiteRunParameters.isEmpty()) { // Parsing the suiteRunParameters template; Properties prop = new Properties(); prop.load(new StringReader(suiteRunParameters)); for (Entry<Object, Object> property : prop.entrySet()) { condition.append(condition.createSimpleCondition( "*" + property.getKey() + "<v>" + property.getValue() + "*", true, "sr.parameters")); } } } // Suite Run Agent { String suiteRunAgent = filter.getSuiteRunAgent(); if (suiteRunAgent != null && !suiteRunAgent.isEmpty()) { if (suiteRunAgent.contains(",")) { condition.append(condition.createArrayCondition(suiteRunAgent, "sr.agent_name")); } else { condition.append(condition.createSimpleCondition(suiteRunAgent, true, "sr.agent_name")); } } } // User designer { String designer = filter.getUserDesigner(); if (designer != null && !designer.isEmpty()) { if (designer.contains(",")) { if (StringUtils.isNumeric(designer.replace(",", ""))) { condition.append(condition.createArrayCondition(designer, "ud.id")); } else { condition.append(condition.createArrayCondition(designer, "ud.login", "ud.name")); } } else { // checking whether it is an id of project or just a name if (StringUtils.isNumeric(designer)) { // The id of a project was provided condition.append(condition.createSimpleCondition(false, "ud.id", designer)); } else { condition.append(condition.createSimpleCondition(designer, true, "ud.login", "ud.name")); } } } } // User runner { String runner = filter.getUserRunner(); if (runner != null && !runner.isEmpty()) { if (runner.contains(",")) { if (StringUtils.isNumeric(runner.replace(",", ""))) { condition.append(condition.createArrayCondition(runner, "ur.id")); } else { condition.append(condition.createArrayCondition(runner, "ur.login", "ur.name")); } } else { // checking whether it is an id of project or just a name if (StringUtils.isNumeric(runner)) { // The id of a project was provided condition.append(condition.createSimpleCondition(false, "ur.id", runner)); } else { condition.append(condition.createSimpleCondition(runner, true, "ur.login", "ur.name")); } } } } // Issue String issueName = filter.getIssue(); if (issueName != null && !issueName.isEmpty()) { if (issueName.contains(",")) { condition.append(condition.createArrayCondition(issueName, "iss.name", "iss.link")); } else { condition.append(condition.createSimpleCondition(issueName, true, "iss.name", "iss.link")); } } return condition; }