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.community.chest.gitcloud.facade.ServletUtils.java
public static final Map<String, String> getRequestHeaders(HttpServletRequest req) { // NOTE: map must be case insensitive as per HTTP requirements Map<String, String> hdrsMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER); for (Enumeration<String> hdrs = req.getHeaderNames(); (hdrs != null) && hdrs.hasMoreElements();) { String hdrName = hdrs.nextElement(), hdrValue = req.getHeader(hdrName); hdrsMap.put(capitalizeHttpHeaderName(hdrName), StringUtils.trimToEmpty(hdrValue)); }//from w w w . ja v a2 s . c om return hdrsMap; }
From source file:com.blackducksoftware.integration.hub.teamcity.server.runner.HubParametersPreprocessor.java
private void addGlobalParameterMap(final Map<String, String> runParameters) { final HubServerConfig hubServerConfig = serverPeristanceManager.getHubServerConfig(); if (!runParameters.containsKey(HubConstantValues.HUB_URL)) { runParameters.put(HubConstantValues.HUB_URL, StringUtils.trimToEmpty(hubServerConfig.getHubUrl().toString())); }/*from w w w.j a v a 2 s . c om*/ if (!runParameters.containsKey(HubConstantValues.HUB_USERNAME)) { runParameters.put(HubConstantValues.HUB_USERNAME, StringUtils.trimToEmpty(hubServerConfig.getGlobalCredentials().getUsername())); } if (!runParameters.containsKey(HubConstantValues.HUB_PASSWORD)) { runParameters.put(HubConstantValues.HUB_PASSWORD, StringUtils.trimToEmpty(hubServerConfig.getGlobalCredentials().getEncryptedPassword())); } if (!runParameters.containsKey(HubConstantValues.HUB_PASSWORD_LENGTH)) { runParameters.put(HubConstantValues.HUB_PASSWORD_LENGTH, Integer.toString(hubServerConfig.getGlobalCredentials().getActualPasswordLength())); } if (!runParameters.containsKey(HubConstantValues.HUB_CONNECTION_TIMEOUT)) { runParameters.put(HubConstantValues.HUB_CONNECTION_TIMEOUT, String.valueOf(hubServerConfig.getTimeout())); } if (!runParameters.containsKey(HubConstantValues.HUB_TRUST_SERVER_CERT)) { runParameters.put(HubConstantValues.HUB_TRUST_SERVER_CERT, String.valueOf(hubServerConfig.isAlwaysTrustServerCertificate())); } if (!runParameters.containsKey(HubConstantValues.HUB_WORKSPACE_CHECK)) { runParameters.put(HubConstantValues.HUB_WORKSPACE_CHECK, String.valueOf(serverPeristanceManager.isHubWorkspaceCheck())); } final String ignoredProxyHosts = hubServerConfig.getProxyInfo().getIgnoredProxyHosts(); if (!runParameters.containsKey(HubConstantValues.HUB_NO_PROXY_HOSTS) && StringUtils.isNotBlank(ignoredProxyHosts)) { runParameters.put(HubConstantValues.HUB_NO_PROXY_HOSTS, StringUtils.trimToEmpty(ignoredProxyHosts)); } final String proxyHost = hubServerConfig.getProxyInfo().getHost(); final int proxyPort = hubServerConfig.getProxyInfo().getPort(); final String proxyUsername = hubServerConfig.getProxyInfo().getUsername(); final String proxyPassword = hubServerConfig.getProxyInfo().getEncryptedPassword(); final String proxyPasswordLength = Integer .toString(hubServerConfig.getProxyInfo().getActualPasswordLength()); if (StringUtils.isNotBlank(proxyHost) && proxyPort > 0) { if (!runParameters.containsKey(HubConstantValues.HUB_PROXY_HOST)) { runParameters.put(HubConstantValues.HUB_PROXY_HOST, StringUtils.trimToEmpty(proxyHost)); } if (!runParameters.containsKey(HubConstantValues.HUB_PROXY_PORT)) { runParameters.put(HubConstantValues.HUB_PROXY_PORT, String.valueOf(proxyPort)); } if (StringUtils.isNotBlank(proxyUsername) && StringUtils.isNotBlank(proxyPassword)) { if (!runParameters.containsKey(HubConstantValues.HUB_PROXY_USER)) { runParameters.put(HubConstantValues.HUB_PROXY_USER, StringUtils.trimToEmpty(proxyUsername)); } if (!runParameters.containsKey(HubConstantValues.HUB_PROXY_PASS)) { runParameters.put(HubConstantValues.HUB_PROXY_PASS, StringUtils.trimToEmpty(proxyPassword)); } if (!runParameters.containsKey(HubConstantValues.HUB_PROXY_PASS_LENGTH)) { runParameters.put(HubConstantValues.HUB_PROXY_PASS_LENGTH, proxyPasswordLength); } } } }
From source file:ke.co.tawi.babblesms.server.servlet.admin.account.AddAccount.java
/** * * @param request// w w w .j a v a2s .com * @param response * @throws ServletException, IOException */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(false); String name = StringUtils.trimToEmpty(request.getParameter("name")); String username = StringUtils.trimToEmpty(request.getParameter("username")); String email = StringUtils.trimToEmpty(request.getParameter("email")); String loginPasswd = StringUtils.trimToEmpty(request.getParameter("password")); String loginPasswd2 = StringUtils.trimToEmpty(request.getParameter("password2")); String phone = StringUtils.trimToEmpty(request.getParameter("phone")); // This is used to store parameter names and values from the form. Map<String, String> paramHash = new HashMap<>(); paramHash.put("name", name); paramHash.put("username", username); paramHash.put("email", email); paramHash.put("phone", phone); // No Name provided if (StringUtils.isBlank(name)) { session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_ERROR_KEY, ERROR_NO_NAME); // No Unique username provided } else if (StringUtils.isBlank(username)) { session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_ERROR_KEY, ERROR_NO_USERNAME); // usernane exist } else if (userNameExist(username)) { session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_ERROR_KEY, "username already exist in the System"); } else if (!emailValidator.isValid(email)) { session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_ERROR_KEY, ERROR_INVALID_EMAIL); // No website login password provided } else if (StringUtils.isBlank(loginPasswd) || StringUtils.isBlank(loginPasswd2)) { session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_ERROR_KEY, ERROR_NO_LOGIN_PASSWD); // The website login passwords provided do not match } else if (!StringUtils.equals(loginPasswd, loginPasswd2)) { session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_ERROR_KEY, ERROR_LOGIN_PASSWD_MISMATCH); } else { // If we get this far then all parameter checks are ok. session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_SUCCESS_KEY, "s"); // Reduce our session data session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_PARAMETERS, null); session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_ERROR_KEY, null); addAccount(name, username, email, loginPasswd, phone); session.setAttribute(SessionConstants.ADMIN_ADD_SUCCESS, "Account created successfully."); } session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_PARAMETERS, paramHash); response.sendRedirect("addaccount.jsp"); }
From source file:com.cognifide.aet.worker.impl.CollectorDispatcherImpl.java
@Override public Url run(Url url, CollectorJobData collectorJobData, WebCommunicationWrapper webCommunicationWrapper) throws AETException { LOGGER.info(/*from www . ja va2 s .c om*/ "Start collection from {}, with {} steps to perform. Company: {} Project: {} TestSuite: {} Test: {}", url.getUrl(), collectorJobData.getUrls().size(), collectorJobData.getCompany(), collectorJobData.getProject(), collectorJobData.getSuiteName(), collectorJobData.getTestName()); int stepNumber = 0; int totalSteps = url.getSteps().size(); for (final Step step : url.getSteps()) { stepNumber++; LOGGER.debug( "Performing collection step {}/{}: {} named {} with parameters: {} from {}. Company: {} Project: {} TestSuite: {} Test: {}", stepNumber, totalSteps, step.getType(), step.getName(), step.getParameters(), url.getUrl(), collectorJobData.getCompany(), collectorJobData.getProject(), collectorJobData.getSuiteName(), collectorJobData.getTestName()); final String urlWithDomain = StringUtils.trimToEmpty(url.getDomain()) + url.getUrl(); CollectorJob collectorJob = getConfiguredCollector(step, urlWithDomain, webCommunicationWrapper, collectorJobData); ExecutionTimer timer = ExecutionTimer.createAndRun("collector"); CollectorStepResult result = null; try { result = collectorJob.collect(); } catch (AETException e) { final String message = String.format( "Step: `%s` (with parameters: %s) thrown an exception when collecting url: %s in: `%s` test. Cause: %s", step.getType(), step.getParameters(), url.getUrl(), collectorJobData.getTestName(), getCause(e)); result = CollectorStepResult.newProcessingErrorResult(message); LOGGER.error("Failed to perform one of collect steps: {}.", step, e); } finally { timer.finishAndLog(step.getType()); step.setStepResult(result); } } LOGGER.info( "All collection steps from {} have been performed! Company: {} Project: {} TestSuite: {} Test: {}", url.getUrl(), collectorJobData.getCompany(), collectorJobData.getProject(), collectorJobData.getSuiteName(), collectorJobData.getTestName()); return url; }
From source file:com.omertron.themoviedbapi.model.PersonCredit.java
public void setDepartment(String department) { this.department = StringUtils.trimToEmpty(department); }
From source file:com.willwinder.universalgcodesender.i18n.Localization.java
public static String getString(String id) { String result = ""; try {//from w w w .jav a 2 s .c o m String val = bundle.getString(id); result = new String(val.getBytes("ISO-8859-1"), "UTF-8"); } catch (Exception e) { // Ignore this error, we will later try to fetch the string from the english bundle } if (StringUtils.isEmpty(StringUtils.trimToEmpty(result))) { try { if (english == null) { english = ResourceBundle.getBundle("resources.MessagesBundle", new Locale("en", "US")); } String val = english.getString(id); result = new String(val.getBytes("ISO-8859-1"), "UTF-8"); } catch (Exception e) { result = "<" + id + ">"; } } return result; }
From source file:com.qq.tars.service.config.ConfigService.java
@Transactional(rollbackFor = Exception.class) public ConfigFile addConfigFile(AddConfigFile params) { int level = params.getLevel(); Preconditions.checkState(level >= 1 && level <= 5); ConfigFile configFile = new ConfigFile(); configFile.setLevel(level == 5 ? 2 : 1); String server;/*from www . j a v a 2 s .c o m*/ if (configFile.getLevel() == 1) { Preconditions.checkState(StringUtils.isNoneBlank(params.getApplication())); server = params.getApplication(); } else { Preconditions.checkState(StringUtils.isNoneBlank(params.getApplication(), params.getServerName())); server = String.format("%s.%s", params.getApplication(), params.getServerName()); } configFile.setServerName(server); if (StringUtils.isNotBlank(params.getSetName())) { configFile.setSetName(params.getSetName()); } if (StringUtils.isNotBlank(params.getSetArea())) { configFile.setSetArea(params.getSetArea()); } if (StringUtils.isNotBlank(params.getSetGroup())) { configFile.setSetGroup(params.getSetGroup()); } Preconditions.checkState(StringUtils.isNotBlank(params.getFilename())); configFile.setFilename(params.getFilename()); configFile.setConfig(StringUtils.trimToEmpty(params.getConfig())); configFile.setPosttime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); configMapper.insertConfigFile(configFile); ConfigFileHistory history = new ConfigFileHistory(); history.setConfigId(configFile.getId()); history.setReason("?"); history.setContent(configFile.getConfig()); history.setPosttime(configFile.getPosttime()); configMapper.insertConfigFileHistory(history); // ?? if (configFile.getLevel() == 2) { boolean enableSet = StringUtils.isNoneBlank(params.getSetName(), params.getSetArea(), params.getSetGroup()); addDefaultNodeConfigFile(params.getApplication(), params.getServerName(), enableSet, params.getSetName(), params.getSetArea(), params.getSetGroup(), params.getFilename()); } return configFile; }
From source file:com.xpn.xwiki.plugin.calendar.CalendarEvent.java
public void setDescription(String description) { this.description = StringUtils.trimToEmpty(description); }
From source file:com.nesscomputing.syslog4j.server.impl.event.structured.StructuredSyslogServerEvent.java
protected void parseProcessId() { int i = this.message.indexOf(' '); if (i > -1) { this.processId = StringUtils.trimToEmpty(this.message.substring(0, i)); this.message = this.message.substring(i + 1); }/*w w w. ja v a2s . co m*/ if (SyslogConstants.STRUCTURED_DATA_NILVALUE.equals(this.processId)) { this.processId = null; } }
From source file:com.esri.geoportal.harvester.migration.MigrationDataBuilder.java
private URI createBrokerUri(MigrationData data) throws URISyntaxException { MigrationHarvestSite site = data.siteuuid != null ? sites.get(data.siteuuid) : null; if (site != null) { String type = StringUtils.trimToEmpty(site.type).toUpperCase(); switch (type) { case "WAF": return new URI("WAF", escapeUri(site.host), null); case "CKAN": return new URI("CKAN", escapeUri(site.host), null); case "ARCGIS": { int rsIdx = site.host.toLowerCase().indexOf("/rest/services"); String host = rsIdx >= 0 ? site.host.substring(0, rsIdx) : site.host; return new URI("AGS", escapeUri(host), null); }/*from w w w. j ava 2 s . com*/ case "CSW": try { Document doc = strToDom(site.protocol); XPath xPath = XPathFactory.newInstance().newXPath(); String protocolId = (String) xPath.evaluate("/protocol[@type='CSW']/profile", doc, XPathConstants.STRING); URL host = new URL(site.host); host = new URL(host.getProtocol(), host.getHost(), host.getPort(), host.getPath()); return new URI("CSW", host.toExternalForm(), protocolId); } catch (Exception ex) { } } } return brokerUri; }