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.github.achatain.nopasswordauthentication.utils.AuthorizedServlet.java
protected String extractApiToken(HttpServletRequest req) { String authorization = req.getHeader(HttpHeaders.AUTHORIZATION); Preconditions.checkArgument(authorization != null, "Missing authorization header"); String apiToken = StringUtils.removeStartIgnoreCase(authorization, BEARER_PREFIX); Preconditions.checkArgument(StringUtils.isNotBlank(apiToken), "Missing api token"); return StringUtils.trim(apiToken); }
From source file:de.micromata.genome.util.text.PipeValueList.java
/** * Trim.// w w w. j a v a2s . c om * * @param text the text * @return the string */ protected static String trim(String text) { if (text.length() < 3) { return text; } String ttext = StringUtils.trim(text); if (ttext.length() > 0 && ttext.endsWith("\\")) { return text; } return ttext; // } // if (text.charAt(text.length() - 2) != '\\') {// falls nicht am Ende escaped wurde, timmen // text = StringUtils.trim(text); // } else { // text = StringUtils.substring(text, 0, text.length() - 2) + StringUtils.substring(text, text.length() - 1, text.length()); // fallls. // escaped // wurde, // escape // zeichen // verwerfen // } // return text; }
From source file:com.mirth.connect.util.CodeTemplateUtil.java
public static String updateCode(String code) { if (StringUtils.isNotBlank(code)) { code = StringUtils.trim(code); int endIndex = 0; Matcher matcher = COMMENT_PATTERN.matcher(code); if (matcher.find()) { endIndex = matcher.end();// w ww . ja v a 2 s .co m } CodeTemplateDocumentation documentation = getDocumentation(code); String description = documentation.getDescription(); CodeTemplateFunctionDefinition functionDefinition = documentation.getFunctionDefinition(); if (StringUtils.isBlank(description)) { description = "Modify the description here. Modify the function name and parameters as needed. One function per template is recommended; create a new code template for each new function."; } StringBuilder builder = new StringBuilder("/**"); for (String descriptionLine : description.split("\r\n|\r|\n")) { builder.append("\n\t").append(WordUtils.wrap(descriptionLine, 100, "\n\t", false)); } if (functionDefinition != null) { builder.append('\n'); if (CollectionUtils.isNotEmpty(functionDefinition.getParameters())) { for (Parameter parameter : functionDefinition.getParameters()) { StringBuilder parameterBuilder = new StringBuilder("\n\t@param {"); parameterBuilder.append(StringUtils.defaultString(parameter.getType(), "Any")); parameterBuilder.append("} ").append(parameter.getName()).append(" - ") .append(StringUtils.trimToEmpty(parameter.getDescription())); builder.append(WordUtils.wrap(parameterBuilder.toString(), 100, "\n\t\t", false)); } } StringBuilder returnBuilder = new StringBuilder("\n\t@return {") .append(StringUtils.defaultString(functionDefinition.getReturnType(), "Any")).append("} ") .append(StringUtils.trimToEmpty(functionDefinition.getReturnDescription())); builder.append(WordUtils.wrap(returnBuilder.toString(), 100, "\n\t\t", false)); } builder.append("\n*/\n"); return builder.toString() + code.substring(endIndex); } return code; }
From source file:de.jfachwert.bank.BIC.java
/** * Hierueber kann man eine BIC ohne den Umweg ueber den Konstruktor * validieren.//www . j a v a2 s. c o m * * @param bic die BIC (11- oder 14-stellig) * @return die validierte BIC (zur Weiterverarbeitung) */ public static String validate(String bic) { String normalized = StringUtils.trim(bic); List<Integer> allowedLengths = Arrays.asList(8, 11, 14); if (!allowedLengths.contains(normalized.length())) { throw new InvalidLengthException(normalized, allowedLengths); } return normalized; }
From source file:com.adguard.android.contentblocker.ServiceApiClient.java
/** * Downloads filter rules//from ww w . j a v a2s . c om * * @param filterId Filter id * @return List of rules * @throws IOException */ public static List<String> downloadFilterRules(Context context, int filterId) throws IOException { String downloadUrl = RawResources.getFilterUrl(context); downloadUrl = downloadUrl.replace("{0}", UrlUtils.urlEncode(Integer.toString(filterId))); LOG.info("Sending request to {}", downloadUrl); String response = downloadString(downloadUrl); LOG.debug("Response length is {}", response.length()); String[] rules = StringUtils.split(response, "\r\n"); List<String> filterRules = new ArrayList<>(); for (String line : rules) { String rule = StringUtils.trim(line); if (!StringUtils.isEmpty(rule)) { filterRules.add(rule); } } return filterRules; }
From source file:com.xpn.xwiki.internal.XWikiConfigDelegate.java
@Override public String getProperty(String key) { return StringUtils.trim(this.source.getProperty(key, String.class)); }
From source file:com.mgmtp.jfunk.data.generator.field.InverseExpression.java
public InverseExpression(final MathRandom random, final Element element, final String characterSetId) { super(random, element, characterSetId); String expression = StringUtils.trim(element.getChildText(XMLTags.EXPRESSION)); // expression2 is optional expression2 = StringUtils.trim(element.getChildText(XMLTags.EXPRESSION + "2")); try {//ww w .j a va 2s. co m CharacterSet set = CharacterSet.getCharacterSet(characterSetId); exp = new GeneratingExpression(random, expression, set); } catch (IOException e) { throw new IllegalStateException("Error initialising GeneratingExpression", e); } range = exp.getRange(); }
From source file:com.dominion.salud.pedicom.negocio.repositories.impl.UsuariosRepositoryImpl.java
public Usuarios validarUsuarios(Usuarios usuarios) { List<LinParInt> list = linParIntRepository.getModulos(); String pass = usuarios.getPasswUsu(); String encriptado = "N"; for (LinParInt lin : list) { if (lin.getLinParIntPK().getTipo().equals("ENCRIPTADO")) { encriptado = StringUtils.trim(lin.getParametro()); }//from ww w. j av a 2 s .c o m } if (encriptado.equals("S")) { pass = encriptar(usuarios.getPasswUsu()); } return (Usuarios) entityManager .createQuery("from Usuarios where loginUsu = :loginUsu and passwUsu = :passwUsu", Usuarios.class) .setParameter("loginUsu", usuarios.getLoginUsu()).setParameter("passwUsu", pass).getSingleResult(); }
From source file:de.micromata.genome.chronos.util.DelayTrigger.java
/** * Instantiates a new delay trigger./*from w w w .jav a2 s . c o m*/ * * @param arg the arg */ public DelayTrigger(final String arg) { if (arg.startsWith("+") == false) { throw new IllegalArgumentException("wrong string format (prefiix '+' is missing: " + arg); } millis = Long.parseLong(StringUtils.trim(arg.substring(1))); nextFireTime = new Date(System.currentTimeMillis() + millis); }
From source file:com.mirth.connect.plugins.httpauth.basic.BasicAuthenticator.java
@Override public AuthenticationResult authenticate(RequestInfo request) { BasicHttpAuthProperties properties = getReplacedProperties(request); List<String> authHeaderList = request.getHeaders().get(HttpHeader.AUTHORIZATION.asString()); if (CollectionUtils.isNotEmpty(authHeaderList)) { String authHeader = StringUtils.trimToEmpty(authHeaderList.iterator().next()); int index = authHeader.indexOf(' '); if (index > 0) { String method = authHeader.substring(0, index); if (StringUtils.equalsIgnoreCase(method, "Basic")) { // Get Base64-encoded credentials String credentials = StringUtils.trim(authHeader.substring(index)); // Get the raw, colon-separated credentials credentials = new String(Base64.decodeBase64(credentials), StandardCharsets.ISO_8859_1); // Split on ':' to get the username and password index = credentials.indexOf(':'); if (index > 0) { String username = credentials.substring(0, index); String password = credentials.substring(index + 1); // Return successful result if the passwords match if (StringUtils.equals(password, properties.getCredentials().get(username))) { return AuthenticationResult.Success(username, properties.getRealm()); }//w w w.j av a2 s . co m } } } } // Return authentication challenge return AuthenticationResult.Challenged("Basic realm=\"" + properties.getRealm() + "\""); }