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.mirth.connect.connectors.jdbc.DatabaseDispatcherProperties.java
@Override public String toFormattedString() { StringBuilder builder = new StringBuilder(); String newLine = "\n"; builder.append("URL: "); builder.append(url);// w w w . j a v a2 s . c o m builder.append(newLine); builder.append("USERNAME: "); builder.append(username); builder.append(newLine); builder.append(newLine); builder.append(useScript ? "[SCRIPT]" : "[QUERY]"); builder.append(newLine); builder.append(StringUtils.trim(query)); for (int i = 0; i < parameters.length; i++) { builder.append(newLine); builder.append(newLine); builder.append("[PARAMETER "); builder.append(String.valueOf(i + 1)); builder.append("]"); builder.append(newLine); builder.append(parameters[i]); } return builder.toString(); }
From source file:com.buildabrand.gsb.util.URLUtils.java
/** * Returns the canonicalized form of a URL, core logic written by Henrik Sjostrand, heavily modified for v2 by Dave Shanley. * * @param queryURL//from ww w.j a v a 2s . co m * @return * @author Henrik Sjostrand, Netvouz, http://www.netvouz.com/, info@netvouz.com & Dave Shanley <dave@buildabrand.com> */ public String canonicalizeURL(String queryURL) { if (StringUtils.isEmpty(queryURL)) { return null; } // Start by stripping off the fragment identifier. queryURL = StringUtils.substringBefore(queryURL, "#"); // Stripping off leading and trailing white spaces. queryURL = StringUtils.trim(queryURL); // Remove any embedded tabs and CR/LF characters which aren't escaped. queryURL = StringUtils.remove(queryURL, '\t'); queryURL = StringUtils.remove(queryURL, '\r'); queryURL = StringUtils.remove(queryURL, '\n'); // Un-escape and re-escpae the URL just in case there are some encoded // characters in the url scheme for example. queryURL = escape(queryURL); URL url; try { url = new URL(queryURL); } catch (MalformedURLException e) { // Try again with "http://" try { url = new URL("http://" + queryURL); } catch (MalformedURLException e2) { logger.error("Malformed url", e); return null; } } if (!(url.getProtocol().equalsIgnoreCase("http") || url.getProtocol().equalsIgnoreCase("https") || url.getProtocol().equalsIgnoreCase("ftp"))) { return null; } // Note: applying HOST_PORT_REGEXP also removes any user and password. Matcher hostMatcher = HOST_PORT_REGEXP.matcher(url.getHost()); if (!hostMatcher.find()) { return null; } String host = hostMatcher.group(1); String canonicalHost = canonicalizeHost(host); if (canonicalHost == null) { return null; } // Now that the host is canonicalized we add the port back if it's not the // default port for that url scheme if (url.getPort() != -1 && ((url.getProtocol().equalsIgnoreCase("http") && url.getPort() != 80) || (url.getProtocol().equalsIgnoreCase("https") && url.getPort() != 443) || (url.getProtocol().equalsIgnoreCase("ftp") && url.getPort() != 21))) { canonicalHost = canonicalHost + ":" + url.getPort(); } String canonicalPath = canonicalizePath(url.getPath()); String canonicalUrl = url.getProtocol() + "://" + canonicalHost + canonicalPath; if (StringUtils.isNotEmpty(url.getQuery()) || queryURL.endsWith("?")) { canonicalUrl += "?" + url.getQuery(); } return canonicalUrl; }
From source file:io.wcm.devops.conga.plugins.sling.fileheader.OsgiConfigFileHeader.java
@Override public FileHeaderContext extract(FileContext file) { try {/*from ww w.j ava2 s .com*/ String content = FileUtils.readFileToString(file.getFile(), file.getCharset()); String[] contentLines = StringUtils.split(content, "\n"); if (contentLines.length > 0 && StringUtils.startsWith(contentLines[0], getCommentLinePrefix())) { String fullComment = StringUtils .trim(StringUtils.substringAfter(contentLines[0], getCommentBlockStart())); List<String> lines = ImmutableList.of(fullComment); return new FileHeaderContext().commentLines(lines); } } catch (IOException ex) { throw new GeneratorException("Unable parse add file header from " + file.getCanonicalPath(), ex); } return null; }
From source file:com.ottogroup.bi.spqr.websocket.server.SPQRWebSocketServer.java
/** * Initializes and executes the server components * @param configurationFile reference to configuration file * @throws IOException/*w w w. j a v a 2s .c o m*/ * @throws InterruptedException */ protected void run(final String configurationFile) throws IOException, InterruptedException { /////////////////////////////////////////////////////////////////// // lookup configuration file and create handle File cfgFile = new File(StringUtils.trim(configurationFile)); if (!cfgFile.isFile()) throw new FileNotFoundException("No configuration file found at '" + configurationFile + "'"); // /////////////////////////////////////////////////////////////////// run(new FileInputStream(cfgFile)); }
From source file:co.runrightfast.core.security.auth.x500.DistinguishedName.java
public DistinguishedName(String commonName, String localityName, String stateOrProvinceName, String organizationName, String organizationalUnitName, String country, String streetAddress, String domain, String userid) { this.commonName = StringUtils.trim(commonName); this.localityName = StringUtils.trim(localityName); this.stateOrProvinceName = StringUtils.trim(stateOrProvinceName); this.organizationName = StringUtils.trim(organizationName); this.organizationalUnitName = StringUtils.trim(organizationalUnitName); this.country = StringUtils.trim(country); this.streetAddress = StringUtils.trim(streetAddress); this.domain = StringUtils.trim(domain); this.userid = StringUtils.trim(userid); validate();//ww w.ja v a 2 s . c om }
From source file:com.datatorrent.contrib.kafka.AbstractKafkaOutputOperator.java
/** * setup producer configuration.// ww w .j a va 2s. c o m * @return ProducerConfig */ protected ProducerConfig createKafkaProducerConfig() { Properties prop = new Properties(); for (String propString : producerProperties.split(",")) { if (!propString.contains("=")) { continue; } String[] keyVal = StringUtils.trim(propString).split("="); prop.put(StringUtils.trim(keyVal[0]), StringUtils.trim(keyVal[1])); } configProperties.putAll(prop); return new ProducerConfig(configProperties); }
From source file:com.orange.ocara.ui.activity.CreateSiteActivity.java
protected String getSiteNoImmo() { return StringUtils.trim(siteNoImmo.getText().toString()); }
From source file:com.norconex.importer.handler.filter.impl.EmptyMetadataFilter.java
@Override protected boolean isDocumentMatched(String reference, InputStream input, ImporterMetadata metadata, boolean parsed) throws ImporterHandlerException { if (ArrayUtils.isEmpty(fields)) { return true; }/*from w ww. jav a2s .c o m*/ for (String prop : fields) { Collection<String> values = metadata.getStrings(prop); boolean isPropEmpty = true; for (String value : values) { if (!StringUtils.isBlank(StringUtils.trim(value))) { isPropEmpty = false; break; } } if (isPropEmpty) { return true; } } return false; }
From source file:com.ifunshow.dbc.util.DBHelper.java
public static String decideDbUrlString(String dbType, String ip_host, Integer port, String dbName) { String url = null;/*from www . ja va2 s. c om*/ String address = StringUtils.isNotBlank(ip_host) ? ip_host : "127.0.0.1"; if ("oracle".equalsIgnoreCase(StringUtils.trim(dbType))) { url = "jdbc:oracle:thin:@" + address + ":" + port + "/" + dbName;//oracle??tns?url } else if ("teradata".equalsIgnoreCase(StringUtils.trim(dbType))) { url = "jdbc:teradata://" + address + "/CLIENT_CHARSET=EUC_CN,TMODE=TERA,CHARSET=ASCII"; } else if ("db2".equalsIgnoreCase(StringUtils.trim(dbType))) { url = "jdbc:db2://" + address + ":" + port + "/" + dbName; } else if ("mysql".equalsIgnoreCase(StringUtils.trim(dbType))) { url = "jdbc:mysql://" + address + ":" + port + "/" + dbName; } return url; }
From source file:com.thoughtworks.go.config.BuiltinArtifactConfig.java
public void setSource(String source) { this.source = StringUtils.trim(source); }