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:net.gtaun.wl.race.dialog.TrackEditDialog.java
@Override public void show() { RacingManagerImpl racingManager = raceService.getRacingManager(); items.clear();//from w w w . j av a 2s . com addItem(stringSet.format("Dialog.TrackEditDialog.Name", track.getName()), (i) -> { String caption = stringSet.get("Dialog.TrackEditNameDialog.Caption"); String message = stringSet.format("Dialog.TrackEditNameDialog.Text", track.getName()); TrackNamingDialog.create(player, rootEventManager, this, caption, message, raceService, (d, name) -> { try { TrackManagerImpl trackManager = raceService.getTrackManager(); trackManager.renameTrack(track, name); showParentDialog(); } catch (AlreadyExistException ex) { d.setAppendMessage( stringSet.format("Dialog.TrackEditNameDialog.AlreadyExistAppendMessage", name)); show(); } catch (IllegalArgumentException ex) { d.setAppendMessage( stringSet.format("Dialog.TrackEditNameDialog.IllegalFormatAppendMessage", name)); show(); } }).show(); }); addItem(() -> { String desc = track.getDesc(); if (StringUtils.isBlank(desc)) desc = stringSet.get("Common.Empty"); return stringSet.format("Dialog.TrackEditDialog.Desc", desc); }, (i) -> { String caption = stringSet.get("Dialog.TrackEditDescDialog.Caption"); String message = stringSet.format("Dialog.TrackEditDescDialog.Text", track.getName(), track.getDesc()); WlInputDialog.create(player, rootEventManager).parentDialog(this).caption(caption).message(message) .onClickOk((d, text) -> { String desc = StringUtils.trimToEmpty(text); desc = StringUtils.replace(desc, "%", "#"); desc = StringUtils.replace(desc, "\t", " "); desc = StringUtils.replace(desc, "\n", " "); track.setDesc(desc); d.showParentDialog(); }).build().show(); }); addItem(() -> stringSet.format("Dialog.TrackEditDialog.Checkpoints", track.getCheckpoints().size()), (i) -> show()); addItem(() -> stringSet.format("Dialog.TrackEditDialog.Length", track.getLength() / 1000.0f), (i) -> show()); addItem(() -> stringSet.get("Dialog.TrackEditDialog.AddCheckpoint"), (i) -> { TrackCheckpoint checkpoint = track.createCheckpoint(player.getLocation()); TrackCheckpointEditDialog.create(player, eventManagerNode, null, raceService, checkpoint, true).show(); }); addItem(() -> stringSet.get("Dialog.TrackEditDialog.Setting"), (i) -> { TrackSettingDialog.create(player, rootEventManager, this, raceService, track).show(); }); addItem(() -> stringSet.get("Dialog.TrackEditDialog.Delete"), (i) -> { String caption = stringSet.get("Dialog.TrackDeleteConfirmDialog.Caption"); String message = stringSet.format("Dialog.TrackDeleteConfirmDialog.Text", track.getName()); WlInputDialog.create(player, rootEventManager).parentDialog(this).caption(caption).message(message) .onClickOk((d, text) -> { if (!track.getName().equals(text)) { d.showParentDialog(); return; } raceService.stopEditingTrack(player); TrackManagerImpl trackManager = raceService.getTrackManager(); trackManager.deleteTrack(track); String msgboxCaption = stringSet.get("Dialog.TrackDeleteCompleteDialog.Caption"); String msgboxMessage = stringSet.format("Dialog.TrackDeleteCompleteDialog.Text", track.getName()); WlMsgboxDialog.create(player, rootEventManager).caption(msgboxCaption) .message(msgboxMessage).onClickOk((dialog) -> player.playSound(1083)).build() .show(); }).build().show(); }); addItem(stringSet.get("Dialog.TrackEditDialog.StopEditing"), (i) -> { raceService.stopEditingTrack(player); }); addItem(stringSet.get("Dialog.TrackEditDialog.FinishEditing"), () -> { if (track.getCheckpoints().size() < 2) return false; return true; }, (i) -> { String caption = stringSet.get("Dialog.TrackFinishEditingConfirmDialog.Caption"); String message = stringSet.format("Dialog.TrackFinishEditingConfirmDialog.Text", track.getName()); MsgboxDialog.create(player, rootEventManager).caption(caption).message(message).onClickOk((d) -> { player.playSound(1083); raceService.stopEditingTrack(player); track.setStatus(TrackStatus.COMPLETED); showParentDialog(); }).build().show(); ; }); addItem(stringSet.get("Dialog.TrackEditDialog.Test"), () -> { if (track.getCheckpoints().isEmpty()) return false; return true; }, (i) -> { Runnable startNewRacing = () -> { Racing racing = racingManager.createRacing(track, player, RacingUtils.getDefaultName(player, track)); racing.teleToStartingPoint(player); racing.beginCountdown(); }; List<TrackCheckpoint> checkpoints = track.getCheckpoints(); if (checkpoints.isEmpty()) return; if (racingManager.isPlayerInRacing(player)) { Racing racing = racingManager.getPlayerRacing(player); NewRacingConfirmDialog.create(player, rootEventManager, this, raceService, racing, () -> { startNewRacing.run(); }).show(); } else startNewRacing.run(); }); addItem("-", (i) -> show()); List<TrackCheckpoint> checkpoints = track.getCheckpoints(); for (int i = 0; i < checkpoints.size(); i++) { TrackCheckpoint checkpoint = checkpoints.get(i); float distance = player.getLocation().distance(checkpoint.getLocation()); String item = stringSet.format("Dialog.TrackEditDialog.Checkpoint", i + 1, distance); addItem(item, (listItem) -> { TrackCheckpointEditDialog.create(player, eventManagerNode, this, raceService, checkpoint, false) .show(); }); } super.show(); }
From source file:ke.co.tawi.babblesms.server.beans.account.Account.java
/** * @param apiPassword the apiPassword to set *//*from w w w. j a v a 2s .c o m*/ public void setApiPassword(String apiPassword) { this.apiPassword = StringUtils.trimToEmpty(apiPassword); }
From source file:com.chiorichan.http.Route.java
public String match(String domain, String subdomain, String uri) { String prop = params.get("pattern"); if (prop == null) prop = params.get("page"); if (prop == null) { Log.get().warning("The `pattern` attribute was null for route '" + this + "'. Unusable!"); return null; }//from w w w . j a va2 s . c om prop = StringUtils.trimToEmpty(prop); uri = StringUtils.trimToEmpty(uri); if (prop.startsWith("/")) { prop = prop.substring(1); params.put("pattern", prop); } if (!StringUtils.trimToEmpty(params.get("subdomain")).equals("*") && !subdomain.equals(params.get("subdomain"))) { Log.get().finer("The subdomain does not match for " + uri + " on route " + this); return null; } String[] propsRaw = prop.split("[.//]"); String[] urisRaw = uri.split("[.//]"); ArrayList<String> props = Lists.newArrayList(); ArrayList<String> uris = Lists.newArrayList(); for (String s : propsRaw) if (s != null && !s.isEmpty()) props.add(s); for (String s : urisRaw) if (s != null && !s.isEmpty()) uris.add(s); if (uris.isEmpty()) uris.add(""); if (props.isEmpty()) props.add(""); if (props.size() > uris.size()) { Log.get().finer("The length of elements in route " + this + " is LONGER then the length of elements on the uri; " + uris); return null; } if (props.size() < uris.size()) { Log.get().finer("The length of elements in route " + this + " is SHORTER then the length of elements on the uri; " + uris); return null; } String weight = StringUtils.repeat("?", Math.max(props.size(), uris.size())); boolean match = true; for (int i = 0; i < Math.max(props.size(), uris.size()); i++) try { Log.get().finest(prop + " --> " + props.get(i) + " == " + uris.get(i)); if (props.get(i).matches("\\[([a-zA-Z0-9]+)=\\]")) { weight = StringFunc.replaceAt(weight, i, "Z"); String key = props.get(i).replaceAll("[\\[\\]=]", ""); String value = uris.get(i); rewrites.put(key, value); // PREG MATCH Log.get().finer("Found a PREG match for " + prop + " on route " + this); } else if (props.get(i).equals(uris.get(i))) { weight = StringFunc.replaceAt(weight, i, "A"); Log.get().finer("Found a match for " + prop + " on route " + this); // MATCH } else { match = false; Log.get().finer("Found no match for " + prop + " on route " + this); break; // NO MATCH } } catch (ArrayIndexOutOfBoundsException e) { match = false; break; } return match ? weight : null; }
From source file:com.creditcloud.payment.model.chinapnr.NetSaveRequest.java
@Override public String chkString() { /**/* w ww . j a va 2 s . com*/ * ? * * Version + * CmdId + * MerCustId + * UsrCustId + * OrdId+ * OrdDate + * GateBusiId+ * OpenBankId+ * DcFlag + * TransAmt+ * RetUrl+ * BgRetUrl+ * OpenAcctId+ * CertId+ * MerPriv */ StringBuilder sb = new StringBuilder(baseChkString()); sb.append(StringUtils.trimToEmpty(getUsrCustId())).append(StringUtils.trimToEmpty(getOrdId())) .append(StringUtils.trimToEmpty(getOrdDate())).append(StringUtils.trimToEmpty(getGateBusiId())) .append(StringUtils.trimToEmpty(getOpenBankId())).append(StringUtils.trimToEmpty(getDcFlag())) .append(StringUtils.trimToEmpty(getTransAmt())).append(StringUtils.trimToEmpty(getRetUrl())) .append(StringUtils.trimToEmpty(getBgRetUrl())).append(StringUtils.trimToEmpty(getOpenAcctId())) .append(StringUtils.trimToEmpty(getCertId())).append(StringUtils.trimToEmpty(getMerPriv())); return sb.toString(); }
From source file:com.nesscomputing.syslog4j.server.impl.event.structured.StructuredSyslogServerEvent.java
protected void parseHost() { int i = this.message.indexOf(' '); if (i > -1) { this.host = StringUtils.trimToEmpty(this.message.substring(0, i)); this.message = this.message.substring(i + 1); }//w w w.jav a 2s. c o m }
From source file:de.micromata.genome.gwiki.pagetemplates_1_0.editor.PtWikiUploadEditor.java
/** * @param ctx/*from w ww . j av a 2 s .c om*/ * @param maxWidthInPx * @return */ private String uploadFile(final GWikiContext ctx) { String parentPageId = ctx.getRequestParameter("pageId"); if (dataFile == null) { dataFile = ctx.getFileItem(sectionName); } String name = dataFile.getName(); String pageIdFromTitle = GWikiContext.getPageIdFromTitle(dataFile.getName()); if (!StringUtils.equals(name, pageIdFromTitle)) { ctx.addSimpleValidationError(ctx.getTranslated("gwiki.editor.upload.allowdSymbols")); return null; } String pageId = parentPageId + "/" + pageIdFromTitle; if (ctx.getWikiWeb().findElement(pageId) != null) { ctx.addSimpleValidationError(ctx.getTranslated("gwiki.editor.upload.fileExists")); return null; } String title = ctx.getRequest().getParameter("title"); try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); IOUtils.copy(dataFile.getInputStream(), bout); data = bout.toByteArray(); String metaTemplateId = "admin/templates/FileWikiPageMetaTemplate"; GWikiElement element = GWikiWebUtils.createNewElement(ctx, pageId, metaTemplateId, parentPageId); GWikiArtefakt<?> art = element.getMainPart(); GWikiBinaryAttachmentArtefakt att = (GWikiBinaryAttachmentArtefakt) art; att.setStorageData(data); if (data.length > 0) { element.getElementInfo().getProps().setIntValue(GWikiPropKeys.SIZE, data.length); } else { ctx.addSimpleValidationError(ctx.getTranslated("gwiki.editor.empty")); return null; } if (!StringUtils.isEmpty(title)) { element.getElementInfo().getProps().setStringValue(GWikiPropKeys.TITLE, title); } else { element.getElementInfo().getProps().setStringValue(GWikiPropKeys.TITLE, pageIdFromTitle); } element.getElementInfo().getProps().setStringValue(GWikiPropKeys.PARENTPAGE, parentPageId); if (maxFileSize != null && StringUtils.isNotEmpty(maxFileSize)) { try { long maxSize = Long.parseLong(StringUtils.trimToEmpty(maxFileSize)) * 1024; long currSize = dataFile.getSize(); if (maxSize < currSize) { ctx.addSimpleValidationError( ctx.getTranslated("gwiki.editor.upload.filesize") + maxFileSize + " kB"); } else { ctx.getWikiWeb().saveElement(ctx, element, false); } } catch (Exception e) { GWikiLog.error(e.getMessage(), e); } } else { ctx.getWikiWeb().saveElement(ctx, element, false); } } catch (IOException ex) { ctx.addValidationError("gwiki.edit.EditPage.attach.message.uploadfailed", ex.getMessage()); } return parentPageId; }
From source file:com.thinkbiganalytics.discovery.model.DefaultField.java
/** * * Returns the structure in the format: Name | DataType | Desc | Primary \ CreatedTracker | UpdatedTracker | otherName * * @param otherName the name of the related field in either the alternate (either source or target) table * @return// w w w .j av a 2s . c om */ public String asFieldStructure(String otherName) { return name + "|" + getDataTypeWithPrecisionAndScale() + "|" + getDescriptionWithoutNewLines() + "|" + BooleanUtils.toInteger(primaryKey) + "|" + BooleanUtils.toInteger(createdTracker) + "|" + BooleanUtils.toInteger(updatedTracker) + "|" + StringUtils.trimToEmpty(otherName); }
From source file:com.intuit.karate.ScriptContext.java
public void configure(String key, ScriptValue value) { // TODO use enum key = StringUtils.trimToEmpty(key); if (key.equals("headers")) { headers = value;/* www . j a v a 2 s .c o m*/ } else if (key.equals("ssl")) { if (value.isString()) { sslEnabled = true; sslAlgorithm = value.getAsString(); } else { sslEnabled = value.isBooleanTrue(); } buildClient(); } else if (key.equals("connectTimeout")) { connectTimeout = Integer.valueOf(value.getAsString()); if (client != null) { client.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout); } // lightweight operation, no need to re-build client } else if (key.equals("readTimeout")) { readTimeout = Integer.valueOf(value.getAsString()); if (client != null) { client.property(ClientProperties.READ_TIMEOUT, readTimeout); } // lightweight operation, no need to re-build client } else if (key.equals("proxy")) { if (value.isString()) { proxyUri = value.getAsString(); } else { Map<String, Object> map = (Map) value.getAfterConvertingFromJsonOrXmlIfNeeded(); proxyUri = (String) map.get("uri"); proxyUsername = (String) map.get("username"); proxyPassword = (String) map.get("password"); } buildClient(); } else { throw new RuntimeException("unexpected 'configure' key: '" + key + "'"); } }
From source file:ke.co.tawi.babblesms.server.servlet.admin.source.Addmask.java
/** * Set the class variables that represent form parameters. * * @param request/*w w w . ja v a 2s . c om*/ */ private void setClassParameters(HttpServletRequest request) { maskname = StringUtils.trimToEmpty(request.getParameter("maskname")); networkuuid = StringUtils.trimToEmpty(request.getParameter("network")); accountuuid = StringUtils.trimToEmpty(request.getParameter("account")); }
From source file:kenh.expl.impl.BaseFunction.java
/** * Find the method with name <code>process</code> or <code>@Processing</code> *///from www.ja v a 2 s . co m @Override public Object invoke(Object... params) throws UnsupportedExpressionException { Method[] methods = this.getClass().getMethods(); for (Method method : methods) { String name = method.getName(); Class[] classes = method.getParameterTypes(); Annotation a = method.getAnnotation(Processing.class); if ((name.equals(METHOD) || a != null) && params.length == classes.length) { logger.trace("Method: " + method.toGenericString()); boolean find = true; Object[] objs = new Object[params.length]; for (int i = 0; i < params.length; i++) { Class class1 = params[i].getClass(); Class class2 = classes[i]; if (class2.isAssignableFrom(class1) || class2 == Object.class) { objs[i] = params[i]; } else if (class1 == String.class) { try { Object obj = Environment.convert((String) params[i], class2); if (obj == null) { logger.trace("Failure(Convert failure[" + (i + 1) + "-" + class1 + "," + class2 + "]): " + method.toGenericString()); find = false; break; } else { objs[i] = obj; } } catch (Exception e) { logger.trace("Failure(Convert exception[" + (i + 1) + "-" + e.getMessage() + "]): " + method.toGenericString()); find = false; break; //UnsupportedExpressionException ex = new UnsupportedExpressionException(e); //throw ex; } } else { logger.trace("Failure(Class unmatched[" + (i + 1) + "]): " + method.toGenericString()); find = false; break; } } if (find) { try { return method.invoke(this, objs); } catch (Exception e) { if (e instanceof UnsupportedExpressionException) throw (UnsupportedExpressionException) e; else throw new UnsupportedExpressionException(e); } } } } String paramStr = ""; for (Object param : params) { paramStr += param.getClass().getCanonicalName() + ", "; } paramStr = StringUtils.defaultIfBlank(StringUtils.chop(StringUtils.trimToEmpty(paramStr)), "<NO PARAM>"); UnsupportedExpressionException e = new UnsupportedExpressionException( "Can't find the method to process.[" + paramStr + "]"); throw e; }