List of usage examples for org.apache.commons.lang StringUtils trim
public static String trim(String str)
Removes control characters (char <= 32) from both ends of this String, handling null
by returning null
.
From source file:com.clt.systemmanger.controller.UserAction.java
/** * @Description: //from w ww.j ava2s .c om * @return String ?? * @author hjx * @create_date 2014721 ?11:04:21 */ @RequestMapping(value = "/registerUser", method = RequestMethod.POST) @ApiOperation(value = "", notes = "", position = 5) @ResponseBody public Map<String, Object> registerUser( @ApiParam(value = "??", required = true) @RequestParam("vcAccount") String vcAccount, @ApiParam(value = "?", required = true) @RequestParam("vcPassword") String vcPassword, @ApiParam(value = "", required = true) @RequestParam("usertypeID") int utypeID, @ApiParam(value = "", required = true) @RequestParam("phone") String phone, @ApiParam(value = "", required = true) @RequestParam(value = "email") String email, @ApiParam(value = "??", required = true) @RequestParam(value = "code") String code, HttpServletResponse resp) { // int utypeID = Integer.parseInt( usertypeID ); // ???????? String codeStr = userCodeService.getCodeByTel(phone); if (StringUtils.isEmpty(codeStr)) { return AjaxUtil.getMap(false, "??????"); } // ????? if (!StringUtils.trim(code).equals(codeStr)) { return AjaxUtil.getMap(false, "???"); } TUser user = new TUser(); user.setIArchiveType(utypeID); user.setDtAddtime(new Date()); user.setVcAccount(vcAccount); user.setVcEmail(email); org.springframework.security.authentication.encoding.Md5PasswordEncoder t = new Md5PasswordEncoder(); String tt = t.encodePassword(vcPassword, user.getVcAccount()); user.setVcPassword(tt); try { TUser userAccount = userService.getByAccount(vcAccount); if (null == userAccount) { userService.saveRegister(user, phone); String token = TokenUtil.getToken(); // token? TTokenUser tokenUser = new TTokenUser(); tokenUser.setVcToken(token); tokenUser.setIUser(user.getId()); tokenUser.setDtLasttime(new Date()); tokenUserService.saveTokenUser(tokenUser); resp.addHeader("token", token); return AjaxUtil.getMap(true, "?!"); } else { return AjaxUtil.getMap(false, "?????"); } /*request.setAttribute( "account" , uname ); request.setAttribute( "password" , upass ); request.getRequestDispatcher( "j_spring_security_check" ).forward( request , resp );*/ } catch (Exception e) { e.printStackTrace(); return AjaxUtil.getMapByException(e); } }
From source file:com.github.technosf.posterer.controllers.impl.RequestController.java
/** * Update the request bean from the values bound to the window *//*from w w w . ja v a 2 s . c o m*/ public void updateRequest() { requestBean.setEndpoint(StringUtils.trim(endpoint.getValue())); requestBean.setMethod(method.getValue()); requestBean.setPayload(StringUtils.trim(payload.getText())); requestBean.setContentType(mime.getValue()); requestBean.setBase64(encode.isSelected()); requestBean.setHttpUser(StringUtils.trim(user.getText())); requestBean.setHttpPassword(StringUtils.trim(password.getText())); }
From source file:adalid.core.wrappers.ArtifactWrapper.java
private String shortWordyLabel(Entity entity, boolean shortest) { String name = shortWordyName(entity.getRoot()); String connector = entity.getResourceGender() == null ? "" : entity.getResourceGender().getConnector(); String label = shortest ? shortLabelOf(entity) : labelOf(entity); String string = StringUtils.trim(StringUtils.replace(name + " " + connector + " " + label, " ", " ")); return string; }
From source file:com.htmlhifive.tools.jslint.dialog.CreateEngineDialog.java
@Override protected void okPressed() { ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(getShell()); DownloadEngineSupport support = createEngineDownload((Boolean) wvJslint.getValue()); try {/* www . j a v a 2 s. c om*/ IFile file = ResourcesPlugin.getWorkspace().getRoot() .getFile(new Path(wvOutputDir.getValue() + "/" + support.getEngine().getFileName())); if (file.exists()) { MessageBox box = new MessageBox(getShell(), SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION); box.setMessage(Messages.DM0004.getText()); box.setText(Messages.DT0011.getText()); if (box.open() == SWT.CANCEL) { return; } } DownloadRunnable progress = new DownloadRunnable(support); progressDialog.run(true, false, progress); EngineInfo info = progress.getResult(); if (info == null) { ErrorDialog.openError(getShell(), Messages.DT0003.getText(), Messages.EM0015.getText(), ValidationStatus.error(Messages.EM0015.getText())); return; } ConfirmLicenseDialog dialog = new ConfirmLicenseDialog(getShell(), StringUtils.trim(info.getLicenseStr()), Messages.DT0009.getText()); if (dialog.open() == IDialogConstants.OK_ID) { if (file.exists()) { file.setContents(new ByteArrayInputStream(info.getMainSource().getBytes()), IResource.FORCE, null); } else { file.create(new ByteArrayInputStream(info.getMainSource().getBytes()), true, null); } this.engineFilePath = file.getFullPath().toString(); } else { return; } } catch (InvocationTargetException e) { ErrorDialog.openError(getShell(), Messages.DT0003.getText(), Messages.EM0015.getText(), new Status(IStatus.ERROR, JSLintPlugin.PLUGIN_ID, e.getMessage(), e)); logger.put(Messages.EM0100, e); } catch (InterruptedException e) { // ????????. throw new AssertionError(); } catch (CoreException e) { ErrorDialog.openError(getShell(), Messages.DT0003.getText(), Messages.EM0016.getText(), e.getStatus()); logger.put(Messages.EM0100, e); } super.okPressed(); }
From source file:ch.entwine.weblounge.security.sql.endpoint.SQLDirectoryProviderEndpoint.java
@PUT @Path("/account/{id}/challenge") public Response updateAccountChallenge(@PathParam("id") String login, @FormParam("challenge") String challenge, @FormParam("response") String response, @Context HttpServletRequest request) { // Make sure that the user owns the roles required for this operation User user = securityService.getUser(); if (!SecurityUtils.userHasRole(user, SystemRole.SITEADMIN) && !user.getLogin().equals(login)) return Response.status(Status.FORBIDDEN).build(); JpaAccount account = null;// w w w .j ava 2 s . co m Site site = getSite(request); try { account = directory.getAccount(site, login); if (account == null) return Response.status(Status.NOT_FOUND).build(); // Set the challenge account.setChallenge(StringUtils.trimToNull(challenge)); // Hash the response if (StringUtils.isNotBlank(response)) { logger.debug("Hashing response for user '{}@{}' using md5", login, site.getIdentifier()); String digestResponse = PasswordEncoder.encode(StringUtils.trim(response)); account.setResponse(digestResponse); } else { account.setResponse(response); } directory.updateAccount(account); return Response.ok().build(); } catch (Throwable t) { return Response.serverError().build(); } }
From source file:com.taobao.tdhs.jdbc.TDHSStatement.java
private void doUpdate(com.taobao.tdhs.client.statement.Statement s, ParseSQL parseSQL, String tableName, String dbName) throws SQLException { Query query = preprocessGet(s, parseSQL, tableName, dbName); List<Entry<String, String>> updateEntries = parseSQL.getUpdateEntries(); if (updateEntries == null || updateEntries.isEmpty()) { throw new TDHSSQLException("no value to update!", parseSQL.getSql()); }//from w w w . j a v a 2s.co m for (Entry<String, String> e : updateEntries) { if (StringUtils.isBlank(e.getKey()) || StringUtils.isBlank(e.getValue())) { throw new TDHSSQLException("insert column and values can't be empty!", parseSQL.getSql()); } String field = StringUtil.escapeField(StringUtils.trim(e.getKey())); if (field == null) { throw new TDHSSQLException("insert column is error!", parseSQL.getSql()); } String value = StringUtils.trim(e.getValue()); if (StringUtils.equalsIgnoreCase("null", value)) { query.set().field(field).setNull(); } else if (StringUtils.equalsIgnoreCase("now()", value)) { query.set().field(field).setNow(); } else { if (StringUtils.startsWith(value, field)) { value = value.substring(field.length()); value = StringUtils.trim(value); if (StringUtils.startsWith(value, "+")) { value = value.substring(1); value = StringUtils.trim(value); if (StringUtil.isLong(value)) { query.set().field(field).add(Long.valueOf(value)); } else { throw new TDHSSQLException("update value is error ,is not long", parseSQL.getSql()); } } else if (StringUtils.startsWith(value, "-")) { value = value.substring(1); value = StringUtils.trim(value); if (StringUtil.isLong(value)) { query.set().field(field).sub(Long.valueOf(value)); } else { throw new TDHSSQLException("update value is error ,is not long", parseSQL.getSql()); } } else { throw new TDHSSQLException("update value is error maybe can't support!", parseSQL.getSql()); } } else { value = StringUtil.escapeValue(value); if (value == null) { throw new TDHSSQLException("update value is error!", parseSQL.getSql()); } if (StringUtils.startsWith(value, BYTE_PARAMETER_PREFIX)) { int pidx = ConvertUtil .safeConvertInt(StringUtils.substring(value, BYTE_PARAMETER_PREFIX.length()), -1); if (byteParameters.containsKey(pidx)) { query.set().field(field).set(byteParameters.get(pidx)); } else { query.set().field(field).set(value); } } else { query.set().field(field).set(value); } } } } TDHSResponse response = null; try { response = query.update(); } catch (TDHSException e) { throw new SQLException(e); } processResponse(response, true); }
From source file:com.ibm.jaggr.core.impl.modulebuilder.css.CSSModuleBuilder.java
/** * Minifies a CSS string by removing comments and excess white-space, as well as * some unneeded tokens.//from w w w .j a va 2 s . com * * @param css The contents of a CSS file as a String * @param res The resource for the CSS file * @return the minified css */ protected String minify(String css, IResource res) { // replace all quoted strings and url(...) patterns with unique ids so that // they won't be affected by whitespace removal. LinkedList<String> quotedStringReplacements = new LinkedList<String>(); Matcher m = quotedStringPattern.matcher(css); StringBuffer sb = new StringBuffer(); int i = 0; while (m.find()) { String text = (m.group(1) != null) ? ("url(" + StringUtils.trim(m.group(1)) + ")") : //$NON-NLS-1$ //$NON-NLS-2$ m.group(0); quotedStringReplacements.add(i, text); String replacement = "%%" + QUOTED_STRING_MARKER + (i++) + "__%%"; //$NON-NLS-1$ //$NON-NLS-2$ m.appendReplacement(sb, ""); //$NON-NLS-1$ sb.append(replacement); } m.appendTail(sb); css = sb.toString(); // Get rid of extra whitespace css = whitespacePattern.matcher(css).replaceAll(" "); //$NON-NLS-1$ css = endsPattern.matcher(css).replaceAll(""); //$NON-NLS-1$ css = closeBracePattern.matcher(css).replaceAll("}"); //$NON-NLS-1$ m = delimitersPattern.matcher(css); sb = new StringBuffer(); while (m.find()) { String text = m.group(1); m.appendReplacement(sb, ""); //$NON-NLS-1$ sb.append(text.length() == 1 ? text : text.replace(" ", "")); //$NON-NLS-1$ //$NON-NLS-2$ } m.appendTail(sb); css = sb.toString(); // restore quoted strings and url(...) patterns m = QUOTED_STRING_MARKER_PAT.matcher(css); sb = new StringBuffer(); while (m.find()) { i = Integer.parseInt(m.group(1)); m.appendReplacement(sb, ""); //$NON-NLS-1$ sb.append(quotedStringReplacements.get(i)); } m.appendTail(sb); css = sb.toString(); return css.toString(); }
From source file:com.greenline.guahao.web.module.home.controllers.my.profile.ProfileController.java
/** * /*from www .j a va 2 s. c o m*/ * * @param userDO * @param mobile * @param code * @return String */ @MethodRemark(value = "remark=,mobile=?,code=??") @RequestMapping(value = "/bindmobile", method = RequestMethod.POST) public String doBindMobile(ModelMap model, @ModelAttribute("userInfo") UserDO userDO, @RequestParam(value = "mobile", required = true) String mobile, @RequestParam(value = "code", required = true) String code) { if (!this.isUserIdValid(userDO)) { // id? model.put("errorMessage", UserProfileConstants.ERR_MSG_LOGIN_USER_ID_ERROR); return MY_PROFILE; } Long cuserId = UserCookieUtil.getUserId(request); if (!userDO.getUserId().equals(cuserId)) { model.put("errorMessage", UserProfileConstants.ERR_MSG_LOGIN_USER_ID_ERROR); return MY_PROFILE; } UserDO userinfo = userManager.findUserByUserId(cuserId); if (null == userinfo) { return MY_ERROR; } // ? if (!RegexUtil.isMobile(StringUtils.trim(mobile))) { profileProcess.setBindModel(userinfo, model); model.put("type", 1); return MY_PROFILE; } UserResult urr = userManager.valiMobileNo(cuserId, mobile, userinfo.getReg_type()); if (urr != null && urr.getUserDO() != null) { // ?? UserDO userdo = urr.getUserDO(); model.put("errorMessage", UserProfileConstants.ERR_MSG_MOBILE_NO_HAS_BEEN_USED_BY_OTHER_PREFIX + profileProcess.loginIdHiden(userdo.getLoginId(), userdo.getReg_type()) + UserProfileConstants.ERR_MSG_MOBILE_NO_HAS_BEEN_USED_BY_OTHER_POSTFIX); profileProcess.setBindModel(userinfo, model); model.put("type", 1); return MY_PROFILE; } UserDO userCheck = userManager.findUserByUserId(cuserId); if (null == userCheck) { return MY_ERROR; } if (!UserUtil.isBindMobile(userCheck)) { profileProcess.setBindModel(userCheck, model); return MY_PROFILE; } if (codeCacheManager.verifyMobileCode(VerifyTypeEnum.UPDATE_PROFILE, mobile, code)) { UserDO user = new UserDO(); user.setUserId(cuserId); user.setMobile(mobile); user.setBindMobile(1); UserResult r = userManager.bindUserMobile(user); codeCacheManager.delCode(VerifyTypeEnum.UPDATE_PROFILE, VCodeCachePrefixEnum.CODE_PRE.getValue() + mobile); if (r.isSystemError()) { profileProcess.setBindModel(userinfo, model); model.put("type", 1); model.put("code", code); return MY_PROFILE; } else { model.put("successMessage", UserProfileConstants.MSG_UPDATE_PROFILE_SUCCESS); UserDO users = userManager.findUserByUserId(cuserId); if (null == users) { return MY_ERROR; } profileProcess.setBindModel(users, model); return MY_PROFILE; } } else { profileProcess.setBindModel(userinfo, model); model.put("type", 1); model.put("code", code); model.put("errorMessage", UserProfileConstants.ERR_MSG_MOBILE_CODE); return MY_PROFILE; } }
From source file:com.atlassian.jira.user.util.UserUtilImpl.java
private String trimEmailAddress(String emailAddress) { return StringUtils.trim(emailAddress); }
From source file:com.hangum.tadpole.rdb.core.dialog.dml.GenerateStatmentDMLDialog.java
/** * Generate SELECT statment//from w ww . ja v a2 s . co m * * @return */ private String buildSelectSQL() { StringBuffer resultSQL = new StringBuffer(); if (chkComment.getSelection()) { resultSQL.append("/* Tadpole SQL Generator */"); //$NON-NLS-1$ } resultSQL.append("SELECT "); //$NON-NLS-1$ int cnt = 0; StringBuffer sbColumn = new StringBuffer(); for (ExtendTableColumnDAO allDao : (List<ExtendTableColumnDAO>) tableViewer.getInput()) { if (allDao.isCheck()) { if (cnt != 0) sbColumn.append("\t, "); //$NON-NLS-1$ if ("*".equals(allDao.getField())) { //$NON-NLS-1$ sbColumn.append(allDao.getSysName()); } else { String strTableAlias = !"".equals(textTableAlias.getText().trim()) ? //$NON-NLS-1$ textTableAlias.getText().trim() + "." + allDao.getSysName() + " as " //$NON-NLS-1$//$NON-NLS-2$ + allDao.getColumnAlias() : allDao.getSysName() + " as " + allDao.getColumnAlias(); //$NON-NLS-1$ sbColumn.append(strTableAlias); } cnt++; } } if (StringUtils.isEmpty(StringUtils.trim(sbColumn.toString()))) sbColumn.append(" * "); //$NON-NLS-1$ resultSQL.append(sbColumn.toString()); resultSQL.append( " FROM " + SQLUtil.getTableName(userDB, tableDAO) + " " + this.textTableAlias.getText().trim()); //$NON-NLS-1$ //$NON-NLS-2$ cnt = 0; for (ExtendTableColumnDAO allDao : (List<ExtendTableColumnDAO>) tableViewer.getInput()) { if ("PK".equals(allDao.getKey())) { //$NON-NLS-1$ if (cnt == 0) { resultSQL.append(" WHERE "); //$NON-NLS-1$ } else { resultSQL.append(" AND "); //$NON-NLS-1$ } resultSQL.append(allDao.getColumnNamebyTableAlias()).append(" = ? "); //$NON-NLS-1$ if (chkComment.getSelection()) { resultSQL.append("/* " + allDao.getType() + " */"); //$NON-NLS-1$ //$NON-NLS-2$ } cnt++; } } return lastSQLGen(resultSQL.toString()); }