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:com.omertron.themoviedbapi.model.PersonCredit.java
public void setMovieTitle(String movieTitle) { this.movieTitle = StringUtils.trimToEmpty(movieTitle); }
From source file:ke.co.tawi.babblesms.server.beans.account.Account.java
/** * * @param statusuuid */ public void setStatusuuid(String statusuuid) { this.statusuuid = StringUtils.trimToEmpty(statusuuid); }
From source file:kenh.xscript.elements.Call.java
@Override public int invoke() throws UnsupportedScriptException { logger.info(getInfo());/*from www . j a v a2s . com*/ this.getEnvironment().removeVariable(Return.VARIABLE_RETURN); // clear {return} // 1) find Method Map<String, Element> methods = this.getEnvironment().getMethods(); String name = getAttribute(ATTRIBUTE_METHOD_NAME); if (StringUtils.isBlank(name)) { UnsupportedScriptException ex = new UnsupportedScriptException(this, "The method name is empty."); throw ex; } try { name = (String) this.getEnvironment().parse(name); } catch (Exception e) { throw new UnsupportedScriptException(this, e); } String var = getAttribute(ATTRIBUTE_RETURN_NAME); if (StringUtils.isNotBlank(var)) { try { var = StringUtils.trimToNull((String) this.getEnvironment().parse(var)); } catch (Exception e) { throw new UnsupportedScriptException(this, e); } } Element e = methods.get(name); if (e == null || !(e instanceof Method)) { UnsupportedScriptException ex = new UnsupportedScriptException(this, "Could't find the method to invoke. [" + name + "]"); throw ex; } // 2) handle the Method's parameter Method m = (Method) e; String[][] parameters = m.getParameters(); Map<String, Object> new_vars = new LinkedHashMap(); List<String> new_cons = new LinkedList(); Vector parameterCallback = new Vector(); for (String[] parameter : parameters) { String paraName = StringUtils.trimToEmpty(parameter[0]); if (StringUtils.isBlank(paraName)) continue; boolean required = false; Object defaultValue = null; if (parameter.length > 1) { for (int i = 1; i < parameter.length; i++) { String modi = StringUtils.trimToEmpty(parameter[i]); if (modi.equals(Method.MODI_FINAL)) { new_cons.add(paraName); } if (modi.equals(Method.MODI_REQUIRED)) { required = true; } if ((modi.startsWith(Method.MODI_DEFAULT + "(") && modi.endsWith(")"))) { String defaultValue_ = StringUtils.substringAfter(modi, Method.MODI_DEFAULT + "("); defaultValue_ = StringUtils.substringBeforeLast(defaultValue_, ")"); try { defaultValue = this.getEnvironment().parse(defaultValue_); } catch (UnsupportedExpressionException e_) { UnsupportedScriptException ex = new UnsupportedScriptException(this, e_); throw ex; } } } } String paraValue = this.getAttribute(paraName); Object paraObj = null; if (paraValue == null) { if (required) { UnsupportedScriptException ex = new UnsupportedScriptException(this, "Missing parameter. [" + paraName + "]"); throw ex; } else { if (defaultValue != null) { new_vars.put(paraName, defaultValue); } } } else { try { paraObj = this.getEnvironment().parse(paraValue); new_vars.put(paraName, paraObj); if (paraObj instanceof kenh.expl.Callback) { parameterCallback.add(paraObj); } } catch (UnsupportedExpressionException ex) { throw new UnsupportedScriptException(this, ex); } } } if (this.getAttributes().size() > new_vars.size() + (this.getAttributes().containsKey(ATTRIBUTE_RETURN_NAME) ? 2 : 1)) { java.util.Set<String> keys = this.getAttributes().keySet(); String additional = ""; for (String key : keys) { if (key.equals(ATTRIBUTE_METHOD_NAME)) continue; if (key.equals(ATTRIBUTE_RETURN_NAME)) continue; if (new_vars.containsKey(key)) continue; additional = additional + key + ", "; } UnsupportedScriptException ex = new UnsupportedScriptException(this, "Unknown parameter. [" + StringUtils.substringBeforeLast(additional, ",") + "]"); throw ex; } // 3) remove non-public variable in Environment. save Method's parameter in Environment. List<String> publics = this.getEnvironment().getPublics(); List<String> constant = this.getEnvironment().getContants(); Map<String, Object> keep_vars = new LinkedHashMap(); List<String> keep_cons = new LinkedList(); List<String> keep_pubs = new LinkedList(); java.util.Set<String> keys = this.getEnvironment().getVariables().keySet(); for (String key : keys) { if (!publics.contains(key)) { keep_vars.put(key, this.getEnvironment().getVariable(key)); if (constant.contains(key)) keep_cons.add(key); } } keys = keep_vars.keySet(); for (String key : keys) { if (constant.contains(key)) constant.remove(key); this.getEnvironment().removeVariable(key, false); } // public variable in Environment have the same name with Method's parameter for (String[] parameter : parameters) { String key = StringUtils.trimToEmpty(parameter[0]); if (this.getEnvironment().containsVariable(key)) { if (constant.contains(key)) { constant.remove(key); keep_cons.add(key); } publics.remove(key); keep_pubs.add(key); keep_vars.put(key, this.getEnvironment().removeVariable(key, false)); } this.getEnvironment().setVariable(key, new_vars.get(key)); if (new_cons.contains(key)) constant.add(key); } // 4)invoke the Method's child elements. int r = m.processChildren(); if (r != RETURN && r != NONE) { if (r == EXCEPTION) { Object ex = this.getEnvironment().getVariable(Constant.VARIABLE_EXCEPTION); if (ex instanceof Exception) { if (ex instanceof UnsupportedScriptException) { throw (UnsupportedScriptException) ex; } else { UnsupportedScriptException ex_ = new UnsupportedScriptException(this, (Exception) ex); throw ex_; } } } UnsupportedScriptException ex = new UnsupportedScriptException(this, "Unsupported value is returned. [" + r + "]"); throw ex; } Object returnObj = null; if (StringUtils.isNotBlank(var)) { if (r == RETURN) { returnObj = this.getEnvironment().getVariable(Return.VARIABLE_RETURN); } else { UnsupportedScriptException ex = new UnsupportedScriptException(this, "The method does not have return value. [" + name + "]"); throw ex; } } // 5) remove non-public variable from Environment. restore original variables List<String> remove_vars = new LinkedList(); keys = this.getEnvironment().getVariables().keySet(); for (String key : keys) { if (!publics.contains(key)) { remove_vars.add(key); } } for (String key : remove_vars) { if (constant.contains(key)) constant.remove(key); Object obj = this.getEnvironment().getVariable(key); if (parameterCallback.contains(obj)) { this.getEnvironment().removeVariable(key, false); } else { this.getEnvironment().removeVariable(key); } } keys = keep_vars.keySet(); for (String key : keys) { if (!constant.contains(key)) { if (!this.getEnvironment().containsVariable(key)) this.getEnvironment().setVariable(key, keep_vars.get(key)); } if (keep_cons.contains(key)) constant.add(key); if (keep_pubs.contains(key)) publics.add(key); } // 6) store {return} if (returnObj != null) { this.saveVariable(var, returnObj, null); } return NONE; }
From source file:com.nesscomputing.syslog4j.server.impl.event.structured.StructuredSyslogServerEvent.java
protected void parseDate() { // skip VERSION field int i = this.message.indexOf(' '); this.message = this.message.substring(i + 1); // parse the date i = this.message.indexOf(' '); if (i > -1) { String dateString = StringUtils.trimToEmpty(this.message.substring(0, i)); try {//ww w . jav a 2 s . c o m DateTimeFormatter formatter = getDateTimeFormatter(); this.dateTime = formatter.parseDateTime(dateString); this.date = this.dateTime.toDate(); this.message = this.message.substring(dateString.length() + 1); } catch (Exception e) { // Not structured date format, try super one super.parseDate(); } } }
From source file:com.blackducksoftware.integration.hub.detect.detector.rubygems.GemlockParser.java
public DependencyGraph parseProjectDependencies(final List<String> gemfileLockLines) { encounteredDependencies = new ArrayList<>(); resolvedDependencies = new ArrayList<>(); lazyBuilder = new LazyExternalIdDependencyGraphBuilder(); currentParent = null;//w w w . j ava2 s .c o m for (final String line : gemfileLockLines) { final String trimmedLine = StringUtils.trimToEmpty(line); if (StringUtils.isBlank(trimmedLine)) { currentSection = NONE; } else if (SPECS_HEADER.equals(trimmedLine)) { currentSection = SPECS; } else if (DEPENDENCIES_HEADER.equals(trimmedLine)) { currentSection = DEPENDENCIES; } else if (BUNDLED_WITH_HEADER.equals(trimmedLine)) { currentSection = BUNDLED_WITH; } else if (BUNDLED_WITH.equals(currentSection)) { addBundlerDependency(trimmedLine); } else if (SPECS.equals(currentSection)) { parseSpecsSectionLine(line); } else if (DEPENDENCIES.equals(currentSection)) { parseDependencySectionLine(trimmedLine); } } List<String> missingDependencies = encounteredDependencies.stream() .filter(it -> !resolvedDependencies.contains(it)).collect(Collectors.toList()); for (final String missingName : missingDependencies) { String missingVersion = ""; final DependencyId dependencyId = new NameDependencyId(missingName); final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.RUBYGEMS, missingName, missingVersion); lazyBuilder.setDependencyInfo(dependencyId, missingName, missingVersion, externalId); } return lazyBuilder.build(); }
From source file:com.omertron.themoviedbapi.model.PersonCredit.java
public void setPosterPath(String posterPath) { this.posterPath = StringUtils.trimToEmpty(posterPath); }
From source file:com.xpn.xwiki.plugin.calendar.CalendarEvent.java
public void setLocation(String location) { this.location = StringUtils.trimToEmpty(location); }
From source file:com.threewks.thundr.http.SyntheticHttpServletResponse.java
@Override public void setContentType(String type) { String[] contentTypeAndCharacterEncoding = type == null ? new String[] { null } : type.split(";"); this.contentType = StringUtils.trim(StringUtils.lowerCase(contentTypeAndCharacterEncoding[0])); if (contentTypeAndCharacterEncoding.length > 1) { String encoding = StringUtils.trimToEmpty(contentTypeAndCharacterEncoding[1]); encoding = encoding.replaceAll("(?i)charset=", ""); setCharacterEncoding(encoding);/* ww w .j ava 2 s.c om*/ } }
From source file:ke.co.tawi.babblesms.server.servlet.upload.UploadUtil.java
/** * Checks that an uploaded Contact file is in proper order. * // w w w.jav a 2 s. c o m * @param file * @return the feedback of having inspected the file, whether it was proper */ protected String inspectContactFile(File file) { String feedback = ContactUpload.UPLOAD_SUCCESS; int count = 1; LineIterator lineIterator = null; try { lineIterator = FileUtils.lineIterator(file, "UTF-8"); String line; String[] rowTokens, phoneTokens, networkTokens; String network; while (lineIterator.hasNext()) { line = lineIterator.nextLine(); rowTokens = StringUtils.split(line, ','); if (rowTokens.length != 3 && line.length() > 0) {// Every row must have 3 columns return ("Invalid format on line " + count + ": " + line); } phoneTokens = StringUtils.split(rowTokens[1], ';'); networkTokens = StringUtils.split(rowTokens[2], ';'); // Check that the number of phone numbers and number of networks match if (phoneTokens.length != networkTokens.length) { return ("Invalid format on line " + count + ": " + line); } // Check that the phone numbers contain only numbers or spaces for (String phone : phoneTokens) { if (!StringUtils.isNumericSpace(phone)) { return ("Invalid number on line " + count + ": " + line); } } // Check to see that only valid networks have been provided for (String s : networkTokens) { network = StringUtils.lowerCase(StringUtils.trimToEmpty(s)); if (!networkList.contains(network)) { return ("Invalid network on line " + count + ": " + line); } } count++; } } catch (IOException e) { logger.error("IOException when inspecting: " + file); logger.error(e); } finally { if (lineIterator != null) { lineIterator.close(); } } return feedback; }
From source file:com.omertron.themoviedbapi.model.PersonCredit.java
public void setReleaseDate(String releaseDate) { this.releaseDate = StringUtils.trimToEmpty(releaseDate); }