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.kafka.emitter.KafkaTopicEmitter.java
/** * @see com.ottogroup.bi.spqr.pipeline.component.MicroPipelineComponent#initialize(java.util.Properties) *//* w w w.j av a 2 s .c o m*/ public void initialize(Properties properties) throws RequiredInputMissingException, ComponentInitializationFailedException { ///////////////////////////////////////////////////////////////////////// // input extraction and validation if (properties == null) throw new RequiredInputMissingException("Missing required properties"); clientId = StringUtils.lowerCase(StringUtils.trim(properties.getProperty(CFG_OPT_KAFKA_CLIENT_ID))); if (StringUtils.isBlank(clientId)) throw new RequiredInputMissingException("Missing required kafka client id"); zookeeperConnect = StringUtils .lowerCase(StringUtils.trim(properties.getProperty(CFG_OPT_ZOOKEEPER_CONNECT))); if (StringUtils.isBlank(zookeeperConnect)) throw new RequiredInputMissingException("Missing required zookeeper connect"); topicId = StringUtils.lowerCase(StringUtils.trim(properties.getProperty(CFG_OPT_TOPIC_ID))); if (StringUtils.isBlank(topicId)) throw new RequiredInputMissingException("Missing required topic"); brokerList = StringUtils.lowerCase(StringUtils.trim(properties.getProperty(CFG_OPT_BROKER_LIST))); if (StringUtils.isBlank(brokerList)) throw new RequiredInputMissingException("Missing required broker list"); String charsetName = StringUtils.trim(properties.getProperty(CFG_OPT_CHARSET)); try { if (StringUtils.isNotBlank(charsetName)) charset = Charset.forName(charsetName); else charset = Charset.forName("UTF-8"); } catch (Exception e) { throw new RequiredInputMissingException( "Invalid character set provided: " + charsetName + ". Error: " + e.getMessage()); } messageAcking = StringUtils .equalsIgnoreCase(StringUtils.trim(properties.getProperty(CFG_OPT_MESSAGE_ACKING)), "true"); // ///////////////////////////////////////////////////////////////////////// if (logger.isDebugEnabled()) logger.debug("kafka emitter[id=" + this.id + ", client=" + clientId + ", topic=" + topicId + ", broker=" + brokerList + ", zookeeper=" + zookeeperConnect + ", charset=" + charset.name() + ", messageAck=" + messageAcking + "]"); // initialize the producer only if it is not already exist --- typically assigned through test case! if (kafkaProducer == null) { Properties props = new Properties(); props.put(CFG_ZK_CONNECT, zookeeperConnect); props.put(CFG_BROKER_LIST, brokerList); props.put(CFG_REQUEST_REQUIRED_ACKS, (messageAcking ? "1" : "0")); props.put(CFG_CLIENT_ID, clientId); this.kafkaProducer = new Producer<>(new ProducerConfig(props)); } }
From source file:com.sonicle.webtop.core.versioning.Whatsnew.java
private void readFile(BufferedReader reader, ServiceVersion fromVersion, ServiceVersion toVersion) throws IOException { Matcher matcher = null;//from ww w. j av a 2s . c o m String line = null, marker = null, text = null; ServiceVersion lineVersion = null; StringBuilder sb = null; boolean skip = false; int lineNo = 0; while ((line = reader.readLine()) != null) { lineNo++; line = StringUtils.trim(line); matcher = PATTER_LINE.matcher(line); if (matcher.matches()) { marker = matcher.group(1); text = StringUtils.trim(matcher.group(2)); text = LangUtils.escapeHtmlAccentsAndSymbols(text); if (marker.equals("$")) { // Version marker // Closes previous version's section if (sb != null) { this.closeList(sb); //htmls.put(lineVersion.toString(), sb.toString()); htmls.put(lineVersion.toString(), replaceVariables(sb.toString())); sb = null; } lineVersion = new ServiceVersion(text); if (lineVersion.getValue() == null) throw new IOException(MessageFormat.format("Bad version [{0}] at line {1}", text, lineNo)); skip = htmls.containsKey(lineVersion.toString()); // Skip all versions already processed! if (skip) continue; if (lineVersion.compareTo(fromVersion) <= 0) break; // Skip all version sections below fromVersion (included) if (lineVersion.compareTo(toVersion) > 0) continue; // Skip all version sections after toVersion sb = new StringBuilder(); // Prepares a new version section } else { if (skip) continue; if (sb == null) continue; // An active builder is required! if (marker.equals("%")) { // Version title this.closeList(sb); sb.append(MessageFormat.format("<div class='wt-wntitle'>{0}</div>", text)); if (prettyPrint) sb.append("\n"); } else if (marker.equals("@")) { // Version sub-title this.closeList(sb); sb.append(MessageFormat.format("<div class='wt-wnsubtitle'>{0}</div>", text)); if (prettyPrint) sb.append("\n"); } else if (marker.equals("!")) { // Free text this.closeList(sb); sb.append(MessageFormat.format("<div class='wt-wnfreetext'>{0}</div>", text)); if (prettyPrint) sb.append("\n"); } else if (marker.equals("*")) { // Unordered list this.closeListItem(sb); this.openList(sb, "unordered"); this.openListItem(sb); sb.append(text); } else { // No special markers this.closeList(sb); sb.append(text); if (prettyPrint) sb.append("\n"); } } } else { if (skip) continue; if (sb == null) continue; // An active builder is required! sb.append(" "); // Inserts a space between lines sb.append(LangUtils.escapeHtmlAccentsAndSymbols(line)); } } // Closes last version's section if (sb != null) { this.closeList(sb); //htmls.put(lineVersion.toString(), sb.toString()); htmls.put(lineVersion.toString(), replaceVariables(sb.toString())); sb = null; } }
From source file:de.micromata.genome.util.runtime.AssertUtils.java
/** * Gets the code line.//from ww w . j a va2 s .c o m * * @param se the se * @return the code line */ public static String getCodeLine(final StackTraceElement se) { if (se == null) { return "<stack not found>"; } final String fname = se.getFileName(); final int cl = se.getLineNumber(); final String clsName = se.getClassName(); final String codeLine = getCodeLine(clsName, fname, cl); return StringUtils.trim(codeLine); }
From source file:de.micromata.genome.util.runtime.config.OrderedPropertiesWithComments.java
protected String decodeValue(String value) { char[] convtBuf = new char[value.length() * 2]; String ret = PropertiesReadWriter.loadConvert(value.toCharArray(), 0, value.length(), convtBuf); ret = StringUtils.trim(ret); return ret;/* w ww .j ava 2 s . c o m*/ }
From source file:com.wxine.android.model.Community.java
public Set<String> getTopics() { try {/*ww w . jav a2 s .com*/ String[] array = topic.split(","); for (String a : array) { if (StringUtils.isNotBlank(a)) { topics.add(StringUtils.trim(StringUtils.strip(a))); } } } catch (Exception e) { } return topics; }
From source file:com.ottogroup.bi.asap.resman.node.ProcessingNodeManager.java
/** * Shuts down the referenced processing node by sending a corresponding message and removing it from internal handler map * @param processingNodeId/*from ww w. j a v a2s. co m*/ * @return * @throws RequiredInputMissingException */ public String shutdownProcessingNode(final String processingNodeId) throws RequiredInputMissingException, UnknownProcessingNodeException { /////////////////////////////////////////////////////// // validate input if (StringUtils.isBlank(processingNodeId)) throw new RequiredInputMissingException("Missing processing node identifier"); String pid = StringUtils.lowerCase(StringUtils.trim(processingNodeId)); if (!this.processingNodes.containsKey(pid)) throw new UnknownProcessingNodeException( "Referenced processing node '" + processingNodeId + "' unknown to node manager"); // /////////////////////////////////////////////////////// final ProcessingNode node = this.processingNodes.remove(pid); node.shutdown(); if (logger.isDebugEnabled()) logger.debug("processing node shutdown [id=" + node.getId() + ", protocol=" + node.getProtocol() + ", host=" + node.getHost() + ", servicePort=" + node.getServicePort() + ", adminPort=" + node.getAdminPort() + "]"); return processingNodeId; }
From source file:ml.shifu.core.di.builtin.binning.AbstractBinning.java
/** * convert @AbstractBinning to String// w w w .j av a 2s. c om * * @return */ protected void stringToObj(String objValStr) { String[] objStrArr = objValStr.split(Character.toString(FIELD_SEPARATOR), -1); if (objStrArr.length < 4) { throw new IllegalArgumentException("The size of argument is incorrect"); } missingValCnt = Integer.parseInt(StringUtils.trim(objStrArr[0])); invalidValCnt = Integer.parseInt(StringUtils.trim(objStrArr[1])); expectedBinningNum = Integer.parseInt(StringUtils.trim(objStrArr[2])); if (missingValSet == null) { missingValSet = new HashSet<String>(); } else { missingValSet.clear(); } String[] elements = objStrArr[3].split(Character.toString(SETLIST_SEPARATOR), -1); for (String element : elements) { missingValSet.add(element); } }
From source file:com.dominion.salud.pedicom.configuration.PEDICOMJpaConfigurationCentral.java
@Bean(name = "CentralEM") @Autowired/*from w w w .java 2 s.c om*/ public EntityManagerFactory entityManagerFactory() throws Exception { HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter(); adapter.setGenerateDdl( Boolean.getBoolean(StringUtils.trim(environment.getRequiredProperty("hibernate.generate_ddl")))); adapter.setShowSql( Boolean.getBoolean(StringUtils.trim(environment.getRequiredProperty("hibernate.show_sql")))); adapter.setDatabasePlatform(StringUtils.trim(environment.getRequiredProperty("hibernate.dialect.central"))); LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setDataSource(crearData()); factory.setJpaVendorAdapter(adapter); factory.setPackagesToScan("com.dominion.salud.pedicom.negocio.entitiesCentral"); factory.setPersistenceUnitName("CentralEM"); factory.afterPropertiesSet(); factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver()); return factory.getObject(); }
From source file:com.tuplejump.stargate.lucene.query.Condition.java
protected String analyze(String field, String value, Analyzer analyzer) { StringBuilder result = new StringBuilder(); TokenStream source = null;//from w w w .java 2s . co m try { source = analyzer.tokenStream(field, value); source.reset(); while (source.incrementToken()) { result.append(source.getAttribute(CharTermAttribute.class).toString()); result.append(" "); } return StringUtils.trim(result.toString()); } catch (IOException e) { throw new RuntimeException("Error analyzing multiTerm term: " + value, e); } finally { IOUtils.closeWhileHandlingException(source); } }
From source file:com.norconex.collector.http.url.impl.TikaLinkExtractor.java
@Override public Set<com.norconex.collector.http.url.Link> extractLinks(InputStream is, String url, ContentType contentType) throws IOException { LinkContentHandler linkHandler = new LinkContentHandler(); Metadata metadata = new Metadata(); ParseContext parseContext = new ParseContext(); HtmlParser parser = new HtmlParser(); try {//ww w .j ava 2s . c o m parser.parse(is, linkHandler, metadata, parseContext); IOUtils.closeQuietly(is); List<Link> tikaLinks = linkHandler.getLinks(); Set<com.norconex.collector.http.url.Link> nxLinks = new HashSet<>(tikaLinks.size()); for (Link tikaLink : tikaLinks) { if (!isIgnoreNofollow() && "nofollow".equalsIgnoreCase(StringUtils.trim(tikaLink.getRel()))) { continue; } String extractedURL = tikaLink.getUri(); if (extractedURL.startsWith("?")) { extractedURL = url + extractedURL; } else if (extractedURL.startsWith("#")) { extractedURL = url; } else { extractedURL = resolve(url, extractedURL); } if (StringUtils.isNotBlank(extractedURL)) { com.norconex.collector.http.url.Link nxLink = new com.norconex.collector.http.url.Link( extractedURL); if (keepReferrerData) { nxLink.setReferrer(url); nxLink.setText(tikaLink.getText()); if (tikaLink.isAnchor()) { nxLink.setTag("a.href"); } else if (tikaLink.isImage()) { nxLink.setTag("img.src"); } nxLink.setTitle(tikaLink.getTitle()); } nxLinks.add(nxLink); } } //grab refresh URL from metadata (if present) String refreshURL = metadata.get("refresh"); if (StringUtils.isNotBlank(refreshURL)) { Matcher matcher = META_REFRESH_PATTERN.matcher(refreshURL); if (matcher.find()) { refreshURL = matcher.group(URL_PATTERN_GROUP_URL); } refreshURL = resolve(url, refreshURL); if (StringUtils.isNotBlank(refreshURL)) { com.norconex.collector.http.url.Link nxLink = new com.norconex.collector.http.url.Link( refreshURL); if (keepReferrerData) { nxLink.setReferrer(url); } nxLinks.add(nxLink); } } return nxLinks; } catch (TikaException | SAXException e) { throw new IOException("Could not parse to extract URLs: " + url, e); } }