List of usage examples for org.apache.commons.lang3 StringUtils trimToEmpty
public static String trimToEmpty(final String str)
Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null .
From source file:ke.co.tawi.babblesms.server.servlet.admin.account.ResetPassword.java
/** * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */// ww w. j a v a2 s .c om public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(false); String loginPasswd = StringUtils.trimToEmpty(request.getParameter("loginPasswd")); String loginPasswd2 = StringUtils.trimToEmpty(request.getParameter("loginPasswd2")); String accountuuid = StringUtils.trimToEmpty(request.getParameter("accountuuid")); account = accountDAO.getAccount(accountuuid); // System.out.println(accountuuid); if (StringUtils.isEmpty(loginPasswd) && StringUtils.isEmpty(loginPasswd2)) { session.setAttribute(SessionConstants.ADMIN_UPDATE_ERROR, "Password can't be empty."); response.sendRedirect("admin/accounts.jsp"); } else if (!loginPasswd.equalsIgnoreCase(loginPasswd2)) { session.setAttribute(SessionConstants.ADMIN_UPDATE_ERROR, "Password Mismatch."); response.sendRedirect("admin/accounts.jsp"); } else { account.setLogpassword(SecurityUtil.getMD5Hash((loginPasswd))); if (accountDAO.updateAccount(accountuuid, account)) { accountCache.put(new Element(account.getUsername(), account)); session.setAttribute(SessionConstants.ADMIN_UPDATE_SUCCESS, "Account Password updated successfully."); } else { session.setAttribute(SessionConstants.ADMIN_UPDATE_ERROR, "Account Password update failed."); } response.sendRedirect("admin/accounts.jsp"); } }
From source file:de.jfachwert.net.ChatAccount.java
private static String[] split(String value) { String[] splitted = StringUtils.trimToEmpty(value).split(":\\s+"); if (splitted.length != 2) { throw new LocalizedIllegalArgumentException(value, "chat_service"); }/* w w w . java 2 s . c o m*/ return splitted; }
From source file:com.nesscomputing.httpclient.factory.httpclient4.InternalResponse.java
@Override public Long getContentLength() { if (httpResponse != null) { final Header header = httpResponse.getFirstHeader("Content-Length"); if (header != null) { final String contentLen = StringUtils.trimToEmpty(header.getValue()); LOG.debug("Response content length header is '%s'", contentLen); try { return Long.parseLong(contentLen); } catch (NumberFormatException nfe) { LOG.warnDebug(nfe, "Could not parse '%s'", contentLen); }// w ww . ja va 2 s. c om } } return null; }
From source file:net.gtaun.wl.race.dialog.NewRacingDialog.java
public static WlListDialog create(Player player, EventManager eventManager, AbstractDialog parent, RaceServiceImpl service, Track track) { PlayerStringSet stringSet = service.getLocalizedStringSet().getStringSet(player); RacingManagerImpl racingManager = service.getRacingManager(); String racingMode = stringSet .get((track.getStatus() == TrackStatus.EDITING) ? "Dialog.NewRacingDialog.RacingTestCaption" : "Dialog.NewRacingDialog.RacingNormalCaption"); String[] racingName = new String[1]; racingName[0] = RacingUtils.getDefaultName(player, track); RacingSetting setting = new RacingSetting(track); return WlListDialog.create(player, eventManager).parentDialog(parent) .caption(() -> stringSet.format("Dialog.NewRacingDialog.Caption", racingMode)) .item(() -> stringSet.format("Dialog.NewRacingDialog.Name", racingName[0]), () -> { if (track.getStatus() == TrackStatus.EDITING) return false; return true; }, (i) -> {/*ww w.j a va 2 s.c o m*/ player.playSound(1083); String caption = stringSet.format("Dialog.NewRacingEditNameDialog.Caption", racingMode); String message = stringSet.get("Dialog.NewRacingEditNameDialog.Text"); WlInputDialog.create(player, eventManager).parentDialog(i.getCurrentDialog()).caption(caption) .message(message).onClickOk((d, text) -> { String name = StringUtils.trimToEmpty(text); if (name.length() < 3 || name.length() > 40) { ((WlInputDialog) d).setAppendMessage( stringSet.get("Dialog.NewRacingEditNameDialog.LimitAppendMessage")); d.show(); return; } racingName[0] = name; }).build().show(); }) .item(() -> stringSet.format("Dialog.NewRacingDialog.Track", track.getName(), track.getCheckpoints().size(), track.getLength() / 1000.0f), (i) -> { player.playSound(1083); TrackDialog.create(player, eventManager, i.getCurrentDialog(), service, track).show(); }) .item(() -> { String trackType = stringSet.get("Track.Type.Normal"); if (track.getType() == TrackType.CIRCUIT) trackType = stringSet.format("Dialog.NewRacingDialog.CircultFormat", track.getCircultLaps()); return stringSet.format("Dialog.NewRacingDialog.TrackType", trackType); }, (i) -> { player.playSound(1083); i.getCurrentDialog().show(); }) .item(ListDialogItemRadio.create().itemText(stringSet.get("Dialog.NewRacingDialog.RacingType")) .selectedIndex(() -> setting.getRacingType().ordinal()) .item(stringSet.get("Racing.Type.Normal"), Color.CORNFLOWERBLUE, (dialogItem) -> setting.setRacingType(RacingType.NORMAL)) .item(stringSet.get("Racing.Type.Knockout"), Color.MAGENTA, (dialogItem) -> setting.setRacingType(RacingType.KNOCKOUT)) .onSelect((i) -> { player.playSound(1083); i.getCurrentDialog().show(); }).build()) .item(() -> { String format = stringSet.get("Dialog.NewRacingDialog.DepartureInterval"); int interval = setting.getDepartureInterval(); if (interval == 0) return String.format(format, stringSet.get("Common.None")); return String.format(format, stringSet.format("Time.Format.S", interval)); }, (i) -> { player.playSound(1083); RacingDepartureSettingDialog .create(player, eventManager, i.getCurrentDialog(), service, setting).show(); }) .item(ListDialogItemRadio.create().selectedIndex(() -> setting.getDeathRule().ordinal()) .itemText(stringSet.get("Dialog.NewRacingDialog.DeathRule")) .item(stringSet.get("Racing.DeathRule.WaitAndReturn"), Color.AQUA, (dialogItem) -> setting.setDeathRule(DeathRule.WAIT_AND_RETURN)) .item(stringSet.get("Racing.DeathRule.Knockout"), Color.FUCHSIA, (dialogItem) -> setting.setDeathRule(DeathRule.KNOCKOUT)) .onSelect((i) -> { player.playSound(1083); i.getCurrentDialog().show(); }).build()) .item(ListDialogItemCheck.create().itemText(stringSet.get("Dialog.NewRacingDialog.Limit")) .item(stringSet.get("Racing.Limit.AutoRepair"), Color.LIME, () -> setting.getLimit().isAllowAutoRepair()) .item(stringSet.get("Racing.Limit.InfiniteNitrous"), Color.RED, () -> setting.getLimit().isAllowInfiniteNitrous()) .item(stringSet.get("Racing.Limit.AutoFlip"), Color.BLUE, () -> setting.getLimit().isAllowAutoFlip()) .item(stringSet.get("Racing.Limit.ChangeVehicle"), Color.GOLD, () -> setting.getLimit().isAllowChangeVehicle()) .onSelect((i) -> { player.playSound(1083); RacingLimitDialog.create(player, eventManager, i.getCurrentDialog(), service, track, setting.getLimit()).show(); }).build()) .item(() -> { int min = track.getSetting().getMinPlayers(); int max = setting.getMaxPlayers(); if (min != 0 && max != 0) return stringSet.format("Dialog.NewRacingDialog.PlayersLimitFormat", min, max); return stringSet.get("Dialog.NewRacingDialog.PlayersLimit") + " " + stringSet.get("Dialog.NewRacingDialog.PlayersLimitNone"); }, (i) -> { player.playSound(1083); i.getCurrentDialog().show(); }) .item(() -> { String itemText = stringSet.get("Dialog.NewRacingDialog.Password"); if (StringUtils.isBlank(setting.getPassword())) return itemText + stringSet.get("Common.None"); return itemText + " " + setting.getPassword(); }, (i) -> { player.playSound(1083); i.getCurrentDialog().show(); }) .item(stringSet.get("Dialog.NewRacingDialog.Create"), (i) -> { Runnable startNewRacing = () -> { Racing racing = racingManager.createRacing(track, player, racingName[0]); racing.teleToStartingPoint(player); racing.setSetting(setting); }; player.playSound(1083); if (track.getCheckpoints().isEmpty()) return; if (racingManager.isPlayerInRacing(player)) { Racing racing = racingManager.getPlayerRacing(player); NewRacingConfirmDialog.create(player, eventManager, i.getCurrentDialog(), service, racing, () -> startNewRacing.run()); } else startNewRacing.run(); }) .build(); }
From source file:ml.shifu.core.di.builtin.binning.AbstractBinning.java
/** * Constructor with expected bin number and expected missing values * * @param binningNum//from w w w .j a va 2 s .com * @param missingValList */ public AbstractBinning(int binningNum, List<String> missingValList) { this.expectedBinningNum = binningNum; this.missingValSet = new HashSet<String>(); this.missingValSet.add(""); if (missingValList != null && !missingValList.isEmpty()) { for (String missingVal : missingValList) { missingValSet.add(StringUtils.trimToEmpty(missingVal)); } } }
From source file:com.creditcloud.payment.model.chinapnr.transfer.AddBidInfoRequest.java
public String chkString() { StringBuilder sb = new StringBuilder(); sb.append(StringUtils.trimToEmpty(getVersion())); sb.append(StringUtils.trimToEmpty(getCmdId().name())); sb.append(StringUtils.trimToEmpty(getMerCustId())); sb.append(StringUtils.trimToEmpty(this.getProId())); sb.append(StringUtils.trimToEmpty(this.getBorrCustId())); sb.append(StringUtils.trimToEmpty(this.getBorrTotAmt())); sb.append(StringUtils.trimToEmpty(this.getYearRate())); sb.append(StringUtils.trimToEmpty(this.getRetType())); sb.append(StringUtils.trimToEmpty(this.getBidStartDate())); sb.append(StringUtils.trimToEmpty(this.getBidEndDate())); sb.append(StringUtils.trimToEmpty(this.getRetAmt())); sb.append(StringUtils.trimToEmpty(this.getRetDate())); sb.append(StringUtils.trimToEmpty(this.getGuarCompId())); sb.append(StringUtils.trimToEmpty(this.getGuarAmt())); sb.append(StringUtils.trimToEmpty(this.getProArea())); sb.append(StringUtils.trimToEmpty(this.getBgRetUrl())); sb.append(StringUtils.trimToEmpty(this.getMerPriv())); sb.append(StringUtils.trimToEmpty(this.getReqExt())); return sb.toString(); }
From source file:com.chiorichan.http.Route.java
/** * * @param args// ww w .jav a 2 s . co m * Line input in the format of "pattern '/dir/[cat=]/[id=]', to '/dir/view_item.gsp'" * @throws IOException * Thrown if input string is not valid */ public Route(String args, Site site) throws IOException { if (args == null || args.isEmpty()) throw new IOException("args can't be null or empty"); this.site = site; type = RouteType.FILE; for (String o : args.split(",")) { String key = null; String val = null; o = o.trim(); if (o.contains(":")) { key = o.substring(0, o.indexOf(":")); val = o.substring(o.indexOf(":") + 1); } else if (!o.contains("\"") && !o.contains("'") || o.contains("\"") && o.indexOf(" ") < o.indexOf("\"") || o.contains("'") && o.indexOf(" ") < o.indexOf("'")) { key = o.substring(0, o.indexOf(" ")); val = o.substring(o.indexOf(" ") + 1); } if (key != null && val != null) { key = StringUtils.trimToEmpty(key.toLowerCase()); val = StringUtils.trimToEmpty(val); val = StringUtils.removeStart(val, "\""); val = StringUtils.removeStart(val, "'"); val = StringUtils.removeEnd(val, "\""); val = StringUtils.removeEnd(val, "'"); params.put(key, val); } } // params.put( "domain", site.getDomain() ); }
From source file:com.qq.tars.web.controller.patch.UploadController.java
@RequestMapping(value = "server/api/upload_patch_package", produces = "application/json") @ResponseBody//from w w w .j av a 2 s . com public ServerPatchView upload(@Application @RequestParam String application, @ServerName @RequestParam("module_name") String moduleName, HttpServletRequest request, ModelMap modelMap) throws Exception { String comment = StringUtils.trimToEmpty(request.getParameter("comment")); String uploadTgzBasePath = systemConfigService.getUploadTgzPath(); CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver( request.getSession().getServletContext()); if (multipartResolver.isMultipart(request)) { MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request; Iterator<String> it = multiRequest.getFileNames(); if (it.hasNext()) { MultipartFile file = multiRequest.getFile(it.next()); String originalName = file.getOriginalFilename(); String extension = FilenameUtils.getExtension(originalName); String temporary = uploadTgzBasePath + "/" + UUID.randomUUID() + "." + extension; IOUtils.copy(file.getInputStream(), new FileOutputStream(temporary)); String packageType = "suse"; // war? if (temporary.endsWith(".war")) { temporary = patchService.war2tgz(temporary, moduleName); } // ? String updateTgzPath = uploadTgzBasePath + "/" + application + "/" + moduleName; // ???? String uploadTgzName = application + "." + moduleName + "_" + packageType + "_" + System.currentTimeMillis() + ".tgz"; // ?? String uploadTgzFullPath = updateTgzPath + "/" + uploadTgzName; log.info("temporary path={}, upload path={}", temporary, uploadTgzFullPath); File uploadPathDir = new File(updateTgzPath); if (!uploadPathDir.exists()) { if (!uploadPathDir.mkdirs()) { throw new IOException( String.format("mkdirs error, path=%s", uploadPathDir.getCanonicalPath())); } } FileUtils.moveFile(new File(temporary), new File(uploadTgzFullPath)); return mapper.map(patchService.addServerPatch(application, moduleName, uploadTgzFullPath, comment), ServerPatchView.class); } } throw new Exception("???"); }
From source file:com.nesscomputing.tinyhttp.HttpContentResponseHandler.java
/** * Processes the client response.// ww w . j a va2 s . c o m */ public T handle(final HttpRequest request, final HttpResponse response) throws IOException { // Find the response stream - the error stream may be valid in cases // where the input stream is not. InputStream is = null; try { final HttpEntity httpEntity = response.getEntity(); if (httpEntity != null) { is = httpEntity.getContent(); } } catch (IOException e) { log.warn("Could not locate response body stream", e); // normal for 401, 403 and 404 responses, for example... } if (is == null) { // Fall back to zero length response. is = new NullInputStream(0); } final Header header = response.getFirstHeader("Content-Encoding"); if (header != null) { final String encoding = StringUtils.trimToEmpty(header.getValue()); if (StringUtils.equalsIgnoreCase(encoding, "gzip") || StringUtils.equalsIgnoreCase(encoding, "x-gzip")) { log.debug("Found GZIP stream"); is = new GZIPInputStream(is); } else if (StringUtils.equalsIgnoreCase(encoding, "deflate")) { log.debug("Found deflate stream"); final Inflater inflater = new Inflater(true); is = new InflaterInputStream(is, inflater); } } return contentConverter.convert(request, response, is); }
From source file:com.hubspot.jinjava.lib.tag.IncludeTag.java
@Override public String interpret(TagNode tagNode, JinjavaInterpreter interpreter) { HelperStringTokenizer helper = new HelperStringTokenizer(tagNode.getHelpers()); if (!helper.hasNext()) { throw new TemplateSyntaxException(tagNode.getMaster().getImage(), "Tag 'include' expects template path", tagNode.getLineNumber()); }/* w w w .j av a 2s.co m*/ String path = StringUtils.trimToEmpty(helper.next()); String templateFile = interpreter.resolveString(path, tagNode.getLineNumber()); try { interpreter.getContext().pushIncludePath(templateFile, tagNode.getLineNumber()); } catch (IncludeTagCycleException e) { interpreter.addError(new TemplateError(ErrorType.WARNING, ErrorReason.EXCEPTION, ErrorItem.TAG, "Include cycle detected for path: '" + templateFile + "'", null, tagNode.getLineNumber(), e)); return ""; } try { String template = interpreter.getResource(templateFile); Node node = interpreter.parse(template); interpreter.getContext().addDependency("coded_files", templateFile); JinjavaInterpreter child = new JinjavaInterpreter(interpreter); String result = child.render(node); interpreter.getErrors().addAll(child.getErrors()); return result; } catch (IOException e) { throw new InterpretException(e.getMessage(), e, tagNode.getLineNumber()); } finally { interpreter.getContext().popIncludePath(); } }