List of usage examples for org.apache.commons.lang3 StringUtils trim
public static String trim(final String str)
Removes control characters (char <= 32) from both ends of this String, handling null by returning null .
The String is trimmed using String#trim() .
From source file:com.ottogroup.bi.asap.component.operator.executor.OperatorExecutor.java
/** * Returns true if the referenced component is a subscriber to this source * @param subscriberId//from w ww.j ava 2 s .c om * @return * @throws RequiredInputMissingException */ public boolean isSubscriber(final String subscriberId) throws RequiredInputMissingException { /////////////////////////////////////////////////////////////////////////// // validate input if (StringUtils.isBlank(subscriberId)) throw new RequiredInputMissingException("Missing required subscriber identifier"); // /////////////////////////////////////////////////////////////////////////// return this.subscriberMailboxes.containsKey(StringUtils.trim(StringUtils.lowerCase(subscriberId))); }
From source file:com.ottogroup.bi.spqr.metrics.MetricsHandler.java
/** * {@link JmxReporter#stop() Stops} the referenced {@link JmxReporter} but keeps it referenced * @param id/*from ww w.ja v a2 s. c o m*/ */ public void stopJmxReporter(final String id) { String key = StringUtils.lowerCase(StringUtils.trim(id)); JmxReporter jmxReporter = this.jmxReporters.get(key); if (jmxReporter != null) { jmxReporter.stop(); } }
From source file:com.ottogroup.bi.spqr.pipeline.MicroPipelineManagerTest.java
/** * Test case for {@link MicroPipelineManager#executePipeline(MicroPipelineConfiguration)} being provided a * valid configuration twice which leads to a {@link NonUniqueIdentifierException} *//*from w w w. j a va 2 s .co m*/ @Test public void testExecutePipeline_withValidConfigurationTwice() throws Exception { MicroPipelineConfiguration cfg = new MicroPipelineConfiguration(); cfg.setId("testExecutePipeline_withValidConfiguration"); MicroPipeline pipeline = Mockito.mock(MicroPipeline.class); Mockito.when(pipeline.getId()).thenReturn(cfg.getId()); MicroPipelineFactory factory = Mockito.mock(MicroPipelineFactory.class); Mockito.when(factory.instantiatePipeline(cfg, executorService)).thenReturn(pipeline); MicroPipelineManager manager = new MicroPipelineManager("id", factory, executorService); Assert.assertEquals("Values must be equal", StringUtils.lowerCase(StringUtils.trim(cfg.getId())), manager.executePipeline(cfg)); Assert.assertEquals("Values must be equal", 1, manager.getNumOfRegisteredPipelines()); Mockito.verify(factory).instantiatePipeline(cfg, executorService); try { manager.executePipeline(cfg); Assert.fail("A pipeline for that identifier already exists"); } catch (NonUniqueIdentifierException e) { // expected } }
From source file:com.devicehive.service.UserService.java
@Transactional(propagation = Propagation.REQUIRED) public UserVO updateUser(@NotNull Long id, UserUpdate userToUpdate, UserRole role) { UserVO existing = userDao.find(id);//w w w. j a v a 2 s. co m if (existing == null) { logger.error("Can't update user with id {}: user not found", id); throw new NoSuchElementException(Messages.USER_NOT_FOUND); } if (userToUpdate == null) { return existing; } if (userToUpdate.getLogin() != null) { final String newLogin = StringUtils.trim(userToUpdate.getLogin().orElse(null)); final String oldLogin = existing.getLogin(); Optional<UserVO> withSuchLogin = userDao.findByName(newLogin); if (withSuchLogin.isPresent() && !withSuchLogin.get().getId().equals(id)) { throw new ActionNotAllowedException(Messages.DUPLICATE_LOGIN); } existing.setLogin(newLogin); final String googleLogin = StringUtils.isNotBlank(userToUpdate.getGoogleLogin().orElse(null)) ? userToUpdate.getGoogleLogin().orElse(null) : null; final String facebookLogin = StringUtils.isNotBlank(userToUpdate.getFacebookLogin().orElse(null)) ? userToUpdate.getFacebookLogin().orElse(null) : null; final String githubLogin = StringUtils.isNotBlank(userToUpdate.getGithubLogin().orElse(null)) ? userToUpdate.getGithubLogin().orElse(null) : null; if (googleLogin != null || facebookLogin != null || githubLogin != null) { Optional<UserVO> userWithSameIdentity = userDao.findByIdentityName(oldLogin, googleLogin, facebookLogin, githubLogin); if (userWithSameIdentity.isPresent()) { throw new ActionNotAllowedException(Messages.DUPLICATE_IDENTITY_LOGIN); } } existing.setGoogleLogin(googleLogin); existing.setFacebookLogin(facebookLogin); existing.setGithubLogin(githubLogin); } if (userToUpdate.getPassword() != null) { if (userToUpdate.getOldPassword() != null && StringUtils.isNotBlank(userToUpdate.getOldPassword().orElse(null))) { final String hash = passwordService.hashPassword(userToUpdate.getOldPassword().orElse(null), existing.getPasswordSalt()); if (!hash.equals(existing.getPasswordHash())) { logger.error("Can't update user with id {}: incorrect password provided", id); throw new ActionNotAllowedException(Messages.INCORRECT_CREDENTIALS); } } else if (role == UserRole.CLIENT) { logger.error("Can't update user with id {}: old password required", id); throw new ActionNotAllowedException(Messages.OLD_PASSWORD_REQUIRED); } if (StringUtils.isEmpty(userToUpdate.getPassword().orElse(null))) { logger.error("Can't update user with id {}: password required", id); throw new IllegalParametersException(Messages.PASSWORD_REQUIRED); } String salt = passwordService.generateSalt(); String hash = passwordService.hashPassword(userToUpdate.getPassword().orElse(null), salt); existing.setPasswordSalt(salt); existing.setPasswordHash(hash); } if (userToUpdate.getStatus() != null || userToUpdate.getRole() != null) { if (role != UserRole.ADMIN) { logger.error( "Can't update user with id {}: users eith the 'client' role are only allowed to change their password", id); throw new HiveException(Messages.INVALID_USER_ROLE, FORBIDDEN.getStatusCode()); } else if (userToUpdate.getRoleEnum() != null) { existing.setRole(userToUpdate.getRoleEnum()); } else { existing.setStatus(userToUpdate.getStatusEnum()); } } if (userToUpdate.getData() != null) { existing.setData(userToUpdate.getData().orElse(null)); } hiveValidator.validate(existing); return userDao.merge(existing); }
From source file:com.shenit.commons.utils.HttpUtils.java
/** * Get?/*from w w w. ja va2s . co m*/ * * @param url * ? * @return */ public static String getAsString(String url) { HttpGet request = new HttpGet(url); HttpClientBuilder clientBuilder = HttpClientBuilder.create(); CloseableHttpClient client = clientBuilder.build(); LOG.info("[getAsString] execute url >> {}", url); try { CloseableHttpResponse resp = client.execute(request); int status = resp.getStatusLine().getStatusCode(); if (status == 200) { String result = EntityUtils.toString(resp.getEntity(), ENC_UTF8); LOG.info("[getAsString] execute result for {} >> {}", url, result); return StringUtils.trim(result); } else { LOG.error("execute with incorrect status code >> {}", status); } } catch (IOException e) { LOG.error("execute with exception >> {}", e.getMessage()); } return null; }
From source file:de.micromata.tpsb.doc.parser.japa.ParserUtil.java
/** * Looks for // comments above given source text * //w w w .ja v a 2 s. com * @param sourceText the source as a text * @param lineNo the line number to look at * @return null if none found */ public static String lookupInlineCode(String sourceText, int lineNo) { if (sourceText == null) { return null; } String[] lines = StringUtils.split(sourceText); if (lines == null || lines.length < lineNo) { return null; } String c1 = StringUtils.trim(lines[lineNo - 1]); if (c1.startsWith("//") == true) { return c1.substring(2); } return null; }
From source file:com.tech.utils.CustomCollectionUtil.java
/** * Converts comma separated value string to set of long values * /*from w w w .j a va 2s.c om*/ * @param csvString * @param seperator * @return itemSet */ public static List<Long> convertStringToList(String csvStr, String fieldSeperator) { List<Long> itemSet = new ArrayList<Long>(); if (StringUtils.isNotEmpty(csvStr) && StringUtils.isNotBlank(csvStr)) { String[] itemsArray = StringUtils.split(csvStr, fieldSeperator); if (itemsArray != null && itemsArray.length > 0) { for (int i = 0; i < itemsArray.length; i++) { if (StringUtils.isNotEmpty(itemsArray[i]) && StringUtils.isNotBlank(itemsArray[i])) { itemSet.add(Long.valueOf(StringUtils.trim(itemsArray[i]))); } } } } return itemSet; }
From source file:com.ottogroup.bi.spqr.pipeline.MicroPipelineManager.java
/** * Shuts down the referenced pipeline/* w w w. j a v a2s. c om*/ * @param pipelineId */ public String shutdownPipeline(final String pipelineId) { String id = StringUtils.lowerCase(StringUtils.trim(pipelineId)); MicroPipeline pipeline = this.pipelines.get(id); if (pipeline != null) { pipeline.shutdown(); this.pipelines.remove(id); if (logger.isDebugEnabled()) logger.debug("pipeline shutdown[id=" + pipelineId + "]"); } return pipelineId; }
From source file:com.ottogroup.bi.spqr.metrics.MetricsHandler.java
/** * {@link JmxReporter#start() Starts} the referenced {@link JmxReporter} * @param id/*from w w w. j a v a 2 s . c om*/ */ public void startJmxReporter(final String id) { String key = StringUtils.lowerCase(StringUtils.trim(id)); JmxReporter jmxReporter = this.jmxReporters.get(key); if (jmxReporter != null) { jmxReporter.start(); } }
From source file:info.rynkowski.hamsterclient.ui.view.activity.FactFormActivity.java
private @NonNull List<String> splitTags(@NonNull String tags) { List<String> result = new ArrayList<>(); for (String i : StringUtils.split(tags, ",")) { result.add(StringUtils.trim(i)); }/*w w w. ja v a2s.co m*/ return result; }