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.ottogroup.bi.spqr.operator.webtrends.source.WebtrendStreamSource.java
/** * @see com.ottogroup.bi.spqr.pipeline.component.MicroPipelineComponent#initialize(java.util.Properties) *///from w w w. ja v a2 s . com public void initialize(Properties properties) throws RequiredInputMissingException, ComponentInitializationFailedException { ////////////////////////////////////////////////////////////////// // extract settings and validate values this.authAudience = StringUtils.trim(properties.getProperty(CFG_WT_AUTH_AUDIENCE)); this.authScope = StringUtils.trim(properties.getProperty(CFG_WT_AUTH_SCOPE)); this.authUrl = StringUtils.trim(properties.getProperty(CFG_WT_AUTH_URL)); this.clientId = StringUtils.trim(properties.getProperty(CFG_WT_CLIENT_ID)); this.clientSecret = StringUtils.trim(properties.getProperty(CFG_WT_CLIENT_SECRET)); this.eventStreamUrl = StringUtils.trim(properties.getProperty(CFG_WT_STREAM_URL)); this.streamType = StringUtils.trim(properties.getProperty(CFG_WT_STREAM_TYPE)); this.streamQuery = StringUtils.trim(properties.getProperty(CFG_WT_STREAM_QUERY)); this.streamVersion = StringUtils.trim(properties.getProperty(CFG_WT_STREAM_VERSION)); this.schemaVersion = StringUtils.trim(properties.getProperty(CFG_WT_SCHEMA_VERSION)); if (StringUtils.isBlank(authAudience)) throw new RequiredInputMissingException( "Missing required input for parameter '" + CFG_WT_AUTH_AUDIENCE + "'"); if (StringUtils.isBlank(authScope)) throw new RequiredInputMissingException( "Missing required input for parameter '" + CFG_WT_AUTH_SCOPE + "'"); if (StringUtils.isBlank(authUrl)) throw new RequiredInputMissingException( "Missing required input for parameter '" + CFG_WT_AUTH_URL + "'"); if (StringUtils.isBlank(clientId)) throw new RequiredInputMissingException( "Missing required input for parameter '" + CFG_WT_CLIENT_ID + "'"); if (StringUtils.isBlank(clientSecret)) throw new RequiredInputMissingException( "Missing required input for parameter '" + CFG_WT_CLIENT_SECRET + "'"); if (StringUtils.isBlank(eventStreamUrl)) throw new RequiredInputMissingException( "Missing required input for parameter '" + CFG_WT_STREAM_URL + "'"); if (StringUtils.isBlank(streamType)) throw new RequiredInputMissingException( "Missing required input for parameter '" + CFG_WT_STREAM_TYPE + "'"); if (StringUtils.isBlank(streamQuery)) throw new RequiredInputMissingException( "Missing required input for parameter '" + CFG_WT_STREAM_QUERY + "'"); if (StringUtils.isBlank(streamVersion)) throw new RequiredInputMissingException( "Missing required input for parameter '" + CFG_WT_STREAM_VERSION + "'"); if (StringUtils.isBlank(schemaVersion)) throw new RequiredInputMissingException( "Missing required input for parameter '" + CFG_WT_SCHEMA_VERSION + "'"); // ////////////////////////////////////////////////////////////////// // authenticate with the webtrends service WebtrendsTokenRequest tokenRequest = new WebtrendsTokenRequest(this.authUrl, this.authAudience, this.authScope, this.clientId, this.clientSecret); try { this.oAuthToken = tokenRequest.execute(); } catch (Exception e) { throw new RuntimeException("Failed to request token from '" + authUrl + "'. Error: " + e.getMessage()); } // initialize the webtrends stream socket client and connect the listener this.webtrendsStreamSocketClient = new WebSocketClient(); try { this.webtrendsStreamSocketClient.start(); ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest(); this.webtrendsStreamSocketClient.connect(this, new URI(this.eventStreamUrl), upgradeRequest); await(5, TimeUnit.SECONDS); } catch (Exception e) { throw new RuntimeException("Unable to connect to web socket: " + e.getMessage(), e); } this.isRunning = true; }
From source file:de.micromata.genome.gwiki.controls.GWikiRegisterUserActionBean.java
protected boolean doRegister() { if (StringUtils.isBlank(catchaInput) == true) { wikiContext.addValidationFieldError("gwiki.page.admin.RegisterUser.message.nocatcha", "catchaInput"); return false; }/* w w w .j a v a 2 s.c om*/ if (checkCatcha() == false) { wikiContext.addValidationFieldError("gwiki.page.admin.RegisterUser.message.wrongcatcha", "catchaInput"); return false; } user = StringUtils.trim(user); if (StringUtils.isBlank(user) == true) { wikiContext.addValidationFieldError("gwiki.page.admin.RegisterUser.message.userempty", "user"); return false; } email = StringUtils.trim(email); if (StringUtils.isBlank(email) == true) { wikiContext.addValidationFieldError("gwiki.page.admin.RegisterUser.message.emailempty", "email"); return false; } if (checkEmail(email) == false) { wikiContext.addValidationFieldError("gwiki.page.admin.RegisterUser.message.emailnotvalid", "email"); return false; } if (doubleOptIn == false) { if (StringUtils.isBlank(pass) == true) { wikiContext.addValidationFieldError("gwiki.page.admin.RegisterUser.message.passempty", "pass"); pass2 = ""; return false; } if (pass.equals(pass2) == false) { wikiContext.addValidationFieldError("gwiki.page.admin.RegisterUser.message.passnotequal", "pass"); return false; } } else { pass = GWikiLoginActionBean.genPassword(); } GWikiAuthorizationExt authExt = (GWikiAuthorizationExt) wikiContext.getWikiWeb().getAuthorization(); if (authExt.hasUser(wikiContext, user) == true) { wikiContext.addValidationFieldError("gwiki.page.admin.RegisterUser.message.userexists", "user"); return false; } if (GWikiSimpleUserAuthorization.rankPasswort(pass) < 1000) { wikiContext.addValidationFieldError("gwiki.profile.message.password_too_simple", "pass"); return false; } String cp = GWikiSimpleUserAuthorization.encrypt(pass); GWikiProps props = new GWikiProps(); GWikiElement registeredUser = wikiContext.getWikiWeb().findElement("admin/user/registereduser"); if (registeredUser != null) { props = new GWikiProps(((GWikiPropsArtefakt) registeredUser.getMainPart()).getCompiledObject()); } props.setStringValue(GWikiAuthorizationExt.USER_PROP_EMAIL, email); if (props.getStringValue(GWikiAuthorizationExt.USER_PROP_RIGHTSRULE, null) == null) { props.setStringValue(GWikiAuthorizationExt.USER_PROP_RIGHTSRULE, "GWIKI_VIEWPAGES"); } props.setStringValue(GWikiAuthorizationExt.USER_PROP_PASSWORD, cp); Locale loc = wikiContext.getRequest().getLocale(); GWikiGlobalConfig gc = wikiContext.getWikiWeb().getWikiConfig(); if (loc != null) { String lang = loc.getLanguage(); if (gc.getAvailableLanguages(wikiContext).contains(lang) == true) { props.setStringValue(GWikiAuthorizationExt.USER_LANG, lang); } } if (StringUtils.isEmpty(clientTzOffset) == false) { try { int offsetMin = Integer.parseInt(clientTzOffset); int daysaving = TimeZone.getDefault().getDSTSavings(); int offsetMs = (offsetMin * 1000 * 60 * -1) - daysaving; int offsetHour = ((offsetMin / 60) * -1) - (daysaving / ((int) TimeInMillis.HOUR)); String tzs = "Etc/GMT"; if (offsetHour != 0) { if (offsetHour > 0) { tzs += "+"; } tzs += offsetHour; } List<String> tcs = gc.getAvailableTimeZones(wikiContext); if (tcs.contains(tzs) == true) { props.setStringValue(GWikiAuthorizationExt.USER_TZ, tzs); } else { // String[] offsets = TimeZone.getAvailableIDs(offsetMs); for (String tzss : tcs) { TimeZone tz = TimeZone.getTimeZone(tzss); int rawo = tz.getOffset(System.currentTimeMillis()); if (rawo == offsetMs) { props.setStringValue(GWikiAuthorizationExt.USER_TZ, tzss); break; } } } } catch (NumberFormatException ex) { // ignore } } if (authExt.createUser(wikiContext, user, props) == false) { wikiContext.addValidationError("gwiki.page.admin.RegisterUser.message.internalerrorstore"); return false; } if (doubleOptIn == true) { try { GWikiLoginActionBean.sendPasswordToUser(wikiContext, user, email, pass); wikiContext.addValidationError("gwiki.page.admin.Login.message.resetpassw.emailsent"); } catch (Exception ex) { GWikiLog.error("Cannot send register email: " + ex.getMessage(), ex); wikiContext.addValidationError("gwiki.page.admin.RegisterUser.message.unabletosend"); } showForm = false; } else { boolean success = wikiContext.getWikiWeb().getAuthorization().login(wikiContext, StringUtils.trim(user), StringUtils.trim(pass)); if (success == false) { return false; } } return true; }
From source file:io.github.seiferma.jameica.hibiscus.dkb.creditcard.synchronize.scraper.DKBTransactionScraper.java
private static boolean matches(String ccNumber, String anonymizedCcNumber) { String candidate = StringUtils.trim(anonymizedCcNumber); Pattern p = Pattern.compile(".*?([0-9]{4})[0-9*]*([0-9]{4}).*"); Matcher m = p.matcher(candidate); if (!m.matches() || m.groupCount() < 2) { return false; }//from w ww . j a v a 2 s. c o m String foundFirstDigits = m.group(1); String foundLastDigits = m.group(2); String requiredFirstDigits = ccNumber.substring(0, 4); String requiredLastDigits = ccNumber.substring(ccNumber.length() - 4, ccNumber.length()); return requiredFirstDigits.equals(foundFirstDigits) && requiredLastDigits.equals(foundLastDigits); }
From source file:mfi.filejuggler.responsibles.BasicApplication.java
@Responsible(conditions = { Condition.LOGIN_GENERATE_CREDENTIALS }) public void fjAnmeldeCredentialsGenerieren(StringBuilder sb, Map<String, String> parameters, Model model) throws Exception { String user = StringUtils.trim(parameters.get("new_user")); String pass1 = StringUtils.trim(parameters.get("new_pass1")); String pass2 = StringUtils.trim(parameters.get("new_pass2")); if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(pass1) && StringUtils.isNotBlank(pass2)) { if (!StringUtils.equals(pass1, pass2)) { model.lookupConversation().getMeldungen() .add("Die beiden eingegebenen Passwrter sind nicht identisch"); model.lookupConversation().setForwardCondition(Condition.LOGIN_GENERATE_CREDENTIALS_FORM); return; }//from w w w . ja v a2 s .com if (KVMemoryMap.getInstance().containsKey("user." + user)) { model.lookupConversation().getMeldungen().add("Ein Account mit dem Namen existiert bereits."); model.lookupConversation().setForwardCondition(Condition.LOGIN_GENERATE_CREDENTIALS_FORM); return; } String hash = Crypto.encryptLoginCredentials(user, pass1); String verification = Security.generateVerificationString(); KVMemoryMap.getInstance().writeKeyValue("user." + user, "FALSE" + " # " + verification, false); KVMemoryMap.getInstance().writeKeyValue("user." + user + ".pass", hash, false); KVMemoryMap.getInstance().writeKeyValue("user." + user + ".allowedDirectory", "##########", false); KVMemoryMap.getInstance().writeKeyValue("user." + user + ".favoriteFolders", "##########", false); KVMemoryMap.getInstance().writeKeyValue("user." + user + ".homeDirectory", "##########", false); KVMemoryMap.getInstance().save(); logger.info("User/Passwort generiert fuer: " + user); model.lookupConversation().getMeldungen() .add("Neuer Account fr Benutzer " + user + " wurde vorbereitet."); model.lookupConversation().getMeldungen().add( "Bitte den Administrator informieren, um das Konto freizuschalten und dabei den Verifikationsschlssel '" + verification + "' nennen"); } else { model.lookupConversation().getMeldungen().add("Bitte Name und Passwort eingeben."); } model.lookupConversation().setForwardCondition(Condition.LOGIN_FORMULAR); return; }
From source file:com.wxine.android.model.Community.java
public Set<String> getTags() { try {/*from w w w .j av a 2 s .c o m*/ String[] array = tag.split(","); for (String a : array) { if (StringUtils.isNotBlank(a)) { tags.add(StringUtils.trim(StringUtils.strip(a))); } } } catch (Exception e) { } return tags; }
From source file:com.ottogroup.bi.asap.pipeline.MicroPipelineManager.java
/** * Creates and registers a {@link Pipeline} for the given {@link PipelineConfiguration} * @param pipelineConfiguration//ww w .ja v a 2 s.c o m * @throws PipelineAlreadyRegisteredException * @throws RequiredInputMissingException * @throws ComponentInstantiationFailedException * @throws UnknownComponentException * @throws IllegalComponentSubscriptionException * @throws ComponentAlreadySubmittedException */ public String instantiatePipeline(final MicroPipelineConfiguration pipelineConfiguration) throws PipelineAlreadyRegisteredException, RequiredInputMissingException, UnknownComponentException, ComponentInstantiationFailedException, ComponentAlreadySubmittedException, IllegalComponentSubscriptionException { ////////////////////////////////////////////////////////////// // validate input if (pipelineConfiguration == null) throw new RequiredInputMissingException("Missing required pipeline configuration"); if (StringUtils.isBlank(pipelineConfiguration.getId())) throw new RequiredInputMissingException("Missing required pipeline identifier"); String pipelineId = StringUtils.lowerCase(StringUtils.trim(pipelineConfiguration.getId())); if (this.microPipelines.containsKey(pipelineId)) throw new PipelineAlreadyRegisteredException("A pipeline already exists for that identifer"); // ////////////////////////////////////////////////////////////// MicroPipeline pipeline = factory.instantiate(pipelineConfiguration, pipelineThreadPool); this.microPipelines.put(pipelineId, pipeline); if (logger.isDebugEnabled()) logger.debug("Pipeline '" + pipelineId + "' successfully instantiated and submitted to thread pool"); return pipelineConfiguration.getId(); }
From source file:jp.co.golorp.emarf.util.StringUtil.java
/** * @param s/*from w w w.jav a 2 s . c o m*/ * s * @return \b,\r,\n," "?? */ public static String trim(final String s) { String ret = StringUtils.trim(s); if (ret != null) { ret.replaceAll("\\b|\\r|\\n", "").trim(); } return ret; }
From source file:com.navercorp.pinpoint.collector.config.CollectorConfiguration.java
protected void readPropertyValues(Properties properties) { LOGGER.info("pinpoint-collector.properties read."); this.agentEventWorkerThreadSize = readInt(properties, "collector.agentEventWorker.threadSize", 32); this.agentEventWorkerQueueSize = readInt(properties, "collector.agentEventWorker.queueSize", 1024 * 5); String[] l4Ips = StringUtils.split(readString(properties, "collector.l4.ip", null), ","); if (l4Ips == null) { this.l4IpList = Collections.emptyList(); } else {/*w ww . j a v a 2 s.c o m*/ this.l4IpList = new ArrayList<>(l4Ips.length); for (String l4Ip : l4Ips) { if (!StringUtils.isEmpty(l4Ip)) { this.l4IpList.add(StringUtils.trim(l4Ip)); } } } this.clusterEnable = readBoolean(properties, "cluster.enable"); this.clusterAddress = readString(properties, "cluster.zookeeper.address", ""); this.clusterSessionTimeout = readInt(properties, "cluster.zookeeper.sessiontimeout", -1); this.clusterListenIp = readString(properties, "cluster.listen.ip", ""); this.clusterListenPort = readInt(properties, "cluster.listen.port", -1); }
From source file:com.kingen.web.CommonController.java
/** * ??/* w w w. jav a 2 s .c om*/ * 1. ?StringHTML?XSS * 2. Date?String */ @InitBinder protected void initBinder(WebDataBinder binder) { // String??StringHTML?XSS binder.registerCustomEditor(String.class, new PropertyEditorSupport() { @Override public void setAsText(String text) { setValue(text == null ? null : text.trim()); // setValue(text == null ? null : StringEscapeUtils.escapeHtml4(text.trim())); // setValue(text == null ? null : StringEscapeUtils.escapeJavaScript(text.trim())); } @Override public String getAsText() { Object value = getValue(); return value != null ? value.toString() : ""; } }); // Date ? binder.registerCustomEditor(Date.class, new PropertyEditorSupport() { @Override public void setAsText(String text) { setValue(DateUtils.parseDate(StringUtils.trim(text))); logger.debug("---" + getValue()); } }); }
From source file:de.micromata.genome.gwiki.utils.CommaListParser.java
/** * Parses the comma list.//from w ww . j av a2 s. c o m * * @param input the input * @param trimValues the trim values * @return the list */ public static List<String> parseCommaList(String input, boolean trimValues) { if (input == null || input.length() == 0) { return Collections.emptyList(); } List<String> ret = new ArrayList<String>(); int lastBegin = 0; State state = State.StartField; loop: for (int i = 0; i < input.length(); ++i) { char c = input.charAt(i); switch (state) { case StartField: if (trimValues == true && Character.isWhitespace(c) == true) { lastBegin = i + 1; continue; } if (c == ',') { ret.add(""); lastBegin = i + 1; continue; } if (c == '"') { lastBegin = i + 1; state = State.InQuotedField; continue; } state = State.InField; lastBegin = i; break; case InField: if (c == ',') { int lc = i; if (trimValues == true) { lc = seekNonWsBack(input, lc - 1); } ret.add(input.substring(lastBegin, lc)); state = State.StartField; continue; } continue; case InQuotedField: if (c == '\\') { if (i + 1 >= input.length()) { ret.add(input.substring(lastBegin, i + 1)); break loop; } char nc = input.charAt(i + 1); if (nc == '\"' || nc == '\\') { ++i; continue; } continue; } else if (c == '"') { String t = input.substring(lastBegin, i); t = unquote(t); ret.add(t); i = skeepWs(input, i + 1); if (i >= input.length()) { lastBegin = i; break loop; } char c2 = input.charAt(i); if (c2 != ',') { throw new RuntimeException("In Input at position " + i + " expects ',', got: " + c2); } ++i; lastBegin = i; state = State.StartField; } break; } } if (lastBegin < input.length()) { switch (state) { case InField: { String t = input.substring(lastBegin, input.length()); t = StringUtils.trim(t); ret.add(t); break; } case InQuotedField: throw new RuntimeException("In Input at position " + (input.length() - 1) + " expects ending '\"', got end of input. text: '" + input + "'"); case StartField: if (ret.size() > 0) { ret.add(""); } break; } } else if (state == State.StartField && ret.size() > 0) { ret.add(""); } return ret; }