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:net.lmxm.ute.configuration.ConfigurationReader.java
/** * Parses the http location./*from w w w. j a v a 2s . com*/ * * @param locationType the location type * @return the http location */ private HttpLocation parseHttpLocation(final HttpLocationType locationType) { final String prefix = "parseHttpLocation() :"; LOGGER.debug("{} entered", prefix); final HttpLocation location = new HttpLocation(); location.setId(StringUtils.trim(locationType.getId())); location.setUrl(StringUtils.trim(StringUtils.trim(locationType.getUrl()))); LOGGER.debug("{} returning {}", prefix, location); return location; }
From source file:com.ottogroup.bi.asap.resman.node.ProcessingNodeManager.java
/** * Generates an unique node identifier// ww w. ja v a2 s . co m * @param host * @param servicePort * @return * @throws RequiredInputMissingException thrown in case either the host or service port is missing */ protected String createNodeIdentifier(final String host, final int servicePort) throws RequiredInputMissingException { return new StringBuffer(StringUtils.lowerCase(StringUtils.trim(host))).append("#").append(servicePort) .toString(); }
From source file:io.cloudslang.lang.cli.SlangCli.java
private String prettyPrintSystemProperties(Set<SystemProperty> systemProperties) { StringBuilder stringBuilder = new StringBuilder(); if (CollectionUtils.isEmpty(systemProperties)) { stringBuilder.append("No system properties found."); } else {/*from ww w.jav a 2 s . c o m*/ stringBuilder.append("Following system properties were loaded:").append(System.lineSeparator()); for (SystemProperty systemProperty : systemProperties) { stringBuilder.append("\t"); stringBuilder.append(systemProperty.getFullyQualifiedName()); stringBuilder.append(": "); stringBuilder.append(systemProperty.getValue()); stringBuilder.append(System.lineSeparator()); } } return StringUtils.trim(stringBuilder.toString()); }
From source file:com.orange.ocara.ui.activity.EditAuditActivity.java
protected String getName() { return StringUtils.trim(name.getText().toString()); }
From source file:com.frostwire.search.youtube.jd.Request.java
public String getLocation() { if (this.httpConnection == null) { return null; }/*from w w w . j a va 2s . co m*/ String red = this.httpConnection.getHeaderField("Location"); if (StringUtils.isEmpty(StringUtils.trim(red))) { /* check if we have an old-school refresh header */ red = this.httpConnection.getHeaderField("refresh"); if (red != null) { // we need to filter the time count from the url red = new Regex(red, "url=(.+);?").getMatch(0); } if (StringUtils.isEmpty(StringUtils.trim(red))) { return null; } } final String encoding = this.httpConnection.getHeaderField("Content-Type"); if (encoding != null && encoding.contains("UTF-8")) { red = Encoding.UTF8Decode(red, "ISO-8859-1"); } try { new URL(red); } catch (final Exception e) { String path = this.getHttpConnection().getURL().getFile(); if (!path.endsWith("/")) { /* * path does not end with / we have to find latest valid path * * \/test.rar should result in empty path * * \/test/test.rar should result in \/test/ */ final String validPath = new Regex(path, "(/.*?/.*?)(\\?|$)").getMatch(0); if (validPath != null && validPath.length() > 0) { path = validPath; } else { path = ""; } } final int port = this.getHttpConnection().getURL().getPort(); final int defaultport = this.getHttpConnection().getURL().getDefaultPort(); String proto = "http://"; if (this.getHttpConnection().getURL().toString().startsWith("https")) { proto = "https://"; } String addPort = ""; if (defaultport > 0 && port > 0 && defaultport != port) { addPort = ":" + port; } red = proto + this.getHttpConnection().getURL().getHost() + addPort + (red.charAt(0) == '/' ? red : path + "/" + red); } return Browser.correctURL(Encoding.urlEncode_light(red)); }
From source file:com.tech.utils.CustomCollectionUtil.java
/** * Converts comma separated value string to Long array * //w ww. j av a2s.c om * @param csvString * @param seperator * @return itemSet */ public static Long[] convertStringToLongArray(String csvString, String seperator) { String[] itemsArray = StringUtils.split(csvString, seperator); Long[] arrLong = new Long[itemsArray.length]; if (StringUtils.isNotEmpty(csvString) && StringUtils.isNotBlank(csvString)) { if (itemsArray != null && itemsArray.length > 0) { for (int i = 0; i < itemsArray.length; i++) { if (StringUtils.isNotEmpty(itemsArray[i]) && StringUtils.isNotBlank(itemsArray[i])) { arrLong[i] = Long.valueOf(StringUtils.trim(itemsArray[i])); } } } } return arrLong; }
From source file:com.ottogroup.bi.asap.pipeline.MicroPipeline.java
/** * Submits the provided {@link EmitterExecutor} to the pipeline instance * @param emitterExecutor/* www . j a v a2 s . c om*/ * @throws RequiredInputMissingException * @throws ComponentAlreadySubmittedException */ public void submitEmitterExecutor(final EmitterExecutor emitterExecutor) throws RequiredInputMissingException, ComponentAlreadySubmittedException { /////////////////////////////////////////////////////////////////// // validate input if (emitterExecutor == null) throw new RequiredInputMissingException("Missing required input for 'emitterExecutor'"); if (StringUtils.isBlank(emitterExecutor.getEmitterId())) throw new RequiredInputMissingException("Missing required input for emitter identifier"); // /////////////////////////////////////////////////////////////////// // normalize identifier to lower case String eid = StringUtils.lowerCase(StringUtils.trim(emitterExecutor.getEmitterId())); if (this.emitterExecutors.containsKey(eid)) throw new ComponentAlreadySubmittedException("Component '" + emitterExecutor.getEmitterId() + "' already submitted to pipeline '" + id + "'"); // add emitter executor to internal map and submit it to executor service this.emitterExecutors.put(eid, emitterExecutor); this.executorService.submit(emitterExecutor); if (logger.isDebugEnabled()) logger.debug("emitter executor submitted [pid=" + id + ", eid=" + eid + ", mb=" + emitterExecutor.getMailbox() + "]"); }
From source file:com.thinkbiganalytics.feedmgr.sla.ServiceLevelAgreementService.java
private ServiceLevelAgreement saveAndScheduleSla(ServiceLevelAgreementGroup serviceLevelAgreement, FeedMetadata feed) {// w w w. ja va 2 s.c o m return metadataAccess.commit(() -> { if (serviceLevelAgreement != null) { ServiceLevelAgreementMetricTransformerHelper transformer = new ServiceLevelAgreementMetricTransformerHelper(); if (feed != null) { transformer.applyFeedNameToCurrentFeedProperties(serviceLevelAgreement, feed.getCategory().getSystemName(), feed.getSystemFeedName()); } ServiceLevelAgreement sla = transformer.getServiceLevelAgreement(serviceLevelAgreement); ServiceLevelAgreementBuilder slaBuilder = null; com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement.ID existingId = null; if (StringUtils.isNotBlank(sla.getId())) { existingId = slaProvider.resolve(sla.getId()); } if (existingId != null) { slaBuilder = slaProvider.builder(existingId); } else { slaBuilder = slaProvider.builder(); } slaBuilder.name(sla.getName()).description(sla.getDescription()); for (com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup group : sla.getGroups()) { ObligationGroupBuilder groupBuilder = slaBuilder .obligationGroupBuilder(ObligationGroup.Condition.valueOf(group.getCondition())); for (Obligation o : group.getObligations()) { groupBuilder.obligationBuilder().metric(o.getMetrics()).description(o.getDescription()) .build(); } groupBuilder.build(); } com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement savedSla = slaBuilder.build(); List<ServiceLevelAgreementActionConfiguration> actions = transformer .getActionConfigurations(serviceLevelAgreement); // now assign the sla checks slaProvider.slaCheckBuilder(savedSla.getId()).removeSlaChecks().actionConfigurations(actions) .build(); //all referencing Feeds List<String> systemCategoryAndFeedNames = transformer.getCategoryFeedNames(serviceLevelAgreement); Set<Feed> slaFeeds = new HashSet<Feed>(); Set<Feed.ID> slaFeedIds = new HashSet<Feed.ID>(); for (String categoryAndFeed : systemCategoryAndFeedNames) { //fetch and update the reference to the sla String categoryName = StringUtils.trim(StringUtils.substringBefore(categoryAndFeed, ".")); String feedName = StringUtils.trim(StringUtils.substringAfterLast(categoryAndFeed, ".")); Feed feedEntity = feedProvider.findBySystemName(categoryName, feedName); if (feedEntity != null) { slaFeeds.add(feedEntity); slaFeedIds.add(feedEntity.getId()); } } if (feed != null) { Feed.ID feedId = feedProvider.resolveFeed(feed.getFeedId()); if (!slaFeedIds.contains(feedId)) { Feed feedEntity = feedProvider.getFeed(feedId); slaFeeds.add(feedEntity); } } //relate them feedSlaProvider.relateFeeds(savedSla, slaFeeds); com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement restModel = ServiceLevelAgreementModelTransform .toModel(savedSla, slaFeeds, true); //schedule it serviceLevelAgreementScheduler.scheduleServiceLevelAgreement(savedSla); return restModel; } return null; }); }
From source file:com.ottogroup.bi.spqr.pipeline.MicroPipelineManagerTest.java
/** * Test case for {@link MicroPipelineManager#shutdownPipeline(String)} being provided * null as input which must not change the number of registered pipelines */// w w w .ja v a 2 s. c o m @Test public void testShutdownPipeline_withNullInput() throws Exception { MicroPipelineConfiguration cfg = new MicroPipelineConfiguration(); cfg.setId("testExecutePipeline_withValidConfiguration"); MicroPipeline pipeline = Mockito.mock(MicroPipeline.class); Mockito.when(pipeline.getId()).thenReturn(cfg.getId()); MicroPipelineFactory factory = Mockito.mock(MicroPipelineFactory.class); Mockito.when(factory.instantiatePipeline(cfg, executorService)).thenReturn(pipeline); MicroPipelineManager manager = new MicroPipelineManager("id", factory, executorService); Assert.assertEquals("Values must be equal", StringUtils.lowerCase(StringUtils.trim(cfg.getId())), manager.executePipeline(cfg)); Assert.assertEquals("Values must be equal", 1, manager.getNumOfRegisteredPipelines()); Mockito.verify(factory).instantiatePipeline(cfg, executorService); manager.shutdownPipeline(null); Assert.assertEquals("Values must be equal", 1, manager.getNumOfRegisteredPipelines()); }
From source file:kenh.xscript.database.elements.Execute.java
/** * Execute sql./*w w w . j a v a 2 s.com*/ * @param sql * @param parameter * @param var variable name of result * @param conn */ private int executeSQL(SQLBean sqlBean, String var, java.sql.Connection conn) throws UnsupportedScriptException { if (sqlBean == null || StringUtils.isBlank(sqlBean.getSql())) { UnsupportedScriptException ex = new UnsupportedScriptException(this, "Can't find the sql to execute."); throw ex; } if (conn == null) { throw new UnsupportedScriptException(this, "Connection is empty."); } var = StringUtils.trimToNull(var); PreparedStatement pstmt = null; ResultSet rs = null; try { if (conn.isClosed()) { throw new UnsupportedScriptException(this, "Connection is closed."); } StringBuffer traceInfo = new StringBuffer(); traceInfo.append("Execute SQL: \n" + StringUtils.trim(sqlBean.getSql())); pstmt = conn.prepareStatement(sqlBean.getSql()); Map<String, String> parameters = getParameters(sqlBean); Iterator<String> elements = parameters.values().iterator(); // set the Paramter for PreparedStatement int i = 1; while (elements.hasNext()) { String str = elements.next(); Object obj = this.getEnvironment().parse(str); traceInfo.append("\nParam " + i + ": " + obj.toString()); pstmt.setObject(i, obj); i++; } logger.trace(traceInfo.toString()); boolean result = false; result = pstmt.execute(); if (result) { rs = pstmt.getResultSet(); if (StringUtils.isNotBlank(var)) { ResultSetBean bean = new ResultSetBean(rs); this.saveVariable(var, bean, null); } } else { int count = pstmt.getUpdateCount(); if (StringUtils.isNotBlank(var)) this.saveVariable(var, count, null); } } catch (java.sql.SQLException | IllegalAccessException | InstantiationException e) { this.getEnvironment().setVariable(Constant.VARIABLE_EXCEPTION, e); return EXCEPTION; } catch (UnsupportedExpressionException e) { throw new UnsupportedScriptException(this, e); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) { } rs = null; } if (pstmt != null) { try { pstmt.close(); } catch (Exception e) { } pstmt = null; } } return NONE; }