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.monarchapis.client.authentication.HawkV1RequestProcessor.java
private static String getHawkHash(BaseClient<?> client) { try {//from w ww . jav a 2 s . c o m StringBuilder sb = new StringBuilder(); String httpContent = client.getBody(); String mimeType = ""; String content = ""; if (httpContent != null) { mimeType = StringUtils.trimToEmpty(StringUtils.substringBefore(client.getContentType(), ";")); content = httpContent; } sb.append("hawk.1.payload\n"); sb.append(mimeType); sb.append("\n"); sb.append(content); sb.append("\n"); MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] hash = digest.digest(sb.toString().getBytes("UTF-8")); return Base64.encodeBase64String(hash); } catch (Exception e) { throw new RuntimeException("Could not create hawk hash", e); } }
From source file:ke.co.tawi.babblesms.server.beans.contact.Contact.java
/** * @param accountUuid the accountUuid to set *///from w w w .j a v a 2 s . c o m public void setAccountUuid(String accountUuid) { this.accountUuid = StringUtils.trimToEmpty(accountUuid); }
From source file:ke.co.tawi.babblesms.server.servlet.admin.smsgateway.ResetNotificationUrl.java
/** * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *///from www. j av a 2 s. c o m public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(false); String Url = StringUtils.trimToEmpty(request.getParameter("url")); String Username = StringUtils.trimToEmpty(request.getParameter("username")); String AccountUuid = StringUtils.trimToEmpty(request.getParameter("accountuuid")); System.out.println(Url); Account account = new Account(); account.setUuid(AccountUuid); TawiGateway gateway = gatewayDAO.get(account); gateway.setUrl(Url); gateway.setUsername(Username); gateway.setAccountUuid(AccountUuid); if (gatewayDAO.edit(gateway)) { session.setAttribute(SessionConstants.ADMIN_UPDATE_SUCCESS, "TawiGateway updated successfully."); } else { session.setAttribute(SessionConstants.ADMIN_UPDATE_ERROR, "TawiGateway update failed."); } response.sendRedirect("admin/accounts.jsp"); }
From source file:ke.co.tawi.babblesms.server.beans.notification.Notification.java
/** * @param longDesc - the longDesc to set */ public void setLongDesc(String longDesc) { this.longDesc = StringUtils.trimToEmpty(longDesc); }
From source file:com.kixeye.chassis.transport.swagger.SwaggerServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // figure out the real path String pathInfo = StringUtils.trimToEmpty(req.getPathInfo()); while (pathInfo.endsWith("/")) { pathInfo = StringUtils.removeEnd(pathInfo, "/"); }//from w ww. j a v a 2s . co m while (pathInfo.startsWith("/")) { pathInfo = StringUtils.removeStart(pathInfo, "/"); } if (StringUtils.isBlank(pathInfo)) { resp.sendRedirect(rootContextPath + "/" + WELCOME_PAGE); } else { // get the resource AbstractFileResolvingResource resource = (AbstractFileResolvingResource) resourceLoader .getResource(SWAGGER_DIRECTORY + "/" + pathInfo); // send it to the response if (resource.exists()) { StreamUtils.copy(resource.getInputStream(), resp.getOutputStream()); resp.setStatus(HttpServletResponse.SC_OK); resp.flushBuffer(); } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND); } } }
From source file:com.esri.geoportal.harvester.waf.WafBrokerDefinitionAdaptor.java
/** * Creates instance of the adaptor.// w w w .jav a 2 s. c o m * @param def broker definition * @throws IllegalArgumentException if invalid broker definition */ public WafBrokerDefinitionAdaptor(EntityDefinition def) throws InvalidDefinitionException { super(def); this.credAdaptor = new CredentialsDefinitionAdaptor(def); this.botsAdaptor = new BotsBrokerDefinitionAdaptor(def); if (StringUtils.trimToEmpty(def.getType()).isEmpty()) { def.setType(WafConnector.TYPE); } else if (!WafConnector.TYPE.equals(def.getType())) { throw new InvalidDefinitionException("Broker definition doesn't match"); } else { try { hostUrl = new URL(get(P_HOST_URL)); } catch (MalformedURLException ex) { throw new InvalidDefinitionException(String.format("Invalid %s: %s", P_HOST_URL, get(P_HOST_URL)), ex); } pattern = get(P_PATTERN); } }
From source file:ke.co.tawi.babblesms.server.beans.log.Log.java
/** * * @param destination */ public void setDestination(String destination) { this.destination = StringUtils.trimToEmpty(destination); }
From source file:com.esri.geoportal.commons.csw.client.impl.DcList.java
/** * Adds the dc string//from ww w .j av a 2 s .c o m * * @param dcString the dc string */ public void add(String dcString) { dcString = StringUtils.trimToEmpty(dcString); if ("".equals(dcString)) { return; } String schemeValues[] = dcString.split(DELIMETER_LIST); String arrKeyValue[]; for (String schemeValue : schemeValues) { schemeValue = StringUtils.trimToEmpty(schemeValue); if ("".equals(schemeValue)) { continue; } arrKeyValue = schemeValue.split(DELIMETER_VALUES); if (arrKeyValue.length == 1) { this.add(this.new Value(arrKeyValue[0], EMPTY_SCHEME)); continue; } this.add(this.new Value(arrKeyValue[0], arrKeyValue[1])); } }
From source file:ke.co.tawi.babblesms.server.servlet.admin.smsgateway.AddNotificationUrl.java
/** * * @param request//from ww w . java 2s . c o m * @param response * @throws ServletException, IOException */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(false); String user = StringUtils.trimToEmpty(request.getParameter("user")); String url = StringUtils.trimToEmpty(request.getParameter("url")); String password = StringUtils.trimToEmpty(request.getParameter("password")); String password2 = StringUtils.trimToEmpty(request.getParameter("password2")); // This is used to store parameter names and values from the form. Map<String, String> paramHash = new HashMap<>(); paramHash.put("url", url); String uuid = user.split("\\|")[0]; String uname = user.split("\\|")[1]; /*System.out.println(uuid); System.out.println(uname);*/ // No Url provided if (StringUtils.isBlank(url)) { session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_ERROR_KEY, "please provide a Url"); // usernane exist } // No Url provided else if (StringUtils.isBlank(password)) { session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_ERROR_KEY, "please provide password"); // usernane exist } else if (StringUtils.isBlank(password2)) { session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_ERROR_KEY, "please confirm password"); // usernane exist } else if (userNameExist(uname)) { session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_ERROR_KEY, "username already exist in the System"); } else if (!StringUtils.equals(password, password2)) { session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_ERROR_KEY, "Password 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); TawiGateway g = new TawiGateway(); g.setAccountUuid(uuid); g.setUrl(url); g.setUsername(uname); g.setPasswd(password); gatewayDAO.put(g); //session.setAttribute(SessionConstants.ADMIN_ADD_SUCCESS, "Account created successfully."); } response.sendRedirect("addaccount.jsp"); session.setAttribute(SessionConstants.ADMIN_ADD_ACCOUNT_PARAMETERS, paramHash); }
From source file:com.blackducksoftware.integration.hub.detect.util.filter.DetectOverrideableFilter.java
private Set<String> createSetFromString(final String s) { final Set<String> set = new HashSet<>(); final StringTokenizer stringTokenizer = new StringTokenizer(StringUtils.trimToEmpty(s), ","); while (stringTokenizer.hasMoreTokens()) { set.add(StringUtils.trimToEmpty(stringTokenizer.nextToken())); }/* w w w . ja v a 2s . c om*/ return set; }